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

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Tue Jan 28 18:23:52 MSK 2014


Author: sergei
Date: 2014-01-28 18:23:52 +0400 (Tue, 28 Jan 2014)
New Revision: 2115

Modified:
   trunk/tkabber-plugins/ChangeLog
   trunk/tkabber-plugins/otr/auth.tcl
   trunk/tkabber-plugins/otr/key.tcl
   trunk/tkabber-plugins/otr/otr.tcl
Log:
	* otr/key.tcl, otr/otr.tcl: Drop existing OTR cnversations only if the
	  key is really is changed or deleted. Show an info message when this
	  happens.

	* otr/auth.tcl: Change OTR icons on all existing windows acorrding to
	  the authentication changes.

	* otr/otr.tcl: Added fingerprint and SSID to the roster and OTR button
	  help text. Do cleanup after the authentication dialog is closed.


Modified: trunk/tkabber-plugins/ChangeLog
===================================================================
--- trunk/tkabber-plugins/ChangeLog	2014-01-27 17:32:17 UTC (rev 2114)
+++ trunk/tkabber-plugins/ChangeLog	2014-01-28 14:23:52 UTC (rev 2115)
@@ -1,3 +1,15 @@
+2014-01-28  Sergei Golovan <sgolovan at nes.ru>
+
+	* otr/key.tcl, otr/otr.tcl: Drop existing OTR cnversations only if the
+	  key is really is changed or deleted. Show an info message when this
+	  happens.
+
+	* otr/auth.tcl: Change OTR icons on all existing windows acorrding to
+	  the authentication changes.
+
+	* otr/otr.tcl: Added fingerprint and SSID to the roster and OTR button
+	  help text. Do cleanup after the authentication dialog is closed.
+
 2014-01-27  Sergei Golovan <sgolovan at nes.ru>
 
 	* otr/otr.tcl: Fail to load OTR plugin if Tkabber doesn't support the

Modified: trunk/tkabber-plugins/otr/auth.tcl
===================================================================
--- trunk/tkabber-plugins/otr/auth.tcl	2014-01-27 17:32:17 UTC (rev 2114)
+++ trunk/tkabber-plugins/otr/auth.tcl	2014-01-28 14:23:52 UTC (rev 2115)
@@ -167,7 +167,7 @@
 
     $w add -text [::msgcat::mc "Apply"] \
 	   -state disabled \
-	   -command [namespace code [list apply_edit_auth_changes $w $f.myjid $f.items.listbox]]
+	   -command [namespace code [list apply_edit_auth_changes $w $f.items.listbox]]
     $w add -text [::msgcat::mc "Cancel"] \
 	   -command [list destroy $w]
 
@@ -349,12 +349,12 @@
     $w itemconfigure 0 -state normal
 }
 
-proc auth::apply_edit_auth_changes {w m l} {
+proc auth::apply_edit_auth_changes {w l} {
     variable Auth
+    variable authjid
 
     $w itemconfigure 0 -state disabled
 
-    set myjid [$m get]
     set data [$l get 0 end]
 
     set items [dict create]
@@ -371,9 +371,17 @@
 	dict set items [list [string range $jid 1 end-1] \
 			     [string range $fingerprint 1 end-1]] $auth1
     }
-    dict set Auth $myjid $items
+    dict set Auth $authjid $items
     store $Auth
-    # TODO: change the icons for all affected chats
+    foreach xlib [connections] {
+	if {![::xmpp::jid::equal \
+		    [::xmpp::jid::removeResource \
+			    [connection_jid $xlib]] $authjid]} continue
+	foreach idx [array names ::otr::ctx msgstate,$xlib,*] {
+	    regexp {msgstate,[^,]*,(.*)} $idx -> fjid
+	    on_msgstate_change $xlib $fjid $::otr::ctx($idx)
+	}
+    }
     fill_mclistbox $w $l
 }
 

Modified: trunk/tkabber-plugins/otr/key.tcl
===================================================================
--- trunk/tkabber-plugins/otr/key.tcl	2014-01-27 17:32:17 UTC (rev 2114)
+++ trunk/tkabber-plugins/otr/key.tcl	2014-01-28 14:23:52 UTC (rev 2115)
@@ -323,9 +323,11 @@
 	return
     }
 
