Ejemplo n.º 1
0
Archivo: sasl.c Proyecto: mmuman/irssi
static void sasl_step_fail(IRC_SERVER_REC *server)
{
	irc_send_cmd_now(server, "AUTHENTICATE *");
	cap_finish_negotiation(server);

	server->sasl_timeout = 0;

	signal_emit("server sasl failure", 2, server, "The server sent an invalid payload");
}
Ejemplo n.º 2
0
Archivo: sasl.c Proyecto: Liaf/irssi
static void sasl_success(IRC_SERVER_REC *server, const char *data, const char *from)
{
	if (server->sasl_timeout != 0) {
		g_source_remove(server->sasl_timeout);
		server->sasl_timeout = 0;
	}

	signal_emit("server sasl success", 1, server);

	/* The authentication succeeded, time to finish the CAP negotiation */
	cap_finish_negotiation(server);
}
Ejemplo n.º 3
0
Archivo: sasl.c Proyecto: Liaf/irssi
static void sasl_already(IRC_SERVER_REC *server, const char *data, const char *from)
{
	if (server->sasl_timeout != 0) {
		g_source_remove(server->sasl_timeout);
		server->sasl_timeout = 0;
	}

	signal_emit("server sasl success", 1, server);

	/* We're already authenticated, do nothing */
	cap_finish_negotiation(server);
}
Ejemplo n.º 4
0
Archivo: sasl.c Proyecto: Liaf/irssi
static gboolean sasl_timeout(IRC_SERVER_REC *server)
{
	/* The authentication timed out, we can't do much beside terminating it */
	irc_send_cmd_now(server, "AUTHENTICATE *");
	cap_finish_negotiation(server);

	server->sasl_timeout = 0;

	signal_emit("server sasl failure", 2, server, "The authentication timed out");

	return FALSE;
}
Ejemplo n.º 5
0
Archivo: sasl.c Proyecto: Liaf/irssi
static void sasl_fail(IRC_SERVER_REC *server, const char *data, const char *from)
{
	char *params, *error;

	/* Stop any pending timeout, if any */
	if (server->sasl_timeout != 0) {
		g_source_remove(server->sasl_timeout);
		server->sasl_timeout = 0;
	}

	params = event_get_params(data, 2, NULL, &error);

	signal_emit("server sasl fail", 2, server, error);

	/* Terminate the negotiation */
	cap_finish_negotiation(server);

	g_free(params);
}
Ejemplo n.º 6
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);
}