Ejemplo n.º 1
0
void PrivacyListItem::fromXml(const QDomElement& el)
{
	//qDebug("privacy.cpp: Parsing privacy list item");
	if (el.isNull() || el.tagName() != "item") {
		qWarning("privacy.cpp: Invalid root tag for privacy list item.");
		return;
	}

	QString type = el.attribute("type"); 
	if (type == "jid")
		type_ = JidType;
	else if (type == "group")
		type_ = GroupType;
	else if (type == "subscription")
		type_ = SubscriptionType;
	else
		type_ = FallthroughType;
	
	QString value = el.attribute("value");
	value_ = value;
	if (type_ == JidType && XMPP::Jid(value_).isEmpty()) 
		qWarning("privacy.cpp: Invalid value for item of type 'jid'.");
	else if (type_ == GroupType && value_.isEmpty()) 
		qWarning("privacy.cpp: Empty value for item of type 'group'.");
	else if (type_ == SubscriptionType && value_ != "from" && value != "to" && value_ != "both" && value_ != "none")
		qWarning("privacy.cpp: Invalid value for item of type 'subscription'.");
	else if (type_ == FallthroughType && !value_.isEmpty()) 
		qWarning("privacy.cpp: Value given for item of fallthrough type.");
		
	QString action = el.attribute("action");
	if (action == "allow") 
		action_ = Allow;
	else if (action == "deny")
		action_ = Deny;
	else
		qWarning("privacy.cpp: Invalid action given for item.");

	bool ok;
	order_ = el.attribute("order").toUInt(&ok);
	if (!ok)
		qWarning("privacy.cpp: Invalid order value for item.");

	if (el.hasChildNodes()) {
		findSubTag(el, "message", &message_);
		findSubTag(el, "presence-in", &presenceIn_);
		findSubTag(el, "presence-out", &presenceOut_);
		findSubTag(el, "iq", &iq_);
	}
	else {
		message_ = presenceIn_ = presenceOut_ = iq_ = true;
	}
}
Ejemplo n.º 2
0
	bool take(const QDomElement& x) {
		if(!iqVerify(x, myjid_, id()))  // , "urn:xmpp:ping"
			return false;

		if(x.attribute("type") == "result") {
			// something bad, we never reply to this stanza so someone
			// else got it.
			// FIXME seems to be no longer true
			//emit result(NotUs, id());
			emit result(LoggedIn, id());
			setSuccess();
		} else if(x.attribute("type") == "get") {
			// All went well!
			emit result(LoggedIn, id());
			setSuccess();
		} else {
			bool found;
			QDomElement tag = findSubTag(x, "error", &found);
			if(!found) {
				emit result(OtherErr, id());
			} else {
				XMPP::Stanza::Error err;
				err.fromXml(tag, client()->stream().baseNS());
				if (err.condition == XMPP::Stanza::Error::ItemNotFound) {
					emit result(NoSuch, id());
				} else if (err.condition == XMPP::Stanza::Error::NotAcceptable ) {
					emit result(NotOccupant, id());
				} else {
					emit result(OtherErr, id());
				}
				setSuccess();
			}
		}
		return true;
	}
