/*---------------------------------------------------------------------------*/
/* network.h                                                                 */
/* copyright (c) innovaphone 2017                                            */
/*                                                                           */
/*---------------------------------------------------------------------------*/

class LocalAddr : public istd::listElement<LocalAddr> {
public:
    bool preferred;
    bool iPv6;
    bool vpn;
    char * addr;
    LocalAddr(char * addr, bool iPv6, bool preferred, bool vpn) { 
        this->addr = addr;
        this->iPv6 = iPv6; 
        this->preferred = preferred;
        this->vpn = vpn;
    };
    ~LocalAddr() { if(addr) free(addr); };
};

class LocalAddresses {
public:
    istd::list <class LocalAddr> localAddresses;

    ~LocalAddresses() {
        while(this->localAddresses.front()) {
            delete this->localAddresses.front();
        }
    }
};

typedef enum {
    HTTP_PROXY_TYPE_NONE,
    HTTP_PROXY_TYPE_FTP,
    HTTP_PROXY_TYPE_HTTP,
    HTTP_PROXY_TYPE_HTTPS,
    HTTP_PROXY_TYPE_SOCKS,
} HTTPProxyType;

class HTTPProxy : public istd::listElement<HTTPProxy> {
public:
    char * host;
    word port;
    HTTPProxyType type;
    char * usr;
    char * pwd;
    HTTPProxy(char * host, word port, HTTPProxyType type, char * usr, char * pwd) { 
        this->host = host;
        this->port = port;
        this->type = type;
        this->usr = usr;
        this->pwd = pwd;
    };
    ~HTTPProxy() {
        if(host) free(host);
        if(usr) free(usr);
        if(pwd) free(pwd);
    };
};

class HTTPProxies {
public:
    istd::list <class HTTPProxy> httpProxies;

    ~HTTPProxies() {
        while(this->httpProxies.front()) {
            delete this->httpProxies.front();
        }
    }
};

class INetwork {
public:
    static LocalAddresses * GetLocalAddresses();
    static HTTPProxies * GetHTTPProxiesForURL(const char * url);
};