-    dict set Keys $keyjid $key
-    store $Keys
-    [namespace parent]::clear_all_jid $keyjid
+    if {![dict exists $Keys $keyjid] || [dict get $Keys $keyjid] ne $key} {
+	dict set Keys $keyjid $key
+	store $Keys
+	[namespace parent]::clear_all_jid $keyjid
+    }
     fill_dialog $w
     return
 }
@@ -384,9 +386,11 @@
     variable Keys
     variable keyjid
 
-    dict unset Keys $keyjid
-    store $Keys
-    [namespace parent]::clear_all_jid $keyjid
+    if {[dict exists $Keys $keyjid]} {
+	dict unset Keys $keyjid
+	store $Keys
+	[namespace parent]::clear_all_jid $keyjid
+    }
     fill_dialog $w
     return
 }
@@ -467,9 +471,12 @@
     incr progress
     update
     set progress -1
-    dict set Keys $keyjid [list $p $q $g $y $x]
-    store $Keys
-    [namespace parent]::clear_all_jid $keyjid
+    set newkey [list $p $q $g $y $x]
+    if {![dict exists $Keys $keyjid] || [dict get $Keys $keyjid] ne $newkey} {
+	dict set Keys $keyjid $newkey
+	store $Keys
+	[namespace parent]::clear_all_jid $keyjid
+    }
     fill_dialog $w
     $w itemconfigure 0 -state normal
     $f.jid configure -state normal

Modified: trunk/tkabber-plugins/otr/otr.tcl
===================================================================
--- trunk/tkabber-plugins/otr/otr.tcl	2014-01-27 17:32:17 UTC (rev 2114)
+++ trunk/tkabber-plugins/otr/otr.tcl	2014-01-28 14:23:52 UTC (rev 2115)
@@ -202,6 +202,9 @@
 	return 0
     }
 
+    set ctx(msgstate,$xlib,$jid) MSGSTATE_PLAINTEXT
+    msgstate:trace {} $xlib $jid
+
     set ctx($xlib,$jid) \
 	[::otr::new $privkey \
 		-policy [get_policy $xlib $jid] \
@@ -224,6 +227,26 @@
 	::otr::free $ctx($xlib,$jid)
 	set jpattern [regsub -all {(.)} $jid {\\\1} ]
 	array unset ctx *,$xlib,$jpattern
+	unset ctx($xlib,$jid)
+
+	set chatid [chat::chatid $xlib $jid]
+	set chatw [chat::chat_win $chatid]
+	if {![winfo exists $chatw]} return
+
+	if {[key::get_key $key::Keys \
+		[::xmpp::jid::removeResource [connection_jid $xlib]]] eq ""} {
+	    chat::add_message $chatid $jid info \
+		      "[::msgcat::mc {OTR Info:}]\
+		       [::msgcat::mc {OTR is disabled because you have deleted your\
+				      OTR key. Generate or import a new one if you\
+				      want to enable it again.}]" {}
+	} else {
+	    chat::add_message $chatid $jid info \
+		      "[::msgcat::mc {OTR Info:}]\
+		       [::msgcat::mc {OTR conversation is lost because you have\
+				      changed your OTR key. The next private chat\
+				      will use the new key.}]" {}
+	}
     }
 }
 
@@ -491,6 +514,9 @@
     $w add -text [::msgcat::mc "Cancel"] \
 	   -command [list destroy $w]
 