Ejemplo n.º 3
0
void readBoolEntry(const QDomElement &e, const QString &name, bool *v)
{
	bool found = FALSE;
	QDomElement tag = findSubTag(e, name, &found);
	if(!found)
		return;
	*v = (tagContent(tag) == "true") ? TRUE: FALSE;
}
Ejemplo n.º 4
0
QString subTagText(const QDomElement &e, const QString &name)
{
	bool found;
	QDomElement i = findSubTag(e, name, &found);
	if ( found )
		return i.text();
	return QString::null;
}
Ejemplo n.º 5
0
void readNumEntry(const QDomElement &e, const QString &name, int *v)
{
	bool found = FALSE;
	QDomElement tag = findSubTag(e, name, &found);
	if(!found)
		return;
	*v = tagContent(tag).toInt();
}
Ejemplo n.º 6
0
QString queryNS(const QDomElement &e)
{
	bool found;
	QDomElement q = findSubTag(e, "query", &found);
	if(found)
		return q.attribute("xmlns");

	return "";
}
Ejemplo n.º 7
0
void readColorEntry(const QDomElement &e, const QString &name, QColor *v)
{
	bool found = FALSE;
	QDomElement tag = findSubTag(e, name, &found);
	if(!found)
		return;
	QColor c;
	c.setNamedColor(tagContent(tag));
	if(c.isValid())
		*v = c;
}
Ejemplo n.º 8
0
void readSizeEntry(const QDomElement &e, const QString &name, QSize *v)
{
	bool found = FALSE;
	QDomElement tag = findSubTag(e, name, &found);
	if(!found)
		return;
	QStringList list = tagContent(tag).split(',');
	if(list.count() != 2)
		return;
	QSize s;
	s.setWidth(list[0].toInt());
	s.setHeight(list[1].toInt());
	*v = s;
}
Ejemplo n.º 9
0
bool ProxySettings::fromXml(const QDomElement &e)
{
	host = findSubTag(e, "host").text();
	port = findSubTag(e, "port").text().toInt();
	url = findSubTag(e, "url").text();
	useAuth = (findSubTag(e, "useAuth").text() == "true") ? true: false;
	user = findSubTag(e, "user").text();
	pass = findSubTag(e, "pass").text();
	return true;
}
Ejemplo n.º 10
0
void xmlToStringList(const QDomElement &e, const QString &name, QStringList *v)
{
	bool found = false;
	QDomElement tag = findSubTag(e, name, &found);
	if(!found)
		return;
	QStringList list;
	for(QDomNode n = tag.firstChild(); !n.isNull(); n = n.nextSibling()) {
		QDomElement i = n.toElement();
		if(i.isNull())
			continue;
		if(i.tagName() == "item")
			list += tagContent(i);
	}
	*v = list;
}
Ejemplo n.º 11
0
void readRectEntry(const QDomElement &e, const QString &name, QRect *v)
{
	bool found = FALSE;
	QDomElement tag = findSubTag(e, name, &found);
	if(!found)
		return;
	QStringList list = tagContent(tag).split(',');
	if(list.count() != 4)
		return;
	QRect r;
	r.setX(list[0].toInt());
	r.setY(list[1].toInt());
	r.setWidth(list[2].toInt());
	r.setHeight(list[3].toInt());
	*v = r;
}
Ejemplo n.º 12
0
void getErrorFromElement(const QDomElement &e, const QString &baseNS, int *code, QString *str)
{
	bool found;
	QDomElement tag = findSubTag(e, "error", &found);
	if(!found)
		return;

	XMPP::Stanza::Error err;
	err.fromXml(tag, baseNS);

	if(code)
		*code = err.code();
	if(str) {
		QPair<QString, QString> desc = err.description();
		if (err.text.isEmpty())
			*str = desc.first + ".\n" + desc.second;
		else
			*str = desc.first + ".\n" + desc.second + "\n" + err.text;
	}

}
Ejemplo n.º 13
0
static JingleRtpReason elementToReason(const QDomElement &e)
{
	if(e.tagName() != "reason")
		return JingleRtpReason();

	QDomElement condElement = firstChildElement(e);
	if(condElement.isNull())
		return JingleRtpReason();
	int x = elementNameToCondition(condElement.tagName());
	if(x == -1)
		return JingleRtpReason();

	JingleRtpReason out;
	out.condition = (JingleRtpReason::Condition)x;
	bool found;
	QDomElement text = findSubTag(e, "text", &found);
	if(found)
		out.text = tagContent(text);

	return out;
}
Ejemplo n.º 14
0
bool hasSubTag(const QDomElement &e, const QString &name)
{
	bool found;
	findSubTag(e, name, &found);
	return found;
}
Ejemplo n.º 15
0
/** \brief returns direct child element named "query"
 * \return the element (or a null QDomElemnt if not found)
*/
QDomElement queryTag(const QDomElement &e)
{
	bool found;
	QDomElement q = findSubTag(e, "query", &found);
	return q;
}
Ejemplo n.º 16
0
bool VCard::fromXml(const QDomElement &q)
{
	if ( q.tagName().upper() != "VCARD" )
		return false;

	QDomNode n = q.firstChild();
	for ( ; !n.isNull(); n = n.nextSibling() ) {
		QDomElement i = n.toElement();
		if ( i.isNull() )
			continue;

		QString tag = i.tagName().upper();

		bool found;
		QDomElement e;

		if ( tag == "VERSION" )
			d->version = i.text();
		else if ( tag == "FN" )
			d->fullName = i.text();
		else if ( tag == "N" ) {
			d->familyName = subTagText(i, "FAMILY");
			d->givenName  = subTagText(i, "GIVEN");
			d->middleName = subTagText(i, "MIDDLE");
			d->prefixName = subTagText(i, "PREFIX");
			d->suffixName = subTagText(i, "SUFFIX");
		}
		else if ( tag == "NICKNAME" )
			d->nickName = i.text();
		else if ( tag == "PHOTO" ) {
			d->photo = Base64::stringToArray( subTagText(i, "BINVAL") );
			d->photoURI = subTagText(i, "EXTVAL");
		}
		else if ( tag == "BDAY" )
			d->bday = i.text();
		else if ( tag == "ADR" ) {
			Address a;

			a.home   = hasSubTag(i, "HOME");
			a.work   = hasSubTag(i, "WORK");
			a.postal = hasSubTag(i, "POSTAL");
			a.parcel = hasSubTag(i, "PARCEL");
			a.dom    = hasSubTag(i, "DOM");
			a.intl   = hasSubTag(i, "INTL");
			a.pref   = hasSubTag(i, "PREF");

			a.pobox    = subTagText(i, "POBOX");
			a.extaddr  = subTagText(i, "EXTADR");
			a.street   = subTagText(i, "STREET");
			a.locality = subTagText(i, "LOCALITY");
			a.region   = subTagText(i, "REGION");
			a.pcode    = subTagText(i, "PCODE");
			a.country  = subTagText(i, "CTRY");

			d->addressList.append ( a );
		}
		else if ( tag == "LABEL" ) {
			Label l;

			l.home   = hasSubTag(i, "HOME");
			l.work   = hasSubTag(i, "WORK");
			l.postal = hasSubTag(i, "POSTAL");
			l.parcel = hasSubTag(i, "PARCEL");
			l.dom    = hasSubTag(i, "DOM");
			l.intl   = hasSubTag(i, "INTL");
			l.pref   = hasSubTag(i, "PREF");

			QDomNode nn = i.firstChild();
			for ( ; !nn.isNull(); nn = nn.nextSibling() ) {
				QDomElement ii = nn.toElement();
				if ( ii.isNull() )
					continue;

				if ( ii.tagName().upper() == "LINE" )
					l.lines.append ( ii.text() );
			}

			d->labelList.append ( l );
		}
		else if ( tag == "TEL" ) {
			Phone p;

			p.home  = hasSubTag(i, "HOME");
			p.work  = hasSubTag(i, "WORK");
			p.voice = hasSubTag(i, "VOICE");
			p.fax   = hasSubTag(i, "FAX");
			p.pager = hasSubTag(i, "PAGER");
			p.msg   = hasSubTag(i, "MSG");
			p.cell  = hasSubTag(i, "CELL");
			p.video = hasSubTag(i, "VIDEO");
			p.bbs   = hasSubTag(i, "BBS");
			p.modem = hasSubTag(i, "MODEM");
			p.isdn  = hasSubTag(i, "ISDN");
			p.pcs   = hasSubTag(i, "PCS");
			p.pref  = hasSubTag(i, "PREF");

			p.number = subTagText(i, "NUMBER");

			d->phoneList.append ( p );
		}
		else if ( tag == "EMAIL" ) {
			Email m;

			m.home     = hasSubTag(i, "HOME");
			m.work     = hasSubTag(i, "WORK");
			m.internet = hasSubTag(i, "INTERNET");
			m.x400     = hasSubTag(i, "X400");

			m.userid = subTagText(i, "USERID");

			d->emailList.append ( m );
		}
		else if ( tag == "JABBERID" )
			d->jid = i.text();
		else if ( tag == "MAILER" )
			d->mailer = i.text();
		else if ( tag == "TZ" )
			d->timezone = i.text();
		else if ( tag == "GEO" ) {
			d->geo.lat = subTagText(i, "LAT");
			d->geo.lon = subTagText(i, "LON");
		}
		else if ( tag == "TITLE" )
			d->title = i.text();
		else if ( tag == "ROLE" )
			d->role = i.text();
		else if ( tag == "LOGO" ) {
			d->logo = Base64::stringToArray( subTagText(i, "BINVAL") );
			d->logoURI = subTagText(i, "EXTVAL");
		}
		else if ( tag == "AGENT" ) {
			e = findSubTag(i, "VCARD", &found);
			if ( found ) {
				VCard a;
				if ( a.fromXml(e) ) {
					if ( !d->agent )
						d->agent = new VCard;
					*(d->agent) = a;
				}
			}

			d->agentURI = subTagText(i, "EXTVAL");
		}
		else if ( tag == "ORG" ) {
			d->org.name = subTagText(i, "ORGNAME");

			QDomNode nn = i.firstChild();
			for ( ; !nn.isNull(); nn = nn.nextSibling() ) {
				QDomElement ii = nn.toElement();
				if ( ii.isNull() )
					continue;

				if ( ii.tagName().upper() == "ORGUNIT" )
					d->org.unit.append( ii.text() );
			}
		}
		else if ( tag == "CATEGORIES") {
			QDomNode nn = i.firstChild();
			for ( ; !nn.isNull(); nn = nn.nextSibling() ) {
				QDomElement ee = nn.toElement();
				if ( ee.isNull() )
					continue;

				if ( ee.tagName().upper() == "KEYWORD" )
					d->categories << ee.text();
			}
		}
		else if ( tag == "NOTE" )
			d->note = i.text();
		else if ( tag == "PRODID" )
			d->prodId = i.text();
		else if ( tag == "REV" )
			d->rev = i.text();
		else if ( tag == "SORT-STRING" )
			d->sortString = i.text();
		else if ( tag == "SOUND" ) {
			d->sound = Base64::stringToArray( subTagText(i, "BINVAL") );
			d->soundURI      = subTagText(i, "EXTVAL");
			d->soundPhonetic = subTagText(i, "PHONETIC");
		}
		else if ( tag == "UID" )
			d->uid = i.text();
		else if ( tag == "URL")
			d->url = i.text();
		else if ( tag == "DESC" )
			d->desc = i.text();
		else if ( tag == "CLASS" ) {
			if ( hasSubTag(i, "PUBLIC") )
				d->privacyClass = pcPublic;
			else if ( hasSubTag(i, "PRIVATE") )
				d->privacyClass = pcPrivate;
			else if ( hasSubTag(i, "CONFIDENTIAL") )
				d->privacyClass = pcConfidential;
		}
		else if ( tag == "KEY" ) {
			// TODO: Justin, please check out this code
			e = findSubTag(i, "TYPE", &found);
			QString type = "text/plain";
			if ( found )
				type = e.text();

			e = findSubTag(i, "CRED", &found );
			if ( !found )
				e = findSubTag(i, "BINVAL", &found); // case for very clever clients ;-)

			if ( found )
				d->key = e.text().utf8(); // FIXME
		}
	}

	return true;
}