diff --git a/ChangeLog b/ChangeLog index 03a8b6d..cc95381 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,10 +1,14 @@ +2012-02-09 22:39:08 +0100 Georg Hopp + + * updated docs (HEAD, master) + 2012-02-09 22:34:32 +0100 Georg Hopp - * start split of request parser (HEAD, master) + * start split of request parser (origin/master, origin/HEAD) 2012-02-09 11:44:17 +0100 Georg Hopp - * no more request body debig output (origin/master, origin/HEAD) + * no more request body debig output 2012-02-09 11:32:28 +0100 Georg Hopp diff --git a/docs/html/accept_8c.html b/docs/html/accept_8c.html index be6c2a1..67473dc 100644 --- a/docs/html/accept_8c.html +++ b/docs/html/accept_8c.html @@ -84,6 +84,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
#include <errno.h>#include <unistd.h>#include "socket.h"#include "interface/class.h"#include "interface/logger.h"
Go to the source code of this file.
@@ -129,7 +132,7 @@ Functions: change port to remote port on success
-Definition at line 8 of file accept.c.
+Definition at line 9 of file accept.c.
{
Sock sock; /* Socket for client */
unsigned int len; /* Length of client address data structure */
@@ -168,7 +171,7 @@ Here is the call graph for this function:
1.7.3 00001 #include <errno.h> /* for errno */ -00002 -00003 #include "socket.h" -00004 #include "interface/class.h" -00005 #include "interface/logger.h" -00006 -00007 Sock -00008 socketAccept(Sock this, char remoteAddr[16]) -00009 { -00010 Sock sock; /* Socket for client */ -00011 unsigned int len; /* Length of client address data structure */ -00012 -00013 /* Set the size of the in-out parameter */ -00014 len = sizeof(this->addr); -00015 -00023 sock = new(Sock, this->log, this->port); -00024 close(sock->handle); -00029 /* Wait for a client to connect */ -00030 sock->handle = accept(this->handle, (struct sockaddr *) &(sock->addr), &len); -00031 if (-1 == sock->handle) { -00032 loggerLog(this->log, LOGGER_WARNING, -00033 "error accepting connection: %s", strerror(errno)); -00034 } else { -00035 loggerLog(this->log, LOGGER_INFO, -00036 "handling client %s\n", inet_ntoa((sock->addr).sin_addr)); -00037 } -00038 -00039 return sock; -00040 } -00041 -00042 // vim: set ts=4 sw=4: +00002 #include <unistd.h> +00003 +00004 #include "socket.h" +00005 #include "interface/class.h" +00006 #include "interface/logger.h" +00007 +00008 Sock +00009 socketAccept(Sock this, char remoteAddr[16]) +00010 { +00011 Sock sock; /* Socket for client */ +00012 unsigned int len; /* Length of client address data structure */ +00013 +00014 /* Set the size of the in-out parameter */ +00015 len = sizeof(this->addr); +00016 +00024 sock = new(Sock, this->log, this->port); +00025 close(sock->handle); +00030 /* Wait for a client to connect */ +00031 sock->handle = accept(this->handle, (struct sockaddr *) &(sock->addr), &len); +00032 if (-1 == sock->handle) { +00033 loggerLog(this->log, LOGGER_WARNING, +00034 "error accepting connection: %s", strerror(errno)); +00035 } else { +00036 loggerLog(this->log, LOGGER_INFO, +00037 "handling client %s\n", inet_ntoa((sock->addr).sin_addr)); +00038 } +00039 +00040 return sock; +00041 } +00042 +00043 // vim: set ts=4 sw=4:
1.7.3 | class | |||||
| HttpHeader | |||||
| HttpRequest | |||||
| HttpRequestParser | |||||
| HttpRequestQueue | |||||
| HttpResponse | |||||
| i_Class | |||||
| i_Logger | |||||
| i_StreamReader | |||||
| HttpResponse | i_StreamReader | Logger | Server | |
| HttpHeader |
| iface_impl | LoggerStderr | Sock | |
| HttpRequest |
1.7.3
1.7.3
1.7.3 |
+ server 0.0.1
+ basicserverinfrastructure
+ |
+
Go to the source code of this file.
++Defines | |
| #define | HAVE_DLFCN_H 1 |
| #define | HAVE_INTTYPES_H 1 |
| #define | HAVE_JSON_JSON_H 1 |
| #define | HAVE_LIBJSON 1 |
| #define | HAVE_MEMORY_H 1 |
| #define | HAVE_MEMSET 1 |
| #define | HAVE_STDARG_H 1 |
| #define | HAVE_STDBOOL_H 1 |
| #define | HAVE_STDINT_H 1 |
| #define | HAVE_STDIO_H 1 |
| #define | HAVE_STDLIB_H 1 |
| #define | HAVE_STRINGS_H 1 |
| #define | HAVE_STRING_H 1 |
| #define | HAVE_SYSLOG_H 1 |
| #define | HAVE_SYS_STAT_H 1 |
| #define | HAVE_SYS_TYPES_H 1 |
| #define | HAVE_UNISTD_H 1 |
| #define | HAVE__BOOL 1 |
| #define | LT_OBJDIR ".libs/" |
| #define | PACKAGE "cclass" |
| #define | PACKAGE_BUGREPORT "Georg Hopp <georg@steffers.org>" |
| #define | PACKAGE_NAME "cclass" |
| #define | PACKAGE_STRING "cclass 0.0.1" |
| #define | PACKAGE_TARNAME "cclass" |
| #define | PACKAGE_URL "" |
| #define | PACKAGE_VERSION "0.0.1" |
| #define | STDC_HEADERS 1 |
| #define | VERSION "0.0.1" |
| #define PACKAGE_BUGREPORT "Georg Hopp <georg@steffers.org>" | +
| #define PACKAGE_STRING "cclass 0.0.1" | +
|
+ server 0.0.1
+ basicserverinfrastructure
+ |
+
00001 /* config.h. Generated from config.h.in by configure. */ +00002 /* config.h.in. Generated from configure.ac by autoheader. */ +00003 +00004 /* Define to 1 if you have the <dlfcn.h> header file. */ +00005 #define HAVE_DLFCN_H 1 +00006 +00007 /* Define to 1 if you have the <inttypes.h> header file. */ +00008 #define HAVE_INTTYPES_H 1 +00009 +00010 /* Define to 1 if you have the <json/json.h> header file. */ +00011 #define HAVE_JSON_JSON_H 1 +00012 +00013 /* Define to 1 if you have the `json' library (-ljson). */ +00014 #define HAVE_LIBJSON 1 +00015 +00016 /* Define to 1 if you have the <memory.h> header file. */ +00017 #define HAVE_MEMORY_H 1 +00018 +00019 /* Define to 1 if you have the `memset' function. */ +00020 #define HAVE_MEMSET 1 +00021 +00022 /* Define to 1 if you have the <stdarg.h> header file. */ +00023 #define HAVE_STDARG_H 1 +00024 +00025 /* Define to 1 if stdbool.h conforms to C99. */ +00026 #define HAVE_STDBOOL_H 1 +00027 +00028 /* Define to 1 if you have the <stdint.h> header file. */ +00029 #define HAVE_STDINT_H 1 +00030 +00031 /* Define to 1 if you have the <stdio.h> header file. */ +00032 #define HAVE_STDIO_H 1 +00033 +00034 /* Define to 1 if you have the <stdlib.h> header file. */ +00035 #define HAVE_STDLIB_H 1 +00036 +00037 /* Define to 1 if you have the <strings.h> header file. */ +00038 #define HAVE_STRINGS_H 1 +00039 +00040 /* Define to 1 if you have the <string.h> header file. */ +00041 #define HAVE_STRING_H 1 +00042 +00043 /* Define to 1 if you have the <syslog.h> header file. */ +00044 #define HAVE_SYSLOG_H 1 +00045 +00046 /* Define to 1 if you have the <sys/stat.h> header file. */ +00047 #define HAVE_SYS_STAT_H 1 +00048 +00049 /* Define to 1 if you have the <sys/types.h> header file. */ +00050 #define HAVE_SYS_TYPES_H 1 +00051 +00052 /* Define to 1 if you have the <unistd.h> header file. */ +00053 #define HAVE_UNISTD_H 1 +00054 +00055 /* Define to 1 if the system has the type `_Bool'. */ +00056 #define HAVE__BOOL 1 +00057 +00058 /* Define to the sub-directory in which libtool stores uninstalled libraries. +00059 */ +00060 #define LT_OBJDIR ".libs/" +00061 +00062 /* Define to 1 if your C compiler doesn't accept -c and -o together. */ +00063 /* #undef NO_MINUS_C_MINUS_O */ +00064 +00065 /* Name of package */ +00066 #define PACKAGE "cclass" +00067 +00068 /* Define to the address where bug reports for this package should be sent. */ +00069 #define PACKAGE_BUGREPORT "Georg Hopp <georg@steffers.org>" +00070 +00071 /* Define to the full name of this package. */ +00072 #define PACKAGE_NAME "cclass" +00073 +00074 /* Define to the full name and version of this package. */ +00075 #define PACKAGE_STRING "cclass 0.0.1" +00076 +00077 /* Define to the one symbol short name of this package. */ +00078 #define PACKAGE_TARNAME "cclass" +00079 +00080 /* Define to the home page for this package. */ +00081 #define PACKAGE_URL "" +00082 +00083 /* Define to the version of this package. */ +00084 #define PACKAGE_VERSION "0.0.1" +00085 +00086 /* Define to 1 if you have the ANSI C header files. */ +00087 #define STDC_HEADERS 1 +00088 +00089 /* Version number of package */ +00090 #define VERSION "0.0.1" +00091 +00092 /* Define to `__inline__' or `__inline' if that's what the C compiler +00093 calls it, or to nothing if 'inline' is not supported under any name. */ +00094 #ifndef __cplusplus +00095 /* #undef inline */ +00096 #endif +00097 +00098 /* Define to `int' if <sys/types.h> does not define. */ +00099 /* #undef pid_t */ +00100 +00101 /* Define to `unsigned int' if <sys/types.h> does not define. */ +00102 /* #undef size_t */ +
1.7.3
1.7.3
1.7.3
1.7.3 | config.h [code] | |||||
| include/class.h [code] | |||||
| include/interface.h [code] | |||||
| include/logger.h [code] | |||||
| include/server.h [code] | |||||
| include/signalHandling.h [code] | |||||
| include/socket.h [code] | |||||
| include/http/header.h [code] | |||||
| include/http/request.h [code] | |||||
| include/http/request_parser.h [code] | |||||
| include/http/request_queue.h [code] | |||||
| include/http/response.h [code] | |||||
| include/interface/class.h [code] | |||||
| include/interface/logger.h [code] | |||||
| include/interface/stream_reader.h [code] | |||||
| src/signalHandling.c [code] | |||||
| src/socket.c [code] | |||||
| src/testserver.c [code] | |||||
| src/http/header.c [code] | |||||
| src/http/request.c [code] | |||||
| src/http/request_parser.c [code] | |||||
| src/http/request_queue.c [code] | |||||
| src/http/header/get.c [code] | |||||
| src/http/header/sort.c [code] | |||||
| src/http/request/header_get.c [code] | |||||
| src/http/request/parser.c [code] | |||||
| src/http/request/queue.c [code] | |||||
| src/http/request/parser/get_header.c [code] | |||||
| src/http/request/parser/get_request_line.c [code] | |||||
| src/http/request/parser/parse.c [code] | |||||
| src/interface/class.c [code] | |||||
| src/interface/logger.c [code] | |||||
| src/interface/stream_reader.c [code] | |||||
|
+ server 0.0.1
+ basicserverinfrastructure
+ |
+
#include <stdlib.h>#include <ctype.h>#include "http/header.h"
Go to the source code of this file.
++Functions | |
| char * | httpHeaderGet (const HttpHeader header[], int nheader, const char *name) |
| char* httpHeaderGet | +( | +const HttpHeader | +header[], | +
| + | + | int | +nheader, | +
| + | + | const char * | +name | +
| + | ) | ++ |
Definition at line 31 of file get.c.
+{
+ unsigned long hash = sdbm((unsigned char *)name);
+ HttpHeader found;
+
+ found = bsearch(&hash, header, nheader, sizeof(HttpHeader), comp);
+
+ return (NULL != found)? found->value : NULL;
+}
+
|
+ server 0.0.1
+ basicserverinfrastructure
+ |
+
00001 #include <stdlib.h> +00002 #include <ctype.h> +00003 +00004 #include "http/header.h" +00005 +00006 static +00007 inline +00008 unsigned long +00009 sdbm(const unsigned char * str) +00010 { +00011 unsigned long hash = 0; +00012 int c; +00013 +00014 while ((c = tolower(*str++))) +00015 hash = c + (hash << 6) + (hash << 16) - hash; +00016 +00017 return hash; +00018 } +00019 +00020 static +00021 inline +00022 int +00023 comp (const void * _a, const void * _b) +00024 { +00025 unsigned long a = *(unsigned long *)_a; +00026 const HttpHeader b = *(const HttpHeader *)_b; +00027 return (a < b->hash)? -1 : (a > b->hash)? 1 : 0; +00028 } +00029 +00030 char * +00031 httpHeaderGet(const HttpHeader header[], int nheader, const char * name) +00032 { +00033 unsigned long hash = sdbm((unsigned char *)name); +00034 HttpHeader found; +00035 +00036 found = bsearch(&hash, header, nheader, sizeof(HttpHeader), comp); +00037 +00038 return (NULL != found)? found->value : NULL; +00039 } +00040 +00041 // vim: set ts=4 sw=4: +
|
+ server 0.0.1
+ basicserverinfrastructure
+ |
+
#include "class.h"#include "interface/class.h"#include "http/header.h"#include "http/request.h"
Go to the source code of this file.
++Functions | |
| void | httpRequestParserGetHeader (HttpRequest request, char *line) |
| void httpRequestParserGetHeader | +( | +HttpRequest | +request, | +
| + | + | char * | +line | +
| + | ) | ++ |
Definition at line 7 of file get_header.c.
+{
+ char * name = line;
+ char * value = strchr(line, ':');
+
+ *value = 0;
+ for (; *value == ' ' && *value != 0; value++);
+
+ (request->header)[request->nheader++] = new(HttpHeader, name, value);
+}
+
1.7.3 |
+ server 0.0.1
+ basicserverinfrastructure
+ |
+
00001 #include "class.h" +00002 #include "interface/class.h" +00003 #include "http/header.h" +00004 #include "http/request.h" +00005 +00006 void +00007 httpRequestParserGetHeader(HttpRequest request, char * line) +00008 { +00009 char * name = line; +00010 char * value = strchr(line, ':'); +00011 +00012 *value = 0; +00013 for (; *value == ' ' && *value != 0; value++); +00014 +00015 (request->header)[request->nheader++] = new(HttpHeader, name, value); +00016 } +00017 +00018 // vim: set ts=4 sw=4: +
1.7.3 |
+ server 0.0.1
+ basicserverinfrastructure
+ |
+
#include <string.h>#include "http/request.h"
Go to the source code of this file.
++Functions | |
| void | httpRequestParserGetRequestLine (HttpRequest request, char *line) |
| void httpRequestParserGetRequestLine | +( | +HttpRequest | +request, | +
| + | + | char * | +line | +
| + | ) | ++ |
Definition at line 7 of file get_request_line.c.
+{
+ char * method, * uri, * version;
+
+ method = line;
+
+ uri = strchr(line, ' ');
+ *uri++ = 0;
+ for (; *uri == ' ' && *uri != 0; uri++);
+
+ version = strchr(uri, ' ');
+ *version++ = 0;
+ for (; *version == ' ' && *version != 0; version++);
+
+ request->method = malloc(strlen(method) + 1);
+ strcpy(request->method, method);
+ request->uri = malloc(strlen(uri) + 1);
+ strcpy(request->uri, uri);
+ request->version = malloc(strlen(version) + 1);
+ strcpy(request->version, method);
+}
+
1.7.3 |
+ server 0.0.1
+ basicserverinfrastructure
+ |
+
00001 #include <string.h> +00002 +00003 #include "http/request.h" +00004 +00005 +00006 void +00007 httpRequestParserGetRequestLine(HttpRequest request, char * line) +00008 { +00009 char * method, * uri, * version; +00010 +00011 method = line; +00012 +00013 uri = strchr(line, ' '); +00014 *uri++ = 0; +00015 for (; *uri == ' ' && *uri != 0; uri++); +00016 +00017 version = strchr(uri, ' '); +00018 *version++ = 0; +00019 for (; *version == ' ' && *version != 0; version++); +00020 +00021 request->method = malloc(strlen(method) + 1); +00022 strcpy(request->method, method); +00023 request->uri = malloc(strlen(uri) + 1); +00024 strcpy(request->uri, uri); +00025 request->version = malloc(strlen(version) + 1); +00026 strcpy(request->version, method); +00027 } +00028 +00029 // vim: set ts=4 sw=4: +
1.7.3
1.7.3
1.7.3
1.7.3
1.7.3 |
+ server 0.0.1
+ basicserverinfrastructure
+ |
+
#include <stdlib.h>#include <string.h>#include <ctype.h>#include "class.h"#include "interface/class.h"#include "http/header.h"
Go to the source code of this file.
++Functions | |
| INIT_IFACE (Class, ctor, dtor, NULL) | |
| CREATE_CLASS (HttpHeader, NULL, IFACE(Class)) | |
| CREATE_CLASS | +( | +HttpHeader | +, | +
| + | + | NULL | +, | +
| + | + | IFACE(Class) | ++ |
| + | ) | ++ |
| INIT_IFACE | +( | +Class | +, | +
| + | + | ctor | +, | +
| + | + | dtor | +, | +
| + | + | NULL | ++ |
| + | ) | ++ |
|
+ server 0.0.1
+ basicserverinfrastructure
+ |
+
00001 #include <stdlib.h> +00002 #include <string.h> +00003 #include <ctype.h> +00004 +00005 #include "class.h" +00006 #include "interface/class.h" +00007 +00008 #include "http/header.h" +00009 +00023 static +00024 inline +00025 unsigned long +00026 sdbm(unsigned char * str) +00027 { +00028 unsigned long hash = 0; +00029 int c; +00030 +00031 while ((c = tolower(*str++))) +00032 hash = c + (hash << 6) + (hash << 16) - hash; +00033 +00034 return hash; +00035 } +00036 +00037 static +00038 void +00039 ctor(void * _this, va_list * params) { +00040 HttpHeader this = _this; +00041 char * name; +00042 char * value; +00043 +00044 name = va_arg(* params, char *); +00045 value = va_arg(* params, char *); +00046 +00047 this->name = malloc(strlen(name) + 1); +00048 strcpy(this->name, name); +00049 +00050 this->hash = sdbm((unsigned char *)name); +00051 +00052 this->value = malloc(strlen(value) + 1); +00053 strcpy(this->value, value); +00054 } +00055 +00056 static +00057 void +00058 dtor(void * _this) +00059 { +00060 HttpHeader this = _this; +00061 +00062 free(this->name); +00063 free(this->value); +00064 } +00065 +00066 INIT_IFACE(Class, ctor, dtor, NULL); +00067 CREATE_CLASS(HttpHeader, NULL, IFACE(Class)); +00068 +00069 // vim: set ts=4 sw=4: +
|
+ server 0.0.1
+ basicserverinfrastructure
+ |
+
#include "class.h"
Go to the source code of this file.
++Classes | |
| struct | HttpHeader |
+Functions | |
| HttpHeader | httpHeaderParse (char *line) |
| void | httpHeaderSort (const HttpHeader[], int) |
| char * | httpHeaderGet (const HttpHeader[], int, const char *) |
| char* httpHeaderGet | +( | +const HttpHeader | +[], | +
| + | + | int | +, | +
| + | + | const char * | ++ |
| + | ) | ++ |
Definition at line 31 of file get.c.
+{
+ unsigned long hash = sdbm((unsigned char *)name);
+ HttpHeader found;
+
+ found = bsearch(&hash, header, nheader, sizeof(HttpHeader), comp);
+
+ return (NULL != found)? found->value : NULL;
+}
+
| HttpHeader httpHeaderParse | +( | +char * | +line | ) | ++ |
| void httpHeaderSort | +( | +const HttpHeader | +[], | +
| + | + | int | ++ |
| + | ) | ++ |
Definition at line 14 of file sort.c.
+{
+ qsort(header, nheader, sizeof(HttpHeader), comp);
+}
+
|
+ server 0.0.1
+ basicserverinfrastructure
+ |
+
00001 #ifndef __HTTP_HEADER_H__ +00002 #define __HTTP_HEADER_H__ +00003 +00004 #include "class.h" +00005 +00006 CLASS(HttpHeader) { +00007 unsigned long hash; +00008 char * name; +00009 char * value; +00010 }; +00011 +00012 HttpHeader httpHeaderParse(char * line); // @INFO: destructive +00013 void httpHeaderSort(const HttpHeader [], int); +00014 char * httpHeaderGet(const HttpHeader [], int, const char *); +00015 +00016 #endif // __HTTP_HEADER_H__ +00017 +00018 // vim: set ts=4 sw=4: +
|
+ server 0.0.1
+ basicserverinfrastructure
+ |
+
#include <stdlib.h>#include <ctype.h>#include "http/request.h"
Go to the source code of this file.
++Functions | |
| char * | httpRequestHeaderGet (HttpRequest this, const char *name) |
| char* httpRequestHeaderGet | +( | +HttpRequest | +this, | +
| + | + | const char * | +name | +
| + | ) | ++ |
Definition at line 31 of file header_get.c.
+{
+ unsigned long hash = sdbm((unsigned char *)name);
+ struct HttpRequestHeader * header;
+
+ header = bsearch(
+ &hash,
+ this->header,
+ this->nheader,
+ sizeof(struct HttpRequestHeader),
+ comp);
+
+ return (NULL != header)? header->value : NULL;
+}
+
1.7.3 |
+ server 0.0.1
+ basicserverinfrastructure
+ |
+
00001 #include <stdlib.h> +00002 #include <ctype.h> +00003 +00004 #include "http/request.h" +00005 +00006 static +00007 inline +00008 unsigned long +00009 sdbm(const unsigned char * str) +00010 { +00011 unsigned long hash = 0; +00012 int c; +00013 +00014 while ((c = tolower(*str++))) +00015 hash = c + (hash << 6) + (hash << 16) - hash; +00016 +00017 return hash; +00018 } +00019 +00020 static +00021 inline +00022 int +00023 comp (const void * _a, const void * _b) +00024 { +00025 unsigned long a = *(unsigned long *)_a; +00026 const struct HttpRequestHeader * b = _b; +00027 return (a < b->hash)? -1 : (a > b->hash)? 1 : 0; +00028 } +00029 +00030 char * +00031 httpRequestHeaderGet(HttpRequest this, const char * name) +00032 { +00033 unsigned long hash = sdbm((unsigned char *)name); +00034 struct HttpRequestHeader * header; +00035 +00036 header = bsearch( +00037 &hash, +00038 this->header, +00039 this->nheader, +00040 sizeof(struct HttpRequestHeader), +00041 comp); +00042 +00043 return (NULL != header)? header->value : NULL; +00044 } +00045 +00046 // vim: set ts=4 sw=4: +
1.7.3
1.7.3
1.7.3
1.7.3
1.7.3 #include <stdlib.h>#include <stdio.h>#include <stdarg.h>#include "logger.h"#include "interface/logger.h"
Definition at line 13 of file logger.c.
+Definition at line 14 of file logger.c.
{
Logger object = _object;
@@ -178,7 +181,7 @@ Here is the caller graph for this function:
1.7.3 00001 #include <stdlib.h> -00002 #include <stdarg.h> -00003 -00004 #include "logger.h" -00005 #include "interface/logger.h" -00006 -00007 const struct interface i_Logger = { -00008 "logger", -00009 1 -00010 }; -00011 -00012 void -00013 loggerLog(void * _object, logger_level level, const char * const fmt, ...) { -00014 Logger object = _object; -00015 -00016 if (level >= object->min_level) { -00017 char * msg = NULL; -00018 size_t msg_size = 0; -00019 va_list params; -00020 -00021 va_start(params, fmt); -00022 msg_size = vsnprintf(msg, msg_size, fmt, params); -00023 va_end(params); -00024 -00025 msg = malloc(msg_size + 1); -00026 -00027 va_start(params, fmt); -00028 vsnprintf(msg, msg_size + 1, fmt, params); -00029 va_end(params); -00030 -00031 CALL(_object, Logger, log, level, msg); -00032 -00033 free(msg); -00034 } -00035 } -00036 -00037 // vim: set ts=4 sw=4: +00002 #include <stdio.h> +00003 #include <stdarg.h> +00004 +00005 #include "logger.h" +00006 #include "interface/logger.h" +00007 +00008 const struct interface i_Logger = { +00009 "logger", +00010 1 +00011 }; +00012 +00013 void +00014 loggerLog(void * _object, logger_level level, const char * const fmt, ...) { +00015 Logger object = _object; +00016 +00017 if (level >= object->min_level) { +00018 char * msg = NULL; +00019 size_t msg_size = 0; +00020 va_list params; +00021 +00022 va_start(params, fmt); +00023 msg_size = vsnprintf(msg, msg_size, fmt, params); +00024 va_end(params); +00025 +00026 msg = malloc(msg_size + 1); +00027 +00028 va_start(params, fmt); +00029 vsnprintf(msg, msg_size + 1, fmt, params); +00030 va_end(params); +00031 +00032 CALL(_object, Logger, log, level, msg); +00033 +00034 free(msg); +00035 } +00036 } +00037 +00038 // vim: set ts=4 sw=4:
1.7.3 Definition at line 13 of file logger.c.
+Definition at line 14 of file logger.c.
{
Logger object = _object;
@@ -206,7 +206,7 @@ Here is the caller graph for this function:
1.7.3
1.7.3
1.7.3
1.7.3
1.7.3
1.7.3
1.7.3
1.7.3
1.7.3
1.7.3
1.7.3
1.7.3 |
+ server 0.0.1
+ basicserverinfrastructure
+ |
+
#include <stdlib.h>#include <string.h>#include <unistd.h>#include <ctype.h>#include "http/request_parser.h"#include "interface/class.h"
Go to the source code of this file.
++Defines | |
| #define | REMAINS(pars, done) ((pars)->buffer_used - ((done) - (pars)->buffer)) |
+Functions | |
| void | httpRequestParserGetRequestLine (HttpRequest, char *) |
| void | httpRequestParserParse (HttpRequestParser this) |
| #define REMAINS | +( | ++ | pars, | +
| + | + | + | done | +
| + | ) | +((pars)->buffer_used - ((done) - (pars)->buffer)) | +
| void httpRequestParserGetRequestLine | +( | +HttpRequest | +, | +
| + | + | char * | ++ |
| + | ) | ++ |
Definition at line 7 of file get_request_line.c.
+{
+ char * method, * uri, * version;
+
+ method = line;
+
+ uri = strchr(line, ' ');
+ *uri++ = 0;
+ for (; *uri == ' ' && *uri != 0; uri++);
+
+ version = strchr(uri, ' ');
+ *version++ = 0;
+ for (; *version == ' ' && *version != 0; version++);
+
+ request->method = malloc(strlen(method) + 1);
+ strcpy(request->method, method);
+ request->uri = malloc(strlen(uri) + 1);
+ strcpy(request->uri, uri);
+ request->version = malloc(strlen(version) + 1);
+ strcpy(request->version, method);
+}
+
| void httpRequestParserParse | +( | +HttpRequestParser | +this | ) | ++ |
enqueue current request
+remove processed stuff from input buffer.
+dont continue loop if input buffer is empty
+prepare for next request
+ + +Definition at line 43 of file parse.c.
+{
+ static HttpRequest request = NULL;
+ static char * data; // static pointer to unprocessed data
+ char * line;
+ int cont = 1;
+
+ while(cont) {
+ switch(this->state) {
+ case HTTP_REQUEST_GARBAGE:
+ data = this->buffer; // initialize static pointer
+ httpRequestSkip(&data);
+ request = new(HttpRequest);
+
+ this->state = HTTP_REQUEST_START;
+ break;
+
+ case HTTP_REQUEST_START:
+ if (NULL == (line = httpRequestParserGetLine(&data))) {
+ cont = 0;
+ break;
+ }
+
+ httpRequestParserGetRequestLine(request, line);
+
+ this->state = HTTP_REQUEST_REQUEST_LINE_DONE;
+ break;
+
+ case HTTP_REQUEST_REQUEST_LINE_DONE:
+ if (NULL == (line = httpRequestParserGetLine(&data))) {
+ cont = 0;
+ break;
+ }
+
+ if (0 == strlen(line)) {
+ this->state = HTTP_REQUEST_HEADERS_DONE;
+ break;
+ }
+
+ httpRequestParserGetHeader(request, line);
+ break;
+
+ case HTTP_REQUEST_HEADERS_DONE:
+ httpHeaderSort(request->header, request->nheader);
+
+ {
+ char * nbody;
+
+ if (0 == request->nbody) {
+ nbody = httpHeaderGet(
+ request->header,
+ request->nheader,
+ "Content-Length");
+
+ if (NULL == nbody) {
+ this->state = HTTP_REQUEST_DONE;
+ break;
+ }
+ else {
+ request->nbody = atoi(nbody);
+ }
+ }
+
+ if (REMAINS(this, data) >= request->nbody) {
+ request->body = calloc(1, request->nbody + 1);
+ memcpy(request->body, data, request->nbody);
+ data += request->nbody;
+ this->state = HTTP_REQUEST_DONE;
+ }
+ }
+
+ break;
+
+ case HTTP_REQUEST_DONE:
+ this->request_queue->requests[(this->request_queue->nrequests)++] =
+ request;
+
+ memmove(this->buffer, data, REMAINS(this, data));
+
+ this->buffer_used -= data - this->buffer;
+
+ if (0 == this->buffer_used) {
+ cont = 0;
+ }
+
+ this->state = HTTP_REQUEST_GARBAGE;
+
+ break;
+
+ default:
+ break;
+ }
+ }
+}
+
|
+ server 0.0.1
+ basicserverinfrastructure
+ |
+
00001 #include <stdlib.h> +00002 #include <string.h> +00003 #include <unistd.h> +00004 #include <ctype.h> +00005 +00006 #include "http/request_parser.h" +00007 #include "interface/class.h" +00008 +00009 +00010 #define REMAINS(pars,done) \ +00011 ((pars)->buffer_used - ((done) - (pars)->buffer)) +00012 +00013 +00014 static +00015 inline +00016 char * +00017 httpRequestParserGetLine(char ** data) +00018 { +00019 char * line_end = strstr(*data, "\r\n"); +00020 char * ret = *data; +00021 +00022 if (NULL == line_end) { +00023 return NULL; +00024 } +00025 +00026 *line_end = 0; +00027 *data = line_end + 2; +00028 +00029 return ret; +00030 } +00031 +00032 static +00033 inline +00034 void +00035 httpRequestSkip(char ** data) +00036 { +00037 for (; 0 != **data && ! isalpha(**data); (*data)++); +00038 } +00039 +00040 void httpRequestParserGetRequestLine(HttpRequest, char *); +00041 +00042 void +00043 httpRequestParserParse(HttpRequestParser this) +00044 { +00045 static HttpRequest request = NULL; +00046 static char * data; // static pointer to unprocessed data +00047 char * line; +00048 int cont = 1; +00049 +00050 while(cont) { +00051 switch(this->state) { +00052 case HTTP_REQUEST_GARBAGE: +00053 data = this->buffer; // initialize static pointer +00054 httpRequestSkip(&data); +00055 request = new(HttpRequest); +00056 +00057 this->state = HTTP_REQUEST_START; +00058 break; +00059 +00060 case HTTP_REQUEST_START: +00061 if (NULL == (line = httpRequestParserGetLine(&data))) { +00062 cont = 0; +00063 break; +00064 } +00065 +00066 httpRequestParserGetRequestLine(request, line); +00067 +00068 this->state = HTTP_REQUEST_REQUEST_LINE_DONE; +00069 break; +00070 +00071 case HTTP_REQUEST_REQUEST_LINE_DONE: +00072 if (NULL == (line = httpRequestParserGetLine(&data))) { +00073 cont = 0; +00074 break; +00075 } +00076 +00077 if (0 == strlen(line)) { +00078 this->state = HTTP_REQUEST_HEADERS_DONE; +00079 break; +00080 } +00081 +00082 httpRequestParserGetHeader(request, line); +00083 break; +00084 +00085 case HTTP_REQUEST_HEADERS_DONE: +00086 httpHeaderSort(request->header, request->nheader); +00087 +00088 { +00089 char * nbody; +00090 +00091 if (0 == request->nbody) { +00092 nbody = httpHeaderGet( +00093 request->header, +00094 request->nheader, +00095 "Content-Length"); +00096 +00097 if (NULL == nbody) { +00098 this->state = HTTP_REQUEST_DONE; +00099 break; +00100 } +00101 else { +00102 request->nbody = atoi(nbody); +00103 } +00104 } +00105 +00106 if (REMAINS(this, data) >= request->nbody) { +00107 request->body = calloc(1, request->nbody + 1); +00108 memcpy(request->body, data, request->nbody); +00109 data += request->nbody; +00110 this->state = HTTP_REQUEST_DONE; +00111 } +00112 } +00113 +00114 break; +00115 +00116 case HTTP_REQUEST_DONE: +00120 this->request_queue->requests[(this->request_queue->nrequests)++] = +00121 request; +00122 +00126 memmove(this->buffer, data, REMAINS(this, data)); +00127 +00128 this->buffer_used -= data - this->buffer; +00129 +00133 if (0 == this->buffer_used) { +00134 cont = 0; +00135 } +00136 +00140 this->state = HTTP_REQUEST_GARBAGE; +00141 +00142 break; +00143 +00144 default: +00145 break; +00146 } +00147 } +00148 } +00149 +00150 // vim: set ts=4 sw=4: +
|
+ server 0.0.1
+ basicserverinfrastructure
+ |
+
#include <string.h>#include <stdlib.h>#include <sys/types.h>#include "class.h"#include "http/request_parser.h"#include "interface/class.h"#include "interface/stream_reader.h"#include "http/request.h"#include "http/request_queue.h"
Go to the source code of this file.
++Functions | |
| void | httpRequestParserParse (HttpRequestParser) |
| INIT_IFACE (Class, ctor, dtor, _clone) | |
| INIT_IFACE (StreamReader, get_data) | |
| CREATE_CLASS (HttpRequestParser, NULL, IFACE(Class), IFACE(StreamReader)) | |
| CREATE_CLASS | +( | +HttpRequestParser | +, | +
| + | + | NULL | +, | +
| + | + | IFACE(Class) | +, | +
| + | + | IFACE(StreamReader) | ++ |
| + | ) | ++ |
| void httpRequestParserParse | +( | +HttpRequestParser | +) | ++ |
enqueue current request
+remove processed stuff from input buffer.
+dont continue loop if input buffer is empty
+prepare for next request
+ + +Definition at line 43 of file parse.c.
+{
+ static HttpRequest request = NULL;
+ static char * data; // static pointer to unprocessed data
+ char * line;
+ int cont = 1;
+
+ while(cont) {
+ switch(this->state) {
+ case HTTP_REQUEST_GARBAGE:
+ data = this->buffer; // initialize static pointer
+ httpRequestSkip(&data);
+ request = new(HttpRequest);
+
+ this->state = HTTP_REQUEST_START;
+ break;
+
+ case HTTP_REQUEST_START:
+ if (NULL == (line = httpRequestParserGetLine(&data))) {
+ cont = 0;
+ break;
+ }
+
+ httpRequestParserGetRequestLine(request, line);
+
+ this->state = HTTP_REQUEST_REQUEST_LINE_DONE;
+ break;
+
+ case HTTP_REQUEST_REQUEST_LINE_DONE:
+ if (NULL == (line = httpRequestParserGetLine(&data))) {
+ cont = 0;
+ break;
+ }
+
+ if (0 == strlen(line)) {
+ this->state = HTTP_REQUEST_HEADERS_DONE;
+ break;
+ }
+
+ httpRequestParserGetHeader(request, line);
+ break;
+
+ case HTTP_REQUEST_HEADERS_DONE:
+ httpHeaderSort(request->header, request->nheader);
+
+ {
+ char * nbody;
+
+ if (0 == request->nbody) {
+ nbody = httpHeaderGet(
+ request->header,
+ request->nheader,
+ "Content-Length");
+
+ if (NULL == nbody) {
+ this->state = HTTP_REQUEST_DONE;
+ break;
+ }
+ else {
+ request->nbody = atoi(nbody);
+ }
+ }
+
+ if (REMAINS(this, data) >= request->nbody) {
+ request->body = calloc(1, request->nbody + 1);
+ memcpy(request->body, data, request->nbody);
+ data += request->nbody;
+ this->state = HTTP_REQUEST_DONE;
+ }
+ }
+
+ break;
+
+ case HTTP_REQUEST_DONE:
+ this->request_queue->requests[(this->request_queue->nrequests)++] =
+ request;
+
+ memmove(this->buffer, data, REMAINS(this, data));
+
+ this->buffer_used -= data - this->buffer;
+
+ if (0 == this->buffer_used) {
+ cont = 0;
+ }
+
+ this->state = HTTP_REQUEST_GARBAGE;
+
+ break;
+
+ default:
+ break;
+ }
+ }
+}
+
| INIT_IFACE | +( | +Class | +, | +
| + | + | ctor | +, | +
| + | + | dtor | +, | +
| + | + | _clone | ++ |
| + | ) | ++ |
| INIT_IFACE | +( | +StreamReader | +, | +
| + | + | get_data | ++ |
| + | ) | ++ |
|
+ server 0.0.1
+ basicserverinfrastructure
+ |
+
00001 #include <string.h> +00002 #include <stdlib.h> +00003 #include <sys/types.h> +00004 +00005 #include "class.h" +00006 #include "http/request_parser.h" +00007 #include "interface/class.h" +00008 #include "interface/stream_reader.h" +00009 #include "http/request.h" +00010 #include "http/request_queue.h" +00011 +00012 void httpRequestParserParse(HttpRequestParser); +00013 +00014 static +00015 void +00016 ctor(void * _this, va_list * params) +00017 { +00018 HttpRequestParser this = _this; +00019 +00020 this->request_queue = new(HttpRequestQueue); +00021 +00022 this->buffer = malloc(HTTP_REQUEST_PARSER_READ_CHUNK); +00023 this->buffer[0] = 0; +00024 } +00025 +00026 static +00027 void +00028 dtor(void * _this) +00029 { +00030 HttpRequestParser this = _this; +00031 +00032 free(this->buffer); +00033 delete(&(this->request_queue)); +00034 } +00035 +00036 static +00037 void +00038 _clone(void * _this, void * _base) +00039 { +00040 HttpRequestParser this = _this; +00041 HttpRequestParser base = _base; +00042 size_t chunks; +00043 +00047 this->request_queue = new(HttpRequestQueue); +00048 this->buffer_used = base->buffer_used; +00049 +00050 chunks = this->buffer_used / HTTP_REQUEST_PARSER_READ_CHUNK; +00051 chunks++; +00052 +00053 this->buffer = malloc(chunks * HTTP_REQUEST_PARSER_READ_CHUNK); +00054 memcpy(this->buffer, base->buffer, this->buffer_used); +00055 } +00056 +00057 static +00058 size_t +00059 get_data(void * _this, int fd) +00060 { +00061 HttpRequestParser this = _this; +00062 size_t remaining, chunks; +00063 char buffer[1024]; +00064 +00065 size_t size = read(fd, buffer, 1024); +00066 +00067 if (0 < size) { +00068 remaining = this->buffer_used % HTTP_REQUEST_PARSER_READ_CHUNK; +00069 chunks = this->buffer_used / HTTP_REQUEST_PARSER_READ_CHUNK; +00070 +00079 chunks++; +00080 +00081 if (size >= remaining) { +00082 this->buffer = +00083 realloc(this->buffer, chunks * HTTP_REQUEST_PARSER_READ_CHUNK); +00084 } +00085 +00086 memcpy(this->buffer + this->buffer_used, buffer, size); +00087 this->buffer_used += size; +00088 this->buffer[this->buffer_used] = 0; +00089 +00090 httpRequestParserParse(this); +00091 } +00092 +00093 return size; +00094 } +00095 +00096 INIT_IFACE(Class, ctor, dtor, _clone); +00097 INIT_IFACE(StreamReader, get_data); +00098 CREATE_CLASS(HttpRequestParser, NULL, IFACE(Class), IFACE(StreamReader)); +00099 +00100 // vim: set ts=4 sw=4: +
1.7.3
1.7.3 |
+ server 0.0.1
+ basicserverinfrastructure
+ |
+
#include <stdarg.h>#include "class.h"#include "interface/class.h"#include "http/request_queue.h"
Go to the source code of this file.
++Functions | |
| INIT_IFACE (Class, ctor, dtor, NULL) | |
| CREATE_CLASS (HttpRequestQueue, NULL, IFACE(Class)) | |
| CREATE_CLASS | +( | +HttpRequestQueue | +, | +
| + | + | NULL | +, | +
| + | + | IFACE(Class) | ++ |
| + | ) | ++ |
| INIT_IFACE | +( | +Class | +, | +
| + | + | ctor | +, | +
| + | + | dtor | +, | +
| + | + | NULL | ++ |
| + | ) | ++ |
|
+ server 0.0.1
+ basicserverinfrastructure
+ |
+
00001 #include <stdarg.h> +00002 +00003 #include "class.h" +00004 #include "interface/class.h" +00005 +00006 #include "http/request_queue.h" +00007 +00008 static +00009 void +00010 ctor(void * _this, va_list * params) {} +00011 +00012 static +00013 void +00014 dtor(void * _this) +00015 { +00016 HttpRequestQueue this = _this; +00017 int i; +00018 +00019 for (i=0; i<this->nrequests; i++) { +00020 delete(&(this->requests)[i]); +00021 } +00022 } +00023 +00024 INIT_IFACE(Class, ctor, dtor, NULL); +00025 CREATE_CLASS(HttpRequestQueue, NULL, IFACE(Class)); +00026 +00027 // vim: set ts=4 sw=4: +
1.7.3
1.7.3
1.7.3
1.7.3 #include "class.h"#include "http/header.h"
| char* httpRequestHeaderGet | +( | +HttpRequest | +this, | +
| + | + | const char * | +name | +
| + | ) | ++ |
Definition at line 31 of file header_get.c.
+{
+ unsigned long hash = sdbm((unsigned char *)name);
+ struct HttpRequestHeader * header;
+
+ header = bsearch(
+ &hash,
+ this->header,
+ this->nheader,
+ sizeof(struct HttpRequestHeader),
+ comp);
+
+ return (NULL != header)? header->value : NULL;
+}
+
1.7.3
1.7.3
1.7.3
1.7.3
1.7.3
1.7.3 |
+ server 0.0.1
+ basicserverinfrastructure
+ |
+
#include "class.h"
Go to the source code of this file.
++Classes | |
| struct | HttpResponse |
+Functions | |
| char * | httpRequestHeaderGet (HttpRequest this, const char *name) |
| char* httpRequestHeaderGet | +( | +HttpRequest | +this, | +
| + | + | const char * | +name | +
| + | ) | ++ |
Definition at line 31 of file header_get.c.
+{
+ unsigned long hash = sdbm((unsigned char *)name);
+ struct HttpRequestHeader * header;
+
+ header = bsearch(
+ &hash,
+ this->header,
+ this->nheader,
+ sizeof(struct HttpRequestHeader),
+ comp);
+
+ return (NULL != header)? header->value : NULL;
+}
+
1.7.3 |
+ server 0.0.1
+ basicserverinfrastructure
+ |
+
00001 #ifndef __HTTP_RESPONSE_H__ +00002 #define __HTTP_RESPONSE_H__ +00003 +00004 #include "class.h" +00005 +00006 CLASS(HttpResponse) { +00007 char * http_version; +00008 char * status; +00009 char * reson; +00010 +00011 HttpHeader header[128]; +00012 int nheader; +00013 +00014 char * body; +00015 int nbody; +00016 }; +00017 +00018 char * +00019 httpRequestHeaderGet(HttpRequest this, const char * name); +00020 +00021 #endif /* __HTTP_RESPONSE_H__ */ +00022 +00023 // vim: set ts=4 sw=4: +
1.7.3
1.7.3
1.7.3