[Tkabber-dev] r268 - in trunk/plugins/antispam: . msgs

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Fri Jan 8 13:23:44 MSK 2010


Author: gebb
Date: 2010-01-08 13:23:44 +0300 (Fri, 08 Jan 2010)
New Revision: 268

Modified:
   trunk/plugins/antispam/ChangeLog
   trunk/plugins/antispam/antispam.tcl
   trunk/plugins/antispam/msgs/ru.msg
Log:
Made the plugin partially unloadable.

Modified: trunk/plugins/antispam/ChangeLog
===================================================================
--- trunk/plugins/antispam/ChangeLog	2010-01-08 03:13:34 UTC (rev 267)
+++ trunk/plugins/antispam/ChangeLog	2010-01-08 10:23:44 UTC (rev 268)
@@ -1,3 +1,8 @@
+2010-01-08 Otto Gebb
+
+	* Upgrade: Made the plugin (not completely) unloadable using
+	the new plugin management feature.
+
 2009-05-19 Otto Gebb
 
 	* Minor change: Made the plugin disabled by default, because

Modified: trunk/plugins/antispam/antispam.tcl
===================================================================
--- trunk/plugins/antispam/antispam.tcl	2010-01-08 03:13:34 UTC (rev 267)
+++ trunk/plugins/antispam/antispam.tcl	2010-01-08 10:23:44 UTC (rev 268)
@@ -12,6 +12,16 @@
 	package require msgcat
 	::msgcat::mcload [file join [file dir [info script]] msgs]
 
+	if {![::plugins::is_registered antispam]} {
+		::plugins::register antispam \
+					-namespace [namespace current] \
+					-source [info script] \
+					-description [::msgcat::mc "Whether the Antispam plugin is loaded."] \
+					-loadcommand [namespace code load] \
+					-unloadcommand [namespace code unload]
+		return
+	}
+
 	custom::defgroup Plugins [::msgcat::mc "Plugins options."] -group Tkabber
 
 	set group "Antispam"
@@ -24,11 +34,6 @@
 			enables the showing of messages."] \
 		-group Plugins
 
-	custom::defvar options(enabled) 0 \
-		[::msgcat::mc "Enables or disables the spam protection."] \
-		-group $group \
-		-type boolean
-
 	custom::defvar options(disable_regex) "^$" \
 		[::msgcat::mc "Regular expression to match JIDs for which\
 			the spam protection will not be used. A (default) value\
@@ -191,10 +196,7 @@
 	variable answered
 	variable postponed_msgs
 	global whitelist
-	# Do nothing if antispam is disabled.
-	if { !$options(enabled) } {
-		return
-	}
+
 	if { $type ne "groupchat" } {
 		debugmsg antispam \
 			"PROCESS: message from $from, type $type, body: $body, args: $args."
@@ -339,10 +341,7 @@
 proc antispam::block_subscription_spam {xlib from type x args} {
 	variable options
 	global whitelist
-	# Do nothing if antispam is disabled.
-	if { !$options(enabled) } {
-		return
-	}
+
 	if {$type ne "subscribe"} {
 		return
 	}
@@ -388,7 +387,21 @@
 	return stop
 }
 
+# HACK: An unloadable plugin should not behave like this.
+# TODO: Remove this when there is a means in Tkabber
+#       to check if the roster is loaded without using hooks.
 namespace eval antispam {
+	hook::add roster_end_hook \
+		[namespace current]::roster_loaded_handler
+	hook::add disconnected_hook \
+		[namespace current]::disconnected_handler
+}
+
+proc antispam::load {} {
+	variable answered
+	variable postponed_msgs
+	global whitelist
+
 	# Must be run before other handlers to prevent
 	# chat window opening for spam messages.
 	hook::add process_message_hook \
@@ -396,9 +409,22 @@
 	# Must be run before the handler showing subcription dialog.
 	hook::add client_presence_hook \
 		[namespace current]::block_subscription_spam 40
-	hook::add roster_end_hook \
-		[namespace current]::roster_loaded_handler
-	hook::add disconnected_hook \
-		[namespace current]::disconnected_handler
+
 }
+
+proc antispam::unload {} {
+	variable answered
+	variable postponed_msgs
+	global whitelist
+
+	catch {unset answered}
+	catch {unset postponed_msgs}
+	catch {unset whitelist}
+
+	hook::remove process_message_hook \
+		[namespace current]::process_message 40
+	hook::remove client_presence_hook \
+		[namespace current]::block_subscription_spam 40
+}
+
 # vim:ai:si:noet:nosta:ts=3:sw=3

Modified: trunk/plugins/antispam/msgs/ru.msg
===================================================================
--- trunk/plugins/antispam/msgs/ru.msg	2010-01-08 03:13:34 UTC (rev 267)
+++ trunk/plugins/antispam/msgs/ru.msg	2010-01-08 10:23:44 UTC (rev 268)
@@ -1,9 +1,9 @@
 # vim:fenc=utf-8
 
+::msgcat::mcset ru "Whether the Antispam plugin is loaded." \
+	"Загружен ли плагин Antispam."
 ::msgcat::mcset ru "Antispam plugin discards incoming subscription requests and chat messages from JIDs that are not in the roster, optionally requesting a password that enables the showing of messages." \
 	"Antispam блокирует входящие запросы на подписку и сообщения типа \"чат\", посланные с адресов, отсутствующих в ростере, и запрашивает при этом пароль для отмены блокировки."
-::msgcat::mcset ru "Enables or disables the spam protection." \
-	"Включает или выключает защиту от спама."
 ::msgcat::mcset ru "Plugins options." \
 	"Настройки плагинов."
 ::msgcat::mcset ru "Regular expression to match unknown JIDs, messages from which will be discarded util a correct password is received. A (default) value of \"\" means any JID." \



More information about the Tkabber-dev mailing list