|
Server 0.0.1
HTTP/REST server implementation
|
00001 00023 #include <stdlib.h> 00024 #include <string.h> 00025 #include <stdarg.h> 00026 #include <sys/types.h> 00027 00028 #include "class.h" 00029 #include "hash.h" 00030 #include "http/cookie.h" 00031 00032 #include "utils/hash.h" 00033 #include "utils/memory.h" 00034 #include "commons.h" 00035 00036 00037 static 00038 int 00039 httpCookieCtor(void * _this, va_list * params) 00040 { 00041 HttpCookie this = _this; 00042 char * key = va_arg(* params, char*); 00043 char * value; 00044 00045 this->nkey = va_arg(* params, size_t); 00046 value = va_arg(* params, char*); 00047 this->nvalue = va_arg(* params, size_t); 00048 00049 this->key = malloc(this->nkey + 1); 00050 this->key[this->nkey] = 0; 00051 memcpy(this->key, key, this->nkey); 00052 00053 this->value = malloc(this->nvalue + 1); 00054 this->value[this->nvalue] = 0; 00055 memcpy(this->value, value, this->nvalue); 00056 00057 this->hash = sdbm((unsigned char *)key, nkey); 00058 00059 return 0; 00060 } 00061 00062 static 00063 void 00064 httpCookieDtor(void * _this, va_list * params) 00065 { 00066 HttpCookie this = _this; 00067 00068 FREE(this->key); 00069 FREE(this->value); 00070 FREE(this->domain); 00071 FREE(this->path); 00072 } 00073 00074 static 00075 unsigned long 00076 httpCookieGetHash(void * _this) 00077 { 00078 HttpCookie this = _this; 00079 00080 return this->hash; 00081 } 00082 00083 static 00084 void 00085 httpCookieHandleDouble(void * _this, void * _double) 00086 { 00087 HttpCookie this = _this; 00088 HttpCookie doub = _double; 00089 00090 SWAP(char*, this->key, doub->key); 00091 SWAP(char*, this->value, doub->value); 00092 SWAP(char*, this->domain, doub->domain); 00093 SWAP(char*, this->path, doub->path); 00094 00095 SWAP(char*, this->nkey, doub->nkey); 00096 SWAP(char*, this->nvalue, doub->nvalue); 00097 } 00098 00099 00100 INIT_IFACE(Class, httpCookieCtor, httpCookieDtor, NULL); 00101 INIT_IFACE(Hashable, httpCookieGetHash, httpCookieHandleDouble); 00102 CREATE_CLASS(HttpCookie, NULL, IFACE(Class), IFACE(Hashable)); 00103 00104 // vim: set ts=4 sw=4: