[Tkabber-dev] r763 - in trunk/tkabber: . examples/configs pixmaps/default pixmaps/default/tkabber

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Fri Oct 20 20:20:50 MSD 2006


Author: sergei
Date: 2006-10-20 20:20:44 +0400 (Fri, 20 Oct 2006)
New Revision: 763

Added:
   trunk/tkabber/pixmaps/default/tkabber/gpg-badencrypted.gif
Modified:
   trunk/tkabber/ChangeLog
   trunk/tkabber/chats.tcl
   trunk/tkabber/examples/configs/mtr-config.tcl
   trunk/tkabber/gpgme.tcl
   trunk/tkabber/pixmaps/default/icondef.xml
Log:
	* chats.tcl: Added new hook rewrite_message_hook. It is run before
	  process_message_hook and allows to change message variables.
	  Removed normalize_chatid_hook.

	* examples/configs/mtr-config.tcl: Use rewrite_message_hook instead
	  of normalize_chatid_hook.

	* pixmaps/default/icondef.xml,
	  pixmaps/default/tkabber/gpg-badencrypted.gif: Added image for
	  message which cannot be deciphered.

	* gpgme.tcl: Use rewrite_message_hook to decrypt message bodies.
	  Draw icon from gpg-badencrypted.gif when message cannot be
	  deciphered. Draw it even if no GPG support at all to make
	  messages more clear.


Modified: trunk/tkabber/ChangeLog
===================================================================
--- trunk/tkabber/ChangeLog	2006-10-15 17:05:13 UTC (rev 762)
+++ trunk/tkabber/ChangeLog	2006-10-20 16:20:44 UTC (rev 763)
@@ -1,3 +1,21 @@
+2006-10-20  Sergei Golovan  <sgolovan at nes.ru>
+
+	* chats.tcl: Added new hook rewrite_message_hook. It is run before
+	  process_message_hook and allows to change message variables.
+	  Removed normalize_chatid_hook.
+
+	* examples/configs/mtr-config.tcl: Use rewrite_message_hook instead
+	  of normalize_chatid_hook.
+
+	* pixmaps/default/icondef.xml,
+	  pixmaps/default/tkabber/gpg-badencrypted.gif: Added image for
+	  message which cannot be deciphered.
+
+	* gpgme.tcl: Use rewrite_message_hook to decrypt message bodies.
+	  Draw icon from gpg-badencrypted.gif when message cannot be
+	  deciphered. Draw it even if no GPG support at all to make
+	  messages more clear.
+
 2006-10-15  Sergei Golovan  <sgolovan at nes.ru>
 
 	* ifacetk/iface.tcl: Restored "Activate lists at startup" menu

Modified: trunk/tkabber/chats.tcl
===================================================================
--- trunk/tkabber/chats.tcl	2006-10-15 17:05:13 UTC (rev 762)
+++ trunk/tkabber/chats.tcl	2006-10-20 16:20:44 UTC (rev 763)
@@ -201,37 +201,31 @@
     return [lindex $chatid 1]
 }
 
-proc client:message {connid from id type is_subject subject body err thread priority x} {
-    debugmsg chat "MESSAGE: $connid; $from; $id $type; $is_subject; $subject; $body; $err;\
-$thread; $priority; $x"
+###############################################################################
 
-    if {![cequal [info commands ::ssj::encrypted:input] ""]} {
-	set xs {}
+proc client:message \
+     {connid from id type is_subject subject body err thread priority x} {
 
-	foreach xe $x {
-	    jlib::wrapper:splitxml $xe tag vars isempty chdata children
+    debugmsg chat "MESSAGE: $connid; $from; $id; $type; $is_subject;\
+		   $subject; $body; $err; $thread; $priority; $x"
 
-	    if {![cequal [jlib::wrapper:getattr $vars xmlns] \
-			 jabber:x:encrypted]} {
-		lappend xs $xe
-		continue
-	    } elseif {[cequal $chdata ""]} {
-# in case the sender didn't check the exit code from gpg...
-	    } elseif {[catch { ssj::encrypted:input $connid $from $chdata } body]} {
-		set body [format [::msgcat::mc ">>> Unable to decipher data: %s <<<"] $body]
-	    } else {
-		lappend xs $xe
-	    }
-	}
+    hook::run rewrite_message_hook connid from id type is_subject \
+				   subject body err thread priority x
 
-	set x $xs
-    }
+    debugmsg chat "REWRITTEN MESSAGE: $connid; $from; $id; $type; $is_subject;\
+		   $subject; $body; $err; $thread; $priority; $x"
 
-    chat::process_message \
-	$connid $from $id $type $is_subject $subject $body $err $thread $priority $x
+    hook::run process_message_hook $connid $from $id $type $is_subject \
+				   $subject $body $err $thread $priority $x
 }
 
-proc chat::process_message {connid from id type is_subject subject body err thread priority x} {
+###############################################################################
+
+proc chat::rewrite_message \
+     {vconnid vfrom vid vtype vis_subject vsubject \
+      vbody verr vthread vpriority vx} {
+    upvar 2 $vfrom from
+    upvar 2 $vtype type
     variable options
 
     if {$type == ""} {
@@ -239,20 +233,20 @@
     }
 
     set from [tolower_node_and_domain $from]
-
-    hook::run process_message_hook \
-	$connid $from $id $type $is_subject $subject $body $err $thread $priority $x
 }
 
-proc chat::process_message_fallback {connid from id type is_subject subject body err thread priority x} {
+hook::add rewrite_message_hook [namespace current]::chat::rewrite_message 99
+
+###############################################################################
+
+proc chat::process_message_fallback \
+     {connid from id type is_subject subject body err thread priority x} {
     global font
     variable opened
     variable chats
 
     set chatid [chatid $connid $from]
-    hook::run normalize_chat_id_hook chatid $type
 
-
     switch -- $type {
 	chat {
 	    if {$thread != ""} {
@@ -302,6 +296,7 @@
 hook::add process_message_hook \
     [namespace current]::chat::process_message_fallback 99
 
+###############################################################################
 
 proc chat::window_titles {chatid} {
     variable chats

Modified: trunk/tkabber/examples/configs/mtr-config.tcl
===================================================================
--- trunk/tkabber/examples/configs/mtr-config.tcl	2006-10-15 17:05:13 UTC (rev 762)
+++ trunk/tkabber/examples/configs/mtr-config.tcl	2006-10-20 16:20:44 UTC (rev 763)
@@ -370,20 +370,22 @@
         }
     }
 
-    proc normalize_chat_id {chatidvar type} {
-        upvar 2 $chatidvar chatid
+    proc normalize_chat_id \
+	 {vconnid vfrom vid vtype vis_subject vsubject vbody verr vthread vpriority vx} {
+        upvar 2 $vconnid connid
+        upvar 2 $vfrom from
+        upvar 2 $vtype type
 
-        if {[cequal [chat::get_nick [chat::get_connid $chatid] [set jid [chat::get_jid $chatid]] \
-                                    $type]/$type \
-                    jbot/chat]} {
-            set chatid [chat::chatid [chat::get_connid $chatid] \
-                            [node_and_server_from_jid $jid]/syslog]
+	if {![cequal $type chat]} return
+
+        if {[cequal [chat::get_nick $connid $from $type] jbot]} {
+            set from [node_and_server_from_jid $from]/syslog
         }
     }
 
-    hook::add open_chat_post_hook    [namespace current]::open_chat_post     1
-    hook::add draw_message_hook      [namespace current]::draw_message       1
-    hook::add normalize_chat_id_hook [namespace current]::normalize_chat_id  1
+    hook::add open_chat_post_hook  [namespace current]::open_chat_post     1
+    hook::add draw_message_hook    [namespace current]::draw_message       1
+    hook::add rewrite_message_hook [namespace current]::normalize_chat_id  1
 }
 
 

Modified: trunk/tkabber/gpgme.tcl
===================================================================
--- trunk/tkabber/gpgme.tcl	2006-10-15 17:05:13 UTC (rev 762)
+++ trunk/tkabber/gpgme.tcl	2006-10-20 16:20:44 UTC (rev 763)
@@ -1,5 +1,36 @@
 # $Id$
 
+namespace eval ::ssj {}
+
+#############################################################################
+# Draw icons aside encrypted messages even if no GPG support
+
+proc ::ssj::draw_encrypted {chatid from type body x} {
+    # we already deciphered it in rewrite_message_hook
+
+    set chatw [chat::chat_win $chatid]
+
+    foreach xe $x {
+	jlib::wrapper:splitxml $xe tag vars isempty cdata children
+
+	if {![cequal [jlib::wrapper:getattr $vars xmlns] $::NS(encrypted)]} {
+	    continue
+	}
+
+	if {[cequal $cdata ""] || \
+	    [cequal [info commands ::ssj::encrypted:input] ""]} {
+	    $chatw image create end -image gpg/badencrypted
+	} else {
+	    $chatw image create end -image gpg/encrypted
+	}
+	break
+    }
+}
+
+hook::add draw_message_hook ::ssj::draw_encrypted 7
+
+#############################################################################
+
 if {[catch { package require gpgme }]} {
     debugmsg ssj "unable to load the GPGME package, so no crypto!"
     set have_gpgme 0
@@ -574,6 +605,43 @@
     }
 }
 
+###############################################################################
+
+proc ::ssj::rewrite_message_body \
+     {vconnid vfrom vid vtype vis_subject vsubject vbody verr vthread vpriority vx} {
+    upvar 2 $vconnid connid
+    upvar 2 $vfrom from
+    upvar 2 $vbody body
+    upvar 2 $vx x
+
+    set xs {}
+
+    foreach xe $x {
+	jlib::wrapper:splitxml $xe tag vars isempty chdata children
+
+	if {![cequal [jlib::wrapper:getattr $vars xmlns] jabber:x:encrypted]} {
+	    lappend xs $xe
+	    continue
+	} elseif {[cequal $chdata ""]} {
+	    # in case the sender didn't check the exit code from gpg...
+	    lappend xs $xe
+	} elseif {[catch {ssj::encrypted:input $connid $from $chdata} msg]} {
+	    set body [format [::msgcat::mc ">>> Unable to decipher data: %s <<<"] $msg]
+	    # Add empty x tag to show problems with gpg...
+	    lappend xs [jlib::wrapper:createtag x -vars {xmlns jabber:x:encrypted}]
+	} else {
+	    set body $msg
+	    lappend xs $xe
+	}
+    }
+
+    set x $xs
+}
+
+hook::add rewrite_message_hook ::ssj::rewrite_message_body 10
+
+###############################################################################
+
 proc ::ssj::encrypted:input {connid from data} {
     variable ctx
     variable warnings
@@ -1225,27 +1293,6 @@
 
 #############################################################################
 
-proc ::ssj::draw_encrypted {chatid from type body x} {
-    # we already deciphered it in client:message...
-
-    set chatw [chat::chat_win $chatid]
-
-    foreach xe $x {
-	jlib::wrapper:splitxml $xe tag vars isempty chdata children
-
-	if {![cequal [jlib::wrapper:getattr $vars xmlns] $::NS(encrypted)]} {
-	    continue
-	}
-
-	$chatw image create end -image gpg/encrypted
-	break
-    }
-}
-
-hook::add draw_message_hook ::ssj::draw_encrypted 7
-
-#############################################################################
-
 proc ::ssj::draw_signed {chatid from type body x} {
     variable signedid
 

Modified: trunk/tkabber/pixmaps/default/icondef.xml
===================================================================
--- trunk/tkabber/pixmaps/default/icondef.xml	2006-10-15 17:05:13 UTC (rev 762)
+++ trunk/tkabber/pixmaps/default/icondef.xml	2006-10-20 16:20:44 UTC (rev 763)
@@ -63,6 +63,10 @@
     <image xmlns='tkimage'>gpg/encrypted</image>
     <object mime="image/gif">tkabber/gpg-encrypted.gif</object>
   </icon>
+  <icon>
+    <image xmlns='tkimage'>gpg/badencrypted</image>
+    <object mime="image/gif">tkabber/gpg-badencrypted.gif</object>
+  </icon>
   <!-- Browser and Disco icons -->
   <icon>
     <image xmlns='tkimage'>browser/client</image>

Added: trunk/tkabber/pixmaps/default/tkabber/gpg-badencrypted.gif
===================================================================
(Binary files differ)


Property changes on: trunk/tkabber/pixmaps/default/tkabber/gpg-badencrypted.gif
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream



More information about the Tkabber-dev mailing list