static char * lxl_dns_core_server(lxl_conf_t *cf, lxl_command_t *cmd, void *conf) { char *rv; void *mconf; lxl_uint_t i; lxl_conf_t pcf; lxl_dns_module_t *module; lxl_dns_conf_ctx_t *ctx, *main_ctx; lxl_dns_core_srv_conf_t *cscf, **cscfp; lxl_dns_core_main_conf_t *cmcf; ctx = lxl_pcalloc(cf->pool, sizeof(lxl_dns_conf_ctx_t)); if (ctx == NULL) { return LXL_CONF_ERROR; } main_ctx = cf->ctx; ctx->main_conf = main_ctx->main_conf; ctx->srv_conf = lxl_pcalloc(cf->pool, lxl_dns_max_module * sizeof(void *)); if (ctx->srv_conf == NULL) { return LXL_CONF_ERROR; } for (i = 0; lxl_modules[i]; ++i) { if (lxl_modules[i]->type != LXL_DNS_MODULE) { continue; } module = lxl_modules[i]->ctx; if (module->create_srv_conf) { mconf = module->create_srv_conf(cf); if (mconf == NULL) { return LXL_CONF_ERROR; } ctx->srv_conf[lxl_modules[i]->ctx_index] = mconf; } } cscf = ctx->srv_conf[lxl_dns_core_module.ctx_index]; cscf->ctx = ctx; cmcf = ctx->main_conf[lxl_dns_core_module.ctx_index]; cscfp = lxl_array_push(&cmcf->servers); if (cscfp == NULL) { return LXL_CONF_ERROR; } *cscfp = cscf; pcf = *cf; cf->ctx = ctx; cf->cmd_type = LXL_DNS_SRV_CONF; rv = lxl_conf_parse(cf, NULL); *cf = pcf; return rv; }
lxl_dfss_request_t * lxl_dfss_create_request(lxl_connection_t *c) { lxl_pool_t *pool; lxl_dfss_request_t *r; pool = lxl_create_pool(512); if (pool == NULL) { return NULL; } r = lxl_pcalloc(pool, sizeof(lxl_dfss_request_t)); if (r == NULL) { lxl_destroy_pool(pool); return NULL; } /* * pcalloc set * first_qtype = 0 * new_request = 0 * r->response_header {0, 0, 0} */ r->pool = pool; r->connection = c; r->response_header.rcode = LXL_DFS_OK; /* 2*N N = 2 or N = 3 */ if (lxl_queue_init(&r->addrs, r->pool, 8, sizeof(lxl_dfss_addr_t)) == -1) { return NULL; } return r; }
static void * lxl_dfss_create_srv_conf(lxl_conf_t *cf) { lxl_dfss_core_srv_conf_t *cscf; cscf = lxl_pcalloc(cf->pool, sizeof(lxl_dfss_core_srv_conf_t)); if (cscf == NULL) { return NULL; } return cscf; }
static void * lxl_dfst_storage_create_conf(lxl_conf_t *cf) { lxl_dfst_storage_srv_conf_t *conf; conf = lxl_pcalloc(cf->pool, sizeof(lxl_dfst_storage_srv_conf_t)); if (conf == NULL) { return NULL; } conf->upstream.connect_timeout = LXL_CONF_UNSET_MSEC; conf->upstream.send_timeout = LXL_CONF_UNSET_MSEC; conf->upstream.read_timeout = LXL_CONF_UNSET_MSEC; conf->upstream.send_timeout = LXL_CONF_UNSET_SIZE; return conf; }
static void * lxl_errlog_module_create_conf(lxl_cycle_t *cycle) { lxl_log_conf_t *lcf; lcf = lxl_pcalloc(cycle->pool, sizeof(lxl_core_conf_t)); if (lcf == NULL) { return NULL; } lcf->use_flush = LXL_CONF_UNSET; lcf->use_stderr = LXL_CONF_UNSET; lcf->error_level = LXL_CONF_UNSET; lcf->debug_level = LXL_CONF_UNSET; lxl_str_null(&lcf->file); return lcf; }
static void * lxl_dns_core_create_srv_conf(lxl_conf_t *cf) { lxl_dns_core_srv_conf_t *cscf; cscf = lxl_pcalloc(cf->pool, sizeof(lxl_dns_core_srv_conf_t)); if (cscf == NULL) { return NULL; } /* set by lxl_pcalloc * cscf->ctx = NULL */ cscf->client_timeout = LXL_CONF_UNSET_UINT; cscf->connection_pool_size = LXL_CONF_UNSET_SIZE; cscf->client_buffer_size = LXL_CONF_UNSET_SIZE; return cscf; }
void lxl_dfst_storage_init(lxl_dfst_request_t *r) { lxl_dfst_upstream_t *u; lxl_dfst_storage_srv_conf_t *sscf; u = r->storage; if (u == NULL) { u = lxl_pcalloc(r->pool, sizeof(lxl_dfst_upstream_t)); if (u == NULL) { return; } r->storage = u; } sscf = lxl_dfst_get_module_srv_conf(r, lxl_dfst_storage_module); u->conf = &sscf->upstream; lxl_dfst_storage_init_request(r); }
static void * lxl_core_module_create_conf(lxl_cycle_t *cycle) { lxl_core_conf_t *ccf; ccf = lxl_pcalloc(cycle->pool, sizeof(lxl_core_conf_t)); if (ccf == NULL) { return NULL; } ccf->daemon = LXL_CONF_UNSET; ccf->worker_process = LXL_CONF_UNSET; ccf->rlimit_nofile = LXL_CONF_UNSET; ccf->priority = 0; ccf->cpu_affinity_n = 0; ccf->cpu_affinity = NULL; ccf->username = NULL; lxl_str_null(&ccf->working_directory); return ccf; }
static void * lxl_dns_core_create_main_conf(lxl_conf_t *cf) { lxl_dns_core_main_conf_t *cmcf; cmcf = lxl_pcalloc(cf->pool, sizeof(lxl_dns_core_main_conf_t)); if (cmcf == NULL) { return NULL; } if (lxl_array_init(&cmcf->servers, cf->pool, 4, sizeof(lxl_dns_core_srv_conf_t)) != 0) { return NULL; } if (lxl_array_init(&cmcf->listens, cf->pool, 4, sizeof(lxl_dns_listen_t)) != 0) { return NULL; } cmcf->tcp = LXL_CONF_UNSET_UINT; cmcf->zone_hash_bucket_size = LXL_CONF_UNSET_UINT; lxl_str_null(&cmcf->named_root_file); return cmcf; }
static char * lxl_events_block(lxl_conf_t *cf, lxl_command_t *cmd, void *conf) { char *rv; lxl_uint_t i; void ***ctx; lxl_conf_t pcf; lxl_event_module_t *m; if (*(void **) conf) { return "is duplicate"; } lxl_event_max_module = 0; for (i = 0; lxl_modules[i]; ++i) { if (lxl_modules[i]->type != LXL_EVENT_MODULE) { continue; } lxl_modules[i]->ctx_index = lxl_event_max_module++; } ctx = lxl_pcalloc(cf->pool, sizeof(void *)); if (ctx == NULL) { return LXL_CONF_ERROR; } *ctx = lxl_pcalloc(cf->pool, lxl_event_max_module * sizeof(void *)); if (*ctx == NULL) { return LXL_CONF_ERROR; } *(void **) conf = ctx; for (i = 0; lxl_modules[i]; ++i) { if (lxl_modules[i]->type != LXL_EVENT_MODULE) { continue; } m = lxl_modules[i]->ctx; if (m->create_conf) { (*ctx)[lxl_modules[i]->ctx_index] = m->create_conf(cf->cycle); if ((*ctx)[lxl_modules[i]->ctx_index] == NULL) { return LXL_CONF_ERROR; } } } pcf = *cf; cf->ctx = ctx; cf->module_type = LXL_EVENT_MODULE; cf->cmd_type = LXL_EVENT_CONF; rv = lxl_conf_parse(cf, NULL); *cf = pcf; if (rv != LXL_CONF_OK) { return rv; } for (i = 0; lxl_modules[i]; ++i) { if (lxl_modules[i]->type != LXL_EVENT_MODULE) { continue; } m = lxl_modules[i]->ctx; if (m->init_conf) { rv = m->init_conf(cf->cycle, (*ctx)[lxl_modules[i]->ctx_index]); if (rv != LXL_CONF_OK) { return rv; } } } return LXL_CONF_OK; }
static char * lxl_dfss_core_listen(lxl_conf_t *cf, lxl_command_t *cmd, void *conf) { off_t off; lxl_uint_t i, nelts; lxl_url_t u; lxl_str_t *value; in_port_t port; struct sockaddr *sa; struct sockaddr_in *sin; lxl_dfss_listen_t *ls; lxl_dfss_core_main_conf_t *cmcf; cmcf = lxl_dfss_conf_get_module_main_conf(cf, lxl_dfss_core_module); if (cmcf->listen != NULL) { return "is duplicate"; } value = lxl_array_elts(cf->args); u.url = value[1]; u.listen = 1; if (lxl_parse_url(cf->pool, &u) != 0) { if (u.err) { lxl_conf_log_error(LXL_LOG_EMERG, cf, 0, "%s in \"%s\" of the \"listen\" directive", u.err, u.url.data); } return LXL_CONF_ERROR; } /*ls = lxl_array_elts(&cmcf->listens); nelts = lxl_array_nelts(&cmcf->listens); for (i = 0; i < nelts; ++i) { sa = (struct sockaddr *) ls[i].sockaddr; off = offsetof(struct sockaddr_in, sin_addr); sin = (struct sockaddr_in *) sa; port = sin->sin_port; if (memcmp(ls[i].sockaddr + off, u.sockaddr + off, 4) != 0) { continue; } if (port != u.port) { continue; } lxl_conf_log_error(LXL_LOG_EMERG, cf, 0, "duplicate \"%s\" address and port again", &u.url); return LXL_CONF_ERROR; } ls = lxl_array_push(&cmcf->listens); if (ls == NULL) { return LXL_CONF_ERROR; }*/ ls = lxl_pcalloc(cf->pool, sizeof(lxl_dfss_listen_t)); if (ls == NULL) { return LXL_CONF_ERROR; } //memset(ls, 0x00, sizeof(lxl_dfss_listen_t)); memcpy(ls->sockaddr, u.sockaddr, u.socklen); ls->socklen = u.socklen; ls->wildcard = u.wildcard; ls->ctx = cf->ctx; cmcf->listen = ls; sin = (struct sockaddr_in *) ls->sockaddr; lxl_dfss_ip_port.ip = sin->sin_addr.s_addr; lxl_dfss_ip_port.port = sin->sin_port; return LXL_CONF_OK; }