static char *hexin_http_percn_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
    hexin_http_percn_loc_conf_t *plcf = conf;

    ngx_str_t                 *value;
    ngx_url_t                  u;
    ngx_http_core_loc_conf_t  *clcf;

    value = cf->args->elts;

    ngx_memzero(&u, sizeof(ngx_url_t));

    u.url = value[1];
    u.no_resolve = 1;

    clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);

    clcf->handler = hexin_http_percn_handler;

    if (clcf->name.data[clcf->name.len - 1] == '/') {
        clcf->auto_redirect = 1;
    }

    plcf->receivers_index = ngx_http_get_variable_index(cf, &hexin_http_percn_form_receivers);
	plcf->common_index = ngx_http_get_variable_index(cf, &hexin_http_percn_form_common);	
	plcf->block_size_index = ngx_http_get_variable_index(cf, &hexin_http_percn_block_size);


    if (plcf->receivers_index == NGX_ERROR) {
        return NGX_CONF_ERROR;
    }

    return NGX_CONF_OK;
}
static char *
ngx_http_mapcache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
   mapcache_context *ctx = conf;
   ngx_str_t *value;
   value = cf->args->elts;
   char *conffile = (char*)value[1].data;
   ctx->config = mapcache_configuration_create(ctx->pool);
   mapcache_configuration_parse(ctx,conffile,ctx->config,1);
   if(GC_HAS_ERROR(ctx)) return NGX_CONF_ERROR;
   mapcache_configuration_post_config(ctx, ctx->config);
   if(GC_HAS_ERROR(ctx)) return NGX_CONF_ERROR;
   
   ngx_http_core_loc_conf_t  *clcf;

    clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
    clcf->handler = ngx_http_mapcache_handler;

   pathinfo_index = ngx_http_get_variable_index(cf, &pathinfo_str);
   if (pathinfo_index == NGX_ERROR) {
		return NGX_CONF_ERROR;
	}
   urlprefix_index = ngx_http_get_variable_index(cf, &urlprefix_str);
   if (urlprefix_index == NGX_ERROR) {
		return NGX_CONF_ERROR;
	}

    return NGX_CONF_OK;
}
Ejemplo n.º 3
0
static char * merge_loc_conf(ngx_conf_t * cf, void * parent, void * child) {
    ngx_http_rdns_loc_conf_t * prev = parent;
    ngx_http_rdns_loc_conf_t * conf = child;
    ngx_http_core_loc_conf_t * core_loc_cf;

    ngx_conf_log_error(NGX_LOG_DEBUG, cf, 0, "merging location configs: %p -> %p", prev, conf);

    core_loc_cf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);

    ngx_conf_merge_value(conf->conf.enabled, prev->conf.enabled, 0);
    ngx_conf_merge_value(conf->conf.double_mode, prev->conf.double_mode, 0);
    ngx_conf_merge_value(conf->rdns_result_index, prev->rdns_result_index,
            ngx_http_get_variable_index(cf, (ngx_str_t *)&var_rdns_result_name));

#if (NGX_PCRE)
    if (conf->rules == NULL) {
        conf->rules = prev->rules;
    }
