Youness Alaoui wrote:
> Hi,
> Thanks for the patch and for giving a detailed explanation
> of your changes... 

Hello again.
I have the patch ready :)

> however, I see two problems :
> 1 - code duplication.. it would be better to have the code
> that checks for the system configs in config.tcl after we
> loadProfile... this way, the code will be there only one...

Now the code is cleaner and there's a procedure to retrieve the proxy
data that is executed everytime you want to login if the option to use
system-wide proxy is checked.

> Also, make sure that the option for 'use system settings'
> would only be available when it is actually possible to
> check user settings (on mac, windows, do not show the
> option)..

DONE.

> also note that it might be confusing if someone has old
> settings for gnome, and is using KDE, and amsn takes gnome
> settings instead of his new KDE settings... maybe check for
> the $::env(DESKTOP) variable too...
> 

I have not found any way to guess the desktop manager that the user is
running. $::env(DESKTOP) is not set. Any other idea?

> Thanks again for the contribution!
> 
> KaKaRoTo
> 

I think this would be a good feature to have in 0.98.
What do you think?

-- 
Regards, Pablo.


> 
> On Tue, Dec 23, 2008 at 04:43:11PM +0100, Pablo Castellano wrote:
>> Hello again!
>>
>> Here I attach a patch to use the system proxy settings like Firefox or
>> Pidgin does.
>>
>> Actually it supports the environment variable "http_proxy"
>> (ex: $ export http_proxy=http://myproxy.com:81)
>>
>> and the proxy set in the gnome preferences:
>> (System -> Preferences -> Proxy)
>>
>> It has a lot of checks about gconf that I didn't know if it would be
>> better to remove to make the code more readable but finally I have left
>> them there. Remove them if you think it's better.
>>
>> Finally I couldn't test authentication but it should work so if someone
>> can confirm it, please do it!
>>
>>
>> ToDo:
>> * Translate the key "systemconnection" "Use system proxy settings" to
>> all of the languages except spanish and english. You can look into the
>> network preferences of firefox and use the same phrase.
>> * KDE, Xfce support...
>> * Testing authentication
>> * Test...
>>
>>
>>
>> I have been using it for two weeks and everything seems to work fine.
>>
>> -- 
>> Regards, Pablo.


Index: lang/langen
===================================================================
--- lang/langen (revisión: 10930)
+++ lang/langen (copia de trabajo)
@@ -935,6 +935,7 @@
 subject Subject
 svnversion SVN Version
 syntaxerror Syntax Error
+systemconnection Use system proxy settings
 tabbedglobal A tabbed window for all users in the contact list
 tabbedgroups A tabbed window for users from the same group
 tabbed Tabbed Windows
Index: lang/langes
===================================================================
--- lang/langes (revisión: 10930)
+++ lang/langes (copia de trabajo)
@@ -936,6 +936,7 @@
 subjectrequired Asunto requerido
 svnversion Versión SVN
 syntaxerror Error de sintaxis
+systemconnection Usar los datos de proxy del sistema
 tabbedglobal Una ventana con pestañas para todos los usuarios
 tabbedgroups Una ventana con pestañas para cada grupo
 tabbed Ventanas con pestañas
Index: protocol.tcl
===================================================================
--- protocol.tcl        (revisión: 10930)
+++ protocol.tcl        (copia de trabajo)
@@ -7263,6 +7263,17 @@
                $name configure -proxy_user [::config::getKey proxyuser]
                $name configure -proxy_password [::config::getKey proxypass]
 
+       } elseif { [::config::getKey connectiontype] == "system" } {
+
+               global systemproxy_host systemproxy_port
+               global systemproxy_auth systemproxy_user systemproxy_pass
+
+               $name configure -proxy_host $systemproxy_host
+               $name configure -proxy_port $systemproxy_port
+               $name configure -proxy_authenticate $systemproxy_auth
+               $name configure -proxy_user $systemproxy_user
+               $name configure -proxy_password $systemproxy_pass
+
        } else {
                #$name configure -connection_wrapper DirectConnection
                ::config::setKey connectiontype "direct"
Index: login_screen.tcl
===================================================================
--- login_screen.tcl    (revisión: 10930)
+++ login_screen.tcl    (copia de trabajo)
@@ -786,6 +786,12 @@
                        CreateProfile $user
                }
 
+               #load system-wide proxy settings
+               #
+               if { [::config::getKey connectiontype] == "system" && [OnUnix] 
} {
+                       load_unix_system_proxy
+               }
+
                # Login with them
                $self login $user $pass
        }
Index: preferences.tcl
===================================================================
--- preferences.tcl     (revisión: 10930)
+++ preferences.tcl     (copia de trabajo)
@@ -2201,6 +2201,13 @@
        pack $lfname.1.direct -anchor w -side top -padx 10
        radiobutton $lfname.2.http -text "[trans httpconnection]" -value http 
