Ejemplo n.º 1
0
// Does parsing; indicates whether the parsing was successful or not
bool XML_Configure::DoParse()
{
	// Sanity check
	if (!CurrentElement) return false;

	// Create the parser
	Parser = XML_ParserCreate("iso-8859-1");
        XML_SetUnknownEncodingHandler(Parser, XML_JapaneseEncodingHandler, NULL);

	// Set up the callbacks
	XML_SetUserData(Parser, this);
	XML_SetElementHandler(Parser, StaticStartElement, StaticEndElement);
	XML_SetCharacterDataHandler(Parser, StaticCharacterData);
	
	NumInterpretErrors = 0;
	LastOne = true;
	do
	{
		if (!GetData())
		{
			// Report a read error
			ReportReadError();
			XML_ParserFree(Parser);
			return false;
		}

		// Expat should really be using size_t for BufLen
		if (!XML_Parse(Parser, Buffer, (int)BufLen, LastOne))
		{
			// Report a parse error
			ReportParseError(
				XML_ErrorString(XML_GetErrorCode(Parser)),
					XML_GetCurrentLineNumber(Parser));

			XML_ParserFree(Parser);
			return false;
		}
		if (RequestAbort())
		{
			XML_ParserFree(Parser);
			return false;
		}
	}
	while (!LastOne);

	XML_ParserFree(Parser);
	return (NumInterpretErrors == 0);
}
Ejemplo n.º 2
0
QStringList DicomImageSet::getOrderedDcmFiles(const QString &datasetFileName, const QString & queryString)
{
    HRESULT hr = S_OK;
    IXMLDOMDocument *pXMLDom = NULL;
    IXMLDOMNodeList *pFileNodes = NULL;
    VARIANT_BOOL varStatus;
    VARIANT varFileName;
	BSTR bstrQuery;

	QStringList fileList;

    CHK_HR(CreateAndInitDOM(&pXMLDom));

	CHK_HR(VariantFromString(datasetFileName.toStdWString().c_str(), varFileName));
    CHK_HR(pXMLDom->load(varFileName, &varStatus));
    if (varStatus != VARIANT_TRUE)
    {
        CHK_HR(ReportParseError(pXMLDom, "Failed to load DOM from stocks.xml."));
    }

    bstrQuery = SysAllocString(queryString.toStdWString().c_str());
    CHK_ALLOC(bstrQuery);
    CHK_HR(pXMLDom->selectNodes(bstrQuery, &pFileNodes));
	if (pFileNodes)
	{
		long nFiles;
		CHK_HR(pFileNodes->get_length(&nFiles));
		for (long i=0; i<nFiles; ++i)
		{
			VARIANT varValue;
			IXMLDOMNode * pFile = NULL;
			CHK_HR(pFileNodes->get_item(i, &pFile));
			CHK_HR(GetAttributeFromNode(pFile, L"path", &varValue));
			fileList <<QString::fromWCharArray(_bstr_t(varValue));
			SAFE_RELEASE(pFile);
		}
	}

CleanUp:
	SAFE_RELEASE(pXMLDom);
	SAFE_RELEASE(pFileNodes);
	return fileList;
}
Ejemplo n.º 3
0
QString DicomImageSet::getDTIFileName(const QString &datasetFolderName, const QString &queryString)
{
	QString datasetFileName = datasetFolderName+DATASET_FILE_NAME;
	HRESULT hr = S_OK;
	IXMLDOMDocument *pXMLDom = NULL;
	IXMLDOMNode *pFileNode = NULL;
	VARIANT_BOOL varStatus;
	VARIANT varFileName;
	BSTR bstrQuery;

	QStringList fileList;

	CHK_HR(CreateAndInitDOM(&pXMLDom));

	CHK_HR(VariantFromString(datasetFileName.toStdWString().c_str(), varFileName));
	CHK_HR(pXMLDom->load(varFileName, &varStatus));
	if (varStatus != VARIANT_TRUE)
	{
		CHK_HR(ReportParseError(pXMLDom, "Failed to load DOM from stocks.xml."));
	}

	bstrQuery = SysAllocString(QString(queryString+"/DTI").toStdWString().c_str());
	CHK_ALLOC(bstrQuery);
	CHK_HR(pXMLDom->selectSingleNode(bstrQuery, &pFileNode));
	if (pFileNode)
	{
		VARIANT varValue;
		CHK_HR(GetAttributeFromNode(pFileNode, L"file_name", &varValue));
		return QString::fromWCharArray(_bstr_t(varValue));
	}

CleanUp:
	SAFE_RELEASE(pXMLDom);
	SAFE_RELEASE(pFileNode);
	return QString();
}
void
nsMathMLmpaddedFrame::ProcessAttributes()
{
  /*
  parse the attributes

  width  = [+|-] unsigned-number (% [pseudo-unit] | pseudo-unit | h-unit | namedspace)
  height = [+|-] unsigned-number (% [pseudo-unit] | pseudo-unit | v-unit | namedspace)
  depth  = [+|-] unsigned-number (% [pseudo-unit] | pseudo-unit | v-unit | namedspace)
  lspace = [+|-] unsigned-number (% [pseudo-unit] | pseudo-unit | h-unit | namedspace)
  voffset= [+|-] unsigned-number (% [pseudo-unit] | pseudo-unit | v-unit | namedspace)
  */

  nsAutoString value;

  /* The REC says:
  There is one exceptional element, <mpadded>, whose attributes cannot be 
  set with <mstyle>. When the attributes width, height and depth are specified
  on an <mstyle> element, they apply only to the <mspace/> element. Similarly, 
  when lspace is set with <mstyle>, it applies only to the <mo> element. To be
  consistent, the voffset attribute of the mpadded element can not be set on
  mstyle. 
  */

  // See if attributes are local, don't access mstyle !

  // width
  mWidthSign = NS_MATHML_SIGN_INVALID;
  GetAttribute(mContent, nullptr, nsGkAtoms::width, value);
  if (!value.IsEmpty()) {
    if (!ParseAttribute(value, mWidthSign, mWidth, mWidthPseudoUnit)) {      
      ReportParseError(nsGkAtoms::width->GetUTF16String(), value.get());
    }
  }

  // height
  mHeightSign = NS_MATHML_SIGN_INVALID;
  GetAttribute(mContent, nullptr, nsGkAtoms::height, value);
  if (!value.IsEmpty()) {
    if (!ParseAttribute(value, mHeightSign, mHeight, mHeightPseudoUnit)) {
      ReportParseError(nsGkAtoms::height->GetUTF16String(), value.get());
    }
  }

  // depth
  mDepthSign = NS_MATHML_SIGN_INVALID;
  GetAttribute(mContent, nullptr, nsGkAtoms::depth_, value);
  if (!value.IsEmpty()) {
    if (!ParseAttribute(value, mDepthSign, mDepth, mDepthPseudoUnit)) {
      ReportParseError(nsGkAtoms::depth_->GetUTF16String(), value.get());
    }
  }

  // lspace
  mLeadingSpaceSign = NS_MATHML_SIGN_INVALID;
  GetAttribute(mContent, nullptr, nsGkAtoms::lspace_, value);
  if (!value.IsEmpty()) {
    if (!ParseAttribute(value, mLeadingSpaceSign, mLeadingSpace, 
                        mLeadingSpacePseudoUnit)) {
      ReportParseError(nsGkAtoms::lspace_->GetUTF16String(), value.get());
    }
  }

  // voffset
  mVerticalOffsetSign = NS_MATHML_SIGN_INVALID;
  GetAttribute(mContent, nullptr, nsGkAtoms::voffset_, value);
  if (!value.IsEmpty()) {
    if (!ParseAttribute(value, mVerticalOffsetSign, mVerticalOffset,
                        mVerticalOffsetPseudoUnit)) {
      ReportParseError(nsGkAtoms::voffset_->GetUTF16String(), value.get());
    }
  }
  
}
void
nsMathMLmpaddedFrame::ProcessAttributes()
{
  /*
  parse the attributes

  width  = [+|-] unsigned-number (% [pseudo-unit] | pseudo-unit | h-unit | namedspace)
  height = [+|-] unsigned-number (% [pseudo-unit] | pseudo-unit | v-unit | namedspace)
  depth  = [+|-] unsigned-number (% [pseudo-unit] | pseudo-unit | v-unit | namedspace)
  lspace = [+|-] unsigned-number (% [pseudo-unit] | pseudo-unit | h-unit | namedspace)
  voffset= [+|-] unsigned-number (% [pseudo-unit] | pseudo-unit | v-unit | namedspace)
  */

  nsAutoString value;

  // width
  mWidthSign = NS_MATHML_SIGN_INVALID;
  mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::width, value);
  if (!value.IsEmpty()) {
    if (!ParseAttribute(value, mWidthSign, mWidth, mWidthPseudoUnit)) {      
      ReportParseError(nsGkAtoms::width->GetUTF16String(), value.get());
    }
  }

  // height
  mHeightSign = NS_MATHML_SIGN_INVALID;
  mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::height, value);
  if (!value.IsEmpty()) {
    if (!ParseAttribute(value, mHeightSign, mHeight, mHeightPseudoUnit)) {
      ReportParseError(nsGkAtoms::height->GetUTF16String(), value.get());
    }
  }

  // depth
  mDepthSign = NS_MATHML_SIGN_INVALID;
  mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::depth_, value);
  if (!value.IsEmpty()) {
    if (!ParseAttribute(value, mDepthSign, mDepth, mDepthPseudoUnit)) {
      ReportParseError(nsGkAtoms::depth_->GetUTF16String(), value.get());
    }
  }

  // lspace
  mLeadingSpaceSign = NS_MATHML_SIGN_INVALID;
  mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::lspace_, value);
  if (!value.IsEmpty()) {
    if (!ParseAttribute(value, mLeadingSpaceSign, mLeadingSpace, 
                        mLeadingSpacePseudoUnit)) {
      ReportParseError(nsGkAtoms::lspace_->GetUTF16String(), value.get());
    }
  }

  // voffset
  mVerticalOffsetSign = NS_MATHML_SIGN_INVALID;
  mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::voffset_, value);
  if (!value.IsEmpty()) {
    if (!ParseAttribute(value, mVerticalOffsetSign, mVerticalOffset,
                        mVerticalOffsetPseudoUnit)) {
      ReportParseError(nsGkAtoms::voffset_->GetUTF16String(), value.get());
    }
  }
  
}
Ejemplo n.º 6
0
void queryNodes()
{
    HRESULT hr = S_OK;
    IXMLDOMDocument *pXMLDom = NULL;
    IXMLDOMNodeList *pNodes = NULL;
    IXMLDOMNode *pNode = NULL;

    BSTR bstrQuery1 = NULL;
    BSTR bstrQuery2 = NULL;
    BSTR bstrNodeName = NULL;
    BSTR bstrNodeValue = NULL;
    VARIANT_BOOL varStatus;
    VARIANT varFileName;
    VariantInit(&varFileName);

    CHK_HR(CreateAndInitDOM(&pXMLDom));

    CHK_HR(VariantFromString(L"stocks.xml", varFileName));
    CHK_HR(pXMLDom->load(varFileName, &varStatus));
    if (varStatus != VARIANT_TRUE)
    {
        CHK_HR(ReportParseError(pXMLDom, "Failed to load DOM from stocks.xml."));
    }

    // Query a single node.
    bstrQuery1 = SysAllocString(L"//stock[1]/*");
    CHK_ALLOC(bstrQuery1);
    CHK_HR(pXMLDom->selectSingleNode(bstrQuery1, &pNode));
    if (pNode)
    {
        printf("Result from selectSingleNode:\n");
        CHK_HR(pNode->get_nodeName(&bstrNodeName));
        printf("Node, <%S>:\n", bstrNodeName);
        SysFreeString(bstrNodeName);

        CHK_HR(pNode->get_xml(&bstrNodeValue));
        printf("\t%S\n\n", bstrNodeValue);
        SysFreeString(bstrNodeValue);
        SAFE_RELEASE(pNode);
    }
    else
    {
        CHK_HR(ReportParseError(pXMLDom, "Error while calling selectSingleNode."));
    }

    // Query a node-set.
    bstrQuery2 = SysAllocString(L"//stock[1]/*");
    CHK_ALLOC(bstrQuery2);
    CHK_HR(pXMLDom->selectNodes(bstrQuery2, &pNodes));
    if(pNodes)
    {
        printf("Results from selectNodes:\n");
        //get the length of node-set
        long length;
        CHK_HR(pNodes->get_length(&length));
        for (long i = 0; i < length; i++)
        {
            CHK_HR(pNodes->get_item(i, &pNode));
            CHK_HR(pNode->get_nodeName(&bstrNodeName));
			/*if(0== wcscmp(bstrNodeValue, L"symbol"))
			{
				 
			}
           */
			printf("Node (%d), <%S>:\n", i, bstrNodeName);
            SysFreeString(bstrNodeName);

            CHK_HR(pNode->get_xml(&bstrNodeValue));
			
            printf("\t%S\n", bstrNodeValue);
            SysFreeString(bstrNodeValue);
            SAFE_RELEASE(pNode);
        }
    }
    else
    {
        CHK_HR(ReportParseError(pXMLDom, "Error while calling selectNodes."));
    }

CleanUp:
    SAFE_RELEASE(pXMLDom);
    SAFE_RELEASE(pNodes);
    SAFE_RELEASE(pNode);
    SysFreeString(bstrQuery1);
    SysFreeString(bstrQuery2);
    SysFreeString(bstrNodeName);
    SysFreeString(bstrNodeValue);
    VariantClear(&varFileName);
}
Ejemplo n.º 7
0
int DicomImageSet::readDatasetFile(const QString &datasetFileName, QTreeWidget *treeWidget)
{
    HRESULT hr = S_OK;
    IXMLDOMDocument *pXMLDom = NULL;
    IXMLDOMNodeList *pPatients = NULL;
    IXMLDOMNode *pPatient = NULL;
	DOMNodeType nodeType;
    VARIANT_BOOL varStatus;
    VARIANT varFileName;
	VARIANT varValue;
	BSTR bstrQuery;

    VariantInit(&varFileName);
    VariantInit(&varValue);

	QString queryPatient, queryDate, queryProtocol, queryCollection;

    CHK_HR(CreateAndInitDOM(&pXMLDom));

	CHK_HR(VariantFromString(datasetFileName.toStdWString().c_str(), varFileName));
    CHK_HR(pXMLDom->load(varFileName, &varStatus));
    if (varStatus != VARIANT_TRUE)
    {
        CHK_HR(ReportParseError(pXMLDom, "Failed to load DOM from stocks.xml."));
    }

	treeWidget->clear();
	treeWidget->setColumnCount(1);
	CHK_HR(pXMLDom->getElementsByTagName(L"Patient", &pPatients));
	if (pPatients)
	{
		long nPatients;
		CHK_HR(pPatients->get_length(&nPatients));
		for (long i=0; i<nPatients; ++i)
		{
			CHK_HR(pPatients->get_item(i, &pPatient));
			CHK_HR(GetAttributeFromNode(pPatient, L"patients_name", &varValue));
			queryPatient = QString::fromWCharArray(_bstr_t(varValue));
			QTreeWidgetItem * patientItem = new QTreeWidgetItem(treeWidget, QStringList(queryPatient));
			patientItem->setExpanded(true);

			IXMLDOMNodeList * pDates = NULL;
			CHK_HR(pPatient->get_childNodes(&pDates));
			long nDates;
			CHK_HR(pDates->get_length(&nDates));
			for (long j=0; j<nDates; ++j)
			{
				IXMLDOMNode * pDate = NULL;
				CHK_HR(pDates->get_item(j, &pDate));
				CHK_HR(pDate->get_nodeType(&nodeType));
				if(nodeType!=NODE_ELEMENT)
				{
					continue;
				}
				CHK_HR(GetAttributeFromNode(pDate, L"acquisition_date", &varValue));
				queryDate = QString::fromWCharArray(_bstr_t(varValue));
				int intDate = queryDate.toInt();
				QDate date = (QDate::fromString("1900-01-01", "yyyy-MM-dd")).addDays(intDate-693962);
				QTreeWidgetItem * dateItem = new QTreeWidgetItem(patientItem, QStringList(date.toString("yyyy-MM-dd")));
				dateItem->setExpanded(true);

				IXMLDOMNodeList * pProtocols = NULL;
				CHK_HR(pDate->get_childNodes(&pProtocols));
				long nProtocols;
				CHK_HR(pProtocols->get_length(&nProtocols));
				for (long j=0; j<nProtocols; ++j)
				{
					IXMLDOMNode * pProtocol = NULL;
					CHK_HR(pProtocols->get_item(j, &pProtocol));
					CHK_HR(pProtocol->get_nodeType(&nodeType));
					if(nodeType!=NODE_ELEMENT)
					{
						continue;
					}
					CHK_HR(GetAttributeFromNode(pProtocol, L"protocol_name", &varValue));
					queryProtocol = QString::fromWCharArray(_bstr_t(varValue));
					QTreeWidgetItem * protocolItem = new QTreeWidgetItem(dateItem, QStringList(queryProtocol));
					protocolItem->setExpanded(true);

					IXMLDOMNodeList * pCollections = NULL;
					CHK_HR(pProtocol->get_childNodes(&pCollections));
					long nCollections;
					CHK_HR(pCollections->get_length(&nCollections));
					for (long j=0; j<nCollections; ++j)
					{
						IXMLDOMNode * pCollection = NULL;
						CHK_HR(pCollections->get_item(j, &pCollection));
						CHK_HR(pCollection->get_nodeType(&nodeType));
						if(nodeType!=NODE_ELEMENT)
						{
							continue;
						}
						CHK_HR(GetAttributeFromNode(pCollection, L"acquisition_number", &varValue));
						queryCollection = QString::fromWCharArray(_bstr_t(varValue));
						QTreeWidgetItem * collectionItem = new QTreeWidgetItem(protocolItem);
						QString queryStr = QString("root/Patient[@patients_name = '%1']/Date[@acquisition_date = '%2']/Protocol[@protocol_name = '%3']/Collection[@acquisition_number = '%4']")
							.arg(queryPatient).arg(queryDate).arg(queryProtocol).arg(queryCollection);

						IXMLDOMElement * pDtiNode = NULL;
						bstrQuery = SysAllocString(QString(queryStr+"/DTI").toStdWString().c_str());
						CHK_ALLOC(bstrQuery);
						CHK_HR(pXMLDom->selectSingleNode(bstrQuery, (IXMLDOMNode**)&pDtiNode));
						SysFreeString(bstrQuery);
						if (pDtiNode)
						{
							collectionItem->setText(0,queryCollection+"*");
						} else
						{
							collectionItem->setText(0, queryCollection);
						}

						collectionItem->setData(0, Qt::UserRole, queryStr);
						collectionItem->setExpanded(true);


						protocolItem->addChild(collectionItem);
						SAFE_RELEASE(pCollection);
					}

					dateItem->addChild(protocolItem);
					SAFE_RELEASE(pProtocol);
				}

				patientItem->addChild(dateItem);
				SAFE_RELEASE(pDate);
			}
			treeWidget->insertTopLevelItem(i, patientItem);
			SAFE_RELEASE(pPatient);
		}
	}

CleanUp:
    SAFE_RELEASE(pXMLDom);
    SAFE_RELEASE(pPatients);
    SAFE_RELEASE(pPatient);
    VariantClear(&varFileName);

	return SUCCEEDED(hr);
}
Ejemplo n.º 8
0
///////////////////////////////////////////////////////
// RADEventsXML::ProcessEvents
//
// Method to process a list of events, either transforming XML
// into RADEvents, or RADEvents into XML event nodes.
// Invoked by the Populate and Persist methods.
//
// When transforming the RADEvent objects on the list 'rel' into
// XML Event nodes, a new XML Event node is created, and appended
// to the XML Events node of the XML document.
// 
// When transforming the XML Events node with XML Event nodes, each
// XML Event node is transformed to a RADEvent object, and the RADEvent
// object is appended to the RADEventsList 'rel'.
//
// Input/Output:
//	rel	- the RADEventsList instance
//  bExtract - processing toggle:
//		When true, run through the XML event nodes, creating
//		RADEvent objects on 'rel'.
//		When false, run through the RADEvent objects, creating
//		XML event nodes on the XML document.
//
///////////////////////////////////////////////////////
bool RADEventsXML::ProcessEvents(RADEventsList& rel, bool bExtract)
{

	// if bExtract, we want to read the XML events and populate the list of event objects
	// first: get count of events nodes
	// second:
	//	for each event node
	//    get the node
	//    create a RADEvent, using the node attributes to populate it
	//	  insert the RADEvent object into the RADEventsList 'rel'
	// end
	// else, not bExtract, we want to transform the list of RADEvent objects into an XML document
	// for each RADEvent on the RADEventsList 'rel,
	//    create a new XML Event Node, using each stirng value as an attribute value
	//    append the XML Event node to the <IR/Events> node
	//  end

	HRESULT hr;
	_bstr_t xbstr = m_xirevsevpath;

	if (bExtract)  // converting from XML <Event> to RADEvent
	{
		IXMLDOMNodeList* pXMLDomNodeList = NULL;
		HRCALL(m_pXMLDom->selectNodes(xbstr, &pXMLDomNodeList), "selectNodes");
		if (pXMLDomNodeList)
		{
			long count = 0;
			HRCALL(pXMLDomNodeList->get_length(&count), "get_length");
			IXMLDOMNode *pEventNode=NULL;
			for (long i=0; i<count; i++)
			{
				HRCALL(pXMLDomNodeList->get_item(i, &pEventNode), "get_item: ");
				if (bDebug)
				{
					BSTR dbg1str;
					BSTR dbg2str;
					HRCALL(pEventNode->get_nodeName(&dbg1str), "get_nodeName: ");
					dprintf("Node (%d), <%S>:\n",i, static_cast<wchar_t*>(dbg1str));
					HRCALL(pEventNode->get_xml(&dbg2str), "get_xml: ");
					dprintf("\t%S\n",  static_cast<wchar_t*>(dbg2str));
				}

				RADEvent* p = XMLToEvent(pEventNode);
				rel.AddToEnd(p);
				if (bDebug)
				{
					dprintf(p->Image());
				}
				if (pEventNode) pEventNode->Release();
			}
			pXMLDomNodeList->Release();
		}
		else
		{
			ReportParseError(m_pXMLDom, "Error while calling ProcessEvents/selectNodes ");
		}
	}
	else // converting from RADEvent to XML <Event>
	{
		IXMLDOMElement * pE;
		IXMLDOMNode *pIXMLDOMNode = NULL;
		long i = 0;
		POSITION pos = rel.GetHeadPosition();
		while( pos != NULL )
		{
			RADEvent* p = (RADEvent*)rel.GetNext( pos );
			pE = ConstructEventNode(p);
			if (pE)
			{
				HRCALL(m_pIRNode->appendChild(pE,&pIXMLDOMNode), ""); 
				AddWhiteSpaceToNode(bstr_wsnt, m_pIRNode);
				i++;
			}
		}
	}

clean: 
	if (FAILED(hr))
		return false;
	else
		return true;
}
Ejemplo n.º 9
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;
}
Ejemplo n.º 10
0
BOOLEAN Deletion_Parameters(LIST Tokens, pDeletionStruct pDeletionParameters, pSTRING pCommandLine)
{
  Token    CurrentToken;         /* Used to hold the token being examined. */
  CARDINAL Error = 0;            /* Used to hold the error return code from LIST operations. */
  BOOLEAN  ReturnValue = FALSE;  /* Used to hold the function return value. */
  pSTRING   pDriveName = NULL;
  pSTRING   pPartitionName = NULL;
  pSTRING   pDriveNumber = NULL;
  pSTRING   pVolumeName = NULL;
  unsigned int TokenPosition;


  /* Get the current token so that we can examine it. */
  GetToken(Tokens,sizeof(Token),&CurrentToken,&TokenPosition,&Error);
  if ( Error )
  {
     /* Report any errors accessing the token list as an internal error! */
     ReportError(Internal_Error);
     return ReturnValue;
  } /* endif */

  /* The next token must be the keyword ALL, PARTITION, or VOLUME */
  switch (CurrentToken.TokenType) {
  case All_CLI:
     pDeletionParameters->NameType = NoNameType;
     pDeletionParameters->DeletionOption = Deletion_None;
     /* All found, advance to next token */
     NextToken(Tokens,&Error);
     SkipOptionalWhitespace(Tokens);

     /* The token following the ALL keyword must be a comma */
     if ( IsComma(Tokens) ) {
        SkipOptionalWhitespace(Tokens);
        GetToken(Tokens,sizeof(Token),&CurrentToken,&TokenPosition,&Error);
        if ( Error) {
           /* Report any errors accessing the token list as an internal error! */
           ReportError(Internal_Error);
           return ReturnValue;
        } /* endif */

        switch (CurrentToken.TokenType) {
        case Compatibility:
           pDeletionParameters->DeletionOption = Deletion_All_Compatibility;
           NextToken(Tokens,&Error);
           ReturnValue = TRUE;
           break;
        case Logical:
           pDeletionParameters->DeletionOption = Deletion_All_Logical;
           NextToken(Tokens,&Error);
           ReturnValue = TRUE;
           break;
        case LVM:
           pDeletionParameters->DeletionOption = Deletion_All_LVM;
           NextToken(Tokens,&Error);
           ReturnValue = TRUE;
           break;
        case Primary:
           pDeletionParameters->DeletionOption = Deletion_All_Primary;
           NextToken(Tokens,&Error);
           ReturnValue = TRUE;
           break;
        case Unused:
           pDeletionParameters->DeletionOption = Deletion_All_Unused;
           NextToken(Tokens,&Error);
           ReturnValue = TRUE;
           break;
        case Volumes:
           pDeletionParameters->DeletionOption = Deletion_All_Volumes;
           NextToken(Tokens,&Error);
           ReturnValue = TRUE;
           break;
        case Eof:
        case SemiColon:
           ReportParseError(Expected_Deletion_Suboption, Tokens, pCommandLine);
           break;
        default:
           ReportParseError(Expected_Deletion_Suboption, Tokens, pCommandLine);
        } /* endswitch */
     } else {
        ReportParseError(Expected_Comma, Tokens, pCommandLine);
     } /* endif */
     break;
  case Partition:
     pDeletionParameters->DeletionOption = Deletion_Partition;
     /* Partition found, advance to next token */
     NextToken(Tokens,&Error);
     SkipOptionalWhitespace(Tokens);

     /* The token following the PARTITION keyword must be a comma */
     if ( IsComma(Tokens) ) {
        SkipOptionalWhitespace(Tokens);
        GetToken(Tokens,sizeof(Token),&CurrentToken,&TokenPosition,&Error);
        if ( Error) {
           /* Report any errors accessing the token list as an internal error! */
           ReportError(Internal_Error);
           return ReturnValue;
        } /* endif */

        /* The token following PARTITION must be a drive number or drive name */
        /* If it is a drive number */
        if ( Drive_Number(Tokens, &pDriveNumber) ) {
           pDeletionParameters->NameType = DriveNumberType;
           pDeletionParameters->pDrive = pDriveNumber;
        } else {
           /* If it is a drive name */
           if ( Drive_Name(Tokens, Comma, &pDriveName) ) {
              pDeletionParameters->NameType = DriveNameType;
              pDeletionParameters->pDrive = pDriveName;
           } else {
              ReportParseError(Expected_Drive_Number_or_Name, Tokens, pCommandLine);
              return ReturnValue;
           } /* endif */
        } /* endif */

        SkipOptionalWhitespace(Tokens);
        /* The next token is a comma, the one following it must be a parition name */
        if ( IsComma(Tokens) ) {
           SkipOptionalWhitespace(Tokens);
           GetToken(Tokens,sizeof(Token),&CurrentToken,&TokenPosition,&Error);
           if ( Error ) {
              /* Report any errors accessing the token list as an internal error! */
              ReportError(Internal_Error);
              return ReturnValue;
           } /* endif */

           pPartitionName = NULL;
           /* The next tokens, up to the next semicolon, must be a Partition name. */
           if ( Partition_Name(Tokens, SemiColon, &pPartitionName) ) {
              pDeletionParameters->pPartitionName = pPartitionName;
              ReturnValue = TRUE;
           } else {
             ReportParseError(Expected_Partition_Name, Tokens, pCommandLine);
           } /* endif */
        } else {
           /* Since the next token was not a comma, assume that the optional */
           /* partition name was not specified. */
           /* When the partition name is not specified, the parser indicates */
           /* that all paritions on the specified drive are to be deleted. */
           pDeletionParameters->DeletionOption = Deletion_Partitions;
           ReturnValue = TRUE;
        } /* endif */
     } else {
        ReportParseError(Expected_Comma, Tokens, pCommandLine);
     } /* endif */
     break;
  case Volume:
     pDeletionParameters->DeletionOption = Deletion_Volume;
     /* Volume found, advance to next token */
     NextToken(Tokens,&Error);
     SkipOptionalWhitespace(Tokens);
     /* The next non-whitespace token must be a comma */
     if ( IsComma(Tokens) ) {
        SkipOptionalWhitespace(Tokens);
        GetToken(Tokens,sizeof(Token),&CurrentToken,&TokenPosition,&Error);
        if ( Error ) {
           ReportError(Internal_Error);
           return ReturnValue;
        } /* endif */

        pVolumeName = NULL;
        /* The next tokens, up to the next semicolon, must be a volume name. */
        if ( Volume_Name(Tokens, SemiColon, &pVolumeName) ) {
           pDeletionParameters->pVolumeName = pVolumeName;
           ReturnValue = TRUE;
        } else {
          ReportParseError(Expected_Volume_Name, Tokens, pCommandLine);
        } /* endif */
     } else {
       ReportParseError(Expected_Comma, Tokens, pCommandLine);
     } /* endif */
     break;
  default:
     ReportParseError(Expected_Deletion_Option, Tokens, pCommandLine);
     break;
  } /* endswitch */

  /* Report any errors accessing the token list as an internal error! */
  if ( Error )
    ReportError(Internal_Error);

  return ReturnValue;

}
Ejemplo n.º 11
0
static BOOLEAN Optional_Query_Parameters(LIST Tokens, pQueryStruct pQueryParameters, pSTRING pCommandLine)
{
  Token    CurrentToken;         /* Used to hold the token being examined. */
  CARDINAL Error = 0;            /* Used to hold the error return code from LIST operations. */
  BOOLEAN  ReturnValue = FALSE;  /* Used to hold the function return value. */
  pSTRING  pDriveName = NULL;
  pSTRING  pFilesystemType = NULL;
  pSTRING  pDriveNumber = NULL;
  pSTRING  pNumber = NULL;
  unsigned int TokenPosition;


  /* Get the current token so that we can examine it. */
  GetToken(Tokens,sizeof(Token),&CurrentToken,&TokenPosition,&Error);
  if ( !Error )
  {
     if (CurrentToken.TokenType == All_CLI) {
        pQueryParameters->NameType = AllNameType;
        NextToken(Tokens, &Error);
        ReturnValue = TRUE;
     } else {
        /* If it is a drive number */
        if ( Drive_Number(Tokens, &pDriveNumber) ) {
           pQueryParameters->NameType = DriveNumberType;
           pQueryParameters->pName = pDriveNumber;
           ReturnValue = TRUE;
        } else {
           if ( Drive_Name(Tokens, SemiColon, &pDriveName) ) {
              pQueryParameters->NameType = DriveNameType;
              pQueryParameters->pName = pDriveName;
              ReturnValue = TRUE;
           } else {
              ReportParseError(Expected_ALL_or_Drive_Number_or_Name, Tokens, pCommandLine);
              return ReturnValue;
           } /* endif */
        } /* endif */
     } /* endif */

     /* If the next token is a comma, the following token */
     /* must be a valid filesystem type. */
     SkipOptionalWhitespace(Tokens);
     GetToken(Tokens,sizeof(Token),&CurrentToken,&TokenPosition,&Error);
     if ( !Error ) {
        if ( IsComma(Tokens) ) {
           SkipOptionalWhitespace(Tokens);
           GetToken(Tokens,sizeof(Token),&CurrentToken,&TokenPosition,&Error);
           if ( !Error) {
              /* The token following the comma must be filesystem type */
              if ( Acceptable_Name(Tokens, SemiColon, &pFilesystemType) ) {
                 pQueryParameters->pFileSystemType = pFilesystemType;
                 ReturnValue = TRUE;
              } else {
                 /* A number is also acceptable as a filesystem type */
                 if (CurrentToken.TokenType == Number) {
                    pNumber = (pSTRING) malloc(strlen(CurrentToken.pTokenText)+1);
                    if (pNumber != NULL) {
                       pQueryParameters->pFileSystemType = pNumber;
                       strcpy(pNumber, CurrentToken.pTokenText);
                       NextToken(Tokens, &Error);
                       ReturnValue = TRUE;
                    } else {
                       ReportError(Not_Enough_Memory);
                       ReturnValue = FALSE;
                       return ReturnValue;
                    } /* endif */
                 } else {
                    ReturnValue = FALSE;
                    ReportParseError(Expected_File_System_Type, Tokens, pCommandLine);
                 } /* endif */
              } /* endif */
           } /* endif */
        } else {
           /* Since we wouldn't have reached this point if the required */
           /* portion of the rule had not been satisfied above, then    */
           /* we have satisfied the optional query parameters rule even */
           /* without the optional comma and filesytem type. */
           ReturnValue = TRUE;
        } /* endif */
     } /* endif */
  } /* endif */

  /* Report any errors accessing the token list as an internal error! */
  if ( Error )
    ReportError(Internal_Error);

  return ReturnValue;

}
Ejemplo n.º 12
0
BOOLEAN Query_Parameters(LIST Tokens, pQueryStruct pQueryParameters, pSTRING pCommandLine)
{
  Token    CurrentToken;         /* Used to hold the token being examined. */
  CARDINAL Error = 0;            /* Used to hold the error return code from LIST operations. */
  BOOLEAN  ReturnValue = FALSE;  /* Used to hold the function return value. */
  pSTRING  pDriveName = NULL;
  pSTRING  pDriveNumber = NULL;
  unsigned int TokenPosition;


  /* Get the current token so that we can examine it. */
  GetToken(Tokens,sizeof(Token),&CurrentToken,&TokenPosition,&Error);
  if ( !Error )
  {
    /* Set the OptionType field of the query structure */
    switch (CurrentToken.TokenType) {
    case All_CLI:
       pQueryParameters->OptionType = Query_All;
       break;
    case Bootable:
       pQueryParameters->OptionType = Query_Bootable;
       break;
    case Compatibility:
       pQueryParameters->OptionType = Query_Compatibility;
       break;
    case Freespace:
       pQueryParameters->OptionType = Query_Freespace;
       break;
    case Logical:
       pQueryParameters->OptionType = Query_Logical;
       break;
    case LVM:
       pQueryParameters->OptionType = Query_LVM;
       break;
    case Primary:
       pQueryParameters->OptionType = Query_Primary;
       break;
    case Unusable:
       pQueryParameters->OptionType = Query_Unusable;
       break;
    case Volumes:
       pQueryParameters->OptionType = Query_Volumes;
       break;
    default:
       pQueryParameters->OptionType = Query_Error;
       ReportParseError(Expected_Query_Option, Tokens, pCommandLine);
       break;
    } /* endswitch */

    /* Check for optional parameters */
    switch (CurrentToken.TokenType) {
    case Primary:
    case Logical:
    case Volumes:
    case Compatibility:
    case LVM:
    case All_CLI:
       NextToken(Tokens, &Error);
       if ( !Error ) {
          SkipOptionalWhitespace(Tokens);
          /* If there is a comma following the option */
          if ( IsComma(Tokens) ) {
             SkipOptionalWhitespace(Tokens);
             /* The token sequence following the comma must */
             /* satisfy the Optional Query Parameters rule. */
             if ( Optional_Query_Parameters(Tokens, pQueryParameters, pCommandLine) ) {
                ReturnValue = TRUE;
             } /* endif */
          } else {
             pQueryParameters->NameType = NoNameType;
             ReturnValue = TRUE;
          } /* endif */
       } /* endif */
       break;
    case Freespace:
    case Unusable:
    case Bootable:
       NextToken(Tokens, &Error);
       if ( !Error ) {
          SkipOptionalWhitespace(Tokens);
          /* If there is a comma following the option */
          if ( IsComma(Tokens) ) {
             SkipOptionalWhitespace(Tokens);
             GetToken(Tokens,sizeof(Token),&CurrentToken,&TokenPosition,&Error);
             if ( !Error ) {
                /* Any token following the comma must be the keword ALL */
                /* or a drive number or a drive name. */
                /* If it is ALL */
                if (CurrentToken.TokenType == All_CLI) {
                   pQueryParameters->NameType = AllNameType;
                   NextToken(Tokens, &Error);
                   ReturnValue = TRUE;
                } else {
                   /* If it is a drive number */
                   if ( Drive_Number(Tokens, &pDriveNumber) ) {
                      pQueryParameters->NameType = DriveNumberType;
                      pQueryParameters->pName = pDriveNumber;
                      ReturnValue = TRUE;
                   } else {
                      if ( Drive_Name(Tokens, SemiColon, &pDriveName) ) {
                         pQueryParameters->NameType = DriveNameType;
                         pQueryParameters->pName = pDriveName;
                         ReturnValue = TRUE;
                      } else {
                         ReportParseError(Expected_ALL_or_Drive_Number_or_Name, Tokens, pCommandLine);
                      } /* endif */
                   } /* endif */
                } /* endif */
             } /* endif */
          } else {
             pQueryParameters->NameType = NoNameType;
             ReturnValue = TRUE;
          } /* endif */
       } /* endif */
    } /* endswitch */
  }

  /* Report any errors accessing the token list as an internal error! */
  if ( Error ) {
    ReportError(Internal_Error);
  }

  return ReturnValue;

}