[pkg-otr-team] [irssi-plugin-otr] 92/167: Fixes from code review.

Holger Levsen holger at moszumanska.debian.org
Mon Mar 3 21:55:35 UTC 2014


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

holger pushed a commit to tag 4.0.0
in repository irssi-plugin-otr.

commit 9619e426b7888057ce8013984d16a8e85aabd6ec
Author: Rob Smits <rdfsmits at cs.uwaterloo.ca>
Date:   Sun Jun 3 22:37:08 2012 -0400

    Fixes from code review.
---
 README                           |   2 +-
 dialogs.h                        |   4 +-
 gtk-dialog.c                     | 114 +++++++------
 gtk-ui.c                         |   8 +-
 otr-plugin.c                     | 336 ++++++++++++++++-----------------------
 otr-plugin.h                     |   9 +-
 packaging/windows/pidgin-otr.nsi |   1 +
 7 files changed, 220 insertions(+), 254 deletions(-)

diff --git a/README b/README
index b083ce6..ed6c87d 100644
--- a/README
+++ b/README
@@ -302,7 +302,7 @@ The Off-the-Record Messaging plugin for pidgin is covered by the following
     Off-the-Record Messaging plugin for pidgin
     Copyright (C) 2004-2012  Ian Goldberg, Rob Smits,
                              Chris Alexander, Willy Lew,
-			     Lisa Du, Nikita Borisov
+                             Lisa Du, Nikita Borisov
                              <otr at cypherpunks.ca>
 
 
diff --git a/dialogs.h b/dialogs.h
index 58ceec6..03d3029 100644
--- a/dialogs.h
+++ b/dialogs.h
@@ -35,6 +35,8 @@
 #define SESSIONID_HELPURL     BASE_HELPURL "sessionid.php"
 #define UNVERIFIED_HELPURL    BASE_HELPURL "unverified.php"
 #define LEVELS_HELPURL        BASE_HELPURL "levels.php"
+#define SESSIONS_HELPURL        BASE_HELPURL "sessions.php"
+
 
 typedef struct s_OtrgDialogWait *OtrgDialogWaitHandle;
 
