aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Server.c23
-rw-r--r--src/Sockets.c48
-rw-r--r--src/http.c55
-rw-r--r--src/http_Request.h1
4 files changed, 77 insertions, 50 deletions
diff --git a/src/Server.c b/src/Server.c
index ba6f071..d3d865d 100644
--- a/src/Server.c
+++ b/src/Server.c
@@ -188,29 +188,6 @@ int HTTP_RegisterPage(const char *path, int (*function)(cGH *, httpRequest *, vo
return 0;
}
- /*@@
- @routine HTTP_Write
- @date Fri Sep 15 18:47:41 2000
- @author Tom Goodale
- @desc
- Writes part or all of an HTTP reply.
- @enddesc
- @calls
- @calledby
- @history
-
- @endhistory
-
-@@*/
-int HTTP_Write(httpRequest *request, const char *buffer, size_t count)
-{
- int retval;
-
- /* Currently don't do anything fancy. */
- retval = write(request->filedes, buffer, count);
-
- return retval;
-}
/*@@
@routine HTTP_UpdateState
diff --git a/src/Sockets.c b/src/Sockets.c
index 122daa5..2c9b97e 100644
--- a/src/Sockets.c
+++ b/src/Sockets.c
@@ -227,6 +227,54 @@ int HTTP_Poll(cGH *cctkGH, long sec, long usec)
return 0;
}
+ /*@@
+ @routine HTTP_Write
+ @date Fri Sep 15 18:47:41 2000
+ @author Tom Goodale
+ @desc
+ Writes part or all of an HTTP reply.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+int HTTP_Write(httpRequest *request, const char *buffer, size_t count)
+{
+ int retval;
+
+ /* Currently don't do anything fancy. */
+ retval = write(request->filedes, buffer, count);
+
+ return retval;
+}
+
+ /*@@
+ @routine HTTP_Read
+ @date Mon Sep 18 10:14:03 2000
+ @author Tom Goodale
+ @desc
+ Reads part or all of an HTTP request.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+int HTTP_Read(httpRequest *request, const char *buffer, size_t count)
+{
+ int retval;
+
+ /* Currently don't do anything fancy. */
+ retval = read(request->filedes, buffer, count);
+
+ return retval;
+}
+
/********************************************************************
********************* Local Routines *************************
********************************************************************/
diff --git a/src/http.c b/src/http.c
index e188c5f..a428233 100644
--- a/src/http.c
+++ b/src/http.c
@@ -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;
}
diff --git a/src/http_Request.h b/src/http_Request.h
index 5f39fe0..614150e 100644
--- a/src/http_Request.h
+++ b/src/http_Request.h
@@ -76,6 +76,7 @@ const httpArg *HTTP_ArgumentWalk(httpRequest *request, int first);
const char *HTTP_HeaderValue(const httpRequest *request, const char *header);
int HTTP_Write(httpRequest *request, const char *buffer, size_t count);
+int HTTP_Read(httpRequest *request, const char *buffer, size_t count);
#ifdef __cplusplus
}