aboutsummaryrefslogtreecommitdiff
path: root/src/http.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/http.c')
-rw-r--r--src/http.c132
1 files changed, 121 insertions, 11 deletions
diff --git a/src/http.c b/src/http.c
index 4520d73..00989c5 100644
--- a/src/http.c
+++ b/src/http.c
@@ -12,7 +12,6 @@
#include "cctk_Parameters.h"
#include <stdio.h>
-#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_SYS_TIME_H
@@ -33,6 +32,8 @@
#include "util_String.h"
#include "httpd.h"
+#include "util_Hash.h"
+#include "SString_Namespace.h"
static const char *rcsid = "$Header$";
@@ -42,6 +43,115 @@ CCTK_FILEVERSION(CactusConnect_HTTPD_http_c)
********************* Local Data Types ***********************
********************************************************************/
+typedef struct HTTPArg
+{
+ /* Public data */
+ char *arg;
+ char *value;
+
+ /* Private data */
+ struct HTTPArg *next;
+ struct HTTPArg *all_next;
+} httpArg_PLACEHOLDER;
+
+/* This is the main structure for storing data about a request. */
+typedef struct httpRequestTag
+{
+ /* Public members of the structure. */
+ char *body; /* The body of the request */
+ int body_length; /* How long the body is */
+
+ const char *method; /* The HTTP method */
+ char *uri; /* The URI */
+ const char *residual; /* What's left of the URI after subtracting the found page */
+
+ /* HTTP version numbers */
+ int http_major_version;
+ int http_minor_version;
+
+ /* How many arguments there are */
+ int n_arguments;
+
+ /* These are all private members of this structure */
+
+ /* The connection data */
+ void *connection;
+
+ /* The request header lines */
+ uHash *headers;
+
+ /* Stuff for arguments */
+
+ /* First a hash table to look the data up quickly */
+ uHash *arguments;
+
+ /* Now a linked list to allow walking. */
+ httpArg *firstarg;
+ httpArg *lastarg;
+ httpArg *currentarg;
+
+} httpRequest_PLACEHOLDER;
+
+#define BLANK_HTTPREQUEST {NULL, 0, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
+ /* Accessors for the httpRequest structure */
+unsigned int HTTP_Major_Version( const httpRequest *request )
+{
+ return request->http_major_version;
+}
+
+unsigned int HTTP_Minor_Version( const httpRequest *request )
+{
+ return request->http_minor_version;
+}
+
+unsigned int HTTP_Num_Arguments( const httpRequest *request )
+{
+ return request->n_arguments;
+}
+
+const char * HTTP_URI( const httpRequest *request )
+{
+ return request->uri;
+}
+
+const char * HTTP_Residual( const httpRequest *request )
+{
+ return request->residual;
+}
+
+void HTTP_SetResidual( httpRequest *request, const char *residual )
+{
+ request->residual = residual;
+}
+
+const char * HTTP_Arg_Value( const httpArg *arg )
+{
+ return arg->value;
+}
+
+const char * HTTP_Arg_Name( const httpArg *arg )
+{
+ return arg->arg;
+}
+
+httpSocket * HTTP_Connection( const httpRequest *request )
+{
+ return request->connection;
+}
+
+SSBOOL HTTP_GetHeaderValueString(const httpRequest *request,
+ const String *header, String *value)
+{
+ const char * v = HTTP_HeaderValue(request, GetBuffer( header ) );
+ if( v )
+ {
+ SetToCString( value, v );
+ return SSTRUE;
+ }
+ else
+ return SSFALSE;
+}
+
struct httpHeader
{
char *line;
@@ -52,13 +162,14 @@ struct httpHeader
********************************************************************/
static char *NextLine(char *buffer, int *start, int size);
-static int DealWithRequest(cGH *cctkGH, httpRequest *request, char *buffer, int bufsize);
-static int AddHeader(httpRequest *request, const char *line);
+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);
+static int StripArgs(httpRequest *request, char *request_uri);
static void Decode(char *string);
-static int InitialiseRequest(httpRequest *request);
-static int ClearRequest(httpRequest *request);
+static int InitialiseRequest(httpRequest *request);
+static int ClearRequest(httpRequest *request);
static void DestroyHeader(struct httpHeader *header);
static void DestroyArgument(httpArg *argument);
@@ -588,9 +699,6 @@ static int AddHeader(httpRequest *request, const char *line)
static int StripArgs(httpRequest *request, char *request_uri)
{
char *position;
- char *token;
- httpArg *argument;
- httpArg *stored;
/* Do we have arguments ? */
if((position = strchr(request_uri, '?')))
{
@@ -603,7 +711,7 @@ static int StripArgs(httpRequest *request, char *request_uri)
/* Parse the argument list */
position++;
- token = strtok(position, "&");
+ char *token = strtok(position, "&");
while(token)
{
@@ -619,11 +727,13 @@ static int StripArgs(httpRequest *request, char *request_uri)
Decode(token);
Decode(value);
- argument = (httpArg *)malloc(sizeof(httpArg));
+ httpArg *argument = (httpArg *)malloc(sizeof(httpArg));
if(argument)
{
httpArg *last = NULL;
+ httpArg *stored;
+
argument->next = NULL;
argument->all_next = NULL;
argument->arg = Util_Strdup(token);