[commit] r10227 - in freeswitch/trunk/src: . include
Author: anthm Date: Mon Nov 3 15:08:44 2008 New Revision: 10227 Modified: freeswitch/trunk/src/include/switch_apr.h freeswitch/trunk/src/include/switch_event.h freeswitch/trunk/src/include/switch_utils.h freeswitch/trunk/src/switch_apr.c freeswitch/trunk/src/switch_event.c Log: add hashing to event header lookup Modified: freeswitch/trunk/src/include/switch_apr.h ============================================================================== --- freeswitch/trunk/src/include/switch_apr.h (original) +++ freeswitch/trunk/src/include/switch_apr.h Mon Nov 3 15:08:44 2008 @@ -202,6 +202,8 @@ */ SWITCH_DECLARE(unsigned int) switch_hashfunc_default(const char *key, switch_ssize_t *klen); +SWITCH_DECLARE(unsigned int) switch_ci_hashfunc_default(const char *char_key, switch_ssize_t *klen); + /** * @defgroup switch_time Time Routines Modified: freeswitch/trunk/src/include/switch_event.h ============================================================================== --- freeswitch/trunk/src/include/switch_event.h (original) +++ freeswitch/trunk/src/include/switch_event.h Mon Nov 3 15:08:44 2008 @@ -67,6 +67,8 @@ char *name; /*! the header value */ char *value; + /*! hash of the header name */ + unsigned long hash; struct switch_event_header *next; }; Modified: freeswitch/trunk/src/include/switch_utils.h ============================================================================== --- freeswitch/trunk/src/include/switch_utils.h (original) +++ freeswitch/trunk/src/include/switch_utils.h Mon Nov 3 15:08:44 2008 @@ -295,6 +295,40 @@ } +static inline char *switch_lc_strdup(const char *it) +{ + char *dup; + char *p; + + if (it) { + dup = strdup(it); + for(p = dup; p && *p; p++) { + *p = tolower(*p); + } + return dup; + } + + return NULL; +} + + +static inline char *switch_uc_strdup(const char *it) +{ + char *dup; + char *p; + + if (it) { + dup = strdup(it); + for(p = dup; p && *p; p++) { + *p = toupper(*p); + } + return dup; + } + + return NULL; +} + + /*! \brief Test if one string is inside another with extra case checking \param s the inner string Modified: freeswitch/trunk/src/switch_apr.c ============================================================================== --- freeswitch/trunk/src/switch_apr.c (original) +++ freeswitch/trunk/src/switch_apr.c Mon Nov 3 15:08:44 2008 @@ -74,6 +74,30 @@ apr_pool_clear(p); } +SWITCH_DECLARE(unsigned int) switch_ci_hashfunc_default(const char *char_key, switch_ssize_t *klen) + +{ + unsigned int hash = 0; + const unsigned char *key = (const unsigned char *)char_key; + const unsigned char *p; + apr_ssize_t i; + + if (*klen == APR_HASH_KEY_STRING) { + for (p = key; *p; p++) { + hash = hash * 33 + tolower(*p); + } + *klen = p - key; + } + else { + for (p = key, i = *klen; i; i--, p++) { + hash = hash * 33 + tolower(*p); + } + } + + return hash; +} + + SWITCH_DECLARE(unsigned int) switch_hashfunc_default(const char *key, switch_ssize_t *klen) { return apr_hashfunc_default(key, klen); Modified: freeswitch/trunk/src/switch_event.c ============================================================================== --- freeswitch/trunk/src/switch_event.c (original) +++ freeswitch/trunk/src/switch_event.c Mon Nov 3 15:08:44 2008 @@ -586,12 +586,17 @@ SWITCH_DECLARE(char *) switch_event_get_header(switch_event_t *event, const char *header_name) { switch_event_header_t *hp; + switch_ssize_t hlen = -1; + unsigned long hash = 0; + switch_assert(event); - if (!header_name) - return NULL; + if (!header_name) return NULL; + + hash = switch_ci_hashfunc_default(header_name, &hlen); + for (hp = event->headers; hp; hp = hp->next) { - if (!strcasecmp(hp->name, header_name)) { + if ((!hp->hash || hash == hp->hash) && !strcasecmp(hp->name, header_name) ) { return hp->value; } } @@ -608,6 +613,9 @@ switch_event_header_t *hp, *lp = NULL, *tp; switch_status_t status = SWITCH_STATUS_FALSE; int x = 0; + switch_ssize_t hlen = -1; + unsigned long hash = 0; + tp = event->headers; while (tp) { hp = tp; @@ -615,7 +623,9 @@ x++; switch_assert(x < 1000); - if (!strcasecmp(header_name, hp->name)) { + hash = switch_ci_hashfunc_default(header_name, &hlen); + + if ((!hp->hash || hash == hp->hash) && !strcasecmp(header_name, hp->name)) { if (lp) { lp->next = hp->next; } else { @@ -642,6 +652,7 @@ switch_status_t switch_event_base_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, char *data) { switch_event_header_t *header; + switch_ssize_t hlen = -1; void *pop; if (switch_queue_trypop(EVENT_HEADER_RECYCLE_QUEUE, &pop) == SWITCH_STATUS_SUCCESS) { @@ -655,7 +666,8 @@ header->name = DUP(header_name); header->value = data; - + header->hash = switch_ci_hashfunc_default(header->name, &hlen); + if (stack == SWITCH_STACK_TOP) { header->next = event->headers; event->headers = header;
participants (1)
-
Freeswitch SVN