server 0.0.1
basicserverinfrastructure

src/http/request/header_get.c

Go to the documentation of this file.
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:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines