[Tkabber-dev] r1770 - in trunk/tkabber-plugins: . jidlink jidlink/plugins

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Tue Mar 31 19:22:21 MSD 2009


Author: sergei
Date: 2009-03-31 19:22:21 +0400 (Tue, 31 Mar 2009)
New Revision: 1770

Modified:
   trunk/tkabber-plugins/ChangeLog
   trunk/tkabber-plugins/jidlink/jidlink.tcl
   trunk/tkabber-plugins/jidlink/plugins/dtcp.tcl
   trunk/tkabber-plugins/jidlink/plugins/filetransfer.tcl
   trunk/tkabber-plugins/jidlink/plugins/ibb.tcl
Log:
	* jidlink/jidlink.tcl, jidlink/plugins/*: Made Jidlink plugin
	  unloadable.


Modified: trunk/tkabber-plugins/ChangeLog
===================================================================
--- trunk/tkabber-plugins/ChangeLog	2009-03-31 15:20:53 UTC (rev 1769)
+++ trunk/tkabber-plugins/ChangeLog	2009-03-31 15:22:21 UTC (rev 1770)
@@ -1,3 +1,8 @@
+2009-03-31  Sergei Golovan <sgolovan at nes.ru>
+
+	* jidlink/jidlink.tcl, jidlink/plugins/*: Made Jidlink plugin
+	  unloadable.
+
 2009-03-29  Sergei Golovan <sgolovan at nes.ru>
 
 	* georoster/georoster.tcl, tclchat/tclchat.tcl: Restored calls to

Modified: trunk/tkabber-plugins/jidlink/jidlink.tcl
===================================================================
--- trunk/tkabber-plugins/jidlink/jidlink.tcl	2009-03-31 15:20:53 UTC (rev 1769)
+++ trunk/tkabber-plugins/jidlink/jidlink.tcl	2009-03-31 15:22:21 UTC (rev 1770)
@@ -1,15 +1,51 @@
 # $Id$
 
 package require msgcat
-package require xmpp::negotiate
 
 namespace eval ::jidlink {
-
     ::msgcat::mcload [file join [file dirname [info script]] msgs]
 
+    if {![::plugins::is_registered jidlink]} {
+	::plugins::register jidlink \
+			    -namespace [namespace current] \
+			    -source [info script] \
+			    -description [::msgcat::mc "Whether the Jidlink plugin is loaded."] \
+			    -loadcommand [namespace code [list load [file dirname [info script]]]] \
+			    -unloadcommand [namespace code unload]
+	return
+    }
+
     set transport(list) {}
 }
 
+proc ::jidlink::load {dir} {
+    ::xmpp::negotiate::register jabber:iq:jidlink ::jidlink::negotiate_handler
+    ::xmpp::iq::register set query jabber:iq:jidlink ::jidlink::set_handler
+
+    # Loading jidlink plugins
+    foreach file [lsort [glob -nocomplain [file join $dir plugins]/*.tcl]] {
+	debugmsg jidlink "Loading plugin from $file"
+	source $file
+    }
+
+    foreach ns [namespace children] {
+	${ns}::load
+    }
+
+    setup_customize
+}
+
+proc ::jidlink::unload {} {
+    foreach ns [namespace children] {
+	${ns}::unload
+    }
+
+    ::xmpp::negotiate::unregister jabber:iq:jidlink
+    ::xmpp::iq::unregister set query jabber:iq:jidlink
+}
+
+package require xmpp::negotiate
+
 proc ::jidlink::connect {xlib jid {key {}}} {
     variable connection
 
@@ -171,8 +207,6 @@
     return {}
 }
 
-::xmpp::negotiate::register jabber:iq:jidlink ::jidlink::negotiate_handler
-
 proc ::jidlink::set_handler {xlib from xml args} {
     debugmsg jidlink "set: [list $from $xml]"
 
@@ -198,10 +232,7 @@
     }
 }
 
-::xmpp::iq::register set query jabber:iq:jidlink ::jidlink::set_handler
-
-
-proc ::jidlink::register_transport {name oppos prio connect send close} {
+proc ::jidlink::register_transport {name oppos prio default connect send close} {
     variable transport
 
     lappend transport(list) [list $name $prio]
@@ -209,28 +240,22 @@
     set transport(connect,$name) $connect
     set transport(send,$name) $send
     set transport(close,$name) $close
+    if {$default == "enabled"} {
+	set transport(default,$name) 1
+    } else {
+	set transport(default,$name) 0
+    }
 }
 
-# Loading jidlink plugins
-foreach file [lsort [glob -nocomplain \
-		    [file join [file dirname [info script]] plugins]/*.tcl]] {
-    debugmsg jidlink "Loading plugin from $file"
-    source $file
-}
-
 proc ::jidlink::setup_customize {} {
     variable transport
 
-    set trans [lsort -unique -index 1 $transport(list)]
-
-    foreach t $trans {
+    foreach t [lsort -unique -index 1 $transport(list)] {
 	lassign $t name prio
 
-	custom::defvar transport(allowed,$name) 1 \
-	[::msgcat::mc "Enable Jidlink transport %s." $name] \
-	-type boolean -group Jidlink
+	custom::defvar transport(allowed,$name) $transport(default,$name) \
+	    [::msgcat::mc "Enable Jidlink transport %s." $name] \
+	    -type boolean -group Jidlink
     }
 }
 
-hook::add finload_hook ::jidlink::setup_customize 40
-

Modified: trunk/tkabber-plugins/jidlink/plugins/dtcp.tcl
===================================================================
--- trunk/tkabber-plugins/jidlink/plugins/dtcp.tcl	2009-03-31 15:20:53 UTC (rev 1769)
+++ trunk/tkabber-plugins/jidlink/plugins/dtcp.tcl	2009-03-31 15:22:21 UTC (rev 1770)
@@ -1,10 +1,34 @@
 # $Id$
 
-namespace eval ::dtcp {}
-namespace eval ::dtcp::active {}
-namespace eval ::dtcp::passive {}
+namespace eval dtcp {}
+namespace eval dtcp::active {}
+namespace eval dtcp::passive {}
 
-proc ::dtcp::active::connect {xlib jid key} {
+proc dtcp::load {} {
+    jidlink::register_transport dtcp-active dtcp-passive 25 disabled \
+		[namespace current]::active::connect \
+		[namespace current]::active::send_data \
+		[namespace current]::active::close
+
+    ::xmpp::iq::register set query jabber:iq:dtcp [namespace current]::iq_set_handler
+
+    jidlink::register_transport dtcp-passive dtcp-active 50 disabled \
+		[namespace current]::passive::connect \
+		[namespace current]::passive::send_data \
+		[namespace current]::passive::close
+}
+
+proc dtcp::unload {} {
+    #jidlink::unregister_transport dtcp-active
+
+    ::xmpp::iq::unregister set query jabber:iq:dtcp
+
+    #jidlink::unregister_transport dtcp-passive
+
+    namespace delete [namespace current]
+}
+
+proc dtcp::active::connect {xlib jid key} {
     variable connection
 
     set_status [::msgcat::mc "Opening DTCP active connection"]
@@ -18,12 +42,12 @@
 					    -subelement [::xmpp::xml::create key \
 								-cdata $key]]] \
 	-to $jid \
-	-command [list ::dtcp::active::recv_connect_response $xlib $jid $key]
+	-command [list [namespace current]::recv_connect_response $xlib $jid $key]
 
     vwait [namespace current]::connection(status,$key)
 }
 
-proc ::dtcp::active::recv_connect_response {xlib jid key status xml} {
+proc dtcp::active::recv_connect_response {xlib jid key status xml} {
     variable connection
 
     if {$status != "ok"} {
@@ -63,7 +87,8 @@
 	    foreach host $hosts {
 		lassign $host addr port
 		debugmsg jidlink "CONNECTING TO $addr:$port..."
-		if {[catch {set sock [socket $addr $port]}]} continue
+		if {[catch {set sock [::pconnect::socket $addr $port \
+					    -proxyfilter ::proxy::proxyfilter]}]} continue
 		debugmsg jidlink "CONNECTED"
 		fconfigure $sock -encoding binary
 		set connection(sock,$key) $sock
@@ -71,7 +96,7 @@
 		flush $sock
 
 		fileevent $sock readable \
-		    [list ::dtcp::active::wait_for_verify $key $sock]
+		    [list [namespace current]::wait_for_verify $key $sock]
 		return
 	    }
 
@@ -88,7 +113,7 @@
     set connection(status,$key) 0
 }
 
-proc ::dtcp::active::sock_connect {key hosts} {
+proc dtcp::active::sock_connect {key hosts} {
     variable connection
     variable verify_key
     variable key_verify
@@ -97,7 +122,8 @@
     foreach host $hosts {
 	lassign $host addr port
 	debugmsg jidlink "CONNECTING TO $addr:$port..."
-	if {[catch {set sock [socket $addr $port]}]} continue
+	if {[catch {set sock [::pconnect::socket $addr $port \
+				    -proxyfilter ::proxy::proxyfilter]}]} continue
 	debugmsg jidlink "CONNECTED"
 	fconfigure $sock -encoding binary
 	set connection(sock,$key) $sock
@@ -105,7 +131,7 @@
 	flush $sock
 
 	fileevent $sock readable \
-	    [list ::dtcp::active::wait_for_verify $key $sock]
+	    [list [namespace current]::wait_for_verify $key $sock]
 	return
     }
 
@@ -115,7 +141,7 @@
 
 }
 
-proc ::dtcp::active::send_data {key data} {
+proc dtcp::active::send_data {key data} {
     variable connection
     variable key_stream
 
@@ -125,7 +151,7 @@
     return 1
 }
 
-proc ::dtcp::active::close {key} {
+proc dtcp::active::close {key} {
     variable connection
     variable key_stream
 
@@ -133,7 +159,7 @@
 }
 
 
-proc ::dtcp::active::wait_for_verify {key chan} {
+proc dtcp::active::wait_for_verify {key chan} {
     variable connection
     variable key_verify
 
@@ -145,7 +171,7 @@
 	if {$verify == $key_verify($key)} {
 	    fconfigure $chan -translation binary -blocking no
 	    fileevent $chan readable \
-		[list ::dtcp::readable $key $chan]
+		[list [namespace parent]::readable $key $chan]
 	    set connection(status,$key) 1
 	    return
 	}
@@ -154,15 +180,12 @@
     jidlink::closed $key
 }
 
-jidlink::register_transport dtcp-active dtcp-passive 25 \
-    ::dtcp::active::connect ::dtcp::active::send_data ::dtcp::active::close
-
-proc ::dtcp::passive::connect {xlib jid key} {
+proc dtcp::passive::connect {xlib jid key} {
     variable connection
 
     set_status [::msgcat::mc "Opening DTCP passive connection"]
 
-    set servsock [socket -server [list ::dtcp::passive::accept $key] 0]
+    set servsock [socket -server [list [namespace current]::accept $key] 0]
     lassign [fconfigure $servsock -sockname] addr hostname port
     set ip [::xmpp::ip $xlib]
 
@@ -178,12 +201,12 @@
 					    -subelement [::xmpp::xml::create key \
 							    -cdata $key]]] \
 	-to $jid \
-	-command [list ::dtcp::passive::recv_connect_response $xlib $jid $key]
+	-command [list [namespace current]::recv_connect_response $xlib $jid $key]
 
     vwait [namespace current]::connection(status,$key)
 }
 
-proc ::dtcp::passive::recv_connect_response {xlib jid key status xml} {
+proc dtcp::passive::recv_connect_response {xlib jid key status xml} {
     variable connection
 
     if {$status != "ok"} {
@@ -231,7 +254,7 @@
     set connection(status,$key) 0
 }
 
-proc ::dtcp::passive::send_data {key data} {
+proc dtcp::passive::send_data {key data} {
     variable connection
     variable key_stream
 
@@ -241,14 +264,14 @@
     return 1
 }
 
-proc ::dtcp::passive::close {key} {
+proc dtcp::passive::close {key} {
     variable connection
     variable key_stream
 
     ::close $connection(sock,$key)
 }
 
-proc ::dtcp::passive::accept {key chan addr port} {
+proc dtcp::passive::accept {key chan addr port} {
     variable connection
     variable key_verify
 
@@ -257,10 +280,10 @@
     set connection(sock,$key) $chan
 
     fileevent $chan readable \
-	[list ::dtcp::passive::wait_for_key $key $chan]
+	[list [namespace current]::wait_for_key $key $chan]
 }
 
-proc ::dtcp::passive::wait_for_key {key chan} {
+proc dtcp::passive::wait_for_key {key chan} {
     variable connection
     variable key_verify
 
@@ -274,7 +297,7 @@
 	    flush $chan
 	    fconfigure $chan -translation binary -blocking no
 	    fileevent $chan readable \
-		[list ::dtcp::readable $key $chan]
+		[list [namespace parent]::readable $key $chan]
 	    set connection(status,$key) 1
 	    return
 	}
@@ -283,7 +306,7 @@
     flush $chan
 }
 
-proc ::dtcp::readable {key chan} {
+proc dtcp::readable {key chan} {
     if {![eof $chan]} {
 	set buf [read $chan 4096]
 	jidlink::recv_data $key $buf
@@ -293,7 +316,7 @@
     }
 }
 
-proc ::dtcp::iq_set_handler {xlib from xml args} {
+proc dtcp::iq_set_handler {xlib from xml args} {
     ::xmpp::xml::split $xml tag xmlns attrs cdata subels
 
     if {$tag == "query"} {
@@ -332,7 +355,7 @@
 
 		set servsock \
 		    [socket -server \
-			 [list ::dtcp::passive::accept $key] 0]
+			 [list [namespace current]::passive::accept $key] 0]
 		lassign [fconfigure $servsock -sockname] addr hostname port
 		set ip [::xmpp::ip $xlib]
 
@@ -351,7 +374,7 @@
 		set active::key_verify($key) $verify
 
 		debugmsg jidlink [list $hosts]
-		after idle [list ::dtcp::active::sock_connect $key $hosts]
+		after idle [list [namespace current]::active::sock_connect $key $hosts]
 		set res [::xmpp::xml::create query \
 				-xmlns jabber:iq:dtcp \
 				-subelement [::xmpp::xml::create verify \
@@ -366,8 +389,3 @@
     }
 }
 
-::xmpp::iq::register set query jabber:iq:dtcp ::dtcp::iq_set_handler
-
-jidlink::register_transport dtcp-passive dtcp-active 50 \
-    ::dtcp::passive::connect ::dtcp::passive::send_data ::dtcp::passive::close
-

Modified: trunk/tkabber-plugins/jidlink/plugins/filetransfer.tcl
===================================================================
--- trunk/tkabber-plugins/jidlink/plugins/filetransfer.tcl	2009-03-31 15:20:53 UTC (rev 1769)
+++ trunk/tkabber-plugins/jidlink/plugins/filetransfer.tcl	2009-03-31 15:22:21 UTC (rev 1770)
@@ -15,6 +15,25 @@
 	-group {File Transfer}
 }
 
+proc ftjl::load {} {
+    ::xmpp::iq::register set query jabber:iq:filexfer \
+			 [namespace current]::ftjl::iq_set_handler
+
+    ft::register_protocol jidlink \
+	-priority 20 \
+	-label "Jidlink" \
+	-send [namespace current]::ftjl::send_file \
+	-close [namespace current]::ftjl::send_file_close
+}
+
+proc ftjl::unload {} {
+    ::xmpp::iq::unregister set query jabber:iq:filexfer
+
+    ft::unregister_protocol jidlink
+
+    namespace delete [namespace current]
+}
+
 ###############################################################################
 
 proc ftjl::send_file {token} {
@@ -159,7 +178,7 @@
     }
 
     Dialog $w -title [::msgcat::mc "Receive file from %s" $from] \
-	-separator 1 -anchor e \
+	-separator 1 -anchor e -transient 0 \
 	-modal none -default 0 -cancel 1
 
 
@@ -179,7 +198,7 @@
     entry $f.saveas -textvariable [namespace current]::saveas$winid
     variable saveas$winid [file join $dir $name]
     button $f.browsefile -text [::msgcat::mc "Browse..."] \
-	-command [list [namespace current]::set_receive_file_name $winid $dir $name]
+	-command [list [namespace current]::set_receive_file_name $w $winid $dir $name]
 
     set pbvar [namespace current]::progress$f.pb
     ProgressBar $f.pb -variable $pbvar
@@ -221,10 +240,10 @@
 
 ###############################################################################
 
-proc ftjl::set_receive_file_name {winid dir fname} {
+proc ftjl::set_receive_file_name {w winid dir fname} {
     variable saveas$winid
 
-    set file [tk_getSaveFile -initialdir $dir -initialfile $fname]
+    set file [tk_getSaveFile -parent $w -initialdir $dir -initialfile $fname]
     if {$file != ""} {
 	set saveas$winid $file
     }
@@ -408,16 +427,5 @@
     }
 }
 
-::xmpp::iq::register set query jabber:iq:filexfer \
-		     [namespace current]::ftjl::iq_set_handler
-
 ###############################################################################
 
-ft::register_protocol jidlink \
-    -priority 20 \
-    -label "Jidlink" \
-    -send [namespace current]::ftjl::send_file \
-    -close [namespace current]::ftjl::send_file_close
-
-###############################################################################
-

Modified: trunk/tkabber-plugins/jidlink/plugins/ibb.tcl
===================================================================
--- trunk/tkabber-plugins/jidlink/plugins/ibb.tcl	2009-03-31 15:20:53 UTC (rev 1769)
+++ trunk/tkabber-plugins/jidlink/plugins/ibb.tcl	2009-03-31 15:22:21 UTC (rev 1770)
@@ -1,8 +1,29 @@
 # $Id$
 
-namespace eval ::ibb {}
+package require base64
 
-proc ::ibb::connect {xlib jid key} {
+namespace eval ibb {}
+
+proc ibb::load {} {
+    ::xmpp::iq::register set query jabber:iq:ibb [namespace current]::iq_set_handler
+    ::xmpp::iq::register set query jabber:iq:inband [namespace current]::iq_inband_set_handler
+
+    jidlink::register_transport inband-bytestream inband-bytestream 75 enabled \
+				[namespace current]::connect \
+				[namespace current]::send_data \
+				[namespace current]::close
+}
+
+proc ibb::unload {} {
+    ::xmpp::iq::unregister set query jabber:iq:ibb
+    ::xmpp::iq::unregister set query jabber:iq:inband
+
+    #jidlink::unregister_transport inband-bytestream
+
+    namespace delete [namespace current]
+}
+
+proc ibb::connect {xlib jid key} {
     variable connection
 
     set_status [::msgcat::mc "Opening IBB connection"]
@@ -19,7 +40,7 @@
     vwait [namespace current]::connection(status,$key)
 }
 
-proc ::ibb::recv_connect_response {xlib jid key status xml} {
+proc ibb::recv_connect_response {xlib jid key status xml} {
     variable connection
 
     if {$status != "ok"} {
@@ -59,9 +80,7 @@
     set connection(status,$key) 0
 }
 
-package require base64
-
-proc ::ibb::send_data {key data} {
+proc ibb::send_data {key data} {
     variable connection
     variable key_stream
 
@@ -82,7 +101,7 @@
     return $connection(ack,$key)
 }
 
-proc ::ibb::send_data_ack {key status xml} {
+proc ibb::send_data_ack {key status xml} {
     variable connection
     if {$status != "ok"} {
 	# TODO
@@ -92,7 +111,7 @@
     set connection(ack,$key) 1
 }
 
-proc ::ibb::close {key} {
+proc ibb::close {key} {
     variable connection
     variable key_stream
 
@@ -105,7 +124,7 @@
 	-to $connection(jid,$key)
 }
 
-proc ::ibb::iq_set_handler {xlib from xml args} {
+proc ibb::iq_set_handler {xlib from xml args} {
     ::xmpp::xml::split $xml tag xmlns attrs cdata subels
 
     if {$tag == "query"} {
@@ -143,9 +162,7 @@
     }
 }
 
-::xmpp::iq::register set query jabber:iq:ibb ibb::iq_set_handler
-
-proc ::ibb::iq_inband_set_handler {xlib from xml args} {
+proc ibb::iq_inband_set_handler {xlib from xml args} {
     variable stream_key
 
     ::xmpp::xml::split $xml tag xmlns attrs cdata subels
@@ -191,8 +208,3 @@
     }
 }
 
-::xmpp::iq::register set query jabber:iq:inband ibb::iq_inband_set_handler
-
-jidlink::register_transport inband-bytestream inband-bytestream 75 \
-			    ibb::connect ibb::send_data ibb::close
-



More information about the Tkabber-dev mailing list