Exemplo n.º 1
0
Engine Engine::create(Server server)
{
    ib_engine_t* ib_engine;
    Internal::throw_if_error(
        ib_engine_create(
            &ib_engine,
            server.ib()
        )
    );
    return Engine(ib_engine);
}
Exemplo n.º 2
0
/// @test Test ironbee library - ib_engine_create()
TEST(TestIronBee, test_engine_create_null_server)
{
    ib_engine_t *ib;
    ib_status_t rc;

    rc = ib_initialize();
    ASSERT_EQ(IB_OK, rc);

    rc = ib_engine_create(&ib, NULL);
    ASSERT_EQ(IB_EINVAL, rc);
    ASSERT_FALSE(ib);

    ib_shutdown();
}
Exemplo n.º 3
0
/**
 * Initializes and configures the ironbee engine.
 */
static int ironbee_post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptmp,
                             server_rec *s)
{
    ironbee_config_t *modcfg =
        (ironbee_config_t *)ap_get_module_config(s->module_config,
                                                 &ironbee_module);
    ib_cfgparser_t *cp;
    ib_provider_t *lpr;
    void *init = NULL;
    ib_status_t rc;


    /* Init IB library. */
    rc = ib_initialize();
    if (rc != IB_OK) {
        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
                     IB_PRODUCT_NAME ": Error initializing ib library");
        return OK;
    }

    ib_util_log_level(4);

    /* Detect first (validation) run vs real config run. */
    apr_pool_userdata_get(&init, "ironbee-init", s->process->pool);
    if (init == NULL) {
        ap_log_error(APLOG_MARK, APLOG_INFO, 0, s,
                     MODULE_NAME_FULL " loading.");

        apr_pool_userdata_set((const void *)1, "ironbee-init",
                              apr_pool_cleanup_null, s->process->pool);

        return OK;
    }

    /// @todo Tracefile needs removed
    //ib_trace_init("/tmp/ironbee.trace");
    ib_trace_init(NULL);

    /* Create the engine handle. */
    rc = ib_engine_create(&ironbee, &ibplugin);
    if (rc != IB_OK) {
        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
                     IB_PRODUCT_NAME ": Error creating engine: %d", rc);
        return OK;
    }

    /* Register the logger. */
    rc = ib_provider_register(ironbee, IB_PROVIDER_TYPE_LOGGER,
                              MODULE_NAME_STR, &lpr,
                              &ironbee_logger_iface,
                              NULL);
    if (rc != IB_OK) {
        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
                     IB_PRODUCT_NAME ": Error registering log provider: %d", rc);
        return OK;
    }
    ib_provider_data_set(lpr, (void *)s);

    /* Default logger */
    /// @todo Need to add a post set hook in core for this to work correctly
    ib_context_set_string(ib_context_engine(ironbee),
                          IB_PROVIDER_TYPE_LOGGER,
                          MODULE_NAME_STR);
    ib_context_set_num(ib_context_engine(ironbee),
                       IB_PROVIDER_TYPE_LOGGER ".log_level",
                       4);


    rc = ib_engine_init(ironbee);
    if (rc != IB_OK) {
        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
                     IB_PRODUCT_NAME ": Error initializing engine: %d", rc);
        return OK;
    }

    /* Register module cleanup. */
    apr_pool_cleanup_register(p, (void *)s, ironbee_module_cleanup,
                              apr_pool_cleanup_null);

    /* Register conn/tx init hooks. */
    ib_hook_register(ironbee, conn_opened_event,
                     (ib_void_fn_t)ironbee_conn_init, s);

    /* Configure the engine. */
    if (modcfg->config != NULL) {
        ib_context_t *ctx;

        /* Notify the engine that the config process has started. This
         * will also create a main configuration context.
         */
        ib_state_notify_cfg_started(ironbee);

        /* Get the main configuration context. */
        ctx = ib_context_main(ironbee);

        /* Set some defaults */
        ib_context_set_string(ctx, IB_PROVIDER_TYPE_LOGGER, MODULE_NAME_STR);
        ib_context_set_num(ctx, "logger.log_level", 4);

        /* Parse the config file. */
        rc = ib_cfgparser_create(&cp, ironbee);
        if ((rc == IB_OK) && (cp != NULL)) {
            ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
                         IB_PRODUCT_NAME ": Parsing config: %s",
                         modcfg->config);
            ib_cfgparser_parse(cp, modcfg->config);
            ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
                         IB_PRODUCT_NAME ": Destroying config parser");
            ib_cfgparser_destroy(cp);
        }

        /* Notify the engine that the config process has finished. This
         * will also close out the main configuration context.
         */
        ib_state_notify_cfg_finished(ironbee);
    }
    else {
        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
                     IB_PRODUCT_NAME ": No config specified with IronBeeConfig directive");
    }

    ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s,
                 MODULE_NAME_FULL " configured.");

    return OK;
}
Exemplo n.º 4
0
/**
 * 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);
}
Exemplo n.º 5
0
static int ironbee_init(const char *configfile, const char *logfile)
{
  /* grab from httpd module's post-config */
  ib_status_t rc;
//  ib_provider_t *lpr;
  ib_cfgparser_t *cp;
  ib_context_t *ctx;
  int rv;

  rc = ib_initialize();
  if (rc != IB_OK) {
    return rc;
  }

  ib_util_log_level(9);

  ib_trace_init(TRACEFILE);

  rc = ib_engine_create(&ironbee, &ibplugin);
  if (rc != IB_OK) {
    return rc;
  }

  rc = ib_provider_register(ironbee, IB_PROVIDER_TYPE_LOGGER, "ironbee-ts",
                            NULL, &ironbee_logger_iface, NULL);
  if (rc != IB_OK) {
    return rc;
  }

  ib_context_set_string(ib_context_engine(ironbee),
                        IB_PROVIDER_TYPE_LOGGER, "ironbee-ts");
  ib_context_set_num(ib_context_engine(ironbee),
                     IB_PROVIDER_TYPE_LOGGER ".log_level", 4);

  rc = ib_engine_init(ironbee);
  if (rc != IB_OK) {
    return rc;
  }

  /* success is documented as TS_LOG_ERROR_NO_ERROR but that's undefined.
   * It's actually a TS_SUCCESS (proxy/InkAPI.cc line 6641).
   */
  rv = TSTextLogObjectCreate(logfile, TS_LOG_MODE_ADD_TIMESTAMP, &ironbee_log);
  if (rv != TS_SUCCESS) {
    return IB_OK + rv;
  }
   
  rc = atexit(ibexit);
  if (rc != 0) {
    return IB_OK + rv;
  }

  ib_hook_register(ironbee, conn_opened_event,
                   (ib_void_fn_t)ironbee_conn_init, NULL);


  ib_state_notify_cfg_started(ironbee);
  ctx = ib_context_main(ironbee);

  ib_context_set_string(ctx, IB_PROVIDER_TYPE_LOGGER, "ironbee-ts");
  ib_context_set_num(ctx, "logger.log_level", 4);

  rc = ib_cfgparser_create(&cp, ironbee);
  if (rc != IB_OK) {
    return rc;
  }
  if (cp != NULL) {  // huh?
    ib_cfgparser_parse(cp, configfile);
    ib_cfgparser_destroy(cp);
  }
  ib_state_notify_cfg_finished(ironbee);


  return IB_OK;
}