static char *ngx_http_hello_counter(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_hello_loc_conf_t* local_conf; ngx_http_core_loc_conf_t *clcf; clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); local_conf = conf; char* rv = NULL; rv = ngx_conf_set_flag_slot(cf, cmd, conf); ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "hello_counter:%d", local_conf->hello_counter); return rv; }
static char * passenger_enabled(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { passenger_loc_conf_t *passenger_conf = conf; ngx_http_core_loc_conf_t *clcf; ngx_str_t *value; ngx_url_t upstream_url; value = cf->args->elts; if (ngx_strcasecmp(value[1].data, (u_char *) "on") == 0) { passenger_conf->enabled = 1; /* Register a placeholder value as upstream address. The real upstream * address (the helper agent socket filename) will be set while processing * requests, because we can't start the helper agent until config * loading is done. */ ngx_memzero(&upstream_url, sizeof(ngx_url_t)); upstream_url.url = pp_placeholder_upstream_address; upstream_url.no_resolve = 1; passenger_conf->upstream_config.upstream = ngx_http_upstream_add(cf, &upstream_url, 0); if (passenger_conf->upstream_config.upstream == NULL) { return NGX_CONF_ERROR; } clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); clcf->handler = passenger_content_handler; if (clcf->name.data != NULL && clcf->name.data[clcf->name.len - 1] == '/') { clcf->auto_redirect = 1; } } else if (ngx_strcasecmp(value[1].data, (u_char *) "off") == 0) { passenger_conf->enabled = 0; } else { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "\"passenger_enabled\" must be either set to \"on\" " "or \"off\""); return NGX_CONF_ERROR; } return NGX_CONF_OK; }
static char * ngx_http_aclog_bypass_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) { uintptr_t *code; ngx_uint_t i; ngx_http_log_loc_conf_t *lcf; ngx_http_aclog_bypass_conf_t *conf = child; ngx_http_aclog_bypass_conf_t *prev = parent; ngx_http_aclog_bypass_condition_t *condition; lcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_log_module); conf->log_off = lcf->off; if (lcf->off || lcf->logs == NULL) { return NGX_CONF_OK; } if (conf->conditions == NULL) { conf->conditions = prev->conditions; } if (conf->conditions == prev->conditions) { return NGX_CONF_OK; } condition = conf->conditions->elts; for (i = 0; i < conf->conditions->nelts; i++) { code = ngx_array_push_n(condition[i].codes, sizeof(uintptr_t)); if (code == NULL) { return NGX_CONF_ERROR; } *code = (uintptr_t) NULL; } if (condition[conf->conditions->nelts - 1].is_and) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "can not use \"and\" flag on the last condition"); return NGX_CONF_ERROR; } return NGX_CONF_OK; }
static char * ngx_http_memcached_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_memcached_loc_conf_t *lcf = conf; ngx_str_t *value; ngx_url_t u; ngx_http_core_loc_conf_t *clcf; if (lcf->upstream.schema.len) { return "is duplicate"; } value = cf->args->elts; ngx_memzero(&u, sizeof(ngx_url_t)); u.url = value[1]; u.no_resolve = 1; lcf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0); if (lcf->upstream.upstream == NULL) { return NGX_CONF_ERROR; } lcf->upstream.schema.len = sizeof("memcached://") - 1; lcf->upstream.schema.data = (u_char *) "memcached://"; 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; } lcf->index = ngx_http_get_variable_index(cf, &ngx_http_memcached_key); if (lcf->index == NGX_ERROR) { return NGX_CONF_ERROR; } return NGX_CONF_OK; }
static char *ngx_http_upstream_dynamic_servers_merge_conf(ngx_conf_t *cf, void *parent, void *child) { // If any dynamic servers are present, verify that a "resolver" is setup as // the http level. ngx_http_upstream_dynamic_server_main_conf_t *udsmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_upstream_dynamic_servers_module); if (udsmcf->dynamic_servers.nelts > 0) { ngx_http_core_loc_conf_t *core_loc_conf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); #if nginx_version >= 1009011 if (core_loc_conf->resolver == NULL || core_loc_conf->resolver->connections.nelts == 0) { #else if (core_loc_conf->resolver == NULL || core_loc_conf->resolver->udp_connections.nelts == 0) { #endif ngx_conf_log_error(NGX_LOG_ERR, cf, 0, "resolver must be defined at the 'http' level of the config"); return NGX_CONF_ERROR; } udsmcf->conf_ctx = cf->ctx; udsmcf->resolver = core_loc_conf->resolver; ngx_conf_merge_msec_value(udsmcf->resolver_timeout, core_loc_conf->resolver_timeout, 30000); } return NGX_CONF_OK; } static ngx_int_t ngx_http_upstream_dynamic_servers_init_process(ngx_cycle_t *cycle) { ngx_http_upstream_dynamic_server_main_conf_t *udsmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_upstream_dynamic_servers_module); ngx_http_upstream_dynamic_server_conf_t *dynamic_server = udsmcf->dynamic_servers.elts; ngx_uint_t i; ngx_event_t *timer; ngx_uint_t refresh_in; for (i = 0; i < udsmcf->dynamic_servers.nelts; i++) { timer = &dynamic_server[i].timer; timer->handler = ngx_http_upstream_dynamic_server_resolve; timer->log = cycle->log; timer->data = &dynamic_server[i]; refresh_in = ngx_random() % 1000; ngx_log_debug(NGX_LOG_DEBUG_CORE, cycle->log, 0, "upstream-dynamic-servers: Initial DNS refresh of '%V' in %ims", &dynamic_server[i].host, refresh_in); ngx_add_timer(timer, refresh_in); } return NGX_OK; }
static char * ngx_http_proxy_connect_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_proxy_connect_loc_conf_t *plcf = conf; ngx_str_t *value, *url; ngx_uint_t n; ngx_http_core_loc_conf_t *clcf; ngx_http_script_compile_t sc; if (plcf->upstream.upstream || plcf->proxy_lengths) { return "is duplicate"; } clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); clcf->handler = ngx_http_proxy_connect_handler; value = cf->args->elts; url = &value[1]; n = ngx_http_script_variables_count(url); if (n) { ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); sc.cf = cf; sc.source = url; sc.lengths = &plcf->proxy_lengths; sc.values = &plcf->proxy_values; sc.variables = n; sc.complete_lengths = 1; sc.complete_values = 1; if (ngx_http_script_compile(&sc) != NGX_OK) { return NGX_CONF_ERROR; } } return NGX_CONF_OK; }
static char * ngx_http_perl(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_perl_loc_conf_t *plcf = conf; ngx_str_t *value; ngx_http_core_loc_conf_t *clcf; ngx_http_perl_main_conf_t *pmcf; value = cf->args->elts; if (plcf->handler.data) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "duplicate perl handler \"%V\"", &value[1]); 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; } } plcf->handler = value[1]; { dTHXa(pmcf->perl); PERL_SET_CONTEXT(pmcf->perl); ngx_http_perl_eval_anon_sub(aTHX_ & value[1], &plcf->sub); if (plcf->sub == &PL_sv_undef) { ngx_conf_log_error(NGX_LOG_ERR, cf, 0, "eval_pv(\"%V\") failed", &value[1]); return NGX_CONF_ERROR; } if (plcf->sub == NULL) { plcf->sub = newSVpvn((char *) value[1].data, value[1].len); } } clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); clcf->handler = ngx_http_perl_handler; return NGX_CONF_OK; }
static char * ngx_http_google_inject_subs_domain(ngx_conf_t * cf) { ngx_http_google_loc_conf_t * glcf; glcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_google_filter_module); ngx_http_core_srv_conf_t *cscf; cscf = ngx_http_conf_get_module_srv_conf(cf, ngx_http_core_module); ngx_uint_t i, len = 512; char * sns_htp, * sns_ssl; ngx_http_server_name_t * sns = cscf->server_names.elts, * sn; for (i = 0; i < cscf->server_names.nelts; i++) { sn = sns + i; if (!sn->name.len) continue; sns_htp = ngx_pcalloc(cf->pool, len + 1); if (!sns_htp) return NGX_CONF_ERROR; sns_ssl = ngx_pcalloc(cf->pool, len + 1); if (!sns_ssl) return NGX_CONF_ERROR; ngx_snprintf((u_char *)sns_htp, len, "http://%V", &sn->name); ngx_snprintf((u_char *)sns_ssl, len, "https://%V", &sn->name); if (glcf->ssl) { if (ngx_http_google_inject_subs_args(cf, "subs_filter", 2, sns_htp, sns_ssl)) return NGX_CONF_ERROR; } else { if (ngx_http_google_inject_subs_args(cf, "subs_filter", 2, sns_ssl, sns_htp)) return NGX_CONF_ERROR; } } return NGX_CONF_OK; }
static char* ngx_http_test_check(ngx_conf_t*cf,ngx_command_t*cmd,void*conf) { ngx_http_core_loc_conf_t *clcf; ngx_str_t *value; clcf=ngx_http_conf_get_module_loc_conf(cf,ngx_http_core_module); value=cf->args->elts; if(ngx_strncmp(value[1].data,"on",2)==0){ clcf->handler=ngx_http_test_check_handler; }else if (ngx_strncmp(value[1].data,"off",3)==0){ clcf->handler=NULL; }else{ return "Invalid args"; } return NGX_CONF_OK; }
static char * ngx_http_js_content(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_js_loc_conf_t *jlcf = conf; ngx_str_t *value; ngx_http_core_loc_conf_t *clcf; if (jlcf->content.data) { return "is duplicate"; } value = cf->args->elts; jlcf->content = value[1]; clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); clcf->handler = ngx_http_js_handler; return NGX_CONF_OK; }
static char * ngx_http_session_show(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_str_t *value; ngx_http_core_loc_conf_t *clcf; ngx_http_session_conf_t *sscf = conf; value = cf->args->elts; if (!strncmp((char *)(value[1].data), "on", value[1].len)) { sscf->session_show_enabled = 1; } if (sscf->session_show_enabled) { clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); clcf->handler = ngx_http_session_show_handler; } return NGX_CONF_OK; }
static char * ngx_http_traffic_status_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_uint_t i; ngx_str_t *value; ngx_http_core_loc_conf_t *clcf = NULL; ngx_http_traffic_status_local_conf_t *tslc = conf; value = cf->args->elts; for (i = 1; i < cf->args->nelts; i++) { if (ngx_strcasecmp(value[i].data, (u_char *) "request_times") == 0) { tslc->req_flag = 1; continue; } else if (ngx_strcasecmp(value[i].data, (u_char *) "packet_bytes") == 0) { tslc->pkt_flag = 1; continue; } else if (ngx_strcasecmp(value[i].data, (u_char *) "status_codes") == 0) { tslc->status_flag = 1; continue; } else { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid value \"%s\" in \"%s\" directive", value[i].data, cmd->name.data); return NGX_CONF_ERROR; } } clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); clcf->handler = ngx_http_traffic_status_handler; return NGX_CONF_OK; }
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; }
/* * 在解析show_param命令时执行的解析函数: 将show_param(含义:一个bool值)转换为 * 0或者1,0代表不启用访问计数,1代表启用访问计数 * */ static char *ngx_http_show_param(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_show_param_loc_conf_t* local_conf; local_conf = conf; char* rv = NULL; /* ngx_conf_set_flag_slot:把“on”和“off”转成1和0,并保存到配置文件结构体中 */ rv = ngx_conf_set_flag_slot(cf, cmd, conf); ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "ngx_http_show_param: show_param:%d", local_conf->enable); // 按需挂载处理函数handler ngx_http_core_loc_conf_t *clcf; clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); clcf->handler = ngx_http_show_param_handler; ngx_conf_log_error(NGX_LOG_EMERG, cf , 0, "show_param: handler hooked\n"); return rv; }
static char * ngx_http_trackuri(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_trackuri_loc_conf_t *flcf = conf; if (flcf->track_uri != NGX_CONF_UNSET) { return "is duplicate"; } ngx_str_t *value = cf->args->elts; if (ngx_strcasecmp(value[1].data, (u_char *) "on") == 0) { flcf->track_uri = 1; } else if (ngx_strcasecmp(value[1].data, (u_char *) "off") == 0) { flcf->track_uri = 0; } else { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid value \"%s\" in \"%s\" directive, " "it must be \"on\" or \"off\"", value[1].data, cmd->name.data); return NGX_CONF_ERROR; } if (flcf->track_uri == 1) { ngx_http_core_loc_conf_t *clcf; clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); clcf->handler = ngx_http_trackuri_handler; // initialize uri_table to start tracking popular uris if (!ngx_uri_table_init(cf->pool, cf->log, &flcf->uri_table)) return NGX_CONF_ERROR; ngx_conf_log_error(NGX_LOG_WARN, cf, 0, "Initialized hash table of size: \"%d\"", flcf->uri_table.hash_table->size); } return NGX_CONF_OK; }
static char* ngx_conf_set_echo(ngx_conf_t *cf, ngx_command_t *cmd, void* conf) { ngx_http_core_loc_conf_t* clcf; //ngx_str_t *value; //ngx_url_t u; /** ngx_http_echov4_loc_conf_t* elcf = (ngx_http_echov4_loc_conf_t*) conf; ngx_log_debug0(NGX_LOG_DEBUG_HTTP, cf->log, 0, "ngx_conf_set_echo called - [rainx]"); value = cf->args->elts; u.url = value[1]; u.no_resolve = 1; elcf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0); if (elcf->upstream.upstream == NULL){ return NGX_CONF_ERROR; } **/ clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); clcf->handler = ngx_http_mytest_handler; //设置handler return NGX_CONF_OK; }
char* ngx_lua_content_readconf(ngx_conf_t* cf, ngx_command_t* cmd, void* conf) { ngx_str_t* value; ngx_http_core_loc_conf_t* pconf; ngx_http_compile_complex_value_t ccv; ngx_lua_loc_conf_t* plocconf = conf; dbg("ngx_lua_content_readconf\n"); value = cf->args->elts; if (value[1].len == 0) { ngx_conf_log_error(NGX_LOG_ERR, cf, 0, "invalid location config: no runable lua code"); return NGX_CONF_ERROR; } ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); ccv.cf = cf; ccv.value = &value[1]; pconf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); if (ngx_strcmp(cmd->name.data, "lua_content") == 0) { ccv.complex_value = &plocconf->lua_content_code; pconf->handler = ngx_lua_content_handler; } else { ccv.complex_value = &plocconf->lua_content_file; pconf->handler = ngx_lua_content_by_file_handler; } if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { pconf->handler = NULL; ngx_conf_log_error(NGX_LOG_ERR, cf, 0, "invalid location config: ngx_http_compile_complex_value error"); return NGX_CONF_ERROR; } return NGX_CONF_OK; }
static char * ngx_http_parallel_command(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_core_loc_conf_t *clcf; ngx_str_t *field, *value; // set up handler clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); clcf->handler = ngx_http_parallel_handler; // save the uri prefix param field = &((ngx_http_parallel_loc_conf_t*)conf)->uri_prefix; if (field->data) { return "is duplicate"; } value = cf->args->elts; *field = value[1]; return NGX_CONF_OK; }
char *ngx_http_set_kafka_topic(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_core_loc_conf_t *clcf; ngx_http_kafka_loc_conf_t *local_conf; /* install ngx_http_kafka_handler */ clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); if (clcf == NULL) { return NGX_CONF_ERROR; } clcf->handler = ngx_http_kafka_handler; /* ngx_http_kafka_loc_conf_t::topic assignment */ if (ngx_conf_set_str_slot(cf, cmd, conf) != NGX_CONF_OK) { return NGX_CONF_ERROR; } local_conf = conf; local_conf->rktc = rd_kafka_topic_conf_new(); return NGX_CONF_OK; }
static char * ngx_http_image(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_str_t *value; value = cf->args->elts; if (ngx_strcasecmp(value[1].data, (u_char *) "on") == 0) { ngx_http_core_loc_conf_t *clcf; clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); clcf->handler = ngx_http_image_handler; return NGX_CONF_OK; } else if (ngx_strcasecmp(value[1].data, (u_char *) "off") == 0) { return NGX_CONF_OK; } else { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,"invalid value \"%s\" in \"%s\" directive, ""it must be \"on\" or \"off\"",value[1].data, cmd->name.data); return NGX_CONF_ERROR; } return NGX_CONF_OK; }
static char * ngx_http_weixin_auth_merge_conf(ngx_conf_t *cf, void *parent, void *child) { ngx_http_weixin_auth_loc_conf_t *prev = parent; ngx_http_weixin_auth_loc_conf_t *conf = child; ngx_http_core_loc_conf_t *clcf; ngx_conf_merge_value(conf->enable, prev->enable, 0); ngx_conf_merge_str_value(conf->token, prev->token, "token"); if (conf->enable) { clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); if (clcf->handler != NULL) { conf->original_handler = clcf->handler; clcf->handler = ngx_http_weixin_auth_access_handler; } else { clcf->handler = ngx_http_weixin_auth_handler; } } 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)) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,ctx->get_error_message(ctx)); return NGX_CONF_ERROR; } mapcache_configuration_post_config(ctx, ctx->config); if(GC_HAS_ERROR(ctx)) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,ctx->get_error_message(ctx)); return NGX_CONF_ERROR; } mapcache_connection_pool_create(&ctx->connection_pool,ctx->pool); ctx->config->non_blocking = 1; 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; }
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; }
char * ngx_http_psgi(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_psgi_loc_conf_t *psgilcf = conf; ngx_str_t *value; ngx_http_core_loc_conf_t *clcf; ngx_http_psgi_main_conf_t *psgimcf; value = cf->args->elts; ngx_log_debug1(NGX_LOG_DEBUG_HTTP, cf->log, 0, "Installing psgi handler \"%V\"", &value[1]); if (psgilcf->app != NULL) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "duplicate psgi app \"%V\"", &value[1]); return NGX_CONF_ERROR; } psgimcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_psgi_module); if (psgimcf->perl == NULL) { if (ngx_http_psgi_init_interpreter(cf, psgimcf) != NGX_CONF_OK) { return NGX_CONF_ERROR; } } psgilcf->app = ngx_palloc(cf->pool, value[1].len + 1); ngx_cpymem(psgilcf->app, value[1].data, value[1].len + 1); clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); clcf->handler = ngx_http_psgi_handler; return NGX_CONF_OK; }
static char* ngx_http_mcset_module_merge_loc_conf( ngx_conf_t *cf, void *parent, void *child ) { ngx_http_mcset_module_conf_t* prev = parent; ngx_http_mcset_module_conf_t* conf = child; ngx_http_core_loc_conf_t* clcf; clcf = ngx_http_conf_get_module_loc_conf( cf, ngx_http_core_module ); ngx_conf_merge_msec_value( conf->upstream.connect_timeout, prev->upstream.connect_timeout, 60000 ); ngx_conf_merge_msec_value( conf->upstream.send_timeout, prev->upstream.send_timeout, 60000 ); ngx_conf_merge_msec_value( conf->upstream.read_timeout, prev->upstream.read_timeout, 60000 ); ngx_conf_merge_msec_value( conf->upstream.buffer_size, prev->upstream.buffer_size, 1024 ); if ( conf->upstream.upstream == NULL ) { conf->upstream.upstream = prev->upstream.upstream; } if ( conf->upstream.upstream != NULL ) { clcf->handler = ngx_http_mcset_module_cache_handler; } return NGX_CONF_OK; }
char * ngx_postgres_conf_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_str_t *value = cf->args->elts; ngx_postgres_loc_conf_t *pglcf = conf; ngx_http_core_loc_conf_t *clcf; ngx_http_compile_complex_value_t ccv; ngx_url_t url; dd("entering"); if ((pglcf->upstream.upstream != NULL) || (pglcf->upstream_cv != NULL)) { dd("returning"); return "is duplicate"; } if (value[1].len == 0) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "postgres: empty upstream in \"%V\" directive", &cmd->name); dd("returning NGX_CONF_ERROR"); return NGX_CONF_ERROR; } clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); clcf->handler = ngx_postgres_handler; if (clcf->name.data[clcf->name.len - 1] == '/') { clcf->auto_redirect = 1; } if (ngx_http_script_variables_count(&value[1])) { /* complex value */ dd("complex value"); pglcf->upstream_cv = ngx_palloc(cf->pool, sizeof(ngx_http_complex_value_t)); if (pglcf->upstream_cv == NULL) { dd("returning NGX_CONF_ERROR"); return NGX_CONF_ERROR; } ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); ccv.cf = cf; ccv.value = &value[1]; ccv.complex_value = pglcf->upstream_cv; if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { dd("returning NGX_CONF_ERROR"); return NGX_CONF_ERROR; } dd("returning NGX_CONF_OK"); return NGX_CONF_OK; } else { /* simple value */ dd("simple value"); ngx_memzero(&url, sizeof(ngx_url_t)); url.url = value[1]; url.no_resolve = 1; pglcf->upstream.upstream = ngx_http_upstream_add(cf, &url, 0); if (pglcf->upstream.upstream == NULL) { dd("returning NGX_CONF_ERROR"); return NGX_CONF_ERROR; } dd("returning NGX_CONF_OK"); return NGX_CONF_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; }
char * ngx_http_lua_content_by_lua(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_str_t *value; ngx_http_core_loc_conf_t *clcf; ngx_http_lua_loc_conf_t *llcf = conf; u_char *p; ngx_http_compile_complex_value_t ccv; dd("enter"); /* must specifiy a content handler */ if (cmd->post == NULL) { return NGX_CONF_ERROR; } if (llcf->content_handler) { return "is duplicate"; } value = cf->args->elts; if (value[1].len == 0) { /* Oops...Invalid location conf */ ngx_conf_log_error(NGX_LOG_ERR, cf, 0, "Invalid location config: no runnable Lua code"); return NGX_CONF_ERROR; } if (cmd->post == ngx_http_lua_content_handler_inline) { /* Don't eval nginx variables for inline lua code */ llcf->content_src.value = value[1]; p = ngx_palloc(cf->pool, NGX_HTTP_LUA_INLINE_KEY_LEN + 1); if (p == NULL) { return NGX_CONF_ERROR; } llcf->content_src_key = p; p = ngx_copy(p, NGX_HTTP_LUA_INLINE_TAG, NGX_HTTP_LUA_INLINE_TAG_LEN); p = ngx_http_lua_digest_hex(p, value[1].data, value[1].len); *p = '\0'; } else { ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); ccv.cf = cf; ccv.value = &value[1]; ccv.complex_value = &llcf->content_src; if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { return NGX_CONF_ERROR; } if (llcf->content_src.lengths == NULL) { /* no variable found */ p = ngx_palloc(cf->pool, NGX_HTTP_LUA_FILE_KEY_LEN + 1); if (p == NULL) { return NGX_CONF_ERROR; } llcf->content_src_key = p; p = ngx_copy(p, NGX_HTTP_LUA_FILE_TAG, NGX_HTTP_LUA_FILE_TAG_LEN); p = ngx_http_lua_digest_hex(p, value[1].data, value[1].len); *p = '\0'; } } llcf->content_handler = cmd->post; /* register location content handler */ clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); if (clcf == NULL) { return NGX_CONF_ERROR; } clcf->handler = ngx_http_lua_content_handler; return NGX_CONF_OK; }
/* * Module enable directive. Directive may be in any context. * In main, server and location contexts it statically enables module. * In 'server if' and 'location if' contexts module works through rewrite module codes * by adding own code ngx_http_rdns_enable_code_t. */ static char * rdns_directive(ngx_conf_t * cf, ngx_command_t * cmd, void * conf) { ngx_http_rdns_loc_conf_t * loc_conf = conf; ngx_str_t * value; ngx_http_rdns_common_conf_t cconf; ngx_conf_log_error(NGX_LOG_DEBUG, cf, 0, "rdns directive"); if (loc_conf == NULL) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "internal error"); ngx_conf_log_error(NGX_LOG_DEBUG, cf, 0, "location config NULL pointer"); return NGX_CONF_ERROR; } cconf.enabled = 0; cconf.double_mode = 0; value = cf->args->elts; if (ngx_strcasecmp(value[1].data, (u_char *)"on") == 0) { cconf.enabled = 1; cconf.double_mode = 0; } else if (ngx_strcasecmp(value[1].data, (u_char *)"off") == 0) { cconf.enabled = 0; cconf.double_mode = 0; } else if (ngx_strcasecmp(value[1].data, (u_char *)"double") == 0) { cconf.enabled = 1; cconf.double_mode = 1; } else { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid value \"%s\" in \"%s\" directive, " "it must be \"on\" or \"off\" or \"double\"", value[1].data, cmd->name.data); return NGX_CONF_ERROR; } #ifndef NGX_RDNS_NO_IF if (cf->cmd_type & (NGX_HTTP_LIF_CONF | NGX_HTTP_SIF_CONF)) { ngx_http_rdns_enable_code_t * code; void * rewrite_lcf; /* * Enable code used to determine enabled state in runtime (when processing request). * Enable code should run only in case directive is used inside 'if'. */ ngx_conf_log_error(NGX_LOG_DEBUG, cf, 0, "setup enable code"); rewrite_lcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_rewrite_module); if (rewrite_lcf == NULL) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "internal error"); ngx_conf_log_error(NGX_LOG_DEBUG, cf, 0, "unable to get rewrite location config"); return NGX_CONF_ERROR; } code = ngx_http_script_start_code(cf->pool, (ngx_array_t **)rewrite_lcf, sizeof(ngx_http_rdns_enable_code_t)); if (code == NULL) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "internal error"); ngx_conf_log_error(NGX_LOG_DEBUG, cf, 0, "unable to add enable code to rewrite module"); return NGX_CONF_ERROR; } code->code = enable_code; code->conf = cconf; loc_conf->conf = cconf; } else { /* statically enable module otherwise */ #endif loc_conf->conf = cconf; #ifndef NGX_RDNS_NO_IF } #endif ngx_conf_log_error(NGX_LOG_DEBUG, cf, 0, "(DONE) rdns directive: enabled = %lu, double_mode = %lu", cconf.enabled, cconf.double_mode); return NGX_CONF_OK; }
char * ngx_http_uwsgi_cache_purge_conf(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_compile_complex_value_t ccv; ngx_http_cache_purge_loc_conf_t *cplcf; ngx_http_core_loc_conf_t *clcf; ngx_http_uwsgi_loc_conf_t *ulcf; ngx_str_t *value; cplcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_cache_purge_module); /* check for duplicates / collisions */ if (cplcf->uwsgi.enable != NGX_CONF_UNSET) { return "is duplicate"; } if (cf->args->nelts != 3) { return ngx_http_cache_purge_conf(cf, &cplcf->uwsgi); } if (cf->cmd_type & (NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF)) { return "(separate location syntax) is not allowed here"; } ulcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_uwsgi_module); if (ulcf->upstream.cache != NGX_CONF_UNSET_PTR && ulcf->upstream.cache != NULL) { return "is incompatible with \"uwsgi_cache\""; } if (ulcf->upstream.upstream || ulcf->uwsgi_lengths) { return "is incompatible with \"uwsgi_pass\""; } if (ulcf->upstream.store > 0 || ulcf->upstream.store_lengths) { return "is incompatible with \"uwsgi_store\""; } value = cf->args->elts; /* set uwsgi_cache part */ ulcf->upstream.cache = ngx_shared_memory_add(cf, &value[1], 0, &ngx_http_uwsgi_module); if (ulcf->upstream.cache == NULL) { return NGX_CONF_ERROR; } /* set uwsgi_cache_key part */ ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); ccv.cf = cf; ccv.value = &value[2]; ccv.complex_value = &ulcf->cache_key; if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { return NGX_CONF_ERROR; } /* set handler */ clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); cplcf->uwsgi.enable = 0; clcf->handler = ngx_http_uwsgi_cache_purge_handler; return NGX_CONF_OK; }