static ngx_int_t ngx_rtmp_control_postconfiguration(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_CONTENT_PHASE].handlers); if (h == NULL) { return NGX_ERROR; } *h = ngx_rtmp_control_handler; return NGX_OK; }
static ngx_int_t ngx_http_prelog_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_POST_READ_PHASE].handlers); if (h == NULL) { return NGX_ERROR; } *h = ngx_http_prelog_handler; return NGX_OK; }
static char * ngx_http_identifier_cache_size(ngx_conf_t * cf, ngx_command_t * cmd, void * conf) { ngx_http_hustdb_ha_main_conf_t * mcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_hustdb_ha_module); if (!mcf || 2 != cf->args->nelts) { return "ngx_http_identifier_cache_size error"; } ngx_str_t * value = cf->args->elts; mcf->identifier_cache_size = ngx_atoi(value[1].data, value[1].len); if (NGX_ERROR == mcf->identifier_cache_size) { return "ngx_http_identifier_cache_size error"; } // TODO: you can modify the value here return NGX_CONF_OK; }
static char * ngx_http_identifier_timeout(ngx_conf_t * cf, ngx_command_t * cmd, void * conf) { ngx_http_hustdb_ha_main_conf_t * mcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_hustdb_ha_module); if (!mcf || 2 != cf->args->nelts) { return "ngx_http_identifier_timeout error"; } ngx_str_t * value = cf->args->elts; mcf->identifier_timeout = ngx_parse_time(&value[1], 0); if (NGX_ERROR == mcf->identifier_timeout) { return "ngx_http_identifier_timeout error"; } // TODO: you can modify the value here return NGX_CONF_OK; }
static ngx_int_t ngx_http_request_parser_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_REWRITE_PHASE].handlers); if (h == NULL) { return NGX_ERROR; } *h = ngx_http_request_parser_post_read_handler; return NGX_OK; }
static ngx_int_t ngx_http_sla_init (ngx_conf_t* cf) { ngx_http_handler_pt* handler; ngx_http_core_main_conf_t* config; config = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); handler = ngx_array_push(&config->phases[NGX_HTTP_LOG_PHASE].handlers); if (handler == NULL) { return NGX_ERROR; } *handler = ngx_http_sla_processor; return NGX_OK; }
/* * Install this filter (post-configuration callback). * * Filters are installed in the post-configuration step */ static ngx_int_t ngx_apikey_access_filter_install(ngx_conf_t *cf) { ngx_http_handler_pt *h = NULL; ngx_http_core_main_conf_t *cmcf = NULL; cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); h = ngx_array_push(&cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers); if (h == NULL) { return NGX_ERROR; } *h = ngx_apikey_access_filter_handler; return NGX_OK; }
// handler模块的挂载 大多数是挂载在NGX_HTTP_CONTENT_PHASE阶段的 // 挂载的动作一般是在模块上下文调用的postconfiguration函数中 static ngx_int_t ngx_http_mmseg_init(ngx_conf_t *cf) { ngx_http_handler_pt *h; ngx_http_core_main_conf_t *cmcf; cmcf = (ngx_http_core_main_conf_t*)ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); h = (ngx_http_handler_pt*)ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers); if (h == NULL) { return NGX_ERROR; } *h = ngx_http_mmseg_handler;// 注册对请求处理函数 return NGX_OK; }
static ngx_int_t ngx_http_hello_world_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_CONTENT_PHASE].handlers); if (h == NULL) { return NGX_ERROR; } *h = ngx_http_hello_world_handler; cmcf->response_event = ngx_http_hello_world_handler; return NGX_OK; }
static ngx_int_t ngx_aws_auth_req_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_ACCESS_PHASE].handlers); if (h == NULL) { return NGX_ERROR; } *h = ngx_http_aws_proxy_sign; return NGX_OK; }
ngx_int_t ngx_http_flex_cache_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_CONTENT_PHASE].handlers); if (h == NULL) { return NGX_ERROR; } *h = ngx_http_flex_cache_handler; return NGX_OK; }
static ngx_int_t ngx_http_push_stream_postconfig(ngx_conf_t *cf) { ngx_http_push_stream_main_conf_t *conf = ngx_http_conf_get_module_main_conf(cf, ngx_http_push_stream_module); size_t shm_size; size_t shm_size_limit = 32 * ngx_pagesize; if (!conf->enabled) { return NGX_OK; } // initialize shared memory shm_size = ngx_align(conf->shm_size, ngx_pagesize); if (shm_size < shm_size_limit) { ngx_conf_log_error(NGX_LOG_WARN, cf, 0, "The push_stream_shared_memory_size value must be at least %udKiB", shm_size_limit >> 10); shm_size = shm_size_limit; }
static ngx_int_t ngx_http_stup_init(ngx_conf_t *cf) { ngx_http_core_main_conf_t *cmcf; ngx_http_handler_pt *h; cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); if (ngx_tcp_io_init_rbtree(cf, &ngx_http_core_module) == NGX_ERROR) return NGX_ERROR; h = ngx_array_push(&cmcf->phases[NGX_HTTP_LOG_PHASE].handlers); if (h == NULL) { return NGX_ERROR; } *h = ngx_http_statu_monitor_handler; return NGX_OK;
// handler installation static ngx_int_t ngx_http_dynamic_redirect_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_ACCESS_PHASE].handlers); if (!h) { return NGX_ERROR; } *h = ngx_http_dynamic_redirect_handler; return NGX_OK; }
static char * ngx_http_disable_sync(ngx_conf_t * cf, ngx_command_t * cmd, void * conf) { ngx_http_hustdb_ha_main_conf_t * mcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_hustdb_ha_module); if (!mcf || 2 != cf->args->nelts) { mcf->disable_sync = false; return NGX_CONF_OK; } int val = ngx_http_get_flag_slot(cf); if (NGX_ERROR == val) { return "ngx_http_disable_sync error"; } mcf->disable_sync = val; // TODO: you can modify the value here return NGX_CONF_OK; }
static ngx_http_sla_pool_t* ngx_http_sla_get_pool (const ngx_conf_t* cf, const ngx_str_t* name) { ngx_uint_t i; ngx_http_sla_pool_t* pool; ngx_http_sla_main_conf_t* config; config = ngx_http_conf_get_module_main_conf(cf, ngx_http_sla_module); pool = config->pools.elts; for (i = 0; i < config->pools.nelts; i++) { if (pool->name.len == name->len && ngx_strcmp(pool->name.data, name->data) == 0) { return pool; } } return NULL; }
ngx_int_t ngx_http_lua_add_package_preload(ngx_conf_t *cf, const char *package, lua_CFunction func) { lua_State *L; ngx_http_lua_main_conf_t *lmcf; ngx_http_lua_preload_hook_t *hook; lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_lua_module); L = lmcf->lua; if (L) { lua_getglobal(L, "package"); lua_getfield(L, -1, "preload"); lua_pushcfunction(L, func); lua_setfield(L, -2, package); lua_pop(L, 2); return NGX_OK; } /* L == NULL */ /* 如果 L 没有建立,即调用的 module 在 ngx_http_lua_module 前建立 * 先存起来,在 L 初始化时再加载 */ if (lmcf->preload_hooks == NULL) { lmcf->preload_hooks = ngx_array_create(cf->pool, 4, sizeof(ngx_http_lua_preload_hook_t)); if (lmcf->preload_hooks == NULL) { return NGX_ERROR; } } hook = ngx_array_push(lmcf->preload_hooks); if (hook == NULL) { return NGX_ERROR; } hook->package = (u_char *) package; hook->loader = func; return NGX_OK; }
static ngx_int_t ngx_http_traffic_status_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_LOG_PHASE].handlers); if (h == NULL) { return NGX_ERROR; } *h = ngx_http_status_codes_statistics; return NGX_OK; }
static char* ngx_http_radius_set_radius_server( ngx_conf_t *cf, ngx_command_t *cmd, void *conf ) { ngx_http_auth_radius_main_conf_t* mconf = ngx_http_conf_get_module_main_conf( cf, ngx_http_auth_radius_module ); ngx_str_t* value = cf->args->elts; if ( cf->args->nelts != 3 && cf->args->nelts != 4 ) return "invalid value"; ngx_url_t u; ngx_memzero( &u, sizeof(ngx_url_t) ); u.url = value[1]; u.uri_part = 1; u.one_addr = 1; u.default_port = RADIUS_DEFAULT_PORT; if ( ngx_parse_url( cf->pool, &u ) != NGX_OK ) { if ( u.err ) { ngx_conf_log_error( NGX_LOG_EMERG, cf, 0, "%s ngx_http_radius_set_radius_server \"%V\"", u.err, &u.url ); } return "invalid address"; } radius_str_t secret; secret.s = value[2].data; secret.len = value[2].len; mconf->secret.s = secret.s; mconf->secret.len = secret.len; radius_str_t nas_identifier; nas_identifier.s = NULL; nas_identifier.len = 0; if ( cf->args->nelts == 4 ) { nas_identifier.s = value[3].data; nas_identifier.len = value[3].len; } radius_server_t* rs; rs = radius_add_server( u.addrs[0].sockaddr, u.addrs[0].socklen, &secret, &nas_identifier ); rs->logger = radius_logger; return NGX_CONF_OK; }
static ngx_int_t ngx_http_limit_conn_init(ngx_conf_t *cf) { syslog(LOG_INFO, "[%s:%s:%d]", __FILE__, __func__, __LINE__); 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_conn_handler; return NGX_OK; }
static ngx_int_t ngx_http_access_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); //在phases[NGX_HTTP_ACCESS_PHASE]中加入一个方法:ngx_http_access_handler h = ngx_array_push(&cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers); if (h == NULL) { return NGX_ERROR; } *h = ngx_http_access_handler; return NGX_OK; }
static ngx_int_t ngx_http_hello_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_CONTENT_PHASE].handlers); if (h == NULL) { return NGX_ERROR; } *h = ngx_http_hello_handler; ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "hello_init"); return NGX_OK; }
static ngx_int_t ngx_http_auth_spnego_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_ACCESS_PHASE].handlers); if (NULL == h) { return NGX_ERROR; } *h = ngx_http_auth_spnego_handler; return NGX_OK; }
static char *ngx_photo_thrift_merge_conf(ngx_conf_t *cf, void *parent, void *child) { photo_thrift_conf_t *prev = parent; photo_thrift_conf_t *conf = child; photo_thrift_conf_t **photo_thrift_conf; // same as 2 above, to push to main configuration ngx_photo_thrift_main_conf_t *photo_thrift_main_conf = ngx_http_conf_get_module_main_conf(cf, ngx_photo_thrift_module); ngx_conf_merge_str_value(conf->content_thrift_server, prev->content_thrift_server, NULL); ngx_conf_merge_str_value(conf->content_thrift_port, prev->content_thrift_port, "10021"); ngx_conf_merge_str_value(conf->meta_thrift_server, prev->meta_thrift_server, NULL); ngx_conf_merge_str_value(conf->meta_thrift_port, prev->meta_thrift_port, "10022"); // push to main configuration if(conf->content_thrift_server.data && conf->meta_thrift_server.data) { photo_thrift_conf = ngx_array_push(&photo_thrift_main_conf->loc_confs); *photo_thrift_conf = conf; } // printf("content thrift server: %s\n", (const char*) conf->content_thrift_server.data); return NGX_CONF_OK; }
static ngx_int_t write_back_request_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_CONTENT_PHASE].handlers); if(NULL == h) { return NGX_ERROR; } *h = ngx_http_write_back_request_handler; return NGX_OK; }
static char * ngx_http_naxsi_flags_loc_conf(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_dummy_loc_conf_t *alcf = conf, **bar; ngx_http_dummy_main_conf_t *main_cf; ngx_str_t *value; if (!alcf || !cf) return (NGX_CONF_ERROR); value = cf->args->elts; main_cf = ngx_http_conf_get_module_main_conf(cf, ngx_http_naxsi_module); if (!alcf->pushed) { bar = ngx_array_push(main_cf->locations); if (!bar) return (NGX_CONF_ERROR); *bar = alcf; alcf->pushed = 1; } /* it's a flagrule, just a hack to enable/disable mod */ if (!ngx_strcmp(value[0].data, TOP_ENABLED_FLAG_T) || !ngx_strcmp(value[0].data, TOP_ENABLED_FLAG_N)) { alcf->enabled = 1; return (NGX_CONF_OK); } else /* it's a flagrule, just a hack to enable/disable mod */ if (!ngx_strcmp(value[0].data, TOP_DISABLED_FLAG_T) || !ngx_strcmp(value[0].data, TOP_DISABLED_FLAG_N)) { alcf->force_disabled = 1; return (NGX_CONF_OK); } else /* it's a flagrule, currently just a hack to enable/disable learning mode */ if (!ngx_strcmp(value[0].data, TOP_LEARNING_FLAG_T) || !ngx_strcmp(value[0].data, TOP_LEARNING_FLAG_N)) { alcf->learning = 1; return (NGX_CONF_OK); } else return (NGX_CONF_ERROR); }
static ngx_int_t ngx_http_pinba_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_LOG_PHASE].handlers); if (h == NULL) { return NGX_ERROR; } *h = ngx_http_pinba_handler; request_uri_key = ngx_hash_key_lc(request_uri_name.data, request_uri_name.len); request_schema_key = ngx_hash_key_lc(request_schema_name.data, request_schema_name.len); return NGX_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 ngx_int_t xml_log_init(ngx_conf_t *cf) { ngx_http_core_main_conf_t *conf_m; ngx_http_handler_pt *h; conf_m = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); #ifdef LOG if ((h = ngx_array_push(&conf_m->phases[NGX_HTTP_LOG_PHASE].handlers)) == NULL) return NGX_ERROR; *h = xml_log; #else if ((h = ngx_array_push(&conf_m->phases[NGX_HTTP_SERVER_REWRITE_PHASE].handlers)) == NULL) return NGX_ERROR; *h = xml_log; #endif return NGX_OK; }
ngx_int_t ngx_http_variables_add_core_vars(ngx_conf_t *cf) { ngx_int_t rc; ngx_http_variable_t *v; ngx_http_core_main_conf_t *cmcf; cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); cmcf->variables_keys = ngx_pcalloc(cf->temp_pool, sizeof(ngx_hash_keys_arrays_t)); if (cmcf->variables_keys == NULL) { return NGX_ERROR; } cmcf->variables_keys->pool = cf->pool; cmcf->variables_keys->temp_pool = cf->pool; if (ngx_hash_keys_array_init(cmcf->variables_keys, NGX_HASH_SMALL) != NGX_OK) { return NGX_ERROR; } for (v = ngx_http_core_variables; v->name.len; v++) { rc = ngx_hash_add_key(cmcf->variables_keys, &v->name, v, NGX_HASH_READONLY_KEY); if (rc == NGX_OK) { continue; } if (rc == NGX_BUSY) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "conflicting variable name \"%V\"", &v->name); } return NGX_ERROR; } return NGX_OK; }