/** * Creates an aho corasick automata with states in trie form * * @param ac_tree pointer to store the matcher * @param flags options for the matcher * @param pool memory pool to use * * @returns Status code */ ib_status_t ib_ac_create(ib_ac_t **ac_tree, uint8_t flags, ib_mpool_t *pool) { IB_FTRACE_INIT(); if (ac_tree == NULL) { IB_FTRACE_RET_STATUS(IB_EINVAL); } *ac_tree = (ib_ac_t *)ib_mpool_calloc(pool, 1, sizeof(ib_ac_t)); if (*ac_tree == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } (*ac_tree)->mp = pool; (*ac_tree)->flags = flags; (*ac_tree)->root = (ib_ac_state_t *)ib_mpool_calloc(pool, 1, sizeof(ib_ac_state_t)); if ( (*ac_tree)->root == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } IB_FTRACE_RET_STATUS(IB_OK); }
/** * Creates an aho corasick automata with states in trie form * * @param ac_tree pointer to store the matcher * @param flags options for the matcher * @param pool memory pool to use * * @returns Status code */ ib_status_t ib_ac_create(ib_ac_t **ac_tree, uint8_t flags, ib_mpool_t *pool) { if (ac_tree == NULL) { return IB_EINVAL; } *ac_tree = (ib_ac_t *)ib_mpool_calloc(pool, 1, sizeof(ib_ac_t)); if (*ac_tree == NULL) { return IB_EALLOC; } (*ac_tree)->mp = pool; (*ac_tree)->flags = flags; (*ac_tree)->root = (ib_ac_state_t *)ib_mpool_calloc(pool, 1, sizeof(ib_ac_state_t)); if ( (*ac_tree)->root == NULL) { return IB_EALLOC; } return IB_OK; }
/** * Add items to the bintree for fast goto() transitions. Recursive calls * * @param states states array sorted by it's letter * @param lb left branch index * @param rb right branch index * @param pos current position * @param pool the memory pool to use * * @return ib_status_t status of the operation */ static ib_status_t ib_ac_add_bintree_sorted(ib_ac_bintree_t *state, ib_ac_state_t *states[], int pos, int lb, int rb, ib_mpool_t *pool) { IB_FTRACE_INIT(); ib_status_t st; int left = 0; int right = 0; if ((pos - lb) > 1) { left = lb + (pos - lb) / 2; state->left = (ib_ac_bintree_t *)ib_mpool_calloc(pool, 1, sizeof(ib_ac_bintree_t)); if (state->left == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } state->left->state = states[left]; state->left->letter = states[left]->letter; } if ((rb - pos) > 1) { right = pos + (rb - pos) / 2; state->right = (ib_ac_bintree_t *)ib_mpool_calloc(pool, 1, sizeof(ib_ac_bintree_t)); if (state->right == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } state->right->state = states[right]; state->right->letter = states[right]->letter; } if (state->right != NULL) { st = ib_ac_add_bintree_sorted(state->right, states, right, pos, rb, pool); if (st != IB_OK) { IB_FTRACE_RET_STATUS(st); } } if (state->left != NULL) { st = ib_ac_add_bintree_sorted(state->left, states, left, lb, pos, pool); if (st != IB_OK) { IB_FTRACE_RET_STATUS(st); } } IB_FTRACE_RET_STATUS(IB_OK); }
ib_status_t ib_array_create(ib_array_t **parr, ib_mpool_t *pool, size_t ninit, size_t nextents) { IB_FTRACE_INIT(); ib_status_t rc; /* Validate. */ if ((ninit == 0) || (nextents == 0)) { IB_FTRACE_RET_STATUS(IB_EINVAL); } /* Create the structure. */ *parr = (ib_array_t *)ib_mpool_alloc(pool, sizeof(**parr)); if (*parr == NULL) { rc = IB_EALLOC; goto failed; } (*parr)->mp = pool; (*parr)->ninit = ninit; (*parr)->nextents = nextents; (*parr)->nelts = 0; (*parr)->size = ninit; /* Create the extents array. */ (*parr)->extents = (void *)ib_mpool_calloc(pool, nextents, sizeof(void *)); if ((*parr)->extents == NULL) { rc = IB_EALLOC; goto failed; } /* Create the first data array in the first extent slot. */ *((void ***)(*parr)->extents) = (void **)ib_mpool_calloc(pool, ninit, sizeof(void *) ); if (*((void ***)(*parr)->extents) == NULL) { rc = IB_EALLOC; goto failed; } IB_FTRACE_RET_STATUS(IB_OK); failed: /* Make sure everything is cleaned up on failure. */ *parr = NULL; IB_FTRACE_RET_STATUS(rc); }
ib_status_t ib_provider_instance_create_ex(ib_engine_t *ib, ib_provider_t *pr, ib_provider_inst_t **ppi, ib_mpool_t *pool, void *data) { IB_FTRACE_INIT(); ib_status_t rc; /* Create the provider instance. */ *ppi = (ib_provider_inst_t *)ib_mpool_calloc(pool, 1, sizeof(**ppi)); if (*ppi == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } (*ppi)->mp = pool; (*ppi)->pr = pr; (*ppi)->data = NULL; /* Use an initialization function if available. */ if (pr->fn_init != NULL) { rc = pr->fn_init(*ppi, data); if (rc != IB_OK) { IB_FTRACE_RET_STATUS(rc); } } else { (*ppi)->data = data; } IB_FTRACE_RET_STATUS(IB_OK); }
ib_status_t ib_hash_resize_slots( ib_hash_t *hash ) { IB_FTRACE_INIT(); assert(hash != NULL); ib_hash_entry_t **new_slots = NULL; ib_hash_entry_t *current_entry = NULL; size_t new_max_slot = 0; /* Maintain power of 2 slots */ new_max_slot = 2 * hash->max_slot + 1; new_slots = (ib_hash_entry_t **)ib_mpool_calloc( hash->pool, new_max_slot + 1, sizeof(*new_slots) ); if (new_slots == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } IB_HASH_LOOP(current_entry, hash) { size_t i = current_entry->hash_value & new_max_slot; current_entry->next_entry = new_slots[i]; new_slots[i] = current_entry; }
ib_status_t ib_parsed_name_value_pair_list_wrapper_create( ib_parsed_name_value_pair_list_wrapper_t **headers, ib_tx_t *tx) { assert(headers != NULL); assert(tx != NULL); ib_parsed_name_value_pair_list_wrapper_t *headers_tmp = ib_mpool_calloc(tx->mp, 1, sizeof(*headers_tmp)); if ( headers_tmp == NULL ) { *headers = NULL; return IB_EALLOC; } headers_tmp->mpool = tx->mp; /* headers_tmp->head = initialized by calloc */ /* headers_tmp->tail = initialized by calloc */ /* headers_tmp->size = initialized by calloc */ /* Commit back successful object. */ *headers = headers_tmp; return IB_OK; }
/** * creates a clone of the prefix instance * * @param orig pointer to the original prefix * @param new_prefix reference to a pointer to the allocated prefix * @param mp memory pool that the allocation should use * * @returns Status code */ ib_status_t ib_radix_clone_prefix(ib_radix_prefix_t *orig, ib_radix_prefix_t **new_prefix, ib_mpool_t *mp) { IB_FTRACE_INIT(ib_radix_clone_prefix); ib_status_t ret = ib_radix_prefix_new(new_prefix, mp); if (ret != IB_OK) { IB_FTRACE_RET_STATUS(ret); } (*new_prefix)->prefixlen = orig->prefixlen; int i = 0; int limit = IB_BITS_TO_BYTES(orig->prefixlen); if ((*new_prefix)->prefixlen == 0) { IB_FTRACE_RET_STATUS(IB_OK); } (*new_prefix)->rawbits = (uint8_t *) ib_mpool_calloc(mp, 1, sizeof(uint8_t)* limit); if ((*new_prefix)->rawbits == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } for (; i < limit; i++) { (*new_prefix)->rawbits[i] = orig->rawbits[i]; } IB_FTRACE_RET_STATUS(IB_OK); }
ib_status_t ib_ctxsel_registration_create( ib_mpool_t *mp, ib_module_t *module, void *common_cb_data, ib_ctxsel_registration_t **pregistration) { assert(module != NULL); assert(pregistration != NULL); ib_ctxsel_registration_t *registration; if (mp == NULL) { registration = calloc(sizeof(*registration), 1); } else { registration = ib_mpool_calloc(mp, sizeof(*registration), 1); } if (registration == NULL) { return IB_EALLOC; } registration->mp = mp; registration->module = module; registration->common_cb_data = common_cb_data; *pregistration = registration; return IB_OK; }
/** * Initialize a provider instance with the given data * * @param mpi provider instance * @param extra data * * @return status of the operation */ static ib_status_t modradix_provider_instance_init(ib_provider_inst_t *mpi, void *data) { IB_FTRACE_INIT(modradix_provider_instance_init); ib_status_t rc; modradix_provider_data_t *dt; dt = (modradix_provider_data_t *) ib_mpool_calloc(mpi->mp, 1, sizeof(modradix_provider_data_t)); if (dt == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } rc = ib_radix_new((ib_radix_t **)&dt->radix_tree, NULL, NULL, NULL, mpi->mp); if (rc != IB_OK) { ib_log_error(mpi->pr->ib, 4, "Unable to create the Radix tree at " "modradix"); IB_FTRACE_RET_STATUS(rc); } mpi->data = dt; IB_FTRACE_RET_STATUS(IB_OK); }
ib_status_t ib_site_loc_create_default(ib_site_t *site, ib_loc_t **ploc) { IB_FTRACE_INIT(ib_site_loc_create); ib_loc_t *loc; ib_status_t rc; if (ploc != NULL) { *ploc = NULL; } /* Create the location structure in the site memory pool */ loc = (ib_loc_t *)ib_mpool_calloc(site->mp, 1, sizeof(*loc)); if (loc == NULL) { rc = IB_EALLOC; IB_FTRACE_RET_STATUS(rc); } loc->site = site; loc->path = IB_DSTR_URI_ROOT_PATH; if (ploc != NULL) { *ploc = loc; } site->default_loc = loc; IB_FTRACE_RET_STATUS(IB_OK); }
ib_status_t ib_provider_define(ib_engine_t *ib, const char *type, ib_provider_register_fn_t fn_reg, void *api) { IB_FTRACE_INIT(ib_provider_define); ib_status_t rc; ib_provider_def_t *prd; char *type_copy; /* Create the provider definition. */ prd = (ib_provider_def_t *)ib_mpool_calloc(ib->config_mp, 1, sizeof(*prd)); if (prd == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } prd->mp = ib->config_mp; prd->fn_reg = fn_reg; prd->api = api; /* Copy the type. */ type_copy = (char *)ib_mpool_alloc(prd->mp, strlen(type) + 1); if (type_copy == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } strcpy(type_copy, type); prd->type = (const char *)type_copy; rc = ib_hash_set(ib->apis, type, prd); if (rc != IB_OK) { IB_FTRACE_RET_STATUS(rc); } IB_FTRACE_RET_STATUS(IB_OK); }
ib_status_t ib_array_setn(ib_array_t *arr, size_t idx, void *val) { IB_FTRACE_INIT(); size_t r, c; void **data; /* Keep extending by ninit elements until the index fits in the array. */ while (idx >= arr->size) { r = arr->size / arr->ninit; /* If this will exceed the max, then reallocate the extents * to double its previous value to make room. */ if (r >= arr->nextents) { void *new_extents = (void *)ib_mpool_calloc(arr->mp, arr->nextents * 2, sizeof(void *)); if (new_extents == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } memcpy(new_extents, arr->extents, sizeof(void *) * arr->nextents); arr->extents = new_extents; arr->nextents *= 2; } ((void ***)arr->extents)[r] = (void **)ib_mpool_calloc(arr->mp, arr->ninit, sizeof(void *) ); arr->size += arr->ninit; } /* Calculate the row/column where the data resides. */ r = IB_ARRAY_EXTENT_INDEX(arr, idx); c = IB_ARRAY_DATA_INDEX(arr, idx, r); data = ((void ***)arr->extents)[r]; data[c] = val; /* Keep track of the number of elements stored. */ if (idx >= arr->nelts) { arr->nelts = idx + 1; } IB_FTRACE_RET_STATUS(IB_OK); }
ib_status_t ib_cfgparser_create(ib_cfgparser_t **pcp, ib_engine_t *ib) { IB_FTRACE_INIT(ib_cfgparser_create); ib_mpool_t *pool; ib_status_t rc; /* Create parser memory pool */ rc = ib_mpool_create(&pool, ib->mp); if (rc != IB_OK) { rc = IB_EALLOC; goto failed; } /* Create the main structure in the memory pool */ *pcp = (ib_cfgparser_t *)ib_mpool_calloc(pool, 1, sizeof(**pcp)); if (*pcp == NULL) { rc = IB_EALLOC; goto failed; } (*pcp)->ib = ib; (*pcp)->mp = pool; /* Create the stack */ rc = ib_list_create(&((*pcp)->stack), pool); if (rc != IB_OK) { goto failed; } (*pcp)->cur_ctx = ib_context_main(ib); ib_list_push((*pcp)->stack, (*pcp)->cur_ctx); /* Create the block tracking list */ rc = ib_list_create(&((*pcp)->block), pool); if (rc != IB_OK) { goto failed; } /* Other fields are NULLed via calloc */ ib_log_debug(ib, 9, "Stack: ctx=%p site=%p(%s) loc=%p(%s)", (*pcp)->cur_ctx, (*pcp)->cur_site, (*pcp)->cur_site?(*pcp)->cur_site->name:"NONE", (*pcp)->cur_loc, (*pcp)->cur_loc?(*pcp)->cur_loc->path:"/"); IB_FTRACE_RET_STATUS(rc); failed: /* Make sure everything is cleaned up on failure */ if (pool != NULL) { ib_mpool_destroy(pool); } *pcp = NULL; IB_FTRACE_RET_STATUS(rc); }
/// @todo Change this to _ex function with all fields and only use /// the required fields here. ib_status_t ib_logevent_create(ib_logevent_t **ple, ib_mpool_t *pool, const char *rule_id, ib_logevent_type_t type, ib_logevent_activity_t activity, ib_logevent_pri_class_t pri_class, ib_logevent_sec_class_t sec_class, ib_logevent_sys_env_t sys_env, ib_logevent_action_t rec_action, ib_logevent_action_t action, uint8_t confidence, uint8_t severity, const char *fmt, ...) { IB_FTRACE_INIT(ib_logevent_create); char buf[8192]; struct timeval tv; va_list ap; *ple = (ib_logevent_t *)ib_mpool_calloc(pool, 1, sizeof(**ple)); if (*ple == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } /// @todo Need a true unique id generator gettimeofday(&tv, NULL); (*ple)->event_id = (tv.tv_sec << (32-8)) + tv.tv_usec; /// @todo Generate the remaining portions of the event (*ple)->mp = pool; (*ple)->rule_id = rule_id; (*ple)->type = type; (*ple)->activity = activity; (*ple)->pri_class = pri_class; (*ple)->sec_class = sec_class; (*ple)->sys_env = sys_env; (*ple)->rec_action = rec_action; (*ple)->action = action; (*ple)->confidence = confidence; (*ple)->severity = severity; va_start(ap, fmt); if (vsnprintf(buf, sizeof(buf), fmt, ap) >= (int)sizeof(buf)) { strcpy(buf, "<msg too long>"); } va_end(ap); /* Copy the formatted message. */ (*ple)->msg = ib_mpool_strdup(pool, buf); IB_FTRACE_RET_STATUS(IB_OK); }
ib_status_t DLL_PUBLIC ib_logevent_create(ib_logevent_t **ple, ib_mpool_t *pool, const char *rule_id, ib_logevent_type_t type, ib_logevent_action_t rec_action, ib_logevent_action_t action, uint8_t confidence, uint8_t severity, const char *fmt, ...) { IB_FTRACE_INIT(); /* * Defined so that size_t to int cast is avoided * checking the result of vsnprintf below. * NOTE: This is assumed >3 bytes and should not * be overly large as it is used as the size * of a stack buffer. */ #define IB_LEVENT_MSG_BUF_SIZE 1024 char buf[IB_LEVENT_MSG_BUF_SIZE]; va_list ap; *ple = (ib_logevent_t *)ib_mpool_calloc(pool, 1, sizeof(**ple)); if (*ple == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } (*ple)->event_id = (uint32_t)ib_clock_get_time(); /* truncated */ (*ple)->mp = pool; (*ple)->rule_id = ib_mpool_strdup(pool, rule_id); (*ple)->type = type; (*ple)->rec_action = rec_action; (*ple)->action = action; (*ple)->confidence = confidence; (*ple)->severity = severity; /* * Generate the message, replacing the last three characters * with "..." if truncation is required. */ va_start(ap, fmt); if (vsnprintf(buf, IB_LEVENT_MSG_BUF_SIZE, fmt, ap) >= IB_LEVENT_MSG_BUF_SIZE) { memcpy(buf + (IB_LEVENT_MSG_BUF_SIZE - 3), "...", 3); } va_end(ap); /* Copy the formatted message. */ (*ple)->msg = ib_mpool_strdup(pool, buf); IB_FTRACE_RET_STATUS(IB_OK); }
ib_status_t ib_stream_create(ib_stream_t **pstream, ib_mpool_t *pool) { IB_FTRACE_INIT(); /* Create the structure. */ *pstream = (ib_stream_t *)ib_mpool_calloc(pool, 1, sizeof(**pstream)); if (*pstream == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } (*pstream)->mp = pool; IB_FTRACE_RET_STATUS(IB_OK); }
void* MemoryPool::calloc(size_t count, size_t size) const { void* memory = ib_mpool_calloc(ib(), count, size); if (! memory) { BOOST_THROW_EXCEPTION( ealloc() << errinfo_what( "ib_mpool_calloc() returned NULL" ) ); } return memory; }
ib_status_t ib_list_create(ib_list_t **plist, ib_mpool_t *pool) { IB_FTRACE_INIT(ib_list_create); /* Create the structure. */ *plist = (ib_list_t *)ib_mpool_calloc(pool, 1, sizeof(**plist)); if (*plist == NULL) { *plist = NULL; IB_FTRACE_RET_STATUS(IB_EALLOC); } (*plist)->mp = pool; IB_FTRACE_RET_STATUS(IB_OK); }
ib_status_t ib_field_create_alias( ib_field_t **pf, ib_mpool_t *mp, const char *name, size_t nlen, ib_ftype_t type, void *storage_pval ) { ib_status_t rc; char *name_copy; /* Allocate the field structure. */ *pf = (ib_field_t *)ib_mpool_alloc(mp, sizeof(**pf)); if (*pf == NULL) { rc = IB_EALLOC; goto failed; } (*pf)->mp = mp; (*pf)->type = type; (*pf)->tfn = NULL; /* Copy the name. */ (*pf)->nlen = nlen; name_copy = (char *)ib_mpool_alloc(mp, nlen); if (name_copy == NULL) { rc = IB_EALLOC; goto failed; } memcpy(name_copy, name, nlen); (*pf)->name = (const char *)name_copy; (*pf)->val = (ib_field_val_t *)ib_mpool_calloc(mp, 1, sizeof(*((*pf)->val)) ); if ((*pf)->val == NULL) { rc = IB_EALLOC; goto failed; } (*pf)->val->pval = storage_pval; ib_field_util_log_debug("FIELD_CREATE_ALIAS", (*pf)); return IB_OK; failed: /* Make sure everything is cleaned up on failure. */ *pf = NULL; return rc; }
ib_status_t ib_logformat_create(ib_mpool_t *mp, ib_logformat_t **lf) { IB_FTRACE_INIT(ib_logformat_alloc); if (lf == NULL) { return IB_EINVAL; } *lf = (ib_logformat_t *)ib_mpool_calloc(mp, 1, sizeof(ib_logformat_t) + 1); if (*lf == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } memset(*lf, 0, sizeof(ib_logformat_t) + 1); (*lf)->mp = mp; IB_FTRACE_RET_STATUS(IB_OK); }
/** * Creates a new node instance * * @param node reference to a pointer that will link to the allocated node * @param pool memory pool that the allocation should use * * @returns Status code */ ib_status_t ib_radix_node_new(ib_radix_node_t **node, ib_mpool_t *pool) { IB_FTRACE_INIT(ib_radix_node_new); *node = (ib_radix_node_t *)ib_mpool_calloc(pool, 1, sizeof(ib_radix_node_t)); if (*node == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } memset(*node, 0, sizeof(ib_radix_node_t)); IB_FTRACE_RET_STATUS(IB_OK); }
/** * Creates a new prefix instance * * @param prefix reference to a pointer that will link to the allocated prefix * @param pool memory pool that the allocation should use * * @returns Status code */ ib_status_t ib_radix_prefix_new(ib_radix_prefix_t **prefix, ib_mpool_t *pool) { IB_FTRACE_INIT(ib_radix_prefix_new); *prefix = (ib_radix_prefix_t *) ib_mpool_calloc(pool, 1, sizeof(ib_radix_prefix_t)); if (*prefix == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } memset(*prefix, 0, sizeof(ib_radix_prefix_t)); IB_FTRACE_RET_STATUS(IB_OK); }
/** * Add a prefix to the prefixes of the binradix, given a prefix and * callback + extra arg * * @param mpr matcher provider * @param prefixes pointer to the prefix container (i.e.: an BinRadix tree) * @param prefix the prefix to be added * @param callback the callback to register with the given prefix * @param arg the extra argument to pass to the callback * @param errptr a pointer reference to point where an error occurred * @param erroffset a pointer holding the offset of the error * * @return status of the operation */ static ib_status_t modbinradix_add_prefix_ex(ib_provider_inst_t *mpi, void *prefixes, const char *prefix, ib_void_fn_t callback, void *arg, const char **errptr, int *erroffset) { IB_FTRACE_INIT(); ib_status_t rc; ib_radix_t *binradix_tree = (ib_radix_t *)mpi->data; modbinradix_content_t *mrc = NULL; mrc = (modbinradix_content_t *)ib_mpool_calloc(mpi->pr->mp, 1, sizeof(modbinradix_content_t)); if (mrc == NULL) { ib_log_error(mpi->pr->ib, "Failed to allocate modbinradix_content_t" " for %s to the BinRadix tree %x", prefix, binradix_tree); IB_FTRACE_RET_STATUS(IB_EALLOC); } mrc->data = arg; mrc->callback = (modbinradix_callback_t)callback; ib_radix_prefix_t *pre = NULL; rc = ib_radix_ip_to_prefix(prefix, &pre, mpi->mp); if (rc != IB_OK) { ib_log_error(mpi->pr->ib, "Failed to create a binradix prefix for %s" " to the BinRadix tree %x", prefix, binradix_tree); IB_FTRACE_RET_STATUS(rc); } rc = ib_radix_insert_data(binradix_tree, pre, (void *) mrc); if (rc == IB_OK) { ib_log_debug(mpi->pr->ib, "prefix %s added to the BinRadix tree %x", prefix, binradix_tree); } else { ib_log_error(mpi->pr->ib, "Failed to load prefix %s to the BinRadix " "tree %x", prefix, binradix_tree); } IB_FTRACE_RET_STATUS(rc); }
/* * @internal * * Create a binary representation (in6_addr) of IP, allocating mem from mp * * @param ip ascii representation * @param mp pool where we should allocate in6_addr * * @returns struct in6_addr* */ static inline struct in6_addr *ib_radix_get_IPV6_addr(const char *ip, ib_mpool_t *mp) { IB_FTRACE_INIT(ib_radix_get_IPV6_addr); struct in6_addr *rawbytes = NULL; if ((rawbytes = (struct in6_addr *) ib_mpool_calloc(mp, 1, sizeof(struct in6_addr))) == NULL) { IB_FTRACE_RET_PTR(struct in6_addr, NULL); } if (inet_pton(AF_INET6, ip, rawbytes) <= 0) { IB_FTRACE_RET_PTR(struct in6_addr, NULL); } IB_FTRACE_RET_PTR(struct in6_addr, rawbytes); }
ib_status_t ib_list_unshift(ib_list_t *list, void *data) { IB_FTRACE_INIT(ib_list_unshift); ib_list_node_t *node = (ib_list_node_t *)ib_mpool_calloc(list->mp, 1, sizeof(*node)); if (node == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } node->data = data; if (list->nelts == 0) { IB_LIST_NODE_INSERT_INITIAL(list, node); IB_FTRACE_RET_STATUS(IB_OK); } IB_LIST_NODE_INSERT_FIRST(list, node, ib_list_node_t); IB_FTRACE_RET_STATUS(IB_OK); }
ib_status_t ib_stream_push(ib_stream_t *s, ib_sdata_type_t type, void *data, size_t dlen) { IB_FTRACE_INIT(); /// @todo take from a resource pool, if available ib_sdata_t *node = (ib_sdata_t *)ib_mpool_calloc(s->mp, 1, sizeof(*node)); if (node == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } node->type = type; node->dlen = dlen; node->data = data; ib_stream_push_sdata(s, node); IB_FTRACE_RET_STATUS(IB_OK); }
/** * Creates a new radix tree registering functions to update, free and print * associated to each prefix it also register the memory pool it should use * for new allocations * * @param radix pointer to link the instance of the new radix * @param free_data pointer to the function that will be used to * free the userdata entries * @param update_data pointer to the function that knows how to update a node * with new user data * @param print_data pointer to a helper function that print_datas a userdata * @param pool memory pool that the allocation should use * * @returns Status code */ ib_status_t ib_radix_new(ib_radix_t **radix, ib_radix_free_fn_t free_data, ib_radix_print_fn_t print_data, ib_radix_update_fn_t update_data, ib_mpool_t *pool) { IB_FTRACE_INIT(ib_radix_new); *radix = (ib_radix_t *) ib_mpool_calloc(pool, 1, sizeof(ib_radix_t)); if (*radix == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } memset(*radix, 0, sizeof(ib_radix_t)); (*radix)->mp = pool; (*radix)->update_data = update_data; (*radix)->print_data = print_data; (*radix)->free_data = free_data; IB_FTRACE_RET_STATUS(IB_OK); }
/** * Initialize a provider instance with the given data * * @param mpi provider instance * @param extra data * * @return status of the operation */ static ib_status_t modac_provider_instance_init(ib_provider_inst_t *mpi, void *data) { IB_FTRACE_INIT(modac_provider_instance_init); ib_status_t rc; modac_provider_data_t *dt; dt = (modac_provider_data_t *) ib_mpool_calloc(mpi->mp, 1, sizeof(modac_provider_data_t)); if (dt == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } mpi->data = (void *)dt; rc = ib_ac_create(&dt->ac_tree, 0, mpi->mp); if (rc != IB_OK) { ib_log_error(mpi->pr->ib, 4, "Unable to create the AC tree at modac"); } IB_FTRACE_RET_STATUS(rc); }
ib_status_t ib_site_create(ib_site_t **psite, ib_engine_t *ib, const char *name) { IB_FTRACE_INIT(ib_site_create); ib_mpool_t *pool = ib->config_mp; ib_status_t rc; /* Create the main structure in the config memory pool */ *psite = (ib_site_t *)ib_mpool_calloc(pool, 1, sizeof(**psite)); if (*psite == NULL) { rc = IB_EALLOC; IB_FTRACE_RET_STATUS(rc); } (*psite)->ib = ib; (*psite)->mp = pool; (*psite)->name = (const char *)ib_mpool_memdup(pool, name, strlen(name)+1); /* Remaining fields are NULL via calloc. */ IB_FTRACE_RET_STATUS(IB_OK); }