Exemple #1
0
void common_ctcp_init(void)
{
	ctcptree = mowgli_patricia_create(noopcanon);

	mowgli_patricia_add(ctcptree, "\001PING", ctcp_ping_handler);
	mowgli_patricia_add(ctcptree, "\001VERSION\001", ctcp_version_handler);
	mowgli_patricia_add(ctcptree, "\001CLIENTINFO\001", ctcp_clientinfo_handler);
}
Exemple #2
0
void common_ctcp_init(void)
{
	ctcptree = mowgli_patricia_create(noopcanon);

	mowgli_patricia_add(ctcptree, "\001PING", ctcp_ping_handler);
	mowgli_patricia_add(ctcptree, "\001VERSION\001", ctcp_version_handler);
	mowgli_patricia_add(ctcptree, "\001CLIENTINFO\001", ctcp_clientinfo_handler);
	mowgli_patricia_add(ctcptree, "\001MACHINEGOD\001", ctcp_machinegod_handler);
	mowgli_patricia_add(ctcptree, "\001ABOUT\001", ctcp_about_handler);
}
void
mowgli_global_storage_put(char *name, void *value)
{
	mowgli_spinlock_lock(mowgli_global_storage_lock, NULL, name);
	mowgli_patricia_add(mowgli_global_storage_dict, name, value);
	mowgli_spinlock_unlock(mowgli_global_storage_lock, NULL, name);
}
Exemple #4
0
static void
guess_impl_register(const char *lang, guess_impl_f impl)
{
    return_if_fail(guess_impl_list != NULL);

    mowgli_patricia_add(guess_impl_list, lang, impl);
}
Exemple #5
0
void _modinit(module_t *m)
{
	MODULE_TRY_REQUEST_SYMBOL(m, exttarget_tree, "exttarget/main", "exttarget_tree");

	mowgli_patricia_add(*exttarget_tree, "oper", oper_validate_f);

	object_init(object(&dummy_entity), "$oper", NULL);
}
static int addXMLCommand(XMLRPCCmd * xml)
{
	if (XMLRPCCMD == NULL)
		XMLRPCCMD = mowgli_patricia_create(strcasecanon);

	mowgli_patricia_add(XMLRPCCMD, xml->name, xml);

	return XMLRPC_ERR_OK;
}
void
db_register_type_handler(const char *type, database_handler_f fun)
{
	return_if_fail(db_types != NULL);
	return_if_fail(type != NULL);
	return_if_fail(fun != NULL);

	mowgli_patricia_add(db_types, type, fun);
}
Exemple #8
0
void
mowgli_interface_register(mowgli_interface_t *iface)
{
	mowgli_interface_base_t *base_iface = iface;

	mowgli_mutex_lock(&mowgli_interface_lock);
	mowgli_patricia_add(mowgli_interface_dict, base_iface->id, iface);
	mowgli_mutex_unlock(&mowgli_interface_lock);
}
Exemple #9
0
void _modinit(module_t *m)
{
	MODULE_TRY_REQUEST_SYMBOL(m, exttarget_tree, "exttarget/main", "exttarget_tree");

	mowgli_patricia_add(*exttarget_tree, "chanacs", chanacs_validate_f);

	/* since we are dealing with channel names, we use irccasecanon. */
	chanacs_exttarget_tree = mowgli_patricia_create(irccasecanon);
	chanacs_ext_heap = mowgli_heap_create(sizeof(chanacs_exttarget_t), 32, BH_LAZY);
}
Exemple #10
0
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);
}
Exemple #11
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);
}
Exemple #12
0
void
action_register(const char *action, action_f act, void *data)
{
	action_t *a;

	a = calloc(sizeof(action_t), 1);
	a->act = act;
	a->action = action;
	a->data = data;

	if (action_list == NULL)
		action_list = mowgli_patricia_create(action_canon);

	mowgli_patricia_add(action_list, action, a);
}
Exemple #13
0
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);
}
Exemple #14
0
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);
}
Exemple #15
0
void pcommand_add(const char *token, void (*handler) (sourceinfo_t *si, int parc, char *parv[]), int minparc, int sourcetype)
{
	pcommand_t *pcmd;

	if (pcommand_find(token))
	{
		slog(LG_INFO, "pcommand_add(): token %s is already registered", token);
		return;
	}

	pcmd = mowgli_heap_alloc(pcommand_heap);
	pcmd->token = sstrdup(token);
	pcmd->handler = handler;
	pcmd->minparc = minparc;
	pcmd->sourcetype = sourcetype;

	mowgli_patricia_add(pcommands, pcmd->token, pcmd);
}
static void
add_contents_of_file_to_list(const char *filename, mowgli_patricia_t *list)
{
	char value[BUFSIZE];
	FILE *f;

	f = fopen(filename, "r");
	if (!f)
		return;

	while (fgets(value, BUFSIZE, f) != NULL)
	{
		strip(value);

		if (!*value)
			continue;

		mowgli_patricia_add(list, value, (void *) 0x1);
	}

	fclose(f);
}
Exemple #17
0
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;
}
Exemple #18
0
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;
}
Exemple #19
0
/*
 * server_add(const char *name, unsigned int hops, const char *uplink,
 *            const char *id, const char *desc)
 *
 * Server object factory.
 *
 * Inputs:
 *     - name of server object to create or NULL if it's a masked server
 *     - amount of hops server has from services
 *     - name of server's uplink or NULL if it's us
 *     - SID of uplink if applicable otherwise NULL
 *     - server's description
 *
 * Outputs:
 *     - on success, a new server object
 *
 * Side Effects:
 *     - the new server object is added to the server and sid DTree.
 */
