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

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Wed Feb 19 23:21:59 MSK 2014


Author: sergei
Date: 2014-02-19 23:21:59 +0400 (Wed, 19 Feb 2014)
New Revision: 2147

Modified:
   trunk/tkabber-plugins/ChangeLog
   trunk/tkabber-plugins/debug/debug.tcl
   trunk/tkabber-plugins/otr/tclotr/smp.tcl
Log:
	* otr/tclotr/smp.tcl: Added a debug print procedure instead of plain
	  puts calls.

	* debug/debug.tcl: Use ::otr::smp::Debug for printing OTR
	  authentication debug info.


Modified: trunk/tkabber-plugins/ChangeLog
===================================================================
--- trunk/tkabber-plugins/ChangeLog	2014-02-15 06:39:29 UTC (rev 2146)
+++ trunk/tkabber-plugins/ChangeLog	2014-02-19 19:21:59 UTC (rev 2147)
@@ -1,3 +1,11 @@
+2014-02-19  Sergei Golovan <sgolovan at nes.ru>
+
+	* otr/tclotr/smp.tcl: Added a debug print procedure instead of plain
+	  puts calls.
+
+	* debug/debug.tcl: Use ::otr::smp::Debug for printing OTR
+	  authentication debug info.
+
 2014-02-15  Sergei Golovan <sgolovan at nes.ru>
 
 	* otr/README: Fixed the requirements list.

Modified: trunk/tkabber-plugins/debug/debug.tcl
===================================================================
--- trunk/tkabber-plugins/debug/debug.tcl	2014-02-15 06:39:29 UTC (rev 2146)
+++ trunk/tkabber-plugins/debug/debug.tcl	2014-02-19 19:21:59 UTC (rev 2147)
@@ -120,6 +120,12 @@
 	}
     }
 
+    if {[llength [info procs ::otr::smp::Debug:debug]] == 0} {
+	    rename ::otr::smp::Debug ::otr::smp::Debug:debug
+	    proc ::otr::smp::Debug {level str} \
+		 "[namespace current]::debugmsg otr \$str"
+	}
+
     hook::add finload_hook [namespace current]::setup_menu
 
     if {![catch {.mainframe getmenu plugins}]} {
@@ -157,6 +163,11 @@
 	}
     }
 
+    if {[llength [info procs ::otr::smp::Debug:debug]] > 0} {
+	rename ::otr::smp::Debug ""
+	rename ::otr::smp::Debug:debug ::otr::smp::Debug
+    }
+
     if {[llength [info procs ::debugmsg:debug]] > 0} {
 	rename ::debugmsg ""
 	rename ::debugmsg:debug ::debugmsg

Modified: trunk/tkabber-plugins/otr/tclotr/smp.tcl
===================================================================
--- trunk/tkabber-plugins/otr/tclotr/smp.tcl	2014-02-15 06:39:29 UTC (rev 2146)
+++ trunk/tkabber-plugins/otr/tclotr/smp.tcl	2014-02-19 19:21:59 UTC (rev 2147)
@@ -22,6 +22,7 @@
 namespace eval ::otr::smp {
     variable q [expr {($::otr::crypto::Prime-1)/2}]
     variable g1 $::otr::crypto::G
+    variable debug 0
 }
 
 # ::otr::smp::createSMPMessage1 --
@@ -127,26 +128,26 @@
             set r6 [::otr::crypto::random 128]
 
             if {[catch {ParsePayload $data} res]} {
-                puts "Parse of SMP message 1 failed"
+                Debug 1 "Parse of SMP message 1 failed"
                 return [list $smpstate 6 ""]
             }
 
             lassign $res g2a c2 D2 g3a c3 D3
 
             if {![Check $g2a] || ![Check $g3a]} {
-                puts "Check 1 of SMP message 1 failed"
+                Debug 1 "Check 1 of SMP message 1 failed"
                 return [list $smpstate 6 ""]
             }
 
             set myc2 [Hash 1 [Mult [Exp $g1 $D2] [Exp $g2a $c2]]]
             if {$myc2 != $c2} {
-                puts "Check 2 of SMP message 1 failed"
+                Debug 1 "Check 2 of SMP message 1 failed"
                 return [list $smpstate 6 ""]
             }
 
             set myc3 [Hash 2 [Mult [Exp $g1 $D3] [Exp $g3a $c3]]]
             if {$myc3 != $c3} {
-                puts "Check 3 of SMP message 1 failed"
+                Debug 1 "Check 3 of SMP message 1 failed"
                 return [list $smpstate 6 ""]
             }
 
@@ -209,7 +210,7 @@
             set r7 [::otr::crypto::random 128]
 
             if {[catch {ParsePayload $data} res]} {
-                puts "Parse of SMP message 2 failed"
+                Debug 1 "Parse of SMP message 2 failed"
                 return [list $smpstate 6 ""]
             }
 
@@ -217,19 +218,19 @@
 
             if {![Check $g2b] || ![Check $g3b] ||
                     ![Check $Pb] || ![Check $Qb]} {
-                puts "Check 1 of SMP message 2 failed"
+                Debug 1 "Check 1 of SMP message 2 failed"
                 return [list $smpstate 6 ""]
             }
 
             set myc2 [Hash 3 [Mult [Exp $g1 $D2] [Exp $g2b $c2]]]
             if {$myc2 != $c2} {
-                puts "Check 2 of SMP message 2 failed"
+                Debug 1 "Check 2 of SMP message 2 failed"
                 return [list $smpstate 6 ""]
             }
 
             set myc3 [Hash 4 [Mult [Exp $g1 $D3] [Exp $g3b $c3]]]
             if {$myc3 != $c3} {
-                puts "Check 3 of SMP message 2 failed"
+                Debug 1 "Check 3 of SMP message 2 failed"
                 return [list $smpstate 6 ""]
             }
 
@@ -239,7 +240,7 @@
                              [Mult [Exp $g1 $D5] \
                                    [Mult [Exp $g2 $D6] [Exp $Qb $cP]]]]
             if {$mycP != $cP} {
-                puts "Check 4 of SMP message 2 failed"
+                Debug 1 "Check 4 of SMP message 2 failed"
                 return [list $smpstate 6 ""]
             }
 
