/* * Copyright (C) Kirill A. Korinskiy */ #include #include #include static char *ngx_dc_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); ngx_uint_t ngx_dc_max_module; static ngx_command_t ngx_dc_commands[] = { { ngx_string("dc"), NGX_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE1, ngx_dc_block, 0, 0, NULL }, ngx_null_command }; static ngx_core_module_t ngx_dc_module_ctx = { ngx_string("dc"), NULL, NULL }; ngx_module_t ngx_dc_module = { NGX_MODULE_V1, &ngx_dc_module_ctx, /* module context */ ngx_dc_commands, /* module directives */ NGX_CORE_MODULE, /* module type */ NULL, /* init master */ NULL, /* init module */ NULL, /* init process */ NULL, /* init thread */ NULL, /* exit thread */ NULL, /* exit process */ NULL, /* exit master */ NGX_MODULE_V1_PADDING }; static void *ngx_dc_core_create_conf(ngx_conf_t *cf); static ngx_command_t ngx_dc_core_commands[] = { { ngx_string("uri"), NGX_DC_CONF|NGX_CONF_TAKE1, ngx_conf_set_str_slot, NGX_DC_CONF_OFFSET, offsetof(ngx_dc_core_conf_t, uri), NULL }, ngx_null_command }; ngx_dc_module_t ngx_dc_core_module_ctx = { ngx_dc_core_create_conf, /* create configuration */ NULL /* init configuration */ }; ngx_module_t ngx_dc_core_module = { NGX_MODULE_V1, &ngx_dc_core_module_ctx, /* module context */ ngx_dc_core_commands, /* module directives */ NGX_DC_MODULE, /* module type */ NULL, /* init master */ NULL, /* init module */ NULL, /* init process */ NULL, /* init thread */ NULL, /* exit thread */ NULL, /* exit process */ NULL, /* exit master */ NGX_MODULE_V1_PADDING }; static char *ngx_dc_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { char *rv; ngx_str_t *value; ngx_uint_t i; ngx_uint_t mi; ngx_conf_t pcf; ngx_dc_module_t *m; ngx_dc_conf_ctx_t *ctx; /* the dc context */ ctx = ngx_pcalloc(cf->pool, sizeof(ngx_dc_conf_ctx_t)); if (ctx == NULL) { return NGX_CONF_ERROR; } *(ngx_dc_conf_ctx_t **) conf = ctx; ngx_dc_max_module = 0; for (i = 0; ngx_modules[i]; i++) { if (ngx_modules[i]->type != NGX_DC_MODULE) { continue; } ngx_modules[i]->ctx_index = ngx_dc_max_module++; } value = cf->args->elts; ctx->name = value[1]; /* the dc conf context, it is the same in the all dc contexts */ ctx->conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_dc_max_module); if (ctx->conf == NULL) { return NGX_CONF_ERROR; } for (i = 0; ngx_modules[i]; i++) { if (ngx_modules[i]->type != NGX_DC_MODULE) { continue; } m = ngx_modules[i]->ctx; mi = ngx_modules[i]->ctx_index; if (m->create_conf) { ctx->conf[mi] = m->create_conf(cf); if (ctx->conf[mi] == NULL) { return NGX_CONF_ERROR; } } } pcf = *cf; cf->ctx = ctx; cf->module_type = NGX_DC_MODULE; cf->cmd_type = NGX_DC_CONF; rv = ngx_conf_parse(cf, NULL); *cf = pcf; if (rv != NGX_CONF_OK) { *cf = pcf; return rv; } for (i = 0; ngx_modules[i]; i++) { if (ngx_modules[i]->type != NGX_DC_MODULE) { continue; } m = ngx_modules[i]->ctx; mi = ngx_modules[i]->ctx_index; if (m->init_conf) { rv = m->init_conf(cf, ctx->conf[mi]); if (rv != NGX_CONF_OK) { return rv; } } } return NGX_CONF_OK; } static void * ngx_dc_core_create_conf(ngx_conf_t *cf) { ngx_dc_core_conf_t *conf; conf = ngx_pcalloc(cf->pool, sizeof(ngx_dc_core_conf_t)); if (conf == NULL) { return NGX_CONF_ERROR; } return conf; } /* Local Variables: */ /* mode: c */ /* c-basic-offset: 4 */ /* End: */