Changeset 5756890 for lib/proxy.c


Ignore:
Timestamp:
2015-10-25T22:37:56Z (9 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
f710673
Parents:
e4c3041
git-author:
dequis <dx@…> (24-10-15 20:45:07)
git-committer:
dequis <dx@…> (25-10-15 22:37:56)
Message:

proxy: Use an array of function pointers for proxy_connect_*

Just cleanup.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/proxy.c

    re4c3041 r5756890  
    6161};
    6262
     63typedef int (*proxy_connect_func)(const char *host, unsigned short port_, struct PHB *phb);
     64
    6365static int proxy_connect_none(const char *host, unsigned short port_, struct PHB *phb);
    6466
     
    502504}
    503505
     506static const proxy_connect_func proxy_connect_funcs_array[] = {
     507        proxy_connect_none,   /* PROXY_NONE */
     508        proxy_connect_http,   /* PROXY_HTTP */
     509        proxy_connect_socks4, /* PROXY_SOCKS4 */
     510        proxy_connect_socks5, /* PROXY_SOCKS5 */
     511        proxy_connect_socks4, /* PROXY_SOCKS4A */
     512};
    504513
    505514/* Export functions */
     
    508517{
    509518        struct PHB *phb;
     519        proxy_connect_func fun;
    510520
    511521        if (!host || port <= 0 || !func || strlen(host) > 128) {
     
    517527        phb->data = data;
    518528
    519         if (proxytype == PROXY_NONE || !proxyhost[0] || proxyport <= 0) {
    520                 return proxy_connect_none(host, port, phb);
    521         } else if (proxytype == PROXY_HTTP) {
    522                 return proxy_connect_http(host, port, phb);
    523         } else if (proxytype == PROXY_SOCKS4 || proxytype == PROXY_SOCKS4A) {
    524                 return proxy_connect_socks4(host, port, phb);
    525         } else if (proxytype == PROXY_SOCKS5) {
    526                 return proxy_connect_socks5(host, port, phb);
    527         }
    528 
    529         g_free(phb);
    530         return -1;
    531 }
     529        if (proxyhost[0] && proxyport > 0 && proxytype >= 0 && proxytype <= G_N_ELEMENTS(proxy_connect_funcs_array)) {
     530                fun = proxy_connect_funcs_array[proxytype];
     531        } else {
     532                fun = proxy_connect_none;
     533        }
     534
     535        return fun(host, port, phb);
     536}
Note: See TracChangeset for help on using the changeset viewer.