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

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Fri Jan 24 09:59:57 MSK 2014


Author: sergei
Date: 2014-01-24 09:59:57 +0400 (Fri, 24 Jan 2014)
New Revision: 2086

Modified:
   trunk/tkabber-plugins/ChangeLog
   trunk/tkabber-plugins/otr/key.tcl
   trunk/tkabber-plugins/otr/otr.tcl
Log:
	* otr/key.tcl, otr/otr.tcl: Finish all existing OTR sessions for a
	  given connection if the associated private key is imported or
	  deleted.


Modified: trunk/tkabber-plugins/ChangeLog
===================================================================
--- trunk/tkabber-plugins/ChangeLog	2014-01-23 20:00:16 UTC (rev 2085)
+++ trunk/tkabber-plugins/ChangeLog	2014-01-24 05:59:57 UTC (rev 2086)
@@ -1,3 +1,9 @@
+2014-01-24  Sergei Golovan <sgolovan at nes.ru>
+
+	* otr/key.tcl, otr/otr.tcl: Finish all existing OTR sessions for a
+	  given connection if the associated private key is imported or
+	  deleted.
+
 2014-01-23  Sergei Golovan <sgolovan at nes.ru>
 
 	* otr/otr.tcl, otr/tclotr/message.tcl, otr/tclotr/otr.tcl: Code

Modified: trunk/tkabber-plugins/otr/key.tcl
===================================================================
--- trunk/tkabber-plugins/otr/key.tcl	2014-01-23 20:00:16 UTC (rev 2085)
+++ trunk/tkabber-plugins/otr/key.tcl	2014-01-24 05:59:57 UTC (rev 2086)
@@ -150,9 +150,9 @@
     # Start with the existing keys
     set jids [lsort [dict keys $Keys]]
     # Next, the existing connections
-    foreach connid [connections] {
+    foreach xlib [connections] {
 	lappend jids \
-	       [::xmpp::jid::normalize [::xmpp::jid::removeResource $connid]]
+	       [::xmpp::jid::normalize [::xmpp::jid::removeResource $xlib]]
     }
     # Next the existing profiles
     for {set i 1} {[info exists ::loginconf$i]} {incr i} {
@@ -280,9 +280,7 @@
 
     dict set Keys $keyjid $key
     store $Keys
-
-    # TODO: Drop all OTR sessions for the old key
-
+    [namespace parent]::clear_all_jid $keyjid
     fill_dialog $w
 }
 
@@ -308,8 +306,13 @@
 
     dict unset Keys $keyjid
     store $Keys
+    [namespace parent]::clear_all_jid $keyjid
+    fill_dialog $w
+}
 
-    # TODO: Drop all OTR sessions for this key
+proc key::gen_key {w} {
+    variable Keys
+    variable keyjid
 
-    fill_dialog $w
+    # TODO
 }

Modified: trunk/tkabber-plugins/otr/otr.tcl
===================================================================
--- trunk/tkabber-plugins/otr/otr.tcl	2014-01-23 20:00:16 UTC (rev 2085)
+++ trunk/tkabber-plugins/otr/otr.tcl	2014-01-24 05:59:57 UTC (rev 2086)
@@ -193,6 +193,35 @@
     return 1
 }
 
+proc otr::clear {xlib jid} {
+    variable ctx
+
+    if {[info exists ctx($xlib,$jid)]} {
+	finish_session $xlib $jid ""
+	::otr::free $ctx($xlib,$jid)
+	set jpattern [regsub -all {(.)} $jid {\\\1} ]
+	array unset ctx *,$xlib,$jpattern
+    }
+}
+
+proc otr::clear_all {xlib} {
+    variable ctx
+
+    foreach idx [array names ctx $xlib,*] {
+	regexp {[^,]*,(.*)} $idx -> jid
+	clear $xlib $jid
+    }
+}
+
+proc otr::clear_all_jid {myjid} {
+    foreach xlib [connections] {
+	if {[::xmpp::jid::equal $myjid \
+		[::xmpp::jid::removeResource [connection_jid $xlib]]]} {
+	    clear_all $xlib
+	}
+    }
+}
+
 #############################################################################
 
 proc otr::on_authstate_change {xlib jid authstate} {
@@ -232,11 +261,11 @@
 
     # Dirty hack to recover message type
     for {set i 1} {$i < 12} {incr i} {
-	upvar $i type type
+	if {[catch {upvar $i type type}]} break
 	if {[info exists type] && $type eq "chat"} break
     }
 
-    if {[info exists type]} {
+    if {[info exists type] && $type eq "chat"} {
 	set targs [list -type $type]
     } else {
 	set targs {}



More information about the Tkabber-dev mailing list