#endif

    if (conf->conf.enabled && ((core_loc_cf->resolver == NULL) || (core_loc_cf->resolver->udp_connections.nelts == 0))) {
        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "no core resolver defined for rdns");
        return NGX_CONF_ERROR;
    }

    ngx_conf_log_error(NGX_LOG_DEBUG, cf, 0, "(DONE) merging location configs");

    return NGX_CONF_OK;
}
static ngx_int_t
ngx_http_reqstat_add_variable(ngx_conf_t *cf)
{
    ngx_str_t                  name = ngx_string("reqstat_enable");
    ngx_http_variable_t       *var;
    ngx_http_reqstat_conf_t   *rmcf;

    rmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_reqstat_module);

    var = ngx_http_add_variable(cf, &name, 0);
    if (var == NULL) {
        return NGX_ERROR;
    }

    var->get_handler = ngx_http_reqstat_variable_enable;
    var->data = 0;

    rmcf->index = ngx_http_get_variable_index(cf, &name);

    if (rmcf->index == NGX_ERROR) {
        return NGX_ERROR;
    }

    return NGX_OK;
}
static char *
ngx_http_perl_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
    ngx_int_t                   index;
    ngx_str_t                  *value;
    ngx_http_variable_t        *v;
    ngx_http_perl_variable_t   *pv;
    ngx_http_perl_main_conf_t  *pmcf;
    value = cf->args->elts;
    if (value[1].data[0] != '$')
    {
        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                           "invalid variable name \"%V\"", &value[1]);
        return NGX_CONF_ERROR;
    }
    value[1].len--;
    value[1].data++;
    v = ngx_http_add_variable(cf, &value[1], NGX_HTTP_VAR_CHANGEABLE);
    if (v == NULL)
    {
        return NGX_CONF_ERROR;
    }
    pv = ngx_palloc(cf->pool, sizeof(ngx_http_perl_variable_t));
    if (pv == NULL)
    {
        return NGX_CONF_ERROR;
    }
    index = ngx_http_get_variable_index(cf, &value[1]);
    if (index == NGX_ERROR)
    {
        return NGX_CONF_ERROR;
    }
    pmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_perl_module);
    if (pmcf->perl == NULL)
    {
        if (ngx_http_perl_init_interpreter(cf, pmcf) != NGX_CONF_OK)
        {
            return NGX_CONF_ERROR;
        }
    }
    pv->handler = value[2];
    {
        dTHXa(pmcf->perl);
        PERL_SET_CONTEXT(pmcf->perl);
        ngx_http_perl_eval_anon_sub(aTHX_ & value[2], &pv->sub);
        if (pv->sub == &PL_sv_undef)
        {
            ngx_conf_log_error(NGX_LOG_ERR, cf, 0,
                               "eval_pv(\"%V\") failed", &value[2]);
            return NGX_CONF_ERROR;
        }
        if (pv->sub == NULL)
        {
            pv->sub = newSVpvn((char *) value[2].data, value[2].len);
        }
    }
    v->get_handler = ngx_http_perl_variable;
    v->data = (uintptr_t) pv;
    return NGX_CONF_OK;
}
static ngx_int_t
ngx_http_replace_script_add_var_code(ngx_http_replace_script_compile_t *sc,
    ngx_str_t *name)
{
    ngx_int_t                            index;
    ngx_http_replace_script_var_code_t  *code;

    index = ngx_http_get_variable_index(sc->cf, name);

    if (index == NGX_ERROR) {
        return NGX_ERROR;
    }

    code = ngx_http_replace_script_add_code(*sc->lengths,
                                  sizeof(ngx_http_replace_script_var_code_t));
    if (code == NULL) {
        return NGX_ERROR;
    }

    code->code = (ngx_http_replace_script_code_pt)
                 ngx_http_replace_script_copy_var_len_code;

    code->index = (uintptr_t) index;

    code = ngx_http_replace_script_add_code(*sc->values,
                                  sizeof(ngx_http_replace_script_var_code_t));
    if (code == NULL) {
        return NGX_ERROR;
    }

    code->code = ngx_http_replace_script_copy_var_code;
    code->index = (uintptr_t) index;

    return NGX_OK;
}
Ejemplo n.º 7
0
static ngx_int_t
ngx_http_sample_init(ngx_conf_t *cf)
{
    ngx_http_handler_pt        *h = NULL;
    ngx_http_core_main_conf_t  *cmcf = NULL;
    ngx_http_sample_loc_conf_t *slcf = NULL;
    ngx_str_t sample_ids_var_name = ngx_string("sample_ids");


    cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);

    h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
    if (h == NULL) {
        return NGX_ERROR;
    }

    *h = ngx_http_sample_handler;

    slcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_sample_module);

    slcf->sample_ids_var_index = ngx_http_get_variable_index(cf, &sample_ids_var_name);
    if (slcf->sample_ids_var_index == NGX_ERROR) {
    	return NGX_ERROR;
    }

    return NGX_OK;
}
static char *
ngx_http_advertise_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
{
    ngx_http_advertise_conf_t  *prev = parent;
    ngx_http_advertise_conf_t  *conf = child;
    ngx_http_variable_t        *var;
    
    ngx_conf_merge_value(conf->inject, prev->inject, 0);    
    ngx_conf_merge_size_value(conf->buffer_size, prev->buffer_size, 1 * 1024 * 1024);
    ngx_conf_merge_ptr_value(conf->advertise_array, prev->advertise_array, NGX_CONF_UNSET_PTR);
    ngx_conf_merge_size_value(conf->min_content_len, prev->min_content_len, 48);
    ngx_conf_merge_uint_value(conf->max_advertise_len, prev->max_advertise_len, 0);
    
#if (NGX_PCRE)
    ngx_conf_merge_ptr_value(conf->black_hosts, prev->black_hosts, NGX_CONF_UNSET_PTR)
#endif

    var = ngx_http_add_variable(cf, &g_advertise_inject_ctx_s, NGX_HTTP_VAR_CHANGEABLE);
    if (var == NULL) {
        return NGX_CONF_ERROR;
    }

    conf->index = ngx_http_get_variable_index(cf, &g_advertise_inject_ctx_s);
    if (conf->index == NGX_ERROR) {
        return NGX_CONF_ERROR;
    }
    
    
    var->get_handler = ngx_http_g_ctx_gethandler;
    var->data = conf->index;

    var = ngx_http_add_variable(cf,  &g_advertise_status_s, NGX_HTTP_VAR_CHANGEABLE);
    var->get_handler = ngx_http_status_gethandler;
    return NGX_CONF_OK;
}
Ejemplo n.º 9
0
static char *
ngx_http_rewrite_variable(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf,
    ngx_str_t *value)
{
    ngx_int_t                    index;
    ngx_http_script_var_code_t  *var_code;

    value->len--;
    value->data++;

    index = ngx_http_get_variable_index(cf, value);

    if (index == NGX_ERROR) {
        return NGX_CONF_ERROR;
    }

    var_code = ngx_http_script_start_code(cf->pool, &lcf->codes,
                                          sizeof(ngx_http_script_var_code_t));
    if (var_code == NULL) {
        return NGX_CONF_ERROR;
    }

    var_code->code = ngx_http_script_var_code;
    var_code->index = index;

    return NGX_CONF_OK;
}
Ejemplo n.º 10
0
static char *
ngx_http_redis_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
    ngx_http_redis_loc_conf_t *rlcf = conf;

    ngx_str_t                 *value;
    ngx_url_t                  u;
    ngx_http_core_loc_conf_t  *clcf;

    if (rlcf->upstream.upstream) {
        return "is duplicate";
    }

    value = cf->args->elts;

    ngx_memzero(&u, sizeof(ngx_url_t));

    u.url = value[1];
    u.no_resolve = 1;

    rlcf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0);
    if (rlcf->upstream.upstream == NULL) {
        return NGX_CONF_ERROR;
    }

    clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);

    clcf->handler = ngx_http_redis_handler;

    if (clcf->name.data[clcf->name.len - 1] == '/') {
        clcf->auto_redirect = 1;
    }

    rlcf->index = ngx_http_get_variable_index(cf, &ngx_http_redis_key);

    if (rlcf->index == NGX_ERROR) {
        return NGX_CONF_ERROR;
    }

    rlcf->db = ngx_http_get_variable_index(cf, &ngx_http_redis_db);

    if (rlcf->db == NGX_ERROR) {
        return NGX_CONF_ERROR;
    }

    return NGX_CONF_OK;
}
Ejemplo n.º 11
0
/*
1. 调用ngx_regex_compile编译正则表达式,并且得到相关的数据,比如子模式数目,命名子模式数目,列表等。
2.	将正则表达式信息存储到ngx_http_regex_t里面,包括正则句柄,子模式数目
3. 	将命名子模式 加入到cmcf->variables_keys和cmcf->variables中。以备后续通过名字查找变量值。*/
ngx_http_regex_t * ngx_http_regex_compile(ngx_conf_t *cf, ngx_regex_compile_t *rc) {
    u_char                     *p;
    size_t                      size;
    ngx_str_t                   name;
    ngx_uint_t                  i, n;
    ngx_http_variable_t        *v;
    ngx_http_regex_t           *re;
    ngx_http_regex_variable_t  *rv;
    ngx_http_core_main_conf_t  *cmcf;

    rc->pool = cf->pool;
    if (ngx_regex_compile(rc) != NGX_OK) {//调用pcre_compile编译正则表达。返回结果存在rc->regex = re;
        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V", &rc->err);
        return NULL;
    }
    re = ngx_pcalloc(cf->pool, sizeof(ngx_http_regex_t));
    if (re == NULL) {
        return NULL;
    }

    re->regex = rc->regex;
    re->ncaptures = rc->captures;//得到$2,$3有多少个。pcre_fullinfo(re, NULL, PCRE_INFO_CAPTURECOUNT, &rc->captures);
    cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
    cmcf->ncaptures = ngx_max(cmcf->ncaptures, re->ncaptures);
    n = (ngx_uint_t) rc->named_captures;//命名的子模式: pcre_fullinfo(re, NULL, PCRE_INFO_NAMECOUNT, &rc->named_captures);
    if (n == 0) {
        return re;
    }
    rv = ngx_palloc(rc->pool, n * sizeof(ngx_http_regex_variable_t));
    if (rv == NULL) {//为每一个命名变量申请空间单独存储。
        return NULL;
    }
    re->variables = rv;//记录这种命名的子模式
    re->nvariables = n;
    re->name = rc->pattern;//记录正则表达式字符串

    size = rc->name_size;
    p = rc->names;//正则的命名子模式的二维表,里面记录了子模式的名称,以及在所有模式中的下标.
    //names是这么得到的: pcre_fullinfo(re, NULL, PCRE_INFO_NAMETABLE, &rc->names);
    //一个命名子模式的二维表存储在p的位置。每一行是一个命名模式,每行的字节数为name_size
    for (i = 0; i < n; i++) {//遍历每一个named_captures,
        rv[i].capture = 2 * ((p[0] << 8) + p[1]);//第一个自己左移8位+第二个字节等于这个命名子模式在所有模式中的下标。
        name.data = &p[2];//第三个字节开始就是命名的名字。
        name.len = ngx_strlen(name.data);//名字长度
		///将这个命名子模式加入到cmcf->variables_keys中
        v = ngx_http_add_variable(cf, &name, NGX_HTTP_VAR_CHANGEABLE);
        if (v == NULL) {
            return NULL;
        }
		//然后从cmcf->variables中查找这个变量对应的下标是多少,如果没有,当然就增加到里面去。
        rv[i].index = ngx_http_get_variable_index(cf, &name);
        if (rv[i].index == NGX_ERROR) {
            return NULL;
        }
        v->get_handler = ngx_http_variable_not_found;//初始化为空函数
        p += size;
    }
    return re;
}
static char *
ngx_http_eval_add_variables(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
    ngx_http_eval_loc_conf_t            *ecf = conf;

    ngx_uint_t                           i;
    ngx_int_t                            index;
    ngx_str_t                           *value;
    ngx_http_variable_t                 *v;
    ngx_http_eval_variable_t            *variable;

    value = cf->args->elts;

    ecf->variables = ngx_array_create(cf->pool,
        cf->args->nelts, sizeof(ngx_http_eval_variable_t));

    if(ecf->variables == NULL) {
        return NGX_CONF_ERROR;
    }

    for(i = 1;i<cf->args->nelts;i++) {
        if (value[i].data[0] != '$') {
            ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                               "invalid variable name \"%V\"", &value[1]);
            return NGX_CONF_ERROR;
        }

        variable = ngx_array_push(ecf->variables);
        if(variable == NULL) {
            return NGX_CONF_ERROR;
        }

        value[i].len--;
        value[i].data++;

        v = ngx_http_add_variable(cf, &value[i], NGX_HTTP_VAR_CHANGEABLE);
        if (v == NULL) {
            return NGX_CONF_ERROR;
        }

        index = ngx_http_get_variable_index(cf, &value[i]);
        if (index == NGX_ERROR) {
            return NGX_CONF_ERROR;
        }

        if (v->get_handler == NULL)
        {
            v->get_handler = ngx_http_eval_variable;
            v->data = index;
        }

        variable->variable = v;
        variable->index = index;
    }

    return NGX_CONF_OK;
}
static char *
ngx_http_auth_request_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
    ngx_http_auth_request_conf_t *arcf = conf;
    ngx_str_t                         *value;
    ngx_http_variable_t               *v;
    ngx_http_auth_request_variable_t  *av;
    ngx_http_compile_complex_value_t   ccv;
    value = cf->args->elts;
    if (value[1].data[0] != '$')
    {
        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                           "invalid variable name \"%V\"", &value[1]);
        return NGX_CONF_ERROR;
    }
    value[1].len--;
    value[1].data++;
    if (arcf->vars == NGX_CONF_UNSET_PTR)
    {
        arcf->vars = ngx_array_create(cf->pool, 1,
                                      sizeof(ngx_http_auth_request_variable_t));
        if (arcf->vars == NULL)
        {
            return NGX_CONF_ERROR;
        }
    }
    av = ngx_array_push(arcf->vars);
    if (av == NULL)
    {
        return NGX_CONF_ERROR;
    }
    v = ngx_http_add_variable(cf, &value[1], NGX_HTTP_VAR_CHANGEABLE);
    if (v == NULL)
    {
        return NGX_CONF_ERROR;
    }
    av->index = ngx_http_get_variable_index(cf, &value[1]);
    if (av->index == NGX_ERROR)
    {
        return NGX_CONF_ERROR;
    }
    if (v->get_handler == NULL)
    {
        v->get_handler = ngx_http_auth_request_variable;
        v->data = (uintptr_t) av;
    }
    av->set_handler = v->set_handler;
    ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
    ccv.cf = cf;
    ccv.value = &value[2];
    ccv.complex_value = &av->value;
    if (ngx_http_compile_complex_value(&ccv) != NGX_OK)
    {
        return NGX_CONF_ERROR;
    }
    return NGX_CONF_OK;
}
static char *
ngx_http_zm_sso_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
{
    ngx_http_zm_sso_loc_conf_t *prev = parent;
    ngx_http_zm_sso_loc_conf_t *conf = child;
    ngx_str_t         host_key;
    ngx_str_t         ssl_client_verify_key;
    ngx_str_t         ssl_client_s_dn_key;

    ngx_conf_merge_uint_value(conf->type, prev->type, NGX_ZM_SSO_CERTAUTH);

    ngx_conf_merge_str_value(conf->redirect_url->url,
                              prev->redirect_url->url, "443");

    ngx_conf_merge_str_value(conf->redirect_schema,
                              prev->redirect_schema, "https");

    conf->redirect_url->no_resolve = 1;
    conf->redirect_url->one_addr = 1;
    conf->redirect_url->listen = 1; /* with this option, the ngx_parse_url accepts
                                       only port case */
    if (ngx_parse_url(cf->pool, conf->redirect_url) != NGX_OK) {
        return NGX_CONF_ERROR;
    }

    if (conf->host_index == NGX_CONF_UNSET) {
        ngx_str_set(&host_key, "host");
        conf->host_index = ngx_http_get_variable_index(cf, &host_key);
    }

    if (conf->ssl_client_verify_index == NGX_CONF_UNSET) {
        ngx_str_set(&ssl_client_verify_key, "ssl_client_verify");
        conf->ssl_client_verify_index = ngx_http_get_variable_index(cf,
                &ssl_client_verify_key);
    }

    if (conf->ssl_client_s_dn_index == NGX_CONF_UNSET) {
        ngx_str_set(&ssl_client_s_dn_key, "ssl_client_s_dn");
        conf->ssl_client_s_dn_index = ngx_http_get_variable_index(cf,
                &ssl_client_s_dn_key);
    }

    return NGX_CONF_OK;
}
Ejemplo n.º 15
0
static char* 
ngx_conf_mcset_set_pass( ngx_conf_t *cf, ngx_command_t *cmd, void *conf ) {
    
    ngx_str_t                 *value;
    ngx_url_t                  u;
    ngx_http_mcset_module_conf_t* mscf;

    mscf = conf;

    if ( mscf->upstream.upstream ) {
        return "is duplicate";
    }

    value = cf->args->elts;

    ngx_memzero( &u, sizeof( ngx_url_t ) );

    u.url = value[1];
    u.no_resolve = 1;

    mscf->upstream.upstream = ngx_http_upstream_add( cf, &u, 0 );
    if ( mscf->upstream.upstream == NULL ) {
        return NGX_CONF_ERROR;
    }

    mscf->key_index = ngx_http_get_variable_index( cf, &ngx_mcset_key );
    if ( mscf->key_index == NGX_ERROR ) {
        return NGX_CONF_ERROR;
    }

    mscf->val_index = ngx_http_get_variable_index( cf, &ngx_mcset_val );
    if ( mscf->val_index == NGX_ERROR ) {
        return NGX_CONF_ERROR;
    }

    mscf->op_index = ngx_http_get_variable_index( cf, &ngx_mcset_op );
    if ( mscf->op_index == NGX_ERROR ) {
        return NGX_CONF_ERROR;
    }

    return NGX_CONF_OK;

}
static char *
ngx_http_hsjson_megre_loc_conf(ngx_conf_t *cf, void *parent, void *child)
{
    u_char *	p;
    ngx_uint_t	i;
    ngx_uint_t	len;
    u_char 		buff[256];

    ngx_http_hsjson_loc_conf_t *prev = parent;
    ngx_http_hsjson_loc_conf_t *conf = child;

    ngx_conf_merge_value(conf->enable, prev->enable, 0);

    if (!conf->enable  == 0) {
        return NGX_CONF_OK;
    }

    ngx_conf_merge_str_value( conf->tablename , prev->tablename , "" );
    ngx_conf_merge_str_value( conf->dbname , prev->dbname , "" );
    ngx_conf_merge_str_value( conf->fieldlist , prev->fieldlist , "" );
    ngx_conf_merge_str_value( conf->indexname , prev->indexname , "PRIMARY" );
    ngx_conf_merge_str_value( conf->hs_operation , prev->hs_operation , "=" );

    ngx_conf_merge_uint_value( conf->limit , prev->limit , 10 );

    ngx_conf_merge_str_value( conf->host , prev->host , "127.0.0.1" );
    ngx_conf_merge_uint_value( conf->port , prev->port , 9998 );

    conf->hs_field_count = 1;
    i = 0;
    p = conf->fieldlist.data;
    while (++i < conf->fieldlist.len) {
        if (*(++p) == ',')
            ++conf->hs_field_count;
    }

    if (conf->fieldlist.len) {
        bzero(buff,256);
        ngx_sprintf( buff, "P\t0\t%s\t%s\t%s\t%s\n", conf->dbname.data, conf->tablename.data,conf->indexname.data,conf->fieldlist.data);

        len = ngx_strlen(buff);
        p = ngx_pcalloc(cf->pool, len);
        ngx_copy(p,buff,len);
        conf->hs_command.data = p;
        conf->hs_command.len = len;
    }

    ngx_str_t str = ngx_string("hs_request");
    conf->variable_index = ngx_http_get_variable_index(cf, &str);

    if (!conf->variable_index)
        ngx_log_error(NGX_LOG_EMERG, cf->log, 0, "The variable '$hs_request' is undefined");

    return NGX_CONF_OK;
}
static char *hexin_http_scribe_init(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
	hexin_http_scribe_loc_conf_t *loc_conf = conf;
	hexin_http_scribe_python = ngx_palloc(cf->pool, sizeof(hexin_http_scribe_python_t));
		
	Py_Initialize();
	 // 检查初始化是否成功
	if (!Py_IsInitialized() ) {
		return NGX_CONF_ERROR;
	}
	
	PyRun_SimpleString("import sys");   
	PyRun_SimpleString((char*)loc_conf->scribe_python_workspace.data); 
	hexin_http_scribe_python->pModule = PyImport_ImportModule((char*)loc_conf->scribe_python_filename.data); 
	if (!hexin_http_scribe_python->pModule) {  
		printf("can't find ScribeClient.py");  
		getchar();
		return NGX_CONF_ERROR;  
	} 
	hexin_http_scribe_python->pDict = PyModule_GetDict(hexin_http_scribe_python->pModule);  
	if (!hexin_http_scribe_python->pDict) {
		return NGX_CONF_ERROR;  
	}  
	hexin_http_scribe_python->pScriberClientClass = PyDict_GetItemString(hexin_http_scribe_python->pDict, (char*)loc_conf->scribe_python_classname.data);
	if (!hexin_http_scribe_python->pScriberClientClass || !PyClass_Check(hexin_http_scribe_python->pScriberClientClass)) {
		return NGX_CONF_ERROR;  
	}

	PyObject *pArgs = PyTuple_New(3);
	PyTuple_SetItem(pArgs, 0, Py_BuildValue("s",loc_conf->scribe_host.data));
	PyTuple_SetItem(pArgs, 1, Py_BuildValue("s",loc_conf->scribe_port.data));
	PyTuple_SetItem(pArgs, 2, Py_BuildValue("b","False"));
	hexin_http_scribe_python->pScriberClient = PyInstance_New(hexin_http_scribe_python->pScriberClientClass, pArgs, NULL);
	 
	if (!hexin_http_scribe_python->pScriberClient) { 
		return NGX_CONF_ERROR;  
	}
	hexin_http_scribe_python->isinit = 1;
   
	ngx_http_complex_value_t  cv; 
    	ngx_memzero(&cv, sizeof(ngx_http_complex_value_t));
	cv.value.len = success_submit.len;
	cv.value.data = success_submit.data;
	hexin_http_scribe_python->success_response = cv;
	loc_conf->message_index = ngx_http_get_variable_index(cf, &message_flag);

	ngx_http_core_loc_conf_t  *clcf;

    	clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);

    	clcf->handler = hexin_http_scribe_handler;

    	return NGX_CONF_OK;
}
//publisher and subscriber handlers now.
static char *ngx_http_push_setup_handler(ngx_conf_t *cf, void * conf, ngx_int_t (*handler)(ngx_http_request_t *)) {
  ngx_http_core_loc_conf_t       *clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
  ngx_http_push_loc_conf_t       *plcf = conf;
  clcf->handler = handler;
  clcf->if_modified_since = NGX_HTTP_IMS_OFF;
  plcf->index = ngx_http_get_variable_index(cf, &ngx_http_push_channel_id);
  if (plcf->index == NGX_ERROR) {
    return NGX_CONF_ERROR;
  }
  return NGX_CONF_OK;
}
Ejemplo n.º 19
0
static char *
ngx_http_memcached_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) {
	ngx_http_memcached_loc_conf_t   *mlcf;
	ngx_http_core_loc_conf_t        *clcf;
	ngx_str_t                       *value;
	ngx_url_t                        url;

	mlcf = conf;
	if (mlcf->upstream.upstream) return "is duplicate";

	value = cf->args->elts;

	ngx_memzero(&url, sizeof(ngx_url_t));
	url.url = value[1];
	url.no_resolve = 1;
	if (!(mlcf->upstream.upstream = ngx_http_upstream_add(cf, &url, 0)))
		return NGX_CONF_ERROR;

	clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
	clcf->handler = ngx_http_memcached_handler;

	if (clcf->name.data[clcf->name.len - 1] == '/')
		clcf->auto_redirect = 1;

	/* define customer variable */
	if (NGX_ERROR == (mlcf->key = ngx_http_get_variable_index(cf,
		&ngx_http_memcached_key)))
		return NGX_CONF_ERROR;
	if (NGX_ERROR == (mlcf->flags = ngx_http_get_variable_index(cf,
		&ngx_http_memcached_flags)))
		return NGX_CONF_ERROR;
	if (NGX_ERROR == (mlcf->exptime = ngx_http_get_variable_index(cf,
		&ngx_http_memcached_exptime)))
		return NGX_CONF_ERROR;
	if (NGX_ERROR == (mlcf->unique = ngx_http_get_variable_index(cf,
		&ngx_http_memcached_unique)))
		return NGX_CONF_ERROR;

	return NGX_CONF_OK;
}
static char *
ngx_http_recaptcha_merge_conf(ngx_conf_t *cf, void *parent, void *child)
{
    ngx_str_t                  body = ngx_string("request_body");
    ngx_http_recaptcha_conf_t *conf = child;

    conf->body_index = ngx_http_get_variable_index(cf, &body);
    if (conf->body_index == (ngx_uint_t) NGX_ERROR) {
        return NGX_CONF_ERROR;
    }

    return NGX_CONF_OK;
}
Ejemplo n.º 21
0
static char *
ndk_set_var_name (ndk_set_var_info_t *info, ngx_str_t *varname)
{
    ngx_int_t                        index;
    ngx_http_variable_t             *v;
    ngx_conf_t                      *cf;
    ndk_http_rewrite_loc_conf_t     *rlcf;
    ngx_str_t                        name;

    name = *varname;

    cf = info->cf;
    rlcf = ngx_http_conf_get_module_loc_conf (cf, ngx_http_rewrite_module);

    if (name.data[0] != '$') {
        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                           "invalid variable name \"%V\"", &name);
        return NGX_CONF_ERROR;
    }

    name.len--;
    name.data++;

    v = ngx_http_add_variable (cf, &name, NGX_HTTP_VAR_CHANGEABLE);
    if (v == NULL) {
        return NGX_CONF_ERROR;
    }

    index = ngx_http_get_variable_index (cf, &name);
    if (index == NGX_ERROR) {
        return NGX_CONF_ERROR;
    }

    if (v->get_handler == NULL
        && ngx_strncasecmp(name.data, (u_char *) "arg_", 4) != 0
        && ngx_strncasecmp(name.data, (u_char *) "cookie_", 7) != 0
        && ngx_strncasecmp(name.data, (u_char *) "http_", 5) != 0
        && ngx_strncasecmp(name.data, (u_char *) "sent_http_", 10) != 0
        && ngx_strncasecmp(name.data, (u_char *) "upstream_http_", 14) != 0)
    {
        v->get_handler = ndk_http_rewrite_var;
        v->data = index;
    }

    info->v = v;
    info->index = index;
    info->rlcf = rlcf;

    return  NGX_CONF_OK;
}
// Parse the jsonp directive
static char * ngx_http_jsonp_directive_jsonp(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
    // Actually, we just get the index of the variable for the config object
    // then let the built-in flag processing function do the rest
    ngx_http_jsonp_conf_t * jsonp_cf = conf;
    jsonp_cf->variable_index = ngx_http_get_variable_index(cf, &ngx_http_jsonp_callback_variable_name);

    if (jsonp_cf->variable_index == NGX_ERROR)
    {
        return NGX_CONF_ERROR;
    }

    return ngx_conf_set_flag_slot(cf, cmd, conf);
}
static ngx_int_t
ngx_lcb_add_variable(ngx_conf_t *cf, ngx_str_t *name)
{
    ngx_http_variable_t *v;

    v = ngx_http_add_variable(cf, name, NGX_HTTP_VAR_CHANGEABLE);
    if (v == NULL) {
        return NGX_ERROR;
    }

    v->get_handler = ngx_lcb_variable_not_found;

    return ngx_http_get_variable_index(cf, name);
}
static char *
ngx_http_limit_req2_whitelist(ngx_conf_t *cf, ngx_command_t *cmd,
    void *conf)
{
    ngx_http_limit_req2_conf_t  *lrcf = conf;

    ngx_str_t              *value, s;
    ngx_uint_t              i;

    value = cf->args->elts;

    for (i = 1; i < cf->args->nelts; i++) {
        if (ngx_strncmp(value[i].data, "geo_var_name=", 13) == 0) {

            s.len = value[i].len - 13;
            s.data = value[i].data + 13;

            lrcf->geo_var_name = s;

            lrcf->geo_var_index = ngx_http_get_variable_index(cf,
                &lrcf->geo_var_name);

            if (lrcf->geo_var_index == NGX_ERROR) {
                return NGX_CONF_ERROR;
            }

            continue;
        }

        if (ngx_strncmp(value[i].data, "geo_var_value=", 14) == 0) {

            s.len = value[i].len - 14;
            s.data = value[i].data + 14;

            lrcf->geo_var_value = s;

            continue;
        }

        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                           "invalid parameter \"%V\"", &value[i]);
        return NGX_CONF_ERROR;
    }

    return NGX_CONF_OK;
}
Ejemplo n.º 25
0
static ngx_int_t
ngx_http_log_variable_compile(ngx_conf_t *cf, ngx_http_log_op_t *op,
    ngx_str_t *value)
{
    ngx_int_t  index;

    index = ngx_http_get_variable_index(cf, value);
    if (index == NGX_ERROR) {
        return NGX_ERROR;
    }

    op->len = 0;
    op->getlen = ngx_http_log_variable_getlen;
    op->run = ngx_http_log_variable;
    op->data = index;

    return NGX_OK;
}
Ejemplo n.º 26
0
static ngx_int_t
ngx_http_log_variable_compile(ngx_conf_t *cf, ngx_http_log_op_t *op,
    ngx_str_t *value)
{
		syslog(LOG_INFO, "[%s:%s:%d]", __FILE__, __func__, __LINE__);
    ngx_int_t  index;

    index = ngx_http_get_variable_index(cf, value);
    if (index == NGX_ERROR) {
        return NGX_ERROR;
    }

    op->len = 0;
    op->getlen = ngx_http_log_variable_getlen;
    op->run = ngx_http_log_variable;
    op->data = index;

    return NGX_OK;
}
static char *
ngx_http_txtlower(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
    ngx_str_t                           *value;
    ngx_http_variable_t                 *v;
    ngx_int_t                           *input_var_index;

    value = cf->args->elts;

    if (value[1].data[0] != '$') {
        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                           "invalid variable name \"%V\"", &value[1]);
        return NGX_CONF_ERROR;
    }

    if (value[2].data[0] != '$') {
        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                           "invalid variable name \"%V\"", &value[2]);
        return NGX_CONF_ERROR;
    }

    value[1].len--;
    value[1].data++;
    value[2].len--;
    value[2].data++;

    v = ngx_http_add_variable(cf, &value[2], NGX_HTTP_VAR_CHANGEABLE);
    if (v == NULL) {
        return NGX_CONF_ERROR;
    }

    v->get_handler = ngx_http_txtset_lowervariable;

    input_var_index = ngx_pcalloc(cf->pool, sizeof(ngx_int_t));

    *input_var_index = ngx_http_get_variable_index(cf, &value[1]);

    v->data = (uintptr_t) input_var_index;

    return NGX_CONF_OK;
}
static char *
ngx_http_filter_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
    ngx_http_filter_cache_conf_t *lcf = conf;
    ngx_http_core_loc_conf_t  *core_conf = NULL;
    ngx_str_t  *value = NULL;

    value = cf->args->elts;

    if (ngx_strcmp(value[1].data, "off") == 0) {
        lcf->upstream.cache = NULL;
        return NGX_CONF_OK;
    }

    if (lcf->upstream.cache != NGX_CONF_UNSET_PTR) {
        return "is duplicate";
    }

    lcf->index = ngx_http_get_variable_index(cf, &ngx_http_filter_cache_key);

    if (lcf->index == NGX_ERROR) {
        return NGX_CONF_ERROR;
    }

    lcf->upstream.cache = ngx_shared_memory_add(cf, &value[1], 0,
                                       &ngx_http_filter_cache_module);
    if (lcf->upstream.cache == NULL) {
        return NGX_CONF_ERROR;
    }

    core_conf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
    lcf->orig_handler = core_conf->handler;
    if(conf->handler) {
        core_conf->handler = ngx_http_filter_cache_handler;
    }
    return NGX_CONF_OK;
}
static ngx_int_t
ngx_http_limit_speed_init(ngx_conf_t *cf)
{
    ngx_http_handler_pt        *h;
    ngx_http_core_main_conf_t  *cmcf;

    cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);

    h = ngx_array_push(&cmcf->phases[NGX_HTTP_PREACCESS_PHASE].handlers);
    if (h == NULL) {
        return NGX_ERROR;
    }

    *h = ngx_http_limit_speed_handler;

    ngx_http_limit_speed_ctx_var_index =
        ngx_http_get_variable_index(cf, &ngx_http_limit_speed_ctx_var_name);

    if (ngx_http_limit_speed_ctx_var_index == NGX_ERROR) {
        return NGX_ERROR;
    }

    return NGX_OK;
}
/*
 * Based on: ngx_http_rewrite_module.c/ngx_http_rewrite_set
 * Copyright (C) Igor Sysoev
 */
