From 4a54613ebf300cf0834016bc6e541971ef249716 Mon Sep 17 00:00:00 2001 From: ishmal Date: Sun, 13 Apr 2008 17:20:55 +0000 Subject: [PATCH] Make pedro dom list simpler --- src/pedro/pedrodom.cpp | 8 ++++---- src/pedro/pedrodom.h | 14 ++++++++++---- src/pedro/pedroxmpp.cpp | 21 ++++++++++----------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/pedro/pedrodom.cpp b/src/pedro/pedrodom.cpp index 4cb176a52..7a66a50d5 100644 --- a/src/pedro/pedrodom.cpp +++ b/src/pedro/pedrodom.cpp @@ -4,7 +4,7 @@ * Authors: * Bob Jamison * - * Copyright (C) 2005-2007 Bob Jamison + * Copyright (C) 2005-2008 Bob Jamison * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -48,7 +48,7 @@ Element *Element::clone() elem->attributes = attributes; elem->namespaces = namespaces; - std::vector::iterator iter; + ElementList::iterator iter; for (iter = children.begin(); iter != children.end() ; iter++) { elem->addChild((*iter)->clone()); @@ -84,7 +84,7 @@ DOMString Element::getAttribute(const DOMString &name) DOMString Element::getTagAttribute(const DOMString &tagName, const DOMString &attrName) { - std::vectorelems = findElements(tagName); + ElementList elems = findElements(tagName); if (elems.size() <1) return ""; DOMString res = elems[0]->getAttribute(attrName); @@ -93,7 +93,7 @@ DOMString Element::getTagAttribute(const DOMString &tagName, const DOMString &at DOMString Element::getTagValue(const DOMString &tagName) { - std::vectorelems = findElements(tagName); + ElementList elems = findElements(tagName); if (elems.size() <1) return ""; DOMString res = elems[0]->getValue(); diff --git a/src/pedro/pedrodom.h b/src/pedro/pedrodom.h index b8078dce1..e82115ede 100644 --- a/src/pedro/pedrodom.h +++ b/src/pedro/pedrodom.h @@ -6,7 +6,7 @@ * Authors: * Bob Jamison * - * Copyright (C) 2005-2007 Bob Jamison + * Copyright (C) 2005-2008 Bob Jamison * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -127,6 +127,12 @@ protected: }; +//#Define a list of elements. (Children, search results, etc) +class Element; +typedef std::vector ElementList; + + + class Element { friend class Parser; @@ -181,10 +187,10 @@ public: Element *getFirstChild() { return (children.size() == 0) ? NULL : children[0]; } - std::vector getChildren() + ElementList getChildren() { return children; } - std::vector findElements(const DOMString &name); + ElementList findElements(const DOMString &name); DOMString getAttribute(const DOMString &name); @@ -237,7 +243,7 @@ protected: Element *parent; - std::vectorchildren; + ElementList children; std::vector attributes; std::vector namespaces; diff --git a/src/pedro/pedroxmpp.cpp b/src/pedro/pedroxmpp.cpp index 757a883da..0dd78c5b8 100644 --- a/src/pedro/pedroxmpp.cpp +++ b/src/pedro/pedroxmpp.cpp @@ -875,7 +875,7 @@ static bool isGroupChat(Element *root) { if (!root) return false; - std::vectorelems = root->findElements("x"); + ElementList elems = root->findElements("x"); for (unsigned int i=0 ; igetAttribute("xmlns"); @@ -1107,7 +1107,7 @@ bool XmppClient::processIq(Element *root) if (root->getTagAttribute("query", "xmlns") == "jabber:iq:roster") { roster.clear(); - std::vectorelems = root->findElements("item"); + ElementList elems = root->findElements("item"); for (unsigned int i=0 ; i list = root->findElements("error"); + ElementList list = root->findElements("error"); if (list.size()==0) { XmppEvent evt(XmppEvent::EVENT_REGISTRATION_CHANGE_PASS); @@ -1167,7 +1167,7 @@ bool XmppClient::processIq(Element *root) else if (id.find("regcancel") != id.npos) { - std::vector list = root->findElements("error"); + ElementList list = root->findElements("error"); if (list.size()==0) { XmppEvent evt(XmppEvent::EVENT_REGISTRATION_CANCEL); @@ -1236,7 +1236,7 @@ bool XmppClient::receiveAndProcess() } //#### MESSAGE - std::vectorelems = root->findElements("message"); + ElementList elems = root->findElements("message"); if (elems.size()>0) { if (!processMessage(root)) @@ -1336,7 +1336,7 @@ bool XmppClient::inBandRegistrationNew() //elem->print(); //# does the entity send the newer "instructions" tag? - std::vector fields = elem->findElements("field"); + ElementList fields = elem->findElements("field"); std::vector fnames; for (unsigned int i=0; iprint(); - std::vector list = elem->findElements("error"); + ElementList list = elem->findElements("error"); if (list.size()>0) { Element *errElem = list[0]; @@ -1732,7 +1732,7 @@ bool XmppClient::saslMd5Authenticate() status("server says:: '%s'", recbuf.c_str()); elem = parser.parse(recbuf); //elem->print(); - //# Early success? + //# Success or failure already? if (elem->findElements("success").size() > 0) { delete elem; @@ -1740,7 +1740,7 @@ bool XmppClient::saslMd5Authenticate() } else { - std::vector list = elem->findElements("failure"); + ElementList list = elem->findElements("failure"); if (list.size() > 0) { DOMString errmsg = ""; @@ -1918,8 +1918,7 @@ bool XmppClient::saslAuthenticate() } //check for sasl authentication mechanisms - std::vector elems = - elem->findElements("mechanism"); + ElementList elems = elem->findElements("mechanism"); if (elems.size() < 1) { error("login: no SASL mechanism offered by server"); -- 2.30.2