server 0.0.1
basicserverinfrastructure

src/http/header/get.c

Go to the documentation of this file.
00001 #include <stdlib.h>
00002 #include <ctype.h>
00003 
00004 #include "http/header.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 HttpHeader b = *(const HttpHeader *)_b;
00027         return (a < b->hash)? -1 : (a > b->hash)? 1 : 0;
00028 }
00029 
00030 char *
00031 httpHeaderGet(const HttpHeader header[], int nheader, const char * name)
00032 {
00033         unsigned long hash = sdbm((unsigned char *)name);
00034         HttpHeader    found;
00035 
00036         found = bsearch(&hash, header, nheader, sizeof(HttpHeader), comp);
00037 
00038         return (NULL != found)? found->value : NULL;
00039 }
00040 
00041 // vim: set ts=4 sw=4:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines