00001 /* 00002 * Copyright (C) 2008-2011 The QXmpp developers 00003 * 00004 * Author: 00005 * Jeremy Lainé 00006 * 00007 * Source: 00008 * http://code.google.com/p/qxmpp 00009 * 00010 * This file is a part of QXmpp library. 00011 * 00012 * This library is free software; you can redistribute it and/or 00013 * modify it under the terms of the GNU Lesser General Public 00014 * License as published by the Free Software Foundation; either 00015 * version 2.1 of the License, or (at your option) any later version. 00016 * 00017 * This library is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00020 * Lesser General Public License for more details. 00021 * 00022 */ 00023 00024 #ifndef QXMPPSERVER_H 00025 #define QXMPPSERVER_H 00026 00027 #include <QTcpServer> 00028 00029 #include "QXmppLogger.h" 00030 00031 class QDomElement; 00032 class QSslSocket; 00033 00034 class QXmppDialback; 00035 class QXmppIncomingClient; 00036 class QXmppOutgoingServer; 00037 class QXmppPasswordChecker; 00038 class QXmppPresence; 00039 class QXmppServerExtension; 00040 class QXmppServerPrivate; 00041 class QXmppSslServer; 00042 class QXmppStanza; 00043 class QXmppStream; 00044 00055 00056 class QXmppServer : public QXmppLoggable 00057 { 00058 Q_OBJECT 00059 00060 public: 00061 QXmppServer(QObject *parent = 0); 00062 ~QXmppServer(); 00063 00064 void addExtension(QXmppServerExtension *extension); 00065 QList<QXmppServerExtension*> extensions(); 00066 00067 QString domain() const; 00068 void setDomain(const QString &domain); 00069 00070 QXmppLogger *logger(); 00071 void setLogger(QXmppLogger *logger); 00072 00073 QXmppPasswordChecker *passwordChecker(); 00074 void setPasswordChecker(QXmppPasswordChecker *checker); 00075 00076 void addCaCertificates(const QString &caCertificates); 00077 void setLocalCertificate(const QString &sslCertificate); 00078 void setPrivateKey(const QString &sslKey); 00079 00080 void close(); 00081 bool listenForClients(const QHostAddress &address = QHostAddress::Any, quint16 port = 5222); 00082 bool listenForServers(const QHostAddress &address = QHostAddress::Any, quint16 port = 5269); 00083 00084 bool sendElement(const QDomElement &element); 00085 bool sendPacket(const QXmppStanza &stanza); 00086 00087 void addIncomingClient(QXmppIncomingClient *stream); 00088 QList<QXmppPresence> availablePresences(const QString &bareJid); 00089 00090 signals: 00092 void streamAdded(QXmppStream *stream); 00093 00095 void streamConnected(QXmppStream *stream); 00096 00098 void streamRemoved(QXmppStream *stream); 00099 00100 private slots: 00101 void slotClientConnection(QSslSocket *socket); 00102 void slotDialbackRequestReceived(const QXmppDialback &dialback); 00103 void slotElementReceived(const QDomElement &element); 00104 void slotServerConnection(QSslSocket *socket); 00105 void slotStreamConnected(); 00106 void slotStreamDisconnected(); 00107 00108 private: 00109 QXmppOutgoingServer *connectToDomain(const QString &domain); 00110 QList<QXmppStream*> getStreams(const QString &to); 00111 virtual void handleStanza(QXmppStream *stream, const QDomElement &element); 00112 QXmppServerPrivate * const d; 00113 }; 00114 00115 class QXmppSslServerPrivate; 00116 00119 00120 class QXmppSslServer : public QTcpServer 00121 { 00122 Q_OBJECT 00123 00124 public: 00125 QXmppSslServer(QObject *parent = 0); 00126 ~QXmppSslServer(); 00127 00128 void addCaCertificates(const QString &caCertificates); 00129 void setLocalCertificate(const QString &localCertificate); 00130 void setPrivateKey(const QString &privateKey); 00131 00132 signals: 00134 void newConnection(QSslSocket *socket); 00135 00136 private: 00137 void incomingConnection(int socketDescriptor); 00138 QXmppSslServerPrivate * const d; 00139 }; 00140 00141 #endif