@@ -119,7 +121,7 @@ void otrg_dialog_notify_info(const char *accountname, const char *protocol,
 /* Display an OTR control message for the given accountname / protocol /
  * username conversation.  Return 0 on success, non-0 on error (in which
  * case the message will be displayed inline as a received message). */
-int otrg_dialog_display_otr_message( const char *accountname,
+int otrg_dialog_display_otr_message(const char *accountname,
 	const char *protocol, const char *username, const char *msg,
 	int force_create);
 
diff --git a/gtk-dialog.c b/gtk-dialog.c
index a8edcae..c9f2392 100644
--- a/gtk-dialog.c
+++ b/gtk-dialog.c
@@ -113,27 +113,26 @@ typedef struct {
     ConnContext *context;
 } ConvOrContext;
 
-gint get_new_instance_index(PurpleConversation *conv) {
+static gint get_new_instance_index(PurpleConversation *conv) {
     gint * max_index = (gint *)
 	    purple_conversation_get_data(conv, "otr-max_idx");
     *max_index = (*max_index) + 1;
     return *max_index;
 }
 
-gint get_context_instance_to_index(PurpleConversation *conv,
+static gint get_context_instance_to_index(PurpleConversation *conv,
 	ConnContext *context) {
     GHashTable * conv_to_idx_map =
 	    purple_conversation_get_data(conv, "otr-conv_to_idx");
-    gint * index = 0;
+    gpointer index = NULL;
 
-    if (!g_hash_table_lookup_extended(conv_to_idx_map, context, NULL,
-	    (gpointer *)&index)) {
+    if (!g_hash_table_lookup_extended(conv_to_idx_map, context, NULL, &index)) {
 	index = g_malloc(sizeof(gint));
-	*index = get_new_instance_index(conv);
-	g_hash_table_replace(conv_to_idx_map, context, (gpointer)index);
+	*(gint *)index = get_new_instance_index(conv);
+	g_hash_table_replace(conv_to_idx_map, context, index);
     }
 
-    return *index;
+    return *(gint *)index;
 }
 
 static void close_progress_window(SMPData *smp_data)
@@ -771,6 +770,8 @@ static GtkWidget *create_smp_dialog(const char *title, const char *primary,
 
     close_progress_window(smp_data);
 
+    /* If you start SMP authentication on a different context, it
+     * will kill any existing SMP */
     if (smp_data->their_instance != context->their_instance) {
 	otrg_gtk_dialog_free_smp_data(conv);
 	otrg_gtk_dialog_add_smp_data(conv);
@@ -1612,7 +1613,7 @@ static void otrg_gtk_dialog_connected(ConnContext *context)
 		context->protocol_version == 1 ? _("  Warning: using old "
 		"protocol version 1.") : "", conv->logging ?
 		_("  Your client is logging this conversation.") :
-		_("   Your client is not logging this conversation."));
+		_("  Your client is not logging this conversation."));
 
     purple_conversation_write(conv, NULL, buf, PURPLE_MESSAGE_SYSTEM,
 	    time(NULL));
@@ -1631,11 +1632,13 @@ static void otrg_gtk_dialog_connected(ConnContext *context)
 
 	if (!*have_warned_instances) {
 	    *have_warned_instances = TRUE;
+	    buf = g_strdup_printf(_("Your buddy is logged in multiple times and"
+		    " OTR has established <a href=\"%s%s\">multiple sessions"
+		    "</a>. Use the icon menu above if you wish to select the "
+		    "outgoing session."), SESSIONS_HELPURL, _("?lang=en"));
 	    otrg_gtk_dialog_display_otr_message(context->accountname,
-		    context->protocol, context->username,
-		    _("Your buddy is logged in multiple times and OTR has "
-		    "established multiple sessions. Use the icon menu above if "
-		    "you wish to select the outgoing session."), 0);
+		    context->protocol, context->username, buf, 0);
+	    g_free(buf);
 	}
     }
 }
@@ -1874,7 +1877,7 @@ static void otr_refresh_otr_buttons(PurpleConversation *conv) {
 }
 
 /* Menu has been destroyed -- let's remove it from the menu_list
-   so that it won't be destroyed again                           */
+ * so that it won't be destroyed again. */
 static void otr_menu_destroy(GtkWidget *widget, gpointer pdata) {
     PidginWindow *win = (PidginWindow *) pdata ;
     GtkWidget *top_menu = widget;
@@ -2286,25 +2289,29 @@ static void select_meta_ctx(GtkWidget *widget, gpointer data) {
 
     if (!context) context = (ConnContext *)
 	    otrg_plugin_conv_to_selected_context(conv, 1);
+
     dialog_update_label(context);
 }
 
 static void select_menu_ctx(GtkWidget *widget, gpointer data) {
     ConnContext *context = (ConnContext *) data;
-    PurpleConversation * conv = otrg_plugin_context_to_conv(context, 1);
+    PurpleConversation *conv = otrg_plugin_context_to_conv(context, 1);
     ConnContext *recent_context = (ConnContext *) otrg_plugin_conv_to_context(
 	    conv, (otrl_instag_t)OTRL_INSTAG_RECENT_RECEIVED, 0);
-    otrl_instag_t * selected_instance = (otrl_instag_t *)
+    otrl_instag_t *selected_instance = (otrl_instag_t *)
 	    purple_conversation_get_data(conv, "otr-ui_selected_ctx");
+    gboolean *is_multi_instance = purple_conversation_get_data(conv,
+		    "otr-conv_multi_instances");
 
-    *selected_instance = context->their_instance;
-
-    unselect_meta_ctx(conv);
+    if (*is_multi_instance) {
+	*selected_instance = context->their_instance;
+	unselect_meta_ctx(conv);
+    }
 
     pidgin_conv_switch_active_conversation(conv);
     dialog_update_label(context);
 
-    if (context != recent_context) {
+    if (*is_multi_instance && context != recent_context) {
 	gchar *buf = g_strdup_printf(_("Warning: The selected outgoing OTR "
 		"session (%u) is not the most recently active one (%u). "
 		"Your buddy may not receive your messages. Use the icon menu "
@@ -2324,25 +2331,18 @@ static void build_meta_instance_submenu( PurpleConversation *conv,
 	    _("Send to most secure"));
     GtkWidget *select_recent = gtk_check_menu_item_new_with_label(
 	    _("Send to most recent"));
-    otrl_instag_t * selected_instance;
-    gboolean selected_existed = g_hash_table_lookup_extended(conv->data,
-	    "otr-ui_selected_ctx", NULL, (gpointer*)&selected_instance);
-
-    if (selected_existed) {
-
-	if (*selected_instance == OTRL_INSTAG_BEST) {
-	    GTK_CHECK_MENU_ITEM(select_recent)->active = 0;
-	    GTK_CHECK_MENU_ITEM(select_best)->active = 1;
-	} else if (*selected_instance == OTRL_INSTAG_RECENT_RECEIVED) {
-	    GTK_CHECK_MENU_ITEM(select_recent)->active = 1;
-	    GTK_CHECK_MENU_ITEM(select_best)->active = 0;
-	} else {
-	    GTK_CHECK_MENU_ITEM(select_recent)->active = 0;
-	    GTK_CHECK_MENU_ITEM(select_best)->active = 0;
-	}
-    } else {
+    otrl_instag_t * selected_instance = purple_conversation_get_data(conv,
+	    "otr-ui_selected_ctx");
+
+    if (*selected_instance == OTRL_INSTAG_BEST) {
 	GTK_CHECK_MENU_ITEM(select_recent)->active = 0;
 	GTK_CHECK_MENU_ITEM(select_best)->active = 1;
+    } else if (*selected_instance == OTRL_INSTAG_RECENT_RECEIVED) {
+	GTK_CHECK_MENU_ITEM(select_recent)->active = 1;
+	GTK_CHECK_MENU_ITEM(select_best)->active = 0;
+    } else {
+	GTK_CHECK_MENU_ITEM(select_recent)->active = 0;
+	GTK_CHECK_MENU_ITEM(select_best)->active = 0;
     }
 
     purple_conversation_set_data(conv, "otr-select_best", select_best);
@@ -2361,9 +2361,16 @@ static void build_meta_instance_submenu( PurpleConversation *conv,
     gtk_menu_shell_append(GTK_MENU_SHELL(menu), select_recent);
 }
 
-static void otr_add_buddy_instances_top_menu(PidginConversation *gtkconv, GList
-		*instances, gboolean active_conv, char *username, const char
-		*accountname, int *pos) {
+/* Build an OTR buddy menu (where the root menu item is an icon corresponding
+ * to the conversation status) for a conversation that has multiple instances.
+ * The ConnContexts are given in the GList "instances." Keep track of the
+ * position this menu was inserted in the "pos" argument. "active_conv"
+ * corresponds to whether this conversation is the active PurpleConversation
+ * for this PidginConversation pane.
+ */
+static void otr_add_buddy_instances_top_menu(PidginConversation *gtkconv,
+		GList *instances, gboolean active_conv, const char *username,
+		const char *accountname, int *pos) {
     PidginWindow *win = pidgin_conv_get_window ( gtkconv );
     GtkWidget *menu_bar = win->menu.menubar;
     GtkWidget *menu;
@@ -2403,7 +2410,7 @@ static void otr_add_buddy_instances_top_menu(PidginConversation *gtkconv, GList
     for (; instances; instances = instances->next) {
 	GtkWidget *instance_menu_item;
 	GtkWidget *instance_submenu;
-	gchar text[35] ;
+	gchar* text;
 	ConnContext *curr_context = instances->data;
 	ConvOrContext * curr_convctx = g_hash_table_lookup(conv_or_ctx_map,
 		curr_context);
@@ -2411,7 +2418,7 @@ static void otr_add_buddy_instances_top_menu(PidginConversation *gtkconv, GList
 		context->their_instance);
 	gint instance_i = -1;
 
-	if (curr_context->their_instance == OTRL_INSTAG_MASTER &&
+	if (curr_context->m_context == curr_context &&
 		curr_context->msgstate == OTRL_MSGSTATE_PLAINTEXT) {
 	    continue;
 	}
@@ -2427,7 +2434,7 @@ static void otr_add_buddy_instances_top_menu(PidginConversation *gtkconv, GList
 
 	instance_i = get_context_instance_to_index(conv, curr_context);
 
-	g_snprintf(text, 35, _("Session %u"), instance_i);
+	text = g_strdup_printf(_("Session %u"), instance_i);
 
 	instance_menu_item = gtk_image_menu_item_new_with_label(text);
 	instance_submenu = gtk_menu_new();
@@ -2442,6 +2449,8 @@ static void otr_add_buddy_instances_top_menu(PidginConversation *gtkconv, GList
 
 	build_otr_menu(curr_convctx, instance_submenu, level);
 
+	g_free(text);
+
 	if (!selection_exists || *instance != curr_context->their_instance) {
 	    GtkWidget *select_ctx = gtk_menu_item_new_with_label(_("Select"));
 	    GtkWidget *menusep = gtk_separator_menu_item_new();
@@ -2513,9 +2522,16 @@ static void otr_add_buddy_instances_top_menu(PidginConversation *gtkconv, GList
     g_hash_table_replace ( otr_win_menus, win, menu_list );
 }
 
-static void otr_add_buddy_top_menu(PidginConversation *gtkconv, ConvOrContext
-	*convctx, gboolean active_conv, char *username, const char
-	*accountname, int *pos) {
+/* Build an OTR buddy menu (where the root menu item is an icon corresponding
+ * to the conversation status) for a conversation that does not have multiple
+ * instances. A pre-allocated ConvOrContext is given. Keep track of the
+ * position this menu was inserted in the "pos" argument. "active_conv"
+ * corresponds to whether this conversation is the active PurpleConversation
+ * for this PidginConversation pane.
+ */
+static void otr_add_buddy_top_menu(PidginConversation *gtkconv,
+	ConvOrContext *convctx, gboolean active_conv, const char *username,
+	const char *accountname, int *pos) {
     PidginWindow *win = pidgin_conv_get_window ( gtkconv );
     GtkWidget *menu_bar = win->menu.menubar;
     GtkWidget *menu;
@@ -2710,7 +2726,7 @@ static void otr_add_buddy_top_menus(PurpleConversation *conv) {
 	    contexts_iter = contexts;
 	    currentContext = contexts_iter->data;
 
-	    while (currentContext->their_instance == OTRL_INSTAG_MASTER &&
+	    while (currentContext->m_context == currentContext &&
 		    contexts_iter->next != NULL) {
 		contexts_iter = contexts_iter->next;
 		currentContext = contexts_iter->data;
@@ -2868,7 +2884,6 @@ static void conversation_destroyed(PurpleConversation *conv, void *data)
     g_hash_table_remove(conv->data, "otr-max_idx");
     g_hash_table_remove(conv->data, "otr-conv_multi_instances");
     g_hash_table_remove(conv->data, "otr-warned_instances");
-    g_hash_table_remove(conv->data, "otr-last_msg_event");
     g_hash_table_remove(conv->data, "otr-last_received_ctx");
 
 #ifdef OLD_OTR_BUTTON
@@ -3294,8 +3309,7 @@ static gboolean check_incoming_instance_change(PurpleAccount *account,
     last_received_instance = g_hash_table_lookup(conv->data,
 	    "otr-last_received_ctx");
 
-    if (last_received_instance &&
-	    (*last_received_instance == OTRL_INSTAG_MASTER || 
+    if ((*last_received_instance == OTRL_INSTAG_MASTER || 
 	    *last_received_instance >= OTRL_MIN_VALID_INSTAG)) {
 	have_received = TRUE;
     }
diff --git a/gtk-ui.c b/gtk-ui.c
index 69c3550..030a90c 100644
--- a/gtk-ui.c
+++ b/gtk-ui.c
@@ -165,7 +165,7 @@ static void otrg_gtk_ui_update_keylist(void)
 	PurplePlugin *p;
 	char *proto_name;
 
-	if (context->their_instance != OTRL_INSTAG_MASTER) continue;
+	if (context->m_context != context) continue;
 
 	fingerprint = context->fingerprint_root.next;
 	/* If there's no fingerprint, don't add it to the known
@@ -291,6 +291,7 @@ static void clist_selected(GtkWidget *widget, gint row, gint column,
 		    forget_sensitive = 0;
 		}
 		else if (context_iter->msgstate == OTRL_MSGSTATE_FINISHED) {
+		    disconnect_sensitive = 1;
 		    connect_sensitive = 1;
 		}
 		else if (context_iter->msgstate == OTRL_MSGSTATE_PLAINTEXT) {
@@ -315,6 +316,11 @@ static void clist_unselected(GtkWidget *widget, gint row, gint column,
     clist_all_unselected();
 }
 
+/* For a given fingerprint, find the master context that the fingerprint is
+ * pointing to, iterate through it and all its childdren.
+ * Of the contexts that are using this fingerprint, return a value that
+ * corresponds to the "best" trust level among these.
+ */
 static int fngsortval(Fingerprint *f)
 {
     int result = 200;
diff --git a/otr-plugin.c b/otr-plugin.c
index 393ee74..259e2b7 100644
--- a/otr-plugin.c
+++ b/otr-plugin.c
@@ -77,7 +77,9 @@
 #include "gtk-ui.h"
 #include "gtk-dialog.h"
 
-#if defined WIN32 && defined USING_GTK /* Only for win32 beta */
+#define BETA_DIALOG 1
+
+#if defined BETA_DIALOG && defined USING_GTK /* Only for beta */
 #include "gtkblist.h"
 #endif
 
@@ -158,13 +160,19 @@ static void notify(void *opdata, OtrlNotifyLevel level,
  * protocol / username conversation.  If force_create is non-zero and
  * if the corresponding conversation window is not present, a new
  * conversation window will be created and the message will be displayed
- * there. Returns 0 if message is successfully displayed. */
-static int display_otr_message(void *opdata, const char *accountname,
+ * there. If the message cannot be displayed, try notify() instead and
+ * return 1. Otherwise return 0 if message is successfully displayed. */
+static int display_otr_message_or_notify(void *opdata, const char *accountname,
 	const char *protocol, const char *username, const char *msg,
-	int force_create)
+	int force_create, OtrlNotifyLevel level, const char *title,
+	const char *primary, const char *secondary)
 {
-    return otrg_dialog_display_otr_message(accountname, protocol,
-	    username, msg, force_create);
+    if (otrg_dialog_display_otr_message(accountname, protocol,
+	    username, msg, force_create)) {
+	notify(opdata, level, accountname, protocol, username, title, primary,
+		secondary);
+	return 1;
+    } else return 0;
 }
 
 static void log_message(void *opdata, const char *message)
@@ -417,7 +425,9 @@ static void handle_smp_event_cb(void *opdata, OtrlSMPEvent smp_event,
     }
 }
 
-void otrg_emit_msg_received(ConnContext *context, const char* message) {
+/* Treat this event like other incoming messages. This allows message
+ * notification events to get properly triggered. */
+static void emit_msg_received(ConnContext *context, const char* message) {
     PurpleConversation *conv = otrg_plugin_userinfo_to_conv(
 	    context->accountname, context->protocol, context->username, 1);
     PurpleMessageFlags flags = PURPLE_MESSAGE_RECV | PURPLE_MESSAGE_SYSTEM
@@ -432,11 +442,11 @@ static void handle_msg_event_cb(void *opdata, OtrlMessageEvent msg_event,
 	ConnContext *context, const char* message, gcry_error_t err)
 {
     PurpleConversation *conv = NULL;
-    if (!context) return;
-    char *buf;
-    const char *format;
+    gchar *buf;
     OtrlMessageEvent * last_msg_event;
 
+    if (!context) return;
+
     conv = otrg_plugin_context_to_conv(context, 1);
     last_msg_event = g_hash_table_lookup(conv->data, "otr-last_msg_event");
 
@@ -445,219 +455,149 @@ static void handle_msg_event_cb(void *opdata, OtrlMessageEvent msg_event,
 	case OTRL_MSGEVENT_NONE:
 	    break;
 	case OTRL_MSGEVENT_ENCRYPTION_REQUIRED:
-	    if (display_otr_message(opdata, context->accountname,
+	    buf = g_strdup_printf(_("You attempted to send an "
+		    "unencrypted message to %s"), context->username);
+	    display_otr_message_or_notify(opdata, context->accountname,
 		    context->protocol, context->username, _("Attempting to"
-		    " start a private conversation..."), 1)) {
-		format = _("You attempted to send an "
-		"unencrypted message to %s");
-		buf = malloc(strlen(format) +
-			strlen(context->username) - 1);
-		if (buf) {
-		    sprintf(buf, format, context->username);
-		    notify(opdata, OTRL_NOTIFY_WARNING, context->accountname,
-			    context->protocol, context->username, _("OTR Policy"
-			    " Violation"), buf,
-			    _("Unencrypted messages to this recipient are "
-			    "not allowed.  Attempting to start a private "
-			    "conversation.\n\nYour message will be "
-			    "retransmitted when the private conversation "
-			    "starts."));
-		    free(buf);
-		}
-	    }
+		    " start a private conversation..."), 1, OTRL_NOTIFY_WARNING,
+		    _("OTR Policy Violation"), buf,
+		    _("Unencrypted messages to this recipient are "
+		    "not allowed.  Attempting to start a private "
+		    "conversation.\n\nYour message will be "
+		    "retransmitted when the private conversation "
+		    "starts."));
+	    g_free(buf);
 	    break;
 	case OTRL_MSGEVENT_ENCRYPTION_ERROR:
-	    if (display_otr_message(opdata, context->accountname,
+	    display_otr_message_or_notify(opdata, context->accountname,
 		    context->protocol, context->username, _("An error occurred "
-		    "when encrypting your message.  The message was not sent."
-		    ), 1)) {
-		notify(opdata, OTRL_NOTIFY_ERROR,
-			context->accountname, context->protocol,
-			context->username,
-			_("Error encrypting message"),
-			_("An error occurred when encrypting your message"),
-			_("The message was not sent."));
-	    }
+		    "when encrypting your message.  The message was not sent.")
+		    , 1, OTRL_NOTIFY_ERROR, _("Error encrypting message"),
+		    _("An error occurred when encrypting your message"),
+		    _("The message was not sent."));
 	    break;
 	case OTRL_MSGEVENT_CONNECTION_ENDED:
-	    if (display_otr_message(opdata, context->accountname,
+	    buf = g_strdup_printf(_("%s has already closed his/her private "
+			"connection to you"), context->username);
+	    display_otr_message_or_notify(opdata, context->accountname,
 		    context->protocol, context->username, _("Your message"
 		    "was not sent.  Either end your private conversation, "
-		    "or restart it."), 1)) {
-		format = _("%s has already closed his/her private "
-			"connection to you");
-		buf = malloc(strlen(format) + strlen(context->username) - 1);
-		if (buf) {
-		    sprintf(buf, format, context->username);
-		    notify(opdata, OTRL_NOTIFY_ERROR,
-			    context->accountname, context->protocol,
-			    context->username,
-			    _("Private connection closed"), buf,
-			    _("Your message was not sent.  Either close your "
-			    "private connection to him, or refresh it."));
-		    free(buf);
-		}
-	    }
+		    "or restart it."), 1, OTRL_NOTIFY_ERROR,
+		    _("Private connection closed"), buf,
+		    _("Your message was not sent.  Either close your "
+		    "private connection to him, or refresh it."));
+	    g_free(buf);
 	    break;
 	case OTRL_MSGEVENT_SETUP_ERROR:
-	    if (!err) {
-		err = GPG_ERR_INV_VALUE;
-	    }
-	    format = _("Error setting up private conversation: %s");
-	    const char *strerr;
-
 	    switch(gcry_err_code(err)) {
 		case GPG_ERR_INV_VALUE:
-		    strerr = _("Malformed message received");
+		    buf = g_strdup(_("Error setting up private "
+			    "conversation: Malformed message received"));
 		    break;
 		default:
-		    strerr = gcry_strerror(err);
+		    buf = g_strdup_printf(_("Error setting up private "
+			    "conversation: %s"), gcry_strerror(err));
 		    break;
 	    }
-	    buf = malloc(strlen(format) + strlen(strerr) - 1);
-	    if (buf) {
-		sprintf(buf, format, strerr);
-	    }
-	    if (display_otr_message(opdata, context->accountname,
-		    context->protocol, context->username, buf, 1)) {
-		notify(opdata, OTRL_NOTIFY_ERROR, context->accountname,
-			context->protocol, context->username, "OTR error",
-			buf, NULL);
-	    }
-	    free(buf);
+
+	    display_otr_message_or_notify(opdata, context->accountname,
+		    context->protocol, context->username, buf, 1,
+		    OTRL_NOTIFY_ERROR, "OTR Error", buf, NULL);
+	    g_free(buf);
 	    break;
 	case OTRL_MSGEVENT_MSG_REFLECTED:
-	    if (display_otr_message(opdata,
+	    display_otr_message_or_notify(opdata,
 		    context->accountname, context->protocol,
 		    context->username,
 		    _("We are receiving our own OTR messages.  "
 		    "You are either trying to talk to yourself, "
 		    "or someone is reflecting your messages back "
-		    "at you."), 1))  {
-		notify(opdata, OTRL_NOTIFY_ERROR,
-			context->accountname, context->protocol,
-			context->username, "OTR Error",
-			_("We are receiving our own OTR messages."),
-			_("You are either trying to talk to yourself, "
-			"or someone is reflecting your messages back "
-			"at you."));
-	    }
+		    "at you."), 1, OTRL_NOTIFY_ERROR,
+		    "OTR Error", _("We are receiving our own OTR messages."),
+		    _("You are either trying to talk to yourself, "
+		    "or someone is reflecting your messages back "
+		    "at you."));
 	    break;
 	case OTRL_MSGEVENT_MSG_RESENT:
-	    format = _("<b>The last message to %s was resent.</b>");
-	    buf = malloc(strlen(format) +
-		    strlen(context->username) - 1);
-	    if (buf) {
-		sprintf(buf, format, context->username);
-		display_otr_message(opdata, context->accountname,
-			context->protocol, context->username, buf, 1);
-		free(buf);
-	    }
+	    buf = g_strdup_printf(_("<b>The last message to %s was resent."
+		    "</b>"), context->username);
+	    display_otr_message_or_notify(opdata, context->accountname,
+		    context->protocol, context->username, buf, 1,
+		    OTRL_NOTIFY_INFO, _("Message resent"), buf, NULL);
+	    g_free(buf);
 	    break;
 	case OTRL_MSGEVENT_RCVDMSG_NOT_IN_PRIVATE:
-	    format = _("<b>The encrypted message received from %s is "
-		    "unreadable, as you are not currently communicating "
-		    "privately.</b>");
-	    buf = malloc(strlen(format) +
-		    strlen(context->username) - 1);
-	    if (buf) {
-		sprintf(buf, format, context->username);
-		display_otr_message(opdata, context->accountname,
-			context->protocol, context->username, buf, 1);
-		free(buf);
-	    }
+	    buf = g_strdup_printf(_("<b>The encrypted message received from "
+		    "%s is unreadable, as you are not currently communicating "
+		    "privately.</b>"), context->username);
+	    display_otr_message_or_notify(opdata, context->accountname,
+		    context->protocol, context->username, buf, 1,
+		    OTRL_NOTIFY_INFO, _("Unreadable message"), buf, NULL);
+	    g_free(buf);
 	    break;
 	case OTRL_MSGEVENT_RCVDMSG_UNREADABLE:
-	    format = _("We received an unreadable "
-		    "encrypted message from %s.");
-	    buf = malloc(strlen(format) + strlen(context->username) - 1);
-	    if (buf) {
-		sprintf(buf, format, context->username);
-		if (display_otr_message(opdata,
-			context->accountname, context->protocol,
-			context->username, buf, 1)) {
-		    notify(opdata, OTRL_NOTIFY_ERROR,
-			    context->accountname, context->protocol,
-			    context->username, "OTR Error", buf, NULL);
-		}
-		free(buf);
-	    }
+	    buf = g_strdup_printf(_("We received an unreadable "
+		    "encrypted message from %s."), context->username);
+	    display_otr_message_or_notify(opdata, context->accountname,
+		    context->protocol, context->username, buf, 1,
+		    OTRL_NOTIFY_ERROR, "OTR Error", buf, NULL);
+	    g_free(buf);
 	    break;
 	case OTRL_MSGEVENT_RCVDMSG_MALFORMED:
-	    format =  _("We received a malformed data "
-		    "message from %s.");
-	    buf = malloc(strlen(format) + strlen(context->username) - 1);
-	    if (buf) {
-		sprintf(buf, format, context->username);
-		if (display_otr_message(opdata,
-			context->accountname, context->protocol,
-			context->username, buf, 1)) {
-		    notify(opdata, OTRL_NOTIFY_ERROR,
-			    context->accountname, context->protocol,
-			    context->username, "OTR Error", buf, NULL);
-		}
-		free(buf);
-	    }
+	    buf = g_strdup_printf(_("We received a malformed data "
+		    "message from %s."), context->username);
+	    display_otr_message_or_notify(opdata, context->accountname,
+		    context->protocol, context->username, buf, 1,
+		    OTRL_NOTIFY_ERROR, "OTR Error", buf, NULL);
+	    g_free(buf);
 	    break;
 	case OTRL_MSGEVENT_LOG_HEARTBEAT_RCVD:
-	    format = _("Heartbeat received from %s.\n");
-	    buf = malloc(strlen(format) + strlen(context->username) - 1);
-	    if (buf) {
-		sprintf(buf, format, context->username);
-		log_message(opdata, buf);
-		free(buf);
-	    }
+	    buf = g_strdup_printf(_("Heartbeat received from %s.\n"),
+		    context->username);
+	    log_message(opdata, buf);
+	    g_free(buf);
 	    break;
 	case OTRL_MSGEVENT_LOG_HEARTBEAT_SENT:
-	    format = _("Heartbeat sent to %s.\n");
-	    buf = malloc(strlen(format) + strlen(context->username) - 1);
-	    if (buf) {
-		sprintf(buf, format, context->username);
-		log_message(opdata, buf);
-		free(buf);
-	    }
+	    buf = g_strdup_printf(_("Heartbeat sent to %s.\n"),
+		    context->username);
+	    log_message(opdata, buf);
+	    g_free(buf);
 	    break;
 	case OTRL_MSGEVENT_RCVDMSG_GENERAL_ERR:
-	    display_otr_message(opdata, context->accountname,
-		    context->protocol, context->username, message, 1);
+	    display_otr_message_or_notify(opdata, context->accountname,
+		    context->protocol, context->username, message, 1,
+		    OTRL_NOTIFY_ERROR, "OTR Error", message, NULL);
 	    break;
 	case OTRL_MSGEVENT_RCVDMSG_UNENCRYPTED:
-	    format = _("<b>The following message received "
-		    "from %s was <i>not</i> encrypted: [</b>%s<b>]</b>");
-	    buf = malloc(strlen(format) + strlen(context->username)
-		    + strlen(message) - 3);
-		/* Remove "%s%s", add username + message + '\0' */
-	    if (buf) {
-		sprintf(buf, format, context->username, message);
-		display_otr_message(opdata, context->accountname,
-			context->protocol, context->username, buf, 1);
-		otrg_emit_msg_received(context, buf);
-		free(buf);
-	    }
+	    buf = g_strdup_printf(_("<b>The following message received "
+		    "from %s was <i>not</i> encrypted: [</b>%s<b>]</b>"),
+		    context->username, message);
+	    display_otr_message_or_notify(opdata, context->accountname,
+		    context->protocol, context->username, buf, 1,
+		    OTRL_NOTIFY_INFO, _("Received unencrypted message"),
+		    buf, NULL);
+	    emit_msg_received(context, buf);
+	    g_free(buf);
 	    break;
 	case OTRL_MSGEVENT_RCVDMSG_UNRECOGNIZED:
-	    format = _("Unrecognized OTR message received from %s.\n");
-	    buf = malloc(strlen(format) + strlen(context->username) - 1);
-	    if (buf) {
-		sprintf(buf, format, context->username);
-		log_message(opdata, buf);
-		free(buf);
-	    }
+	    buf = g_strdup_printf(_("Unrecognized OTR message received "
+		    "from %s.\n"), context->username);
+	    log_message(opdata, buf);
+	    g_free(buf);
 	    break;
 	case OTRL_MSGEVENT_RCVDMSG_FOR_OTHER_INSTANCE:
 	    if (*last_msg_event == msg_event) {
 		break;
 	    }
-	    format = _("%s has sent a message intended for a different session."
-		    " If you are logged in multiple times, another session may "
-		    "have received the message.");
-	    buf = malloc(strlen(format) + strlen(context->username) - 1);
-	    if (buf) {
-		sprintf(buf, format, context->username);
-		display_otr_message(opdata, context->accountname,
-			context->protocol, context->username, buf, 1);
-		free(buf);
-	    }
+	    buf = g_strdup_printf(_("%s has sent a message intended for a "
+		    "different session. If you are logged in multiple times, "
+		    "another session may have received the message."),
+		    context->username);
+	    display_otr_message_or_notify(opdata, context->accountname,
+		    context->protocol, context->username, buf, 1,
+		    OTRL_NOTIFY_INFO, _("Received message for a different "
+		    "session"), buf, NULL);
+	    g_free(buf);
 	    break;
     }
 
@@ -709,12 +649,10 @@ static OtrlMessageAppOps ui_ops = {
     handle_smp_event_cb,
     handle_msg_event_cb,
     create_instag_cb,
-    NULL, /* convert_data */
-    NULL /* convert_data_free */
+    NULL,		    /* convert_data */
+    NULL		    /* convert_data_free */
 };
 
-otrl_instag_t otrg_plugin_conv_to_selected_instag(PurpleConversation *conv,
-	otrl_instag_t default_value);
 
 static void process_sending_im(PurpleAccount *account, char *who,
 	char **message, void *m)
@@ -899,10 +837,16 @@ ConnContext *otrg_plugin_conv_to_context(PurpleConversation *conv,
 otrl_instag_t otrg_plugin_conv_to_selected_instag(PurpleConversation *conv,
 	otrl_instag_t default_val)
 {
-    otrl_instag_t * selected_instance;
+    otrl_instag_t *selected_instance;
+
+    if (!conv || !conv->data) {
+	return default_val;
+    }
+
+    selected_instance = purple_conversation_get_data(conv,
+	    "otr-ui_selected_ctx");
 
-    if (!conv || !conv->data || !g_hash_table_lookup_extended(conv->data,
-	    "otr-ui_selected_ctx", NULL, (gpointer*)&selected_instance)) {
+    if (!selected_instance) {
 	return default_val;
     }
 
@@ -927,13 +871,15 @@ static void process_conv_create(PurpleConversation *conv, void *data)
     OtrlMessageEvent * msg_event;
     if (!conv) return;
 
+    /* If this malloc fails (or the others below), trouble will be
+     * unavoidable. */
     selected_instance = g_malloc(sizeof(otrl_instag_t));
     *selected_instance = OTRL_INSTAG_BEST;
     purple_conversation_set_data(conv, "otr-ui_selected_ctx",
 	    (gpointer)selected_instance);
 
     msg_event = g_malloc(sizeof(OtrlMessageEvent));
-    *msg_event = -1;
+    *msg_event = OTRL_MSGEVENT_NONE;
     purple_conversation_set_data(conv, "otr-last_msg_event",
 	    (gpointer)msg_event);
 
@@ -1222,7 +1168,7 @@ static gboolean otr_plugin_load(PurplePlugin *handle)
     FILE *privf;
     FILE *storef;
     FILE *instagf;
-#if defined WIN32 && defined USING_GTK /* Only for win32 beta */
+#if defined BETA_DIALOG && defined USING_GTK /* Only for beta */
     GtkWidget *dialog;
     GtkWidget *dialog_text;
     PidginBuddyList *blist;
@@ -1235,21 +1181,21 @@ static gboolean otr_plugin_load(PurplePlugin *handle)
 	return 0;
     }
 
-#if defined WIN32 && defined USING_GTK /* Only for win32 beta */
+#if defined BETA_DIALOG && defined USING_GTK /* Only for beta */
     blist = pidgin_blist_get_default_gtk_blist();
 
     if (time(NULL) > 1356998400) /* 2013-01-01 */ {
-	dialog = gtk_dialog_new_with_buttons ("OTR PLUGIN V4.0 BETA",
+	dialog = gtk_dialog_new_with_buttons (_("OTR PLUGIN V4.0 BETA"),
 		GTK_WINDOW(blist->window),
 		GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
 		GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL);
 	dialog_text = gtk_label_new(NULL);
 	gtk_widget_set_size_request(dialog_text, 350, 100);
 	gtk_label_set_line_wrap(GTK_LABEL(dialog_text), TRUE);
-	gtk_label_set_text(GTK_LABEL(dialog_text), "This beta copy of the "
+	gtk_label_set_text(GTK_LABEL(dialog_text), _("This beta copy of the "
 		"Off-the-Record Messaging v4.0 Pidgin plugin has expired as of "
 		"2013-01-01. Please look for an updated release at "
-		"www.cypherpunks.ca/otr.");
+		"http://otr.cypherpunks.ca."));
 	gtk_widget_show(dialog_text);
 	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), dialog_text,
 		TRUE, TRUE, 0);
@@ -1263,17 +1209,17 @@ static gboolean otr_plugin_load(PurplePlugin *handle)
     }
 
 
-    dialog = gtk_dialog_new_with_buttons ("OTR PLUGIN V4.0 BETA",
+    dialog = gtk_dialog_new_with_buttons (_("OTR PLUGIN V4.0 BETA"),
 	    GTK_WINDOW(blist->window),
 	    GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
 	    GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL);
     dialog_text = gtk_label_new(NULL);
     gtk_widget_set_size_request(dialog_text, 350, 100);
     gtk_label_set_line_wrap(GTK_LABEL(dialog_text), TRUE);
-    gtk_label_set_text(GTK_LABEL(dialog_text), "You have enabled a beta "
+    gtk_label_set_text(GTK_LABEL(dialog_text), _("You have enabled a beta "
 	    "version of the Off-the-Record Messaging v4.0 Pidgin plugin. "
 	    "This version is intended for testing purposes only and is not "
-	    "for general purpose use.");
+	    "for general purpose use."));
     gtk_widget_show(dialog_text);
     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), dialog_text,
 	    TRUE, TRUE, 0);
@@ -1417,8 +1363,8 @@ static PurplePluginInfo info =
 	NULL,                                             /* description    */
 							  /* author         */
 	"Ian Goldberg, Rob Smits,\n"
-	    "\t\t\tChris Alexander, Willy Lew, Nikita Borisov\n"
-	    "\t\t\t<otr at cypherpunks.ca>",
+	    "\t\t\tChris Alexander, Willy Lew, Lisa Du,\n"
+	    "\t\t\tNikita Borisov <otr at cypherpunks.ca>",
 	"http://otr.cypherpunks.ca/",                     /* homepage       */
 
 	otr_plugin_load,                                  /* load           */
diff --git a/otr-plugin.h b/otr-plugin.h
index 70eb023..e33359c 100644
--- a/otr-plugin.h
+++ b/otr-plugin.h
@@ -40,11 +40,12 @@ extern PurplePlugin *otrg_plugin_handle;
 
 extern OtrlUserState otrg_plugin_userstate;
 
-/* Given a PurpleConversation, return the selected ConnContext */
+/* Given a PurpleConversation, return the ConnContext corresponding to the
+ * selected instance tag. */
 ConnContext* otrg_plugin_conv_to_selected_context(PurpleConversation *conv,
 	int force_create);
 
-/* Given a PurpleConversation, return the selected instag */
+/* Given a PurpleConversation, return the selected instag. */
 otrl_instag_t otrg_plugin_conv_to_selected_instag(PurpleConversation *conv,
 	otrl_instag_t default_value);
 
@@ -104,10 +105,6 @@ PurpleConversation *otrg_plugin_userinfo_to_conv(const char *accountname,
 PurpleConversation *otrg_plugin_context_to_conv(ConnContext *context,
 	int force_create);
 
-/* Cause the "msg-received" signal to be emitted with the given message
- * payload. This causes the message to pop-up in the notification area when the
- * user has the libnotify plugin enabled. */
-void otrg_emit_msg_received(ConnContext *context, const char* message);
 
 typedef enum {
     TRUST_NOT_PRIVATE,
diff --git a/packaging/windows/pidgin-otr.nsi b/packaging/windows/pidgin-otr.nsi
index 0bda765..5ad3462 100644
--- a/packaging/windows/pidgin-otr.nsi
+++ b/packaging/windows/pidgin-otr.nsi
@@ -137,6 +137,7 @@ Section Uninstall
   Delete "$INSTDIR\README.Toolkit.txt"
   Delete "$INSTDIR\README.txt"
   Delete "$INSTDIR\Protocol-v3.html"
+  Delete "$INSTDIR\Protocol-v2.html" ;Left behind by v3.2.0 uninstaller
   Delete "$INSTDIR\COPYING.txt"
   Delete "$INSTDIR\COPYING.LIB.txt"
   Delete "$INSTDIR\otr_mackey.exe"

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



More information about the Pkg-otr-team mailing list