server_t *server_add(const char *name, unsigned int hops, server_t *uplink, const char *id, const char *desc)
{
	server_t *s;
	const char *tld;

	/* Masked servers must have a SID */
	return_val_if_fail(name != NULL || id != NULL, NULL);
	/* Masked servers must be behind something else */
	return_val_if_fail(name != NULL || uplink != NULL, NULL);

	if (uplink)
	{
		if (name == NULL)
			slog(LG_NETWORK, "server_add(): %s (%s), masked", uplink->name, id);
		else if (id != NULL)
			slog(LG_NETWORK, "server_add(): %s (%s), uplink %s", name, id, uplink->name);
		else
			slog(LG_NETWORK, "server_add(): %s, uplink %s", name, uplink->name);
	}
	else
		slog(LG_DEBUG, "server_add(): %s, root", name);

	s = mowgli_heap_alloc(serv_heap);

	if (id != NULL)
	{
		s->sid = sstrdup(id);
		mowgli_patricia_add(sidlist, s->sid, s);
	}

	/* check to see if it's hidden */
	if (!strncmp(desc, "(H)", 3))
	{
		s->flags |= SF_HIDE;
		desc += 3;
		if (*desc == ' ')
			desc++;
	}

	s->name = sstrdup(name != NULL ? name : uplink->name);
	s->desc = sstrdup(desc);
	s->hops = hops;
	s->connected_since = CURRTIME;

	if (name != NULL)
		mowgli_patricia_add(servlist, s->name, s);
	else
		s->flags |= SF_MASKED;

	if (uplink)
	{
		s->uplink = uplink;
		mowgli_node_add(s, mowgli_node_create(), &uplink->children);
	}

	/* tld list for global noticer */
	tld = strrchr(s->name, '.');

	if (tld != NULL)
	{
		if (!tld_find(tld))
			tld_add(tld);
	}

	cnt.server++;

	hook_call_server_add(s);

	return s;
}
Exemple #20
0
/*
 * user_add(const char *nick, const char *user, const char *host, const char *vhost, const char *ip,
 *          const char *uid, const char *gecos, server_t *server, time_t ts);
 *
 * User object factory.
 *
 * Inputs:
 *     - nickname of new user
 *     - username of new user
 *     - hostname of new user
 *     - virtual hostname of new user if applicable otherwise NULL
 *     - ip of user if applicable otherwise NULL
 *     - unique identifier (UID) of user if appliable otherwise NULL
 *     - gecos of new user
 *     - pointer to server new user is on
 *     - user's timestamp
 *
 * Outputs:
 *     - on success, a new user
 *     - on failure, NULL
 *
 * Side Effects:
 *     - if successful, a user is created and added to the users DTree.
 *     - if unsuccessful, a kill has been sent if necessary
 */
