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; }
ib_status_t ib_capture_acquire( const ib_tx_t *tx, const char *collection_name, ib_field_t **field ) { assert(tx != NULL); assert(tx->var_store != NULL); ib_status_t rc; ib_var_source_t *source; /* Look up the capture list */ collection_name = get_collection_name(collection_name); // @todo Acquire source at configuration time. rc = ib_var_source_acquire(&source, tx->mm, ib_engine_var_config_get(tx->ib), collection_name, strlen(collection_name) ); if (rc != IB_OK) { return rc; } rc = ib_var_source_get(source, field, tx->var_store); if ( rc == IB_ENOENT || (rc == IB_OK && (*field)->type != IB_FTYPE_LIST) ) { rc = ib_var_source_initialize( source, field, tx->var_store, IB_FTYPE_LIST ); } if (rc != IB_OK) { return rc; } return IB_OK; }
/** * 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; }