示例#1
0
void devsXMLInitialize(void)
{
	// initialize only if 10 minutes have passed since last init
	long lMinutes = getDBCacheAge()/60;
	
	if ((lMinutes < 0) || (lMinutes > 10))
	{
		CURL *curl = 0;
		CURLcode res;
    
		ohciDb.memory = (char *)malloc(1);  /* will be grown as needed by the realloc above */ 
		ohciDb.size = 0;    /* no data at this point */ 
        
		curl_global_init(CURL_GLOBAL_ALL);
		curl = curl_easy_init();
    
		if (curl)
		{
			curl_easy_setopt(curl, CURLOPT_URL, "http://www.tctechnologies.tc/appdata/ohci1394db.xml/");
			curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
			curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_ALL);
			curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 5L);
			curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); // the http URL redirects to an https URL
			curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
			curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);
			curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&ohciDb);
			res = curl_easy_perform(curl);
			if (CURLE_OK != res)
			{
				printf ("curl error %d \n", (int)res);
			}
//			printf("%s", ohciDb.memory);
			
			curl_easy_cleanup(curl);
		}
		
		timeval curTime;
		gettimeofday (&curTime, NULL);
		gLastLoadTime = curTime.tv_sec;
		
		parseOhciDB();
	}
}
示例#2
0
long findControllerInfoXML(fwi::OHCI1394_DEV_INFO * devInfo)
{
    MSXML2::IXMLDOMNodeList *pNodes=NULL;
    MSXML2::IXMLDOMNode *pNode=NULL;
    static VARIANT_BOOL status;
    static VARIANT var;
    BSTR bstr = NULL;
    HRESULT hr;
    long num_controllers;
    long num_attributes;
    BOOL bVendorMatch = FALSE;
    BOOL bDeviceMatch = FALSE;
    long lMinutes = 0;

    MSXML2::IXMLDOMElementPtr pXMLDocElement = NULL;
    MSXML2::IXMLDOMNodeListPtr pXMLDomNodeList = NULL;

    VariantInit(&var);

    // the URL below has a server-side redirect to the actual xml file in the svn repo
    var = VariantString(L"http://www.tctechnologies.tc/appdata/ohci1394db.xml");

    // reload online file if cached data is stale
    lMinutes = getDBCacheAge();
    if ( (lMinutes < 0) || (lMinutes > 10) )
    {
        if (gpXMLDom) gpXMLDom->Release();
        gpXMLDom = DomFromCOM();
        if (!gpXMLDom) return 1;

        HRCALL(gpXMLDom->load(var, &status), "dom->load(): ");

        if (status!=VARIANT_TRUE)
        {
            if (&var) VariantClear(&var);

            return FWI_ERROR_FILE_NOT_FOUND;
        }
        else
        {
            GetLocalTime(&gLastLoadTime);
        }
    }

    gpXMLDom->get_documentElement(&pXMLDocElement);
    pXMLDocElement->selectNodes(TEXT("//controller"), &pXMLDomNodeList);
    pXMLDomNodeList->get_length(&num_controllers);

    for (long n=0; n<num_controllers; n++)
    {
        TCHAR buf[32];
        StringCchPrintf( buf, 20, TEXT("//controller[%i]/*"), n);

        // Query the node-set.
        HRCALL(gpXMLDom->selectNodes(buf, &pNodes), "selectNodes ");
        if (!pNodes) {
            ReportParseError(gpXMLDom, "Error while calling selectNodes ");
        }
        else {
            HRCALL(pNodes->get_length(&num_attributes), "get_length: ");
            for (long i=0; i<num_attributes; i++) {
                if (pNode) pNode->Release();
                HRCALL(pNodes->get_item(i, &pNode), "get_item: ");
                if (bstr) SysFreeString(bstr);
                HRCALL(pNode->get_nodeName(&bstr), "get_nodeName: ");

                if (_tcsicmp((TCHAR*)bstr,TEXT("vendorid"))==0)
                {
                    BSTR nodeTextStr;
                    HRCALL(pNode->get_text(&nodeTextStr), "get_text: ");
                    if (_tcsicmp((TCHAR*)nodeTextStr, devInfo->vendorId)==0)
                    {
                        bVendorMatch = TRUE;
                    }
                    SysFreeString(nodeTextStr);
                }
                else if (_tcsicmp((TCHAR*)bstr,TEXT("deviceid"))==0)
                {
                    BSTR nodeTextStr;
                    HRCALL(pNode->get_text(&nodeTextStr), "get_text: ");
                    if (_tcsicmp((TCHAR*)nodeTextStr, devInfo->deviceId)==0)
                    {
                        bDeviceMatch = TRUE;
                    }
                    SysFreeString(nodeTextStr);
                }

                if (bVendorMatch)
                {
                    if ( (_tcsicmp((TCHAR*)bstr,TEXT("vendorname"))==0) && (_tcsicmp(TEXT("Unknown"),&devInfo->vendorName[0]))==0 )
                    {
                        BSTR nodeTextStr;
                        HRCALL(pNode->get_text(&nodeTextStr), "get_text: ");
                        _tcscpy_s(&devInfo->vendorName[0], VENDOR_SIZE, nodeTextStr);
                        SysFreeString(nodeTextStr);
                    }
                }

                if (bVendorMatch && bDeviceMatch)
                {
                    devInfo->bFound = TRUE;
                    if (_tcsicmp((TCHAR*)bstr,TEXT("chipset"))==0)
                    {
                        BSTR nodeTextStr;
                        HRCALL(pNode->get_text(&nodeTextStr), "get_text: ");
                        _tcscpy_s(&devInfo->chipset[0], CHIPSET_SIZE, nodeTextStr);
                        SysFreeString(nodeTextStr);
                    }
                    else if (_tcsicmp((TCHAR*)bstr,TEXT("maxtx"))==0)
                    {
                        BSTR nodeTextStr;
                        HRCALL(pNode->get_text(&nodeTextStr), "get_text: ");
                        _tcscpy_s(&devInfo->maxTx[0], NUM_STR_SIZE, nodeTextStr);
                        SysFreeString(nodeTextStr);
                    }
                    else if (_tcsicmp((TCHAR*)bstr,TEXT("maxrx"))==0)
                    {
                        BSTR nodeTextStr;
                        HRCALL(pNode->get_text(&nodeTextStr), "get_text: ");
                        _tcscpy_s(&devInfo->maxRx[0], NUM_STR_SIZE, nodeTextStr);
                        SysFreeString(nodeTextStr);
                    }
                    else if (_tcsicmp((TCHAR*)bstr,TEXT("maxspeed"))==0)
                    {
                        BSTR nodeTextStr;
                        HRCALL(pNode->get_text(&nodeTextStr), "get_text: ");
                        swscanf_s(nodeTextStr, TEXT("%04d"), &devInfo->maxspeed);
                        SysFreeString(nodeTextStr);
                    }
                    else if (_tcsicmp((TCHAR*)bstr,TEXT("notes"))==0)
                    {
                        BSTR nodeTextStr;
                        HRCALL(pNode->get_text(&nodeTextStr), "get_text: ");
                        _tcscpy_s(&devInfo->notes[0], NOTES_SIZE, nodeTextStr);
                        SysFreeString(nodeTextStr);
                    }
                    else if (_tcsicmp((TCHAR*)bstr,TEXT("support"))==0)
                    {
                        BSTR nodeTextStr;
                        HRCALL(pNode->get_text(&nodeTextStr), "get_text: ");
                        swscanf_s(nodeTextStr, TEXT("%04x"), &devInfo->support);
                        devInfo->bValid = true;
                        SysFreeString(nodeTextStr);
                        if (&var) VariantClear(&var);
                        if (bstr) SysFreeString(bstr);
                        if (pNodes) pNodes->Release();
                        if (pNode) pNode->Release();

                        return FWI_NO_ERROR;
                    }
                }
            }
        }
    }
clean:
    if (&var) VariantClear(&var);
    if (bstr) SysFreeString(bstr);
    if (pNodes) pNodes->Release();
    if (pNode) pNode->Release();

    return FWI_ERROR_END_OF_FILE;
}