bool TestBaseLine::isDeepEqual(const QDomNode &n1, const QDomNode &n2)
{
    if(n1.nodeType() != n2.nodeType())
        return false;

    switch(n1.nodeType())
    {
        case QDomNode::CommentNode:
        /* Fallthrough. */
        case QDomNode::TextNode:
        {
            return static_cast<const QDomCharacterData &>(n1).data() ==
                   static_cast<const QDomCharacterData &>(n2).data();
        }
        case QDomNode::ProcessingInstructionNode:
        {
            return n1.nodeName() == n2.nodeName() &&
                   n1.nodeValue() == n2.nodeValue();
        }
        case QDomNode::DocumentNode:
            return isChildrenDeepEqual(n1.childNodes(), n2.childNodes());
        case QDomNode::ElementNode:
        {
            return n1.localName() == n2.localName()                     &&
                   n1.namespaceURI() == n2.namespaceURI()               &&
                   n1.nodeName() == n2.nodeName()                       && /* Yes, this one is needed in addition to localName(). */
                   isAttributesEqual(n1.attributes(), n2.attributes())  &&
                   isChildrenDeepEqual(n1.childNodes(), n2.childNodes());
        }
        /* Fallthrough all these. */
        case QDomNode::EntityReferenceNode:
        case QDomNode::CDATASectionNode:
        case QDomNode::EntityNode:
        case QDomNode::DocumentTypeNode:
        case QDomNode::DocumentFragmentNode:
        case QDomNode::NotationNode:
        case QDomNode::BaseNode:
        case QDomNode::CharacterDataNode:
        {
            Q_ASSERT_X(false, Q_FUNC_INFO,
                       "An unsupported node type was encountered.");
            return false;
        }
        case QDomNode::AttributeNode:
        {
            Q_ASSERT_X(false, Q_FUNC_INFO,
                       "This should never happen. QDom doesn't allow us to compare DOM attributes "
                       "properly.");
            return false;
        }
        default:
        {
            Q_ASSERT_X(false, Q_FUNC_INFO, "Unhandled QDom::NodeType value.");
            return false;
        }
    }
}
Exemple #2
0
QString QDomNodeProto:: localName() const
{
  QDomNode *item = qscriptvalue_cast<QDomNode*>(thisObject());
  if (item)
    return item->localName();
  return QString();
}
Exemple #3
0
void CWMPEventParser::addEvent(const QDomNode &event) {
    QDomNode node = event.firstChild();
    QString eventCode, cmdKey;

    while(!node.isNull()) {
        if(QString("EventCode") == node.localName()) {
            eventCode = node.firstChild().toText().data();
        } else if(QString("CommandKey") == node.localName()) {
            cmdKey = node.firstChild().toText().data();
        }

        node = node.nextSibling();
    }

    _event.events().append(
            CWMPEvent::Event(eventCode, cmdKey));
}
bool TestBaseLine::isAttributesEqual(const QDomNamedNodeMap &cl1, const QDomNamedNodeMap &cl2)
{
    const unsigned int len = cl1.length();
    pDebug() << "LEN:" << len;

    if(len == cl2.length())
    {
        for(unsigned int i1 = 0; i1 < len; ++i1)
        {
            const QDomNode attr1(cl1.item(i1));
            Q_ASSERT(!attr1.isNull());

            /* This is set if attr1 cannot be found at all in cl2. */
            bool earlyExit = false;

            for(unsigned int i2 = 0; i2 < len; ++i2)
            {
                const QDomNode attr2(cl2.item(i2));
                Q_ASSERT(!attr2.isNull());
                pDebug() << "ATTR1:" << attr1.localName() << attr1.namespaceURI() << attr1.prefix() << attr1.nodeName();
                pDebug() << "ATTR2:" << attr2.localName() << attr2.namespaceURI() << attr2.prefix() << attr2.nodeName();

                if(attr1.localName() == attr2.localName()       &&
                   attr1.namespaceURI() == attr2.namespaceURI() &&
                   attr1.prefix() == attr2.prefix()             &&
                   attr1.nodeName() == attr2.nodeName()         && /* Yes, needed in addition to all the other. */
                   attr1.nodeValue() == attr2.nodeValue())
                {
                    earlyExit = true;
                    break;
                }
            }

            if(!earlyExit)
            {
                /* An attribute was found that doesn't exist in the other list so exit. */
                return false;
            }
        }

        return true;
    }
    else
        return false;
}
Exemple #5
0
CWMPEventParser::CWMPEventParser(const QDomNode &eventNode) {
    QDomNode node = eventNode.firstChild();
    while(!node.isNull()) {
        QByteArray dbgA = node.localName().toLatin1();
        qDebug("%s, %d: Node's name is %s", __FUNCTION__, __LINE__, dbgA.constData());
        addEvent(node);

        node = node.nextSibling();
    }
}
Exemple #6
0
CWMPDeviceIDParser::CWMPDeviceIDParser(const QDomNode &deviceIDNode) {
    QDomNode node = deviceIDNode.firstChild();
    QByteArray dbgA;

    while(!node.isNull()) {
        QByteArray dbgA = node.localName().toLatin1();
        dbgA = node.firstChild().toText().data().toLatin1();
        if(QString("Manufacturer") == node.localName()) {
            _deviceID.setManufacturer(node.firstChild().toText().data());
        } else if(QString("OUI") == node.localName()) {
            _deviceID.setOui(node.firstChild().toText().data());
        } else if(QString("ProductClass") == node.localName()) {
            _deviceID.setProductClass(node.firstChild().toText().data());
        } else if(QString("SerialNumber") == node.localName()) {
            _deviceID.setSerialNumber(node.firstChild().toText().data());
        }

        node = node.nextSibling();
    }
}
void XmppReg::processStanza(const Stanza& s)
{
	QDomNode node;
	switch (state)
	{
	case Start:
		if (s.type() != "result")
		{
			//emit error();
			return;
		}
		node = s.node().firstChild().firstChild();
		while (!node.isNull())
		{
			printf("[XMPPREG] node = %s\n", node.localName().toLatin1().constData());
			if (node.localName() == "username")
				needUsername = true;
			if (node.localName() == "password")
				needPassword = true;
			if (node.localName() == "email")
				needEmail = true;
			node = node.nextSibling();
		}
		sendRegistration();
		state = WaitResult;
		break;
	case WaitResult:
		if (s.type() == "result")
		{
			//registerOk = true;
			emit finished();
		}
		if (s.type() == "error")
		{
			;
			//registerOk = false;
			//emit error();
		}
		break;
	}
}
void Xmpp::processEvent(Event *event)
{
	/*
	 * WARNING: An event is NOT still the same as before.
	 * Now, an event contains all data from depth = 1 
	 * to depth back to 1.
	 */
	//printf("Elem = %s\n", event->node().localName().toLatin1().constData());
	switch (state)
	{
		case isHandShaking:
			break;
		case PrepareRegistering:
		case waitStream:
			if (event->type() == Event::Stream)
			{
				printf("[XMPP] Ok, received the stream tag.\n");
				if (state != PrepareRegistering)
					state = waitFeatures;
				else
				{
					state = active;
					emit registerReady();
				}
			}
			//else
			//	printf(" ! Didn't receive the stream ! \n");
			break;
		case waitFeatures:
			if (event->node().localName() == "features")
			{
				printf("[XMPP] Ok, received the features tag.\n");
				if (!tlsDone && useTls)
				{
					QDomNode node = event->node().firstChild();
					printf("[XMPP] Next Status : ");
					//state = waitStartTls;
					printf("[XMPP]     %s\n", node.localName().toLatin1().constData());
					if (node.localName() == QString("mechanisms"))
					{
						printf("[XMPP] Must directly switch to SASL authentication\n");
						useTls = false;
						node = node.firstChild();
						// Must directly switch to SASL authentication
						printf("[XMPP]     %s\n", node.localName().toLatin1().constData());
						while(node.localName() == QString("mechanism"))
						{
							printf("[XMPP] Ok, received a mechanism tag.\n");
							if (node.firstChild().toText().data() == QString("PLAIN"))
							{
								plainMech = true;
								printf("[XMPP] Ok, PLAIN mechanism supported\n");

								// Sstartauth method.
								QDomDocument doc("");
								QDomElement e = doc.createElement("auth");
								doc.appendChild(e);
								e.setAttribute(QString("xmlns"), QString("urn:ietf:params:xml:ns:xmpp-sasl"));
								e.setAttribute(QString("mechanism"), QString("PLAIN"));
								QString text = QString("%1%2%3%4").arg('\0').arg(username).arg('\0').arg(password);
								QDomText t = doc.createTextNode(text.toLatin1().toBase64());
								e.appendChild(t);
								QByteArray sData = doc.toString().toLatin1();
								sendData(sData);
								state = waitSuccess;
								
							}
							node = node.nextSibling();
						}
					
					}
					if (node.localName() == QString("starttls"))
					{
						printf("[XMPP] Ok, received the starttls tag.\n");
						// Send starttls tag
						QDomDocument doc("");
						QDomElement e = doc.createElement("starttls");
						doc.appendChild(e);
						e.setAttribute(QString("xmlns"), QString("urn:ietf:params:xml:ns:xmpp-tls"));
						QByteArray sData = doc.toString().toLatin1();
						sendData(sData);
						// Next state
						state = waitProceed;
						// Even if TLS isn't required, I use TLS.
					}
				}
				else
				{
					if (!saslDone)
					{
						//TODO:Must first check that event->node().firstChild() == mechanisms
						QDomNode node = event->node().firstChild().firstChild();
						printf("[XMPP] Tls done or not used. --> sasl\n");
						while(node.localName() == QString("mechanism"))
						{
							printf("[XMPP] Ok, received a mechanism tag.\n");
							if (node.firstChild().toText().data() == QString("PLAIN"))
							{
								plainMech = true;
								printf("[XMPP] Ok, PLAIN mechanism supported\n");

								// Sstartauth method.
								QDomDocument doc("");
								QDomElement e = doc.createElement("auth");
								doc.appendChild(e);
								e.setAttribute(QString("xmlns"), QString("urn:ietf:params:xml:ns:xmpp-sasl"));
								e.setAttribute(QString("mechanism"), QString("PLAIN"));
								QString text = QString("%1%2%3%4").arg('\0').arg(username).arg('\0').arg(password);
								QDomText t = doc.createTextNode(text.toLatin1().toBase64());
								e.appendChild(t);
								QByteArray sData = doc.toString().toLatin1();
								sendData(sData);
								state = waitSuccess;
								
							}
							node = node.nextSibling();
						} //FIXME: this is impemented two times in this function. Another way to do the same ?
					}
					else
					{
				//		printf("Wait Ncessary\n");
				//		state = waitNecessary;
						QDomNode node = event->node().firstChild();
						while(!node.isNull())
						{
							if (node.localName() == QString("bind"))
							{
								printf("[XMPP] Ok, bind needed.\n");
								needBind = true;
							}
							if (node.localName() == QString("session"))
							{
								printf("[XMPP] Ok, session needed.\n");
								needSession = true;
							}
							node = node.nextSibling();
						}
						if (needBind)
						{
							QDomDocument doc("");
							QDomElement e = doc.createElement("iq");
							e.setAttribute("type", "set"); // Trying without id.

							QDomElement e2 = doc.createElement("bind");
							e2.setAttribute("xmlns", "urn:ietf:params:xml:ns:xmpp-bind");
				
							QDomElement e3 = doc.createElement("resource");
							QDomText t = doc.createTextNode(resource);
				
							e3.appendChild(t);
							e2.appendChild(e3);
							e.appendChild(e2);
							doc.appendChild(e);
							QByteArray sData = doc.toString().toLatin1();
							sendData(sData);
				
							state = waitBind;
						}
					}
				}
			}
			break;
		case waitProceed:
			if (event->node().localName() == QString("proceed"))
			{
				//printf(" * Ok, received the proceed tag.\n");
				printf("[XMPP] Proceeding...\n[XMPP] Enabling TLS connection.\n");
				
				state = isHandShaking;
				tls = new TlsHandler();
				connect(tls, SIGNAL(readyRead()), this, SLOT(clearDataReceived()));
				connect(tls, SIGNAL(readyReadOutgoing()), this, SLOT(sendDataFromTls()));
				connect(tls, SIGNAL(connected()), this, SLOT(tlsIsConnected()));
				tls->connect();
				state = isHandShaking;
				isTlsing = true;
			}
			break;
		case waitSuccess:
			if (event->node().localName() == QString("success"))
			{
				printf("[XMPP] Ok, SASL established.\n");
				saslDone = true;
				start();
			}
			if (event->node().localName() == QString("failure"))
			{
				printf("[XMPP]  ! Check Username and password.\n");
				QByteArray sData = "</stream:stream>";
				sendData(sData);
			}
			break;
		case waitBind:
			if (event->node().localName() == QString("iq"))
			{
				if (event->node().toElement().attribute("type") != QString("result"))
				{
					printf("[XMPP] Authentification Error.\n");
					QByteArray sData = "</stream:stream>";
					sendData(sData);
					return;
				}
				if (event->node().firstChild().localName() == QString("bind"))
				{
					QDomNode node = event->node().firstChild();
					if (node.firstChild().localName() == QString("jid"))
					{
						node = node.firstChild().firstChild();
						QString u, r, s;
						if (!node.toText().data().isEmpty())
						{
							u = node.toText().data().split('@')[0]; // Username
							s = node.toText().data().split('@')[1].split('/')[0]; // Server
							r = node.toText().data().split('/')[1]; // Resource
							printf("[XMPP] '%s'@'%s'/'%s'\n", u.toLatin1().constData(), s.toLatin1().constData(), r.toLatin1().constData());
						}
						if (u == username && s == server)
						{
							printf("[XMPP] Jid OK !\n");
							resource = r;
							jidDone = true;
							j.setResource(r);
						}
					}

					if (needSession && jidDone)
					{
						printf("[XMPP] Launching Session...\n");
						QDomDocument doc("");
						QDomElement e = doc.createElement("iq");
						e.setAttribute("to", server);
						e.setAttribute("type", "set");
						e.setAttribute("id", "sess_1");

						QDomElement e2 = doc.createElement("session");
						e2.setAttribute("xmlns", "urn:ietf:params:xml:ns:xmpp-session");

						e.appendChild(e2);
						doc.appendChild(e);

						QByteArray sData = doc.toString().toLatin1();
						sendData(sData);

						state = waitSession;
					}
					
				}
			}
			break;
		case waitSession:
			if (event->node().localName() == QString("iq"))
			{
				if (event->node().toElement().attribute("type") == "result")
				{
					printf("[XMPP] Connection is now active !\n");
					
					/*
					 * Presence must be sent after getting the roster
					 * so we already have the contacts to assign their presence
					 * when receiving presence stanza's wich come after
					 * setting the first presence.
					 */

					state = active;
					emit connected(); 

				}
				else
				{
					if (event->node().toElement().attribute("type") == "error")
					{
						printf("[XMPP] An error occured ! \n");
					}
				}

			}
			break;
		case active:
		{
			Stanza *s = new Stanza(event->node());
			QDomDocument doc = event->node().toDocument();
			printf("[XMPP] Xmpp::processEvent : node = %s\n", doc.toString().toLatin1().constData());
			stanzaList << s;
			emit readyRead();
			break;
		}
		default :
			break;
	}
}