Exemplo n.º 1
0
static SETUP_SERVER_REC *setupserver_add_node(CONFIG_NODE *node)
{
	SETUP_SERVER_REC *rec;
	char *server;
	int port;

	g_return_val_if_fail(node != NULL, NULL);

	server = config_node_get_str(node, "address", NULL);
	if (server == NULL) return NULL;

	port = config_node_get_int(node, "port", 6667);
	if (server_setup_find(server, port) != NULL) {
		/* already exists - don't let it get there twice or
		   server reconnects will screw up! */
		return NULL;
	}

	rec = g_new0(SETUP_SERVER_REC, 1);
	rec->ircnet = g_strdup(config_node_get_str(node, "ircnet", NULL));
	rec->address = g_strdup(server);
	rec->password = g_strdup(config_node_get_str(node, "password", NULL));
	rec->port = port;
	rec->autoconnect = config_node_get_bool(node, "autoconnect", FALSE);
	rec->max_cmds_at_once = config_node_get_int(node, "cmds_max_at_once", 0);
	rec->cmd_queue_speed = config_node_get_int(node, "cmd_queue_speed", 0);
	rec->own_host = g_strdup(config_node_get_str(node, "own_host", 0));

	setupservers = g_slist_append(setupservers, rec);
	return rec;
}
Exemplo n.º 2
0
static void read_hilight_config(void)
{
	CONFIG_NODE *node;
	HILIGHT_REC *rec;
	GSList *tmp;
	char *text, *color;

	hilights_destroy_all();

	node = iconfig_node_traverse("hilights", FALSE);
	if (node == NULL) {
                reset_cache();
		return;
	}

	tmp = config_node_first(node->value);
	for (; tmp != NULL; tmp = config_node_next(tmp)) {
		node = tmp->data;

		if (node->type != NODE_TYPE_BLOCK)
			continue;

		text = config_node_get_str(node, "text", NULL);
		if (text == NULL || *text == '\0')
			continue;

		rec = g_new0(HILIGHT_REC, 1);
		hilights = g_slist_append(hilights, rec);

		rec->text = g_strdup(text);

		color = config_node_get_str(node, "color", NULL);
		rec->color = color == NULL || *color == '\0' ? NULL :
			g_strdup(color);

		color = config_node_get_str(node, "act_color", NULL);
		rec->act_color = color == NULL || *color == '\0' ? NULL :
			g_strdup(color);

		rec->level = config_node_get_int(node, "level", 0);
		rec->priority = config_node_get_int(node, "priority", 0);
		rec->nick = config_node_get_bool(node, "nick", TRUE);
		rec->word = config_node_get_bool(node, "word", TRUE);
		rec->case_sensitive = config_node_get_bool(node, "matchcase", FALSE);

		rec->nickmask = config_node_get_bool(node, "mask", FALSE);
		rec->fullword = config_node_get_bool(node, "fullword", FALSE);
		rec->regexp = config_node_get_bool(node, "regexp", FALSE);
		rec->servertag = config_node_get_str(node, "servertag", NULL);
		hilight_init_rec(rec);

		node = iconfig_node_section(node, "channels", -1);
		if (node != NULL) rec->channels = config_node_get_list(node);
	}

	reset_cache();
}
Exemplo n.º 3
0
static void sig_server_setup_read(IRC_SERVER_SETUP_REC *rec, CONFIG_NODE *node)
{
	g_return_if_fail(rec != NULL);
	g_return_if_fail(node != NULL);

	if (!IS_IRC_SERVER_SETUP(rec))
		return;

	rec->max_cmds_at_once = config_node_get_int(node, "cmds_max_at_once", 0);
	rec->cmd_queue_speed = config_node_get_int(node, "cmd_queue_speed", 0);
	rec->max_query_chans = config_node_get_int(node, "max_query_chans", 0);
}
Exemplo n.º 4
0
static CONFIG_NODE *statusbar_copy_config(CONFIG_REC *config, CONFIG_NODE *source,
                                          CONFIG_NODE *parent)
{
	GSList *tmp;

	g_return_val_if_fail(parent != NULL, NULL);

	parent = iconfig_sbar_items_section(parent, TRUE);

	/* since items list in config file overrides defaults,
	   we'll need to copy the whole list. */
	for (tmp = config_node_first(source->value); tmp != NULL; tmp = config_node_next(tmp)) {
		int priority, right_alignment;
		CONFIG_NODE *node, *snode;

		snode = tmp->data;

		priority = config_node_get_int(snode, "priority", 0);
		right_alignment =
		    g_strcmp0(config_node_get_str(snode, "alignment", ""), "right") == 0;

		/* create new item */
		node = iconfig_node_section(parent, snode->key, NODE_TYPE_BLOCK);

		if (priority != 0)
			iconfig_node_set_int(node, "priority", priority);
		if (right_alignment)
			iconfig_node_set_str(node, "alignment", "right");
	}

	return parent;
}
Exemplo n.º 5
0
static void botuser_config_read_user(CONFIG_NODE *node)
{
	USER_REC *user;
	USER_CHAN_REC *userchan;
	USER_MASK_REC *usermask;
	CONFIG_NODE *subnode;
	GSList *tmp;
	char *value;

	g_return_if_fail(node != NULL);

	/* nick = { ... } */
	if (node->key == NULL || node->value == NULL)
		return;

	/* Add new user */
	user = g_new0(USER_REC, 1);
	user->nick = g_strdup(node->key);
	g_hash_table_insert(users, user->nick, user);

	/* password, flags, modify time */
	user->password = g_strdup(config_node_get_str(node, "password", NULL));
	user->flags = botuser_flags2value(config_node_get_str(node, "flags", ""));
	user->last_modify = (time_t) config_node_get_int(node, "last_modify", 0);

	/* get masks */
        user->masks = NULL;
	subnode = config_node_section(node, "masks", -1);
	tmp = subnode == NULL ? NULL : subnode->value;
	for (; tmp != NULL; tmp = tmp->next) {
		subnode = tmp->data;

		value = config_node_get_str(subnode, "mask", NULL);
		if (value == NULL) continue; /* mask is required */

		usermask = botuser_create_mask(user, value);
		value = config_node_get_str(subnode, "not_flags", "");
		usermask->not_flags = botuser_flags2value(value);
	}

	/* get channels - must be last, messes up pvalue */
	user->channels = g_hash_table_new((GHashFunc) g_istr_hash, (GCompareFunc) g_istr_equal);
	subnode = config_node_section(node, "channels", -1);
	tmp = subnode == NULL ? NULL : subnode->value;
	for (; tmp != NULL; tmp = tmp->next) {
		subnode = tmp->data;

		value = config_node_get_str(subnode, "channel", NULL);
		if (value == NULL) continue; /* channel is required */

		/* create user channel specific record */
		userchan = g_new0(USER_CHAN_REC, 1);
		userchan->channel = g_strdup(value);
		g_hash_table_insert(user->channels, userchan->channel, userchan);

		value = config_node_get_str(subnode, "flags", "");
		userchan->flags = botuser_flags2value(value);
	}
}
Exemplo n.º 6
0
static void statusbar_read_item(STATUSBAR_CONFIG_REC *bar, CONFIG_NODE *node)
{
	int priority, right_alignment;

	priority = config_node_get_int(node, "priority", 0);
	right_alignment = strcmp(config_node_get_str(node, "alignment", ""), "right") == 0;
	statusbar_item_config_create(bar, node->key,
				     priority, right_alignment);
}
Exemplo n.º 7
0
Arquivo: session.c Projeto: ahf/irssi
static void session_restore_server(CONFIG_NODE *node)
{
	CHAT_PROTOCOL_REC *proto;
	SERVER_CONNECT_REC *conn;
	SERVER_REC *server;
	const char *chat_type, *address, *chatnet, *password, *nick;
        int port, handle;

        chat_type = config_node_get_str(node, "chat_type", NULL);
	address = config_node_get_str(node, "address", NULL);
	port = config_node_get_int(node, "port", 0);
	chatnet = config_node_get_str(node, "chatnet", NULL);
	password = config_node_get_str(node, "password", NULL);
	nick = config_node_get_str(node, "nick", NULL);
	handle = config_node_get_int(node, "handle", -1);

	if (chat_type == NULL || address == NULL || nick == NULL || handle < 0)
		return;

	proto = chat_protocol_find(chat_type);
	if (proto == NULL || proto->not_initialized) {
		if (handle < 0) close(handle);
		return;
	}

	conn = server_create_conn(proto->id, address, port,
				  chatnet, password, nick);
	if (conn != NULL) {
		conn->reconnection = TRUE;
		conn->connect_handle = g_io_channel_new(handle);

		server = proto->server_init_connect(conn);
		server->version = g_strdup(config_node_get_str(node, "version", NULL));
		server->session_reconnect = TRUE;
		signal_emit("session restore server", 2, server, node);

		proto->server_connect(server);
	}
}
Exemplo n.º 8
0
static void botnet_config_read_botnet(CONFIG_NODE *node)
{
	CONFIG_NODE *subnode;
	BOTNET_REC *botnet;
	GSList *tmp;

	g_return_if_fail(node != NULL);

	if (node->key == NULL || node->value == NULL)
		return;

	/* New botnet */
	botnet = g_new0(BOTNET_REC, 1);
	botnet->name = g_strdup(node->key);
	botnet->nick = g_strdup(config_node_get_str(node, "nick", "bot"));
	botnet->priority = config_node_get_int(node, "priority", DEFAULT_BOTNET_PRIORITY);
	botnet->autoconnect = config_node_get_bool(node, "autoconnect", FALSE);

	botnet->addr = g_strdup(config_node_get_str(node, "listen_addr", NULL));
	botnet->port = config_node_get_int(node, "listen_port", DEFAULT_BOTNET_PORT);

	botnet->listen_handle = -1;
	botnet->listen_tag = -1;

	/* read uplinks */
	subnode = config_node_section(node, "uplinks", -1);
	tmp = subnode == NULL ? NULL : subnode->value;
	for (; tmp != NULL; tmp = tmp->next)
		botnet_config_read_uplink(botnet, tmp->data);

	/* read downlinks */
	subnode = config_node_section(node, "downlinks", -1);
	tmp = subnode == NULL ? NULL : subnode->value;
	for (; tmp != NULL; tmp = tmp->next)
		botnet_config_read_downlink(botnet, tmp->data);

	botnets = g_slist_append(botnets, botnet);
}
Exemplo n.º 9
0
int settings_get_int(const char *key)
{
	SETTINGS_REC *rec;
	CONFIG_NODE *node;

	rec = settings_get(key, SETTING_TYPE_INT);
	if (rec == NULL) return 0;

	node = iconfig_node_traverse("settings", FALSE);
	node = node == NULL ? NULL : iconfig_node_section(node, rec->module, -1);

	return node == NULL ? rec->default_value.v_int :
		config_node_get_int(node, key, rec->default_value.v_int);
}
Exemplo n.º 10
0
static void statusbar_read(STATUSBAR_GROUP_REC *group, CONFIG_NODE *node)
{
	STATUSBAR_CONFIG_REC *bar;
        GSList *tmp;
        const char *visible_str;

	g_return_if_fail(is_node_list(node));
	g_return_if_fail(node->key != NULL);

	bar = statusbar_config_find(group, node->key);
	if (config_node_get_bool(node, "disabled", FALSE)) {
		/* disabled, destroy it if it already exists */
		if (bar != NULL)
			statusbar_config_destroy(group, bar);
                return;
	}

	if (bar == NULL) {
		bar = statusbar_config_create(group, node->key);
		bar->type = STATUSBAR_TYPE_ROOT;
		bar->placement = STATUSBAR_BOTTOM;
		bar->position = 0;
	}

        visible_str = config_node_get_str(node, "visible", "");
	if (g_ascii_strcasecmp(visible_str, "active") == 0)
                bar->visible = STATUSBAR_VISIBLE_ACTIVE;
	else if (g_ascii_strcasecmp(visible_str, "inactive") == 0)
		bar->visible = STATUSBAR_VISIBLE_INACTIVE;
	else
		bar->visible = STATUSBAR_VISIBLE_ALWAYS;

	if (g_ascii_strcasecmp(config_node_get_str(node, "type", ""), "window") == 0)
                bar->type = STATUSBAR_TYPE_WINDOW;
	if (g_ascii_strcasecmp(config_node_get_str(node, "placement", ""), "top") == 0)
                bar->placement = STATUSBAR_TOP;
	bar->position = config_node_get_int(node, "position", 0);

	node = iconfig_node_section(node, "items", -1);
	if (node != NULL) {
                /* we're overriding the items - destroy the old */
                while (bar->items != NULL)
			statusbar_config_item_destroy(bar, bar->items->data);

		tmp = config_node_first(node->value);
		for (; tmp != NULL; tmp = config_node_next(tmp))
			statusbar_read_item(bar, tmp->data);
	}
}
Exemplo n.º 11
0
static int compare_server_setup (CONFIG_NODE *node, SERVER_SETUP_REC *server)
{
	char *address, *chatnet;
	int port;

	address = config_node_get_str(node, "address", NULL);
	chatnet = config_node_get_str(node, "chatnet", NULL);
	port = config_node_get_int(node, "port", 0);

	if (g_strcmp0(address, server->address) != 0 ||
	    g_strcmp0(chatnet, server->chatnet) != 0 ||
	    port != server->port)
		return 1;

	return 0;
}
Exemplo n.º 12
0
Arquivo: ignore.c Projeto: ahf/irssi
static void read_ignores(void)
{
	IGNORE_REC *rec;
	CONFIG_NODE *node;
	GSList *tmp;

	while (ignores != NULL)
                ignore_destroy(ignores->data, FALSE);

	node = iconfig_node_traverse("ignores", FALSE);
	if (node == NULL) {
		nickmatch_rebuild(nickmatch);
		return;
	}

	tmp = config_node_first(node->value);
	for (; tmp != NULL; tmp = config_node_next(tmp)) {
		node = tmp->data;

		if (node->type != NODE_TYPE_BLOCK)
			continue;

		rec = g_new0(IGNORE_REC, 1);
		ignores = g_slist_append(ignores, rec);

		rec->mask = g_strdup(config_node_get_str(node, "mask", NULL));
		rec->pattern = g_strdup(config_node_get_str(node, "pattern", NULL));
		rec->level = level2bits(config_node_get_str(node, "level", ""), NULL);
                rec->exception = config_node_get_bool(node, "exception", FALSE);
		rec->regexp = config_node_get_bool(node, "regexp", FALSE);
		rec->fullword = config_node_get_bool(node, "fullword", FALSE);
		rec->replies = config_node_get_bool(node, "replies", FALSE);
		rec->unignore_time = config_node_get_int(node, "unignore_time", 0);
		rec->servertag = g_strdup(config_node_get_str(node, "servertag", 0));

		node = iconfig_node_section(node, "channels", -1);
		if (node != NULL) rec->channels = config_node_get_list(node);

		ignore_init_rec(rec);
	}

	nickmatch_rebuild(nickmatch);
}
Exemplo n.º 13
0
static void botnet_config_read_uplink(BOTNET_REC *botnet, CONFIG_NODE *node)
{
	BOT_UPLINK_REC *rec;
	char *value;

	g_return_if_fail(botnet != NULL);
	g_return_if_fail(node != NULL);

	value = config_node_get_str(node, "host", NULL);
	if (value == NULL) return; /* host required */

	rec = g_new0(BOT_UPLINK_REC, 1);
	rec->botnet = botnet;
	rec->host = g_strdup(value);
	rec->port = config_node_get_int(node, "port", DEFAULT_BOTNET_PORT);
	rec->password = g_strdup(config_node_get_str(node, "password", NULL));

	botnet->uplinks = g_slist_append(botnet->uplinks, rec);
}
Exemplo n.º 14
0
Arquivo: session.c Projeto: ahf/irssi
static void session_restore_channel(SERVER_REC *server, CONFIG_NODE *node)
{
        CHANNEL_REC *channel;
	const char *name, *visible_name;

	name = config_node_get_str(node, "name", NULL);
	if (name == NULL)
		return;

	visible_name = config_node_get_str(node, "visible_name", NULL);
	channel = CHAT_PROTOCOL(server)->channel_create(server, name, visible_name, TRUE);
	channel->topic = g_strdup(config_node_get_str(node, "topic", NULL));
	channel->topic_by = g_strdup(config_node_get_str(node, "topic_by", NULL));
	channel->topic_time = config_node_get_int(node, "topic_time", 0);
        channel->key = g_strdup(config_node_get_str(node, "key", NULL));
        channel->session_rejoin = TRUE;

	signal_emit("session restore channel", 2, channel, node);
}
Exemplo n.º 15
0
static void ircnet_read(CONFIG_NODE *node)
{
	IRC_CHATNET_REC *rec;

	if (node == NULL || node->key == NULL)
		return;

	rec = g_new0(IRC_CHATNET_REC, 1);
	rec->chat_type = IRC_PROTOCOL;

	rec->max_cmds_at_once = config_node_get_int(node, "cmdmax", 0);
	rec->cmd_queue_speed = config_node_get_int(node, "cmdspeed", 0);

	rec->max_kicks = config_node_get_int(node, "max_kicks", 0);
	rec->max_msgs = config_node_get_int(node, "max_msgs", 0);
	rec->max_modes = config_node_get_int(node, "max_modes", 0);
	rec->max_whois = config_node_get_int(node, "max_whois", 0);

	chatnet_read((CHATNET_REC *) rec, node);
}
Exemplo n.º 16
0
static SERVER_SETUP_REC *server_setup_read(CONFIG_NODE *node)
{
	SERVER_SETUP_REC *rec;
        CHATNET_REC *chatnetrec;
	char *server, *chatnet, *family;
	int port;

	g_return_val_if_fail(node != NULL, NULL);

	server = config_node_get_str(node, "address", NULL);
	if (server == NULL)
		return NULL;

	port = config_node_get_int(node, "port", 0);
	chatnet = config_node_get_str(node, "chatnet", NULL);

	if (server_setup_find(server, port, chatnet) != NULL) {
		return NULL;
	}

	rec = NULL;

	chatnetrec = chatnet == NULL ? NULL : chatnet_find(chatnet);
	if (chatnetrec == NULL && chatnet != NULL) {
                /* chat network not found, create it. */
		chatnetrec = chat_protocol_get_default()->create_chatnet();
		chatnetrec->chat_type = chat_protocol_get_default()->id;
		chatnetrec->name = g_strdup(chatnet);
		chatnet_create(chatnetrec);
	}

        family = config_node_get_str(node, "family", "");

	rec = CHAT_PROTOCOL(chatnetrec)->create_server_setup();
	rec->type = module_get_uniq_id("SERVER SETUP", 0);
        rec->chat_type = CHAT_PROTOCOL(chatnetrec)->id;
	rec->chatnet = chatnetrec == NULL ? NULL : g_strdup(chatnetrec->name);
	rec->family = g_ascii_strcasecmp(family, "inet6") == 0 ? AF_INET6 :
		(g_ascii_strcasecmp(family, "inet") == 0 ? AF_INET : 0);
	rec->address = g_strdup(server);
	rec->password = g_strdup(config_node_get_str(node, "password", NULL));
	rec->use_ssl = config_node_get_bool(node, "use_ssl", FALSE);
	rec->ssl_cert = g_strdup(config_node_get_str(node, "ssl_cert", NULL));
	rec->ssl_pkey = g_strdup(config_node_get_str(node, "ssl_pkey", NULL));
	rec->ssl_verify = config_node_get_bool(node, "ssl_verify", FALSE);
	rec->ssl_cafile = g_strdup(config_node_get_str(node, "ssl_cafile", NULL));
	rec->ssl_capath = g_strdup(config_node_get_str(node, "ssl_capath", NULL));
	if (rec->ssl_cafile || rec->ssl_capath)
		rec->ssl_verify = TRUE;
	if (rec->ssl_cert != NULL || rec->ssl_verify)
		rec->use_ssl = TRUE;
	rec->port = port;
	rec->autoconnect = config_node_get_bool(node, "autoconnect", FALSE);
	rec->no_proxy = config_node_get_bool(node, "no_proxy", FALSE);
	rec->own_host = g_strdup(config_node_get_str(node, "own_host", NULL));

	signal_emit("server setup read", 2, rec, node);

	setupservers = g_slist_append(setupservers, rec);
	return rec;
}