void CMetaDataCustomType::AddInterface(CMetaDataInterface *pIntf, unsigned int Offset)
{
	std::vector<SMetaDataCustomTypeInterface> *pIntfList(GetInterfaceList());
	if (pIntfList)
	{
		SMetaDataCustomTypeInterface intf;
		intf.Intf = pIntf;
		intf.Offset = Offset;
		pIntfList->push_back(intf);
	}
}
bool CMetaDataCustomType::QueryInterface(void *pObj, char *pIntfName, IInterface **outIntf)
{
	if (!pObj || !pIntfName || !outIntf) return false;

	std::vector<SMetaDataCustomTypeInterface> *pIntfList(GetInterfaceList());
	std::vector<SMetaDataCustomTypeInterface>::iterator itr;
	char FullNameBuffer[256];
	
	if (!pIntfList) return false;

	for (itr = pIntfList->begin(); itr != pIntfList->end(); ++itr)
	{
		if (itr->Intf->GetFullName(FullNameBuffer, 256) && strcmp(FullNameBuffer, pIntfName) == 0)
		{
			*outIntf = reinterpret_cast<IInterface*>((unsigned int)pObj + itr->Offset);
			return true;
		}
	}
	return false;
}
Exemple #3
0
int syscfg_GetIFInfo_2000(int *count, int *addrs, int *masks, int *mtus, int *flags)
{
    int maxCount = *count;
    char *IFListBase = NULL;
    char *IFList, *ifname;
    HKEY skey;
    int i, n, nConfig;

    if (RegOpenKeyAlt(AFSREG_NULL_KEY, AFSREG_IPSRV_KEY,
		      KEY_READ, 0, &skey, NULL))
	return -1;

    if ((nConfig = GetInterfaceList(skey, &IFListBase)) < 0) {
	(void) RegCloseKey(skey);
	return -1;
    }

    IFList = IFListBase;
    n = 0;

    while ((n < maxCount) && (ifname = GetNextInterface(IFList))) {
	if (!IsLoopback(ifname) && GetIP(skey, ifname, &addrs[n], &masks[n]) == 0 && addrs[n] != 0) {
	    n++;
	} else {
            maxCount--;
        }
	IFList = ifname;
    }

    /* And until we get mtu's and flags */
    for (i = 0; i < n; i++) {
	mtus[i] = 1500;
	flags[i] = 0;
    }

    (void) RegCloseKey(skey);
    free(IFListBase);

    *count = n;
    return nConfig;
}
Network::Network()
    : KAccessorObject("Network")
    , global(kroll::Host::GetInstance()->GetGlobalObject())
{
    GetInterfaceList();
    KValueRef online = Value::NewBool(true);

    /**
     * @tiapi(property=True,name=Network.online,since=0.2)
     * @tiapi Whether or not the system is connected to the internet
     * @tiresult[Boolean] True if the system is connected to the internet, false if otherwise
     */
    this->Set("online", online);

    // methods that are available on Titanium.Network
    /**
     * @tiapi(method=True,name=Network.createTCPSocket,since=0.2) Creates a TCPSocket object
     * @tiarg(for=Network.createTCPSocket,name=host,type=String) the hostname to connect to
     * @tiarg(for=Network.createTCPSocket,name=port,type=Number) the port to use
     * @tiresult(for=Network.createTCPSocket,type=Network.TCPSocket) a TCPSocket object
     */
    this->SetMethod("createTCPSocket",&Network::_CreateTCPSocket);
    /**
     * @tiapi(method=True,name=Network.createTCPServerSocket,since=1.2) Creates a TCPServerSocket object
     * @tiarg(for=Network.createTCPServerSocket,name=callback,type=Function) the callback to receive a new connection
     * @tiresult(for=Network.createTCPServerSocket,type=Network.TCPServerSocket) a TCPServerSocket object
     */
    this->SetMethod("createTCPServerSocket",&Network::_CreateTCPServerSocket);
    /**
     * @tiapi(method=True,name=Network.createIRCClient,since=0.2) Creates an IRCClient object
     * @tiresult(for=Network.createIRCClient,type=Network.IRCClient) an IRCClient object
     */
    this->SetMethod("createIRCClient",&Network::_CreateIRCClient);
    /**
     * @tiapi(method=True,name=Network.createIPAddress,since=0.2) Creates an IPAddress object
     * @tiarg(for=Network.createIPAddress,name=address,type=String) the IP address
     * @tiresult(for=Network.createIPAddress,type=Network.IPAddress) an IPAddress object
     */
    this->SetMethod("createIPAddress",&Network::_CreateIPAddress);
    /**
     * @tiapi(method=True,name=Network.createHTTPClient,since=0.3) Creates an HTTPClient object
     * @tiresult(for=Network.createHTTPClient,type=Network.HTTPClient) an HTTPClient object
     */
    this->SetMethod("createHTTPClient",&Network::_CreateHTTPClient);
    /**
     * @tiapi(method=True,name=Network.createHTTPServer,since=0.4) Creates an HTTPServer object
     * @tiresult(for=Network.createHTTPServer,type=Network.HTTPServer) a HTTPServer object
     */
    this->SetMethod("createHTTPServer",&Network::_CreateHTTPServer);
    /**
     * @tiapi(method=True,name=Network.createHTTPCookie,since=0.7) Creates a new HTTPCookie object
     * @tiresult(for=Network.createHTTPCookie,type=Network.HTTPCookie) a HTTPCookie object
     */
    this->SetMethod("createHTTPCookie",&Network::_CreateHTTPCookie);
    /**
     * @tiapi(method=True,name=Network.getHostByName,since=0.2) Returns a Host object using a hostname
     * @tiarg(for=Network.getHostByName,name=name,type=String) the hostname
     * @tiresult(for=Network.getHostByName,type=Network.Host) a Host object referencing the hostname
     */
    this->SetMethod("getHostByName",&Network::_GetHostByName);
    /**
     * @tiapi(method=True,name=Network.getHostByAddress,since=0.2) Returns a Host object using an address
     * @tiarg(for=Network.getHostByAddress,name=address,type=String) the address
     * @tiresult(for=Network.getHostByAddress,type=Network.Host) a Host object referencing the address
     */
    this->SetMethod("getHostByAddress",&Network::_GetHostByAddress);
    /**
     * @tiapi(method=True,name=Network.encodeURIComponent,since=0.3) Encodes a URI Component
     * @tiarg(for=Network.encodeURIComponent,name=value,type=String) value to encode
     * @tiresult(for=Network.encodeURIComponent,type=String) the encoded value
     */
    this->SetMethod("encodeURIComponent",&Network::_EncodeURIComponent);
    /**
     * @tiapi(method=True,name=Network.decodeURIComponent,since=0.3) Decodes a URI component
     * @tiarg(for=Network.decodeURIComponent,name=value,type=String) value to decode
     * @tiresult(for=Network.decodeURIComponent,type=String) the decoded value
     */
    this->SetMethod("decodeURIComponent",&Network::_DecodeURIComponent);

    /**
     * @tiapi(method=True,name=Network.addConnectivityListener,since=0.2)
     * @tiapi Adds a connectivity change listener that fires when the system
     * @tiapi connects or disconnects from the internet
     * @tiarg(for=Network.addConnectivityListener,type=Function,name=listener) 
     * @tiarg A callback method to be fired when the system connects or disconnects from the internet
     * @tiresult(for=Network.addConnectivityListener,type=Number) a callback id for the event
     */
    this->SetMethod("addConnectivityListener",&Network::_AddConnectivityListener);
    /**
     * @tiapi(method=True,name=Network.removeConnectivityListener,since=0.2) Removes a connectivity change listener
     * @tiarg(for=Network.removeConnectivityListener,type=Number,name=id) the callback id of the method
     */
    this->SetMethod("removeConnectivityListener",&Network::_RemoveConnectivityListener);

    /**
     * @tiapi(method=True,name=Network.setHTTPProxy,since=0.7)
     * @tiapi Override application proxy autodetection with a proxy URL.
     * @tiarg[String, hostname] The full proxy hostname.
     */
    this->SetMethod("setHTTPProxy", &Network::_SetHTTPProxy);
    this->SetMethod("setProxy", &Network::_SetHTTPProxy);

    /**
     * @tiapi(method=True,name=Network.getHTTPProxy,since=0.7) 
     * @tiapi Return the proxy override, if one is set.
     * @tiresult[String|null] The full proxy override URL or null if none is set.
     */
    this->SetMethod("getHTTPProxy", &Network::_GetHTTPProxy);
    this->SetMethod("getProxy", &Network::_GetHTTPProxy);

    /**
     * @tiapi(method=True,name=Network.setHTTPSProxy,since=0.7)
     * @tiapi Override application proxy autodetection with a proxy URL.
     * @tiarg[String, hostname] The full proxy hostname.
     */
    this->SetMethod("setHTTPSProxy", &Network::_SetHTTPSProxy);

    /**
     * @tiapi(method=True,name=Network.getHTTPSProxy,since=0.7)
     * @tiapi Return the proxy override, if one is set.
     * @tiresult[String|null] The full proxy override URL or null if none is set.
     */
    this->SetMethod("getHTTPSProxy", &Network::_GetHTTPSProxy);

    /**
     * @tiapi(method=True,name=Network.getInterfaces,since=0.9)
     * Get a list of interfaces active on this machine.
     * @tiresult[Array<Netowrk.Interface>] An array of active interfaces.
     */
    this->SetMethod("getInterfaces", &Network::_GetInterfaces);

    /**
     * @tiapi(method=True,name=Network.getFirstIPAddress,since=0.9)
     * Get the first IPv4 address in this machine's list of interfaces.
     * @tiarg[String, address] The first IPv4 address in this system's list of interfaces.
     */ 
    this->SetMethod("getFirstIPAddress", &Network::_GetFirstIPAddress);
    this->SetMethod("getAddress", &Network::_GetFirstIPAddress); // COMPATBILITY

    /**
     * @tiapi(method=True,name=Network.getFirstMACAddress,since=0.9)
     * Get the first MAC address in this system's list of interfaces.
     * @tiarg[String, adress] The first MAC address in this system's list of interfaces.
     */
    this->SetMethod("getFirstMACAddress", &Network::_GetFirstMACAddress);
    this->SetMethod("getMACAddress", &Network::_GetFirstMACAddress);

    this->netStatus = new NetworkStatus(this);
    this->netStatus->Start();
}
    NetworkBinding::NetworkBinding(Host* host) :
        KAccessorObject("Network"),
        host(host),
        global(host->GetGlobalObject())
    {
        GetInterfaceList();

        // methods that are available on Ti.Network
        /**
         * @tiapi(method=True,name=Network.createTCPSocket,since=0.2) Creates a TCPSocket object
         * @tiarg(for=Network.createTCPSocket,name=host,type=String) the hostname to connect to
         * @tiarg(for=Network.createTCPSocket,name=port,type=Number) the port to use
         * @tiresult(for=Network.createTCPSocket,type=Network.TCPSocket) a TCPSocket object
         */
        this->SetMethod("createTCPSocket",&NetworkBinding::_CreateTCPSocket);
        /**
         * @tiapi(method=True,name=Network.createTCPServerSocket,since=1.2) Creates a TCPServerSocket object
         * @tiarg(for=Network.createTCPServerSocket,name=callback,type=Function) the callback to receive a new connection
         * @tiresult(for=Network.createTCPServerSocket,type=Network.TCPServerSocket) a TCPServerSocket object
         */
        this->SetMethod("createTCPServerSocket",&NetworkBinding::_CreateTCPServerSocket);
        /**
         * @tiapi(method=True,name=Network.createIRCClient,since=0.2) Creates an IRCClient object
         * @tiresult(for=Network.createIRCClient,type=Network.IRCClient) an IRCClient object
         */
        this->SetMethod("createIRCClient",&NetworkBinding::_CreateIRCClient);
        /**
         * @tiapi(method=True,name=Network.createIPAddress,since=0.2) Creates an IPAddress object
         * @tiarg(for=Network.createIPAddress,name=address,type=String) the IP address
         * @tiresult(for=Network.createIPAddress,type=Network.IPAddress) an IPAddress object
         */
        this->SetMethod("createIPAddress",&NetworkBinding::_CreateIPAddress);
        /**
         * @tiapi(method=True,name=Network.createHTTPClient,since=0.3) Creates an HTTPClient object
         * @tiresult(for=Network.createHTTPClient,type=Network.HTTPClient) an HTTPClient object
         */
        this->SetMethod("createHTTPClient",&NetworkBinding::_CreateHTTPClient);
        /**
         * @tiapi(method=True,name=Network.createHTTPServer,since=0.4) Creates an HTTPServer object
         * @tiresult(for=Network.createHTTPServer,type=Network.HTTPServer) a HTTPServer object
         */
        this->SetMethod("createHTTPServer",&NetworkBinding::_CreateHTTPServer);
        /**
         * @tiapi(method=True,name=Network.createHTTPCookie,since=0.7) Creates a new HTTPCookie object
         * @tiresult(for=Network.createHTTPCookie,type=Network.HTTPCookie) a HTTPCookie object
         */
        this->SetMethod("createHTTPCookie",&NetworkBinding::_CreateHTTPCookie);
        /**
         * @tiapi(method=True,name=Network.getHostByName,since=0.2) Returns a Host object using a hostname
         * @tiarg(for=Network.getHostByName,name=name,type=String) the hostname
         * @tiresult(for=Network.getHostByName,type=Network.Host) a Host object referencing the hostname
         */
        this->SetMethod("getHostByName",&NetworkBinding::_GetHostByName);
        /**
         * @tiapi(method=True,name=Network.getHostByAddress,since=0.2) Returns a Host object using an address
         * @tiarg(for=Network.getHostByAddress,name=address,type=String) the address
         * @tiresult(for=Network.getHostByAddress,type=Network.Host) a Host object referencing the address
         */
        this->SetMethod("getHostByAddress",&NetworkBinding::_GetHostByAddress);
        /**
         * @tiapi(method=True,name=Network.encodeURIComponent,since=0.3) Encodes a URI Component
         * @tiarg(for=Network.encodeURIComponent,name=value,type=String) value to encode
         * @tiresult(for=Network.encodeURIComponent,type=String) the encoded value
         */
        this->SetMethod("encodeURIComponent",&NetworkBinding::_EncodeURIComponent);
        /**
         * @tiapi(method=True,name=Network.decodeURIComponent,since=0.3) Decodes a URI component
         * @tiarg(for=Network.decodeURIComponent,name=value,type=String) value to decode
         * @tiresult(for=Network.decodeURIComponent,type=String) the decoded value
         */
        this->SetMethod("decodeURIComponent",&NetworkBinding::_DecodeURIComponent);

        /**
         * @tiapi(method=True,name=Network.setHTTPProxy,since=0.7)
         * @tiapi Override application proxy autodetection with a proxy URL.
         * @tiarg[String, hostname] The full proxy hostname.
         */
        this->SetMethod("setHTTPProxy", &NetworkBinding::_SetHTTPProxy);
        this->SetMethod("setProxy", &NetworkBinding::_SetHTTPProxy);

        /**
         * @tiapi(method=True,name=Network.getHTTPProxy,since=0.7) 
         * @tiapi Return the proxy override, if one is set.
         * @tiresult[String|null] The full proxy override URL or null if none is set.
         */
        this->SetMethod("getHTTPProxy", &NetworkBinding::_GetHTTPProxy);
        this->SetMethod("getProxy", &NetworkBinding::_GetHTTPProxy);

        /**
         * @tiapi(method=True,name=Network.setHTTPSProxy,since=0.7)
         * @tiapi Override application proxy autodetection with a proxy URL.
         * @tiarg[String, hostname] The full proxy hostname.
         */
        this->SetMethod("setHTTPSProxy", &NetworkBinding::_SetHTTPSProxy);

        /**
         * @tiapi(method=True,name=Network.getHTTPSProxy,since=0.7)
         * @tiapi Return the proxy override, if one is set.
         * @tiresult[String|null] The full proxy override URL or null if none is set.
         */
        this->SetMethod("getHTTPSProxy", &NetworkBinding::_GetHTTPSProxy);

        /**
         * @tiapi(method=True,name=Network.getInterfaces,since=0.9)
         * Get a list of interfaces active on this machine.
         * @tiresult[Array<Netowrk.Interface>] An array of active interfaces.
         */
        this->SetMethod("getInterfaces", &NetworkBinding::_GetInterfaces);

        /**
         * @tiapi(method=True,name=Network.getFirstIPAddress,since=0.9)
         * Get the first IPv4 address in this machine's list of interfaces.
         * @tiarg[String, address] The first IPv4 address in this system's list of interfaces.
         */ 
        this->SetMethod("getFirstIPAddress", &NetworkBinding::_GetFirstIPAddress);
        this->SetMethod("getAddress", &NetworkBinding::_GetFirstIPAddress); // COMPATBILITY

        /**
         * @tiapi(method=True,name=Network.getFirstMACAddress,since=0.9)
         * Get the first MAC address in this system's list of interfaces.
         * @tiarg[String, adress] The first MAC address in this system's list of interfaces.
         */
        this->SetMethod("getFirstMACAddress", &NetworkBinding::_GetFirstMACAddress);
        this->SetMethod("getMACAddress", &NetworkBinding::_GetFirstMACAddress);
    }