Changeset 1880

Show
Ignore:
Timestamp:
08/20/08 14:58:47 (3 months ago)
Author:
alo
Message:

--

Files:

Legend:

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

    r1878 r1880  
    112008-08-20  Alvaro Lopez Ortega  <alvaro@alobbs.com> 
     2 
     3        * cherokee/rule_list.c, cherokee/virtual_server.c, 
     4        cherokee/connection-protected.h, cherokee/config_entry.c, 
     5        cherokee/config_entry.h, cherokee/connection.c, 
     6        admin/PageEntry.py, admin/consts.py: Adds support por expiration 
     7        headers.  This patch adds support to both the server and the 
     8        configuration interface. 
    29 
    310        * cherokee/config_node.c (cherokee_config_node_read_long), 
  • cherokee/trunk/admin/PageEntry.py

    r1752 r1880  
    1111DEFAULT_RULE_WARNING = 'The default match ought not to be changed.' 
    1212 
    13 NOTE_DOCUMENT_ROOT = 'Allows to specify an alternative document root path.' 
    14 NOTE_HANDLER       = 'How the connection will be handled.' 
    15 NOTE_HTTPS_ONLY    = 'Enable to allow access to the resource only by https.' 
    16 NOTE_ALLOW_FROM    = 'List of IPs and subnets allowed to access the resource.' 
    17 NOTE_VALIDATOR     = 'Which, if any, will be the authentication method.' 
     13NOTE_DOCUMENT_ROOT   = 'Allows to specify an alternative document root path.' 
     14NOTE_HANDLER         = 'How the connection will be handled.' 
     15NOTE_HTTPS_ONLY      = 'Enable to allow access to the resource only by https.' 
     16NOTE_ALLOW_FROM      = 'List of IPs and subnets allowed to access the resource.' 
     17NOTE_VALIDATOR       = 'Which, if any, will be the authentication method.' 
     18NOTE_EXPIRATION      = 'Points how long the files should be cached' 
     19NOTE_EXPIRATION_TIME = 'How long from the object can be cached' 
    1820 
    1921DATA_VALIDATION = [ 
     
    129131            tabs += [('Handler', str(table))] 
    130132 
     133        # Expiration 
     134        tabs += [('Expiration', self._render_expiration())] 
     135 
    131136        # Security 
    132137        tabs += [('Security', self._render_security())] 
     
    158163        return str(table) + e 
    159164 
     165    def _render_expiration (self): 
     166        txt = '' 
     167        pre = "%s!expiration"%(self._conf_prefix) 
     168 
     169        table = TableProps() 
     170        self.AddPropOptions_Ajax (table, "Expiration", pre, EXPIRATION_TYPE, NOTE_EXPIRATION) 
     171 
     172        exp = self._cfg.get_val(pre) 
     173        if exp == 'time': 
     174            self.AddPropEntry (table, 'Time to expire', '%s!time'%(pre), NOTE_EXPIRATION_TIME) 
     175 
     176        txt += str(table) 
     177        return txt 
     178 
    160179    def _render_security (self): 
    161180        pre = self._conf_prefix 
  • cherokee/trunk/admin/consts.py

    r1736 r1880  
    108108    ('geoip',      'GeoIP') 
    109109] 
     110 
     111EXPIRATION_TYPE = [ 
     112    ('',         'Not set'), 
     113    ('epoch',    'Already expired on 1970'), 
     114    ('max',      'Do not expire until 2038'), 
     115    ('time',     'Custom value') 
     116] 
  • cherokee/trunk/cherokee/config_entry.c

    r1375 r1880  
    6262        entry->document_root        = NULL; 
    6363        entry->users                = NULL; 
     64 
     65        entry->expiration           = cherokee_expiration_none; 
     66        entry->expiration_time      = 0; 
    6467 
    6568        return ret_ok; 
     
    160163                entry->users = source->users; 
    161164         
     165        if ((entry->expiration  == cherokee_expiration_none) && 
     166            (source->expiration != cherokee_expiration_none)) 
     167        { 
     168                entry->expiration      = source->expiration; 
     169                entry->expiration_time = source->expiration_time; 
     170        } 
     171 
    162172        return ret_ok; 
    163173} 
     
    177187        printf ("auth_realm:                %s\n", entry->auth_realm ? entry->auth_realm->buf : ""); 
    178188        printf ("users:                     %p\n", entry->users); 
     189        printf ("expiration type:           %d\n", entry->expiration); 
     190        printf ("expiration_time            %lu\n", entry->expiration_time); 
    179191 
    180192        return ret_ok; 
  • cherokee/trunk/cherokee/config_entry.h

    r1430 r1880  
    3838#define CHEROKEE_CONFIG_PRIORITY_DEFAULT 1 
    3939 
     40typedef enum { 
     41        cherokee_expiration_none, 
     42        cherokee_expiration_epoch, 
     43        cherokee_expiration_max, 
     44        cherokee_expiration_time 
     45} cherokee_expiration_t; 
    4046 
    4147typedef struct { 
     
    6066        cherokee_http_auth_t        authentication; 
    6167        cherokee_avl_t             *users; 
     68 
     69        /* Headers 
     70         */ 
     71        cherokee_expiration_t       expiration; 
     72        time_t                      expiration_time; 
    6273} cherokee_config_entry_t;  
    6374 
  • cherokee/trunk/cherokee/connection-protected.h

    r1871 r1880  
    186186        int                           regex_ovector[OVECTOR_LEN]; 
    187187        int                           regex_ovecsize; 
     188 
     189        cherokee_expiration_t         expiration; 
     190        time_t                        expiration_time; 
    188191}; 
    189192 
  • cherokee/trunk/cherokee/connection.c

    r1871 r1880  
    7979#include "header-protected.h" 
    8080#include "iocache.h" 
     81#include "dtm.h" 
    8182 
    8283#define ENTRIES "core,connection" 
     
    119120        n->polling_multiple     = false; 
    120121        n->polling_mode         = FDPOLL_MODE_NONE; 
     122        n->expiration           = cherokee_expiration_none; 
     123        n->expiration_time      = 0; 
    121124 
    122125        cherokee_buffer_init (&n->buffer); 
     
    247250        conn->polling_multiple     = false; 
    248251        conn->polling_mode         = FDPOLL_MODE_NONE; 
     252        conn->expiration           = cherokee_expiration_none; 
     253        conn->expiration_time      = 0; 
    249254 
    250255        memset (conn->regex_ovector, OVECTOR_LEN * sizeof(int), 0); 
     
    409414 
    410415static void 
    411 build_response_header__authenticate (cherokee_connection_t *conn, cherokee_buffer_t *buffer) 
     416build_response_header_authentication (cherokee_connection_t *conn, cherokee_buffer_t *buffer) 
    412417{ 
    413418        /* Basic Authenticatiom 
     
    452457 
    453458static void 
     459build_response_header_expiration (cherokee_connection_t *conn, cherokee_buffer_t *buffer) 
     460{ 
     461        time_t    exp_time; 
     462        struct tm exp_tm; 
     463        size_t    szlen = 0; 
     464        char      bufstr[DTM_SIZE_GMTTM_STR + 2]; 
     465 
     466        switch (conn->expiration) { 
     467        case cherokee_expiration_epoch: 
     468                cherokee_buffer_add_str (buffer, "Expires: Tue, 01 Jan 1970 00:00:01 GMT" CRLF); 
     469                cherokee_buffer_add_str (buffer, "Cache-Control: no-cache" CRLF); 
     470                break; 
     471        case cherokee_expiration_max: 
     472                cherokee_buffer_add_str (buffer, "Expires: Thu, 31 Dec 2037 23:55:55 GMT" CRLF); 
     473                cherokee_buffer_add_str (buffer, "Cache-Control: max-age=315360000" CRLF); 
     474                break; 
     475        case cherokee_expiration_time: 
     476                exp_time = (cherokee_bogonow_now + conn->expiration_time); 
     477                cherokee_gmtime (&exp_time, &exp_tm); 
     478                szlen = cherokee_dtm_gmttm2str (bufstr, sizeof(bufstr), &exp_tm); 
     479 
     480                cherokee_buffer_add_str (buffer, "Expires: "); 
     481                cherokee_buffer_add (buffer, bufstr, szlen); 
     482                cherokee_buffer_add_str (buffer, CRLF); 
     483 
     484                cherokee_buffer_add_str (buffer, "Cache-Contro: max-age="); 
     485                cherokee_buffer_add_long10 (buffer, conn->expiration_time); 
     486                cherokee_buffer_add_str (buffer, CRLF); 
     487                break; 
     488        default: 
     489                SHOULDNT_HAPPEN; 
     490        } 
     491} 
     492 
     493 
     494static void 
    454495build_response_header (cherokee_connection_t *conn, cherokee_buffer_t *buffer) 
    455496{        
     
    510551         */ 
    511552        if ((conn->realm_ref != NULL) && (conn->error_code == http_unauthorized)) { 
    512                 build_response_header__authenticate (conn, buffer); 
     553                build_response_header_authentication (conn, buffer); 
     554        } 
     555 
     556        /* Expiration 
     557         */ 
     558        if (conn->expiration != cherokee_expiration_none) { 
     559                build_response_header_expiration (conn, buffer); 
    513560        } 
    514561 
  • cherokee/trunk/cherokee/rule_list.c

    r1398 r1880  
    6161} 
    6262 
     63static void 
     64update_connection (cherokee_connection_t   *conn, 
     65                   cherokee_config_entry_t *ret_config) 
     66{ 
     67        if (! conn->realm_ref) 
     68                conn->realm_ref = ret_config->auth_realm; 
     69        if (! conn->auth_type) 
     70                conn->auth_type = ret_config->authentication; 
     71 
     72        if ((conn->expiration       == cherokee_expiration_none) && 
     73            (ret_config->expiration != cherokee_expiration_none)) 
     74        { 
     75                conn->expiration = ret_config->expiration; 
     76                conn->expiration_time = ret_config->expiration_time; 
     77        } 
     78} 
    6379 
    6480ret_t  
     
    95111                cherokee_config_entry_complete (ret_config, &rule->config); 
    96112 
    97                 /* TODO: FIX this.. 
     113                /* Update the connection 
    98114                 */ 
    99                 if (! conn->realm_ref) 
    100                         conn->realm_ref = ret_config->auth_realm; 
    101                 if (! conn->auth_type) 
    102                         conn->auth_type = ret_config->authentication; 
     115                update_connection (conn, ret_config); 
    103116 
    104117                /* Should it continue? */ 
     
    114127        list->def_rule->match(list->def_rule, conn); 
    115128        cherokee_config_entry_complete (ret_config, &list->def_rule->config); 
     129         
     130        /* Update the connection 
     131         */ 
     132        update_connection (conn, ret_config); 
    116133 
    117         /* TODO: FIX this.. 
    118          */ 
    119         if (! conn->realm_ref) 
    120                 conn->realm_ref = ret_config->auth_realm; 
    121         if (! conn->auth_type) 
    122                 conn->auth_type = ret_config->authentication; 
    123          
    124134        return ret_ok; 
    125135} 
  • cherokee/trunk/cherokee/virtual_server.c

    r1715 r1880  
    457457                entry->only_secure = !! atoi(conf->val.buf); 
    458458 
     459        } else if (equal_buf_str (&conf->key, "expiration")) { 
     460                if (equal_buf_str (&conf->val, "none")) { 
     461                        entry->expiration = cherokee_expiration_none; 
     462 
     463                } else if (equal_buf_str (&conf->val, "epoch")) { 
     464                        entry->expiration = cherokee_expiration_epoch; 
     465 
     466                } else if (equal_buf_str (&conf->val, "max")) { 
     467                        entry->expiration = cherokee_expiration_max; 
     468 
     469                } else if (equal_buf_str (&conf->val, "time")) { 
     470                        entry->expiration = cherokee_expiration_time; 
     471                        ret = cherokee_config_node_read_long (conf, "time", &entry->expiration_time); 
     472                        if (ret != ret_ok) { 
     473                                PRINT_ERROR_S ("Expiration 'time' without a time property\n"); 
     474                                return ret_error; 
     475                        } 
     476                } 
     477 
    459478        } else if (equal_buf_str (&conf->key, "match")) { 
    460479                /* Ignore: Previously handled