|
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: