Ejemplo n.º 1
0
static void msg_join(IRC_SERVER_REC *server, const char *channel,
		     const char *nick, const char *address)
{
	NETSPLIT_REC *split;
	NETJOIN_REC *netjoin;
	GSList *channels;
	int rejoin = 1;

	if (!IS_IRC_SERVER(server))
		return;

	if (ignore_check(SERVER(server), nick, address,
			 channel, NULL, MSGLEVEL_JOINS))
		return;

	split = netsplit_find(server, nick, address);
	netjoin = netjoin_find(server, nick);
	if (split == NULL && netjoin == NULL)
                return;

	/* if this was not a channel they split from, treat it normally */
	if (netjoin != NULL) {
		if (!gslist_find_icase_string(netjoin->old_channels, channel))
			return;
	} else {
		channels = split->channels;
		while (channels != NULL) {
			NETSPLIT_CHAN_REC *schannel = channels->data;

			if (!strcasecmp(schannel->name, channel))
				break;
			channels = channels->next;
		}
		/* we still need to create a NETJOIN_REC now as the
		 * NETSPLIT_REC will be destroyed */
		if (channels == NULL)
			rejoin = 0;
	}

	if (join_tag == -1) {
		join_tag = g_timeout_add(1000, (GSourceFunc)
					 sig_check_netjoins, NULL);
		signal_add("print starting", (SIGNAL_FUNC) sig_print_starting);
	}

	if (netjoin == NULL)
		netjoin = netjoin_add(server, nick, split->channels);

	if (rejoin)
	{
		netjoin->now_channels = g_slist_append(netjoin->now_channels,
						       g_strconcat(" ", channel, NULL));
		signal_stop();
	}
}
Ejemplo n.º 2
0
/* verify that all settings in config file for `module' are actually found
   from /SET list */