-variable [::config::getVar connectiontype] -command UpdatePreferences
        pack $lfname.2.http -anchor w -side top -padx 10
+
+       #Only show this option if the OS supports a system-wide proxy 
configuration.
+       if { [OnUnix] } {
+               radiobutton $lfname.3.system -text "[trans systemconnection]" 
-value system -variable [::config::getVar connectiontype] -command 
UpdatePreferences
+               pack $lfname.3.system -anchor w -side top -padx 10
+       }
+       
        radiobutton $lfname.3.proxy -text "[trans proxyconnection]" -value 
proxy -variable [::config::getVar connectiontype] -command UpdatePreferences
        pack $lfname.3.proxy -anchor w -side top -padx 10
 
Index: soap.tcl
===================================================================
--- soap.tcl    (revisión: 10930)
+++ soap.tcl    (copia de trabajo)
@@ -81,6 +81,20 @@
                                set headers [linsert $headers 0 
"Proxy-Authorization" "Basic $auth"]
                        }
                        http::register https 443 HTTPsecureSocket
+                       http::register http 80 ::socket
+               } elseif { [::config::getKey connectiontype] == "system" } {
+                       
+                       global systemproxy_host systemproxy_port
+                       global systemproxy_auth systemproxy_user 
systemproxy_pass
+
+                       ::http::config -proxyhost $systemproxy_host -proxyport 
$systemproxy_port
+
+                       if { $systemproxy_auth == 1 } {
+                               set auth [string map {"\n" "" } [base64::encode 
${systemproxy_user}:${systemproxy_pass}]]
+                               set headers [linsert $headers 0 
"Proxy-Authorization" "Basic $auth"]
+                       }
+
+                       http::register https 443 HTTPsecureSocket
                        http::register http 80 ::socket
                } elseif { [::config::getKey connectiontype] == "proxy" && 
[::config::getKey proxytype] == "socks5" } {
                        if {$proxy_host == "" } {
Index: config.tcl
===================================================================
--- config.tcl  (revisión: 10930)
+++ config.tcl  (copia de trabajo)
@@ -27,7 +27,7 @@
                ::config::setKey log_event_nick 0               ;#Log 
changement of status
                ::config::setKey log_event_psm 0                ;#Log 
changement of status
 
-               ::config::setKey connectiontype direct  ;# Connection type: 
direct|http|proxy
+               ::config::setKey connectiontype direct  ;# Connection type: 
direct|http|proxy|system
                ::config::setKey proxy ""                       ;# If using 
proxy, proxy host
                ::config::setKey proxytype "http"               ;# Proxy type: 
http|ssl|socks5
                ::config::setKey proxyauthenticate 0            ;# SOCKS5 use 
username/password
@@ -831,6 +831,112 @@
 
 }
 
+#///////////////////////////////////////////////////////////////////////////////
+# load_unix_system_proxy ( )
+# Called when key connectiontype == "system" and [OnUnix].
+# It tries to get env $http_proxy after trying to get use_http_proxy from 
gconf        .
+# Note that $::env(http_proxy) will only exist if amsn is launched from a 
terminal.
+# TODO: Act depending on the desktop (KDE, GNOME, XFce...).
+proc load_unix_system_proxy {} {
+
+       global systemproxy_host
+       global systemproxy_port
+       global systemproxy_auth #0-disabled 1-enabled
+       global systemproxy_user
+       global systemproxy_pass
+
+       # System-wide proxy settings by PabloCastellano
+       # !!!Only GNOME and $http_proxy support at the moment!!!
+       # Maybe the gconf keys use_same_proxy and autoconfig_url should be 
considered.
+       # system http proxy working
+       # I HAVE NOT TESTED authentication over http but it should work.
+       
+       if { [info exists ::env(http_proxy)] } {
+               status_log "systemproxy: using 
\$http_proxy=$::env(http_proxy)\n" red
+               #regexp. http://%s:%...@%s:%d
+               regsub 
{^(?:(?:[^:/?#]+):)?(?://(?:(?:(?:([^:@]*):?([^:@]*))?@)?([^:/?#]*)(?::(\d*).*)?))?}
 $::env(http_proxy) {"\1" "\2" "\3" "\4"} result
+
+               set     systemproxy_user [lindex $result 0]
+               set systemproxy_pass [lindex $result 1]
+               set systemproxy_host [lindex $result 2]
+               set systemproxy_port [lindex $result 3]
+
+               if { [llength $systemproxy_user] == 0 } {
+                       set systemproxy_auth 0
+               } else {
+                       set systemproxy_auth 1
+               }
+       
+       } elseif { ! [catch { eval [concat [list "exec"] "gconftool -g 
/system/proxy/mode"]} proxymode ] } {
+               set usehttp [eval [concat [list "exec"] "gconftool -g 
/system/http_proxy/use_http_proxy"]]
+               status_log "systemproxy: using gconf\n" red
+
+               if {$usehttp == "true" && $proxymode != "none"} {
+                       #Get host from gconf
+                       if { [catch { eval [concat [list "exec"] "gconftool -g 
/system/http_proxy/host"]} systemproxy_host ] } {
+                               status_log "systemproxy: Error getting host 
from gconf\n" red
+                       }
+                               
+                       #Get port from gconf
+                       if { [catch { eval [concat [list "exec"] "gconftool -g 
/system/http_proxy/port"]} systemproxy_port ] } {
+                               status_log "systemproxy: Error getting port 
from gconf\n" red
+                       }
+
+                       #Get use_authentication from gconf
+                       if { [catch { eval [concat [list "exec"] "gconftool -g 
/system/http_proxy/use_authentication"]} proxyauth ] } {
+                               status_log "systemproxy: Error getting 
use_authentication from gconf\n" red
+                       } else {
+
+                               if {$proxyauth == "true"} {
+                                       
+                                       set systemproxy_auth 1
+
+                                       #Get authentication_user from gconf
+                                       if { [catch { eval [concat [list 
"exec"] "gconftool -g /system/http_proxy/authentication_user"]} 
systemproxy_user ] } {
+                                               status_log "systemproxy: Error 
getting authentication_user from gconf\n" red
+                                       }
+
+                                       #Get authentication_password from gconf
+                                       if { [catch { eval [concat [list 
"exec"] "gconftool -g /system/http_proxy/authentication_password"]} 
systemproxy_pass ] } {
+                                               status_log "systemproxy: Error 
getting authentication_password from gconf\n" red
+                                       }
+
+                               } else { # use_authentication == "false"
+                                       set systemproxy_auth 0
+                                       set systemproxy_user ""
+                                       set systemproxy_pass ""
+                               } 
+                       }
+
+               } else { # use_http_proxy == "false" || mode == "none"
+                       #Configure as direct
+                       set systemproxy_host ""
+                       set systemproxy_port ""
+                       set systemproxy_auth 0
+                       set systemproxy_user ""
+                       set systemproxy_pass ""
+               }
+
+       } else { #it's not gnome and ENV $http_proxy is not set. => Don't use 
proxy
+               status_log "systemproxy: use_http_proxy gconf key and 
\$http_proxy NOT FOUND\n" red
+                       
+               #Configure as direct
+               set systemproxy_host ""
+               set systemproxy_port ""
+               set systemproxy_auth 0
+               set systemproxy_user ""
+               set systemproxy_pass ""
+       } 
+
+       #Print result
+       status_log "systemproxy: host is: $systemproxy_host\n" red
+       status_log "systemproxy: port is: $systemproxy_port\n" red
+       status_log "systemproxy: auth is: $systemproxy_auth\n" red
+       status_log "systemproxy: user is: $systemproxy_user\n" red
+       status_log "systemproxy: pass is: $systemproxy_pass\n" red
+
+}
+
 proc load_config {} {
        global HOME password protocol osspecific_keys
 
@@ -965,6 +1071,17 @@
            ::ChatWindow::ShowHideChatWindowMenus . 0
        }
 
+#      #load system-wide proxy settings
+#      #
+       if { [::config::getKey connectiontype] == "system" } {
+               if { [OnUnix] } {
+                       load_unix_system_proxy
+               } else {
+                       status_log "connectiontype reset to direct"
+                       ::config::setKey connectiontype direct
+               }
+       }
+
        #load Snack
        if {![catch {require_snack} res]} {
                # TODO this is bad because it already gets called by 
require_snack once... 
Index: proxy.tcl
===================================================================
--- proxy.tcl   (revisión: 10930)
+++ proxy.tcl   (copia de trabajo)
@@ -172,6 +172,16 @@
                        install proxy using ProxyDirect %AUTO% -name $self
                } elseif { [::config::getKey connectiontype] == "proxy" && 
[::config::getKey proxytype] == "socks5" } {
                        install proxy using ProxyDirect %AUTO% -name $self
+               } elseif { [::config::getKey connectiontype] == "system" } {
+
+                       global systemproxy_host
+
+                       if { $systemproxy_host != "" } {
+                               install proxy using ProxyHTTP %AUTO% -name 
$self -direct 0
+                       } else {
+                               install proxy using ProxyDirect %AUTO% -name 
$self
+                       }
+                       
                } else {
                        ::config::setKey connectiontype "direct"
                        install proxy using ProxyDirect %AUTO% -name $self
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Amsn-devel mailing list
Amsn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/amsn-devel

Reply via email to