diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-08-10 16:22:18 +0000 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-08-10 16:22:18 +0000 |
| commit | 70c376063aa3a30db16facd8c103b2c6ef3b3e36 (patch) | |
| tree | 5b28dd41176dba2d11eb45c3a6ed84fb7f263498 /example | |
| parent | 1b16399a98d3f659d349e3e13e12d91dab954a22 (diff) | |
| download | qxmpp-70c376063aa3a30db16facd8c103b2c6ef3b3e36.tar.gz | |
rename "example" to "examples"
Diffstat (limited to 'example')
41 files changed, 0 insertions, 2027 deletions
diff --git a/example/example.pri b/example/example.pri deleted file mode 100644 index 0875ca16..00000000 --- a/example/example.pri +++ /dev/null @@ -1,19 +0,0 @@ -TEMPLATE = app - -INCLUDEPATH += ../../source - -QT += network xml - -CONFIG += console debug_and_release - -CONFIG(debug, debug|release) { - QXMPP_LIB = qxmpp_d - QXMPP_DIR = ../../source/debug -} else { - QXMPP_LIB = qxmpp - QXMPP_DIR = ../../source/release -} - -LIBS += -L$$QXMPP_DIR -l$$QXMPP_LIB -PRE_TARGETDEPS += $${QXMPP_DIR}/lib$${QXMPP_LIB}.a - diff --git a/example/example.pro b/example/example.pro deleted file mode 100644 index c19cfde3..00000000 --- a/example/example.pro +++ /dev/null @@ -1,13 +0,0 @@ -TEMPLATE = subdirs - -SUBDIRS = example_0_connected\ - example_1_echoClient\ - example_2_rosterHandling\ - example_3_transferHandling\ - example_4_callHandling\ - example_5_rpcInterface\ - example_6_rpcClient\ - example_7_archiveHandling\ - tests - -CONFIG += debug_and_release diff --git a/example/example_0_connected/README b/example/example_0_connected/README deleted file mode 100644 index fb84fea9..00000000 --- a/example/example_0_connected/README +++ /dev/null @@ -1,5 +0,0 @@ -This example just connects to the xmpp server. And start receiving presences (updates) from the server. - -After running this example, you can see this user online, if it's added in your roster (friends list). - -Logging type has been set to stdout. You can see the progress on the command line. diff --git a/example/example_0_connected/example_0_connected.pro b/example/example_0_connected/example_0_connected.pro deleted file mode 100644 index 2e38510d..00000000 --- a/example/example_0_connected/example_0_connected.pro +++ /dev/null @@ -1,7 +0,0 @@ -include(../example.pri) - -TARGET = example_0_connected - -SOURCES += main.cpp - -OTHER_FILES += README diff --git a/example/example_0_connected/main.cpp b/example/example_0_connected/main.cpp deleted file mode 100644 index bb34f177..00000000 --- a/example/example_0_connected/main.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * 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. - * - */ - - -#include <QtCore/QCoreApplication> - -#include "QXmppClient.h" -#include "QXmppLogger.h" - -int main(int argc, char *argv[]) -{ - QCoreApplication a(argc, argv); - - QXmppLogger::getLogger()->setLoggingType(QXmppLogger::STDOUT); - - QXmppClient client; - -// For google talk -// client.connectToServer("talk.google.com", "usernamewithoutdomain", "passwd", "gmail.com"); - -// For jabber -// client.connectToServer("jabber.org", "usernamewithoutdomain", "passwd", "jabber.org"); - - client.connectToServer("talk.google.com", "qxmpp.test1", "qxmpp123", "gmail.com"); - - return a.exec(); -} diff --git a/example/example_1_echoClient/README b/example/example_1_echoClient/README deleted file mode 100644 index 4c3ac681..00000000 --- a/example/example_1_echoClient/README +++ /dev/null @@ -1,5 +0,0 @@ -This is a very simple bot which echoes the message sent to it. - -Run this example, send it a message from a friend of this bot. You will recieve the message back. - -This example shows how to receive and send messages. diff --git a/example/example_1_echoClient/echoClient.cpp b/example/example_1_echoClient/echoClient.cpp deleted file mode 100644 index a6780bcc..00000000 --- a/example/example_1_echoClient/echoClient.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * 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. - * - */ - - -#include "echoClient.h" -#include "QXmppMessage.h" - -echoClient::echoClient(QObject *parent) - : QXmppClient(parent) -{ - bool check = connect(this, SIGNAL(messageReceived(const QXmppMessage&)), - SLOT(messageReceived(const QXmppMessage&))); - Q_ASSERT(check); - Q_UNUSED(check); -} - -echoClient::~echoClient() -{ - -} - -void echoClient::messageReceived(const QXmppMessage& message) -{ - QString from = message.from(); - QString msg = message.body(); - - sendPacket(QXmppMessage("", from, "Your message: " + msg)); -} diff --git a/example/example_1_echoClient/echoClient.h b/example/example_1_echoClient/echoClient.h deleted file mode 100644 index 0412f10d..00000000 --- a/example/example_1_echoClient/echoClient.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * 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. - * - */ - - -#ifndef ECHOCLIENT_H -#define ECHOCLIENT_H - -#include "QXmppClient.h" - -class echoClient : public QXmppClient -{ - Q_OBJECT - -public: - echoClient(QObject *parent = 0); - ~echoClient(); - -public slots: - void messageReceived(const QXmppMessage&); -}; - -#endif // ECHOCLIENT_H diff --git a/example/example_1_echoClient/example_1_echoClient.pro b/example/example_1_echoClient/example_1_echoClient.pro deleted file mode 100644 index ec5a3f05..00000000 --- a/example/example_1_echoClient/example_1_echoClient.pro +++ /dev/null @@ -1,10 +0,0 @@ -include(../example.pri) - -TARGET = example_1_echoClient - -SOURCES += main.cpp \ - echoClient.cpp - -HEADERS += echoClient.h - -OTHER_FILES += README diff --git a/example/example_1_echoClient/main.cpp b/example/example_1_echoClient/main.cpp deleted file mode 100644 index dc26371f..00000000 --- a/example/example_1_echoClient/main.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * 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. - * - */ - - -#include <QtCore/QCoreApplication> -#include "echoClient.h" -#include "QXmppLogger.h" - -int main(int argc, char *argv[]) -{ - QCoreApplication a(argc, argv); - - QXmppLogger::getLogger()->setLoggingType(QXmppLogger::StdoutLogging); - - echoClient client; - client.connectToServer("talk.google.com", "qxmpp.test1", "qxmpp123", "gmail.com"); - return a.exec(); -} diff --git a/example/example_2_rosterHandling/README b/example/example_2_rosterHandling/README deleted file mode 100644 index 83c75d05..00000000 --- a/example/example_2_rosterHandling/README +++ /dev/null @@ -1 +0,0 @@ -This example demonstrates how to get the roster and presence updates. diff --git a/example/example_2_rosterHandling/example_2_rosterHandling.pro b/example/example_2_rosterHandling/example_2_rosterHandling.pro deleted file mode 100644 index a7a9d250..00000000 --- a/example/example_2_rosterHandling/example_2_rosterHandling.pro +++ /dev/null @@ -1,10 +0,0 @@ -include(../example.pri) - -TARGET = example_2_rosterHandling - -SOURCES += main.cpp \ - xmppClient.cpp - -HEADERS += xmppClient.h - -OTHER_FILES += README diff --git a/example/example_2_rosterHandling/main.cpp b/example/example_2_rosterHandling/main.cpp deleted file mode 100644 index 74f8bc62..00000000 --- a/example/example_2_rosterHandling/main.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * 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. - * - */ - - -#include <QtCore/QCoreApplication> -#include "xmppClient.h" -#include "QXmppLogger.h" - -int main(int argc, char *argv[]) -{ - QCoreApplication a(argc, argv); - - QXmppLogger::getLogger()->setLoggingType(QXmppLogger::FileLogging); - - xmppClient client; - client.connectToServer("talk.google.com", "qxmpp.test1@gmail.com", "qxmpp123"); - return a.exec(); -} diff --git a/example/example_2_rosterHandling/xmppClient.cpp b/example/example_2_rosterHandling/xmppClient.cpp deleted file mode 100644 index 353090fc..00000000 --- a/example/example_2_rosterHandling/xmppClient.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * 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. - * - */ - -#include <iostream> - -#include "QXmppMessage.h" -#include "QXmppRosterManager.h" - -#include "xmppClient.h" - -xmppClient::xmppClient(QObject *parent) - : QXmppClient(parent) -{ - bool check = connect(this, SIGNAL(connected()), - SLOT(clientConnected())); - Q_ASSERT(check); - - check = connect(&this->rosterManager(), SIGNAL(rosterReceived()), - SLOT(rosterReceived())); - Q_ASSERT(check); - - /// Then QXmppRoster::presenceChanged() is emitted whenever presence of someone - /// in roster changes - check = connect(&this->rosterManager(), - SIGNAL(presenceChanged(const QString&, const QString&)), - SLOT(presenceChanged(const QString&, const QString&))); - Q_ASSERT(check); -} - -xmppClient::~xmppClient() -{ - -} - -void xmppClient::clientConnected() -{ - std::cout<<"example_2_rosterHandling:: CONNECTED"<<std::endl; -} - -void xmppClient::rosterReceived() -{ - std::cout<<"example_2_rosterHandling:: Roster Received"<<std::endl; - QStringList list = rosterManager().getRosterBareJids(); - for(int i = 0; i < list.size(); ++i) - { - std::cout<<"Roster Received:: "<<qPrintable(list.at(i))<<std::endl; - } -} - -void xmppClient::presenceChanged(const QString& bareJid, - const QString& resource) -{ - std::cout<<"Presence changed:: "<< qPrintable(bareJid) - << qPrintable(resource)<<std::endl; -} diff --git a/example/example_2_rosterHandling/xmppClient.h b/example/example_2_rosterHandling/xmppClient.h deleted file mode 100644 index 90bcf9d2..00000000 --- a/example/example_2_rosterHandling/xmppClient.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * 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. - * - */ - - -#ifndef XMPPCLIENT_H -#define XMPPCLIENT_H - -#include "QXmppClient.h" - -class xmppClient : public QXmppClient -{ - Q_OBJECT - -public: - xmppClient(QObject *parent = 0); - ~xmppClient(); - -public slots: - void clientConnected(); - void rosterReceived(); - void presenceChanged(const QString& bareJid, const QString& resource); -}; - -#endif // XMPPCLIENT_H diff --git a/example/example_3_transferHandling/example_3_transferHandling.pro b/example/example_3_transferHandling/example_3_transferHandling.pro deleted file mode 100644 index 9ac85e59..00000000 --- a/example/example_3_transferHandling/example_3_transferHandling.pro +++ /dev/null @@ -1,8 +0,0 @@ -include(../example.pri) - -TARGET = example_3_transferHandling - -SOURCES += main.cpp \ - xmppClient.cpp - -HEADERS += xmppClient.h diff --git a/example/example_3_transferHandling/main.cpp b/example/example_3_transferHandling/main.cpp deleted file mode 100644 index 1d6b49b2..00000000 --- a/example/example_3_transferHandling/main.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Ian Reinhart Geiser - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * 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. - * - */ - -#include <cstdlib> -#include <cstdio> - -#include <QtCore/QCoreApplication> - -#include "QXmppLogger.h" -#include "xmppClient.h" - -int main(int argc, char *argv[]) -{ - QCoreApplication a(argc, argv); - - QXmppLogger::getLogger()->setLoggingType(QXmppLogger::StdoutLogging); - - // we want one argument : "send" or "receive" - if (argc != 2 || (strcmp(argv[1], "send") && strcmp(argv[1], "receive"))) - { - fprintf(stderr, "Usage: ibbClient send|receive\n"); - return EXIT_FAILURE; - } - const QString username = (!strcmp(argv[1], "send")) ? QLatin1String("qxmpp.test1") : QLatin1String("qxmpp.test2"); - - xmppClient client; - client.connectToServer("talk.google.com", username, "qxmpp123", "gmail.com"); - return a.exec(); -} diff --git a/example/example_3_transferHandling/xmppClient.cpp b/example/example_3_transferHandling/xmppClient.cpp deleted file mode 100644 index 4d092491..00000000 --- a/example/example_3_transferHandling/xmppClient.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Authors: - * Ian Reinhart Geiser - * Jeremy Lainé - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * 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. - * - */ - -#include <QBuffer> -#include <QDebug> - -#include "QXmppMessage.h" -#include "QXmppUtils.h" - -#include "xmppClient.h" - -xmppClient::xmppClient(QObject *parent) - : QXmppClient(parent) -{ - // comment the following to use all available methods (highly recommended) - transferManager().setSupportedMethods(QXmppTransferJob::InBandMethod); - - bool check = connect(this, SIGNAL(presenceReceived(QXmppPresence)), - this, SLOT(slotPresenceReceived(QXmppPresence))); - Q_ASSERT(check); - - check = connect(&transferManager(), SIGNAL(fileReceived(QXmppTransferJob*)), - this, SLOT(slotFileReceived(QXmppTransferJob*))); - Q_ASSERT(check); -} - -/// A file transfer failed. - -void xmppClient::slotError(QXmppTransferJob::Error error) -{ - qDebug() << "Transmission failed:" << error; -} - -/// A file transfer request was received. - -void xmppClient::slotFileReceived(QXmppTransferJob *job) -{ - qDebug() << "Got transfer request from:" << job->jid(); - - bool check = connect(job, SIGNAL(error(QXmppTransferJob::Error)), this, SLOT(slotError(QXmppTransferJob::Error))); - Q_ASSERT(check); - - check = connect(job, SIGNAL(finished()), this, SLOT(slotFinished())); - Q_ASSERT(check); - - check = connect(job, SIGNAL(progress(qint64,qint64)), this, SLOT(slotProgress(qint64,qint64))); - Q_ASSERT(check); - - // allocate a buffer to receive the file - QBuffer *buffer = new QBuffer(this); - buffer->open(QIODevice::WriteOnly); - job->accept(buffer); -} - -/// A file transfer finished. - -void xmppClient::slotFinished() -{ - qDebug() << "Transmission finished"; -} - -/// A presence was received - -void xmppClient::slotPresenceReceived(const QXmppPresence &presence) -{ - const QLatin1String recipient("qxmpp.test2@gmail.com"); - - // if we are the recipient, or if the presence is not from the recipient, - // do nothing - if (configuration().jidBare() == recipient || - jidToBareJid(presence.from()) != recipient || - presence.type() != QXmppPresence::Available) - return; - - // send the file and connect to the job's signals - QXmppTransferJob *job = transferManager().sendFile(presence.from(), "xmppClient.cpp"); - - bool check = connect( job, SIGNAL(error(QXmppTransferJob::Error)), - this, SLOT(slotError(QXmppTransferJob::Error)) ); - Q_ASSERT(check); - - check = connect( job, SIGNAL(finished()), - this, SLOT(slotFinished()) ); - Q_ASSERT(check); - - check = connect( job, SIGNAL(progress(qint64,qint64)), - this, SLOT(slotProgress(qint64,qint64)) ); - Q_ASSERT(check); -} - -/// A file transfer has made progress. - -void xmppClient::slotProgress(qint64 done, qint64 total) -{ - qDebug() << "Transmission progress:" << done << "/" << total; -} diff --git a/example/example_3_transferHandling/xmppClient.h b/example/example_3_transferHandling/xmppClient.h deleted file mode 100644 index f57168db..00000000 --- a/example/example_3_transferHandling/xmppClient.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Ian Reinhart Geiser - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * 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. - * - */ - - -#ifndef IBBCLIENT_H -#define IBBCLIENT_H - -#include "QXmppClient.h" -#include "QXmppTransferManager.h" - -class QBuffer; - -class xmppClient : public QXmppClient -{ - Q_OBJECT - -public: - xmppClient(QObject *parent = 0); - -private slots: - void slotError(QXmppTransferJob::Error error); - void slotFileReceived(QXmppTransferJob *job); - void slotFinished(); - void slotPresenceReceived(const QXmppPresence &presence); - void slotProgress(qint64 done, qint64 total); -}; - -#endif // IBBCLIENT_H diff --git a/example/example_4_callHandling/example_4_callHandling.pro b/example/example_4_callHandling/example_4_callHandling.pro deleted file mode 100644 index 5628f14f..00000000 --- a/example/example_4_callHandling/example_4_callHandling.pro +++ /dev/null @@ -1,10 +0,0 @@ -include(../example.pri) - -QT += multimedia - -TARGET = example_4_callHandling - -SOURCES += main.cpp \ - xmppClient.cpp - -HEADERS += xmppClient.h diff --git a/example/example_4_callHandling/main.cpp b/example/example_4_callHandling/main.cpp deleted file mode 100644 index 237da8ee..00000000 --- a/example/example_4_callHandling/main.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Ian Reinhart Geiser - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * 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. - * - */ - -#include <cstdlib> -#include <cstdio> - -#include <QCoreApplication> - -#include "QXmppLogger.h" -#include "xmppClient.h" - -int main(int argc, char *argv[]) -{ - QCoreApplication a(argc, argv); - - QXmppLogger::getLogger()->setLoggingType(QXmppLogger::StdoutLogging); - - // we want one argument : "send" or "receive" - if (argc != 2 || (strcmp(argv[1], "send") && strcmp(argv[1], "receive"))) - { - fprintf(stderr, "Usage: callClient send|receive\n"); - return EXIT_FAILURE; - } - const QString username = (!strcmp(argv[1], "send")) ? QLatin1String("qxmpp.test1") : QLatin1String("qxmpp.test2"); - - xmppClient client; - client.connectToServer("talk.google.com", username, "qxmpp123", "gmail.com"); - return a.exec(); -} diff --git a/example/example_4_callHandling/xmppClient.cpp b/example/example_4_callHandling/xmppClient.cpp deleted file mode 100644 index d4f040f3..00000000 --- a/example/example_4_callHandling/xmppClient.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Authors: - * Ian Reinhart Geiser - * Jeremy Lainé - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * 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. - * - */ - -#include <QAudioInput> -#include <QAudioOutput> -#include <QDebug> - -#include "QXmppCallManager.h" -#include "QXmppUtils.h" - -#include "xmppClient.h" - -xmppClient::xmppClient(QObject *parent) - : QXmppClient(parent) -{ - bool check = connect(this, SIGNAL(presenceReceived(QXmppPresence)), - this, SLOT(slotPresenceReceived(QXmppPresence))); - Q_ASSERT(check); - - check = connect(&callManager(), SIGNAL(callReceived(QXmppCall*)), - this, SLOT(slotCallReceived(QXmppCall*))); - Q_ASSERT(check); -} - -/// A call was received. - -void xmppClient::slotCallReceived(QXmppCall *call) -{ - qDebug() << "Got call from:" << call->jid(); - - bool check = connect(call, SIGNAL(connected()), this, SLOT(slotConnected())); - Q_ASSERT(check); - - check = connect(call, SIGNAL(finished()), this, SLOT(slotFinished())); - Q_ASSERT(check); - - // accept call - call->accept(); -} - -/// A call connected. - -void xmppClient::slotConnected() -{ - QXmppCall *call = qobject_cast<QXmppCall*>(sender()); - Q_ASSERT(call); - - qDebug() << "Call connected"; - - // prepare audio format - QAudioFormat format; - format.setFrequency(call->payloadType().clockrate()); - format.setChannels(call->payloadType().channels()); - format.setSampleSize(16); - format.setCodec("audio/pcm"); - format.setByteOrder(QAudioFormat::LittleEndian); - format.setSampleType(QAudioFormat::SignedInt); - - // initialise audio output - QAudioOutput *audioOutput = new QAudioOutput(format, this); - audioOutput->start(call); - - // initialise audio input - QAudioInput *audioInput = new QAudioInput(format, this); - audioInput->start(call); -} - -/// A call finished. - -void xmppClient::slotFinished() -{ - qDebug() << "Call finished"; -} - -/// A presence was received. - -void xmppClient::slotPresenceReceived(const QXmppPresence &presence) -{ - const QLatin1String recipient("qxmpp.test2@gmail.com"); - - // if we are the recipient, or if the presence is not from the recipient, - // do nothing - if (configuration().jidBare() == recipient || - jidToBareJid(presence.from()) != recipient || - presence.type() != QXmppPresence::Available) - return; - - // start the call and connect to the its signals - QXmppCall *call = callManager().call(presence.from()); - - bool check = connect(call, SIGNAL(connected()), this, SLOT(slotConnected())); - Q_ASSERT(check); - - check = connect(call, SIGNAL(finished()), this, SLOT(slotFinished())); - Q_ASSERT(check); -} - diff --git a/example/example_4_callHandling/xmppClient.h b/example/example_4_callHandling/xmppClient.h deleted file mode 100644 index 75e14dcc..00000000 --- a/example/example_4_callHandling/xmppClient.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Ian Reinhart Geiser - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * 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. - * - */ - - -#ifndef XMPPCLIENT_H -#define XMPPCLIENT_H - -#include "QXmppClient.h" - -class QXmppCall; - -class xmppClient : public QXmppClient -{ - Q_OBJECT - -public: - xmppClient(QObject *parent = 0); - -private slots: - void slotCallReceived(QXmppCall *call); - void slotConnected(); - void slotFinished(); - void slotPresenceReceived(const QXmppPresence &presence); -}; - -#endif // IBBCLIENT_H diff --git a/example/example_5_rpcInterface/example_5_rpcInterface.pro b/example/example_5_rpcInterface/example_5_rpcInterface.pro deleted file mode 100644 index eaa19e67..00000000 --- a/example/example_5_rpcInterface/example_5_rpcInterface.pro +++ /dev/null @@ -1,12 +0,0 @@ -include(../example.pri) - -TARGET = example_5_rpcInterface - -SOURCES += main.cpp \ - rpcClient.cpp \ - remoteinterface.cpp - -HEADERS += rpcClient.h \ - remoteinterface.h - -OTHER_FILES += README diff --git a/example/example_5_rpcInterface/main.cpp b/example/example_5_rpcInterface/main.cpp deleted file mode 100644 index 5792cc21..00000000 --- a/example/example_5_rpcInterface/main.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * 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. - * - */ - - -#include <QtCore/QCoreApplication> -#include "rpcClient.h" -#include "QXmppLogger.h" - -int main(int argc, char *argv[]) -{ - QCoreApplication a(argc, argv); - - QXmppLogger::getLogger()->setLoggingType(QXmppLogger::StdoutLogging); - - rpcClient client; - client.configuration().setUseSASLAuthentication( false ); - client.connectToServer("jabber.geiseri.com", "server", "Passw0rd", "geiseri.com"); - return a.exec(); -} diff --git a/example/example_5_rpcInterface/remoteinterface.cpp b/example/example_5_rpcInterface/remoteinterface.cpp deleted file mode 100644 index 77d52384..00000000 --- a/example/example_5_rpcInterface/remoteinterface.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "remoteinterface.h" - -RemoteInterface::RemoteInterface(QObject *parent) : QXmppInvokable(parent) -{ -} - -bool RemoteInterface::isAuthorized( const QString &jid ) const -{ - return true; -} - -QString RemoteInterface::echoString(const QString& message) -{ - return "Echo: " + message; -} diff --git a/example/example_5_rpcInterface/remoteinterface.h b/example/example_5_rpcInterface/remoteinterface.h deleted file mode 100644 index 02ce72d7..00000000 --- a/example/example_5_rpcInterface/remoteinterface.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef REMOTEINTERFACE_H -#define REMOTEINTERFACE_H - -#include "QXmppInvokable.h" - -class RemoteInterface : public QXmppInvokable -{ - Q_OBJECT -public: - RemoteInterface(QObject *parent = 0); - - bool isAuthorized( const QString &jid ) const; - -// RPC Interface -public slots: - QString echoString( const QString &message ); - -}; - -#endif // REMOTEINTERFACE_H diff --git a/example/example_5_rpcInterface/rpcClient.cpp b/example/example_5_rpcInterface/rpcClient.cpp deleted file mode 100644 index 60dd75ea..00000000 --- a/example/example_5_rpcInterface/rpcClient.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Ian Reinhart Geiser - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * 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. - * - */ - - -#include "rpcClient.h" -#include "remoteinterface.h" - -rpcClient::rpcClient(QObject *parent) - : QXmppClient(parent) -{ - addInvokableInterface( new RemoteInterface(this) ); -} - -rpcClient::~rpcClient() -{ - -} - diff --git a/example/example_5_rpcInterface/rpcClient.h b/example/example_5_rpcInterface/rpcClient.h deleted file mode 100644 index 22eda459..00000000 --- a/example/example_5_rpcInterface/rpcClient.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Ian Reinhart Geiser - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * 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. - * - */ - - -#ifndef RPCCLIENT_H -#define RPCCLIENT_H - -#include "QXmppClient.h" - -class rpcClient : public QXmppClient -{ - Q_OBJECT - -public: - rpcClient(QObject *parent = 0); - ~rpcClient(); - -}; - -#endif // RPCCLIENT_H diff --git a/example/example_5_rpcInterface/xmlrpctest.txt b/example/example_5_rpcInterface/xmlrpctest.txt deleted file mode 100644 index 4796fdd3..00000000 --- a/example/example_5_rpcInterface/xmlrpctest.txt +++ /dev/null @@ -1,63 +0,0 @@ -<stream:stream - to='geiseri.com' - xmlns='jabber:client' - xmlns:stream='http://etherx.jabber.org/streams'> - -<iq id='A3' type='set'> - <query xmlns='jabber:iq:auth'> - <username>client</username> - <resource>telnet</resource> - <password>Passw0rd</password> - </query> -</iq> - -<presence/> - -<iq type='set' - from='client@geiseri.com/telnet' - to='server@geiseri.com/QXmpp' - id='rpc1'> - <query xmlns='jabber:iq:rpc'> - <methodCall> - <methodName>RemoteInterface.echoString</methodName> - <params> - <param> - <value><string>Test string</string></value> - </param> - </params> - </methodCall> - </query> -</iq> - -<iq type='set' - from='client@geiseri.com/telnet' - to='server@geiseri.com/QXmpp' - id='rpc1'> - <query xmlns='jabber:iq:rpc'> - <methodCall> - <methodName>RemoteInterface.badMethod</methodName> - <params> - <param> - <value><string>Test string</string></value> - </param> - </params> - </methodCall> - </query> -</iq> - -<iq type='set' - from='client@geiseri.com/telnet' - to='server@geiseri.com/QXmpp' - id='rpc1'> - <query xmlns='jabber:iq:rpc'> - <methodCall> - <methodName>BadInterface.echoString</methodName> - <params> - <param> - <value><string>Test string</string></value> - </param> - </params> - </methodCall> - </query> -</iq> - diff --git a/example/example_6_rpcClient/example_6_rpcClient.pro b/example/example_6_rpcClient/example_6_rpcClient.pro deleted file mode 100644 index 0dbb806f..00000000 --- a/example/example_6_rpcClient/example_6_rpcClient.pro +++ /dev/null @@ -1,10 +0,0 @@ -include(../example.pri) - -TARGET = example_6_rpcClient - -SOURCES += main.cpp \ - rpcClient.cpp - -HEADERS += rpcClient.h - -OTHER_FILES += README diff --git a/example/example_6_rpcClient/main.cpp b/example/example_6_rpcClient/main.cpp deleted file mode 100644 index 08d43af4..00000000 --- a/example/example_6_rpcClient/main.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Ian Reinhart Geiser - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * 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. - * - */ - - -#include <QtCore/QCoreApplication> -#include "rpcClient.h" -#include "QXmppLogger.h" - -int main(int argc, char *argv[]) -{ - QCoreApplication a(argc, argv); - - QXmppLogger::getLogger()->setLoggingType(QXmppLogger::StdoutLogging); - - rpcClient client; - client.configuration().setUseSASLAuthentication( false ); - client.connectToServer("jabber.geiseri.com", "client", "Passw0rd", "geiseri.com"); - return a.exec(); -} diff --git a/example/example_6_rpcClient/rpcClient.cpp b/example/example_6_rpcClient/rpcClient.cpp deleted file mode 100644 index 3f63d062..00000000 --- a/example/example_6_rpcClient/rpcClient.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Ian Reinhart Geiser - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * 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. - * - */ - - -#include "rpcClient.h" -#include "QXmppRemoteMethod.h" -#include <qdebug.h> -#include <QTimer> - -rpcClient::rpcClient(QObject *parent) - : QXmppClient(parent) -{ - connect( this, SIGNAL(connected()), this, SLOT(isConnected())); -} - -rpcClient::~rpcClient() -{ - -} - -void rpcClient::isConnected() -{ - //We need to wait until we have sent the presense stuff, or for some - //reason the server ignores us... - QTimer::singleShot(5000, this, SLOT(invokeRemoteMethod())); -} - -void rpcClient::invokeRemoteMethod() -{ - QXmppRemoteMethodResult methodResult = callRemoteMethod( - "server@geiseri.com/QXmpp", "RemoteInterface.echoString", "This is a test" ); - if( methodResult.hasError ) - error( methodResult.code, methodResult.errorMessage ); - else - result( methodResult.result ); -} - -void rpcClient::result(const QVariant &value ) -{ - qDebug() << "Result:" << value; -} - -void rpcClient::error( int code, const QString &message ) -{ - qDebug() << "Error:" << code << message; -} diff --git a/example/example_6_rpcClient/rpcClient.h b/example/example_6_rpcClient/rpcClient.h deleted file mode 100644 index aeb7d605..00000000 --- a/example/example_6_rpcClient/rpcClient.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Ian Reinhart Geiser - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * 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. - * - */ - - -#ifndef RPCCLIENT_H -#define RPCCLIENT_H - -#include "QXmppClient.h" - -class rpcClient : public QXmppClient -{ - Q_OBJECT - -public: - rpcClient(QObject *parent = 0); - ~rpcClient(); - -public slots: - void isConnected(); - void invokeRemoteMethod(); - void result(const QVariant &value ); - void error( int code, const QString &message ); - -}; - -#endif // RPCCLIENT_H diff --git a/example/example_7_archiveHandling/example_7_archiveHandling.pro b/example/example_7_archiveHandling/example_7_archiveHandling.pro deleted file mode 100644 index 42b79c1d..00000000 --- a/example/example_7_archiveHandling/example_7_archiveHandling.pro +++ /dev/null @@ -1,8 +0,0 @@ -include(../example.pri) - -TARGET = example_7_archiveHandling - -SOURCES += main.cpp \ - xmppClient.cpp - -HEADERS += xmppClient.h diff --git a/example/example_7_archiveHandling/main.cpp b/example/example_7_archiveHandling/main.cpp deleted file mode 100644 index 74f8bc62..00000000 --- a/example/example_7_archiveHandling/main.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * 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. - * - */ - - -#include <QtCore/QCoreApplication> -#include "xmppClient.h" -#include "QXmppLogger.h" - -int main(int argc, char *argv[]) -{ - QCoreApplication a(argc, argv); - - QXmppLogger::getLogger()->setLoggingType(QXmppLogger::FileLogging); - - xmppClient client; - client.connectToServer("talk.google.com", "qxmpp.test1@gmail.com", "qxmpp123"); - return a.exec(); -} diff --git a/example/example_7_archiveHandling/xmppClient.cpp b/example/example_7_archiveHandling/xmppClient.cpp deleted file mode 100644 index 32959653..00000000 --- a/example/example_7_archiveHandling/xmppClient.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Jeremy Lainé - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * 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. - * - */ - - -#include <QDateTime> -#include <iostream> - -#include "QXmppArchiveIq.h" -#include "QXmppArchiveManager.h" - -#include "xmppClient.h" - -xmppClient::xmppClient(QObject *parent) - : QXmppClient(parent) -{ - bool check = connect(this, SIGNAL(connected()), - SLOT(clientConnected())); - Q_ASSERT(check); - - check = connect(&archiveManager(), SIGNAL(archiveChatReceived(const QXmppArchiveChat &)), - SLOT(archiveChatReceived(const QXmppArchiveChat &))); - Q_ASSERT(check); - - check = connect(&archiveManager(), SIGNAL(archiveListReceived(const QList<QXmppArchiveChat> &)), - SLOT(archiveListReceived(const QList<QXmppArchiveChat> &))); - Q_ASSERT(check); -} - -xmppClient::~xmppClient() -{ - -} - -void xmppClient::clientConnected() -{ - std::cout << "example_7_archiveHandling:: CONNECTED" << std::endl; - archiveManager().listCollections("", - QDateTime::currentDateTime().addDays(-7)); -} - -void xmppClient::archiveListReceived(const QList<QXmppArchiveChat> &chats) -{ - std::cout << "example_7_archiveHandling:: LIST RECEIVED" << std::endl; - foreach (const QXmppArchiveChat &chat, chats) - archiveManager().retrieveCollection(chat.with(), chat.start()); -} - -void xmppClient::archiveChatReceived(const QXmppArchiveChat &chat) -{ - std::cout << "example_7_archiveHandling:: CHAT RECEIVED" << std::endl; - foreach (const QXmppArchiveMessage &msg, chat.messages()) - { - std::cout << "example_7_archiveHandling::" << msg.body().toStdString() << std::endl; - } -} - diff --git a/example/example_7_archiveHandling/xmppClient.h b/example/example_7_archiveHandling/xmppClient.h deleted file mode 100644 index a672e98d..00000000 --- a/example/example_7_archiveHandling/xmppClient.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Jeremy Lainé - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * 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. - * - */ - - -#ifndef XMPPCLIENT_H -#define XMPPCLIENT_H - -#include "QXmppClient.h" - -class QXmppArchiveChat; - -class xmppClient : public QXmppClient -{ - Q_OBJECT - -public: - xmppClient(QObject *parent = 0); - ~xmppClient(); - -public slots: - void clientConnected(); - void archiveListReceived(const QList<QXmppArchiveChat> &chats); - void archiveChatReceived(const QXmppArchiveChat &chat); -}; - -#endif // XMPPCLIENT_H diff --git a/example/tests/tests.cpp b/example/tests/tests.cpp deleted file mode 100644 index a838020a..00000000 --- a/example/tests/tests.cpp +++ /dev/null @@ -1,534 +0,0 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Jeremy Lainé - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * 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. - * - */ - -#include <cstdlib> - -#include <QCoreApplication> -#include <QDomDocument> -#include <QVariant> -#include <QtTest/QtTest> - -#include "QXmppBind.h" -#include "QXmppJingleIq.h" -#include "QXmppMessage.h" -#include "QXmppPresence.h" -#include "QXmppRpcIq.h" -#include "QXmppSession.h" -#include "QXmppUtils.h" -#include "tests.h" - -void TestUtils::testHmac() -{ - QByteArray hmac = generateHmacMd5(QByteArray(16, 0x0b), QByteArray("Hi There")); - QCOMPARE(hmac, QByteArray::fromHex("9294727a3638bb1c13f48ef8158bfc9d")); - - hmac = generateHmacMd5(QByteArray("Jefe"), QByteArray("what do ya want for nothing?")); - QCOMPARE(hmac, QByteArray::fromHex("750c783e6ab0b503eaa86e310a5db738")); - - hmac = generateHmacMd5(QByteArray(16, 0xaa), QByteArray(50, 0xdd)); - QCOMPARE(hmac, QByteArray::fromHex("56be34521d144c88dbb8c733f0e8b3f6")); -} - -template <class T> -static void parsePacket(T &packet, const QByteArray &xml) -{ - //qDebug() << "parsing" << xml; - QDomDocument doc; - QCOMPARE(doc.setContent(xml, true), true); - QDomElement element = doc.documentElement(); - packet.parse(element); -} - -template <class T> -static void serializePacket(T &packet, const QByteArray &xml) -{ - QBuffer buffer; - buffer.open(QIODevice::ReadWrite); - QXmlStreamWriter writer(&buffer); - packet.toXml(&writer); - qDebug() << "expect " << xml; - qDebug() << "writing" << buffer.data(); - QCOMPARE(buffer.data(), xml); -} - -void TestPackets::testBindNoResource() -{ - const QByteArray xml( - "<iq id=\"bind_1\" type=\"set\">" - "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\"/>" - "</iq>"); - - QXmppBind bind; - parsePacket(bind, xml); - QCOMPARE(bind.type(), QXmppIq::Set); - QCOMPARE(bind.id(), QString("bind_1")); - QCOMPARE(bind.jid(), QString()); - QCOMPARE(bind.resource(), QString()); - serializePacket(bind, xml); -} - -void TestPackets::testBindResource() -{ - const QByteArray xml( - "<iq id=\"bind_2\" type=\"set\">" - "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\">" - "<resource>someresource</resource>" - "</bind>" - "</iq>"); - - QXmppBind bind; - parsePacket(bind, xml); - QCOMPARE(bind.type(), QXmppIq::Set); - QCOMPARE(bind.id(), QString("bind_2")); - QCOMPARE(bind.jid(), QString()); - QCOMPARE(bind.resource(), QString("someresource")); - serializePacket(bind, xml); -} - -void TestPackets::testBindResult() -{ - const QByteArray xml( - "<iq id=\"bind_2\" type=\"result\">" - "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\">" - "<jid>somenode@example.com/someresource</jid>" - "</bind>" - "</iq>"); - - QXmppBind bind; - parsePacket(bind, xml); - QCOMPARE(bind.type(), QXmppIq::Result); - QCOMPARE(bind.id(), QString("bind_2")); - QCOMPARE(bind.jid(), QString("somenode@example.com/someresource")); - QCOMPARE(bind.resource(), QString()); - serializePacket(bind, xml); -} - -void TestPackets::testMessage() -{ - const QByteArray xml( - "<message to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\" type=\"normal\"/>"); - - QXmppMessage message; - parsePacket(message, xml); - QCOMPARE(message.to(), QString("foo@example.com/QXmpp")); - QCOMPARE(message.from(), QString("bar@example.com/QXmpp")); - serializePacket(message, xml); -} - -void TestPackets::testMessageFull() -{ - const QByteArray xml( - "<message to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\" type=\"normal\">" - "<subject>test subject</subject>" - "<body>test body</body>" - "<thread>test thread</thread>" - "<composing xmlns=\"http://jabber.org/protocol/chatstates\"/>" - "</message>"); - - QXmppMessage message; - parsePacket(message, xml); - QCOMPARE(message.to(), QString("foo@example.com/QXmpp")); - QCOMPARE(message.from(), QString("bar@example.com/QXmpp")); - QCOMPARE(message.type(), QXmppMessage::Normal); - QCOMPARE(message.body(), QString("test body")); - QCOMPARE(message.subject(), QString("test subject")); - QCOMPARE(message.thread(), QString("test thread")); - QCOMPARE(message.state(), QXmppMessage::Composing); - serializePacket(message, xml); -} - -void TestPackets::testMessageDelay() -{ - const QByteArray xml( - "<message to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\" type=\"normal\">" - "<delay xmlns=\"urn:xmpp:delay\" stamp=\"2010-06-29T08:23:06Z\"/>" - "</message>"); - - QXmppMessage message; - parsePacket(message, xml); - QCOMPARE(message.stamp(), QDateTime(QDate(2010, 06, 29), QTime(8, 23, 6), Qt::UTC)); - serializePacket(message, xml); -} - -void TestPackets::testMessageLegacyDelay() -{ - const QByteArray xml( - "<message to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\" type=\"normal\">" - "<x xmlns=\"jabber:x:delay\" stamp=\"20100629T08:23:06\"/>" - "</message>"); - - QXmppMessage message; - parsePacket(message, xml); - QCOMPARE(message.stamp(), QDateTime(QDate(2010, 06, 29), QTime(8, 23, 6), Qt::UTC)); - serializePacket(message, xml); -} - -void TestPackets::testPresence() -{ - const QByteArray xml( - "<presence to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\"/>"); - - QXmppPresence presence; - parsePacket(presence, xml); - QCOMPARE(presence.to(), QString("foo@example.com/QXmpp")); - QCOMPARE(presence.from(), QString("bar@example.com/QXmpp")); - serializePacket(presence, xml); -} - -void TestPackets::testPresenceFull() -{ - const QByteArray xml( - "<presence to=\"foo@example.com/QXmpp\" from=\"bar@example.com/QXmpp\">" - "<show>away</show>" - "<status>In a meeting</status>" - "<priority>5</priority>" - "</presence>"); - - QXmppPresence presence; - parsePacket(presence, xml); - QCOMPARE(presence.to(), QString("foo@example.com/QXmpp")); - QCOMPARE(presence.from(), QString("bar@example.com/QXmpp")); - QCOMPARE(presence.status().type(), QXmppPresence::Status::Away); - QCOMPARE(presence.status().statusText(), QString("In a meeting")); - QCOMPARE(presence.status().priority(), 5); - serializePacket(presence, xml); -} - -void TestPackets::testSession() -{ - const QByteArray xml( - "<iq id=\"session_1\" to=\"example.com\" type=\"set\">" - "<session xmlns=\"urn:ietf:params:xml:ns:xmpp-session\"/>" - "</iq>"); - - QXmppSession session; - parsePacket(session, xml); - QCOMPARE(session.id(), QString("session_1")); - QCOMPARE(session.to(), QString("example.com")); - QCOMPARE(session.type(), QXmppIq::Set); - serializePacket(session, xml); -} - -void TestJingle::testSession() -{ - const QByteArray xml( - "<iq" - " id=\"zid615d9\"" - " to=\"juliet@capulet.lit/balcony\"" - " from=\"romeo@montague.lit/orchard\"" - " type=\"set\">" - "<jingle xmlns=\"urn:xmpp:jingle:1\"" - " action=\"session-initiate\"" - " initiator=\"romeo@montague.lit/orchard\"" - " sid=\"a73sjjvkla37jfea\">" - "<content creator=\"initiator\" name=\"this-is-a-stub\">" - "<description xmlns=\"urn:xmpp:jingle:apps:stub:0\"/>" - "<transport xmlns=\"urn:xmpp:jingle:transports:stub:0\"/>" - "</content>" - "</jingle>" - "</iq>"); - - QXmppJingleIq session; - parsePacket(session, xml); - QCOMPARE(session.action(), QXmppJingleIq::SessionInitiate); - QCOMPARE(session.initiator(), QLatin1String("romeo@montague.lit/orchard")); - QCOMPARE(session.sid(), QLatin1String("a73sjjvkla37jfea")); - QCOMPARE(session.content().creator(), QLatin1String("initiator")); - QCOMPARE(session.content().name(), QLatin1String("this-is-a-stub")); - QCOMPARE(session.reason().text(), QString()); - QCOMPARE(session.reason().type(), QXmppJingleIq::Reason::None); - serializePacket(session, xml); -} - -void TestJingle::testTerminate() -{ - const QByteArray xml( - "<iq" - " id=\"le71fa63\"" - " to=\"romeo@montague.lit/orchard\"" - " from=\"juliet@capulet.lit/balcony\"" - " type=\"set\">" - "<jingle xmlns=\"urn:xmpp:jingle:1\"" - " action=\"session-terminate\"" - " sid=\"a73sjjvkla37jfea\">" - "<reason>" - "<success/>" - "</reason>" - "</jingle>" - "</iq>"); - - QXmppJingleIq session; - parsePacket(session, xml); - QCOMPARE(session.action(), QXmppJingleIq::SessionTerminate); - QCOMPARE(session.initiator(), QString()); - QCOMPARE(session.sid(), QLatin1String("a73sjjvkla37jfea")); - QCOMPARE(session.reason().text(), QString()); - QCOMPARE(session.reason().type(), QXmppJingleIq::Reason::Success); - serializePacket(session, xml); -} - -void TestJingle::testPayloadType() -{ - const QByteArray xml("<payload-type id=\"103\" name=\"L16\" channels=\"2\" clockrate=\"16000\"/>"); - QXmppJinglePayloadType payload; - parsePacket(payload, xml); - QCOMPARE(payload.id(), static_cast<unsigned char>(103)); - QCOMPARE(payload.name(), QLatin1String("L16")); - QCOMPARE(payload.channels(), static_cast<unsigned char>(2)); - QCOMPARE(payload.clockrate(), 16000u); - serializePacket(payload, xml); -} - -void TestJingle::testRinging() -{ - const QByteArray xml( - "<iq" - " id=\"tgr515bt\"" - " to=\"romeo@montague.lit/orchard\"" - " from=\"juliet@capulet.lit/balcony\"" - " type=\"set\">" - "<jingle xmlns=\"urn:xmpp:jingle:1\"" - " action=\"session-info\"" - " initiator=\"romeo@montague.lit/orchard\"" - " sid=\"a73sjjvkla37jfea\">" - "<ringing xmlns=\"urn:xmpp:jingle:apps:rtp:info:1\"/>" - "</jingle>" - "</iq>"); - - QXmppJingleIq iq; - parsePacket(iq, xml); - QCOMPARE(iq.ringing(), true); - serializePacket(iq, xml); -} - -static void checkVariant(const QVariant &value, const QByteArray &xml) -{ - // serialise - QBuffer buffer; - buffer.open(QIODevice::ReadWrite); - QXmlStreamWriter writer(&buffer); - XMLRPC::marshall(&writer, value); - qDebug() << "expect " << xml; - qDebug() << "writing" << buffer.data(); - QCOMPARE(buffer.data(), xml); - - // parse - QDomDocument doc; - QCOMPARE(doc.setContent(xml, true), true); - QDomElement element = doc.documentElement(); - QStringList errors; - QVariant test = XMLRPC::demarshall(element, errors); - if (!errors.isEmpty()) - qDebug() << errors; - QCOMPARE(errors, QStringList()); - QCOMPARE(test, value); -} - -void TestXmlRpc::testBase64() -{ - checkVariant(QByteArray("\0\1\2\3", 4), - QByteArray("<value><base64>AAECAw==</base64></value>")); -} - -void TestXmlRpc::testBool() -{ - checkVariant(false, - QByteArray("<value><boolean>0</boolean></value>")); - checkVariant(true, - QByteArray("<value><boolean>1</boolean></value>")); -} - -void TestXmlRpc::testDateTime() -{ - checkVariant(QDateTime(QDate(1998, 7, 17), QTime(14, 8, 55)), - QByteArray("<value><dateTime.iso8601>1998-07-17T14:08:55</dateTime.iso8601></value>")); -} - -void TestXmlRpc::testDouble() -{ - checkVariant(double(-12.214), - QByteArray("<value><double>-12.214</double></value>")); -} - -void TestXmlRpc::testInt() -{ - checkVariant(int(-12), - QByteArray("<value><i4>-12</i4></value>")); -} - -void TestXmlRpc::testNil() -{ - checkVariant(QVariant(), - QByteArray("<value><nil/></value>")); -} - -void TestXmlRpc::testString() -{ - checkVariant(QString("hello world"), - QByteArray("<value><string>hello world</string></value>")); -} - -void TestXmlRpc::testArray() -{ - checkVariant(QVariantList() << QString("hello world") << double(-12.214), - QByteArray("<value><array><data>" - "<value><string>hello world</string></value>" - "<value><double>-12.214</double></value>" - "</data></array></value>")); -} - -void TestXmlRpc::testStruct() -{ - QMap<QString, QVariant> map; - map["bar"] = QString("hello world"); - map["foo"] = double(-12.214); - checkVariant(map, - QByteArray("<value><struct>" - "<member>" - "<name>bar</name>" - "<value><string>hello world</string></value>" - "</member>" - "<member>" - "<name>foo</name>" - "<value><double>-12.214</double></value>" - "</member>" - "</struct></value>")); -} - -void TestXmlRpc::testInvoke() -{ - const QByteArray xml( - "<iq" - " id=\"rpc1\"" - " to=\"responder@company-a.com/jrpc-server\"" - " from=\"requester@company-b.com/jrpc-client\"" - " type=\"set\">" - "<query xmlns=\"jabber:iq:rpc\">" - "<methodCall>" - "<methodName>examples.getStateName</methodName>" - "<params>" - "<param>" - "<value><i4>6</i4></value>" - "</param>" - "</params>" - "</methodCall>" - "</query>" - "</iq>"); - - QXmppRpcInvokeIq iq; - parsePacket(iq, xml); - QCOMPARE(iq.method(), QLatin1String("examples.getStateName")); - QCOMPARE(iq.arguments(), QVariantList() << int(6)); - serializePacket(iq, xml); -} - -void TestXmlRpc::testResponse() -{ - const QByteArray xml( - "<iq" - " id=\"rpc1\"" - " to=\"requester@company-b.com/jrpc-client\"" - " from=\"responder@company-a.com/jrpc-server\"" - " type=\"result\">" - "<query xmlns=\"jabber:iq:rpc\">" - "<methodResponse>" - "<params>" - "<param>" - "<value><string>Colorado</string></value>" - "</param>" - "</params>" - "</methodResponse>" - "</query>" - "</iq>"); - - QXmppRpcResponseIq iq; - parsePacket(iq, xml); - QCOMPARE(iq.faultCode(), 0); - QCOMPARE(iq.faultString(), QString()); - QCOMPARE(iq.values(), QVariantList() << QString("Colorado")); - serializePacket(iq, xml); -} - -void TestXmlRpc::testResponseFault() -{ - const QByteArray xml( - "<iq" - " id=\"rpc1\"" - " to=\"requester@company-b.com/jrpc-client\"" - " from=\"responder@company-a.com/jrpc-server\"" - " type=\"result\">" - "<query xmlns=\"jabber:iq:rpc\">" - "<methodResponse>" - "<fault>" - "<value>" - "<struct>" - "<member>" - "<name>faultCode</name>" - "<value><i4>404</i4></value>" - "</member>" - "<member>" - "<name>faultString</name>" - "<value><string>Not found</string></value>" - "</member>" - "</struct>" - "</value>" - "</fault>" - "</methodResponse>" - "</query>" - "</iq>"); - - QXmppRpcResponseIq iq; - parsePacket(iq, xml); - QCOMPARE(iq.faultCode(), 404); - QCOMPARE(iq.faultString(), QLatin1String("Not found")); - QCOMPARE(iq.values(), QVariantList()); - serializePacket(iq, xml); -} - -int main(int argc, char *argv[]) -{ - QCoreApplication app(argc, argv); - - // run tests - int errors = 0; - - TestUtils testUtils; - errors += QTest::qExec(&testUtils); - - TestPackets testPackets; - errors += QTest::qExec(&testPackets); - - TestJingle testJingle; - errors += QTest::qExec(&testJingle); - - TestXmlRpc testXmlRpc; - errors += QTest::qExec(&testXmlRpc); - - if (errors) - { - qWarning() << "Total failed tests:" << errors; - return EXIT_FAILURE; - } - return EXIT_SUCCESS; -}; - diff --git a/example/tests/tests.h b/example/tests/tests.h deleted file mode 100644 index 33536883..00000000 --- a/example/tests/tests.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2008-2010 The QXmpp developers - * - * Author: - * Jeremy Lainé - * - * Source: - * http://code.google.com/p/qxmpp - * - * This file is a part of QXmpp library. - * - * 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. - * - */ - -#include <QObject> - -class TestUtils : public QObject -{ - Q_OBJECT - -private slots: - void testHmac(); -}; - -class TestPackets : public QObject -{ - Q_OBJECT - -private slots: - void testBindNoResource(); - void testBindResource(); - void testBindResult(); - void testMessage(); - void testMessageFull(); - void testMessageDelay(); - void testMessageLegacyDelay(); - void testPresence(); - void testPresenceFull(); - void testSession(); -}; - -class TestJingle : public QObject -{ - Q_OBJECT - -private slots: - void testSession(); - void testTerminate(); - void testPayloadType(); - void testRinging(); -}; - -class TestXmlRpc : public QObject -{ - Q_OBJECT - -private slots: - void testBase64(); - void testBool(); - void testDateTime(); - void testDouble(); - void testInt(); - void testNil(); - void testString(); - - void testArray(); - void testStruct(); - - void testInvoke(); - void testResponse(); - void testResponseFault(); -}; diff --git a/example/tests/tests.pro b/example/tests/tests.pro deleted file mode 100644 index b51cda23..00000000 --- a/example/tests/tests.pro +++ /dev/null @@ -1,9 +0,0 @@ -include(../example.pri) - -QT += testlib - -TARGET = tests - -SOURCES += tests.cpp - -HEADERS += tests.h |
