Changeset 435

Show
Ignore:
Timestamp:
10/24/06 11:25:47 (2 years ago)
Author:
alo
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • cherokee/trunk/ChangeLog

    r434 r435  
     12006-10-24  A.D.F  <adefacc@tin.it> 
     2 
     3        * cherokee/buffer.c (cherokee_buffer_decode): change 
     4          cherokee_buffer_decode() in order to speed up it and to avoid to 
     5          use original BSD (Jeff Poskanzer) source code. 
     6 
     72006-10-24  Alvaro Lopez Ortega  <alvaro@alobbs.com> 
     8 
     9        * cherokee/util.h, cherokee/util.c (cherokee_hexit): Removed. 
     10 
    1112006-10-21  Alvaro Lopez Ortega  <alvaro@alobbs.com> 
    212 
  • cherokee/trunk/cherokee/buffer.c

    r417 r435  
    351351 
    352352 
     353/* 
     354 * Decode a string that may have encoded characters %xx 
     355 * where xx is the hexadecimal number corresponding 
     356 * to the character ascii value. 
     357 */ 
    353358ret_t 
    354359cherokee_buffer_decode (cherokee_buffer_t *buffer) 
    355360{ 
    356         char *from; 
    357         char *to; 
     361        static const char hex2dec_tab[256] = { 
     362                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* 00-0F */ 
     363                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* 10-1F */ 
     364                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* 20-2F */ 
     365                0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0,  /* 30-3F */ 
     366                0,10,11,12,13,14,15, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* 40-4F */ 
     367                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* 50-5F */ 
     368                0,10,11,12,13,14,15, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* 60-6F */ 
     369                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* 70-7F */ 
     370                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* 80-8F */ 
     371                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* 90-9F */ 
     372                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* A0-AF */ 
     373                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* B0-BF */ 
     374                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* C0-CF */ 
     375                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* D0-DF */ 
     376                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* E0-EF */ 
     377                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0   /* F0-FF */ 
     378        }; 
     379 
     380        char *psrc; 
     381        char *ptgt; 
     382        int   len; 
     383 
     384#define hex2dec_m(c)    ( (int) hex2dec_tab[ ( (unsigned char )(c) ) ] ) 
    358385 
    359386        if (buffer->buf == NULL) { 
    360387                return ret_error; 
    361388        } 
    362  
    363         /* Copies and decodes a string.  It's ok for from and to to be 
    364          * the same string. 
    365          */ 
    366         from = to = buffer->buf; 
    367  
    368         for (; *from != '\0'; ++to, ++from) { 
    369                 if (from[0] == '%' && isxdigit(from[1]) && isxdigit(from[2])) { 
    370                         if (unlikely (((from[1] == '0') && (from[2] == '0')))) { 
     389         
     390        /* Verify if decoding is needed. 
     391         */ 
     392        if ((psrc = strchr (buffer->buf, '%')) == NULL) 
     393                return ret_ok; 
     394 
     395        /* Decode string. 
     396         */ 
     397        len = buffer->len; 
     398        for (ptgt = psrc; *psrc != '\0'; ++ptgt, ++psrc) { 
     399                if (psrc[0] == '%' && isxdigit(psrc[1]) && isxdigit(psrc[2])) { 
     400                        if (unlikely (((psrc[1] == '0') && (psrc[2] == '0')))) { 
    371401                                /* Replace null bytes (%00) with 
    372402                                 * spaces, to prevent attacks 
    373403                                 */ 
    374                                 *to = ' '; 
     404                                *ptgt = ' '; 
    375405                        } else { 
    376                                 *to = cherokee_hexit(from[1]) * 16 + cherokee_hexit(from[2]); 
     406                                *ptgt = hex2dec_m(psrc[1]) * 16 + hex2dec_m(psrc[2]); 
    377407                        } 
    378408 
    379                         from += 2; 
    380                         buffer->len -= 2; 
     409                        psrc += 2; 
     410                        len -= 2; 
    381411                } else { 
    382                         *to = *from
     412                        *ptgt = *psrc
    383413                } 
    384414        } 
    385         *to = '\0'; 
    386  
    387         return ret_ok; 
    388 
     415        *ptgt = '\0'; 
     416        buffer->len = len; 
     417 
     418#undef hex2dec_m 
     419        return ret_ok; 
     420
     421 
    389422 
    390423ret_t  
  • cherokee/trunk/cherokee/exts_table.c

    r433 r435  
    6262        if (dot == NULL) return ret_not_found; 
    6363 
    64         printf ("GET0: et %p table %p ext %s\n", et, &et->table, dot+1); 
    6564        ret = cherokee_table_get (&et->table, dot+1, (void **)&entry); 
    66         printf ("GET1: et %p table %p ext %s: %d\n", et, &et->table, dot+1, ret); 
    6765        if (ret != ret_ok) return ret; 
    6866 
     
    9391         * plugin entry object. 
    9492         */ 
    95         printf ("ADD: et %p table %p ext %s\n", et, &et->table, ext); 
     93        TRACE ("ADD: et %p table %p ext %s\n", et, &et->table, ext); 
    9694        return cherokee_table_add (&et->table, ext, plugin_entry); 
    9795} 
  • cherokee/trunk/cherokee/util.c

    r427 r435  
    9090                                   "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; 
    9191const char *cherokee_weekdays[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; 
    92  
    93  
    94  
    95 int 
    96 cherokee_hexit (char c) 
    97 { 
    98         if ( c >= '0' && c <= '9' ) 
    99                 return c - '0'; 
    100         if ( c >= 'a' && c <= 'f' ) 
    101                 return c - 'a' + 10; 
    102         if ( c >= 'A' && c <= 'F' ) 
    103                 return c - 'A' + 10; 
    104  
    105         /* shouldn't happen, we're guarded by isxdigit() */ 
    106         return 0;            
    107 } 
    10892 
    10993 
  • cherokee/trunk/cherokee/util.h

    r426 r435  
    7676/* String management functions 
    7777 */ 
    78 int     cherokee_hexit              (char c); 
    7978int     cherokee_isbigendian        (void); 
    8079char   *cherokee_min_str            (char *s1, char *s2);