@@ -293,7 +294,7 @@
             set r7 [::otr::crypto::random 128]
 
             if {[catch {ParsePayload $data} res]} {
-                puts "Parse of SMP message 3 failed"
+                Debug 1 "Parse of SMP message 3 failed"
                 return [list $smpstate 6 ""]
             }
 
@@ -302,7 +303,7 @@
             set QaQb [Mult $Qa [Inv $Qb]]
 
             if {![Check $Pa] || ![Check $Qa] || ![Check $Ra]} {
-                puts "Check 1 of SMP message 3 failed"
+                Debug 1 "Check 1 of SMP message 3 failed"
                 return [list $smpstate 6 ""]
             }
 
@@ -310,14 +311,14 @@
                              [Mult [Exp $g1 $D5] \
                                    [Mult [Exp $g2 $D6] [Exp $Qa $cP]]]]
             if {$mycP != $cP} {
-                puts "Check 2 of SMP message 3 failed"
+                Debug 1 "Check 2 of SMP message 3 failed"
                 return [list $smpstate 6 ""]
             }
 
             set mycR [Hash 7 [Mult [Exp $g1 $D7] [Exp $g3a $cR]] \
                              [Mult [Exp $QaQb $D7] [Exp $Ra $cR]]]
             if {$mycR != $cR} {
-                puts "Check 3 of SMP message 3 failed"
+                Debug 1 "Check 3 of SMP message 3 failed"
                 return [list $smpstate 6 ""]
             }
 
@@ -329,7 +330,7 @@
             set Rab [Exp $Ra $b3]
             set res [expr {$PaPb == $Rab}]
 
-            puts "$smpstate $res"
+            Debug 1 "$smpstate $res"
 
             return [list SMPSTATE_EXPECT1 5 \
                          [Payload $Rb $cR $D7] \
@@ -368,28 +369,28 @@
     switch -- $smpstate {
         SMPSTATE_EXPECT4 {
             if {[catch {ParsePayload $data} res]} {
-                puts "Parse of SMP message 4 failed"
+                Debug 1 "Parse of SMP message 4 failed"
                 return [list $smpstate 6 ""]
             }
 
             lassign $res Rb cR D7
 
             if {![Check $Rb]} {
-                puts "Check 1 of SMP message 4 failed"
+                Debug 1 "Check 1 of SMP message 4 failed"
                 return [list $smpstate 6 ""]
             }
 
             set mycR [Hash 8 [Mult [Exp $g1 $D7] [Exp $g3b $cR]] \
                              [Mult [Exp $QaQb $D7] [Exp $Rb $cR]]]
             if {$mycR != $cR} {
-                puts "Check 2 of SMP message 3 failed"
+                Debug 1 "Check 2 of SMP message 3 failed"
                 return [list $smpstate 6 ""]
             }
 
             set Rab [Exp $Rb $a3]
             set res [expr {$PaPb == $Rab}]
 
-            puts "$smpstate $res"
+            Debug 1 "$smpstate $res"
 
             return [list SMPSTATE_EXPECT1 0 "" $res]
         }
@@ -568,4 +569,30 @@
     ::otr::crypto::Bits2Int [::sha2::sha256 -bin $res]
 }
 
+# ::otr::smp::Debug --
+#
+#       Prints debug information.
+#
+# Arguments:
+#       level   Debug level.
+#       str     Debug message.
+#
+# Result:
+#       An empty string.
+#
+# Side effects:
+#       A debug message is printed to the console if the value of
+#       ::otr::smp::debug variable is not less than num.
+
+proc ::otr::smp::Debug {level str} {
+    variable debug
+
+    if {$debug >= $level} {
+        puts "[clock format [clock seconds] -format %T]\
+              [lindex [info level -1] 0] $str"
+    }
+
+    return
+}
+
 # vim:ts=8:sw=4:sts=4:et



More information about the Tkabber-dev mailing list