|
Server 0.0.1
HTTP/REST server implementation
|
00001 00023 #include <stdlib.h> 00024 #include <string.h> 00025 #include <sys/types.h> 00026 00027 #include "class.h" 00028 #include "http/header.h" 00029 #include "http/parser.h" 00030 #include "http/message.h" 00031 #include "http/request.h" 00032 #include "hash.h" 00033 00034 void 00035 httpParserHeader( 00036 HttpParser this, 00037 const char * line, 00038 const char * lend) 00039 { 00040 const char * name = line; 00041 char * value = memchr(line, ':', lend - line); 00042 size_t nname = (value++) - name; 00043 HttpMessage current = this->current; 00044 00045 if (NULL == value) { 00046 return; 00047 } 00048 00049 for (; *value == ' ' && value < lend; value++); 00050 00051 if (value == lend) { 00052 return; 00053 } 00054 00055 if (0 == strncasecmp("content-length", name, nname-1)) { 00056 current->nbody = strtoul(value, NULL, 10); 00057 if (0 < this->current->nbody) { 00058 current->body = malloc(current->nbody); 00059 } 00060 current->dbody = 0; 00061 } 00062 00063 if (0 == strncasecmp("cookie", name, nname-1)) { 00064 HttpRequest request = (HttpRequest)this->current; 00065 char * pair = value; 00066 ssize_t togo = lend - value; 00067 00068 while(NULL != pair && 0 < togo) { 00069 char * key = pair; 00070 char * eqsign; 00071 char * val; 00072 size_t nval; 00073 00074 for (; *key == ' ' && key < lend; key++, togo--); 00075 eqsign = memchr(key, '=', togo); 00076 00077 if (NULL == eqsign) { 00078 break; 00079 } 00080 00081 togo -= (eqsign - key); 00082 pair = memchr(eqsign, ';', togo); 00083 00084 if (NULL == pair) { 00085 pair = (char *)lend; 00086 } 00087 00088 nval = pair-eqsign-1; 00089 val = (0 != nval)? eqsign+1 : NULL; 00090 00091 hashAdd(request->cookies, 00092 new(HashValue, key, eqsign-key, val, nval)); 00093 00094 pair++; 00095 togo -= (pair - eqsign); 00096 } 00097 } 00098 00099 hashAdd(current->header, 00100 new(HttpHeader, name, nname, value, lend - value)); 00101 } 00102 00103 // vim: set ts=4 sw=4: