[Tkabber-dev] r2069 - in trunk/tkabber-plugins: . otr otr/tclotr

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Mon Jan 20 22:29:09 MSK 2014


Author: sergei
Date: 2014-01-20 22:29:09 +0400 (Mon, 20 Jan 2014)
New Revision: 2069

Modified:
   trunk/tkabber-plugins/ChangeLog
   trunk/tkabber-plugins/otr/otr.tcl
   trunk/tkabber-plugins/otr/tclotr/otr.tcl
Log:
	* otr/tclotr/otr.tcl: Fixed typo in code which stores old MAC keys.

	* otr/otr.tcl: Don't filter outgoing messages with empty body (or
	  without body at all). Don't allow the user to send messages in
	  finished OTR state.

	* otr/otr.tcl, otr/tclotr/otr.tcl: Removed unnecessary field from
	  OTR procedures' result.


Modified: trunk/tkabber-plugins/ChangeLog
===================================================================
--- trunk/tkabber-plugins/ChangeLog	2014-01-20 18:13:55 UTC (rev 2068)
+++ trunk/tkabber-plugins/ChangeLog	2014-01-20 18:29:09 UTC (rev 2069)
@@ -16,6 +16,15 @@
 	* otr/tclotr/otr.tcl, otr/otr.tcl: Implemented sending heartbeat
 	  messages (the OTR plugin doesn't use this yet).
 
+	* otr/tclotr/otr.tcl: Fixed typo in code which stores old MAC keys.
+
+	* otr/otr.tcl: Don't filter outgoing messages with empty body (or
+	  without body at all). Don't allow the user to send messages in
+	  finished OTR state.
+
+	* otr/otr.tcl, otr/tclotr/otr.tcl: Removed unnecessary field from
+	  OTR procedures' result.
+
 2014-01-19  Sergei Golovan <sgolovan at nes.ru>
 
 	* otr/tclotr/otr.tcl: Fixed checking data message hash for protocol

Modified: trunk/tkabber-plugins/otr/otr.tcl
===================================================================
--- trunk/tkabber-plugins/otr/otr.tcl	2014-01-20 18:13:55 UTC (rev 2068)
+++ trunk/tkabber-plugins/otr/otr.tcl	2014-01-20 18:29:09 UTC (rev 2069)
@@ -334,7 +334,7 @@
 
     set result [::otr::requestConversation $ctx($xlib,$jid)]
     array set res $result
