/** * Store a field in the agent list * * Creates a new field and adds it to the agent list field list. * * @param[in] ib IronBee object * @param[in,out] mp Memory pool to allocate from * @param[in] agent_list Field to add the field to * @param[in] name Field name * @param[in] value Field value * * @returns Status code */ static ib_status_t modua_store_field(ib_engine_t *ib, ib_mpool_t *mp, ib_field_t *agent_list, const char *name, const char *value) { IB_FTRACE_INIT(); ib_field_t *tmp_field = NULL; ib_status_t rc = IB_OK; /* No value? Do nothing */ if (value == NULL) { ib_log_debug3(ib, "No %s field in user agent", name); IB_FTRACE_RET_STATUS(IB_OK); } /* Create the field */ rc = ib_field_create( &tmp_field, mp, IB_FIELD_NAME(name), IB_FTYPE_NULSTR, ib_ftype_nulstr_in(value) ); if (rc != IB_OK) { ib_log_alert(ib, "Error creating user agent %s field: %s", name, ib_status_to_string(rc)); IB_FTRACE_RET_STATUS(rc); } /* Add the field to the list */ rc = ib_field_list_add(agent_list, tmp_field); if (rc != IB_OK) { ib_log_alert(ib, "Error adding user agent %s field: %s", name, ib_status_to_string(rc)); IB_FTRACE_RET_STATUS(rc); } ib_log_debug3(ib, "Stored user agent %s '%s'", name, value); IB_FTRACE_RET_STATUS(IB_OK); }
/** * Called to initialize data in a new connection. */ static ib_status_t ironbee_conn_init(ib_engine_t *ib, ib_state_event_type_t event, ib_conn_t *iconn, void *cbdata) { assert(event == conn_opened_event); //server_rec *s = cbdata; conn_rec *c = (conn_rec *)iconn->server_ctx; ib_status_t rc; ib_log_debug3(ib, "Initializing connection remote=%s:%d local=%s:%d", c->remote_ip, c->remote_addr->port, c->local_ip, c->local_addr->port); /* * Create connection fields */ /* remote_ip */ iconn->remote_ipstr = c->remote_ip; rc = ib_data_add_bytestr(iconn->dpi, "remote_ip", (uint8_t *)c->remote_ip, strlen(c->remote_ip), NULL); if (rc != IB_OK) { return rc; } /* remote_port */ iconn->remote_port = c->remote_addr->port; rc = ib_data_add_num(iconn->dpi, "remote_port", c->remote_addr->port, NULL); if (rc != IB_OK) { return rc; } /* local_ip */ iconn->local_ipstr = c->local_ip; rc = ib_data_add_bytestr(iconn->dpi, "local_ip", (uint8_t *)c->remote_ip, strlen(c->remote_ip), NULL); if (rc != IB_OK) { return rc; } /* local_port */ iconn->local_port = c->local_addr->port; rc = ib_data_add_num(iconn->dpi, "local_port", c->local_addr->port, NULL); if (rc != IB_OK) { return rc; } return IB_OK; }
/** * Setup the connection structures, filters and a disconnect handler. */ static int ironbee_pre_connection(conn_rec *c, void *csd) { ib_conn_t *iconn = NULL; ib_status_t rc; ironbee_conn_context *ctx_in; ironbee_conn_context *ctx_out; ironbee_config_t *modcfg = (ironbee_config_t *)ap_get_module_config(c->base_server->module_config, &ironbee_module); if (!modcfg->enabled) { return DECLINED; } /* Ignore backend connections. The backend connection does not have * a handle to the scoreboard. */ if (c->sbh == NULL) { ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, c->base_server, IB_PRODUCT_NAME ": Skipping proxy connect"); return DECLINED; } ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, c->base_server, IB_PRODUCT_NAME ": ironbee_pre_connection remote=%pI local=%pI", (void *)c->remote_addr, (void *)c->local_addr); /* Create the connection structure. */ /// @todo Perhaps the engine should do this instead via an event??? ib_log_debug3(ironbee, "Creating connection structure"); rc = ib_conn_create(ironbee, &iconn, c); if (rc != IB_OK) { return DECLINED; } /* Tell the engine a connection has started. */ ib_state_notify_conn_opened(ironbee, iconn); /* Create the incoming context. */ ctx_in = apr_pcalloc(c->pool, sizeof(*ctx_in)); ctx_in->iconn = iconn; ctx_in->direction = IRONBEE_REQUEST; apr_table_setn(c->notes, "IRONBEE_CTX_IN", (void *)ctx_in); /* Create the outgoing context. */ ctx_out = apr_pcalloc(c->pool, sizeof(*ctx_out)); ctx_out->iconn = iconn; ctx_out->direction = IRONBEE_RESPONSE; apr_table_setn(c->notes, "IRONBEE_CTX_OUT", (void *)ctx_out); /* Register callback on disconnect. */ /// @todo use apr_pool_pre_cleanup_register() when APR >= 1.3 apr_pool_cleanup_register(c->pool, c, ironbee_disconnection, NULL); /* Add the connection level filters which generate I/O events. */ ap_add_input_filter("IRONBEE_IN", ctx_in, NULL, c); #ifdef IB_DEBUG ap_add_input_filter("IRONBEE_DBG_IN", ctx_in, NULL, c); #endif ap_add_output_filter("IRONBEE_OUT", ctx_out, NULL, c); return OK; }