[Pkg-privacy-commits] [pidgin-otr] 68/255: * dialogs.c: * dialogs.h: * gtk-dialog.c: * otr-plugin.c: Use the new SMP event callback instead of handling the SMP state machine ourselves.

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 12:51:24 UTC 2015


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

infinity0 pushed a commit to branch experimental
in repository pidgin-otr.

commit 24518597dd2bb48544a99034e2623cb9462b955b
Author: cypherpunk <cypherpunk>
Date:   Wed Jul 2 15:38:35 2008 +0000

    	* dialogs.c:
    	* dialogs.h:
    	* gtk-dialog.c:
    	* otr-plugin.c: Use the new SMP event callback instead of
    	handling the SMP state machine ourselves.
---
 ChangeLog    |   8 +++++
 dialogs.c    |   5 +--
 dialogs.h    |   6 ++--
 gtk-dialog.c |   4 +--
 otr-plugin.c | 104 ++++++++++++++++++-----------------------------------------
 5 files changed, 49 insertions(+), 78 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 771a2d1..64e5ff6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-07-02
+
+	* dialogs.c:
+	* dialogs.h:
+	* gtk-dialog.c:
+	* otr-plugin.c: Use the new SMP event callback instead of
+	handling the SMP state machine ourselves.
+
 2008-06-19
 
 	* Makefile.static: Forgot to add tooltipmenu.o to
diff --git a/dialogs.c b/dialogs.c
index d36ee02..3f568ef 100644
--- a/dialogs.c
+++ b/dialogs.c
@@ -153,9 +153,10 @@ void otrg_dialog_socialist_millionaires_q(ConnContext *context,
 }
 
 /* Update the status of an ongoing socialist millionaires protocol. */
-void otrg_dialog_update_smp(ConnContext *context, double progress_level)
+void otrg_dialog_update_smp(ConnContext *context, OtrlSMPEvent smp_event,
+	double progress_level)
 {
-    ui_ops->update_smp(context, progress_level);
+    ui_ops->update_smp(context, smp_event, progress_level);
 }
 
 /* Call this when a context transitions to ENCRYPTED. */
