static ib_status_t core_slow_get( ib_field_t **f, ib_tx_t *tx, const char *name ) { assert(f != NULL); assert(tx != NULL); assert(name != NULL); ib_status_t rc; ib_var_source_t *source; ib_field_t *value = NULL; rc = ib_var_source_acquire( &source, ib_var_store_pool(tx->var_store), ib_var_store_config(tx->var_store), name, strlen(name) ); if (rc != IB_OK) { return rc; } rc = ib_var_source_get(source, &value, tx->var_store); if (rc != IB_OK) { return rc; } if (value == NULL) { return IB_EOTHER; } *f = value; return IB_OK; }
static bool core_vars_is_set(ib_tx_t *tx, const char *name) { assert(tx != NULL); assert(name != NULL); ib_status_t rc; ib_var_source_t *source; ib_field_t *f; rc = ib_var_source_acquire( &source, ib_var_store_pool(tx->var_store), ib_var_store_config(tx->var_store), name, strlen(name) ); if (rc != IB_OK) { return false; } rc = ib_var_source_get(source, &f, tx->var_store); if (rc == IB_ENOENT || ! f) { return false; } return true; }
static void core_vars_gen_list(ib_tx_t *tx, const char *name) { assert(tx != NULL); assert(name != NULL); ib_status_t rc; ib_var_source_t *source; rc = ib_var_source_acquire( &source, tx->mp, ib_var_store_config(tx->var_store), name, strlen(name) ); if (rc != IB_OK) { ib_log_warning_tx(tx, "Failed to acquire \"%s\" var: %s", name, ib_status_to_string(rc)); return; } rc = ib_var_source_initialize(source, NULL, tx->var_store, IB_FTYPE_LIST); if (rc != IB_OK) { ib_log_warning_tx(tx, "Failed add \"%s\" var to transaction: %s", name, ib_status_to_string(rc) ); } }
TEST_F(XRulesTest, SetFlag) { ib_field_t *field; ib_num_t num; ib_var_target_t *target; const ib_list_t *list; std::string config = std::string( "LogLevel DEBUG\n" "LoadModule \"ibmod_persistence_framework.so\"\n" "LoadModule \"ibmod_init_collection.so\"\n" "LoadModule \"ibmod_xrules.so\"\n" "InitCollection GeoIP vars: country_code=US\n" "SensorId B9C1B52B-C24A-4309-B9F9-0EF4CD577A3E\n" "SensorName UnitTesting\n" "SensorHostname unit-testing.sensor.tld\n" /* Note that both rules should fire and result in a single entry. */ "XRulePath / EnableRequestParamInspection priority=1\n" "XRuleGeo US EnableRequestParamInspection priority=1\n" "<Site test-site>\n" " SiteId AAAABBBB-1111-2222-3333-000000000000\n" " Hostname somesite.com\n" "</Site>\n" ); configureIronBeeByString(config.c_str()); performTx(); ASSERT_TRUE(ib_tx); ASSERT_TRUE(ib_tx->flags & IB_TX_FINSPECT_REQPARAMS); ASSERT_EQ( IB_OK, ib_var_target_acquire_from_string( &target, ib_tx->mp, ib_var_store_config(ib_tx->var_store), "FLAGS:inspectRequestParams", strlen("FLAGS:inspectRequestParams"), NULL, NULL) ); ASSERT_EQ( IB_OK, ib_var_target_get_const( target, &list, ib_tx->mp, ib_tx->var_store) ); ASSERT_EQ(1U, ib_list_elements(list)); field = (ib_field_t *)ib_list_node_data_const(ib_list_first_const(list)); ASSERT_EQ(IB_FTYPE_NUM, field->type); ASSERT_EQ( IB_OK, ib_field_value(field, ib_ftype_num_out(&num)) ); ASSERT_EQ(1, num); }
static void core_gen_tx_bytestr_alias(ib_tx_t *tx, const char *name, ib_bytestr_t *val) { assert(tx != NULL); assert(name != NULL); assert(val != NULL); ib_field_t *f; ib_var_source_t *source; ib_status_t rc; rc = ib_field_create_no_copy( &f, tx->mp, name, strlen(name), IB_FTYPE_BYTESTR, val ); if (rc != IB_OK) { ib_log_warning_tx(tx, "Failed to create \"%s\" var: %s", name, ib_status_to_string(rc)); return; } rc = ib_var_source_acquire( &source, tx->mp, ib_var_store_config(tx->var_store), name, strlen(name) ); if (rc != IB_OK) { ib_log_warning_tx(tx, "Failed to acquire \"%s\" var: %s", name, ib_status_to_string(rc)); return; } rc = ib_var_source_set(source, tx->var_store, f); if (rc != IB_OK) { ib_log_warning_tx(tx, "Failed add \"%s\" var to transaction: %s", name, ib_status_to_string(rc) ); } }
static void core_gen_tx_numeric(ib_tx_t *tx, const char *name, ib_num_t val) { assert(tx != NULL); assert(name != NULL); ib_field_t *f; ib_num_t num = val; ib_status_t rc; ib_var_source_t *source; rc = ib_field_create(&f, tx->mp, name, strlen(name), IB_FTYPE_NUM, &num); if (rc != IB_OK) { ib_log_warning_tx(tx, "Failed to create \"%s\" field: %s", name, ib_status_to_string(rc)); return; } rc = ib_var_source_acquire( &source, tx->mp, ib_var_store_config(tx->var_store), name, strlen(name) ); if (rc != IB_OK) { ib_log_warning_tx(tx, "Failed to acquire \"%s\" var: %s", name, ib_status_to_string(rc)); return; } rc = ib_var_source_set(source, tx->var_store, f); if (rc != IB_OK) { ib_log_warning_tx(tx, "Failed add \"%s\" var to transaction: %s", name, ib_status_to_string(rc) ); } }
static ib_status_t core_vars_placeholder_bytestr( ib_var_store_t *store, const char *name ) { ib_status_t rc; ib_var_source_t *source; ib_field_t *f; rc = ib_var_source_acquire( &source, ib_var_store_pool(store), ib_var_store_config(store), name, strlen(name) ); if (rc != IB_OK) { return rc; } rc = ib_field_create_bytestr_alias( &f, ib_var_store_pool(store), name, strlen(name), (uint8_t *)core_placeholder_value, sizeof(core_placeholder_value) ); if (rc != IB_OK) { return rc; } rc = ib_var_source_set( source, store, f ); return rc; }
/** * Create an alias list collection. * * @param ib Engine. * @param tx Transaction. * @param name Collection name * @param header Header list to alias * * @returns Status code */ static ib_status_t create_header_alias_list( ib_engine_t *ib, ib_tx_t *tx, const char *name, ib_parsed_header_wrapper_t *header) { ib_field_t *f; ib_list_t *header_list; ib_status_t rc; ib_parsed_name_value_pair_list_t *nvpair; ib_var_source_t *source; assert(ib != NULL); assert(tx != NULL); assert(name != NULL); assert(header != NULL); /* Create the list */ rc = ib_var_source_acquire( &source, ib_var_store_pool(tx->var_store), ib_var_store_config(tx->var_store), name, strlen(name) ); if (rc != IB_OK) { return rc; } rc = ib_var_source_get(source, &f, tx->var_store); if (rc == IB_ENOENT || ! f) { rc = ib_var_source_initialize( source, &f, tx->var_store, IB_FTYPE_LIST ); if (rc != IB_OK) { return rc; } } rc = ib_field_mutable_value(f, ib_ftype_list_mutable_out(&header_list)); if (rc != IB_OK) { return rc; } /* Loop through the list & alias everything */ for(nvpair = header->head; nvpair != NULL; nvpair = nvpair->next) { assert(nvpair); assert(nvpair->value); ib_bytestr_t *bs = NULL; if (ib_bytestr_ptr(nvpair->value) != NULL) { rc = ib_bytestr_alias_mem( &bs, tx->mp, ib_bytestr_ptr(nvpair->value), ib_bytestr_length(nvpair->value) ); } else { rc = ib_bytestr_dup_mem(&bs, tx->mp, (const uint8_t *)"", 0); } if (rc != IB_OK) { ib_log_error_tx( tx, "Error creating bytestring of '%.*s' for %s: %s", (int)ib_bytestr_length(nvpair->name), (const char *)ib_bytestr_ptr(nvpair->name), name, ib_status_to_string(rc) ); return rc; } /* Create a byte string field */ rc = ib_field_create( &f, tx->mp, (const char *)ib_bytestr_const_ptr(nvpair->name), ib_bytestr_length(nvpair->name), IB_FTYPE_BYTESTR, ib_ftype_bytestr_in(bs) ); if (rc != IB_OK) { ib_log_error_tx(tx, "Error creating field of '%.*s' for %s: %s", (int)ib_bytestr_length(nvpair->name), (const char *)ib_bytestr_ptr(nvpair->name), name, ib_status_to_string(rc)); return rc; } /* Add the field to the list */ rc = ib_list_push(header_list, f); if (rc != IB_OK) { ib_log_error_tx(tx, "Error adding alias of '%.*s' to %s list: %s", (int)ib_bytestr_length(nvpair->name), (const char *)ib_bytestr_ptr(nvpair->name), name, ib_status_to_string(rc)); return rc; } } return IB_OK; }