Changeset 7bf8e1


Ignore:
Timestamp:
02/19/08 15:44:50 (4 years ago)
Author:
Tomash Brechko <tomash.brechko@…>
Branches:
master-v0.7, master-v0.6, memcached_hash, upstream_count_limit
Children:
11531c
Parents:
a64318
git-author:
Tomash Brechko <tomash.brechko@…> (02/19/08 15:44:50)
git-committer:
Tomash Brechko <tomash.brechko@…> (02/19/08 15:44:50)
Message:

Add optional variable $memcached_namespace.

Location:
server/src/http
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • server/src/http/modules/ngx_http_memcached_module.c

    r0019fc r7bf8e1  
    1414    ngx_http_upstream_conf_t   upstream; 
    1515    ngx_int_t                  index; 
     16    ngx_int_t                  ns_index; 
    1617} ngx_http_memcached_loc_conf_t; 
    1718 
     
    150151 
    151152static ngx_str_t  ngx_http_memcached_key = ngx_string("memcached_key"); 
     153static ngx_str_t  ngx_http_memcached_ns = ngx_string("memcached_namespace"); 
    152154 
    153155 
     
    227229{ 
    228230    size_t                          len; 
    229     uintptr_t                       escape; 
     231    uintptr_t                       escape, ns_escape = 0; 
    230232    ngx_buf_t                      *b; 
    231233    ngx_chain_t                    *cl; 
    232234    ngx_http_memcached_ctx_t       *ctx; 
    233     ngx_http_variable_value_t      *vv; 
     235    ngx_http_variable_value_t      *vv, *ns_vv; 
    234236    ngx_http_memcached_loc_conf_t  *mlcf; 
    235237 
     
    246248    escape = 2 * ngx_escape_uri(NULL, vv->data, vv->len, NGX_ESCAPE_MEMCACHED); 
    247249 
    248     len = sizeof("get ") - 1 + vv->len + escape + sizeof(CRLF) - 1; 
     250    ns_vv = ngx_http_get_indexed_variable(r, mlcf->ns_index); 
     251 
     252    if (ns_vv != NULL && !ns_vv->not_found && ns_vv->len != 0) { 
     253        ns_escape = 2 * ngx_escape_uri(NULL, ns_vv->data, 
     254                                       ns_vv->len, NGX_ESCAPE_MEMCACHED); 
     255    } 
     256 
     257    len = sizeof("get ") - 1 + ns_vv->len + ns_escape 
     258                             + vv->len + escape + sizeof(CRLF) - 1; 
    249259 
    250260    b = ngx_create_temp_buf(r->pool, len); 
     
    268278 
    269279    ctx->key.data = b->last; 
     280 
     281    if (ns_vv != NULL && !ns_vv->not_found && ns_vv->len != 0) { 
     282        if (ns_escape == 0) { 
     283            b->last = ngx_copy(b->last, ns_vv->data, ns_vv->len); 
     284        } else { 
     285            b->last = (u_char *) ngx_escape_uri(b->last, ns_vv->data, 
     286                                                ns_vv->len, 
     287                                                NGX_ESCAPE_MEMCACHED); 
     288        } 
     289    } 
    270290 
    271291    if (escape == 0) { 
     
    525545     * 
    526546     *     conf->index = 0; 
     547     *     conf->ns_index = 0; 
    527548     */ 
    528549 
     
    629650    } 
    630651 
     652    lcf->ns_index = ngx_http_get_variable_index(cf, &ngx_http_memcached_ns); 
     653 
     654    if (lcf->ns_index == NGX_ERROR) { 
     655        return NGX_CONF_ERROR; 
     656    } 
     657 
    631658    return NGX_CONF_OK; 
    632659} 
  • server/src/http/ngx_http_variables.c

    r0019fc r7bf8e1  
    13131313 
    13141314 
     1315static ngx_int_t 
     1316ngx_http_optional_variable(ngx_http_request_t *r, 
     1317    ngx_http_variable_value_t *v, uintptr_t data) 
     1318{ 
     1319    *v = ngx_http_variable_null_value; 
     1320    return NGX_OK; 
     1321} 
     1322 
     1323 
    13151324ngx_int_t 
    13161325ngx_http_variables_init_vars(ngx_conf_t *cf) 
     
    13741383        } 
    13751384 
     1385        if (ngx_strncmp(v[i].name.data, "memcached_namespace", 19) == 0) { 
     1386            v[i].get_handler = ngx_http_optional_variable; 
     1387 
     1388            continue; 
     1389        } 
     1390 
    13761391        ngx_log_error(NGX_LOG_EMERG, cf->log, 0, 
    13771392                      "unknown \"%V\" variable", &v[i].name); 
Note: See TracChangeset for help on using the changeset viewer.