[Pkg-privacy-commits] [irssi-plugin-otr] 130/267: Add /me support passing through OTR

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 12:26:25 UTC 2015


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch debian
in repository irssi-plugin-otr.

commit 9167e819cf88a841c97782dbe03102f5c50bf41e
Author: David Goulet <dgoulet at ev0ke.net>
Date:   Tue Nov 13 16:40:54 2012 -0500

    Add /me support passing through OTR
    
    Signed-off-by: David Goulet <dgoulet at ev0ke.net>
---
 src/irssi_otr.h |  2 ++
 src/module.c    | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+)

diff --git a/src/irssi_otr.h b/src/irssi_otr.h
index c02bc23..8607d8f 100644
--- a/src/irssi_otr.h
+++ b/src/irssi_otr.h
@@ -34,7 +34,9 @@
 #include <src/core/modules.h>
 #include <src/core/settings.h>
 #include <src/irc/core/irc.h>
+#include <src/irc/core/irc-commands.h>
 #include <src/irc/core/irc-queries.h>
+#include <src/irc/core/irc-servers.h>
 #include <src/fe-text/statusbar-item.h>
 
 #define get_client_config_dir get_irssi_dir
diff --git a/src/module.c b/src/module.c
index 161e719..7b77719 100644
--- a/src/module.c
+++ b/src/module.c
@@ -19,10 +19,12 @@
  * Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA
  */
 
+#define _GNU_SOURCE
 #include <assert.h>
 #include <glib.h>
 #include <glib/gprintf.h>
 #include <glib/gstdio.h>
+#include <stdio.h>
 
 #include "cmd.h"
 #include "otr.h"
@@ -130,6 +132,61 @@ static void sig_query_destroyed(QUERY_REC *query)
 }
 
 /*
+ * Handle /me IRC command.
+ */
+static void cmd_me(const char *data, IRC_SERVER_REC *server,
+		WI_ITEM_REC *item)
+{
+	int ret;
+	const char *target;
+	char *msg, *otrmsg = NULL;
+	QUERY_REC *query;
+
+	query = QUERY(item);
+
+	if (!query || !query->server) {
+		goto end;
+	}
+
+	CMD_IRC_SERVER(server);
+	if (!IS_IRC_QUERY(query)) {
+		goto end;
+	}
+
+	if (!server || !server->connected) {
+		cmd_return_error(CMDERR_NOT_CONNECTED);
+	}
+
+	target = window_item_get_target(item);
+
+	ret = asprintf(&msg, "/me %s", data);
+	if (ret < 0) {
+		goto end;
+	}
+
+	/* Critical section. On error, message MUST NOT be sent */
+	ret = otr_send(query->server, msg, target, &otrmsg);
+	free(msg);
+
+	if (!otrmsg) {
+		goto end;
+	}
+
+	signal_stop();
+
+	if (otrmsg) {
+		/* Send encrypted message */
+		irssi_send_message(SERVER(server), target, otrmsg);
+		otrl_message_free(otrmsg);
+	}
+
+	signal_emit("message irc own_action", 3, server, data, item->visible_name);
+
+end:
+	return;
+}
+
+/*
  * Handle the "/otr" command.
  */
 static void cmd_otr(const char *data, void *server, WI_ITEM_REC *item)
@@ -249,6 +306,7 @@ void otr_init(void)
 
 	command_bind("otr", NULL, (SIGNAL_FUNC) cmd_otr);
 	command_bind_first("quit", NULL, (SIGNAL_FUNC) cmd_quit);
+	command_bind_irc_first("me", NULL, (SIGNAL_FUNC) cmd_me);
 
 	settings_add_str("otr", "otr_policy", OTR_DEFAULT_POLICY);
 	settings_add_str("otr", "otr_policy_known", OTR_DEFAULT_POLICY_KNOWN);
@@ -281,6 +339,7 @@ void otr_deinit(void)
 
 	command_unbind("otr", (SIGNAL_FUNC) cmd_otr);
 	command_unbind("quit", (SIGNAL_FUNC) cmd_quit);
+	command_unbind("me", (SIGNAL_FUNC) cmd_me);
 
 	signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/irssi-plugin-otr.git



More information about the Pkg-privacy-commits mailing list