-    if {$res(action) eq "send"} {
+    if {[info exists res(body)]} {
 	append res(body) \n \
 	    [format [::trans::trans $lang \
 		"%s has requested an Off-the-Record\ private conversation\
@@ -353,7 +353,7 @@
 
     set result [::otr::finishConversation $ctx($xlib,$jid)]
     array set res $result
-    if {$res(action) eq "send"} {
+    if {[info exists res(body)]} {
 	::xmpp::sendMessage $xlib $jid -type $type -body $res(body)
     }
     foreach state {authstate msgstate smpstate} {
@@ -548,7 +548,7 @@
 
     set result [::otr::startSMP $ctx($xlib,$jid) $secret {*}$question]
     array set res $result
-    if {$res(action) eq "send"} {
+    if {[info exists res(body)]} {
 	::xmpp::sendMessage $xlib $jid -body $res(body)
     }
     foreach state {authstate msgstate smpstate} {
@@ -692,7 +692,7 @@
 
     set result [::otr::replySMP $ctx($xlib,$jid) $secret]
     array set res $result
-    if {$res(action) eq "send"} {
+    if {[info exists res(body)]} {
 	::xmpp::sendMessage $xlib $jid -body $res(body)
     }
     foreach state {authstate msgstate smpstate} {
@@ -711,7 +711,7 @@
     if {$ctx(msgstate,$xlib,$jid) eq "MSGSTATE_ENCRYPTED"} {
 	set result [::otr::abortSMP $ctx($xlib,$jid)]
 	array set res $result
-	if {$res(action) eq "send"} {
+	if {[info exists res(body)]} {
 	    ::xmpp::sendMessage $xlib $jid -body $res(body)
 	}
 	foreach state {authstate msgstate smpstate} {
@@ -785,6 +785,11 @@
     variable ns
     variable ctx
 
+    # We can't distinguish between bodyless message and message with empty
+    # body, so be it
+
+    if {$body eq ""} return
+
     once_only $xlib $from
 
     set result [::otr::incomingMessage $ctx($xlib,$from) $body] 
@@ -905,15 +910,31 @@
     upvar 2 $vto to
     upvar 2 $vbody body
     upvar 2 $vx x
+    variable ctx
 
     if {![info exists body]} return
 
+    once_only $xlib $to
+
     # Only the message body is encrypted if appropriate
-    lassign [filter:output $xlib $to $body] encrypted status
 
-    if {$status ne ""} {
-	set body $encrypted
+    set result [::otr::outgoingMessage $ctx($xlib,$to) $body]
+
+    debugmsg otr "FILTER_OUTPUT: $xlib; $to; $result"
+
+    array set res $result
+
+    if {[info exists res(body)]} {
+	set body $res(body)
     }
+
+    if {[info exists res(info)]} {
+	set chatid [::chat::chatid $xlib $to]
+	chat::add_message $chatid $to info $res(info) {}
+	hook::unset_flag chat_send_message_hook draw
+	# Rewrite to JID to disable sending.
+	set to ""
+    }
 }
 
 hook::add rewrite_outgoing_message_hook \

Modified: trunk/tkabber-plugins/otr/tclotr/otr.tcl
===================================================================
--- trunk/tkabber-plugins/otr/tclotr/otr.tcl	2014-01-20 18:13:55 UTC (rev 2068)
+++ trunk/tkabber-plugins/otr/tclotr/otr.tcl	2014-01-20 18:29:09 UTC (rev 2069)
@@ -260,7 +260,7 @@
     variable $token
     upvar $token state
 
-    list action send body [::otr::data::queryMessage $state(Policy)]
+    list body [::otr::data::queryMessage $state(Policy)]
 }
 
 proc ::otr::finishConversation {token} {
@@ -269,19 +269,18 @@
 
     switch -- $state(MsgState) {
         MSGSTATE_PLAINTEXT {
-            return [list action discard]
+            return {}
         }
         MSGSTATE_ENCRYPTED {
             set message [CreateEncryptedMessage $token {} "" {1 ""}]
             set state(MsgState) MSGSTATE_PLAINTEXT
             InitDHKeys $token
-            return [list action   send \
-                         body     $message \
+            return [list body     $message \
                          msgstate $state(MsgState)]
         }
         MSGSTATE_FINISHED {
             set state(MsgState) MSGSTATE_PLAINTEXT
-            return [list action discard msgstate $state(MsgState)]
+            return [list msgstate $state(MsgState)]
         }
     }
 }
@@ -307,13 +306,12 @@
                     state(SMPState) progress flags body tlvlist
             set message [CreateEncryptedMessage $token $flags $body $tlvlist]
 
-            return [list action      send \
-                         body        $message \
+            return [list body        $message \
                          smpstate    $state(SMPState) \
                          smpprogress $progress]
         }
         default {
-            return [list action discard smpprogress SMP_ABORT]
+            return [list smpprogress SMP_ABORT]
         }
     }
 }
@@ -328,13 +326,12 @@
                     state(SMPState) progress flags body tlvlist
             set message [CreateEncryptedMessage $token $flags $body $tlvlist]
 
-            return [list action      send \
-                         body        $message \
+            return [list body        $message \
                          smpstate    $state(SMPState) \
                          smpprogress $progress]
         }
         default {
-            return [list action discard smpprogress SMP_ABORT]
+            return [list smpprogress SMP_ABORT]
         }
     }
 }
@@ -348,13 +345,12 @@
             set message [CreateEncryptedMessage $token {} "" {6 ""}]
 
             set state(SMPState) SMPSTATE_EXPECT1
-            return [list action      send \
-                         body        $message \
+            return [list body        $message \
                          smpstate    $state(SMPState) \
                          smpprogress SMP_ABORT]
         }
         default {
-            return [list action discard smpprogress SMP_ABORT]
+            return [list smpprogress SMP_ABORT]
         }
     }
 }
@@ -369,16 +365,14 @@
         MSGSTATE_PLAINTEXT {
             if {[QueryPolicy $token REQUIRE_ENCRYPTION]} {
                 Store $token $body
-                return [list action send \
-                             body [::otr::data::queryMessage $state(Policy)]]
+                return [list body [::otr::data::queryMessage $state(Policy)]]
             } elseif {[QueryPolicy $token SEND_WHITESPACE_TAG] &&
                       ([QueryPolicy $token ALLOW_V2] ||
                        [QueryPolicy $token ALLOW_V3])} {
-                return [list action send \
-                             body "$body[::otr::data::whitespaceTag \
-                                                        $state(Policy)]"]
+                return [list body "$body[::otr::data::whitespaceTag \
+                                                    $state(Policy)]"]
             } else {
-                return [list action send body $body]
+                return [list body $body]
             }
         }
         MSGSTATE_ENCRYPTED {
@@ -388,13 +382,13 @@
             set state(LastMessage) [clock seconds]
 
             set message [CreateEncryptedMessage $token {} $body {}]
-            return [list action send \
-                         body   $message]
+            return [list body $message]
         }
         MSGSTATE_FINISHED {
             Store $token $body
-            return [list action stop info "Can't send message when OTR\
-                                           conversation is in finished state"]
+
+            return [list info "Message is not sent. Either end your private\
+                               conversation, or restart it."]
         }
     }
 }
@@ -956,7 +950,7 @@
                         foreach id [array names state oldmackey,*,$rkeyid] {
                             # Add the used receiving MAC keys to the
                             # revealed keys list
-                            lappend state(oldmackeys) $state(id)
+                            lappend state(oldmackeys) $state($id)
                             unset state($id)
                         }
                         incr rkeyid 2
@@ -971,7 +965,7 @@
                         foreach id [array names state oldmackey,$skeyid,*] {
                             # Add the used receiving MAC keys to the
                             # revealed keys list
-                            lappend state(oldmackeys) $state(id)
+                            lappend state(oldmackeys) $state($id)
                             unset state($id)
                         }
                         incr skeyid 2



More information about the Tkabber-dev mailing list