char *
ngx_postgres_conf_escape(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
    ngx_str_t                           *value = cf->args->elts;
    ngx_str_t                            src = value[cf->args->nelts - 1];
    ngx_int_t                            index;
    ngx_http_variable_t                 *v;
    ngx_http_script_var_code_t          *vcode;
    ngx_http_script_var_handler_code_t  *vhcode;
    ngx_postgres_rewrite_loc_conf_t     *rlcf;
    ngx_postgres_escape_t               *pge;
    ngx_str_t                            dst;
    ngx_uint_t                           empty;

    dd("entering");

    if ((src.len != 0) && (src.data[0] == '=')) {
        empty = 1;
        src.len--;
        src.data++;
    } else {
        empty = 0;
    }

    if (src.len == 0) {
        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                           "postgres: empty value in \"%V\" directive",
                           &cmd->name);

        dd("returning NGX_CONF_ERROR");
        return NGX_CONF_ERROR;
    }

    if (cf->args->nelts == 2) {
        dst = src;
    } else {
        dst = value[1];
    }

    if (dst.len < 2) {
        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                           "postgres: empty variable name in \"%V\" directive",
                           &cmd->name);

        dd("returning NGX_CONF_ERROR");
        return NGX_CONF_ERROR;
    }

    if (dst.data[0] != '$') {
        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                           "postgres: invalid variable name \"%V\""
                           " in \"%V\" directive", &dst, &cmd->name);

        dd("returning NGX_CONF_ERROR");
        return NGX_CONF_ERROR;
    }

    dst.len--;
    dst.data++;

    v = ngx_http_add_variable(cf, &dst, NGX_HTTP_VAR_CHANGEABLE);
    if (v == NULL) {
        dd("returning NGX_CONF_ERROR");
        return NGX_CONF_ERROR;
    }

    index = ngx_http_get_variable_index(cf, &dst);
    if (index == NGX_ERROR) {
        dd("returning NGX_CONF_ERROR");
        return NGX_CONF_ERROR;
    }

    if (v->get_handler == NULL
        && ngx_strncasecmp(dst.data, (u_char *) "http_", 5) != 0
        && ngx_strncasecmp(dst.data, (u_char *) "sent_http_", 10) != 0
        && ngx_strncasecmp(dst.data, (u_char *) "upstream_http_", 14) != 0)
    {
        v->get_handler = ngx_postgres_rewrite_var;
        v->data = index;
    }

    rlcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_rewrite_module);

    if (ngx_postgres_rewrite_value(cf, rlcf, &src) != NGX_CONF_OK) {
        dd("returning NGX_CONF_ERROR");
        return NGX_CONF_ERROR;
    }

    pge = ngx_http_script_start_code(cf->pool, &rlcf->codes,
                                     sizeof(ngx_postgres_escape_t));
    if (pge == NULL) {
        dd("returning NGX_CONF_ERROR");
        return NGX_CONF_ERROR;
    }

    pge->code = ngx_postgres_escape_string;
    pge->empty = empty;

    if (v->set_handler) {
        vhcode = ngx_http_script_start_code(cf->pool, &rlcf->codes,
                                   sizeof(ngx_http_script_var_handler_code_t));
        if (vhcode == NULL) {
            dd("returning NGX_CONF_ERROR");
            return NGX_CONF_ERROR;
        }

        vhcode->code = ngx_http_script_var_set_handler_code;
        vhcode->handler = v->set_handler;
        vhcode->data = v->data;

        dd("returning NGX_CONF_OK");
        return NGX_CONF_OK;
    }

    vcode = ngx_http_script_start_code(cf->pool, &rlcf->codes,
                                       sizeof(ngx_http_script_var_code_t));
    if (vcode == NULL) {
        dd("returning NGX_CONF_ERROR");
        return NGX_CONF_ERROR;
    }

    vcode->code = ngx_http_script_set_var_code;
    vcode->index = (uintptr_t) index;

    dd("returning NGX_CONF_OK");
    return NGX_CONF_OK;
}