EnglishРусский  

   ..

   ping.g

   proxy.g

   socket.g

   strinet.g

Ads

Perfect Automation tool
All-In-One: Script editor, Launcher, Scheduler, Keyboard & Mouse Recorder. Try now!

CreateInstall
Freeware and commercial installers.

Cell Phone Batteries
Batteries Plus offers batteries for laptop, camcorder, cell phone, camera.

Gentee needs your help!
How to advertise with us
 
laptop battery

source\lib\socket\proxy.g
  1 /******************************************************************************
  2 *
  3 * Copyright (C) 2004-2008, The Gentee Group. All rights reserved. 
  4 * This file is part of the Gentee open source project - http://www.gentee.com. 
  5 * 
  6 * THIS FILE IS PROVIDED UNDER THE TERMS OF THE GENTEE LICENSE ("AGREEMENT"). 
  7 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE CONSTITUTES RECIPIENTS 
  8 * ACCEPTANCE OF THE AGREEMENT.
  9 *
 10 * Author: Alexey Krivonogov ( gentee )
 11 *
 12 ******************************************************************************/
 13 
 14 include : $"..\registry\registry.g"
 15 
 16 define <export>
 17 {
 18 /*-----------------------------------------------------------------------------
 19 * Id: proxyflag D
 20 * 
 21 * Summary: Proxy types.
 22 *
 23 -----------------------------------------------------------------------------*/
 24    PROXY_HTTP  = 0x0001       // Use a proxy server for the HTTP protocol.  
 25    PROXY_FTP   = 0x0002       // Use a proxy server for the FTP protocol.
 26    PROXY_ALL   = 0x0003       // Use a proxy server for all protocols.
 27    PROXY_EXPLORER  = 0x0080   // Take the proxy server information from the /
 28                               // Internet Explorer settings. In this case /
 29                               // the proxyname parameter can be empty.
 30    
 31 //-----------------------------------------------------------------------------
 32 }
 33 
 34 operator proxyinfo =( proxyinfo left right )
 35 {
 36    left.host = right.host
 37    left.port = right.port
 38    left.enable = right.enable
 39    return left
 40 }
 41 
 42 /*-----------------------------------------------------------------------------
 43 * Id: inet_proxy F
 44 *
 45 * Summary: Using a proxy server. The functions allows you to specify a 
 46            proxy server to be used for connecting to the Internet. 
 47 *
 48 * Params: flag - The flag specifying for which protocols the specified proxy /
 49                  should be used. $$[proxyflag] 
 50           proxyname - The name of the proxy server. It must contain a host /
 51                       name and a port number separated by a colon. 
 52 *  
 53 * Return: #lng/retf# 
 54 *
 55 -----------------------------------------------------------------------------*/
 56 
 57 func uint inet_proxy( uint flag, str proxyname )
 58 {
 59    arrstr     shostport
 60    proxyinfo  ieproxy
 61    str        regie  stemp
 62    uint       i
 63    
 64    regie = $"Software\Microsoft\Windows\CurrentVersion\Internet Settings"
 65    
 66    ieproxy.enable = 1
 67    if flag & $PROXY_EXPLORER
 68    {
 69       ieproxy.enable = reggetnum( $HKEY_CURRENT_USER, regie,
 70                                      "ProxyEnable", 0 )
 71       stemp.regget( $HKEY_CURRENT_USER, regie, "ProxyServer" )
 72    }
 73    else : stemp = proxyname
 74 
 75    stemp.split( shostport, ':', $SPLIT_FIRST | $SPLIT_NOSYS )
 76    ieproxy.host = shostport[0]
 77    if *shostport > 1 : ieproxy.port = uint( shostport[1] )  
 78 
 79    if flag & $PROXY_HTTP : proxy[ $INET_HTTP ] = ieproxy
 80    if flag & $PROXY_FTP : proxy[ $INET_FTP ] = ieproxy
 81 
 82    return 1
 83 }
 84 
 85 /*-----------------------------------------------------------------------------
 86 * Id: socket_urlconnect F2
 87 *
 88 * Summary: Creating and connecting a socket to a URL. The method is used to
 89            create and connect a socket to the specified Internet address. 
 90            If a proxy server is enabled, the connection will be established 
 91            via it.
 92 *
 93 * Params: url - The URL address for connecting. 
 94           host - The string for getting the host from the URL. 
 95           path - The string for getting the relative path from the URL. 
 96 *  
 97 * Return: #lng/retf# 
 98 *
 99 -----------------------------------------------------------------------------*/
100 
101 method uint socket.urlconnect( str url, str host, str path )
102 {
103    str   port
104    uint  protocol = $INET_HTTP
105    uint  defport = 80
106    
107    this.flag &= ~$SOCKF_PROXY
108    if url.iurl( host, port, path ) == $INET_FTP 
109    {
110       this.flag |= $SOCKF_FTP
111    } 
112    if this.flag & $SOCKF_FTP : protocol = $INET_FTP; defport = 21
113 
114    if proxy[ protocol ].enable
115    {
116       this.flag |= $SOCKF_PROXY
117       this.host = proxy[ protocol ].host
118       this.port = proxy[ protocol ].port
119    }
120    else
121    {
122       this.host = host
123       this.port = ?( !*port, defport, uint( port ))
124    }
125    if *port : host += ":\(port)"
126 //   print("URL: \(this.host):\(this.port)\n")   
127    return this.connect()
128 }
129 
130 /*-----------------------------------------------------------------------------
131 ** Id: inet_proxyenable F
132 *
133 * Summary: Enabling/disabling a proxy server. The function allows you to 
134            enable or disable the proxy server for various protocols. 
135            Initially, the proxy server must be specified using the 
136            #a(inet_proxy) function.
137 *
138 * Params: flag - The flag specifying for which protocols the proxy should /
139                  be enabled or disabled. $$[proxyflag]
140           enable - Specify 1 to enable the proxy server or 0 to disable /
141                    the proxy server.     
142 *  
143 * Return: #lng/retf# 
144 *
145 -----------------------------------------------------------------------------*/
146 
147 func uint inet_proxyenable( uint flag, uint enable )
148 {
149    uint i
150 
151    if flag & $PROXY_HTTP 
152    {
153       if !*proxy[ $INET_HTTP ].host : return 0
154       proxy[ $INET_HTTP ].enable = enable
155    }
156    if flag & $PROXY_FTP 
157    {
158       if !*proxy[ $INET_FTP ].host : return 0
159       proxy[ $INET_FTP ].enable = enable
160    }
161    return 1   
162 }
Edit