diff --git a/dialogs.h b/dialogs.h
index 1fad217..a8de431 100644
--- a/dialogs.h
+++ b/dialogs.h
@@ -62,7 +62,8 @@ typedef struct {
     void (*socialist_millionaires)(ConnContext *context, char *question,
 	    gboolean responder);
 
-    void (*update_smp)(ConnContext *context, double progress_level);
+    void (*update_smp)(ConnContext *context, OtrlSMPEvent smp_event,
+	    double progress_level);
 
     void (*connected)(ConnContext *context);
 
@@ -146,7 +147,8 @@ void otrg_dialog_socialist_millionaires_q(ConnContext *context,
 	char *question);
 
 /* Update the status of an ongoing socialist millionaires protocol. */
-void otrg_dialog_update_smp(ConnContext *context, double progress_level);
+void otrg_dialog_update_smp(ConnContext *context, OtrlSMPEvent smp_event,
+	double progress_level);
 
 /* Call this when a context transitions to ENCRYPTED. */
 void otrg_dialog_connected(ConnContext *context);
diff --git a/gtk-dialog.c b/gtk-dialog.c
index 65250a0..7bd32bf 100644
--- a/gtk-dialog.c
+++ b/gtk-dialog.c
@@ -1441,7 +1441,7 @@ static void otrg_gtk_dialog_socialist_millionaires(ConnContext *context,
  * protocol.  Progress_level is a percentage, from 0.0 (aborted) to
  * 1.0 (complete).  Any other value represents an intermediate state. */
 static void otrg_gtk_dialog_update_smp(ConnContext *context,
-	double progress_level)
+	OtrlSMPEvent smp_event, double progress_level)
 {
     PurpleConversation *conv = otrg_plugin_context_to_conv(context, 0);
     GtkProgressBar *bar;
@@ -1473,7 +1473,7 @@ static void otrg_gtk_dialog_update_smp(ConnContext *context,
 	gtk_dialog_set_default_response(GTK_DIALOG(dialog),
 		GTK_RESPONSE_ACCEPT);
 
-        if (context->smstate->sm_prog_state == OTRL_SMP_PROG_SUCCEEDED) {
+        if (smp_event == OTRL_SMPEVENT_SUCCESS) {
 	    if (context->active_fingerprint->trust &&
 		    context->active_fingerprint->trust[0]) {
 		gtk_label_set_text(GTK_LABEL(smp_data->smp_progress_label),
diff --git a/otr-plugin.c b/otr-plugin.c
index 0d801b6..f901b50 100644
--- a/otr-plugin.c
+++ b/otr-plugin.c
@@ -308,6 +308,35 @@ static int max_message_size_cb(void *opdata, ConnContext *context)
         return *((int*)lookup_result);
 }
 
+static void handle_smp_event(void *opdata, OtrlSMPEvent smp_event, 
+        ConnContext *context, unsigned short progress_percent,
+	char *question)
+{
+    if (!context) return;
+    switch (smp_event) 
+    {
+        case OTRL_SMPEVENT_ASK_FOR_SECRET :
+            otrg_dialog_socialist_millionaires(context);
+            break;
+        case OTRL_SMPEVENT_ASK_FOR_ANSWER :
+            otrg_dialog_socialist_millionaires_q(context, question);
+            break;
+        case OTRL_SMPEVENT_CHEATED :  
+            otrg_plugin_abort_smp(context);
+	    /* FALLTHROUGH */
+        case OTRL_SMPEVENT_IN_PROGRESS :
+        case OTRL_SMPEVENT_SUCCESS : 
+        case OTRL_SMPEVENT_FAILURE :  
+        case OTRL_SMPEVENT_ABORT :  
+            otrg_dialog_update_smp(context,
+		    smp_event, ((gdouble)progress_percent)/100.0);
+            break;
+        case OTRL_SMPEVENT_ERROR :  
+            otrg_plugin_abort_smp(context);
+            break;
+    }   
+}
+
 static OtrlMessageAppOps ui_ops = {
     policy_cb,
     create_privkey_cb,
@@ -326,7 +355,9 @@ static OtrlMessageAppOps ui_ops = {
     log_message_cb,
     max_message_size_cb,
     NULL,                   /* account_name */
-    NULL                    /* account_name_free */
+    NULL,                   /* account_name_free */
+    NULL,		    /* received_symkey */
+    handle_smp_event
 };
 
 static void process_sending_im(PurpleAccount *account, char *who,
@@ -440,8 +471,6 @@ static gboolean process_receiving_im(PurpleAccount *account, char **who,
     gboolean res;
     const char *accountname;
     const char *protocol;
-    ConnContext *context;
-    NextExpectedSMP nextMsg;
 
     if (!who || !*who || !message || !*message)
         return 0;
@@ -471,75 +500,6 @@ static gboolean process_receiving_im(PurpleAccount *account, char **who,
 	otrg_ui_update_keylist();
     }
 
-    /* Keep track of our current progress in the Socialist Millionaires'
-     * Protocol. */
-    context = otrl_context_find(otrg_plugin_userstate, username,
-	    accountname, protocol, 0, NULL, NULL, NULL);
-    if (context) {
-	nextMsg = context->smstate->nextExpected;
-
-	if (context->smstate->sm_prog_state == OTRL_SMP_PROG_CHEATED) {
-	    otrg_plugin_abort_smp(context);
-	    otrg_dialog_update_smp(context, 0.0);
-	    context->smstate->nextExpected = OTRL_SMP_EXPECT1;
-	    context->smstate->sm_prog_state = OTRL_SMP_PROG_OK;
-	} else {
-	    tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP1Q);
-	    if (tlv) {
-		if (nextMsg != OTRL_SMP_EXPECT1)
-		    otrg_plugin_abort_smp(context);
-		else {
-		    char *question = (char *)tlv->data;
-		    char *eoq = memchr(question, '\0', tlv->len);
-		    if (eoq) {
-			otrg_dialog_socialist_millionaires_q(context,
-				question);
-		    }
-		}
-	    }
-	    tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP1);
-	    if (tlv) {
-		if (nextMsg != OTRL_SMP_EXPECT1)
-		    otrg_plugin_abort_smp(context);
-		else {
-		    otrg_dialog_socialist_millionaires(context);
-		}
-	    }
-	    tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP2);
-	    if (tlv) {
-		if (nextMsg != OTRL_SMP_EXPECT2)
-		    otrg_plugin_abort_smp(context);
-		else {
-		    otrg_dialog_update_smp(context, 0.6);
-		    context->smstate->nextExpected = OTRL_SMP_EXPECT4;
-		}
-	    }
-	    tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP3);
-	    if (tlv) {
-		if (nextMsg != OTRL_SMP_EXPECT3)
-		    otrg_plugin_abort_smp(context);
-		else {
-		    otrg_dialog_update_smp(context, 1.0);
-		    context->smstate->nextExpected = OTRL_SMP_EXPECT1;
-		}
-	    }
-	    tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP4);
-	    if (tlv) {
-		if (nextMsg != OTRL_SMP_EXPECT4)
-		    otrg_plugin_abort_smp(context);
-		else {
-		    otrg_dialog_update_smp(context, 1.0);
-		    context->smstate->nextExpected = OTRL_SMP_EXPECT1;
-		}
-	    }
-	    tlv = otrl_tlv_find(tlvs, OTRL_TLV_SMP_ABORT);
-	    if (tlv) {
-		otrg_dialog_update_smp(context, 0.0);
-		context->smstate->nextExpected = OTRL_SMP_EXPECT1;
-	    }
-	}
-    }
-
     otrl_tlv_free(tlvs);
 
     free(username);

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



More information about the Pkg-privacy-commits mailing list