+    bind $w <Destroy> [list unset -nocomplain [namespace current]::ctx(status,$xlib,$jid)]
+    bind $w <Destroy> +[list unset -nocomplain [namespace current]::ctx(progress,$xlib,$jid)]
+
     set f [$w getframe]
 
     set m [message $f.header -text [::msgcat::mc "Authenticate %s\n\nAuthenticating\
@@ -672,8 +698,12 @@
 	    set tjid [peer_jid $xlib $jid]
 	    auth::set_auth auth::Auth $myjid $tjid $fingerprint $val
 	    auth::store $auth::Auth
-	    # TODO: change the icons for all chats with this jid
-	    on_msgstate_change $xlib $jid $ctx(msgstate,$xlib,$jid)
+	    foreach idx [array names ctx msgstate,$xlib,*] {
+		regexp {msgstate,[^,]*,(.*)} $idx -> fjid
+		if {[peer_jid $fjid] eq $tjid} {
+		    on_msgstate_change $xlib $fjid $ctx($idx)
+		}
+	    }
 	    destroy $w
 	    return
 	}
@@ -699,6 +729,9 @@
     $w add -text [::msgcat::mc "Cancel"] \
 	   -command [list destroy $w]
 
+    bind $w <Destroy> [list unset -nocomplain [namespace current]::ctx(status,$xlib,$jid)]
+    bind $w <Destroy> +[list unset -nocomplain [namespace current]::ctx(progress,$xlib,$jid)]
+
     set f [$w getframe]
 
     set m [message $f.header -text [::msgcat::mc "Authenticate %s\n\nAuthenticating\
@@ -752,6 +785,9 @@
     $w add -text [::msgcat::mc "Cancel"] \
 	   -command [list destroy $w]
 
+    bind $w <Destroy> [list unset -nocomplain [namespace current]::ctx(status,$xlib,$jid)]
+    bind $w <Destroy> +[list unset -nocomplain [namespace current]::ctx(progress,$xlib,$jid)]
+
     set f [$w getframe]
 
     set m [message $f.header -text [::msgcat::mc "Authenticate %s\n\nAuthenticating\
@@ -826,7 +862,6 @@
 proc otr::result_smp {w xlib jid} {
     variable ctx
 
-    # TODO: delete status and progress vars
     $w itemconfigure 0 -state normal -text [::msgcat::mc "OK"] -command [list destroy $w]
     $w itemconfigure 1 -state disabled -command [list destroy $w]
 }
@@ -838,7 +873,6 @@
 
     set w $ctx(smpdialog,$xlib,$jid)
 
-    # TODO: Call out after the finish
     switch -- $progress {
 	SMP_PROGRESS {
 	    incr ctx(progress,$xlib,$jid)
@@ -863,8 +897,12 @@
 	    set tjid [peer_jid $xlib $jid]
 	    auth::set_auth auth::Auth $myjid $tjid $fingerprint 1
 	    auth::store $auth::Auth
-	    # TODO: change the icons for all chats with this jid
-	    on_msgstate_change $xlib $jid $ctx(msgstate,$xlib,$jid)
+	    foreach idx [array names ctx msgstate,$xlib,*] {
+		regexp {msgstate,[^,]*,(.*)} $idx -> fjid
+		if {[peer_jid $fjid] eq $tjid} {
+		    on_msgstate_change $xlib $fjid $ctx($idx)
+		}
+	    }
 	}
 	SMP_FAILURE {
 	    set ctx(progress,$xlib,$jid) 3
@@ -876,8 +914,12 @@
 	    set tjid [peer_jid $xlib $jid]
 	    auth::set_auth auth::Auth $myjid $tjid $fingerprint 0
 	    auth::store $auth::Auth
-	    # TODO: change the icons for all chats with this jid
-	    on_msgstate_change $xlib $jid $ctx(msgstate,$xlib,$jid)
+	    foreach idx [array names ctx msgstate,$xlib,*] {
+		regexp {msgstate,[^,]*,(.*)} $idx -> fjid
+		if {[peer_jid $fjid] eq $tjid} {
+		    on_msgstate_change $xlib $fjid $ctx($idx)
+		}
+	    }
 	}
     }
 }
@@ -1070,9 +1112,12 @@
 
     if {![info exists trace(msgstate,$xlib,$jid)]} {
         set trace(msgstate,$xlib,$jid) {}
+    }
 
-        ::trace variable [namespace current]::ctx(msgstate,$xlib,$jid) w \
-			 [namespace current]::trace
+    if {[list write [namespace current]::trace] ni
+	    [::trace info variable [namespace current]::ctx(msgstate,$xlib,$jid)]} {
+        ::trace add variable [namespace current]::ctx(msgstate,$xlib,$jid) write \
+			     [namespace current]::trace
     }
 
     lappend trace(msgstate,$xlib,$jid) $script
@@ -1104,8 +1149,7 @@
 		 -height 24 \
 		 -width 24 \
 		 -relief link \
-		 -bd $::tk_borderwidth \
-		 -command [list # $xlib $jid]]
+		 -bd $::tk_borderwidth
     msgstate:trace \
 	"$b configure -image \[[namespace current]::msgstate:icon [list $xlib] [list $jid]\] \
 		      -helptext \[[namespace current]::msgstate:helptext [list $xlib] [list $jid]\]" \
@@ -1131,8 +1175,7 @@
 	   -relief flat \
            -image [msgstate:icon $xlib $jid] \
            -helptype balloon \
-           -helptext [msgstate:helptext $xlib $jid] \
-           -command [list # $xlib $jid]
+           -helptext [msgstate:helptext $xlib $jid]
 
     msgstate:trace "$cw.status.otrmsgstate configure \
 		-image \[[namespace current]::msgstate:icon [list $xlib] [list $jid]\] \
@@ -1154,6 +1197,22 @@
 }
 
 proc otr::msgstate:helptext {xlib jid} {
+    variable ctx
+
+    set text [::msgcat::mc "State:"]
+    append text " " [msgstate:state $xlib $jid]
+    switch -- [msgstate:index $xlib $jid] {
+	1 - 2 {
+	    append text \n [::msgcat::mc "Fingerprint:"] " " \
+			[::otr::fingerprint $ctx($xlib,$jid)] \
+			\n [::msgcat::mc "SSID:"] " " \
+			[::otr::ssid $ctx($xlib,$jid)]
+	}
+    }
+    set text
+}
+
+proc otr::msgstate:state {xlib jid} {
     lindex [list [::msgcat::mc "Not private"] \
 		 [::msgcat::mc "Unverified"] \
 		 [::msgcat::mc "Private"] \
@@ -1164,7 +1223,7 @@
 proc otr::msgstate:index {xlib jid} {
     variable ctx
 
-    if {[info exists ctx(msgstate,$xlib,$jid)]} {
+    if {[info exists ctx($xlib,$jid)]} {
 	switch -- $ctx(msgstate,$xlib,$jid) {
 	    MSGSTATE_PLAINTEXT {
 		return 0
@@ -1194,16 +1253,13 @@
 
     upvar 0 $infovar info
 
-    if {[info exists ctx(authstate,$xlib,$jid)]} {
+    if {[info exists ctx($xlib,$jid)]} {
 	append info [::msgcat::mc "\n\tOTR:"]
-	# TODO: nice report
-	append info "\n\t    Authstate: $ctx(authstate,$xlib,$jid)"
-	append info "\n\t    Msgstate: $ctx(msgstate,$xlib,$jid)"
-	append info "\n\t    SMPstate: $ctx(smpstate,$xlib,$jid)"
+	append info [regsub -all {\n} \n[msgstate:helptext $xlib $jid] "\n\t    "]
     }
 }
 
-#hook::add roster_user_popup_info_hook [namespace current]::otr::user_popup_info 99
+hook::add roster_user_popup_info_hook [namespace current]::otr::user_popup_info 99
 
 #############################################################################
 
@@ -1232,9 +1288,8 @@
 	    regexp {authstate,[^,]*,(.*)} $j -> fjid
 	    set x [userinfo::pack_frame $otrinfo.otr_$i $fjid]
 
-	    # TODO: nice report
 	    userinfo::pack_entry $jid $x 1 otr_state_$i [::msgcat::mc "State:"]
-	    set userinfo::userinfo(otr_state_$i,$jid) [msgstate:helptext $xlib $fjid]
+	    set userinfo::userinfo(otr_state_$i,$jid) [msgstate:state $xlib $fjid]
 
 	    userinfo::pack_entry $jid $x 3 otr_fingerprint_$i [::msgcat::mc "Fingerprint:"]
 	    set userinfo::userinfo(otr_fingerprint_$i,$jid) [::otr::fingerprint $ctx($xlib,$fjid)]



More information about the Tkabber-dev mailing list