예제 #1
0
static void
text_sent_cb(GtkEntry *entry)
{
	const char *txt;
	PurpleConnection *gc;
	const char *protocol_id;

	if (account == NULL)
		return;

	gc = purple_account_get_connection(account);

	txt = gtk_entry_get_text(entry);

	protocol_id = purple_account_get_protocol_id(account);

	purple_debug_misc("raw", "protocol_id = %s\n", protocol_id);

	if (strcmp(protocol_id, "prpl-toc") == 0) {
		int *a = (int *)purple_connection_get_protocol_data(gc);
		unsigned short seqno = htons(a[1]++ & 0xffff);
		unsigned short len = htons(strlen(txt) + 1);
		write(*a, "*\002", 2);
		write(*a, &seqno, 2);
		write(*a, &len, 2);
		write(*a, txt, ntohs(len));
		purple_debug(PURPLE_DEBUG_MISC, "raw", "TOC C: %s\n", txt);

	} else if (strcmp(protocol_id, "prpl-msn") == 0) {
		MsnSession *session = purple_connection_get_protocol_data(gc);
		char buf[strlen(txt) + 3];

		g_snprintf(buf, sizeof(buf), "%s\r\n", txt);
		msn_servconn_write(session->notification->servconn, buf, strlen(buf));

	} else if (strcmp(protocol_id, "prpl-irc") == 0) {
		write(*(int *)purple_connection_get_protocol_data(gc), txt, strlen(txt));
		write(*(int *)purple_connection_get_protocol_data(gc), "\r\n", 2);
		purple_debug(PURPLE_DEBUG_MISC, "raw", "IRC C: %s\n", txt);

	} else if (strcmp(protocol_id, "prpl-jabber") == 0) {
		jabber_send_raw((JabberStream *)purple_connection_get_protocol_data(gc), txt, -1);

	} else {
		purple_debug_error("raw", "Unknown protocol ID %s\n", protocol_id);
	}

	gtk_entry_set_text(entry, "");
}
예제 #2
0
void
msn_cmdproc_send_trans(MsnCmdProc *cmdproc, MsnTransaction *trans)
{
	MsnServConn *servconn;
	char *data;
	size_t len;

	g_return_if_fail(cmdproc != NULL);
	g_return_if_fail(trans != NULL);

	servconn = cmdproc->servconn;

	if (!servconn->connected) {
		/* TODO: Need to free trans */
		return;
	}

	msn_history_add(cmdproc->history, trans);

	data = msn_transaction_to_string(trans);

	len = strlen(data);

	show_debug_cmd(cmdproc, FALSE, data);

	if (trans->callbacks == NULL)
		trans->callbacks = g_hash_table_lookup(cmdproc->cbs_table->cmds,
											   trans->command);

	if (trans->payload != NULL)
	{
		data = g_realloc(data, len + trans->payload_len);
		memcpy(data + len, trans->payload, trans->payload_len);
		len += trans->payload_len;

		/*
		 * We're done with trans->payload.  Free it so that the memory
		 * doesn't sit around in cmdproc->history.
		 */
		g_free(trans->payload);
		trans->payload = NULL;
		trans->payload_len = 0;
	}

	msn_servconn_write(servconn, data, len);

	g_free(data);
}
예제 #3
0
void
msn_cmdproc_send_quick(MsnCmdProc *cmdproc, const char *command,
					   const char *format, ...)
{
	MsnServConn *servconn;
	char *data;
	char *params = NULL;
	va_list arg;
	size_t len;

	g_return_if_fail(cmdproc != NULL);
	g_return_if_fail(command != NULL);

	servconn = cmdproc->servconn;

	if (!servconn->connected)
		return;

	if (format != NULL)
	{
		va_start(arg, format);
		params = g_strdup_vprintf(format, arg);
		va_end(arg);
	}

	if (params != NULL)
		data = g_strdup_printf("%s %s\r\n", command, params);
	else
		data = g_strdup_printf("%s\r\n", command);

	g_free(params);

	len = strlen(data);

	show_debug_cmd(cmdproc, FALSE, data);

	msn_servconn_write(servconn, data, len);

	g_free(data);
}
예제 #4
0
void
msn_cmdproc_send_trans(MsnCmdProc *cmdproc, MsnTransaction *trans)
{
	MsnServConn *servconn;
	char *data;
	size_t len;

	g_return_if_fail(cmdproc != NULL);
	g_return_if_fail(trans != NULL);

	servconn = cmdproc->servconn;

	if (!servconn->connected)
		return;

	msn_history_add(cmdproc->history, trans);

	data = msn_transaction_to_string(trans);

	len = strlen(data);

	show_debug_cmd(cmdproc, FALSE, data);

	if (trans->callbacks == NULL)
		trans->callbacks = g_hash_table_lookup(cmdproc->cbs_table->cmds,
											   trans->command);

	if (trans->payload != NULL)
	{
		data = g_realloc(data, len + trans->payload_len);
		memcpy(data + len, trans->payload, trans->payload_len);
		len += trans->payload_len;
	}

	msn_servconn_write(servconn, data, len);

	g_free(data);
}