Server 0.0.1
HTTP/REST server implementation

src/http/header.c

Go to the documentation of this file.
00001 
00024 #include <stdlib.h>
00025 #include <string.h>
00026 
00027 #include "class.h"
00028 #include "hash.h"
00029 #include "http/header.h"
00030 
00031 #include "utils/hash.h"
00032 #include "utils/memory.h"
00033 
00034 static
00035 int
00036 httpHeaderCtor(void * _this, va_list * params) {
00037         HttpHeader this = _this;
00038         char * name;
00039         char * value;
00040 
00041         name            = va_arg(* params, char *);
00042         this->nname     = va_arg(* params, size_t);
00043         value           = va_arg(* params, char *);
00044         this->nvalue[0] = va_arg(* params, size_t);
00045         
00046         this->name              = malloc(this->nname + 1);
00047         this->name[this->nname] = 0;
00048         memcpy(this->name, name, this->nname);
00049 
00050         this->hash = sdbm((unsigned char *)name, this->nname);
00051 
00052         (this->value)[0]                    = malloc((this->nvalue)[0] + 1);
00053         (this->value)[0][(this->nvalue)[0]] = 0;
00054         memcpy((this->value)[0], value, (this->nvalue)[0]);
00055         this->cvalue = 1;
00056         this->size   = this->nname + 2 + (this->nvalue)[0] + 2;
00057 
00058         return 0;
00059 }
00060 
00061 static
00062 void
00063 httpHeaderDtor(void * _this)
00064 {
00065         HttpHeader this = _this;
00066         size_t     i;
00067 
00068         FREE(this->name);
00069 
00070         for (i=0; i<this->cvalue; i++) {
00071                 FREE(this->value[i]);
00072         }
00073 }
00074 
00075 static
00076 unsigned long
00077 httpHeaderGetHash(void * _this)
00078 {
00079         HttpHeader this = _this;
00080 
00081         return this->hash;
00082 }
00083 
00084 static
00085 void
00086 httpHeaderHandleDouble(void * _this, void * _double)
00087 {
00088         HttpHeader this = _this;
00089         HttpHeader doub = _double;
00090 
00091         if (this->cvalue >= N_VALUES) {
00093                 return;
00094         }
00095 
00096         (this->nvalue)[this->cvalue]    = (doub->nvalue)[0];
00097         (this->value)[(this->cvalue)++] = (doub->value)[0];
00098         this->size += doub->size;
00099         (doub->value)[0] = NULL;
00100 }
00101 
00102 INIT_IFACE(Class, httpHeaderCtor, httpHeaderDtor, NULL);
00103 INIT_IFACE(Hashable, httpHeaderGetHash, httpHeaderHandleDouble);
00104 CREATE_CLASS(HttpHeader, NULL, IFACE(Class), IFACE(Hashable));
00105 
00106 // vim: set ts=4 sw=4:
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines