<commit_before>/* Tethys, conf.c -- configuration parser
   Copyright (C) 2013 <NAME>
   Copyright (C) 2014 <NAME>

   This file is protected under the terms contained
   in the COPYING file in the project root */

#include "ircd.h"

struct conf_handler {
	const char *key;
	u_conf_handler_t *cb;
	u_module *owner;
};

static mowgli_patricia_t *u_conf_handlers = NULL;

void u_conf_traverse(mowgli_config_file_t *cf, mowgli_config_file_entry_t *ce, mowgli_patricia_t *handlers)
{
	struct conf_handler *h;

	u_log(LG_FINE, "conf: %s=%s", ce->varname, ce->vardata);

	if (!handlers)
		return;

	h = mowgli_patricia_retrieve(handlers, ce->varname);

	if (h == NULL) {
		u_log(LG_WARN, "No config handler for %s=%s", ce->varname, ce->vardata);
		return;
	}

	h->cb(cf, ce);
}

bool u_conf_read(const char *path)
{
	mowgli_config_file_t *cf;
	mowgli_config_file_entry_t *ce;

	cf = mowgli_config_file_load(path);
	if (cf == NULL)
		return false;

	u_hook_call(HOOK_CONF_START, cf);

	MOWGLI_ITER_FOREACH(ce, cf->entries) {
		u_conf_traverse(cf, ce, u_conf_handlers);
	}

	u_hook_call(HOOK_CONF_END, cf);
<commit_msg>conf: Make u_conf_traverse perform iteration<commit_after>/* Tethys, conf.c -- configuration parser
   Copyright (C) 2013 <NAME>
   Copyright (C) 2014 <NAME>

   This file is protected under the terms contained
   in the COPYING file in the project root */

#include "ircd.h"

struct conf_handler {
	const char *key;
	u_conf_handler_t *cb;
	u_module *owner;
};

static mowgli_patricia_t *u_conf_handlers = NULL;

void u_conf_traverse(mowgli_config_file_t *cf, mowgli_config_file_entry_t *ce,
                     mowgli_patricia_t *handlers)
{
	struct conf_handler *h;
	mowgli_config_file_entry_t *cce;

	if (!handlers)
		return;

	MOWGLI_ITER_FOREACH(cce, ce) {
		u_log(LG_FINE, "conf: %s=%s", cce->varname, cce->vardata);

		h = mowgli_patricia_retrieve(handlers, cce->varname);

		if (h == NULL) {
			u_log(LG_WARN, "No config handler for %s=%s",
			      cce->varname, cce->vardata);
			continue;
		}

		h->cb(cf, cce);
	}
}

bool u_conf_read(const char *path)
{
	mowgli_config_file_t *cf;

	cf = mowgli_config_file_load(path);
	if (cf == NULL)
		return false;

	u_hook_call(HOOK_CONF_START, cf);

	u_conf_traverse(cf, cf->entries, u_conf_handlers);

	u_hook_call(HOOK_CONF_END, cf);

{'fraction_non_alphanumeric': 0.12048716833405829, 'fraction_numerical': 0.006959547629404089, 'mean_word_length': 4.542168674698795, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3037802', 'n_tokens_mistral': 1023, 'n_tokens_neox': 956, 'n_words': 210}