Ignore:
Timestamp:
Jul 18, 2012 7:52:33 AM (12 years ago)
Author:
ming
Message:

Fixed #1556: Fix From/To? tag and Via branch comparison to be case insensitive

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/src/pj/hash.c

    r3553 r4208  
    8080    for (i=0; i<key->slen; ++i) { 
    8181        pj_uint8_t c = key->ptr[i]; 
     82        char lower; 
    8283        if (c & 64) 
    83             result[i] = (char)(c | 32); 
     84            lower = (char)(c | 32); 
    8485        else 
    85             result[i] = (char)c; 
    86         hval = hval * PJ_HASH_MULTIPLIER + result[i]; 
     86            lower = (char)c; 
     87        if (result) 
     88            result[i] = lower; 
     89        hval = hval * PJ_HASH_MULTIPLIER + lower; 
    8790    } 
    8891#else 
    8992    for (i=0; i<key->slen; ++i) { 
    90         result[i] = (char)pj_tolower(key->ptr[i]); 
    91         hval = hval * PJ_HASH_MULTIPLIER + result[i]; 
     93        char lower = (char)pj_tolower(key->ptr[i]); 
     94        if (result) 
     95            result[i] = lower; 
     96        hval = hval * PJ_HASH_MULTIPLIER + lower; 
    9297    } 
    9398#endif 
     
    129134                                   const void *key, unsigned keylen, 
    130135                                   void *val, pj_uint32_t *hval, 
    131                                    void *entry_buf) 
     136                                   void *entry_buf, pj_bool_t lower) 
    132137{ 
    133138    pj_uint32_t hash; 
     
    147152            const pj_uint8_t *p = (const pj_uint8_t*)key; 
    148153            for ( ; *p; ++p ) { 
    149                 hash = hash * PJ_HASH_MULTIPLIER + *p; 
     154                if (lower) 
     155                    hash = hash * PJ_HASH_MULTIPLIER + pj_tolower(*p); 
     156                else  
     157                    hash = hash * PJ_HASH_MULTIPLIER + *p; 
    150158            } 
    151159            keylen = p - (const unsigned char*)key; 
     
    154162                                  *end = p + keylen; 
    155163            for ( ; p!=end; ++p) { 
    156                 hash = hash * PJ_HASH_MULTIPLIER + *p; 
     164                if (lower) 
     165                    hash = hash * PJ_HASH_MULTIPLIER + pj_tolower(*p); 
     166                else 
     167                    hash = hash * PJ_HASH_MULTIPLIER + *p; 
    157168            } 
    158169        } 
     
    168179         p_entry = &entry->next, entry = *p_entry) 
    169180    { 
     181        pj_str_t str; 
     182         
     183        if (lower) { 
     184            str.ptr = (char *)entry->key; 
     185            str.slen = keylen; 
     186        } 
    170187        if (entry->hash==hash && entry->keylen==keylen && 
    171             pj_memcmp(entry->key, key, keylen)==0)  
     188            ((lower && pj_strnicmp2(&str, (const char *)key, keylen)==0) || 
     189             (!lower && pj_memcmp(entry->key, key, keylen)==0))) 
    172190        { 
    173191            break;       
     
    215233{ 
    216234    pj_hash_entry *entry; 
    217     entry = *find_entry( NULL, ht, key, keylen, NULL, hval, NULL); 
     235    entry = *find_entry( NULL, ht, key, keylen, NULL, hval, NULL, PJ_FALSE); 
    218236    return entry ? entry->value : NULL; 
    219237} 
    220238 
    221 PJ_DEF(void) pj_hash_set( pj_pool_t *pool, pj_hash_table_t *ht, 
    222                           const void *key, unsigned keylen, pj_uint32_t hval, 
    223                           void *value ) 
     239PJ_DEF(void *) pj_hash_get_lower( pj_hash_table_t *ht, 
     240                                  const void *key, unsigned keylen, 
     241                                  pj_uint32_t *hval) 
     242{ 
     243    pj_hash_entry *entry; 
     244    entry = *find_entry( NULL, ht, key, keylen, NULL, hval, NULL, PJ_TRUE); 
     245    return entry ? entry->value : NULL; 
     246} 
     247 
     248static void hash_set( pj_pool_t *pool, pj_hash_table_t *ht, 
     249                      const void *key, unsigned keylen, pj_uint32_t hval, 
     250                      void *value, void *entry_buf, pj_bool_t lower ) 
    224251{ 
    225252    pj_hash_entry **p_entry; 
    226253 
    227     p_entry = find_entry( pool, ht, key, keylen, value, &hval, NULL); 
     254    p_entry = find_entry( pool, ht, key, keylen, value, &hval, entry_buf, 
     255                          lower); 
    228256    if (*p_entry) { 
    229257        if (value == NULL) { 
     
    242270} 
    243271 
     272PJ_DEF(void) pj_hash_set( pj_pool_t *pool, pj_hash_table_t *ht, 
     273                          const void *key, unsigned keylen, pj_uint32_t hval, 
     274                          void *value ) 
     275{ 
     276    hash_set(pool, ht, key, keylen, hval, value, NULL, PJ_FALSE); 
     277} 
     278 
     279PJ_DEF(void) pj_hash_set_lower( pj_pool_t *pool, pj_hash_table_t *ht, 
     280                                const void *key, unsigned keylen, 
     281                                pj_uint32_t hval, void *value ) 
     282{ 
     283    hash_set(pool, ht, key, keylen, hval, value, NULL, PJ_TRUE); 
     284} 
     285 
    244286PJ_DEF(void) pj_hash_set_np( pj_hash_table_t *ht, 
    245287                             const void *key, unsigned keylen,  
     
    247289                             void *value) 
    248290{ 
    249     pj_hash_entry **p_entry; 
    250  
    251     p_entry = find_entry( NULL, ht, key, keylen, value, &hval,  
    252                          (void*)entry_buf ); 
    253     if (*p_entry) { 
    254         if (value == NULL) { 
    255             /* delete entry */ 
    256             PJ_LOG(6, ("hashtbl", "%p: p_entry %p deleted", ht, *p_entry)); 
    257             *p_entry = (*p_entry)->next; 
    258             --ht->count; 
    259              
    260         } else { 
    261             /* overwrite */ 
    262             (*p_entry)->value = value; 
    263             PJ_LOG(6, ("hashtbl", "%p: p_entry %p value set to %p", ht,  
    264                        *p_entry, value)); 
    265         } 
    266     } 
     291    hash_set(NULL, ht, key, keylen, hval, value, (void *)entry_buf, PJ_FALSE); 
     292} 
     293 
     294PJ_DEF(void) pj_hash_set_np_lower( pj_hash_table_t *ht, 
     295                                   const void *key, unsigned keylen, 
     296                                   pj_uint32_t hval, 
     297                                   pj_hash_entry_buf entry_buf, 
     298                                   void *value) 
     299{ 
     300    hash_set(NULL, ht, key, keylen, hval, value, (void *)entry_buf, PJ_TRUE); 
    267301} 
    268302 
Note: See TracChangeset for help on using the changeset viewer.