static QString parseInstrName(const QString& name) { QString sName; QDomDocument dom; int line, column; QString err; if (!dom.setContent(name, false, &err, &line, &column)) { QString col, ln; col.setNum(column); ln.setNum(line); QString error = err + "\n at line " + ln + " column " + col; qDebug("error: %s\n", qPrintable(error)); qDebug(" data:<%s>\n", qPrintable(name)); return QString(); } for (QDomNode e = dom.documentElement(); !e.isNull(); e = e.nextSiblingElement()) { for (QDomNode ee = e.firstChild(); !ee.isNull(); ee = ee.nextSibling()) { QDomElement el = ee.toElement(); const QString& tag(el.tagName()); if (tag == "symbol") { QString name = el.attribute(QString("name")); if (name == "flat") sName += "b"; else if (name == "sharp") sName += "#"; } QDomText t = ee.toText(); if (!t.isNull()) sName += t.data(); } } return sName; }
void operator <<= (SensorPositionIDL& position, const QDomNode& node) { if (!node.isNull()) { QDomNode n1 = node.firstChild(); while(!n1.isNull() ) { QDomNode n2 = n1.firstChild(); if (!n2.isNull()) { QDomText t = n2.toText(); // try to convert the node to a text if(!t.isNull() ) { // the node was really a text element. if (n1.nodeName() == "height") { position.height = t.data().toInt(); } else if (n1.nodeName() == "distance") { position.distance = t.data().toInt(); } else if (n1.nodeName() == "alpha") { position.alpha = deg2Rad(t.data().toDouble()); } else if (n1.nodeName() == "beta") { position.beta = deg2Rad(t.data().toDouble()); } else if (n1.nodeName() == "gamma") { position.gamma = deg2Rad(t.data().toDouble()); } else if (n1.nodeName() == "masked") { position.masked = (t.data() == "true"); } } } n1 = n1.nextSibling(); } } }
void Format::parseBlock( QTextCursor &cursor, const QDomElement &element ) { // dbg() << "Format::parseBlock()" << endl; QDomNode n; for( n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) { QDomElement e = n.toElement(); if ( e.tagName() == "fragment" ) { QTextCharFormat format; if ( e.hasAttribute( "link" ) ) { format.setAnchor( true ); QString href = e.attribute( "link" ); format.setAnchorHref( href ); format.setFontUnderline( true ); if ( href.startsWith( "todoodle:" ) ) { format = TextFormats::topicLinkCharFormat( href ); } else { format = TextFormats::hyperLinkCharFormat( href ); } } if ( e.attribute( "bold" ) == "true" ) { format.setFontWeight( QFont::Bold ); } if ( e.attribute( "italic" ) == "true" ) { format.setFontItalic( true ); } int fontSize = 0; if ( e.hasAttribute( "fontsize" ) ) { fontSize = e.attribute( "fontsize" ).toInt(); } else { fontSize = 10; } if ( fontSize > 0 ) format.setFontPointSize( fontSize ); QDomNode n2; for( n2 = e.firstChild(); !n2.isNull(); n2 = n2.nextSibling() ) { // dbg() << "TICK" << endl; QDomText t = n2.toText(); if ( !t.isNull() ) { // dbg() << "TEXT: '" << t.data() << "'" << endl; cursor.insertText( t.data(), format ); // dbg() << "done" << endl; } else { QDomElement e2 = n2.toElement(); if ( !e2.isNull() ) { if ( e2.tagName() == "todo" ) { QTextImageFormat f; if ( e2.attribute( "status" ) == "todo" ) { f.setName( ":/images/todo.png" ); } else { f.setName( ":/images/tododone.png" ); } cursor.insertImage( f ); } } } } } } }
void operator <<= (SensorDescriptionIDL& sensor, const QDomNode& node) { if (!node.isNull()) { QDomNode n1 = node.firstChild(); while(!n1.isNull() ) { QDomNode n2 = n1.firstChild(); if (!n2.isNull()) { QDomText t = n2.toText(); // try to convert the node to a text if(!t.isNull() ) { // the node was really a text element. if (n1.nodeName() == "minrange") { sensor.minRange = t.data().toInt(); } else if (n1.nodeName() == "maxrange") { sensor.maxRange = t.data().toInt(); } else if (n1.nodeName() == "focus") { sensor.focus = deg2Rad(t.data().toDouble()); } } } n1 = n1.nextSibling(); } } }
void UPnpDeviceDesc::SetStrValue( const QDomNode &n, QString &sValue ) { if (!n.isNull()) { QDomText oText = n.firstChild().toText(); if (!oText.isNull()) sValue = oText.nodeValue(); } }
void UPnpDeviceDesc::SetNumValue( const QDomNode &n, int &nValue ) { if (!n.isNull()) { QDomText oText = n.firstChild().toText(); if (!oText.isNull()) nValue = oText.nodeValue().toInt(); } }
QDomNode EmoticonExpander::visit(QDomText textNode) const { QDomText result = textNode; while (!textNode.isNull()) { result = textNode; textNode = expandFirstEmoticon(textNode); } return result; // last real node }
static QString getFirstText(QDomElement element) { for (QDomNode dname = element.firstChild(); !dname.isNull(); dname = dname.nextSibling()) { QDomText t = dname.toText(); if (!t.isNull()) return t.data(); } return QString(); }
/** * Loads the <UML:CheckConstraint> XMI element. */ bool UMLCheckConstraint::load( QDomElement & element ) { QDomNode node = element.firstChild(); QDomText checkConstraintText = node.toText(); if ( checkConstraintText.isNull() ) return false; m_CheckCondition = checkConstraintText.data(); return true; }
QString tagContent(const QDomElement &e) { // look for some tag content for(QDomNode n = e.firstChild(); !n.isNull(); n = n.nextSibling()) { QDomText i = n.toText(); if(i.isNull()) continue; return i.data(); } return ""; }
/*! *\en * Sets text for current node. * \param text (in) - new text value. * \return void. *\_en \ru * Устанавливает текст текущего узла. * \param text (in) - Значение нового текста. * \return ничего. *\_ru */ bool AExtXML::setText( const QString &text ) { QDomText t; if (current.isNull()) return false; while (!current.firstChild().isNull()) { current.removeChild( current.firstChild() ); } t = xml.createTextNode( text ); if ( t.isNull() ) return false; current.appendChild( t ); return true; }
void UPnpDeviceDesc::SetBoolValue( const QDomNode &n, bool &nValue ) { if (!n.isNull()) { QDomText oText = n.firstChild().toText(); if (!oText.isNull()) { QString s = oText.nodeValue(); nValue = (s == "yes" || s == "true" || s.toInt()); } } }
/** * Parses an xml reply form a start * @param xmlMessage XML message with tags data as root * @return Path of the decode file, or "" if there have been an error while parsing */ QString NMGNetperfXMLInterpret::getResultFilePathFromResult ( const QString & xmlMessage ) { QDomDocument doc; if ( !doc.setContent ( xmlMessage ) ) { cerr << "Error: the document is not well formed." << endl; return ""; } QDomElement root = doc.documentElement(); QString resultPath = ""; if ( root.tagName() != TAG_DATA ) cerr << "Error root element at NMGNetperfXMLInterpret different from data (" << qPrintable ( root.tagName() ) << ")." << endl; else { for ( QDomNode node = root.firstChild(); !node.isNull(); node = node.nextSibling() ) { if ( node.isElement() ) { QDomElement elem = node.toElement(); if ( elem.tagName() == TAG_DECODE_FILE ) { QDomText id = elem.firstChild().toText(); if ( id.isNull() ) cerr << "Result file path node has no value!" << endl; } else if ( elem.tagName() == TAG_TEST_FILE ) { QDomText id = elem.firstChild().toText(); if ( !id.isNull() ) resultPath = id.nodeValue(); else cerr << "Result file path node has no value!" << endl; } else cerr << "Incorrect Tag in Netperf XML reply (" << qPrintable ( elem.tagName() ) << ")." << endl; } } } return resultPath; }
void Parameters::operator <<= (const QDomNode& node) { Super::operator <<= (node); if (!node.isNull()) { QDomNode n1 = node.firstChild(); while(!n1.isNull() ) { QDomNode n2 = n1.firstChild(); if (!n2.isNull()) { if (n1.nodeName() == "stdcrystal") { QDomText t = n2.toText(); // try to convert the node to a text if(!t.isNull() ) { // the node was really a text element. stdcrystal = (t.data() == "true"); } } else if (n1.nodeName() == "continousmode") { QDomText t = n2.toText(); // try to convert the node to a text if(!t.isNull() ) { // the node was really a text element. continousmode = (t.data() == "true"); } } else if (n1.nodeName() == "pollintervall") { QDomText t = n2.toText(); // try to convert the node to a text if(!t.isNull() ) { // the node was really a text element. pollintervall = t.data().toInt(); } } else if (n1.nodeName() == "notify") { QDomText t = n2.toText(); // try to convert the node to a text if(!t.isNull() ) { // the node was really a text element. notify = (t.data() == "true"); } } else if (n1.nodeName() == "positionstamps") { QDomText t = n2.toText(); // try to convert the node to a text if(!t.isNull() ) { // the node was really a text element. positionStamps = (t.data() == "true"); } } else if (n1.nodeName() == "statistics") { QDomText t = n2.toText(); // try to convert the node to a text if(!t.isNull() ) { // the node was really a text element. statistics = (t.data() == "true"); } } else if (n1.nodeName() == "laser") { while (!n2.isNull()) { if (n2.nodeName() == "scandescription") laserDescription <<= n2; n2 = n2.nextSibling(); } } } n1 = n1.nextSibling(); } } }
QString XmlConfiguration::GetValue( const QString &sSetting, QString sDefault ) { QDomNode node = FindNode( sSetting ); if (!node.isNull()) { // -=>TODO: This Always assumes firstChild is a Text Node... should change QDomText oText = node.firstChild().toText(); if (!oText.isNull()) return oText.nodeValue(); } return sDefault; }
void DifferentialMotionParameters::operator <<= (const QDomNode& _node) { Super::operator<<=(_node); QDomNode n = _node.firstChild(); while( !n.isNull() ) { QDomElement e = n.toElement(); // try to convert the node to an element. if( !e.isNull() ) { // the node was really an element. if (e.tagName()=="parameter") { QDomAttr parameterName = e.attributeNode("name"); QString name; QString value; if (!parameterName.isNull()) { name = parameterName.value(); } else { throw Exception("Parameter tag without name."); } QDomNode n2 = n.firstChild(); while (!n2.isNull()) { QDomText t = n2.toText(); // try to convert the node to a text if(!t.isNull() ) { // the node was really a text element. value = t.data(); break; } n2 = n2.nextSibling(); } if (n2.isNull()) throw Exception("Parameter " + std::string(name) + "without value."); if (name == "MinLTranslation") minLTranslation = value.toInt(); else if (name == "MaxLTranslation") maxLTranslation = value.toInt(); else if (name == "MinRTranslation") minRTranslation = value.toInt(); else if (name == "MaxRTranslation") maxRTranslation = value.toInt(); else if (name == "WheelBase") wheelBase = value.toInt(); } } n = n.nextSibling(); } }
void DevParameters::operator <<= (const QDomNode& node) { if (!node.isNull()) { QDomNode n1 = node.firstChild(); while(!n1.isNull() ) { if (n1.nodeName() == "device") { QDomNode n2 = n1.firstChild(); QDomText t = n2.toText(); // try to convert the node to a text if(!t.isNull() ) { // the node was really an element. device = t.data(); } } n1 = n1.nextSibling(); } } }
// Author & Date: Ehsan Azar 15 June 2010 // Purpose: Get current node value // Inputs: // val - the default value QVariant XmlFile::value(const QVariant & val) { QVariant res = val; if (!m_nodes.isEmpty()) { // Get the current node QDomElement node = m_nodes.last(); if (!node.isNull()) { // Array Type is how we distinguish lists if (node.attribute("Type").compare("Array", Qt::CaseInsensitive) == 0) { QVariantList varlist; QStringList keys = childKeys(); for (int i = 0; i < keys.count(); ++i) { QString key = keys[i]; if (i > 0 && key == keys[i - 1]) key = QString(key + "<%1>").arg(i); // Recursively return the list beginGroup(key); QVariant nodevalue = value(QString()); endGroup(); // Make sure value is meaningful if (nodevalue.isValid()) varlist += nodevalue; // add new value } if (!keys.isEmpty()) res = varlist; } else { QDomNode child = node.firstChild(); if (!child.isNull()) { QDomText domText = child.toText(); if (!domText.isNull()) res = domText.data(); else return toString(); } } } } return res; }
void VarList::fromXml(const QDomElement &e) { clear(); for(QDomNode n = e.firstChild(); !n.isNull(); n = n.nextSibling()) { QDomElement i = n.toElement(); if(i.isNull()) continue; if(i.tagName() == "item") { QString var, val; var = i.attribute("name"); QDomText t = i.firstChild().toText(); if(!t.isNull()) val = t.data(); set(var, val); } } }
void OutlineTree::getHeaderInformation( const QDomElement &header ) { // visit all children of the header element and look if you can make // something with it QDomNode node = header.firstChild(); while ( !node.isNull() ) { if ( node.isElement() ) { // case for the different header entries if ( node.nodeName() == "title" ) { QDomText textChild = node.firstChild().toText(); if ( !textChild.isNull() ) { setColumnText( 0, textChild.nodeValue() ); } } } node = node.nextSibling(); } }
static QTextDocumentFragment parseInstrName(const QString& name) { if (name.isEmpty()) return QTextDocumentFragment(); QTextDocument doc; QTextCursor cursor(&doc); QTextCharFormat f = cursor.charFormat(); QTextCharFormat sf(f); QFont font("MScore1"); sf.setFont(font); QDomDocument dom; int line, column; QString err; if (!dom.setContent(name, false, &err, &line, &column)) { QString col, ln; col.setNum(column); ln.setNum(line); QString error = err + "\n at line " + ln + " column " + col; qDebug("parse instrument name: %s\n", qPrintable(error)); qDebug(" data:<%s>\n", qPrintable(name)); return QTextDocumentFragment(); } for (QDomNode e = dom.documentElement(); !e.isNull(); e = e.nextSibling()) { for (QDomNode ee = e.firstChild(); !ee.isNull(); ee = ee.nextSibling()) { QDomElement de1 = ee.toElement(); QString tag(de1.tagName()); if (tag == "symbol") { QString name = de1.attribute(QString("name")); if (name == "flat") cursor.insertText(QString(0xe10d), sf); else if (name == "sharp") cursor.insertText(QString(0xe10c), sf); } QDomText t = ee.toText(); if (!t.isNull()) cursor.insertText(t.data(), f); } } return QTextDocumentFragment(&doc); }
void Parameters::operator <<= (const QDomNode& node) { Super::operator <<= (node); if (!node.isNull()) { QDomNode n1 = node.firstChild(); while(!n1.isNull() ) { if (n1.nodeName() == "DifferentialMotion") motion <<= n1; else { QDomNode n2 = n1.firstChild(); if (!n2.isNull()) { QDomText t = n2.toText(); // try to convert the node to a text if(!t.isNull() ) { // the node was really a text element. if (n1.nodeName() == "radius") { radius = t.data().toDouble(); } if (n1.nodeName() == "maxTransVelocity") { maxTransVelocity = t.data().toInt(); } if (n1.nodeName() == "maxTransAccel") { maxTransAccel = t.data().toInt(); } if (n1.nodeName() == "maxRotVelocity") { maxRotVelocity = Miro::deg2Rad(t.data().toDouble()); } if (n1.nodeName() == "maxRotAccel") { maxRotAccel = Miro::deg2Rad(t.data().toDouble()); } if (n1.nodeName() == "voltWarn") { voltWarn = t.data().toInt(); } if (n1.nodeName() == "voltPanic") { voltPanic = t.data().toInt(); } } } } n1 = n1.nextSibling(); } } }
QString SOAPClient::GetNodeValue( QDomNode &node, const QString &sName, const QString &sDefault ) { if (node.isNull()) return sDefault; QString sValue = ""; QDomNode valNode = FindNode( sName, node ); if (!valNode.isNull()) { // -=>TODO: Assumes first child is Text Node. QDomText oText = valNode.firstChild().toText(); if (!oText.isNull()) sValue = oText.nodeValue(); return QUrl::fromPercentEncoding(sValue.toUtf8()); } return sDefault; }
/** * Parses the status message and returns the integer value of the status * @param xmlMessage * @return Status value or -1 if error */ int NMGNetperfXMLInterpret::parseStatusMessage ( const QString & xmlMessage ) { QDomDocument doc; if ( !doc.setContent ( xmlMessage ) ) { cerr << "Error: the document is not well formed." << endl; return -1; } QDomElement root = doc.documentElement(); if ( root.tagName() != TAG_DATA ) cerr << "Error root element at NMGNetperfXMLInterpret different from data (" << qPrintable ( root.tagName() ) << ")." << endl; else { for ( QDomNode node = root.firstChild(); !node.isNull(); node = node.nextSibling() ) { if ( node.isElement() ) { QDomElement elem = node.toElement(); if ( elem.tagName() == TAG_STATUS ) { QDomText id = elem.firstChild().toText(); if ( !id.isNull() ) { bool ok; int num = id.nodeValue().toInt ( &ok ); if ( ok ) return num; } else cerr << "The status node has no value!" << endl; } #ifdef DEBUG else cerr << "Tag not managed in Netperf Status XML (" << elem.tagName() << ")." << endl; #endif } } } return -1; }
bool SOAPClient::SendSOAPRequest( const QString &sMethod, QStringMap &list, int &nErrCode, QString &sErrDesc, bool bInQtThread ) { QUrl url( m_url ); url.setPath( m_sControlPath ); // -------------------------------------------------------------- // Add appropriate headers // -------------------------------------------------------------- QHttpRequestHeader header; header.setValue("CONTENT-TYPE", "text/xml; charset=\"utf-8\"" ); header.setValue("SOAPACTION" , QString( "\"%1#GetConnectionInfo\"" ) .arg( m_sNamespace )); // -------------------------------------------------------------- // Build request payload // -------------------------------------------------------------- QByteArray aBuffer; QTextStream os( &aBuffer ); os << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"; os << "<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n"; os << " <s:Body>\r\n"; os << " <u:" << sMethod << " xmlns:u=\"" << m_sNamespace << "\">\r\n"; // -------------------------------------------------------------- // Add parameters from list // -------------------------------------------------------------- for ( QStringMap::iterator it = list.begin(); it != list.end(); ++it ) { os << " <" << it.key() << ">"; os << HTTPRequest::Encode( *it ); os << "</" << it.key() << ">\r\n"; } os << " </u:" << sMethod << ">\r\n"; os << " </s:Body>\r\n"; os << "</s:Envelope>\r\n"; os.flush(); // -------------------------------------------------------------- // Perform Request // -------------------------------------------------------------- QBuffer buff( &aBuffer ); QString sXml = HttpComms::postHttp( url, &header, (QIODevice *)&buff, 10000, // ms 3, // retries 0, // redirects false, // allow gzip NULL, // login bInQtThread ); // -------------------------------------------------------------- // Parse response // -------------------------------------------------------------- list.clear(); QDomDocument doc; if ( !doc.setContent( sXml, true, &sErrDesc, &nErrCode )) { VERBOSE( VB_UPNP, QString( "MythXMLClient::SendSOAPRequest( %1 ) - Invalid response from %2" ) .arg( sMethod ) .arg( url.toString() )); return false; } // -------------------------------------------------------------- // Is this a valid response? // -------------------------------------------------------------- QString sResponseName = sMethod + "Response"; QDomNodeList oNodeList = doc.elementsByTagNameNS( m_sNamespace, sResponseName ); if (oNodeList.count() > 0) { QDomNode oMethod = oNodeList.item(0); if (!oMethod.isNull()) { for ( QDomNode oNode = oMethod.firstChild(); !oNode.isNull(); oNode = oNode.nextSibling() ) { QDomElement e = oNode.toElement(); if (!e.isNull()) { QString sName = e.tagName(); QString sValue = ""; QDomText oText = oNode.firstChild().toText(); if (!oText.isNull()) sValue = oText.nodeValue(); list.insert(QUrl::fromPercentEncoding(sName.toUtf8()), QUrl::fromPercentEncoding(sValue.toUtf8())); } } } return true; } // -------------------------------------------------------------- // Must be a fault... parse it to return reason // -------------------------------------------------------------- nErrCode = GetNodeValue( doc, "Envelope/Body/Fault/detail/UPnPResult/errorCode" , 500 ); sErrDesc = GetNodeValue( doc, "Envelope/Body/Fault/detail/UPnPResult/errorDescription", QString( "Unknown" )); return false; }
/** Actually sends the sMethod action to the command URL specified * in the constructor (url+[/]+sControlPath). * * \param sMethod method to be invoked. e.g. "SetChannel", * "GetConnectionInfoResult" * * \param list Parsed as a series of key value pairs for the input params * and then cleared and used for the output params. * * \param nErrCode set to zero on success, non-zero in case of error. * * \param sErrCode returns error description from device, when applicable. * * \param bInQtThread May be set to true if this is run from within * a QThread with a running an event loop. * * \return Returns a QDomDocument containing output parameters on success. */ QDomDocument SOAPClient::SendSOAPRequest(const QString &sMethod, QStringMap &list, int &nErrCode, QString &sErrDesc, bool bInQtThread) { QUrl url(m_url); url.setPath(m_sControlPath); nErrCode = UPnPResult_Success; sErrDesc = ""; QDomDocument xmlResult; if (m_sNamespace.isEmpty()) { nErrCode = UPnPResult_MythTV_NoNamespaceGiven; sErrDesc = "No namespace given"; return xmlResult; } // -------------------------------------------------------------- // Add appropriate headers // -------------------------------------------------------------- QHttpRequestHeader header("POST", sMethod, 1, 0); header.setValue("CONTENT-TYPE", "text/xml; charset=\"utf-8\"" ); header.setValue("SOAPACTION", QString("\"%1#%2\"").arg(m_sNamespace).arg(sMethod)); // -------------------------------------------------------------- // Build request payload // -------------------------------------------------------------- QByteArray aBuffer; QTextStream os( &aBuffer ); os.setCodec("UTF-8"); os << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"; os << "<s:Envelope " " s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"" " xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n"; os << " <s:Body>\r\n"; os << " <u:" << sMethod << " xmlns:u=\"" << m_sNamespace << "\">\r\n"; // -------------------------------------------------------------- // Add parameters from list // -------------------------------------------------------------- for (QStringMap::iterator it = list.begin(); it != list.end(); ++it) { os << " <" << it.key() << ">"; os << HTTPRequest::Encode( *it ); os << "</" << it.key() << ">\r\n"; } os << " </u:" << sMethod << ">\r\n"; os << " </s:Body>\r\n"; os << "</s:Envelope>\r\n"; os.flush(); // -------------------------------------------------------------- // Perform Request // -------------------------------------------------------------- QBuffer buff(&aBuffer); LOG(VB_UPNP, LOG_DEBUG, QString("SOAPClient(%1) sending:\n").arg(url.toString()) + header.toString() + QString("\n%1\n").arg(aBuffer.constData())); QString sXml = HttpComms::postHttp(url, &header, &buff, // QIODevice* 10000, // ms -- Technically should be 30ms per spec 3, // retries 0, // redirects false, // allow gzip NULL, // login bInQtThread, QString() // userAgent, UPnP/1.0 very strict on // format if set ); // -------------------------------------------------------------- // Parse response // -------------------------------------------------------------- LOG(VB_UPNP, LOG_DEBUG, "SOAPClient response:\n" + QString("%1\n").arg(sXml)); // TODO handle timeout without response correctly. list.clear(); QDomDocument doc; if (!doc.setContent(sXml, true, &sErrDesc, &nErrCode)) { LOG(VB_UPNP, LOG_ERR, QString("SendSOAPRequest( %1 ) - Invalid response from %2") .arg(sMethod).arg(url.toString()) + QString("%1: %2").arg(nErrCode).arg(sErrDesc)); return xmlResult; } // -------------------------------------------------------------- // Is this a valid response? // -------------------------------------------------------------- QString sResponseName = sMethod + "Response"; QDomNodeList oNodeList = doc.elementsByTagNameNS(m_sNamespace, sResponseName); if (oNodeList.count() == 0) { // -------------------------------------------------------------- // Must be a fault... parse it to return reason // -------------------------------------------------------------- nErrCode = GetNodeValue( doc, "Envelope/Body/Fault/detail/UPnPError/errorCode", 500); sErrDesc = GetNodeValue( doc, "Envelope/Body/Fault/detail/UPnPError/errorDescription", ""); if (sErrDesc.isEmpty()) sErrDesc = QString("Unknown #%1").arg(nErrCode); QDomNode oNode = FindNode( "Envelope/Body/Fault", doc ); oNode = xmlResult.importNode( oNode, true ); xmlResult.appendChild( oNode ); return xmlResult; } QDomNode oMethod = oNodeList.item(0); if (oMethod.isNull()) return xmlResult; QDomNode oNode = oMethod.firstChild(); for (; !oNode.isNull(); oNode = oNode.nextSibling()) { QDomElement e = oNode.toElement(); if (e.isNull()) continue; QString sName = e.tagName(); QString sValue = ""; QDomText oText = oNode.firstChild().toText(); if (!oText.isNull()) sValue = oText.nodeValue(); list.insert(QUrl::fromPercentEncoding(sName.toUtf8()), QUrl::fromPercentEncoding(sValue.toUtf8())); } // Create copy of oMethod that can be used with xmlResult. oMethod = xmlResult.importNode( oMethod.firstChild(), true ); // importNode does not attach the new nodes to the document, // do it here. xmlResult.appendChild( oMethod ); return xmlResult; }
void CameraParameters::operator <<= (const QDomNode& node) { if (!node.isNull()) { QDomNode n1 = node.firstChild(); while(!n1.isNull() ) { if (n1.nodeName() == "ncx") { QDomNode n2 = n1.firstChild(); QDomText t = n2.toText(); // try to convert the node to a text if(!t.isNull() ) { // the node was really an element. ncx = t.data().toDouble(); } } else if (n1.nodeName() == "nfx") { QDomNode n2 = n1.firstChild(); QDomText t = n2.toText(); // try to convert the node to a text if(!t.isNull() ) { // the node was really an element. nfx = t.data().toDouble(); } } else if (n1.nodeName() == "dx") { QDomNode n2 = n1.firstChild(); QDomText t = n2.toText(); // try to convert the node to a text if(!t.isNull() ) { // the node was really an element. dx = t.data().toDouble(); } } else if (n1.nodeName() == "dy") { QDomNode n2 = n1.firstChild(); QDomText t = n2.toText(); // try to convert the node to a text if(!t.isNull() ) { // the node was really an element. dy = t.data().toDouble(); } } else if (n1.nodeName() == "cx") { QDomNode n2 = n1.firstChild(); QDomText t = n2.toText(); // try to convert the node to a text if(!t.isNull() ) { // the node was really an element. cx = t.data().toDouble(); } } else if (n1.nodeName() == "cy") { QDomNode n2 = n1.firstChild(); QDomText t = n2.toText(); // try to convert the node to a text if(!t.isNull() ) { // the node was really an element. cy = t.data().toDouble(); } } else if (n1.nodeName() == "sx") { QDomNode n2 = n1.firstChild(); QDomText t = n2.toText(); // try to convert the node to a text if(!t.isNull() ) { // the node was really an element. sx = t.data().toDouble(); } } else if (n1.nodeName() == "f") { QDomNode n2 = n1.firstChild(); QDomText t = n2.toText(); // try to convert the node to a text if(!t.isNull() ) { // the node was really an element. f = t.data().toDouble(); } } else if (n1.nodeName() == "kappa") { QDomNode n2 = n1.firstChild(); QDomText t = n2.toText(); // try to convert the node to a text if(!t.isNull() ) { // the node was really an element. kappa = t.data().toDouble(); } } else if (n1.nodeName() == "height") { QDomNode n2 = n1.firstChild(); QDomText t = n2.toText(); // try to convert the node to a text if(!t.isNull() ) { // the node was really an element. height = t.data().toDouble(); } } else if (n1.nodeName() == "alpha") { QDomNode n2 = n1.firstChild(); QDomText t = n2.toText(); // try to convert the node to a text if(!t.isNull() ) { // the node was really an element. alpha = deg2Rad(t.data().toDouble()); } } else if (n1.nodeName() == "latency") { QDomNode n2 = n1.firstChild(); QDomText t = n2.toText(); // try to convert the node to a text if(!t.isNull() ) { // the node was really an element. double d = t.data().toDouble(); latency.sec((int)floor(d)); latency.usec((int)floor((d - floor(d)) * 1000000.)); } } n1 = n1.nextSibling(); } } }
QDomDocument SOAPClient::SendSOAPRequest(const QString &sMethod, QStringMap &list, int &nErrCode, QString &sErrDesc) { QUrl url(m_url); url.setPath(m_sControlPath); nErrCode = UPnPResult_Success; sErrDesc = ""; QDomDocument xmlResult; if (m_sNamespace.isEmpty()) { nErrCode = UPnPResult_MythTV_NoNamespaceGiven; sErrDesc = "No namespace given"; return xmlResult; } // -------------------------------------------------------------- // Add appropriate headers // -------------------------------------------------------------- QHash<QByteArray, QByteArray> headers; headers.insert("Content-Type", "text/xml; charset=\"utf-8\""); QString soapHeader = QString("\"%1#%2\"").arg(m_sNamespace).arg(sMethod); headers.insert("SOAPACTION", soapHeader.toUtf8()); headers.insert("User-Agent", "Mozilla/9.876 (X11; U; Linux 2.2.12-20 i686, en) " "Gecko/25250101 Netscape/5.432b1"); // -------------------------------------------------------------- // Build request payload // -------------------------------------------------------------- QByteArray aBuffer; QTextStream os( &aBuffer ); os.setCodec("UTF-8"); os << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"; os << "<s:Envelope " " s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"" " xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n"; os << " <s:Body>\r\n"; os << " <u:" << sMethod << " xmlns:u=\"" << m_sNamespace << "\">\r\n"; // -------------------------------------------------------------- // Add parameters from list // -------------------------------------------------------------- for (QStringMap::iterator it = list.begin(); it != list.end(); ++it) { os << " <" << it.key() << ">"; os << HTTPRequest::Encode( *it ); os << "</" << it.key() << ">\r\n"; } os << " </u:" << sMethod << ">\r\n"; os << " </s:Body>\r\n"; os << "</s:Envelope>\r\n"; os.flush(); // -------------------------------------------------------------- // Perform Request // -------------------------------------------------------------- LOG(VB_UPNP, LOG_DEBUG, QString("SOAPClient(%1) sending:\n %2").arg(url.toString()).arg(aBuffer.constData())); QString sXml; if (!GetMythDownloadManager()->postAuth(url.toString(), &aBuffer, NULL, NULL, &headers)) { LOG(VB_GENERAL, LOG_ERR, QString("SOAPClient::SendSOAPRequest: request failed: %1") .arg(url.toString())); } else sXml = QString(aBuffer); // -------------------------------------------------------------- // Parse response // -------------------------------------------------------------- LOG(VB_UPNP, LOG_DEBUG, "SOAPClient response:\n" + QString("%1\n").arg(sXml)); // TODO handle timeout without response correctly. list.clear(); QDomDocument doc; if (!doc.setContent(sXml, true, &sErrDesc, &nErrCode)) { LOG(VB_UPNP, LOG_ERR, QString("SendSOAPRequest( %1 ) - Invalid response from %2") .arg(sMethod).arg(url.toString()) + QString("%1: %2").arg(nErrCode).arg(sErrDesc)); return xmlResult; } // -------------------------------------------------------------- // Is this a valid response? // -------------------------------------------------------------- QString sResponseName = sMethod + "Response"; QDomNodeList oNodeList = doc.elementsByTagNameNS(m_sNamespace, sResponseName); if (oNodeList.count() == 0) { // -------------------------------------------------------------- // Must be a fault... parse it to return reason // -------------------------------------------------------------- nErrCode = GetNodeValue( doc, "Envelope/Body/Fault/detail/UPnPError/errorCode", 500); sErrDesc = GetNodeValue( doc, "Envelope/Body/Fault/detail/UPnPError/errorDescription", ""); if (sErrDesc.isEmpty()) sErrDesc = QString("Unknown #%1").arg(nErrCode); QDomNode oNode = FindNode( "Envelope/Body/Fault", doc ); oNode = xmlResult.importNode( oNode, true ); xmlResult.appendChild( oNode ); return xmlResult; } QDomNode oMethod = oNodeList.item(0); if (oMethod.isNull()) return xmlResult; QDomNode oNode = oMethod.firstChild(); for (; !oNode.isNull(); oNode = oNode.nextSibling()) { QDomElement e = oNode.toElement(); if (e.isNull()) continue; QString sName = e.tagName(); QString sValue = ""; QDomText oText = oNode.firstChild().toText(); if (!oText.isNull()) sValue = oText.nodeValue(); list.insert(QUrl::fromPercentEncoding(sName.toUtf8()), QUrl::fromPercentEncoding(sValue.toUtf8())); } // Create copy of oMethod that can be used with xmlResult. oMethod = xmlResult.importNode( oMethod.firstChild(), true ); // importNode does not attach the new nodes to the document, // do it here. xmlResult.appendChild( oMethod ); return xmlResult; }
/** * Parses an xml reply form a start * @param xmlMessage XML message with tags data as root * @return Path of the decode file, or "" if there have been an error while parsing */ QString NMGMGenXMLInterpret::getResultFilePathFromResult(const QString & xmlMessage) { QDomDocument doc; if(!doc.setContent(xmlMessage)) { cerr << RED << "[ERROR] the document is not well formed." << ENDCOLOR << endl; return ""; } NMGQDomSortElement root = doc.documentElement(); QString resultPath = ""; if(root.tagName()!=TAG_DATA) cerr << RED << "[ERROR] root element at NMGMGenXMLInterpret different from data ("<< qPrintable(root.tagName()) <<")."<< ENDCOLOR <<endl; else { for(QDomNode node = root.firstChild(); !node.isNull(); node = node.nextSibling()) { if(node.isElement()) { NMGQDomSortElement elem = node.toElement(); if(elem.tagName()==TAG_DECODE_FILE) { QString text = ""; QDomText id = elem.firstChild().toText(); if(!id.isNull()) text = id.nodeValue(); //if(!id.isNull()) resultPath = id.nodeValue(); //else cerr << "The decode result path node has no value!" << endl; } else if(elem.tagName()==TAG_RESULT_FILE) { QString text = ""; QDomText id = elem.firstChild().toText(); if(!id.isNull()) text = id.nodeValue(); } else if(elem.tagName()==TAG_TEST_FILE) { //QString text = ""; QDomText id = elem.firstChild().toText(); if(!id.isNull()) resultPath = id.nodeValue(); else cerr << "The decode result path node has no value!" << endl; } else if(elem.tagName()==TAG_RESULT_GRAPH_OWDD) { QString text = ""; QDomText id = elem.firstChild().toText(); if(!id.isNull()) text = id.nodeValue(); } else if(elem.tagName()==TAG_RESULT_GRAPH_IPDV) { QString text = ""; QDomText id = elem.firstChild().toText(); if(!id.isNull()) text = id.nodeValue(); } else if(elem.tagName()==TAG_RESULT_GRAPH_IPDVD) { QString text = ""; QDomText id = elem.firstChild().toText(); if(!id.isNull()) text = id.nodeValue(); } else if(elem.tagName()==TAG_TIME_FILE) { } else cerr << "Tag not correct in Mgen XML reply (" << qPrintable(elem.tagName()) <<")." << endl; } } } return resultPath; }