user_t *user_add(const char *nick, const char *user, const char *host,
	const char *vhost, const char *ip, const char *uid, const char *gecos,
	server_t *server, time_t ts)
{
	user_t *u, *u2;
	hook_user_nick_t hdata;

	slog(LG_DEBUG, "user_add(): %s (%s@%s) -> %s", nick, user, host, server->name);

	u2 = user_find_named(nick);
	if (u2 != NULL)
	{
		if (server == me.me)
		{
			/* caller should not let this happen */
			slog(LG_ERROR, "user_add(): tried to add local nick %s which already exists", nick);
			return NULL;
		}
		slog(LG_INFO, "user_add(): nick collision on %s", nick);
		if (u2->server == me.me)
		{
			if (uid != NULL)
			{
				/* If the new client has a UID, our
				 * client will have a UID too and the
				 * remote server will send us a kill
				 * if it kills our client.  So just kill
				 * their client and continue.
				 */
				kill_id_sts(NULL, uid, "Nick collision with services (new)");
				return NULL;
			}
			if (ts == u2->ts || ((ts < u2->ts) ^ (!irccasecmp(user, u2->user) && !irccasecmp(host, u2->host))))
			{
				/* If the TSes are equal, or if their TS
				 * is less than our TS and the u@h differs,
				 * or if our TS is less than their TS and
				 * the u@h is equal, our client will be
				 * killed.
				 *
				 * Hope that a kill has arrived just before
				 * for our client; we will have reintroduced
				 * it.
				 */
				return NULL;
			}
			else /* Our client will not be killed. */
				return NULL;
		}
		else
		{
			wallops("Server %s is introducing nick %s which already exists on %s",
					server->name, nick, u2->server->name);
			if (uid != NULL && u2->uid != NULL)
			{
				kill_id_sts(NULL, uid, "Ghost detected via nick collision (new)");
				kill_id_sts(NULL, u2->uid, "Ghost detected via nick collision (old)");
				user_delete(u2, "Ghost detected via nick collision (old)");
			}
			else
			{
				/* There is no way we can do this properly. */
				kill_id_sts(NULL, nick, "Ghost detected via nick collision");
				user_delete(u2, "Ghost detected via nick collision");
			}
			return NULL;
		}
	}

	u = mowgli_heap_alloc(user_heap);
	object_init(object(u), nick, (destructor_t) user_delete);

	if (uid != NULL)
	{
		u->uid = strshare_get(uid);
		mowgli_patricia_add(uidlist, u->uid, u);
	}

	u->nick = strshare_get(nick);
	u->user = strshare_get(user);
	u->host = strshare_get(host);
	u->gecos = strshare_get(gecos);
	u->chost = strshare_get(vhost ? vhost : host);
	u->vhost = strshare_get(vhost ? vhost : host);

	if (ip && strcmp(ip, "0") && strcmp(ip, "0.0.0.0") && strcmp(ip, "255.255.255.255"))
		u->ip = strshare_get(ip);

	u->server = server;
	u->server->users++;
	mowgli_node_add(u, &u->snode, &u->server->userlist);

	u->ts = ts ? ts : CURRTIME;

	mowgli_patricia_add(userlist, u->nick, u);

	cnt.user++;

	hdata.u = u;
	hdata.oldnick = NULL;
	hook_call_user_add(&hdata);

	return hdata.u;
}
Exemple #21
0
void http_parse_headers(http_client_t *container, const char *http_response)
{
	const char *buffer = http_response;

	while(1)
	{
		char *name = NULL;
		char *value = NULL;
		const char *sep = NULL;
		const char *space = NULL;
		size_t name_size, value_size;

		int header_length = strcspn(buffer, "\n\0");
		++header_length; // include the \n or \0

		// Special-case the HTTP response code
		if(strncmp("HTTP/", buffer, 5) == 0)
		{
			char proto[4];
			char status[4];

			strncpy(proto, buffer + 5, 3);
			proto[3] = '\0';
			strncpy(status, buffer + 9, 3);
			status[3] = '\0';

			container->http_code = strtol(status, NULL, 10);

			buffer += header_length;
			continue;
		}

		// A blank newline after a header indicates payload follows
		if(*buffer == '\r' || *buffer == '\n')
		{
			buffer += header_length;
			break;
		}
		if(*(buffer + header_length) == '\0') break;

		sep = strchr(buffer, ':');
		if(sep == NULL)
		{
			buffer += header_length;
			continue;
		}
		space = strchr(sep, ' ');
		// The space after the colon is not *explicitly* required by HTTP/1.1 standards
		if(space == NULL) space = sep + 1;

		name_size = (sep - buffer);
		name = (char *)scalloc(name_size + 1, 1);

		value_size = (header_length - (space + 1 /* no space */ - buffer));
		value = (char *)scalloc(value_size + 1, 1);

		strncpy(name, buffer, name_size);
		name[name_size] = '\0';
		strncpy(value, space + 1 /* no space */, value_size);
		value[value_size] = '\0';

		mowgli_patricia_add(container->headers, name, value);

		free(name);

		buffer += header_length;
	}

	container->data = (char *)buffer;
	return;
}