Esempio n. 1
0
bool CPbl2XML::Convert(MSXML2::IXMLDOMElementPtr &library, _bstr_t &path)
{
	MSXML2::IXMLDOMElementPtr childnode = library->ownerDocument->
		createElement("childs");

	char buffer[256] = {0};

	int iResult = m_orca.LibraryDirectory((char *) path, 
		buffer, sizeof(buffer),	LibDir, (LPVOID) childnode.GetInterfacePtr());

	if(iResult != PBORCA_OK) {
		CString msg; msg.Format("FAILED: LibraryDirectory(...) : %s", (char *) path);
		log.write(msg);
		
		childnode = NULL;
		return false;
	}

	_bstr_t xpath("childs");
	MSXML2::IXMLDOMNodeListPtr childlist = library->selectNodes(xpath);

	if(childlist->length > 0) {
		library->replaceChild(childnode, childlist->item[0]);
	} else {
		library->appendChild(childnode);
	}

	// сохраняем значение комментария библиотеки
	library->setAttribute(_bstr_t("comment"), _bstr_t(buffer));

	return true;
}
Esempio n. 2
0
long CIconImgList::GetGroupCount( MSXML2::IXMLDOMElementPtr piGroups)
{
    long lCount = 0;

    MSXML2::IXMLDOMNodeListPtr piGroupsList;
    piGroupsList = piGroups->selectNodes( _bstr_t( _T( "GROUP")));
    if( NULL != piGroupsList)
    {
        long lChildCount = piGroupsList->Getlength();

        lCount = lChildCount;

        MSXML2::IXMLDOMElementPtr piGroupChild;
        for( long lIndex = 0; lIndex < lChildCount; lIndex++)
        {
            piGroupChild = piGroupsList->Getitem( lIndex);
            lCount += GetGroupCount( piGroupChild);
        }
    }
    return lCount;
}
Esempio n. 3
0
BOOL parseRootTsl(PSTR IN url, TCertListPtr IN pCertList, TURLListPtr IN URLListPtr) 
{
	BOOL ret;
	
	IXMLDOMDocument2Ptr pXMLDoc;
	LPWSTR pInsertStrings[2] = {NULL, NULL};
	LPCWSTR searchTerm;
	MSXML2::IXMLDOMElementPtr pXMLDocElement = NULL;
	MSXML2::IXMLDOMNodeListPtr pXMLDomNodeList = NULL;
	INT i;

	pInsertStrings[0] = (LPWSTR) _strdup(url);
	ret = ReportEvent(hEventLog, EVENTLOG_INFORMATION_TYPE, CAT_TSL_PARSER, TSL_PARSE_START, NULL, 1, 0, (LPCWSTR*)pInsertStrings, NULL);

	printf("Opening %s...\n", url);

	// add currently processed URL
	ret = addUrl( url, &URLListPtr);

	// initialize XML trees
	CoInitialize(NULL);

	// attempt to fetch TSL file from Internet
	pXMLDoc = TslFetch(url);

	try{

#define DSIG_NS L"xmlns:tsl='http://uri.etsi.org/02231/v2#' xmlns:tslx='http://uri.etsi.org/02231/v2/additionaltypes#'"

		// Initialize XML parser
		pXMLDoc->async =  VARIANT_FALSE;
		pXMLDoc->setProperty("SelectionLanguage", "XPath");		// tell MSXML that we will use XPath syntax
		pXMLDoc->setProperty("SelectionNamespaces",	DSIG_NS);	// set namespace
		
		pXMLDocElement = pXMLDoc->documentElement;
	
		// Structure for root TSL (root=true)
		// OtherTSLPointer
		//	+- ServiceDigitalIdentities
		//		+- ServiceDigitalIdentity
		//			+- DigitalId
		//				+- X509Certificate	CERT - we add this to GlobalCertList
		//	+- TSLLocation					SUB-TSL - we parse this recursively
		//	+- AdditionalInformation
		//		+- OtherInformation*
		//			+- tslx:MimeType				MIME - need this to skip PDF files
		//      +- OtherInformation*
		//          +- SchemeOperatorName
		//              +- Name
		
		searchTerm = L"//tsl:TSLLocation[../tsl:AdditionalInformation/tsl:OtherInformation/tslx:MimeType='application/vnd.etsi.tsl+xml']";
		pXMLDomNodeList = pXMLDocElement->selectNodes(searchTerm);
		INT count = 0;
		count = pXMLDomNodeList->length;
		wprintf(L"XML query: %s\n", searchTerm);
		printf("Found %d nodes.\n", count);

		for(i=0; i<count; i++) {
			// process sub-TSL location
			MSXML2::IXMLDOMElementPtr current_elem = NULL;
			MSXML2::IXMLDOMElementPtr cert_elem = NULL;
			MSXML2::IXMLDOMElementPtr name_elem = NULL;
			BSTR tagName, newUrl;
			PSTR copyNewUrl;
			
			current_elem = pXMLDomNodeList->item[i]; // for root we are at TSLLocation level, for child at 
			tagName = current_elem->tagName;
			newUrl =  current_elem->text;

			copyNewUrl = (PSTR) malloc(wcslen(newUrl)*2);
			// convert URL to PSTR as this is what TslFetch expects later on
			WideCharToMultiByte(CP_ACP, 0, newUrl, -1, copyNewUrl, wcslen(newUrl)*2, NULL, NULL);

			// this part is recursively calling parseTSL()
			// need to check duplicate urls because most TSL will publish reference to EU TSL
			if(isKnownUrl((PSTR) copyNewUrl, URLListPtr) == false) {

				// fetch operator name for current certificate
				name_elem = current_elem->selectSingleNode(L"../tsl:AdditionalInformation/tsl:OtherInformation/tsl:SchemeOperatorName/tsl:Name");
				assert(name_elem != NULL);
				wprintf(L"Child TSL operator name=%s\n", (LPWSTR) name_elem->text);

				// if this TSL wasn't previously parse, do it now
				wprintf(L"Found new TSL %s=%s\n", (LPWSTR) tagName, (LPWSTR) newUrl);
				ret = parseChildTsl( copyNewUrl, pCertList, URLListPtr);

			}

			// fetch certificate
			/* this is not really needed until we verify TSL signatures
			cert_elem = current_elem->selectSingleNode(L"../tsl:ServiceDigitalIdentities/tsl:ServiceDigitalIdentity/tsl:DigitalId/tsl:X509Certificate");
			if(cert_elem == NULL) {
				printf("No certificate found in TSL: %s\n", copyNewUrl);
			} else {
				printf("Adding cert to urllist, size=%d\n", certCount(pCertList));
				// add certificate to global certificate list for further processing
				ret = addCert((PSTR) cert_elem->text, &pCertList);
			}
			*/

			if(certCount(pCertList) > 4) // XXX for faster debugging just process 4 certs
				return true;

		} /* end of XML parsing loop */

	} // end of try block

	catch(_com_error &e)
	{
		dump_com_error(e);
 		return false;
	}
	return true;
} // end of parseTSL
Esempio n. 4
0
BOOL parseChildTsl(PSTR IN url, TCertListPtr IN pCertList, TURLListPtr IN URLListPtr) 
{
	BOOL ret;
	
	IXMLDOMDocument2Ptr pXMLDoc;
	LPWSTR pInsertStrings[2] = {NULL, NULL};
	LPCWSTR searchTerm;
	MSXML2::IXMLDOMElementPtr pXMLDocElement = NULL;
	MSXML2::IXMLDOMNodeListPtr pXMLDomNodeList = NULL;
	INT i;

	pInsertStrings[0] = (LPWSTR) _strdup(url);
	ret = ReportEvent(hEventLog, EVENTLOG_INFORMATION_TYPE, CAT_TSL_PARSER, TSL_PARSE_START, NULL, 1, 0, (LPCWSTR*)pInsertStrings, NULL);

	printf("Opening child TSL %s...\n", url);

	// add currently processed URL
	ret = addUrl( url, &URLListPtr);

	// initialize XML trees
	CoInitialize(NULL);

	// attempt to fetch TSL file from Internet
	pXMLDoc = TslFetch(url);

	try{

#define DSIG_NS L"xmlns:tsl='http://uri.etsi.org/02231/v2#' xmlns:tslx='http://uri.etsi.org/02231/v2/additionaltypes#'"

		// Initialize XML parser
		pXMLDoc->async =  VARIANT_FALSE;
		pXMLDoc->setProperty("SelectionLanguage", "XPath");		// tell MSXML that we will use XPath syntax
		pXMLDoc->setProperty("SelectionNamespaces",	DSIG_NS);	// set namespace
		
		pXMLDocElement = pXMLDoc->documentElement;
	
		// Structure for child TSL (root=false)
		//tsl:TrustServiceProvider
		//	tsl:TSPInformation
		//		tsl:TSPName
		//			tsl:Name[xml:lang='en']
		//	tsl:TSPServices
		//		tsl:TSPService
		//			tsl:ServiceInformation
		//				tsl:ServiceTypeIdentifier
		//				tsl:ServiceDigitalIdentity
		//					tsl:DigitalId
		//						tsl:X509Certificate
 
		searchTerm = L"//tsl:TSPService";
		pXMLDomNodeList = pXMLDocElement->selectNodes(searchTerm);
		INT count = 0;
		count = pXMLDomNodeList->length;
		wprintf(L"XML query: %s\n", searchTerm);
		printf("Found %d nodes.\n", count);

		for(i=0; i<count; i++) {
			// process sub-TSL location
			MSXML2::IXMLDOMElementPtr current_elem = NULL;
			MSXML2::IXMLDOMElementPtr cert_elem = NULL;
			MSXML2::IXMLDOMElementPtr name_elem = NULL;
			MSXML2::IXMLDOMElementPtr service_elem = NULL;
			MSXML2::IXMLDOMElementPtr status_elem = NULL;
			
			current_elem = pXMLDomNodeList->item[i]; // at tsl:TSPService level
			wprintf(L"Found %s\n", (LPWSTR) current_elem->tagName);

			// fetch operator name for current certificate
			name_elem = current_elem->selectSingleNode(L"../../tsl:TSPInformation/tsl:TSPName/tsl:Name[@xml:lang='en']");
			assert(name_elem != NULL);
			wprintf(L"Operator name=%s\n", (LPWSTR) name_elem->text);

			// fetch service name identifier (QC, TSP etc)
			// Annex D.2 page 73 of ETSI TS 102 200
			status_elem = current_elem->selectSingleNode(L"tsl:ServiceInformation/tsl:ServiceTypeIdentifier");
			assert(status_elem != NULL);
			wprintf(L"Service id=%s\n", (LPWSTR) status_elem->text);

			// fetch service status identifier (active, discontinued etc)
			// Annex L.2 page 100 of ETSI TS 102 200
			service_elem = current_elem->selectSingleNode(L"tsl:ServiceInformation/tsl:ServiceStatus");
			assert(service_elem != NULL);
			wprintf(L"Service status=%s\n", (LPWSTR) service_elem->text);
			//assert( wcscmp(L"http://uri.etsi.org/TrstSvc/eSigDir-1999-93-EC-TrustedList/Svcstatus/undersupervision", status_elem->text) == 0);

			// fetch certificate
			cert_elem = current_elem->selectSingleNode(L"tsl:ServiceInformation/tsl:ServiceDigitalIdentity/tsl:DigitalId/tsl:X509Certificate");
			assert(cert_elem != NULL);
			printf("Adding cert to urllist, size=%d\n", certCount(pCertList));
			// add certificate to global certificate list for further processing
			ret = addCert((PSTR) cert_elem->text, &pCertList);

			if(certCount(pCertList) > 20) // XXX for faster debugging
				return true;

		} /* end of XML parsing loop */

	} // end of try block

	catch(_com_error &e)
	{
		dump_com_error(e);
 		return false;
	}
	return true;
} // end of parseTSL
Esempio n. 5
0
BOOL CVoucherFile::LoadXml(const CString& strFileName, VoucherFileInfo &voucherInfo)
{	
	CString strFullPath = strFileName;
	BOOL bRet = FALSE;
	try
	{
		voucherInfo.Reset();

		::CoInitialize(NULL);
		MSXML2::IXMLDOMDocumentPtr pXmlDoc(__uuidof(MSXML2::DOMDocument));
		MSXML2::IXMLDOMElementPtr pRootNode = NULL;
		CString strTemp;
		
		pXmlDoc->put_async(VARIANT_FALSE);
		pXmlDoc->load(_bstr_t(strFullPath.AllocSysString()));
		pRootNode = pXmlDoc->GetdocumentElement();
		if (pRootNode == NULL)
			return FALSE;

		// 错误类型
		MSXML2::IXMLDOMElementPtr pNode = pRootNode->selectSingleNode(_T("error"));
		if (pNode != NULL)
		{
			voucherInfo.strError = _GetNodeText(pNode);
		}

		// 模型信息
		pNode = pRootNode->selectSingleNode(_T("model"));
		if (pNode != NULL)
		{
			// 版本
			MSXML2::IXMLDOMElementPtr pChildNode = pNode->selectSingleNode(_T("version"));
			if (pChildNode != NULL)
				voucherInfo.strModelVersion = _GetNodeText(pChildNode);

			// 日期
			pChildNode = pNode->selectSingleNode(_T("date"));
			if (pChildNode != NULL)
				voucherInfo.strModelDate = _GetNodeText(pChildNode);

			// 时间
			pChildNode = pNode->selectSingleNode(_T("time"));
			if (pChildNode != NULL)
				voucherInfo.strModelTime = _GetNodeText(pChildNode);

			// 大小
			pChildNode = pNode->selectSingleNode(_T("size"));
			if (pChildNode != NULL)
				voucherInfo.strModelSize = _GetNodeText(pChildNode);
		}
		
		// 用户列表
		MSXML2::IXMLDOMElementPtr pUserNode = pRootNode->selectSingleNode(_T("nodeinfo"));
		if (pUserNode != NULL)
		{
			CString strText;
			MSXML2::IXMLDOMNodeListPtr pList = pUserNode->selectNodes(_bstr_t("username"));
			if (pList != NULL)
			{
				int nUserCount = pList->Getlength();
				for(int i = 0; i < nUserCount; i++)
				{
					MSXML2::IXMLDOMNodePtr pChiledNode = pList->Getitem(i);
					if (pChiledNode != NULL)
					{
						strText = _GetNodeText(pChiledNode);
						voucherInfo.vecUser.push_back(strText);
					}
				}
			}
		}
		bRet = TRUE;
	}
	catch (...)
	{
		bRet = FALSE;
	}
	return bRet;
}
Esempio n. 6
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;
}