static struct a_net_chan *netdata_chan(struct a_network *net, const char *name) { if (net == NULL || name == NULL) return; return mowgli_patricia_retrieve(net->nd.chans, name); }
mowgli_allocation_policy_t * mowgli_allocation_policy_lookup(const char *name) { if (mowgli_allocation_policy_dict == NULL) mowgli_allocation_policy_dict = mowgli_patricia_create(_allocation_policy_key_canon); return mowgli_patricia_retrieve(mowgli_allocation_policy_dict, name); }
struct a_network *a_network_by_name(struct a_account *acct, char *name) { mowgli_patricia_t *networks; if (acct == NULL || name == NULL) return NULL; return mowgli_patricia_retrieve(acct->networks, name); }
void db_process(database_handle_t *db, const char *type) { database_handler_f fun; return_if_fail(db_types != NULL); return_if_fail(db != NULL); return_if_fail(type != NULL); fun = mowgli_patricia_retrieve(db_types, type); if (!fun) { fun = mowgli_patricia_retrieve(db_types, "???"); } fun(db, type); }
void * mowgli_global_storage_get(char *name) { void *ret; /* name serves as lock token */ mowgli_spinlock_lock(mowgli_global_storage_lock, name, NULL); ret = mowgli_patricia_retrieve(mowgli_global_storage_dict, name); mowgli_spinlock_unlock(mowgli_global_storage_lock, name, NULL); return ret; }
static struct myentity * chanacs_validate_f(const char *param) { static const struct entity_chanacs_validation_vtable chanacs_ext_validate = { .match_entity = chanacs_ext_match_entity, .match_user = chanacs_ext_match_user, .can_register_channel = chanacs_ext_can_register_channel, .allow_foundership = chanacs_allow_foundership, }; char *name; struct this_exttarget *ext; size_t namelen; if (param == NULL) return NULL; if (*param == '\0') return NULL; // if we already have an object, return it from our tree. if ((ext = mowgli_patricia_retrieve(chanacs_exttarget_tree, param)) != NULL) return entity(ext); ext = mowgli_heap_alloc(chanacs_ext_heap); ext->channel = strshare_get(param); ext->checking = 0; // name the entity... $chanacs:param #define NAMEPREFIX "$chanacs:" namelen = sizeof NAMEPREFIX + strlen(param); name = smalloc(namelen); memcpy(name, NAMEPREFIX, sizeof NAMEPREFIX - 1); memcpy(name + sizeof NAMEPREFIX - 1, param, namelen - sizeof NAMEPREFIX + 1); entity(ext)->name = strshare_get(name); sfree(name); #undef NAMEPREFIX // hook up the entity's validation table. entity(ext)->chanacs_validate = &chanacs_ext_validate; entity(ext)->type = ENT_EXTTARGET; // initialize the object. atheme_object_init(atheme_object(ext), entity(ext)->name, (atheme_object_destructor_fn) chanacs_ext_delete); // add the object to the exttarget tree mowgli_patricia_add(chanacs_exttarget_tree, ext->channel, ext); // return the object as initially unowned by sinking the reference count. return atheme_object_sink_ref(ext); }
unsigned int handle_ctcp_common(sourceinfo_t *si, char *cmd, char *args) { void (*handler)(sourceinfo_t *si, char *, char *); if ((handler = mowgli_patricia_retrieve(ctcptree, cmd)) != NULL) { handler(si, cmd, args); return 1; } return 0; }
static void netdata_chan_add(struct a_network *net, const char *name) { struct a_net_chan *chan; if (!net || !name || mowgli_patricia_retrieve(net->nd.chans, name)) return; chan = mowgli_alloc(sizeof(*chan)); chan->name = mowgli_strdup(name); chan->topic = mowgli_string_create(); chan->users = create_users_patricia(net); mowgli_patricia_add(net->nd.chans, name, chan); }
unsigned int handle_ctcp_common(sourceinfo_t *si, char *cmd, char *args) { void (*handler)(char *, char *, char *, char *); handler = mowgli_patricia_retrieve(ctcptree, cmd); if (handler != NULL) { handler(cmd, args, si->su->nick, si->service->nick); return 1; } return 0; }
const char * libguess_determine_encoding(const char *inbuf, int buflen, const char *lang) { guess_impl_f impl; libguess_init(); impl = mowgli_patricia_retrieve(guess_impl_list, lang); if (impl != NULL) return impl(inbuf, buflen); /* TODO: try other languages as fallback? */ return NULL; }
char *strshare_get(const char *str) { strshare_t *ss; ss = mowgli_patricia_retrieve(strshare_dict, str); if (ss != NULL) ss->refcount++; else { ss = smalloc(sizeof(strshare_t) + strlen(str) + 1); ss->refcount = 1; strcpy((char *)(ss + 1), str); mowgli_patricia_add(strshare_dict, (char *)(ss + 1), ss); } return (char *)(ss + 1); }
static myentity_t *chanacs_validate_f(const char *param) { char *name; chanacs_exttarget_t *ext; size_t namelen; if (param == NULL) return NULL; if (*param == '\0') return NULL; /* if we already have an object, return it from our tree. */ if ((ext = mowgli_patricia_retrieve(chanacs_exttarget_tree, param)) != NULL) return entity(ext); ext = mowgli_heap_alloc(chanacs_ext_heap); ext->channel = strshare_get(param); ext->checking = 0; /* name the entity... $chanacs:param */ #define NAMEPREFIX "$chanacs:" namelen = sizeof NAMEPREFIX + strlen(param); name = smalloc(namelen); memcpy(name, NAMEPREFIX, sizeof NAMEPREFIX - 1); memcpy(name + sizeof NAMEPREFIX - 1, param, namelen - sizeof NAMEPREFIX + 1); entity(ext)->name = strshare_get(name); free(name); #undef NAMEPREFIX /* hook up the entity's validation table. */ entity(ext)->chanacs_validate = &chanacs_ext_validate; entity(ext)->type = ENT_EXTTARGET; /* initialize the object. */ object_init(object(ext), entity(ext)->name, (destructor_t) chanacs_ext_delete); /* add the object to the exttarget tree */ mowgli_patricia_add(chanacs_exttarget_tree, ext->channel, ext); /* return the object as initially unowned by sinking the reference count. */ return object_sink_ref(ext); }
mowgli_interface_t * mowgli_interface_get(const char *id, uint32_t abirev) { mowgli_interface_base_t *base_iface; mowgli_mutex_lock(&mowgli_interface_lock); base_iface = mowgli_patricia_retrieve(mowgli_interface_dict, id); if (base_iface->abirev != abirev) { mowgli_log("requested interface %s, abi mismatch %" PRIu32 " != %" PRIu32, id, abirev, base_iface->abirev); base_iface = NULL; } mowgli_mutex_unlock(&mowgli_interface_lock); return base_iface; }
static command_t *help_cmd_find(sourceinfo_t *si, const char *subcmd_of, const char *cmd, mowgli_patricia_t *list) { command_t *c; if ((c = mowgli_patricia_retrieve(list, cmd)) != NULL && command_has_help(c)) return c; no_help_available(si, subcmd_of, cmd); /* Fun for helpchan/helpurl. */ if (config_options.helpchan && config_options.helpurl) command_fail(si, fault_nosuch_target, _("If you're having trouble, you may want to join the help channel %s or visit the help webpage %s"), config_options.helpchan, config_options.helpurl); else if (config_options.helpchan && !config_options.helpurl) command_fail(si, fault_nosuch_target, _("If you're having trouble, you may want to join the help channel %s"), config_options.helpchan); else if (!config_options.helpchan && config_options.helpurl) command_fail(si, fault_nosuch_target, _("If you're having trouble, you may want to visit the help webpage %s"), config_options.helpurl); return NULL; }
mowgli_allocation_policy_t * mowgli_allocation_policy_create(const char *name, mowgli_allocation_func_t allocator, mowgli_deallocation_func_t deallocator) { mowgli_allocation_policy_t *policy; if (mowgli_allocation_policy_dict == NULL) mowgli_allocation_policy_dict = mowgli_patricia_create(_allocation_policy_key_canon); if ((policy = mowgli_patricia_retrieve(mowgli_allocation_policy_dict, name))) return policy; policy = mowgli_alloc(sizeof(mowgli_allocation_policy_t)); mowgli_object_init_from_class(mowgli_object(policy), name, &klass); policy->allocate = allocator; policy->deallocate = deallocator; mowgli_patricia_add(mowgli_allocation_policy_dict, name, policy); return policy; }
static void aknl_nickhook(hook_user_nick_t *data) { return_if_fail(data != NULL); if (! data->u) return; user_t *const u = data->u; if (is_internal_client(u)) return; if (is_autokline_exempt(u)) return; if (u->flags & UF_KLINESENT) return; const char *username = u->user; if (*username == '~') username++; bool doit = false; if (mowgli_patricia_retrieve(akillnicklist, u->nick)) doit = true; else if (mowgli_patricia_retrieve(akilluserlist, username)) doit = true; else if (mowgli_patricia_retrieve(akillreallist, u->gecos)) doit = true; else if (mowgli_patricia_retrieve(akillalllist, u->nick)) doit = true; else if (mowgli_patricia_retrieve(akillalllist, username)) doit = true; else if (mowgli_patricia_retrieve(akillalllist, u->gecos)) doit = true; else return; slog(LG_INFO, "AKNL: k-lining \2%s\2!%s@%s [%s] due to appearing to be a possible spambot", u->nick, u->user, u->host, u->gecos); kline_add(u->user, u->host, "Possible spambot", 86400, "*"); u->flags |= UF_KLINESENT; }
static int net_add_to_account(struct a_network *net, const char *acct_name) { struct a_account *acct; acct = a_account_find(acct_name); if (acct == NULL) { a_log(LERROR, "Could not find account %s", acct_name); return -1; } if (mowgli_patricia_retrieve(acct->networks, net->name) != NULL) { a_log(LERROR, "Network %s for %s already exists, ignoring duplicate configuration", net->name, acct->name); return -1; } a_log(LINFO, "Adding network %s to account %s", net->name, acct->name); mowgli_patricia_add(acct->networks, net->name, net); net->acct = acct; return 0; }
static void aknl_nickhook(hook_user_nick_t *data) { user_t *u; bool doit = false; const char *username; return_if_fail(data != NULL); if (!data->u) return; u = data->u; if (is_internal_client(u)) return; if (is_autokline_exempt(u)) return; username = u->user; if (*username == '~') username++; if (mowgli_patricia_retrieve(akillalllist, u->nick) != NULL && mowgli_patricia_retrieve(akillalllist, username) != NULL && mowgli_patricia_retrieve(akillalllist, u->gecos) != NULL) doit = true; if (mowgli_patricia_retrieve(akillnicklist, u->nick) != NULL) doit = true; if (mowgli_patricia_retrieve(akilluserlist, username) != NULL) doit = true; if (mowgli_patricia_retrieve(akillreallist, u->gecos) != NULL) doit = true; if (!doit) return; slog(LG_INFO, "AKNL: k-lining \2%s\2!%s@%s [%s] due to appearing to be a possible spambot", u->nick, u->user, u->host, u->gecos); kline_sts("*", "*", u->host, 86400, "Possible spambot"); }
pcommand_t *pcommand_find(const char *token) { return mowgli_patricia_retrieve(pcommands, token); }
void xmlrpc_process(char *buffer, void *userdata) { int retVal = 0; XMLRPCCmd *current = NULL; XMLRPCCmd *xml; char *tmp; int ac; char **av = NULL; char *name = NULL; xmlrpc_error_code = 0; if (!buffer) { xmlrpc_error_code = -1; return; } tmp = xmlrpc_parse(buffer); if (tmp) { name = xmlrpc_method(tmp); if (name) { xml = mowgli_patricia_retrieve(XMLRPCCMD, name); if (xml) { ac = xmlrpc_split_buf(tmp, &av); if (xml->func) { retVal = xml->func(userdata, ac, av); if (retVal == XMLRPC_CONT) { current = xml->next; while (current && current->func && retVal == XMLRPC_CONT) { retVal = current->func(userdata, ac, av); current = current->next; } } else { /* we assume that XMLRPC_STOP means the handler has given no output */ xmlrpc_error_code = -7; xmlrpc_generic_error(xmlrpc_error_code, "XMLRPC error: First eligible function returned XMLRPC_STOP"); } } else { xmlrpc_error_code = -6; xmlrpc_generic_error(xmlrpc_error_code, "XMLRPC error: Method has no registered function"); } } else { xmlrpc_error_code = -4; xmlrpc_generic_error(xmlrpc_error_code, "XMLRPC error: Unknown routine called"); } } else { xmlrpc_error_code = -3; xmlrpc_generic_error(xmlrpc_error_code, "XMLRPC error: Missing methodRequest or methodName."); } } else { xmlrpc_error_code = -2; xmlrpc_generic_error(xmlrpc_error_code, "XMLRPC error: Invalid document end at line 1"); } free(av); free(tmp); free(name); }
action_t * action_find(const char *action) { return mowgli_patricia_retrieve(action_list, action); }