Exemple #1
0
result_t os_base::networkInfo(v8::Local<v8::Object> &retVal)
{
    unsigned long size = 0;
    IP_ADAPTER_ADDRESSES *adapter_addresses;
    IP_ADAPTER_ADDRESSES *adapter_address;
    IP_ADAPTER_UNICAST_ADDRESS_XP *unicast_address;

    if (GetAdaptersAddresses(AF_UNSPEC, 0, NULL, NULL, &size)
            != ERROR_BUFFER_OVERFLOW)
        return CHECK_ERROR(LastError());

    adapter_addresses = (IP_ADAPTER_ADDRESSES *) malloc(size);
    if (!adapter_addresses)
        return CHECK_ERROR(LastError());

    if (GetAdaptersAddresses(AF_UNSPEC, 0, NULL, adapter_addresses, &size)
            != ERROR_SUCCESS)
        return CHECK_ERROR(LastError());

    retVal = v8::Object::New(isolate);

    for (adapter_address = adapter_addresses; adapter_address != NULL;
            adapter_address = adapter_address->Next)
    {
        v8::Local<v8::Array> ret;
        v8::Local<v8::Object> o;
        v8::Local<v8::String> name, ipaddr, family;

        if (adapter_address->OperStatus != IfOperStatusUp)
            continue;

        name = v8::String::NewFromUtf8(isolate, UTF8_A(adapter_address->FriendlyName));

        ret = v8::Array::New(isolate);
        retVal->Set(name, ret);

        unicast_address =
            (IP_ADAPTER_UNICAST_ADDRESS_XP *) adapter_address->FirstUnicastAddress;
        while (unicast_address)
        {
            inetAddr *sock_addr = (inetAddr *) unicast_address->Address.lpSockaddr;

            o = v8::Object::New(isolate);
            o->Set(v8::String::NewFromUtf8(isolate, "address"), v8::String::NewFromUtf8(isolate, sock_addr->str().c_str()));
            o->Set(v8::String::NewFromUtf8(isolate, "family"), sock_addr->family() == net_base::_AF_INET6 ?
                   v8::String::NewFromUtf8(isolate, "IPv6") : v8::String::NewFromUtf8(isolate, "IPv4"));
            o->Set(v8::String::NewFromUtf8(isolate, "internal"),
                   adapter_address->IfType == IF_TYPE_SOFTWARE_LOOPBACK ?
                   v8::True(isolate) : v8::False(isolate));

            ret->Set(ret->Length(), o);

            unicast_address = unicast_address->Next;
        }
    }

    free(adapter_addresses);

    return 0;
}
Exemple #2
0
		// IInternetProtocol
		STDMETHODIMP Start(LPCWSTR szUrl, IInternetProtocolSink *pIProtSink,
		                   IInternetBindInfo *pIBindInfo, DWORD grfSTI,
		                   HANDLE_PTR dwReserved)
		{
			if (!szUrl || !pIProtSink)
				return E_POINTER;

			if (grfSTI & PI_PARSE_URL)
				return S_OK;

			m_pProtSink = pIProtSink;
			m_pProtSink->AddRef();

			result_t hr = fs_base::cc_open(UTF8_A(szUrl + 3), "r", m_file);
			if (hr < 0)
				return INET_E_OBJECT_NOT_FOUND;

			LPWSTR pwszMimeType = 0;
			if (SUCCEEDED(FindMimeFromData(NULL, szUrl, NULL, 0, NULL, 0,
			                               &pwszMimeType, 0)))
				m_pProtSink->ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE,
				                            pwszMimeType);
			else m_pProtSink->ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE,
				                                 L"text/html");
			if (pwszMimeType)
				CoTaskMemFree(pwszMimeType);

			return m_pProtSink->ReportData(
			           BSCF_FIRSTDATANOTIFICATION |
			           BSCF_LASTDATANOTIFICATION |
			           BSCF_DATAFULLYAVAILABLE, 1, 0);
		}
Exemple #3
0
std::string getResultMessage(result_t hr)
{
    static const char *s_errors[] =
    {
        "",
        // CALL_E_BADPARAMCOUNT
        "Invalid number of parameters.",
        // CALL_E_PARAMNOTOPTIONAL
        "Parameter not optional.",
        // CALL_E_BADVARTYPE
        "The input parameter is not a valid type.",
        // CALL_E_INVALIDARG
        "Invalid argument.",
        // CALL_E_TYPEMISMATCH
        "The argument could not be coerced to the specified type.",
        // CALL_E_OUTRANGE
        "Value is out of range.",

        // CALL_E_CONSTRUCTOR
        "Constructor cannot be called as a function.",
        // CALL_E_NOTINSTANCE
        "Object is not an instance of declaring class.",
        // CALL_E_INVALID_CALL
        "Invalid procedure call.",
        // CALL_E_REENTRANT_CALL
        "Re-entrant calls are not allowed.",
        // CALL_E_INVALID_DATA
        "Invalid input data.",
        // CALL_E_BADINDEX
        "Index was out of range.",
        // CALL_E_OVERFLOW
        "Memory overflow error.",
        // CALL_E_EMPTY
        "Collection is empty.",
        // CALL_E_PENDDING
        "Operation now in progress.",
        // CALL_E_NOSYNC
        "Operation not support synchronous call.",
        // CALL_E_NOASYNC
        "Operation not support asynchronous call.",
        // CALL_E_INTERNAL
        "Internal error.",
        // CALL_E_RETURN_TYPE
        "Invalid return type.",
        // CALL_E_EXCEPTION
        "Exception occurred.",
        // CALL_E_JAVASCRIPT
        "Javascript error."
    };

    if (hr == CALL_E_EXCEPTION)
    {
        std::string s = Runtime::errMessage();

        if (s.length() > 0)
            return s;
    }

    if (hr > CALL_E_MIN && hr < CALL_E_MAX)
        return fmtString(hr, s_errors[CALL_E_MAX - hr]);

    hr = -hr;

#ifdef _WIN32
    WCHAR MsgBuf[1024];

    if (FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
                       NULL, hr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), MsgBuf, 1024, NULL ))
    {
        std::string s = fmtString(hr, UTF8_A(MsgBuf));
        return s;
    }

    return fmtString(hr, "Unknown error.");
#else
    return fmtString(hr, strerror(hr));
#endif
}