# HG changeset patch # User Matti Hamalainen # Date 1594288188 -10800 # Node ID 17183d85ab623567dc7c0505e264e35254ec010c # Parent 06d984a92a2851cf04cb0e09f0af9041ae0b53b8 urllog: Cleanups. diff -r 06d984a92a28 -r 17183d85ab62 urllog.tcl --- a/urllog.tcl Thu Jul 09 12:47:39 2020 +0300 +++ b/urllog.tcl Thu Jul 09 12:49:48 2020 +0300 @@ -33,17 +33,18 @@ ########################################################################## # No need to look below this line ########################################################################## +package require sqlite3 +package require http + set urllog_name "URLLog" set urllog_version "2.4.3" +set urllog_message "$urllog_name v$urllog_version (C) 2000-2020 ccr/TNSP" + set urllog_tld_list [split $urllog_tld_list ","] set urllog_httprep [split "\@|%40|{|%7B|}|%7D|\[|%5B|\]|%5D" "|"] -### Require packages -package require sqlite3 -package require http - ### Binding initializations bind pub - !urlfind urllog_pub_cmd_urlfind bind msg - !urlfind urllog_msg_cmd_urlfind @@ -51,55 +52,14 @@ bind topc - *.* urllog_check_line -### Initialization messages -set urllog_message "$urllog_name v$urllog_version (C) 2000-2020 ccr/TNSP" -putlog "$urllog_message" - -### Miscellaneous init messages -if {$urllog_extra_checks != 0} { - putlog " - Additional URL validity checks enabled." -} - -if {$urllog_check_tld != 0} { - putlog " - Check TLD enabled." -} - -if {$urllog_verbose != 0} { - putlog " - Verbose mode enabled." -} - -### HTTP module initialization -if {[info exists http_user_agent] && $http_user_agent != ""} { - ::http::config -useragent $http_user_agent -} else { - ::http::config -useragent "$urllog_name/$urllog_version" -} - -if {[info exists http_use_proxy] && $http_use_proxy != 0} { - ::http::config -proxyhost $http_proxy_host -proxyport $http_proxy_port - putlog " - Using proxy $http_proxy_host:$http_proxy_port" -} - -if {[info exists http_tls_support] && $http_tls_support != 0} { - package require tls - ::http::register https 443 [list ::tls::socket -request true -require true -ssl2 false -ssl3 false -tls1 true -tls1.1 true -tls1.2 true -cadir $http_tls_cadir -autoservername true] - putlog " - TLS/SSL support enabled." -} - -### SQLite database initialization -if {[catch {sqlite3 urldb $urllog_db_file} uerrmsg]} { - putlog "Could not open SQLite3 database '$urllog_db_file': $uerrmsg" - exit 2 -} - #------------------------------------------------------------------------- ### Utility functions -proc urllog_log {arg} { +proc urllog_log {umsg} { global urllog_log_enable urllog_name if {$urllog_log_enable != 0} { - putlog "$urllog_name: $arg" + putlog "$urllog_name: $umsg" } } @@ -629,4 +589,48 @@ return 0 } + +#------------------------------------------------------------------------- +# Script initialization +#------------------------------------------------------------------------- +putlog "$urllog_message" + +if {$urllog_extra_checks != 0} { + putlog " - Additional URL validity checks enabled." +} + +if {$urllog_check_tld != 0} { + putlog " - Check TLD enabled." +} + +if {$urllog_verbose != 0} { + putlog " - Verbose mode enabled." +} + +### HTTP module initialization +if {[info exists http_user_agent] && $http_user_agent != ""} { + ::http::config -useragent $http_user_agent +} else { + ::http::config -useragent "$urllog_name/$urllog_version" +} + +if {[info exists http_use_proxy] && $http_use_proxy != 0} { + ::http::config -proxyhost $http_proxy_host -proxyport $http_proxy_port + putlog " - Using proxy $http_proxy_host:$http_proxy_port" +} + +if {[info exists http_tls_support] && $http_tls_support != 0} { + package require tls + ::http::register https 443 [list ::tls::socket -request true -require true -ssl2 false -ssl3 false -tls1 true -tls1.1 true -tls1.2 true -cadir $http_tls_cadir -autoservername true] + putlog " - TLS/SSL support enabled." +} + + +### SQLite database initialization +if {[catch {sqlite3 urldb $urllog_db_file} uerrmsg]} { + putlog "Could not open SQLite3 database '$urllog_db_file': $uerrmsg" + exit 2 +} + + # end of script