/** * Initialize a new server plugin module instance. * * @param[in] ib Engine this module is operating on. * @param[in] module This module structure. * @param[in] cbdata The server plugin module data. * * @returns * - IB_OK On success. * - Other on error. */ static ib_status_t init_module( ib_engine_t *ib, ib_module_t *module, void *cbdata ) { ib_status_t rc; assert(ib != NULL); assert(module != NULL); assert(cbdata != NULL); module_data_t *mod_data = (module_data_t *)cbdata; ib_logger_format_t *logger; rc = ib_logger_format_create( ib_engine_logger_get(ib), &logger, logger_format, mod_data, NULL, NULL); if (rc != IB_OK) { return IB2NG(rc); } ib_logger_writer_add( ib_engine_logger_get(ib), NULL, /* Open. */ NULL, /* Callback data. */ NULL, /* Close. */ mod_data, /* Callback data. */ NULL, /* Reopen. */ NULL, /* Callback data. */ logger, /* Format - This does all the work. */ NULL, /* Record. */ NULL /* Callback data. */ ); return IB_OK; }
/** * Ironbee initialisation function. Sets up engine and logging, * and reads Ironbee config. * * @param[in] cf Configuration rec * @return NGX_OK or error */ static ngx_int_t ironbee_init(ngx_conf_t *cf) { ngx_log_t *prev_log; ib_context_t *ctx; ib_cfgparser_t *cp; ironbee_proc_t *proc; ib_status_t rc, rc1; prev_log = ngxib_log(cf->log); ngx_regex_malloc_init(cf->pool); ngx_log_error(NGX_LOG_NOTICE, cf->log, 0, "ironbee_init %d", getpid()); proc = ngx_http_conf_get_module_main_conf(cf, ngx_ironbee_module); if (proc->loglevel == NGX_CONF_UNSET_UINT) proc->loglevel = 4; /* default */ rc = ib_initialize(); if (rc != IB_OK) cleanup_return(prev_log) IB2NG(rc); ib_util_log_level(proc->loglevel); rc = ib_engine_create(&ironbee, ngxib_server()); if (rc != IB_OK) cleanup_return(prev_log) IB2NG(rc); if (proc->use_ngxib_logger) ib_log_set_logger_fn(ironbee, ngxib_logger, NULL); /* Using default log level function. */ rc = ib_engine_init(ironbee); if (rc != IB_OK) cleanup_return(prev_log) IB2NG(rc); /* TODO: TS creates logfile at this point */ ib_hook_conn_register(ironbee, conn_opened_event, ngxib_conn_init, NULL); rc = ib_cfgparser_create(&cp, ironbee); assert((cp != NULL) || (rc != IB_OK)); if (rc != IB_OK) cleanup_return(prev_log) IB2NG(rc); rc = ib_engine_config_started(ironbee, cp); if (rc != IB_OK) cleanup_return(prev_log) IB2NG(rc); /* Get the main context, set some defaults */ ctx = ib_context_main(ironbee); ib_context_set_num(ctx, "logger.log_level", proc->loglevel); /* FIXME - use the temp pool operation for this */ char *buf = strndup((char*)proc->config_file.data, proc->config_file.len); rc = ib_cfgparser_parse(cp, buf); free(buf); rc1 = ib_engine_config_finished(ironbee); ib_cfgparser_destroy(cp); cleanup_return(prev_log) rc == IB_OK ? rc1 == IB_OK ? NGX_OK : IB2NG(rc1) : IB2NG(rc); }
/** * IronBee initialization function. Sets up engine and logging, * and reads IronBee config. * * @param[in] cf Configuration rec * @return NGX_OK or error */ static ngx_int_t ironbee_init(ngx_conf_t *cf) { ironbee_proc_t *proc; ib_status_t rc; module_data_t *mod_data = &module_data; char *buf; /* We still use the global-log hack to initialise */ ngx_regex_malloc_init(cf->pool); ngx_log_error(NGX_LOG_NOTICE, cf->log, 0, "ironbee_init %d", getpid()); proc = ngx_http_conf_get_module_main_conf(cf, ngx_ironbee_module); if (proc->log_level == NGX_CONF_UNSET_UINT) { proc->log_level = IB_LOG_NOTICE; } if (proc->max_engines == NGX_CONF_UNSET_UINT) { proc->max_engines = IB_MANAGER_DEFAULT_MAX_ENGINES; } if (proc->use_ngxib_logger == NGX_CONF_UNSET) { proc->use_ngxib_logger =1; } /* initialise fields in mod_data */ mod_data->ib_log_active = proc->use_ngxib_logger; mod_data->log = cf->log; mod_data->log_level = proc->log_level; rc = ib_initialize(); if (rc != IB_OK) { cleanup_return IB2NG(rc); } /* Create the IronBee engine manager */ rc = ib_manager_create(&(mod_data->manager), /* Engine Manager */ ngxib_server(), /* Server object */ proc->max_engines); /* Max engines */ if (rc != IB_OK) { cleanup_return IB2NG(rc); } rc = ib_manager_register_module_fn( mod_data->manager, ngxib_module, mod_data); if (rc != IB_OK) { cleanup_return IB2NG(rc); } /* Null manager here would be a bug, as per RNS-CR-143 comments */ assert(mod_data->manager != NULL); /* FIXME - use the temp pool operation for this */ buf = strndup((char*)proc->config_file.data, proc->config_file.len); /* Create the initial engine */ rc = ib_manager_engine_create(mod_data->manager, buf); if (rc != IB_OK) { free(buf); cleanup_return IB2NG(rc); } free(buf); cleanup_return rc == IB_OK ? NGX_OK : IB2NG(rc); }