void settings_check_module(const char *module)
{
        SETTINGS_REC *set;
	CONFIG_NODE *node, *parent;
        GString *errors;
	GSList *tmp, *next;
        int count;

        g_return_if_fail(module != NULL);

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

        errors = g_string_new(NULL);
	g_string_printf(errors, "Unknown settings in configuration "
			 "file for module %s:", module);

        count = 0;
	parent = node;
	tmp = config_node_first(node->value);
	for (; tmp != NULL; tmp = next) {
		node = tmp->data;
		next = config_node_next(tmp);
		if (node->key == NULL) continue;

		set = g_hash_table_lookup(settings, node->key);
		if (backwards_compatibility(module, node, parent))
			continue;

		if (set == NULL || g_strcmp0(set->module, module) != 0) {
			g_string_append_printf(errors, " %s", node->key);
                        count++;
		}
	}
	if (count > 0) {
		if (gslist_find_icase_string(last_invalid_modules,
					     module) == NULL) {
                        /* mark this module having invalid settings */
			last_invalid_modules =
				g_slist_append(last_invalid_modules,
					       g_strdup(module));
		}
		if (fe_initialized)
                        signal_emit("settings errors", 1, errors->str);
		else {
			if (last_errors == NULL)
				last_errors = g_string_new(NULL);
			else
				g_string_append_c(last_errors, '\n');
                        g_string_append(last_errors, errors->str);
		}
	}
        g_string_free(errors, TRUE);
}
Ejemplo n.º 3
0
static void add_private_msg(IRC_SERVER_REC *server, const char *nick)
{
	GSList *link;

	link = gslist_find_icase_string(server->lastmsgs, nick);
	if (link != NULL) {
		g_free(link->data);
		server->lastmsgs = g_slist_remove(server->lastmsgs, link->data);
	}
	server->lastmsgs = g_slist_prepend(server->lastmsgs, g_strdup(nick));
}
Ejemplo n.º 4
0
static int py_settings_add(PyScript *self, const char *name)
{
    GSList *node;

    node = gslist_find_icase_string(self->settings, name);
    if (node)
        return 0;

    self->settings = g_slist_append(self->settings, g_strdup(name));
    
    return 1;
}
Ejemplo n.º 5
0
static int netjoin_set_nickmode(NETJOIN_REC *rec, const char *channel,
				char mode)
{
	GSList *pos;

	pos = gslist_find_icase_string(rec->now_channels, channel);
	if (pos == NULL)
		return FALSE;

	g_free(pos->data);
	pos->data = g_strdup_printf("%c%s", mode, channel);
	return TRUE;
}
Ejemplo n.º 6
0
static int netjoin_set_operator(NETJOIN_REC *rec, const char *channel, int on)
{
	GSList *pos;

	pos = gslist_find_icase_string(rec->now_channels, channel);
	if (pos == NULL)
		return FALSE;

	g_free(pos->data);
	pos->data = !on ? g_strdup(channel) :
		g_strconcat("@", channel, NULL);
	return TRUE;
}
Ejemplo n.º 7
0
static int py_settings_remove(PyScript *self, const char *name)
{
    GSList *node;

    node = gslist_find_icase_string(self->settings, name);
    if (!node)
        return 0;
  
    settings_remove(node->data);
    g_free(node->data);

    self->settings = g_slist_delete_link(self->settings, node);

    return 1;
}
Ejemplo n.º 8
0
/* add the nick of a hostmask to list if it isn't there already */
static GSList *mask_add_once(GSList *list, const char *mask)
{
	char *str, *ptr;

	g_return_val_if_fail(mask != NULL, NULL);

	ptr = strchr(mask, '!');
	str = ptr == NULL ? g_strdup(mask) :
		g_strndup(mask, (int) (ptr-mask)+1);

	if (gslist_find_icase_string(list, str) == NULL)
		return g_slist_append(list, str);

	g_free(str);
	return list;
}
Ejemplo n.º 9
0
static void ison_check_parts(IRC_SERVER_REC *server)
{
	MODULE_SERVER_REC *mserver;
	GSList *tmp, *next;

	mserver = MODULE_DATA(server);
	for (tmp = mserver->notify_users; tmp != NULL; tmp = next) {
		NOTIFY_NICK_REC *rec = tmp->data;
		next = tmp->next;

		if (gslist_find_icase_string(mserver->ison_tempusers, rec->nick) != NULL)
			continue;

                notifylist_left(server, rec);
	}
}
Ejemplo n.º 10
0
void fe_common_irc_finish_init(void)
{
	GSList *tmp, *ircnets;
	char *str;

	if (cmdline_nick != NULL) {
		/* override nick found from setup */
		iconfig_set_str("settings", "nick", cmdline_nick);
	}

	if (cmdline_hostname != NULL) {
		/* override host name found from setup */
		iconfig_set_str("settings", "hostname", cmdline_hostname);
	}

	if (autocon_server != NULL) {
		/* connect to specified server */
		str = g_strdup_printf(autocon_password == NULL ? "%s %d" : "%s %d %s",
				      autocon_server, autocon_port, autocon_password);
		signal_emit("command connect", 1, str);
		g_free(str);
		return;
	}

	if (no_autoconnect) {
		/* don't autoconnect */
		return;
	}

	/* connect to autoconnect servers */
	ircnets = NULL;
	for (tmp = setupservers; tmp != NULL; tmp = tmp->next) {
		SERVER_SETUP_REC *rec = tmp->data;

		if (rec->autoconnect && (rec->chatnet == NULL || *rec->chatnet == '\0' ||
					 gslist_find_icase_string(ircnets, rec->chatnet) == NULL)) {
			if (rec->chatnet != NULL && *rec->chatnet != '\0')
				ircnets = g_slist_append(ircnets, rec->chatnet);

			str = g_strdup_printf("%s %d", rec->address, rec->port);
			signal_emit("command connect", 1, str);
			g_free(str);
		}
	}

	g_slist_free(ircnets);
}
Ejemplo n.º 11
0
static void autoconnect_servers(void)
{
	GSList *tmp, *chatnets;
	char *str;

	if (autocon_server != NULL) {
		/* connect to specified server */
		if (autocon_password == NULL)
			str = g_strdup_printf("%s %d", autocon_server, autocon_port);
		else
			str = g_strdup_printf("%s %d %s", autocon_server, autocon_port, autocon_password);

		signal_emit("command connect", 1, str);
		g_free(str);
		return;
	}

	if (no_autoconnect) {
		/* don't autoconnect */
		return;
	}

	/* connect to autoconnect servers */
	chatnets = NULL;
	for (tmp = setupservers; tmp != NULL; tmp = tmp->next) {
		SERVER_SETUP_REC *rec = tmp->data;

		if (rec->autoconnect &&
		    (rec->chatnet == NULL ||
		     gslist_find_icase_string(chatnets, rec->chatnet) == NULL)) {
			if (rec->chatnet != NULL) {
				chatnets = g_slist_append(chatnets, rec->chatnet);
				str = g_strdup_printf("-network %s %s %d", rec->chatnet, rec->address, rec->port);
			} else {
				str = g_strdup_printf("%s %d", rec->address, rec->port);
			}

			signal_emit("command connect", 1, str);
			g_free(str);
		}
	}

	g_slist_free(chatnets);
}
Ejemplo n.º 12
0
static void print_netjoins(NETJOIN_SERVER_REC *server)
{
	TEMP_PRINT_REC *temp;
	GHashTable *channels;
	GSList *tmp, *next, *old;

	g_return_if_fail(server != NULL);

	printing_joins = TRUE;

	/* save nicks to string, clear now_channels and remove the same
	   channels from old_channels list */
	channels = g_hash_table_new((GHashFunc) g_istr_hash,
				    (GCompareFunc) g_istr_equal);
	for (tmp = server->netjoins; tmp != NULL; tmp = next) {
		NETJOIN_REC *rec = tmp->data;

		next = tmp->next;
		while (rec->now_channels != NULL) {
			char *channel = rec->now_channels->data;
			char *realchannel = channel + isnickflag(*channel);

			temp = g_hash_table_lookup(channels, realchannel);
			if (temp == NULL) {
				temp = g_new0(TEMP_PRINT_REC, 1);
				temp->nicks = g_string_new(NULL);
				g_hash_table_insert(channels,
						    g_strdup(realchannel),
						    temp);
			}

			temp->count++;
			if (temp->count <= netjoin_max_nicks) {
				if (isnickflag(*channel))
					g_string_append_c(temp->nicks,
							  *channel);
				g_string_sprintfa(temp->nicks, "%s, ",
						  rec->nick);
			}

			/* remove the channel from old_channels too */
			old = gslist_find_icase_string(rec->old_channels,
						       realchannel);
			if (old != NULL) {
				g_free(old->data);
				rec->old_channels =
					g_slist_remove(rec->old_channels,
						       old->data);
			}

			g_free(channel);
			rec->now_channels =
				g_slist_remove(rec->now_channels, channel);
		}

		if (rec->old_channels == NULL)
                        netjoin_remove(server, rec);
	}

	g_hash_table_foreach(channels, (GHFunc) print_channel_netjoins,
			     server);
	g_hash_table_destroy(channels);

	if (server->netjoins == NULL)
		netjoin_server_remove(server);

	printing_joins = FALSE;
}
Ejemplo n.º 13
0
static void print_netjoins(NETJOIN_SERVER_REC *server, const char *filter_channel)
{
	TEMP_PRINT_REC *temp;
	GHashTable *channels;
	GSList *tmp, *tmp2, *next, *next2, *old;

	g_return_if_fail(server != NULL);

	printing_joins = TRUE;

	/* save nicks to string, clear now_channels and remove the same
	   channels from old_channels list */
	channels = g_hash_table_new((GHashFunc) g_istr_hash,
				    (GCompareFunc) g_istr_equal);
	for (tmp = server->netjoins; tmp != NULL; tmp = next) {
		NETJOIN_REC *rec = tmp->data;

		next = g_slist_next(tmp);

		for (tmp2 = rec->now_channels; tmp2 != NULL; tmp2 = next2) {
			char *channel = tmp2->data;
			char *realchannel = channel + 1;

			next2 = g_slist_next(tmp2);

			/* Filter the results by channel if asked to do so */
			if (filter_channel != NULL &&
			    strcasecmp(realchannel, filter_channel) != 0)
				continue;

			temp = g_hash_table_lookup(channels, realchannel);
			if (temp == NULL) {
				temp = g_new0(TEMP_PRINT_REC, 1);
				temp->nicks = g_string_new(NULL);
				g_hash_table_insert(channels,
						    g_strdup(realchannel),
						    temp);
			}

			temp->count++;
			if (temp->count <= netjoin_max_nicks) {
				if (*channel != ' ')
					g_string_append_c(temp->nicks,
							  *channel);
				g_string_append_printf(temp->nicks, "%s, ",
						  rec->nick);
			}

			/* remove the channel from old_channels too */
			old = gslist_find_icase_string(rec->old_channels,
						       realchannel);
			if (old != NULL) {
				void *data = old->data;
				rec->old_channels =
					g_slist_remove(rec->old_channels, data);
				g_free(data);
			}

			/* drop tmp2 from the list */
			rec->now_channels = g_slist_delete_link(rec->now_channels, tmp2);
			g_free(channel);
		}

		if (rec->old_channels == NULL)
                        netjoin_remove(server, rec);
	}

	g_hash_table_foreach(channels, (GHFunc) print_channel_netjoins,
			     server);
	g_hash_table_destroy(channels);

	if (server->netjoins == NULL)
		netjoin_server_remove(server);

	printing_joins = FALSE;
}