|
Server 0.0.1
HTTP/REST server implementation
|
00001 00023 #include <stdlib.h> 00024 #include <sys/types.h> 00025 #include <string.h> 00026 00027 #include "http/message.h" 00028 #include "http/request.h" 00029 #include "http/response.h" 00030 00031 #include "class.h" 00032 00033 #include "commons.h" 00034 00035 char 00036 isHttpVersion(const char * str, size_t len) 00037 { 00038 if (NULL == str) 00039 return FALSE; 00040 00041 if (8 > len) 00042 return FALSE; 00043 00044 if (0 != memcmp("HTTP/", str, sizeof("HTTP/")-1)) 00045 return FALSE; 00046 00047 return TRUE; 00048 } 00049 00050 HttpMessage 00051 httpGetMessage( 00052 const char * part1, size_t len1, 00053 const char * part2, size_t len2, 00054 const char * part3, size_t len3) 00055 { 00056 if (isHttpVersion(part1, len1)) { 00057 return new(HttpResponse, 00058 part1, len1, 00059 strtoul(part2, NULL, 10), 00060 part3, len3); 00061 } 00062 00063 if (isHttpVersion(part3, len3)) { 00064 return new(HttpRequest, 00065 part1, len1, 00066 part2, len2, 00067 part3, len3); 00068 } 00069 00070 return NULL; 00071 } 00072 00073 // vim: set ts=4 sw=4: