Changeset 622

Show
Ignore:
Timestamp:
01/18/07 19:20:32 (2 years ago)
Author:
alo
Message:

--

Files:

Legend:

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

    r621 r622  
    112007-01-18  Alvaro Lopez Ortega  <alvaro@alobbs.com> 
     2 
     3        * cherokee/config_reader.h, cherokee/config_reader.c, 
     4        cherokee/config_node.h, cherokee/config_node.c, 
     5        cherokee/server.c (cherokee_server_read_config_string), 
     6        cherokee/Makefile.am: Configuration reading methods have been 
     7        splitted from the config_node class. They didn't make sense over 
     8        there. 
    29 
    310        * cherokee.conf.sample.pre: Error log fixed. 
  • cherokee/trunk/cherokee/Makefile.am

    r610 r622  
    878878config_node.h \ 
    879879config_node.c \ 
     880config_reader.h \ 
     881config_reader.c \ 
    880882balancer.h \ 
    881883balancer.c \ 
  • cherokee/trunk/cherokee/config_node.c

    r601 r622  
    2525#include "common-internal.h" 
    2626 
    27 #include <sys/types.h> 
    28 #include <sys/stat.h> 
    29 #include <unistd.h> 
    30  
    3127#include "config_node.h" 
    3228#include "util.h" 
     
    114110        cherokee_list_add_tail (LIST(n), &entry->child); 
    115111        return n; 
    116 } 
    117  
    118  
    119 static ret_t 
    120 do_include (cherokee_config_node_t *conf, cherokee_buffer_t *path)  
    121 { 
    122         int         re; 
    123         struct stat info; 
    124  
    125         re = stat (path->buf, &info); 
    126         if (re < 0) { 
    127                 PRINT_MSG ("Could not access '%s'\n", path->buf); 
    128                 return ret_error; 
    129         } 
    130  
    131         if (S_ISREG(info.st_mode)) { 
    132                 return cherokee_config_node_parse_file (conf, path->buf); 
    133  
    134         } else if (S_ISDIR(info.st_mode)) { 
    135                 DIR              *dir; 
    136                 struct dirent    *entry; 
    137                 int               entry_len; 
    138                  
    139                 dir = opendir (path->buf); 
    140                 if (dir == NULL) return ret_error; 
    141                  
    142                 while ((entry = readdir(dir)) != NULL) { 
    143                         ret_t             ret; 
    144                         cherokee_buffer_t full_new = CHEROKEE_BUF_INIT; 
    145                          
    146                         /* Ignore backup files 
    147                          */ 
    148                         entry_len = strlen(entry->d_name); 
    149                          
    150                         if ((entry->d_name[0] == '.') || 
    151                             (entry->d_name[0] == '#') || 
    152                             (entry->d_name[entry_len-1] == '~')) 
    153                         { 
    154                                 continue; 
    155                         } 
    156                          
    157                         ret = cherokee_buffer_add_va (&full_new, "%s/%s", path->buf, entry->d_name); 
    158                         if (unlikely (ret != ret_ok)) return ret; 
    159  
    160                         ret = cherokee_config_node_parse_file (conf, full_new.buf); 
    161                         if (ret != ret_ok) { 
    162                                 cherokee_buffer_mrproper (&full_new); 
    163                                 return ret; 
    164                         } 
    165  
    166                         cherokee_buffer_mrproper (&full_new); 
    167                 } 
    168                          
    169                 closedir (dir); 
    170                 return ret_ok; 
    171         }  
    172          
    173         SHOULDNT_HAPPEN; 
    174         return ret_error; 
    175112} 
    176113 
     
    189126         */ 
    190127        if (equal_str (key, "include")) { 
    191                 return do_include (conf, val); 
     128                return cherokee_config_reader_parse (conf, val); 
    192129        } else if (equal_str (key, "try_include")) { 
    193                 do_include (conf, val); 
     130                cherokee_config_reader_parse (conf, val); 
    194131        } 
    195132 
     
    305242 
    306243        return ret_ok; 
    307 } 
    308  
    309  
    310 ret_t  
    311 cherokee_config_node_parse_string (cherokee_config_node_t *conf, cherokee_buffer_t *buf) 
    312 { 
    313         ret_t              ret; 
    314         char              *eol; 
    315         char              *begin; 
    316         char              *equal; 
    317         char              *tmp; 
    318         char              *eof; 
    319         cherokee_buffer_t  key = CHEROKEE_BUF_INIT; 
    320         cherokee_buffer_t  val = CHEROKEE_BUF_INIT; 
    321  
    322         eof = buf->buf + buf->len; 
    323  
    324         begin = buf->buf; 
    325         do { 
    326                 /* Skip whites at the begining 
    327                  */ 
    328                 while ((begin < eof) &&  
    329                        ((*begin == ' ') || (*begin == '\t') ||  
    330                         (*begin == '\r') || (*begin == '\n')))  
    331                 { 
    332                         begin++; 
    333                 } 
    334  
    335                 /* Look for the EOL 
    336                  */ 
    337                 eol = cherokee_min_str (strchr(begin, '\n'),  
    338                                         strchr(begin, '\r')); 
    339  
    340                 if (eol == NULL)  
    341                         break; 
    342  
    343                 /* Check that it's long enough 
    344                  */ 
    345                 if (eol - begin <= 4) { 
    346                         begin = eol + 1; 
    347                         continue; 
    348                 } 
    349                 *eol = '\0'; 
    350  
    351                 /* Read the line  
    352                  */ 
    353                 if (*begin != '#') { 
    354                         cuint_t val_len; 
    355  
    356                         equal = strstr (begin, " = "); 
    357                         if (equal == NULL) goto error; 
    358                  
    359                         tmp = equal; 
    360  
    361                         /* Skip whites: end of the key 
    362                          */ 
    363                         while (*tmp == ' ') tmp--; 
    364                         cherokee_buffer_add (&key, begin, (tmp + 1) - begin); 
    365                          
    366                         tmp = equal + 3; 
    367                         while (*tmp == ' ') tmp++;               
    368  
    369                         /* Skip whites: end of the value 
    370                          */ 
    371                         val_len = strlen(tmp); 
    372                         while (tmp[val_len-1] == ' ') val_len--; 
    373  
    374                         cherokee_buffer_add (&val, tmp, val_len); 
    375  
    376                         TRACE(ENTRIES, "'%s' => '%s'\n", key.buf, val.buf); 
    377  
    378                         ret = cherokee_config_node_add_buf (conf, &key, &val); 
    379                         if (ret != ret_ok) goto error; 
    380                 } 
    381  
    382                 /* Next loop 
    383                  */ 
    384                 begin = eol + 1; 
    385  
    386                 cherokee_buffer_clean (&key); 
    387                 cherokee_buffer_clean (&val); 
    388  
    389         } while (eol != NULL); 
    390          
    391         cherokee_buffer_mrproper (&key); 
    392         cherokee_buffer_mrproper (&val); 
    393         return ret_ok; 
    394  
    395 error: 
    396         PRINT_MSG ("Error parsing: %s\n", begin); 
    397  
    398         cherokee_buffer_mrproper (&key); 
    399         cherokee_buffer_mrproper (&val); 
    400         return ret_error; 
    401 } 
    402  
    403  
    404 ret_t  
    405 cherokee_config_node_parse_file (cherokee_config_node_t *conf, const char *file) 
    406 { 
    407         ret_t              ret; 
    408         cherokee_buffer_t  buf = CHEROKEE_BUF_INIT; 
    409  
    410         ret = cherokee_buffer_read_file (&buf, (char *)file); 
    411         if (ret != ret_ok) return ret; 
    412  
    413         ret = cherokee_config_node_parse_string (conf, &buf); 
    414         if (ret != ret_ok) goto error; 
    415  
    416         cherokee_buffer_mrproper (&buf); 
    417         return ret_ok; 
    418  
    419 error: 
    420         cherokee_buffer_mrproper (&buf); 
    421         return ret_error; 
    422244} 
    423245 
  • cherokee/trunk/cherokee/config_node.h

    r597 r622  
    6666ret_t cherokee_config_node_while     (cherokee_config_node_t *conf, cherokee_config_node_while_func_t func, void *data); 
    6767 
    68 ret_t cherokee_config_node_parse_file   (cherokee_config_node_t *conf, const char *file); 
    69 ret_t cherokee_config_node_parse_string (cherokee_config_node_t *conf, cherokee_buffer_t *string); 
    70  
    7168/* Convenience functions: value retrieving 
    7269 */ 
  • cherokee/trunk/cherokee/server.c

    r597 r622  
    15131513        /* Load the main file 
    15141514         */ 
    1515         ret = cherokee_config_node_parse_string (&srv->config, string); 
     1515        ret = cherokee_config_reader_parse (&srv->config, string); 
    15161516        if (ret != ret_ok) return ret; 
    15171517 
     
    15351535        /* Load the main file 
    15361536         */ 
    1537         ret = cherokee_config_node_parse_file (&srv->config, fullpath); 
     1537        ret = cherokee_config_reader_parse (&srv->config, fullpath); 
    15381538        if (ret != ret_ok) return ret; 
    15391539