void setReqline(int kind, char *uri) { ReqLine_t t = ReqLine_new ( kind , uri , HTTP_ONE_ONE); gReqline = t; }
ReqLine_t parseRequestLine (int fd) { enum ReqKind_t kind; ReqLine_t reqline; switch(token.kind){ case TOKEN_HEAD: kind = REQ_KIND_HEAD; break; case TOKEN_GET: kind = REQ_KIND_GET; break; default: parseError(fd); break; } advance(fd, 1); eatToken(TOKEN_SPACE, fd, 1); char *uri = eatToken(TOKEN_STR, fd, 1); eatToken(TOKEN_SPACE, fd, 1); eatToken(TOKEN_HTTP_ONE_ONE, fd, 1); eatToken(TOKEN_CRLF, fd, 1); if (DEBUG){ fprintf (stderr, "uri=%s\n", uri); } reqline = ReqLine_new (0 , uri , HTTP_ONE_ONE); ReqLine_print (1, reqline); return reqline; }
ReqLine_t Parse_reqLine (int fd) { enum ReqKind_t kind; ReqLine_t reqline; getToken(fd, 1); //modify //printf("parse(F) uri = %s; kind = %d; n = %d\n", token.lexeme, token.kind, TOKEN_POST); switch(token.kind){ case TOKEN_HEAD: kind = REQ_KIND_HEAD; break; case TOKEN_GET: kind = REQ_KIND_GET; break; case TOKEN_POST: kind = REQ_KIND_POST; break; default: parseError(fd); break; } advance(fd, 1); eatToken(TOKEN_SPACE, fd, 1); advance (fd, 1); //modify char *uri = eatToken(TOKEN_STR, fd, 1); //eatToken(TOKEN_SPACE, fd, 1); advance (fd, 1); eatToken(TOKEN_SPACE, fd , 1); advance(fd, 1); eatToken(TOKEN_HTTP_ONE_ONE, fd, 1); advance(fd, 1); eatToken(TOKEN_CRLF, fd, 1); ///no more eat token if (DEBUG){ fprintf (stderr, "uri=%s\n", uri); } reqline = ReqLine_new ( kind , uri , HTTP_ONE_ONE); ReqLine_print (1, reqline); return reqline; }
int main (int argc, char **argv) { Http_t tree; if (argc<2) die ("server bug"); signal(SIGCHLD, SIG_IGN); // get the pipe fd int pipefd = atoi (argv[1]); if (DEBUG) printf ("pipefd = %d\n", pipefd); while (1){ char uri_str[1024]; int sockfd; recvfd (pipefd, uri_str, sizeof(uri_str), &sockfd); if (DEBUG){ printf("uri=[%s]\n", uri_str); printf ("banksv client recieves a sockfd = %d\n", sockfd); } if(fork() == 0){ int ruid, euid, suid; getresuid(&ruid, &euid, &suid); if (DEBUG) printf("ruid=[%d], euid=[%d], suid=[%d]\n" , ruid , euid , suid); ReqLine_t reqline = ReqLine_new(REQ_KIND_POST , uri_str , HTTP_ONE_ONE); tree = Parse_parse(sockfd, 0); tree->reqLine = reqline; //response Handle_main (sockfd, tree); close(sockfd); exit(0); } close(sockfd); } return 0; }