diff options
author | goodale <goodale@1faa4e14-9dd3-4be0-9f0e-ffe519881164> | 2000-09-18 11:34:52 +0000 |
---|---|---|
committer | goodale <goodale@1faa4e14-9dd3-4be0-9f0e-ffe519881164> | 2000-09-18 11:34:52 +0000 |
commit | 72a5bfb5bef0946f92d935990b17c0bb0c69f9ae (patch) | |
tree | 049314ccaa92fbdf40f1af1f01c3f7123ac705e8 /src/http.c | |
parent | 7d29b42986d5c0af3846831923b52d36e310d8c1 (diff) |
All reading from socket is now done with HTTP_Read. HTTP_Read and HTTP_Write
now both live in Sockets.c.
Tom
git-svn-id: http://svn.cactuscode.org/arrangements/CactusConnect/HTTPD/trunk@40 1faa4e14-9dd3-4be0-9f0e-ffe519881164
Diffstat (limited to 'src/http.c')
-rw-r--r-- | src/http.c | 55 |
1 files changed, 28 insertions, 27 deletions
@@ -37,7 +37,7 @@ struct httpHeader ********************************************************************/ static char *NextLine(char *buffer, int *start, int size); -static int DealWithRequest(cGH *cctkGH, int filedes, char *buffer, int bufsize); +static int DealWithRequest(cGH *cctkGH, httpRequest *request, char *buffer, int bufsize); static int AddHeader(httpRequest *request, const char *line); static int StripArgs(httpRequest *request, char *request_uri); @@ -83,13 +83,19 @@ int HTTP_ReadFromClient(cGH *cctkGH, int filedes) int keepalive; char buffer[MAXMSG]; int nbytes; + httpRequest request; + + InitialiseRequest(&request); + + request.filedes = filedes; + + nbytes = HTTP_Read(&request, buffer, MAXMSG); - nbytes = read (filedes, buffer, MAXMSG); if (nbytes < 0) { /* Read error. */ perror ("read"); - exit (EXIT_FAILURE); + CCTK_Abort(cctkGH, EXIT_FAILURE); } else if (nbytes == 0) /* End-of-file. */ @@ -104,7 +110,7 @@ int HTTP_ReadFromClient(cGH *cctkGH, int filedes) if(nbytes > 0) { - keepalive = DealWithRequest(cctkGH, filedes, buffer, nbytes); + keepalive = DealWithRequest(cctkGH, &request, buffer, nbytes); } if(keepalive) @@ -291,7 +297,7 @@ static char *NextLine(char *buffer, int *start, int size) @endhistory @@*/ -static int DealWithRequest(cGH *cctkGH, int filedes, char *buffer, int bufsize) +static int DealWithRequest(cGH *cctkGH, httpRequest *request, char *buffer, int bufsize) { char *line; char *tmp; @@ -301,11 +307,6 @@ static int DealWithRequest(cGH *cctkGH, int filedes, char *buffer, int bufsize) char *method; char *request_uri; char *http_version; - httpRequest request; - - InitialiseRequest(&request); - - request.filedes = filedes; tmp = buffer; @@ -348,33 +349,33 @@ static int DealWithRequest(cGH *cctkGH, int filedes, char *buffer, int bufsize) { printf("Method: %s\n", method); - request.method = method; + request->method = method; } if(request_uri) { printf("URI: %s\n", request_uri); - request.uri = request_uri; - StripArgs(&request, request.uri); + request->uri = request_uri; + StripArgs(request, request->uri); } if(http_version) { printf("HTTP: %s\n", http_version); - sscanf(http_version, "%*5s%d%*1[.]%d", &(request.http_major_version), - &(request.http_minor_version)); + sscanf(http_version, "%*5s%d%*1[.]%d", &(request->http_major_version), + &(request->http_minor_version)); } else { - request.http_major_version = 0; - request.http_minor_version = 90; + request->http_major_version = 0; + request->http_minor_version = 90; } #ifdef HTTP_DEBUG - printf("HTTP Major version: %d\n", request.http_major_version); - printf("HTTP Minor version: %d\n", request.http_minor_version); + printf("HTTP Major version: %d\n", request->http_major_version); + printf("HTTP Minor version: %d\n", request->http_minor_version); #endif #ifdef HTTP_DEBUG @@ -383,9 +384,9 @@ static int DealWithRequest(cGH *cctkGH, int filedes, char *buffer, int bufsize) while(line = NextLine(tmp, &start, bufsize)) { - if(! request.body && *line != 0) + if(! request->body && *line != 0) { - AddHeader(&request, line); + AddHeader(request, line); } #ifdef HTTP_DEBUG @@ -402,7 +403,7 @@ static int DealWithRequest(cGH *cctkGH, int filedes, char *buffer, int bufsize) printf("Start of request body\n"); #endif - request.body = line + 2; + request->body = line + 2; } } @@ -410,24 +411,24 @@ static int DealWithRequest(cGH *cctkGH, int filedes, char *buffer, int bufsize) printf("End of request body\n"); #endif - request.body_length = buffer + bufsize - request.body; + request->body_length = buffer + bufsize - request->body; printf("Replying...\n"); - if(!strcmp(request.method, "GET")) + if(!strcmp(request->method, "GET")) { - HTTP_RequestGET(cctkGH, &request); + HTTP_RequestGET(cctkGH, request); } else { - HTTP_RequestUnsupported(cctkGH, &request); + HTTP_RequestUnsupported(cctkGH, request); } #ifdef HTTP_DEBUG printf("Dealt with.\n"); #endif - ClearRequest(&request); + ClearRequest(request); return 0; } |