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;
}
示例#2
0
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;
}