Пример #1
0
int cap_toggle (IRC_SERVER_REC *server, char *cap, int enable)
{
	if (cap == NULL || *cap == '\0')
		return FALSE;

	/* If the negotiation hasn't been completed yet just queue the requests */
	if (!server->cap_complete) {
		if (enable && !gslist_find_string(server->cap_queue, cap)) {
			server->cap_queue = g_slist_prepend(server->cap_queue, g_strdup(cap));
			return TRUE;
		}
		else if (!enable && gslist_find_string(server->cap_queue, cap)) {
			server->cap_queue = gslist_remove_string(server->cap_queue, cap);
			return TRUE;
		}

		return FALSE;
	}

	if (enable && !gslist_find_string(server->cap_active, cap)) {
		/* Make sure the required cap is supported by the server */
		if (!gslist_find_string(server->cap_supported, cap))
			return FALSE;

		irc_send_cmdv(server, "CAP REQ %s", cap);
		return TRUE;
	}
	else if (!enable && gslist_find_string(server->cap_active, cap)) {
		irc_send_cmdv(server, "CAP REQ -%s", cap);
		return TRUE;
	}

	return FALSE;
}
Пример #2
0
static int perl_script_destroy(const char *name)
{
	GSList *tmp, *next, *item;
	char *package;
	int package_len;

	item = gslist_find_string(perl_scripts, name);
	if (item == NULL)
		return FALSE;

	package = g_strdup_printf("Irssi::Script::%s", name);
	package_len = strlen(package);

        signal_emit("script destroy", 3, "PERL", name, package);

        perl_signals_package_destroy(package);

	/* timeouts and input waits */
	for (tmp = perl_sources; tmp != NULL; tmp = next) {
		PERL_SOURCE_REC *rec = tmp->data;

		next = tmp->next;
		if (strncmp(rec->func, package, package_len) == 0)
			perl_source_destroy(rec);
	}

	g_free(package);
	g_free(item->data);
	perl_scripts = g_slist_remove(perl_scripts, item->data);
	return TRUE;
}
Пример #3
0
int dcc_str2type(const char *str)
{
	if (gslist_find_string(dcc_types, str) == NULL)
		return -1;

        return module_get_uniq_id_str("DCC", str);
}
Пример #4
0
void dcc_unregister_type(const char *type)
{
	GSList *pos;

	pos = gslist_find_string(dcc_types, type);
	if (pos != NULL) {
		g_free(pos->data);
                dcc_types = g_slist_remove(dcc_types, pos->data);
	}
}
Пример #5
0
static void log_read_config(void)
{
	CONFIG_NODE *node;
	LOG_REC *log;
	GSList *tmp, *next, *fnames;

	/* close old logs, save list of open logs */
	fnames = NULL;
	for (tmp = logs; tmp != NULL; tmp = next) {
		log = tmp->data;

		next = tmp->next;
		if (log->temp)
			continue;

		if (log->handle != -1)
			fnames = g_slist_append(fnames, g_strdup(log->fname));
		log_destroy(log);
	}

	node = iconfig_node_traverse("logs", FALSE);
	if (node == NULL) 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;

		log = g_new0(LOG_REC, 1);
		logs = g_slist_append(logs, log);

		log->handle = -1;
		log->fname = g_strdup(node->key);
		log->autoopen = config_node_get_bool(node, "auto_open", FALSE);
		log->level = level2bits(config_node_get_str(node, "level", 0));

		signal_emit("log config read", 2, log, node);

		node = config_node_section(node, "items", -1);
		if (node != NULL)
			log_items_read_config(node, log);

		if (log->autoopen || gslist_find_string(fnames, log->fname))
			log_start_logging(log);
	}

	g_slist_foreach(fnames, (GFunc) g_free, NULL);
	g_slist_free(fnames);
}
Пример #6
0
/* Find specified event from signals list. If it's found, remove it from the
   list and return it's target signal. */
static char *signal_list_move(GSList **signals, const char *event)
{
	GSList *link;
        char *linkevent, *linksignal;

	link = gslist_find_string(*signals, event);
	if (link == NULL)
		return NULL;

	linkevent = link->data;
        linksignal = link->next->data;

	*signals = g_slist_remove(*signals, linkevent);
	*signals = g_slist_remove(*signals, linksignal);

	g_free(linkevent);
        return linksignal;
}
Пример #7
0
static void event_cap (IRC_SERVER_REC *server, char *args, char *nick, char *address)
{
	GSList *tmp;
	GString *cmd;
	char *params, *evt, *list, **caps;
	int i, caps_length, disable, avail_caps;

	params = event_get_params(args, 3, NULL, &evt, &list);
	if (params == NULL)
		return;

	/* Strip the trailing whitespaces before splitting the string, some servers send responses with
	 * superfluous whitespaces that g_strsplit the interprets as tokens */
	caps = g_strsplit(g_strchomp(list), " ", -1);
	caps_length = g_strv_length(caps);

	if (!g_strcmp0(evt, "LS")) {
		/* Create a list of the supported caps */
		for (i = 0; i < caps_length; i++)
			server->cap_supported = g_slist_prepend(server->cap_supported, g_strdup(caps[i]));

		/* Request the required caps, if any */
		if (server->cap_queue == NULL) {
			cap_finish_negotiation(server);
		}
		else {
			cmd = g_string_new("CAP REQ :");

			avail_caps = 0;

			/* Check whether the cap is supported by the server */
			for (tmp = server->cap_queue; tmp != NULL; tmp = tmp->next) {
				if (gslist_find_string(server->cap_supported, tmp->data)) {
					g_string_append_c(cmd, ' ');
					g_string_append(cmd, tmp->data);

					avail_caps++;
				}
			}

			/* Clear the queue here */
			gslist_free_full(server->cap_queue, (GDestroyNotify) g_free);
			server->cap_queue = NULL;

			/* If the server doesn't support any cap we requested close the negotiation here */
			if (avail_caps > 0)
				irc_send_cmd_now(server, cmd->str);
			else
				cap_finish_negotiation(server);

			g_string_free(cmd, TRUE);
		}
	}
	else if (!g_strcmp0(evt, "ACK")) {
		int got_sasl = FALSE;

		/* Emit a signal for every ack'd cap */
		for (i = 0; i < caps_length; i++) {
			disable = (*caps[i] == '-');

			if (disable)
				server->cap_active = gslist_remove_string(server->cap_active, caps[i] + 1);
			else
				server->cap_active = g_slist_prepend(server->cap_active, g_strdup(caps[i]));

			if (!g_strcmp0(caps[i], "sasl"))
				got_sasl = TRUE;

			cap_emit_signal(server, "ack", caps[i]);
		}

		/* Hopefully the server has ack'd all the caps requested and we're ready to terminate the
		 * negotiation, unless sasl was requested. In this case we must not terminate the negotiation
		 * until the sasl handshake is over. */
		if (got_sasl == FALSE)
			cap_finish_negotiation(server);
	}
	else if (!g_strcmp0(evt, "NAK")) {
		g_warning("The server answered with a NAK to our CAP request, this should not happen");

		/* A NAK'd request means that a required cap can't be enabled or disabled, don't update the
		 * list of active caps and notify the listeners. */
		for (i = 0; i < caps_length; i++)
			cap_emit_signal(server, "nak", caps[i]);
	}

	g_strfreev(caps);
	g_free(params);
}