/** * Adds state to parent state, if it is not already there * * @param parent the state where we want to link the new state * @param child the new state * */ static void ib_ac_add_child(ib_ac_state_t *parent, ib_ac_state_t *child) { IB_FTRACE_INIT(); ib_ac_state_t *state = NULL; child->parent = parent; if (parent->child == NULL) { parent->child = child; IB_FTRACE_RET_VOID(); } for (state = parent->child; state->sibling != NULL; state = state->sibling) { if (state == child) { IB_FTRACE_RET_VOID(); } } if (state != child) { /* We have found the right place */ state->sibling = child; } IB_FTRACE_RET_VOID(); }
/** * Engine default logger. * * This is the default logger that executes when no other logger has * been configured. * * @param fp File pointer * @param level Log level * @param prefix Optional prefix to the log * @param file Optional source filename (or NULL) * @param line Optional source line number (or 0) * @param fmt Formatting string * @param ap Variable argument list */ static void default_logger(FILE *fp, int level, const char *prefix, const char *file, int line, const char *fmt, va_list ap) { IB_FTRACE_INIT(default_logger); char fmt2[1024 + 1]; if (level > 4) { IB_FTRACE_RET_VOID(); } if ((file != NULL) && (line > 0)) { int ec = snprintf(fmt2, 1024, "%s[%d] (%s:%d) %s\n", (prefix?prefix:""), level, file, line, fmt); if (ec > 1024) { /// @todo Do something better abort(); } } else { int ec = snprintf(fmt2, 1024, "%s[%d] %s\n", (prefix?prefix:""), level, fmt); if (ec > 1024) { /// @todo Do something better abort(); } } vfprintf(fp, fmt2, ap); fflush(fp); IB_FTRACE_RET_VOID(); }
void ib_mpool_clear(ib_mpool_t *mp) { IB_FTRACE_INIT(ib_mpool_clear); ib_mpool_buffer_t *bufs = NULL; ib_mpool_buffer_t *next = NULL; if (mp == NULL) { IB_FTRACE_RET_VOID(); } /* @todo: destroy child pools */ int i = 0; ib_mpool_t *childs = NULL; ib_mpool_t *child_next = NULL; for (; childs; childs = child_next) { child_next = childs->next; ib_mpool_destroy(childs); } /* Move all out of the array of indexed, into busy_buffers */ for (; i < IB_MPOOL_MAX_INDEX; i++) { bufs = mp->indexed[i]; if (bufs != NULL) { for (; bufs != NULL; bufs = next) { next = bufs->next; bufs->prev = NULL; bufs->next = mp->busy_buffers; mp->busy_buffers = bufs; } mp->indexed[i] = NULL; } } /* Reset all buffers and index them */ size_t free_space = 0; bufs = mp->busy_buffers; for (; bufs != NULL; bufs = next) { next = bufs->next; /* Return some mem to the system if we have enough space already */ if (free_space > IB_MPOOL_INCREASE_FACTOR * IB_MPOOL_DEFAULT_PAGE_SIZE) { free(bufs); } else { IB_MPOOL_BUFFER_RESET(bufs); size_t slot = 0; /* Index the remaining buffer of the page */ IB_MPOOL_SET_INDEX(IB_MPOOL_BUFFER_AVAILABLE(bufs), slot); IB_MPOOL_ADD_BUFFER(mp, bufs, slot); free_space += bufs->size; } } mp->busy_buffers = NULL; mp->size = free_space; mp->inuse = 0; IB_FTRACE_RET_VOID(); }
void ib_mpool_destroy(ib_mpool_t *mp) { IB_FTRACE_INIT(ib_mpool_destroy); ib_mpool_buffer_t *bufs = NULL; ib_mpool_buffer_t *next = NULL; if (mp == NULL) { IB_FTRACE_RET_VOID(); } /* @todo: destroy child pools */ int i = 0; ib_mpool_t *childs = NULL; ib_mpool_t *child_next = NULL; for (; childs; childs = child_next) { child_next = childs->next; ib_mpool_destroy(childs); } /* Move all out of the array of indexed, into busy_buffers */ for (; i < IB_MPOOL_MAX_INDEX; i++) { bufs = mp->indexed[i]; if (bufs != NULL) { for (; bufs != NULL; bufs = next) { next = bufs->next; bufs->prev = NULL; bufs->next = mp->busy_buffers; mp->busy_buffers = bufs; } mp->indexed[i] = NULL; } } /* Free all buffers */ bufs = mp->busy_buffers; for (; bufs != NULL; bufs = next) { next = bufs->next; free(bufs); } mp->busy_buffers = NULL; mp->size = 0; mp->inuse = 0; /* If there's a registered clean up function, use it */ if (mp->free != NULL) { mp->free(mp->free_data); } /* Check if mp is alloced inside another pool or not */ if (mp->parent == NULL) { free(mp); } IB_FTRACE_RET_VOID(); }
/** * Engine default logger. * * This is the default logger that executes when no other logger has * been configured. * * @param fp File pointer * @param level Log level * @param tx Transaction information (or NULL) * @param prefix Optional prefix to the log * @param file Optional source filename (or NULL) * @param line Optional source line number (or 0) * @param fmt Formatting string * @param ap Variable argument list */ static void default_logger(FILE *fp, int level, const ib_tx_t *tx, const char *prefix, const char *file, int line, const char *fmt, va_list ap) { IB_FTRACE_INIT(); char fmt2[1024 + 1]; char tx_info[1024 + 1]; char time_info[32 + 1]; struct tm *tminfo; time_t timet; int ec = 0; if (level > 4) { IB_FTRACE_RET_VOID(); } if (tx != NULL) { ec = snprintf(tx_info, 1024, "[tx:%s] ", tx->id+31); } else { tx_info[0] = '\0'; } if (ec > 1024) { abort(); } timet = time(NULL); tminfo = localtime(&timet); strftime(time_info, sizeof(time_info)-1, "%d%m%Y.%Hh%Mm%Ss", tminfo); if ((file != NULL) && (line > 0)) { ec = snprintf(fmt2, 1024, "%s %s[%d] (%s:%d) %s%s\n", time_info, (prefix?prefix:""), level, file, line, tx_info, fmt); } else { ec = snprintf(fmt2, 1024, "%s %s[%d] %s%s\n", time_info, (prefix?prefix:""), level, tx_info, fmt); } if (ec > 1024) { /// @todo Do something better abort(); } vfprintf(fp, fmt2, ap); fflush(fp); IB_FTRACE_RET_VOID(); }
/** * Handle event starts. * * Here we set start times and increment the call counter. * * \param[in] ib IronBee object. * \param[in] eventp Event info. * \param[in] perf_info Perf info. **/ static void mod_perf_stats_event_start( ib_engine_t *ib, event_info_t *eventp, perf_info_t *perf_info ) { IB_FTRACE_INIT(); int cevent = eventp->number; /* Current event number. */ perf_info_t *perfp; /* Perf data on current event. */ if (perf_info != NULL) { /* Set perfp to current event type. */ perfp = &perf_info[cevent]; /* Set the start time for event */ perfp->start_usec = ib_clock_get_time(); /* Increment the call counter */ perfp->call_cnt++; ib_log_debug(ib, "Start Callback: %s (%llu) (%llu) ", perfp->name, perfp->call_cnt, perfp->start_usec); } else { ib_log_debug(ib, "Connection based perf_info is NULL"); } IB_FTRACE_RET_VOID(); }
void ib_vclog_ex(ib_context_t *ctx, int level, const char *prefix, const char *file, int line, const char *fmt, va_list ap) { IB_FTRACE_INIT(ib_vclog_ex); IB_PROVIDER_API_TYPE(logger) *api; ib_core_cfg_t *corecfg; ib_provider_inst_t *pi = NULL; ib_status_t rc; char prefix_with_pid[1024]; if (prefix != NULL) { snprintf(prefix_with_pid, 1024, "[%d] %s", getpid(), prefix); } else { snprintf(prefix_with_pid, 1024, "[%d] ", getpid()); } if (ctx != NULL) { rc = ib_context_module_config(ctx, ib_core_module(), (void *)&corecfg); if (rc == IB_OK) { pi = corecfg->pi.logger; } if (pi != NULL) { api = (IB_PROVIDER_API_TYPE(logger) *)pi->pr->api; api->vlogmsg(pi, ctx, level, prefix_with_pid, file, line, fmt, ap); IB_FTRACE_RET_VOID(); }
void ib_list_clear(ib_list_t *list) { IB_FTRACE_INIT(ib_list_clear); list->nelts = 0; list->head = list->tail = NULL; IB_FTRACE_RET_VOID(); }
void ib_cfgmap_clear(ib_cfgmap_t *cm) { IB_FTRACE_INIT(ib_cfgmap_clear); /// @todo Implement abort(); IB_FTRACE_RET_VOID(); }
void DLL_PUBLIC ib_vlog_ex(ib_engine_t *ib, int level, const ib_tx_t *tx, const char *prefix, const char *file, int line, const char *fmt, va_list ap) { IB_FTRACE_INIT(); IB_PROVIDER_API_TYPE(logger) *api; ib_core_cfg_t *corecfg; ib_provider_inst_t *pi = NULL; ib_status_t rc; ib_context_t *ctx; ctx = ib_context_main(ib); if (ctx != NULL) { rc = ib_context_module_config(ctx, ib_core_module(), (void *)&corecfg); if (rc == IB_OK) { pi = corecfg->pi.logger; } if (pi != NULL) { api = (IB_PROVIDER_API_TYPE(logger) *)pi->pr->api; api->vlogmsg(pi, ctx, level, tx, prefix, file, line, fmt, ap); IB_FTRACE_RET_VOID(); }
void ib_log_provider_set_instance(ib_context_t *ctx, ib_provider_inst_t *pi) { IB_FTRACE_INIT(); ib_core_cfg_t *corecfg; ib_status_t rc; rc = ib_context_module_config(ctx, ib_core_module(), (void *)&corecfg); if (rc != IB_OK) { /// @todo This func should return ib_status_t now IB_FTRACE_RET_VOID(); } corecfg->pi.logger = pi; IB_FTRACE_RET_VOID(); }
static void cfgp_set_current(ib_cfgparser_t *cp, ib_context_t *ctx) { IB_FTRACE_INIT(cfgp_set_current); cp->cur_ctx = ctx; cp->cur_loc = (ib_loc_t *)ctx->fn_ctx_data; cp->cur_site = cp->cur_loc?cp->cur_loc->site:NULL; IB_FTRACE_RET_VOID(); }
void ib_bytestr_make_read_only( ib_bytestr_t *bs ) { IB_FTRACE_INIT(); bs->flags |= IB_BYTESTR_FREADONLY; IB_FTRACE_RET_VOID(); }
void ib_cfgparser_destroy(ib_cfgparser_t *cp) { IB_FTRACE_INIT(ib_cfgparser_destroy); if (cp != NULL) { ib_mpool_destroy(cp->mp); } IB_FTRACE_RET_VOID(); }
/** * Count the amount of whitespace in a string for whitespace compression * * @param[in] minlen Minimum length of a run of whitespace to count * @param[in] data String to analyze * @param[in] dlen Length of @a dlen * @param[out] count Number of whitespace characters of runs > whitespace * @param[out] other Number of whitespace characters that are not ' '. */ static void ws_compress_count(size_t minlen, const uint8_t *data, size_t dlen, size_t *count, size_t *other) { IB_FTRACE_INIT(); ws_count(false, minlen, data, dlen, count, other); IB_FTRACE_RET_VOID(); }
void ib_hash_next( ib_hash_iterator_t *iterator ) { IB_FTRACE_INIT(); assert(iterator != NULL); iterator->current_entry = iterator->next_entry; while (! iterator->current_entry) { if (iterator->slot_index > iterator->hash->max_slot) { IB_FTRACE_RET_VOID(); } iterator->current_entry = iterator->hash->slots[iterator->slot_index]; ++iterator->slot_index; } iterator->next_entry = iterator->current_entry->next_entry; IB_FTRACE_RET_VOID(); }
void ib_mpool_cleanup_register(ib_mpool_t *mp, void *data, ib_mpool_cleanup_fn_t cleanup) { IB_FTRACE_INIT(ib_mpool_cleanup_register); /* @todo We should create here a list of callbacks, instead of just one, to allow multiple cleanups of different things */ mp->free = cleanup; mp->free_data = data; IB_FTRACE_RET_VOID(); }
/** * Remove unuseful failure links to skip using an invalid transition * * @param ac_tree the matcher that holds the patterns * @param state the state where it should start (it's used recursively) * */ static void ib_ac_unlink_unuseful(ib_ac_t *ac_tree, ib_ac_state_t *state) { IB_FTRACE_INIT(); ib_ac_state_t *child = NULL; ib_ac_state_t *fail_state = NULL; ib_ac_state_t *found = NULL; for (child = state->child; child != NULL; child = child->sibling) { if (child->fail == NULL || child->fail->child == NULL || child->child == NULL) { continue; } for (fail_state = child->fail->child; fail_state != ac_tree->root && fail_state != NULL; fail_state = fail_state->sibling) { found = ib_ac_child_for_code(child, fail_state->letter); if (found == NULL) { break; } } if (found != NULL) { /* There's no transition in the fail state that will * success, since the fail state doesn't have any letter not * present at the goto() of the main state. So let's * change the fail state to parent. Consider that this is * different to the output links (they'll still valid) */ child->fail = ac_tree->root; /* printf("Removing invalid fails\n"); */ } } for (child = state->child; child != NULL; child = child->sibling) { if (child->child != NULL) { ib_ac_unlink_unuseful(ac_tree, child); } } IB_FTRACE_RET_VOID(); }
void DLL_PUBLIC ib_log_ex(ib_engine_t *ib, int level, const ib_tx_t *tx, const char *prefix, const char *file, int line, const char *fmt, ...) { IB_FTRACE_INIT(); va_list ap; va_start(ap, fmt); ib_vlog_ex(ib, level, tx, prefix, file, line, fmt, ap); va_end(ap); IB_FTRACE_RET_VOID(); }
/** * Wrapper for the callback call * * @param ac_ctx the matching context * @param ac_ctx the state where a pattern match (output) is found * */ static void ib_ac_do_callback(ib_ac_context_t *ac_ctx, ib_ac_state_t *state) { IB_FTRACE_INIT(); ib_ac_t *ac_tree = ac_ctx->ac_tree; if (state->callback != NULL) { state->callback(ac_tree, state->pattern, state->level + 1, state->data, ac_ctx->processed - (state->level + 1), ac_ctx->current_offset - (state->level + 1)); } state->match_cnt++; IB_FTRACE_RET_VOID(); }
/** * Count the amount of whitespace in a string * * @param[in] force_other_zero If true, force @a other to zero * @param[in] minlen Minimum length of a run of whitespace to count * @param[in] data String to analyze * @param[in] dlen Length of @a dlen * @param[out] count Number of whitespace characters of runs > whitespace * @param[out] other Number of whitespace characters that are not ' '. */ static void ws_count(bool force_other_zero, size_t minlen, const uint8_t *data, size_t dlen, size_t *count, size_t *other) { IB_FTRACE_INIT(); const uint8_t *end; size_t icount = 0; /* Internal count */ size_t iother = 0; /* Internal other */ size_t runlen = 0; /* Loop through the whole string */ end = data + dlen; while (data <= end) { uint8_t c = *data; if (isspace(c) == 0) { runlen = 0; } else { ++runlen; if (runlen >= minlen) { ++icount; } if (c != ' ') { ++iother; } } ++data; } *count = icount; *other = (force_other_zero == true) ? 0 : iother; IB_FTRACE_RET_VOID(); }
/** * Link branches that are subpatterns of other to produce it's output * * @param ac_tree the matcher that holds the patterns * @param state the state where it should start (it's used recursively) * */ static void ib_ac_link_outputs(ib_ac_t *ac_tree, ib_ac_state_t *state) { IB_FTRACE_INIT(); ib_ac_state_t *child = NULL; ib_ac_state_t *outs = NULL; for (child = state->child; child != NULL; child = child->sibling) { if (child->fail == NULL) { continue; } for (outs = child->fail; outs != ac_tree->root && outs != NULL; outs = outs->fail) { if (outs->flags & IB_AC_FLAG_STATE_OUTPUT) { child->outputs = outs; break; } } } for (child = state->child; child != NULL; child = child->sibling) { if (child->child != NULL) { ib_ac_link_outputs(ac_tree, child); } } IB_FTRACE_RET_VOID(); }
void ib_list_node_remove(ib_list_t *list, ib_list_node_t *node) { IB_FTRACE_INIT(ib_list_node_remove); IB_LIST_NODE_REMOVE(list, node); IB_FTRACE_RET_VOID(); }
void ib_log_provider_set_instance(ib_context_t *ctx, ib_provider_inst_t *pi) { IB_FTRACE_INIT(ib_log_provider_set_instance); ctx->logger = pi; IB_FTRACE_RET_VOID(); }
void ib_provider_data_set(ib_provider_t *pr, void *data) { IB_FTRACE_INIT(); pr->data = data; IB_FTRACE_RET_VOID(); }