diff --git a/ksirk/Jabber/kmessagejabber.cpp b/ksirk/Jabber/kmessagejabber.cpp index fd407b7..849fac9 100644 --- a/ksirk/Jabber/kmessagejabber.cpp +++ b/ksirk/Jabber/kmessagejabber.cpp @@ -1,103 +1,103 @@ /* This file is part of the KDE games library Copyright (C) 2001 Burkhard Lehner (Burkhard.Lehner@gmx.de) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* subclass KMessageJabber of KMessageIO */ #include "jabber_protocol_debug.h" #include "kmessagejabber.h" #include #include // ----------------------KMessageJabber ----------------------- KMessageJabber::KMessageJabber (const QString& peerJid, JabberClient* jabberClient, QObject *parent) : KMessageIO (parent), mClient(jabberClient), mPeerJid(peerJid) { qCDebug(JABBER_PROTOCOL_LOG) << peerJid; // initSocket (); connect(jabberClient, SIGNAL(messageReceived(XMPP::Message)), this, SLOT(slotMessageReceived(XMPP::Message))); connect(jabberClient, SIGNAL(resourceUnavailable(Jid,Resource)), this, SLOT(slotResourceUnavailable(Jid,Resource))); connect(jabberClient, SIGNAL(groupChatLeft(XMPP::Jid)), this, SLOT(slotGroupChatLeft(XMPP::Message))); connect(jabberClient, SIGNAL(groupChatPresence(XMPP::Jid,XMPP::Status)), this, SLOT(slotGroupChatPresence(XMPP::Jid,XMPP::Status))); } KMessageJabber::~KMessageJabber () { // delete mClient; } bool KMessageJabber::isConnected () const { return mClient->isConnected (); } void KMessageJabber::send (const QByteArray &msg) { XMPP::Message message(mPeerJid); message.setType("ksirkgame"); message.setId(QUuid::createUuid().toString().remove("{").remove("}").remove("-")); message.setBody(msg.toBase64()); mClient->sendMessage(message); } void KMessageJabber::slotMessageReceived(const XMPP::Message &message) { if (message.from().full() == mPeerJid) { - QByteArray msg = QByteArray::fromBase64(message.body().toAscii()); + QByteArray msg = QByteArray::fromBase64(message.body().toLatin1()); qCDebug(JABBER_PROTOCOL_LOG) << mPeerJid << msg; emit received (msg); } } QString KMessageJabber::peerName () const { return mPeerJid; } void KMessageJabber::slotGroupChatLeft(const XMPP::Message& msg) { qCDebug(JABBER_PROTOCOL_LOG) << msg.from().full() << msg.to().full() << msg.body(); } void KMessageJabber::slotResourceUnavailable(const Jid& jid, const Resource& resource) { qCDebug(JABBER_PROTOCOL_LOG) << jid.full() << resource.name(); } void KMessageJabber::slotGroupChatPresence(const XMPP::Jid& jid, const XMPP::Status& status) { qCDebug(JABBER_PROTOCOL_LOG) << jid.full() << status.status(); if (jid.full() == mPeerJid && !status.isAvailable()) { emit connectionBroken(); } } diff --git a/ksirk/Jabber/privacylist.cpp b/ksirk/Jabber/privacylist.cpp index e3e5c71..4d617a6 100644 --- a/ksirk/Jabber/privacylist.cpp +++ b/ksirk/Jabber/privacylist.cpp @@ -1,160 +1,162 @@ /* * privacylist.cpp * Copyright (C) 2006 Remko Troncon * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ + +#include #include #include #include #include #include "jabber_protocol_debug.h" // #include "jabberprotocol.h" #include "privacylist.h" #define ORDER_INCREMENT 10 PrivacyList::PrivacyList(const QString& name, const QList& items) : name_(name), items_(items) { - qSort(items_); + std::sort(items_.begin(), items_.end()); } PrivacyList::PrivacyList(const QDomElement& e) { fromXml(e); } void PrivacyList::updateItem(int index, const PrivacyListItem& item) { unsigned int order = items_[index].order(); items_[index] = item; items_[index].setOrder(order); } void PrivacyList::insertItem(int index, const PrivacyListItem& item) { items_.insert(index,item); reNumber(); } void PrivacyList::reNumber() { unsigned int order = 100; for (int i = 0; i < items_.size(); ++i) { items_[i].setOrder(order); order += ORDER_INCREMENT; } } bool PrivacyList::moveItemUp(int index) { if (index < items().count() && index > 0) { unsigned int order =items_[index].order(); if (order == items_[index-1].order()) { reNumber(); return true; } items_[index].setOrder(items_[index-1].order()); items_[index-1].setOrder(order); items_.swap(index,index-1); return true; } else { return false; } } bool PrivacyList::moveItemDown(int index) { if (index >= 0 && index < items().count()-1) { unsigned int order =items_[index].order(); if (order == items_[index+1].order()) { reNumber(); return true; } items_[index].setOrder(items_[index+1].order()); items_[index+1].setOrder(order); items_.swap(index,index+1); return true; } else { return false; } } bool PrivacyList::onlyBlockItems() const { bool allBlocked = true; bool fallThrough = false; QList::ConstIterator it; for (it = items_.begin(); it != items_.end() && allBlocked; ++it ) { if ((*it).type() == PrivacyListItem::FallthroughType && (*it).action() == PrivacyListItem::Allow && (*it).all()) { fallThrough = true; } else if ((*it).isBlock()) { if (fallThrough) allBlocked = false; } else { allBlocked = false; } } return allBlocked; } QDomElement PrivacyList::toXml(QDomDocument& doc) const { QDomElement list = doc.createElement("list"); list.setAttribute("name",name()); for (QList::ConstIterator it = items_.begin() ; it != items_.end(); it++) { list.appendChild((*it).toXml(doc)); } return list; } void PrivacyList::fromXml(const QDomElement& el) { //qCDebug(JABBER_PROTOCOL_LOG) << "Parsing privacy list"; if (el.isNull() || el.tagName() != "list") { qCWarning(JABBER_PROTOCOL_LOG) << "Invalid root tag for privacy list."; return; } setName(el.attribute("name")); for(QDomNode n = el.firstChild(); !n.isNull(); n = n.nextSibling()) { QDomElement e = n.toElement(); if (!e.isNull()) items_.append(PrivacyListItem(e)); } - qSort(items_); + std::sort(items_.begin(), items_.end()); } QString PrivacyList::toString() const { QString s; for (QList::ConstIterator it = items_.begin() ; it != items_.end(); it++) { s += QString("%1 (%2)\n").arg((*it).toString()).arg((*it).order()); } return s; } diff --git a/ksirk/iris/src/xmpp/sasl/digestmd5response.cpp b/ksirk/iris/src/xmpp/sasl/digestmd5response.cpp index 483690d..eff9036 100644 --- a/ksirk/iris/src/xmpp/sasl/digestmd5response.cpp +++ b/ksirk/iris/src/xmpp/sasl/digestmd5response.cpp @@ -1,85 +1,85 @@ /* * Copyright (C) 2008 Remko Troncon * See COPYING for license details. */ #include "xmpp/sasl/digestmd5response.h" #include #include #include #include "xmpp/sasl/digestmd5proplist.h" #include "xmpp/base/randomnumbergenerator.h" #include "xmpp/base64/base64.h" namespace XMPP { DIGESTMD5Response::DIGESTMD5Response(const QByteArray& challenge, const QString& service, const QString& host, const QString& arealm, const QString& user, const QString& authz, const QByteArray& password, const RandomNumberGenerator& rand) : isValid_(true) { QString realm = arealm; // get props DIGESTMD5PropList in; if(!in.fromString(challenge)) { isValid_ = false; return; } //qDebug() << (QString("simplesasl.cpp: IN: %1").arg(QString(in.toString()))); // make a cnonce QByteArray a; a.resize(32); for(int n = 0; n < (int)a.size(); ++n) { a[n] = (char) rand.generateNumberBetween(0, 255); } QByteArray cnonce = Base64::encode(a).toLatin1(); // make other variables if (realm.isEmpty()) { realm = QString::fromUtf8(in.get("realm")); } QByteArray nonce = in.get("nonce"); QByteArray nc = "00000001"; QByteArray uri = service.toUtf8() + '/' + host.toUtf8(); QByteArray qop = "auth"; // build 'response' QByteArray X = user.toUtf8() + ':' + realm.toUtf8() + ':' + password; QByteArray Y = QCA::Hash("md5").hash(X).toByteArray(); QByteArray tmp = ':' + nonce + ':' + cnonce; if (!authz.isEmpty()) tmp += ':' + authz.toUtf8(); //qDebug() << (QString(tmp)); QByteArray A1(Y + tmp); QByteArray A2 = QByteArray("AUTHENTICATE:") + uri; QByteArray HA1 = QCA::Hash("md5").hashToString(A1).toLatin1(); QByteArray HA2 = QCA::Hash("md5").hashToString(A2).toLatin1(); QByteArray KD = HA1 + ':' + nonce + ':' + nc + ':' + cnonce + ':' + qop + ':' + HA2; QByteArray Z = QCA::Hash("md5").hashToString(KD).toLatin1(); - //qDebug() << (QString("simplesasl.cpp: A1 = %1").arg(QString(A1)).toAscii()); - //qDebug() << (QString("simplesasl.cpp: A2 = %1").arg(QString(A2)).toAscii()); - //qDebug() << (QString("simplesasl.cpp: KD = %1").arg(QString(KD)).toAscii()); + //qDebug() << (QString("simplesasl.cpp: A1 = %1").arg(QString(A1)).toLatin1()); + //qDebug() << (QString("simplesasl.cpp: A2 = %1").arg(QString(A2)).toLatin1()); + //qDebug() << (QString("simplesasl.cpp: KD = %1").arg(QString(KD)).toLatin1()); // build output DIGESTMD5PropList out; out.set("username", user.toUtf8()); if (!realm.isEmpty()) out.set("realm", realm.toUtf8()); out.set("nonce", nonce); out.set("cnonce", cnonce); out.set("nc", nc); //out.set("serv-type", service.toUtf8()); //out.set("host", host.toUtf8()); out.set("digest-uri", uri); out.set("qop", qop); out.set("response", Z); out.set("charset", "utf-8"); if (!authz.isEmpty()) out.set("authzid", authz.toUtf8()); value_ = out.toString(); } } diff --git a/ksirk/iris/src/xmpp/xmpp-core/compressionhandler.cpp b/ksirk/iris/src/xmpp/xmpp-core/compressionhandler.cpp index e3f0add..f8fcf47 100644 --- a/ksirk/iris/src/xmpp/xmpp-core/compressionhandler.cpp +++ b/ksirk/iris/src/xmpp/xmpp-core/compressionhandler.cpp @@ -1,68 +1,68 @@ #include #include #include "compressionhandler.h" #include "xmpp/zlib/zlibcompressor.h" #include "xmpp/zlib/zlibdecompressor.h" CompressionHandler::CompressionHandler() : errorCode_(0) { outgoing_buffer_.open(QIODevice::ReadWrite); compressor_ = new ZLibCompressor(&outgoing_buffer_); incoming_buffer_.open(QIODevice::ReadWrite); decompressor_ = new ZLibDecompressor(&incoming_buffer_); } CompressionHandler::~CompressionHandler() { delete compressor_; delete decompressor_; } void CompressionHandler::writeIncoming(const QByteArray& a) { //qDebug("CompressionHandler::writeIncoming"); - //qDebug() << (QString("Incoming %1 bytes").arg(a.size()).toAscii()); + //qDebug() << (QString("Incoming %1 bytes").arg(a.size()).toLatin1()); errorCode_ = decompressor_->write(a); if (!errorCode_) QTimer::singleShot(0, this, SIGNAL(readyRead())); else QTimer::singleShot(0, this, SIGNAL(error())); } void CompressionHandler::write(const QByteArray& a) { - //qDebug() << (QString("CompressionHandler::write(%1)").arg(a.size()).toAscii()); + //qDebug() << (QString("CompressionHandler::write(%1)").arg(a.size()).toLatin1()); errorCode_ = compressor_->write(a); if (!errorCode_) QTimer::singleShot(0, this, SIGNAL(readyReadOutgoing())); else QTimer::singleShot(0, this, SIGNAL(error())); } QByteArray CompressionHandler::read() { //qDebug("CompressionHandler::read"); QByteArray b = incoming_buffer_.buffer(); incoming_buffer_.buffer().clear(); incoming_buffer_.reset(); return b; } QByteArray CompressionHandler::readOutgoing(int* i) { //qDebug("CompressionHandler::readOutgoing"); - //qDebug() << (QString("Outgoing %1 bytes").arg(outgoing_buffer_.size()).toAscii()); + //qDebug() << (QString("Outgoing %1 bytes").arg(outgoing_buffer_.size()).toLatin1()); QByteArray b = outgoing_buffer_.buffer(); outgoing_buffer_.buffer().clear(); outgoing_buffer_.reset(); *i = b.size(); return b; } int CompressionHandler::errorCode() { return errorCode_; } diff --git a/ksirk/iris/src/xmpp/xmpp-im/xmpp_vcard.cpp b/ksirk/iris/src/xmpp/xmpp-im/xmpp_vcard.cpp index cdbd49b..de3067d 100644 --- a/ksirk/iris/src/xmpp/xmpp-im/xmpp_vcard.cpp +++ b/ksirk/iris/src/xmpp/xmpp-im/xmpp_vcard.cpp @@ -1,1191 +1,1191 @@ /* * xmpp_vcard.cpp - classes for handling vCards * Copyright (C) 2003 Michail Pishchagin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "xmpp_vcard.h" #include #include #include // needed for image format recognition #include #include #include #include #include "xmpp_xmlcommon.h" using namespace XMPP; using namespace XMLHelper; //---------------------------------------------------------------------------- // VCard //---------------------------------------------------------------------------- QString image2type(const QByteArray &ba) { QBuffer buf; buf.setData(ba); buf.open(QIODevice::ReadOnly); QString format = QImageReader::imageFormat( &buf ); // TODO: add more formats if ( format.toUpper() == "PNG" || format == "PsiPNG" ) return "image/png"; if ( format.toUpper() == "MNG" ) return "video/x-mng"; if ( format.toUpper() == "GIF" ) return "image/gif"; if ( format.toUpper() == "BMP" ) return "image/bmp"; if ( format.toUpper() == "XPM" ) return "image/x-xpm"; if ( format.toUpper() == "SVG" ) return "image/svg+xml"; if ( format.toUpper() == "JPEG" ) return "image/jpeg"; - const QByteArray formatAscii = format.toAscii(); + const QByteArray formatAscii = format.toLatin1(); qWarning("WARNING! VCard::image2type: unknown format = '%s'", format.isNull() ? "UNKNOWN" : formatAscii.constData()); return "image/unknown"; } // Long lines of encoded binary data SHOULD BE folded to 75 characters using the folding method defined in [MIME-DIR]. static QString foldString(const QString &s) { QString ret; for (int i = 0; i < (int)s.length(); i++) { if ( !(i % 75) ) ret += '\n'; ret += s[i]; } return ret; } class VCard::Private { public: Private(); ~Private(); QString version; QString fullName; QString familyName, givenName, middleName, prefixName, suffixName; QString nickName; QByteArray photo; QString photoURI; QString bday; AddressList addressList; LabelList labelList; PhoneList phoneList; EmailList emailList; QString jid; QString mailer; QString timezone; Geo geo; QString title; QString role; QByteArray logo; QString logoURI; VCard *agent; QString agentURI; Org org; QStringList categories; QString note; QString prodId; QString rev; QString sortString; QByteArray sound; QString soundURI, soundPhonetic; QString uid; QString url; QString desc; PrivacyClass privacyClass; QByteArray key; bool isEmpty(); }; VCard::Private::Private() { privacyClass = pcNone; agent = 0; } VCard::Private::~Private() { delete agent; } bool VCard::Private::isEmpty() { if ( !version.isEmpty() || !fullName.isEmpty() || !familyName.isEmpty() || !givenName.isEmpty() || !middleName.isEmpty() || !prefixName.isEmpty() || !suffixName.isEmpty() || !nickName.isEmpty() || !photo.isEmpty() || !photoURI.isEmpty() || !bday.isEmpty() || !addressList.isEmpty() || !labelList.isEmpty() || !phoneList.isEmpty() || !emailList.isEmpty() || !jid.isEmpty() || !mailer.isEmpty() || !timezone.isEmpty() || !geo.lat.isEmpty() || !geo.lon.isEmpty() || !title.isEmpty() || !role.isEmpty() || !logo.isEmpty() || !logoURI.isEmpty() || (agent && !agent->isEmpty()) || !agentURI.isEmpty() || !org.name.isEmpty() || !org.unit.isEmpty() || !categories.isEmpty() || !note.isEmpty() || !prodId.isEmpty() || !rev.isEmpty() || !sortString.isEmpty() || !sound.isEmpty() || !soundURI.isEmpty() || !soundPhonetic.isEmpty() || !uid.isEmpty() || !url.isEmpty() || !desc.isEmpty() || (privacyClass != pcNone) || !key.isEmpty() ) { return false; } return true; } VCard::VCard() { d = new Private; } VCard::VCard(const VCard &from) { d = new Private; *this = from; } VCard & VCard::operator=(const VCard &from) { if(d->agent) { delete d->agent; d->agent = 0; } *d = *from.d; if(from.d->agent) { // dup the agent d->agent = new VCard(*from.d->agent); } return *this; } VCard::~VCard() { delete d; } QDomElement VCard::toXml(QDomDocument *doc) const { QDomElement v = doc->createElement("vCard"); v.setAttribute("version", "2.0"); v.setAttribute("prodid", "-//HandGen//NONSGML vGen v1.0//EN"); v.setAttribute("xmlns", "vcard-temp"); if ( !d->version.isEmpty() ) v.appendChild( textTag(doc, "VERSION", d->version) ); if ( !d->fullName.isEmpty() ) v.appendChild( textTag(doc, "FN", d->fullName) ); if ( !d->familyName.isEmpty() || !d->givenName.isEmpty() || !d->middleName.isEmpty() || !d->prefixName.isEmpty() || !d->suffixName.isEmpty() ) { QDomElement w = doc->createElement("N"); if ( !d->familyName.isEmpty() ) w.appendChild( textTag(doc, "FAMILY", d->familyName) ); if ( !d->givenName.isEmpty() ) w.appendChild( textTag(doc, "GIVEN", d->givenName) ); if ( !d->middleName.isEmpty() ) w.appendChild( textTag(doc, "MIDDLE", d->middleName) ); if ( !d->prefixName.isEmpty() ) w.appendChild( textTag(doc, "PREFIX", d->prefixName) ); if ( !d->suffixName.isEmpty() ) w.appendChild( textTag(doc, "SUFFIX", d->suffixName) ); v.appendChild(w); } if ( !d->nickName.isEmpty() ) v.appendChild( textTag(doc, "NICKNAME", d->nickName) ); if ( !d->photo.isEmpty() || !d->photoURI.isEmpty() ) { QDomElement w = doc->createElement("PHOTO"); if ( !d->photo.isEmpty() ) { w.appendChild( textTag(doc, "TYPE", image2type(d->photo)) ); w.appendChild( textTag(doc, "BINVAL", foldString( QCA::Base64().arrayToString(d->photo)) ) ); } else if ( !d->photoURI.isEmpty() ) w.appendChild( textTag(doc, "EXTVAL", d->photoURI) ); v.appendChild(w); } if ( !d->bday.isEmpty() ) v.appendChild( textTag(doc, "BDAY", d->bday) ); if ( !d->addressList.isEmpty() ) { AddressList::Iterator it = d->addressList.begin(); for ( ; it != d->addressList.end(); ++it ) { QDomElement w = doc->createElement("ADR"); Address a = *it; if ( a.home ) w.appendChild( emptyTag(doc, "HOME") ); if ( a.work ) w.appendChild( emptyTag(doc, "WORK") ); if ( a.postal ) w.appendChild( emptyTag(doc, "POSTAL") ); if ( a.parcel ) w.appendChild( emptyTag(doc, "PARCEL") ); if ( a.dom ) w.appendChild( emptyTag(doc, "DOM") ); if ( a.intl ) w.appendChild( emptyTag(doc, "INTL") ); if ( a.pref ) w.appendChild( emptyTag(doc, "PREF") ); if ( !a.pobox.isEmpty() ) w.appendChild( textTag(doc, "POBOX", a.pobox) ); if ( !a.extaddr.isEmpty() ) w.appendChild( textTag(doc, "EXTADR", a.extaddr) ); if ( !a.street.isEmpty() ) w.appendChild( textTag(doc, "STREET", a.street) ); if ( !a.locality.isEmpty() ) w.appendChild( textTag(doc, "LOCALITY", a.locality) ); if ( !a.region.isEmpty() ) w.appendChild( textTag(doc, "REGION", a.region) ); if ( !a.pcode.isEmpty() ) w.appendChild( textTag(doc, "PCODE", a.pcode) ); if ( !a.country.isEmpty() ) w.appendChild( textTag(doc, "CTRY", a.country) ); v.appendChild(w); } } if ( !d->labelList.isEmpty() ) { LabelList::Iterator it = d->labelList.begin(); for ( ; it != d->labelList.end(); ++it ) { QDomElement w = doc->createElement("LABEL"); Label l = *it; if ( l.home ) w.appendChild( emptyTag(doc, "HOME") ); if ( l.work ) w.appendChild( emptyTag(doc, "WORK") ); if ( l.postal ) w.appendChild( emptyTag(doc, "POSTAL") ); if ( l.parcel ) w.appendChild( emptyTag(doc, "PARCEL") ); if ( l.dom ) w.appendChild( emptyTag(doc, "DOM") ); if ( l.intl ) w.appendChild( emptyTag(doc, "INTL") ); if ( l.pref ) w.appendChild( emptyTag(doc, "PREF") ); if ( !l.lines.isEmpty() ) { QStringList::Iterator it = l.lines.begin(); for ( ; it != l.lines.end(); ++it ) w.appendChild( textTag(doc, "LINE", *it) ); } v.appendChild(w); } } if ( !d->phoneList.isEmpty() ) { PhoneList::Iterator it = d->phoneList.begin(); for ( ; it != d->phoneList.end(); ++it ) { QDomElement w = doc->createElement("TEL"); Phone p = *it; if ( p.home ) w.appendChild( emptyTag(doc, "HOME") ); if ( p.work ) w.appendChild( emptyTag(doc, "WORK") ); if ( p.voice ) w.appendChild( emptyTag(doc, "VOICE") ); if ( p.fax ) w.appendChild( emptyTag(doc, "FAX") ); if ( p.pager ) w.appendChild( emptyTag(doc, "PAGER") ); if ( p.msg ) w.appendChild( emptyTag(doc, "MSG") ); if ( p.cell ) w.appendChild( emptyTag(doc, "CELL") ); if ( p.video ) w.appendChild( emptyTag(doc, "VIDEO") ); if ( p.bbs ) w.appendChild( emptyTag(doc, "BBS") ); if ( p.modem ) w.appendChild( emptyTag(doc, "MODEM") ); if ( p.isdn ) w.appendChild( emptyTag(doc, "ISDN") ); if ( p.pcs ) w.appendChild( emptyTag(doc, "PCS") ); if ( p.pref ) w.appendChild( emptyTag(doc, "PREF") ); if ( !p.number.isEmpty() ) w.appendChild( textTag(doc, "NUMBER", p.number) ); v.appendChild(w); } } if ( !d->emailList.isEmpty() ) { EmailList::Iterator it = d->emailList.begin(); for ( ; it != d->emailList.end(); ++it ) { QDomElement w = doc->createElement("EMAIL"); Email e = *it; if ( e.home ) w.appendChild( emptyTag(doc, "HOME") ); if ( e.work ) w.appendChild( emptyTag(doc, "WORK") ); if ( e.internet ) w.appendChild( emptyTag(doc, "INTERNET") ); if ( e.x400 ) w.appendChild( emptyTag(doc, "X400") ); if ( !e.userid.isEmpty() ) w.appendChild( textTag(doc, "USERID", e.userid) ); v.appendChild(w); } } if ( !d->jid.isEmpty() ) v.appendChild( textTag(doc, "JABBERID", d->jid) ); if ( !d->mailer.isEmpty() ) v.appendChild( textTag(doc, "MAILER", d->mailer) ); if ( !d->timezone.isEmpty() ) v.appendChild( textTag(doc, "TZ", d->timezone) ); if ( !d->geo.lat.isEmpty() || !d->geo.lon.isEmpty() ) { QDomElement w = doc->createElement("GEO"); if ( !d->geo.lat.isEmpty() ) w.appendChild( textTag(doc, "LAT", d->geo.lat) ); if ( !d->geo.lon.isEmpty() ) w.appendChild( textTag(doc, "LON", d->geo.lon)); v.appendChild(w); } if ( !d->title.isEmpty() ) v.appendChild( textTag(doc, "TITLE", d->title) ); if ( !d->role.isEmpty() ) v.appendChild( textTag(doc, "ROLE", d->role) ); if ( !d->logo.isEmpty() || !d->logoURI.isEmpty() ) { QDomElement w = doc->createElement("LOGO"); if ( !d->logo.isEmpty() ) { w.appendChild( textTag(doc, "TYPE", image2type(d->logo)) ); w.appendChild( textTag(doc, "BINVAL", foldString( QCA::Base64().arrayToString(d->logo)) ) ); } else if ( !d->logoURI.isEmpty() ) w.appendChild( textTag(doc, "EXTVAL", d->logoURI) ); v.appendChild(w); } if ( !d->agentURI.isEmpty() || (d->agent && d->agent->isEmpty()) ) { QDomElement w = doc->createElement("AGENT"); if ( d->agent && !d->agent->isEmpty() ) w.appendChild( d->agent->toXml(doc) ); else if ( !d->agentURI.isEmpty() ) w.appendChild( textTag(doc, "EXTVAL", d->agentURI) ); v.appendChild(w); } if ( !d->org.name.isEmpty() || !d->org.unit.isEmpty() ) { QDomElement w = doc->createElement("ORG"); if ( !d->org.name.isEmpty() ) w.appendChild( textTag(doc, "ORGNAME", d->org.name) ); if ( !d->org.unit.isEmpty() ) { QStringList::Iterator it = d->org.unit.begin(); for ( ; it != d->org.unit.end(); ++it ) w.appendChild( textTag(doc, "ORGUNIT", *it) ); } v.appendChild(w); } if ( !d->categories.isEmpty() ) { QDomElement w = doc->createElement("CATEGORIES"); QStringList::Iterator it = d->categories.begin(); for ( ; it != d->categories.end(); ++it ) w.appendChild( textTag(doc, "KEYWORD", *it) ); v.appendChild(w); } if ( !d->note.isEmpty() ) v.appendChild( textTag(doc, "NOTE", d->note) ); if ( !d->prodId.isEmpty() ) v.appendChild( textTag(doc, "PRODID", d->prodId) ); if ( !d->rev.isEmpty() ) v.appendChild( textTag(doc, "REV", d->rev) ); if ( !d->sortString.isEmpty() ) v.appendChild( textTag(doc, "SORT-STRING", d->sortString) ); if ( !d->sound.isEmpty() || !d->soundURI.isEmpty() || !d->soundPhonetic.isEmpty() ) { QDomElement w = doc->createElement("SOUND"); if ( !d->sound.isEmpty() ) w.appendChild( textTag(doc, "BINVAL", foldString( QCA::Base64().arrayToString(d->sound)) ) ); else if ( !d->soundURI.isEmpty() ) w.appendChild( textTag(doc, "EXTVAL", d->soundURI) ); else if ( !d->soundPhonetic.isEmpty() ) w.appendChild( textTag(doc, "PHONETIC", d->soundPhonetic) ); v.appendChild(w); } if ( !d->uid.isEmpty() ) v.appendChild( textTag(doc, "UID", d->uid) ); if ( !d->url.isEmpty() ) v.appendChild( textTag(doc, "URL", d->url) ); if ( !d->desc.isEmpty() ) v.appendChild( textTag(doc, "DESC", d->desc) ); if ( d->privacyClass != pcNone ) { QDomElement w = doc->createElement("CLASS"); if ( d->privacyClass == pcPublic ) w.appendChild( emptyTag(doc, "PUBLIC") ); else if ( d->privacyClass == pcPrivate ) w.appendChild( emptyTag(doc, "PRIVATE") ); else if ( d->privacyClass == pcConfidential ) w.appendChild( emptyTag(doc, "CONFIDENTIAL") ); v.appendChild(w); } if ( !d->key.isEmpty() ) { QDomElement w = doc->createElement("KEY"); // TODO: Justin, please check out this code w.appendChild( textTag(doc, "TYPE", "text/plain")); // FIXME w.appendChild( textTag(doc, "CRED", QString::fromUtf8(d->key)) ); // FIXME v.appendChild(w); } return v; } bool VCard::fromXml(const QDomElement &q) { if ( q.tagName().toUpper() != "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().toUpper(); bool found; QDomElement e; if ( tag == "VERSION" ) d->version = i.text().trimmed(); else if ( tag == "FN" ) d->fullName = i.text().trimmed(); 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().trimmed(); else if ( tag == "PHOTO" ) { d->photo = QCA::Base64().stringToArray(subTagText(i, "BINVAL").replace("\n","")).toByteArray(); d->photoURI = subTagText(i, "EXTVAL"); } else if ( tag == "BDAY" ) d->bday = i.text().trimmed(); 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"); if ( a.country.isEmpty() ) // FIXME: Workaround for Psi prior to 0.9 if ( hasSubTag(i, "COUNTRY") ) a.country = subTagText(i, "COUNTRY"); if ( a.extaddr.isEmpty() ) // FIXME: Workaround for Psi prior to 0.9 if ( hasSubTag(i, "EXTADD") ) a.extaddr = subTagText(i, "EXTADD"); 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().toUpper() == "LINE" ) l.lines.append ( ii.text().trimmed() ); } 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"); if ( p.number.isEmpty() ) // FIXME: Workaround for Psi prior to 0.9 if ( hasSubTag(i, "VOICE") ) p.number = subTagText(i, "VOICE"); 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"); if ( m.userid.isEmpty() ) // FIXME: Workaround for Psi prior to 0.9 if ( !i.text().isEmpty() ) m.userid = i.text().trimmed(); d->emailList.append ( m ); } else if ( tag == "JABBERID" ) d->jid = i.text().trimmed(); else if ( tag == "MAILER" ) d->mailer = i.text().trimmed(); else if ( tag == "TZ" ) d->timezone = i.text().trimmed(); else if ( tag == "GEO" ) { d->geo.lat = subTagText(i, "LAT"); d->geo.lon = subTagText(i, "LON"); } else if ( tag == "TITLE" ) d->title = i.text().trimmed(); else if ( tag == "ROLE" ) d->role = i.text().trimmed(); else if ( tag == "LOGO" ) { d->logo = QCA::Base64().stringToArray( subTagText(i, "BINVAL").replace("\n","") ).toByteArray(); 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().toUpper() == "ORGUNIT" ) d->org.unit.append( ii.text().trimmed() ); } } 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().toUpper() == "KEYWORD" ) d->categories << ee.text().trimmed(); } } else if ( tag == "NOTE" ) d->note = i.text().trimmed(); else if ( tag == "PRODID" ) d->prodId = i.text().trimmed(); else if ( tag == "REV" ) d->rev = i.text().trimmed(); else if ( tag == "SORT-STRING" ) d->sortString = i.text().trimmed(); else if ( tag == "SOUND" ) { d->sound = QCA::Base64().stringToArray( subTagText(i, "BINVAL").replace("\n","") ).toByteArray(); d->soundURI = subTagText(i, "EXTVAL"); d->soundPhonetic = subTagText(i, "PHONETIC"); } else if ( tag == "UID" ) d->uid = i.text().trimmed(); else if ( tag == "URL") d->url = i.text().trimmed(); else if ( tag == "DESC" ) d->desc = i.text().trimmed(); 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().trimmed(); e = findSubTag(i, "CRED", &found ); if ( !found ) e = findSubTag(i, "BINVAL", &found); // case for very clever clients ;-) if ( found ) d->key = e.text().toUtf8(); // FIXME } } return true; } bool VCard::isEmpty() const { return d->isEmpty(); } // Some constructors VCard::Address::Address() { home = work = postal = parcel = dom = intl = pref = false; } VCard::Label::Label() { home = work = postal = parcel = dom = intl = pref = false; } VCard::Phone::Phone() { home = work = voice = fax = pager = msg = cell = video = bbs = modem = isdn = pcs = pref = false; } VCard::Email::Email() { home = work = internet = x400 = false; } VCard::Geo::Geo() { } VCard::Org::Org() { } // vCard properties... const QString &VCard::version() const { return d->version; } void VCard::setVersion(const QString &v) { d->version = v; } const QString &VCard::fullName() const { return d->fullName; } void VCard::setFullName(const QString &n) { d->fullName = n; } const QString &VCard::familyName() const { return d->familyName; } void VCard::setFamilyName(const QString &n) { d->familyName = n; } const QString &VCard::givenName() const { return d->givenName; } void VCard::setGivenName(const QString &n) { d->givenName = n; } const QString &VCard::middleName() const { return d->middleName; } void VCard::setMiddleName(const QString &n) { d->middleName = n; } const QString &VCard::prefixName() const { return d->prefixName; } void VCard::setPrefixName(const QString &p) { d->prefixName = p; } const QString &VCard::suffixName() const { return d->suffixName; } void VCard::setSuffixName(const QString &s) { d->suffixName = s; } const QString &VCard::nickName() const { return d->nickName; } void VCard::setNickName(const QString &n) { d->nickName = n; } const QByteArray &VCard::photo() const { return d->photo; } void VCard::setPhoto(const QByteArray &i) { d->photo = i; } const QString &VCard::photoURI() const { return d->photoURI; } void VCard::setPhotoURI(const QString &p) { d->photoURI = p; } const QDate VCard::bday() const { return QDate::fromString(d->bday); } void VCard::setBday(const QDate &date) { d->bday = date.toString(); } const QString &VCard::bdayStr() const { return d->bday; } void VCard::setBdayStr(const QString &date) { d->bday = date; } const VCard::AddressList &VCard::addressList() const { return d->addressList; } void VCard::setAddressList(const VCard::AddressList &a) { d->addressList = a; } const VCard::LabelList &VCard::labelList() const { return d->labelList; } void VCard::setLabelList(const VCard::LabelList &l) { d->labelList = l; } const VCard::PhoneList &VCard::phoneList() const { return d->phoneList; } void VCard::setPhoneList(const VCard::PhoneList &p) { d->phoneList = p; } const VCard::EmailList &VCard::emailList() const { return d->emailList; } void VCard::setEmailList(const VCard::EmailList &e) { d->emailList = e; } const QString &VCard::jid() const { return d->jid; } void VCard::setJid(const QString &j) { d->jid = j; } const QString &VCard::mailer() const { return d->mailer; } void VCard::setMailer(const QString &m) { d->mailer = m; } const QString &VCard::timezone() const { return d->timezone; } void VCard::setTimezone(const QString &t) { d->timezone = t; } const VCard::Geo &VCard::geo() const { return d->geo; } void VCard::setGeo(const VCard::Geo &g) { d->geo = g; } const QString &VCard::title() const { return d->title; } void VCard::setTitle(const QString &t) { d->title = t; } const QString &VCard::role() const { return d->role; } void VCard::setRole(const QString &r) { d->role = r; } const QByteArray &VCard::logo() const { return d->logo; } void VCard::setLogo(const QByteArray &i) { d->logo = i; } const QString &VCard::logoURI() const { return d->logoURI; } void VCard::setLogoURI(const QString &l) { d->logoURI = l; } const VCard *VCard::agent() const { return d->agent; } void VCard::setAgent(const VCard &v) { if ( !d->agent ) d->agent = new VCard; *(d->agent) = v; } const QString VCard::agentURI() const { return d->agentURI; } void VCard::setAgentURI(const QString &a) { d->agentURI = a; } const VCard::Org &VCard::org() const { return d->org; } void VCard::setOrg(const VCard::Org &o) { d->org = o; } const QStringList &VCard::categories() const { return d->categories; } void VCard::setCategories(const QStringList &c) { d->categories = c; } const QString &VCard::note() const { return d->note; } void VCard::setNote(const QString &n) { d->note = n; } const QString &VCard::prodId() const { return d->prodId; } void VCard::setProdId(const QString &p) { d->prodId = p; } const QString &VCard::rev() const { return d->rev; } void VCard::setRev(const QString &r) { d->rev = r; } const QString &VCard::sortString() const { return d->sortString; } void VCard::setSortString(const QString &s) { d->sortString = s; } const QByteArray &VCard::sound() const { return d->sound; } void VCard::setSound(const QByteArray &s) { d->sound = s; } const QString &VCard::soundURI() const { return d->soundURI; } void VCard::setSoundURI(const QString &s) { d->soundURI = s; } const QString &VCard::soundPhonetic() const { return d->soundPhonetic; } void VCard::setSoundPhonetic(const QString &s) { d->soundPhonetic = s; } const QString &VCard::uid() const { return d->uid; } void VCard::setUid(const QString &u) { d->uid = u; } const QString &VCard::url() const { return d->url; } void VCard::setUrl(const QString &u) { d->url = u; } const QString &VCard::desc() const { return d->desc; } void VCard::setDesc(const QString &desc) { d->desc = desc; } const VCard::PrivacyClass &VCard::privacyClass() const { return d->privacyClass; } void VCard::setPrivacyClass(const VCard::PrivacyClass &c) { d->privacyClass = c; } const QByteArray &VCard::key() const { return d->key; } void VCard::setKey(const QByteArray &k) { d->key = k; }