initial commit

This commit is contained in:
mikhail "synzr" 2025-12-25 01:37:49 +05:00
commit 9d20827c46
2469 changed files with 470994 additions and 0 deletions

View file

@ -0,0 +1,609 @@
#!/bin/sh
show_usage() {
cat <<EOT
Usage: ./configure [OPTION]...
This script creates necessary configuration files to build/install.
Main options:
--prefix=[path] Base path for build/install. Default: /usr/local
--bindir=[path] Directory for binaries. Default: PREFIX/bin
--qtdir=[path] Directory where Qt is installed.
--debug Enable debug output.
--help This help text.
EOT
}
while [ $# -gt 0 ]; do
case "$1" in
--prefix=*)
PREFIX="${1#--prefix=}"
shift
;;
--bindir=*)
BINDIR="${1#--bindir=}"
shift
;;
--qtdir=*)
QTDIR="${1#--qtdir=}"
shift
;;
--debug)
QC_DEBUG="Y"
shift
;;
--help) show_usage; exit ;;
*) show_usage; exit ;;
esac
done
PREFIX=${PREFIX:-/usr/local}
BINDIR=${BINDIR:-$PREFIX/bin}
echo "Configuring Iris Conntest ..."
if [ "$QC_DEBUG" = "Y" ]; then
echo
echo PREFIX=$PREFIX
echo BINDIR=$BINDIR
echo QTDIR=$QTDIR
echo
fi
printf "Verifying Qt 3.x Multithreaded (MT) build environment ... "
if [ -z "$QTDIR" ]; then
if [ "$QC_DEBUG" = "Y" ]; then
echo \$QTDIR not set... trying to find Qt manually
fi
for p in /usr/lib/qt /usr/share/qt /usr/share/qt3 /usr/local/lib/qt /usr/local/share/qt /usr/lib/qt3 /usr/local/lib/qt3 /usr/X11R6/share/qt /usr/qt/3 ; do
if [ -d "$p/mkspecs" ]; then
QTDIR=$p
break;
fi;
done
if [ -z "$QTDIR" ]; then
echo fail
echo
echo "Unable to find Qt 'mkspecs'. Perhaps you need to"
echo "install the Qt 3 development utilities. You may download"
echo "them either from the vendor of your operating system"
echo "or from http://www.trolltech.com/"
echo
echo "If you're sure you have the Qt development utilities"
echo "installed, you might try using the --qtdir option."
echo
exit 1;
fi
if [ ! -x "$QTDIR/bin/moc" ]; then
m=`which moc 2>/dev/null`
if [ ! -x "$m" ]; then
echo fail
echo
echo "We found Qt in $QTDIR, but we were unable to locate"
echo "the moc utility. It was not found in $QTDIR/bin"
echo "nor in PATH. This seems to be a very unusual setup."
echo "You might try using the --qtdir option."
echo
exit 1;
fi
qtpre=`echo $m | awk '{ n = index($0, "/bin/moc"); if (!n) { exit 1; } print substr($0, 0, n-1); exit 0; }' 2>/dev/null`
ret="$?"
if [ "$ret" != "0" ]; then
echo fail
echo
echo "We found Qt in $QTDIR, but the location of moc"
echo "($m) is not suitable for use with this build system."
echo "This is a VERY unusual and likely-broken setup. You"
echo "should contact the maintainer of your Qt package."
echo
exit 1;
fi
QTDIR=$qtpre
fi
fi
if [ ! -x "$QTDIR/bin/qmake" ]; then
if [ "$QC_DEBUG" = "Y" ]; then
echo Warning: qmake not in \$QTDIR/bin/qmake
echo trying to find it in \$PATH
fi
qm=`which qmake 2>/dev/null`
if [ -x "$qm" ]; then
if [ "$QC_DEBUG" = "Y" ]; then
echo qmake found in $qm
fi
else
echo fail
echo
echo Sorry, you seem to have a very unusual setup,
echo or I missdetected \$QTDIR=$QTDIR
echo
echo Please set \$QTDIR manually and make sure that
echo \$QTDIR/bin/qmake exists.
echo
exit 1;
fi
else
qm=$QTDIR/bin/qmake
fi
gen_files() {
cat >$1/modules.cpp <<EOT
EOT
cat >$1/modules_new.cpp <<EOT
EOT
cat >$1/conf.cpp <<EOT
#include<stdio.h>
#include<stdlib.h>
#include<qstring.h>
#include<qdict.h>
#include<qptrlist.h>
#include<qfileinfo.h>
#include<qfile.h>
#include<qdir.h>
#include<qstringlist.h>
#include<qobject.h>
class MocTestObject : public QObject
{
Q_OBJECT
public:
MocTestObject() {}
};
class Conf;
class ConfObj
{
public:
ConfObj(Conf *c);
virtual ~ConfObj();
virtual QString name() const=0;
virtual QString shortname() const=0;
virtual QString checkString() const;
virtual QString resultString() const;
virtual bool exec()=0;
Conf *conf;
bool required;
bool disabled;
};
typedef QPtrList<ConfObj> ConfObjList;
typedef QPtrListIterator<ConfObj> ConfObjListIt;
class Conf
{
public:
Conf() : vars(17)
{
list.setAutoDelete(true);
vars.setAutoDelete(true);
vars.insert("QMAKE_INCDIR_X11", new QString(X11_INC));
vars.insert("QMAKE_LIBDIR_X11", new QString(X11_LIBDIR));
vars.insert("QMAKE_LIBS_X11", new QString(X11_LIB));
vars.insert("QMAKE_CC", new QString(CC));
do_debug = false;
done_debug = false;
}
~Conf()
{
}
void added(ConfObj *o)
{
list.append(o);
}
QString getenv(const QString &var)
{
char *p = ::getenv(var.latin1());
if(!p)
return QString::null;
return QString(p);
}
void debug(const QString &s)
{
if(do_debug) {
if(!done_debug)
printf("\n");
done_debug = true;
printf(" * %s\n", s.latin1());
}
}
bool exec()
{
if(getenv("QC_DEBUG") == "Y")
do_debug = true;
ConfObjListIt it(list);
for(ConfObj *o; (o = it.current()); ++it) {
// if this was a disabled-by-default option, check if it was enabled
if(o->disabled) {
QString v = QString("QC_ENABLE_") + o->shortname();
if(getenv(v) != "Y")
continue;
}
// and the opposite?
else {
QString v = QString("QC_DISABLE_") + o->shortname();
if(getenv(v) == "Y")
continue;
}
QString check = o->checkString();
if(check.isEmpty())
check = QString("Checking for %1 ...").arg(o->name());
printf("%s", check.latin1());
fflush(stdout);
done_debug = false;
bool ok = o->exec();
QString result = o->resultString();
if(result.isEmpty()) {
if(ok)
result = "yes";
else
result = "no";
}
if(done_debug)
printf(" -> %s\n", result.latin1());
else
printf(" %s\n", result.latin1());
if(!ok && o->required) {
printf("\nError: need %s!\n", o->name().latin1());
return false;
}
}
return true;
}
const QString & qvar(const QString &s)
{
QString *p = vars.find(s);
if(p)
return *p;
else
return blank;
}
QString expandIncludes(const QString &inc)
{
return QString("-I") + inc;
}
QString expandLibs(const QString &lib)
{
return QString("-L") + lib;
}
int doCommand(const QString &s)
{
debug(QString("[%1]").arg(s));
QString fullcmd;
if(do_debug)
fullcmd = s;
else
fullcmd = s + " 1>/dev/null 2>/dev/null";
int r = system(fullcmd.latin1());
debug(QString("returned: %1").arg(r));
return r;
}
bool doCompileAndLink(const QString &filedata, const QString &flags, int *retcode=0)
{
QDir dir(".");
QString fname = "atest.c";
QString out = "atest";
QFile f(fname);
QCString cs = filedata.latin1();
if(!f.open(IO_WriteOnly | IO_Truncate)) {
debug("unable to open atest.c for writing");
return false;
}
if(f.writeBlock(cs.data(), cs.length()) == -1) {
debug("error writing to atest.c");
return false;
}
f.close();
debug(QString("Wrote atest.c:\n%1").arg(filedata));
QString str = qvar("QMAKE_CC") + ' ' + fname + " -o " + out;
if(!flags.isEmpty()) {
str += ' ';
str += flags;
}
int r = doCommand(str);
if(r == 0 && retcode)
*retcode = doCommand(QString("./") + out);
dir.remove(fname);
dir.remove(out);
if(r != 0)
return false;
return true;
}
bool checkHeader(const QString &path, const QString &h)
{
QFileInfo fi(path + '/' + h);
if(fi.exists())
return true;
return false;
}
bool findHeader(const QString &h, const QStringList &ext, QString *inc)
{
if(checkHeader("/usr/include", h)) {
*inc = "";
return true;
}
QStringList dirs;
dirs += "/usr/local/include";
dirs += ext;
for(QStringList::ConstIterator it = dirs.begin(); it != dirs.end(); ++it) {
if(checkHeader(*it, h)) {
*inc = *it;
return true;
}
}
return false;
}
bool checkLibrary(const QString &path, const QString &name)
{
QString str =
"int main()\n"
"{\n"
" return 0;\n"
"}\n";
QString extra;
if(!path.isEmpty())
extra += QString("-L") + path + ' ';
extra += QString("-l") + name;
if(!doCompileAndLink(str, extra))
return false;
return true;
}
bool findLibrary(const QString &name, QString *lib)
{
if(checkLibrary("", name)) {
*lib = "";
return true;
}
if(checkLibrary("/usr/local/lib", name)) {
*lib = "/usr/local/lib";
return true;
}
return false;
}
void addDefine(const QString &str)
{
if(DEFINES.isEmpty())
DEFINES = str;
else
DEFINES += QString(" ") + str;
debug(QString("DEFINES += %1").arg(str));
}
void addLib(const QString &str)
{
if(LIBS.isEmpty())
LIBS = str;
else
LIBS += QString(" ") + str;
debug(QString("LIBS += %1").arg(str));
}
void addIncludePath(const QString &str)
{
if(INCLUDEPATH.isEmpty())
INCLUDEPATH = str;
else
INCLUDEPATH += QString(" ") + str;
debug(QString("INCLUDEPATH += %1").arg(str));
}
void addExtra(const QString &str)
{
extra += str + '\n';
debug(QString("extra += %1").arg(str));
}
QString DEFINES;
QString INCLUDEPATH;
QString LIBS;
QString extra;
private:
ConfObjList list;
QDict<QString> vars;
QString blank;
bool do_debug, done_debug;
};
ConfObj::ConfObj(Conf *c)
{
conf = c;
conf->added(this);
required = false;
disabled = false;
}
ConfObj::~ConfObj()
{
}
QString ConfObj::checkString() const
{
return QString();
}
QString ConfObj::resultString() const
{
return QString();
}
#include"modules.cpp"
//----------------------------------------------------------------------------
// main
//----------------------------------------------------------------------------
int main()
{
Conf *conf = new Conf;
ConfObj *o;
o = 0;
#include"modules_new.cpp"
printf("ok\n");
bool success = false;
if(conf->exec()) {
QFile f("conf.pri");
if(!f.open(IO_WriteOnly | IO_Truncate)) {
printf("Error writing %s\n", f.name().latin1());
return 1;
}
QString str;
str += "# qconf\n";
str += "QT_PATH_PLUGINS = " + QString(qInstallPathPlugins()) + '\n';
if(!conf->DEFINES.isEmpty())
str += "DEFINES += " + conf->DEFINES + '\n';
if(!conf->INCLUDEPATH.isEmpty())
str += "INCLUDEPATH += " + conf->INCLUDEPATH + '\n';
if(!conf->LIBS.isEmpty())
str += "LIBS += " + conf->LIBS + '\n';
if(!conf->extra.isEmpty())
str += conf->extra;
str += '\n';
char *p = getenv("BINDIR");
if(p) {
str += QString("target.path = ") + p + '\n';
str += "INSTALLS += target\n";
}
QCString cs = str.latin1();
f.writeBlock(cs.data(), cs.length());
f.close();
success = true;
}
delete conf;
if(success)
return 0;
else
return 1;
}
#include"conf.moc"
EOT
cat >$1/conf.pro <<EOT
TEMPLATE = app
CONFIG += qt x11 thread console
TARGET = conf
DEFINES += X11_INC='"\$\$QMAKE_INCDIR_X11"'
DEFINES += X11_LIBDIR='"\$\$QMAKE_LIBDIR_X11"'
DEFINES += X11_LIB='"\$\$QMAKE_LIBS_X11"'
DEFINES += CC='"\$\$QMAKE_CC"'
SOURCES += conf.cpp
EOT
}
export PREFIX
export BINDIR
export QTDIR
export QC_DEBUG
rm -rf .qconftemp
(
mkdir .qconftemp
gen_files .qconftemp
cd .qconftemp
$qm conf.pro >/dev/null
QTDIR=$QTDIR make clean >/dev/null 2>&1
QTDIR=$QTDIR make >../conf.log 2>&1
)
if [ "$?" != "0" ]; then
rm -rf .qconftemp
echo fail
echo
echo "There was an error compiling 'conf'. Be sure you have a proper"
echo "Qt 3.x Multithreaded (MT) build environment set up. This"
echo "means not just Qt, but also a C++ compiler, the 'make' command,"
echo "and any other packages necessary to compile C++ programs."
echo "See conf.log for details."
if [ ! -f "$QTDIR/lib/libqt-mt.so.3" ]; then
echo
echo "One possible reason is that you don't have"
echo "libqt-mt.so.3 installed in $QTDIR/lib/."
fi
echo
exit 1;
fi
.qconftemp/conf
ret="$?"
if [ "$ret" = "1" ]; then
rm -rf .qconftemp
echo
exit 1;
else
if [ "$ret" != "0" ]; then
rm -rf .qconftemp
echo fail
echo
echo Unexpected error launching 'conf'
echo
exit 1;
fi
fi
rm -rf .qconftemp
if [ -x "./qcextra" ]; then
./qcextra
fi
# run qmake
$qm conntest.pro
if [ "$?" != "0" ]; then
echo
exit 1;
fi
cat >Makefile.tmp <<EOT
export QTDIR = $QTDIR
export PATH = $QTDIR/bin:$PATH
EOT
cat Makefile >> Makefile.tmp
rm -f Makefile
cp -f Makefile.tmp Makefile
rm -f Makefile.tmp
echo
echo Good, your configure finished. Now run \'make\'.
echo

View file

@ -0,0 +1,578 @@
#include <qapplication.h>
#include "bconsole.h"
#include <QtCrypto>
#include "xmpp.h"
#include <stdio.h>
#define ROOTCERT_PATH "/usr/local/share/psi/certs/rootcert.xml"
QCA::Cert readCertXml(const QDomElement &e)
{
QCA::Cert cert;
// there should be one child data tag
QDomElement data = e.elementsByTagName("data").item(0).toElement();
if(!data.isNull())
cert.fromDER(Base64::stringToArray(data.text()));
return cert;
}
QPtrList<QCA::Cert> getRootCerts(const QString &store)
{
QPtrList<QCA::Cert> list;
// open the Psi rootcerts file
QFile f(store);
if(!f.open(IO_ReadOnly)) {
printf("unable to open %s\n", f.name().latin1());
return list;
}
QDomDocument doc;
doc.setContent(&f);
f.close();
QDomElement base = doc.documentElement();
if(base.tagName() != "store") {
printf("wrong format of %s\n", f.name().latin1());
return list;
}
QDomNodeList cl = base.elementsByTagName("certificate");
if(cl.count() == 0) {
printf("no certs found in %s\n", f.name().latin1());
return list;
}
int num = 0;
for(int n = 0; n < (int)cl.count(); ++n) {
QCA::Cert *cert = new QCA::Cert(readCertXml(cl.item(n).toElement()));
if(cert->isNull()) {
printf("error reading cert\n");
delete cert;
continue;
}
++num;
list.append(cert);
}
printf("imported %d root certs\n", num);
return list;
}
static QString prompt(const QString &s)
{
printf("* %s ", s.latin1());
fflush(stdout);
char line[256];
fgets(line, 255, stdin);
QString result = line;
if(result[result.length()-1] == '\n')
result.truncate(result.length()-1);
return result;
}
static void showCertInfo(const QCA::Cert &cert)
{
fprintf(stderr, "-- Cert --\n");
fprintf(stderr, " CN: %s\n", cert.subject()["CN"].latin1());
fprintf(stderr, " Valid from: %s, until %s\n",
cert.notBefore().toString().latin1(),
cert.notAfter().toString().latin1());
fprintf(stderr, " PEM:\n%s\n", cert.toPEM().latin1());
}
static QString resultToString(int result)
{
QString s;
switch(result) {
case QCA::TLS::NoCert:
s = QObject::tr("No certificate presented.");
break;
case QCA::TLS::Valid:
break;
case QCA::TLS::HostMismatch:
s = QObject::tr("Hostname mismatch.");
break;
case QCA::TLS::Rejected:
s = QObject::tr("Root CA rejects the specified purpose.");
break;
case QCA::TLS::Untrusted:
s = QObject::tr("Not trusted for the specified purpose.");
break;
case QCA::TLS::SignatureFailed:
s = QObject::tr("Invalid signature.");
break;
case QCA::TLS::InvalidCA:
s = QObject::tr("Invalid CA certificate.");
break;
case QCA::TLS::InvalidPurpose:
s = QObject::tr("Invalid certificate purpose.");
break;
case QCA::TLS::SelfSigned:
s = QObject::tr("Certificate is self-signed.");
break;
case QCA::TLS::Revoked:
s = QObject::tr("Certificate has been revoked.");
break;
case QCA::TLS::PathLengthExceeded:
s = QObject::tr("Maximum cert chain length exceeded.");
break;
case QCA::TLS::Expired:
s = QObject::tr("Certificate has expired.");
break;
case QCA::TLS::Unknown:
default:
s = QObject::tr("General validation error.");
break;
}
return s;
}
class App : public QObject
{
Q_OBJECT
public:
XMPP::AdvancedConnector *conn;
QCA::TLS *tls;
XMPP::QCATLSHandler *tlsHandler;
XMPP::ClientStream *stream;
BConsole *c;
XMPP::Jid jid;
QPtrList<QCA::Cert> rootCerts;
App(const XMPP::Jid &_jid, const XMPP::AdvancedConnector::Proxy &proxy, const QString &host, int port, bool opt_ssl, bool opt_probe)
:QObject(0)
{
c = 0;
jid = _jid;
// Connector
conn = new XMPP::AdvancedConnector;
conn->setProxy(proxy);
if(!host.isEmpty())
conn->setOptHostPort(host, port);
conn->setOptProbe(opt_probe);
conn->setOptSSL(opt_ssl);
// TLSHandler
tls = 0;
tlsHandler = 0;
rootCerts.setAutoDelete(true);
if(QCA::isSupported(QCA::CAP_TLS)) {
rootCerts = getRootCerts(ROOTCERT_PATH);
tls = new QCA::TLS;
tls->setCertificateStore(rootCerts);
tlsHandler = new XMPP::QCATLSHandler(tls);
connect(tlsHandler, SIGNAL(tlsHandshaken()), SLOT(tls_handshaken()));
}
// Stream
stream = new XMPP::ClientStream(conn, tlsHandler);
connect(stream, SIGNAL(connected()), SLOT(cs_connected()));
connect(stream, SIGNAL(securityLayerActivated(int)), SLOT(cs_securityLayerActivated()));
connect(stream, SIGNAL(needAuthParams(bool, bool, bool)), SLOT(cs_needAuthParams(bool, bool, bool)));
connect(stream, SIGNAL(authenticated()), SLOT(cs_authenticated()));
connect(stream, SIGNAL(connectionClosed()), SLOT(cs_connectionClosed()));
connect(stream, SIGNAL(readyRead()), SLOT(cs_readyRead()));
connect(stream, SIGNAL(stanzaWritten()), SLOT(cs_stanzaWritten()));
connect(stream, SIGNAL(warning(int)), SLOT(cs_warning(int)));
connect(stream, SIGNAL(error(int)), SLOT(cs_error(int)));
fprintf(stderr, "conntest: Connecting ...\n");
stream->setSSFRange(0, 256);
stream->connectToServer(jid);
}
~App()
{
delete stream;
delete tls; // this destroys the TLSHandler also
delete conn;
delete c;
}
signals:
void quit();
private slots:
void tls_handshaken()
{
QCA::Cert cert = tls->peerCertificate();
int vr = tls->certificateValidityResult();
fprintf(stderr, "conntest: Successful TLS handshake.\n");
if(!cert.isNull())
showCertInfo(cert);
if(vr == QCA::TLS::Valid)
fprintf(stderr, "conntest: Valid certificate.\n");
else
fprintf(stderr, "conntest: Invalid certificate: %s\n", resultToString(vr).latin1());
tlsHandler->continueAfterHandshake();
}
void cs_connected()
{
fprintf(stderr, "conntest: Connected\n");
}
void cs_securityLayerActivated()
{
fprintf(stderr, "conntest: Security layer activated (%s)\n", tls->isHandshaken() ? "TLS": "SASL");
}
void cs_needAuthParams(bool user, bool pass, bool realm)
{
fprintf(stderr, "conntest: need auth params -");
if(user)
fprintf(stderr, " (user)");
if(pass)
fprintf(stderr, " (pass)");
if(realm)
fprintf(stderr, " (realm)");
fprintf(stderr, "\n");
if(user)
stream->setUsername(jid.node());
if(pass)
stream->setPassword(prompt("Password (not hidden!) :"));
stream->continueAfterParams();
}
void cs_authenticated()
{
fprintf(stderr, "conntest: <<< Authenticated >>>\n");
// console
c = new BConsole;
connect(c, SIGNAL(connectionClosed()), SLOT(con_connectionClosed()));
connect(c, SIGNAL(readyRead()), SLOT(con_readyRead()));
}
void cs_connectionClosed()
{
fprintf(stderr, "conntest: Disconnected by peer\n");
quit();
}
void cs_readyRead()
{
for(XMPP::Stanza s; !(s = stream->read()).isNull();) {
QString str = s.toString();
printf("%s\n", str.local8Bit().data());
}
}
void cs_stanzaWritten()
{
fprintf(stderr, "conntest: Stanza written\n");
}
void cs_warning(int warn)
{
if(warn == XMPP::ClientStream::WarnOldVersion) {
fprintf(stderr, "conntest: Warning: pre-1.0 protocol server\n");
}
else if(warn == XMPP::ClientStream::WarnNoTLS) {
fprintf(stderr, "conntest: Warning: TLS not available!\n");
}
stream->continueAfterWarning();
}
void cs_error(int err)
{
if(err == XMPP::ClientStream::ErrParse) {
fprintf(stderr, "conntest: XML parsing error\n");
}
else if(err == XMPP::ClientStream::ErrProtocol) {
fprintf(stderr, "conntest: XMPP protocol error\n");
}
else if(err == XMPP::ClientStream::ErrStream) {
int x = stream->errorCondition();
QString s;
if(x == XMPP::Stream::GenericStreamError)
s = "generic stream error";
else if(x == XMPP::ClientStream::Conflict)
s = "conflict (remote login replacing this one)";
else if(x == XMPP::ClientStream::ConnectionTimeout)
s = "timed out from inactivity";
else if(x == XMPP::ClientStream::InternalServerError)
s = "internal server error";
else if(x == XMPP::ClientStream::InvalidXml)
s = "invalid XML";
else if(x == XMPP::ClientStream::PolicyViolation)
s = "policy violation. go to jail!";
else if(x == XMPP::ClientStream::ResourceConstraint)
s = "server out of resources";
else if(x == XMPP::ClientStream::SystemShutdown)
s = "system is shutting down NOW";
fprintf(stderr, "conntest: XMPP stream error: %s\n", s.latin1());
}
else if(err == XMPP::ClientStream::ErrConnection) {
int x = conn->errorCode();
QString s;
if(x == XMPP::AdvancedConnector::ErrConnectionRefused)
s = "unable to connect to server";
else if(x == XMPP::AdvancedConnector::ErrHostNotFound)
s = "host not found";
else if(x == XMPP::AdvancedConnector::ErrProxyConnect)
s = "proxy connect";
else if(x == XMPP::AdvancedConnector::ErrProxyNeg)
s = "proxy negotiating";
else if(x == XMPP::AdvancedConnector::ErrProxyAuth)
s = "proxy authorization";
else if(x == XMPP::AdvancedConnector::ErrStream)
s = "stream error";
fprintf(stderr, "conntest: connection error: %s\n", s.latin1());
}
else if(err == XMPP::ClientStream::ErrNeg) {
int x = stream->errorCondition();
QString s;
if(x == XMPP::ClientStream::HostGone)
s = "host no longer hosted";
else if(x == XMPP::ClientStream::HostUnknown)
s = "host unknown";
else if(x == XMPP::ClientStream::RemoteConnectionFailed)
s = "a required remote connection failed";
else if(x == XMPP::ClientStream::SeeOtherHost)
s = QString("see other host: [%1]").arg(stream->errorText());
else if(x == XMPP::ClientStream::UnsupportedVersion)
s = "server does not support proper xmpp version";
fprintf(stderr, "conntest: stream negotiation error: %s\n", s.latin1());
}
else if(err == XMPP::ClientStream::ErrTLS) {
int x = stream->errorCondition();
QString s;
if(x == XMPP::ClientStream::TLSStart)
s = "server rejected STARTTLS";
else if(x == XMPP::ClientStream::TLSFail) {
int t = tlsHandler->tlsError();
if(t == QCA::TLS::ErrHandshake)
s = "TLS handshake error";
else
s = "broken security layer (TLS)";
}
fprintf(stderr, "conntest: %s\n", s.latin1());
}
else if(err == XMPP::ClientStream::ErrAuth) {
int x = stream->errorCondition();
QString s;
if(x == XMPP::ClientStream::GenericAuthError)
s = "unable to login";
else if(x == XMPP::ClientStream::NoMech)
s = "no appropriate auth mechanism available for given security settings";
else if(x == XMPP::ClientStream::BadProto)
s = "bad server response";
else if(x == XMPP::ClientStream::BadServ)
s = "server failed mutual authentication";
else if(x == XMPP::ClientStream::EncryptionRequired)
s = "encryption required for chosen SASL mechanism";
else if(x == XMPP::ClientStream::InvalidAuthzid)
s = "invalid authzid";
else if(x == XMPP::ClientStream::InvalidMech)
s = "invalid SASL mechanism";
else if(x == XMPP::ClientStream::InvalidRealm)
s = "invalid realm";
else if(x == XMPP::ClientStream::MechTooWeak)
s = "SASL mechanism too weak for authzid";
else if(x == XMPP::ClientStream::NotAuthorized)
s = "not authorized";
else if(x == XMPP::ClientStream::TemporaryAuthFailure)
s = "temporary auth failure";
fprintf(stderr, "conntest: auth error: %s\n", s.latin1());
}
else if(err == XMPP::ClientStream::ErrSecurityLayer)
fprintf(stderr, "conntest: broken security layer (SASL)\n");
quit();
}
void con_connectionClosed()
{
fprintf(stderr, "conntest: Closing.\n");
stream->close();
quit();
}
void con_readyRead()
{
QByteArray a = c->read();
QCString cs;
cs.resize(a.size()+1);
memcpy(cs.data(), a.data(), a.size());
QString s = QString::fromLocal8Bit(cs);
stream->writeDirect(s);
}
};
#include "conntest.moc"
int main(int argc, char **argv)
{
QApplication app(argc, argv, false);
if(argc < 2) {
printf("usage: conntest [options] [jid]\n");
printf(" Options:\n");
printf(" --host=host:port\n");
printf(" --sslhost=host:port\n");
printf(" --probe\n");
printf(" --proxy=[https|poll|socks],host:port,url\n");
printf(" --proxy-auth=user,pass\n");
printf("\n");
return 0;
}
bool have_tls = QCA::isSupported(QCA::CAP_TLS);
XMPP::Jid jid;
XMPP::AdvancedConnector::Proxy proxy;
QString host;
int port = 0;
bool opt_ssl = false;
bool opt_probe = false;
for(int at = 1; at < argc; ++at) {
QString s = argv[at];
// is it an option?
if(s.left(2) == "--") {
QString name;
QStringList args;
int n = s.find('=', 2);
if(n != -1) {
name = s.mid(2, n-2);
++n;
args = QStringList::split(',', s.mid(n), true);
}
else {
name = s.mid(2);
args.clear();
}
// eat the arg
--argc;
for(int x = at; x < argc; ++x)
argv[x] = argv[x+1];
--at; // don't advance
// process option
if(name == "proxy") {
QString proxy_host;
int proxy_port = 0;
QString type = args[0];
QString s = args[1];
int n = s.find(':');
if(n == -1) {
if(type != "poll") {
printf("Invalid host:port for proxy\n");
return 0;
}
}
else {
proxy_host = s.mid(0, n);
++n;
proxy_port = s.mid(n).toInt();
}
if(type == "https") {
proxy.setHttpConnect(proxy_host, proxy_port);
}
else if(type == "poll") {
if(args.count() < 3) {
printf("poll needs more args\n");
return 0;
}
QString proxy_url = args[2];
proxy.setHttpPoll(proxy_host, proxy_port, proxy_url);
}
else if(type == "socks") {
proxy.setSocks(proxy_host, proxy_port);
}
else {
printf("No such proxy type '%s'\n", type.latin1());
return 0;
}
}
else if(name == "proxy-auth") {
proxy.setUserPass(args[0], args[1]);
}
else if(name == "host") {
QString s = args[0];
int n = s.find(':');
if(n == -1) {
printf("Invalid host:port for host\n");
return 0;
}
host = s.mid(0, n);
++n;
port = s.mid(n).toInt();
}
else if(name == "sslhost") {
QString s = args[0];
int n = s.find(':');
if(n == -1) {
printf("Invalid host:port for host\n");
return 0;
}
host = s.mid(0, n);
++n;
port = s.mid(n).toInt();
opt_ssl = true;
}
else if(name == "probe") {
opt_probe = true;
}
else {
printf("Unknown option '%s'\n", name.latin1());
return 0;
}
}
}
if(argc < 2) {
printf("No host specified!\n");
return 0;
}
jid = argv[1];
if((opt_ssl || opt_probe) && !have_tls) {
printf("TLS not supported, so the sslhost and probe options are not allowed.\n");
return 0;
}
printf("JID: %s\n", jid.full().latin1());
if(proxy.type() != XMPP::AdvancedConnector::Proxy::None) {
printf("Proxy: ");
if(proxy.type() == XMPP::AdvancedConnector::Proxy::HttpConnect)
printf("HttpConnect (%s:%d)", proxy.host().latin1(), proxy.port());
else if(proxy.type() == XMPP::AdvancedConnector::Proxy::HttpPoll) {
printf("HttpPoll {%s}", proxy.url().latin1());
if(!proxy.host().isEmpty()) {
printf(" (%s:%d)", proxy.host().latin1(), proxy.port());
}
}
else if(proxy.type() == XMPP::AdvancedConnector::Proxy::Socks)
printf("Socks (%s:%d)", proxy.host().latin1(), proxy.port());
printf("\n");
}
if(proxy.type() != XMPP::AdvancedConnector::Proxy::HttpPoll) {
if(!host.isEmpty()) {
printf("Host: %s:%d", host.latin1(), port);
if(opt_ssl)
printf(" (ssl)");
printf("\n");
}
else {
if(opt_probe)
printf("Probe active\n");
}
}
printf("----------\n");
App *a = new App(jid, proxy, host, port, opt_ssl, opt_probe);
QObject::connect(a, SIGNAL(quit()), &app, SLOT(quit()));
app.exec();
delete a;
return 0;
}

View file

@ -0,0 +1,15 @@
TEMPLATE = app
CONFIG += qt thread console
TARGET = conntest
QT += qt3support network xml
# Dependencies
CONFIG += crypto
include(../../../cutestuff/cutestuff.pri)
include(../../iris.pri)
irisnet {
include(../../irisnet/irisnet.pri)
}
SOURCES += conntest.cpp

View file

@ -0,0 +1,4 @@
<qconf>
<name>Iris Conntest</name>
<profile>conntest.pro</profile>
</qconf>

View file

@ -0,0 +1,30 @@
#!/bin/sh
CS_BASE=../../../cutestuff
QCA_BASE=../../../qca
IRIS_BASE=../..
# import cutestuff
mkdir cutestuff
cp -a $CS_BASE/util cutestuff
cp -a $CS_BASE/network cutestuff
# import qca
mkdir qca
cp -a $QCA_BASE/src/* qca
# import iris
mkdir iris
cp -a $IRIS_BASE/libidn iris
cp -a $IRIS_BASE/libidn.pri iris
cp -a $IRIS_BASE/include iris
cp -a $IRIS_BASE/xmpp-core iris
cp -a $IRIS_BASE/xmpp-im iris
cp -a $IRIS_BASE/jabber iris
cp -a $IRIS_BASE/iris.pri iris
# other stuff
cp -a $IRIS_BASE/cs.pri .
cp -a $IRIS_BASE/example/example.pri .
cp -a $IRIS_BASE/COPYING .

View file

@ -0,0 +1,217 @@
#include <qapplication.h>
#include <qsocket.h>
#include <qserversocket.h>
#include <qvaluelist.h>
#include <qtimer.h>
#include <qca.h>
#include <stdlib.h>
#include <time.h>
#include "bsocket.h"
#include "xmpp.h"
#include <unistd.h>
char pemdata_cert[] =
"-----BEGIN CERTIFICATE-----\n"
"MIIDbjCCAtegAwIBAgIBADANBgkqhkiG9w0BAQQFADCBhzELMAkGA1UEBhMCVVMx\n"
"EzARBgNVBAgTCkNhbGlmb3JuaWExDzANBgNVBAcTBklydmluZTEYMBYGA1UEChMP\n"
"RXhhbXBsZSBDb21wYW55MRQwEgYDVQQDEwtleGFtcGxlLmNvbTEiMCAGCSqGSIb3\n"
"DQEJARYTZXhhbXBsZUBleGFtcGxlLmNvbTAeFw0wMzA3MjQwNzMwMDBaFw0wMzA4\n"
"MjMwNzMwMDBaMIGHMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEP\n"
"MA0GA1UEBxMGSXJ2aW5lMRgwFgYDVQQKEw9FeGFtcGxlIENvbXBhbnkxFDASBgNV\n"
"BAMTC2V4YW1wbGUuY29tMSIwIAYJKoZIhvcNAQkBFhNleGFtcGxlQGV4YW1wbGUu\n"
"Y29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCobzCF268K2sRp473gvBTT\n"
"4AgSL1kjeF8N57vxS1P8zWrWMXNs4LuH0NRZmKTajeboy0br8xw+smIy3AbaKAwW\n"
"WZToesxebu3m9VeA8dqWyOaUMjoxAcgVYesgVaMpjRe7fcWdJnX1wJoVVPuIcO8m\n"
"a+AAPByfTORbzpSTmXAQAwIDAQABo4HnMIHkMB0GA1UdDgQWBBTvFierzLmmYMq0\n"
"cB/+5rK1bNR56zCBtAYDVR0jBIGsMIGpgBTvFierzLmmYMq0cB/+5rK1bNR566GB\n"
"jaSBijCBhzELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExDzANBgNV\n"
"BAcTBklydmluZTEYMBYGA1UEChMPRXhhbXBsZSBDb21wYW55MRQwEgYDVQQDEwtl\n"
"eGFtcGxlLmNvbTEiMCAGCSqGSIb3DQEJARYTZXhhbXBsZUBleGFtcGxlLmNvbYIB\n"
"ADAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBAUAA4GBAGqGhXf7xNOnYNtFO7gz\n"
"K6RdZGHFI5q1DAEz4hhNBC9uElh32XGX4wN7giz3zLC8v9icL/W4ff/K5NDfv3Gf\n"
"gQe/+Wo9Be3H3ul6uwPPFnx4+PIOF2a5TW99H9smyxWdNjnFtcUte4al3RszcMWG\n"
"x3iqsWosGtj6F+ridmKoqKLu\n"
"-----END CERTIFICATE-----\n";
char pemdata_privkey[] =
"-----BEGIN RSA PRIVATE KEY-----\n"
"MIICXAIBAAKBgQCobzCF268K2sRp473gvBTT4AgSL1kjeF8N57vxS1P8zWrWMXNs\n"
"4LuH0NRZmKTajeboy0br8xw+smIy3AbaKAwWWZToesxebu3m9VeA8dqWyOaUMjox\n"
"AcgVYesgVaMpjRe7fcWdJnX1wJoVVPuIcO8ma+AAPByfTORbzpSTmXAQAwIDAQAB\n"
"AoGAP83u+aYghuIcaWhmM03MLf69z/WztKYSi/fu0BcS977w67bL3MC9CVPoPRB/\n"
"0nLSt/jZIuRzHKUCYfXLerSU7v0oXDTy6GPzWMh/oXIrpF0tYNbwWF7LSq2O2gGZ\n"
"XtA9MSmUNNJaKzQQeXjqdVFOY8A0Pho+k2KByBiCi+ChkcECQQDRUuyX0+PKJtA2\n"
"M36BOTFpy61BAv+JRlXUnHuevOfQWl6NR6YGygqCyH1sWtP1sa9S4wWys3DFH+5A\n"
"DkuAqk7zAkEAzf4eUH2hp5CIMsXH+WpIzKj09oY1it2CAKjVq4rUELf8iXvmGoFl\n"
"000spua4MjHNUYm7LR0QaKesKrMyGZUesQJAL8aLdYPJI+SD9Tr/jqLtIkZ4frQe\n"
"eshw4pvsoyheiHF3zyshO791crAr4EVCx3sMlxB1xnmqLXPCPyCEHxO//QJBAIBY\n"
"IYkjDZJ6ofGIe1UyXJNvfdkPu9J+ut4wU5jjEcgs6mK62J6RGuFxhy2iOQfFMdjo\n"
"yL+OCUg7mDCun7uCxrECQAtSvnLOFMjO5qExRjFtwi+b1rcSekd3Osk/izyRFSzg\n"
"Or+AL56/EKfiogNnFipgaXIbb/xj785Cob6v96XoW1I=\n"
"-----END RSA PRIVATE KEY-----\n";
QCA::Cert *cert;
QCA::RSAKey *privkey;
using namespace XMPP;
int id_num = 0;
class Session : public QObject
{
Q_OBJECT
public:
Session(const QString &host, const QString &defRealm, ByteStream *bs) : QObject(0)
{
id = id_num++;
tls = new QCA::TLS;
tls->setCertificate(*cert, *privkey);
cs = new ClientStream(host, defRealm, bs, tls);
connect(cs, SIGNAL(connectionClosed()), SLOT(cs_connectionClosed()));
connect(cs, SIGNAL(error(int)), SLOT(cs_error(int)));
}
~Session()
{
delete cs;
delete tls;
printf("[%d]: deleted\n", id);
}
void start()
{
printf("[%d]: New session!\n", id);
cs->accept();
}
signals:
void done();
private slots:
void cs_connectionClosed()
{
printf("[%d]: Connection closed by peer\n", id);
done();
}
void cs_error(int)
{
printf("[%d]: Error\n", id);
done();
}
private:
int id;
ClientStream *cs;
QCA::TLS *tls;
};
class ServerTest : public QServerSocket
{
Q_OBJECT
public:
enum { Idle, Handshaking, Active, Closing };
ServerTest(const QString &_host, int _port) : QServerSocket(_port), host(_host), port(_port)
{
cert = new QCA::Cert;
privkey = new QCA::RSAKey;
cert->fromPEM(pemdata_cert);
privkey->fromPEM(pemdata_privkey);
list.setAutoDelete(true);
}
~ServerTest()
{
}
void start()
{
char buf[256];
int r = gethostname(buf, sizeof(buf)-1);
if(r == -1) {
printf("Error getting hostname!\n");
QTimer::singleShot(0, this, SIGNAL(quit()));
return;
}
QString myhostname = buf;
realm = myhostname;
if(host.isEmpty())
host = myhostname;
if(cert->isNull() || privkey->isNull()) {
printf("Error loading cert and/or private key!\n");
QTimer::singleShot(0, this, SIGNAL(quit()));
return;
}
if(!ok()) {
printf("Error binding to port %d!\n", port);
QTimer::singleShot(0, this, SIGNAL(quit()));
return;
}
printf("Listening on %s:%d ...\n", host.latin1(), port);
}
void newConnection(int s)
{
BSocket *bs = new BSocket;
bs->setSocket(s);
Session *sess = new Session(host, realm, bs);
list.append(sess);
connect(sess, SIGNAL(done()), SLOT(sess_done()));
sess->start();
}
signals:
void quit();
private slots:
void sess_done()
{
Session *sess = (Session *)sender();
list.removeRef(sess);
}
private:
QString host, realm;
int port;
QPtrList<Session> list;
};
#include "server.moc"
int main(int argc, char **argv)
{
QApplication app(argc, argv, false);
QString host = argc > 1 ? QString(argv[1]) : QString();
int port = argc > 2 ? QString(argv[2]).toInt() : 5222;
if(!QCA::isSupported(QCA::CAP_TLS)) {
printf("TLS not supported!\n");
return 1;
}
if(!QCA::isSupported(QCA::CAP_SASL)) {
printf("SASL not supported!\n");
return 1;
}
srand(time(NULL));
ServerTest *s = new ServerTest(host, port);
QObject::connect(s, SIGNAL(quit()), &app, SLOT(quit()));
s->start();
app.exec();
delete s;
// clean up
QCA::unloadAllPlugins();
return 0;
}

View file

@ -0,0 +1,15 @@
TEMPLATE = app
CONFIG += qt thread console
TARGET = server
MOC_DIR = .moc
OBJECTS_DIR = .obj
UI_DIR = .ui
include(../xmpptest/iris.pri)
SOURCES += server.cpp
# gentoo hack?
LIBS += -lcrypto

View file

@ -0,0 +1,470 @@
<ui version="4.0" stdsetdef="1" >
<author></author>
<comment></comment>
<exportmacro></exportmacro>
<class>TestUI</class>
<widget class="QDialog" name="TestUI" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>652</width>
<height>591</height>
</rect>
</property>
<property name="windowTitle" >
<string>Form1</string>
</property>
<layout class="QHBoxLayout" >
<item>
<widget class="QTabWidget" name="tb_main" >
<widget class="QWidget" name="tab" >
<attribute name="title" >
<string>Core</string>
</attribute>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<item>
<widget class="Q3GroupBox" name="gb_server" >
<property name="title" >
<string>Server</string>
</property>
<layout class="QVBoxLayout" >
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<item>
<widget class="QLabel" name="textLabel1" >
<property name="text" >
<string>Full JID:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="le_jid" />
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<item>
<widget class="QLabel" name="textLabel5_2" >
<property name="text" >
<string>User (if needed):</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="le_user" >
<property name="text" >
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="textLabel7_2" >
<property name="text" >
<string>Pass:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="le_pass" >
<property name="echoMode" >
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QGridLayout" >
<property name="margin" >
<number>0</number>
</property>
<item row="1" column="2" >
<widget class="QCheckBox" name="ck_ssl" >
<property name="text" >
<string>SSL</string>
</property>
</widget>
</item>
<item rowspan="1" row="2" column="1" colspan="2" >
<widget class="QComboBox" name="cb_proxy" >
<item>
<property name="text" >
<string>None</string>
</property>
</item>
<item>
<property name="text" >
<string>HTTP(S)</string>
</property>
</item>
<item>
<property name="text" >
<string>SOCKS5</string>
</property>
</item>
<item>
<property name="text" >
<string>HTTP Polling</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0" >
<widget class="QLabel" name="lb_host" >
<property name="text" >
<string>Host:Port:</string>
</property>
</widget>
</item>
<item rowspan="1" row="0" column="0" colspan="3" >
<widget class="QCheckBox" name="ck_probe" >
<property name="text" >
<string>Legacy SSL probe</string>
</property>
</widget>
</item>
<item row="2" column="0" >
<widget class="QLabel" name="textLabel4" >
<property name="text" >
<string>Proxy:</string>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="QLineEdit" name="le_host" />
</item>
</layout>
</item>
<item>
<widget class="Q3GroupBox" name="gb_proxy" >
<property name="title" >
<string>Proxy Settings</string>
</property>
<layout class="QGridLayout" >
<item row="0" column="0" >
<widget class="QLabel" name="textLabel2_2" >
<property name="text" >
<string>Host:Port:</string>
</property>
</widget>
</item>
<item rowspan="1" row="0" column="1" colspan="3" >
<widget class="QLineEdit" name="le_proxyhost" />
</item>
<item row="1" column="0" >
<widget class="QLabel" name="textLabel5" >
<property name="text" >
<string>User/Pass:</string>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="QLineEdit" name="le_proxyuser" />
</item>
<item row="1" column="2" >
<widget class="QLabel" name="textLabel7" >
<property name="text" >
<string>/</string>
</property>
</widget>
</item>
<item row="1" column="3" >
<widget class="QLineEdit" name="le_proxypass" >
<property name="echoMode" >
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="2" column="0" >
<widget class="QLabel" name="lb_proxyurl" >
<property name="text" >
<string>Polling URL:</string>
</property>
</widget>
</item>
<item rowspan="1" row="2" column="1" colspan="3" >
<widget class="QLineEdit" name="le_proxyurl" />
</item>
</layout>
</widget>
</item>
<item>
<widget class="Q3GroupBox" name="gb_security" >
<property name="title" >
<string>Security Settings</string>
</property>
<layout class="QVBoxLayout" >
<item>
<widget class="QCheckBox" name="ck_plain" >
<property name="text" >
<string>Allow plaintext login</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="ck_mutual" >
<property name="text" >
<string>Require mutual authentication</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<item>
<widget class="QLabel" name="textLabel1_2" >
<property name="text" >
<string>SASL SSF min/max:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="sb_ssfmin" />
</item>
<item>
<widget class="QLabel" name="textLabel2" >
<property name="text" >
<string>/</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="sb_ssfmax" />
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="pb_go" >
<property name="text" >
<string>&amp;Connect</string>
</property>
<property name="shortcut" >
<string>Alt+C</string>
</property>
</widget>
</item>
<item>
<spacer name="spacer5" >
<property name="sizeHint" >
<size>
<width>130</width>
<height>20</height>
</size>
</property>
<property name="sizeType" >
<enum>Expanding</enum>
</property>
<property name="orientation" >
<enum>Horizontal</enum>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pb_about" >
<property name="text" >
<string>&amp;About</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="spacer3_2" >
<property name="sizeHint" >
<size>
<width>20</width>
<height>16</height>
</size>
</property>
<property name="sizeType" >
<enum>Expanding</enum>
</property>
<property name="orientation" >
<enum>Vertical</enum>
</property>
</spacer>
</item>
<item>
<widget class="Q3GroupBox" name="groupBox3" >
<property name="title" >
<string>Quick XML >></string>
</property>
<layout class="QVBoxLayout" >
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<item>
<widget class="QLabel" name="textLabel8" >
<property name="text" >
<string>To:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="le_to" />
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="pb_im" >
<property name="text" >
<string>&amp;IM Session</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pb_msg" >
<property name="text" >
<string>&amp;Message</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pb_iqv" >
<property name="text" >
<string>IQ &amp;Version</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab" >
<attribute name="title" >
<string>IM</string>
</attribute>
</widget>
</widget>
</item>
<item>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<item>
<widget class="Q3TextEdit" name="te_log" >
<property name="minimumSize" >
<size>
<width>300</width>
<height>0</height>
</size>
</property>
<property name="wrapPolicy" >
<enum>AtWordOrDocumentBoundary</enum>
</property>
<property name="readOnly" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="Q3TextEdit" name="te_input" >
<property name="maximumSize" >
<size>
<width>32767</width>
<height>200</height>
</size>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<item>
<spacer name="spacer3" >
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
<property name="sizeType" >
<enum>Expanding</enum>
</property>
<property name="orientation" >
<enum>Horizontal</enum>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pb_send" >
<property name="text" >
<string>&amp;Send</string>
</property>
<property name="shortcut" >
<string>Alt+S</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11" />
<pixmapfunction>qPixmapFromMimeSource</pixmapfunction>
<tabstops>
<tabstop>le_jid</tabstop>
<tabstop>le_user</tabstop>
<tabstop>le_pass</tabstop>
<tabstop>ck_probe</tabstop>
<tabstop>le_host</tabstop>
<tabstop>ck_ssl</tabstop>
<tabstop>cb_proxy</tabstop>
<tabstop>le_proxyhost</tabstop>
<tabstop>le_proxyuser</tabstop>
<tabstop>le_proxypass</tabstop>
<tabstop>le_proxyurl</tabstop>
<tabstop>ck_plain</tabstop>
<tabstop>ck_mutual</tabstop>
<tabstop>sb_ssfmin</tabstop>
<tabstop>sb_ssfmax</tabstop>
<tabstop>pb_go</tabstop>
<tabstop>pb_about</tabstop>
<tabstop>le_to</tabstop>
<tabstop>pb_im</tabstop>
<tabstop>pb_msg</tabstop>
<tabstop>pb_iqv</tabstop>
<tabstop>te_input</tabstop>
<tabstop>pb_send</tabstop>
<tabstop>te_log</tabstop>
</tabstops>
</ui>

View file

@ -0,0 +1,916 @@
#include <qapplication.h>
#include <q3textedit.h>
#include <q3groupbox.h>
#include <qlineedit.h>
#include <qlabel.h>
#include <qcheckbox.h>
#include <q3textedit.h>
#include <qcombobox.h>
#include <qpushbutton.h>
#include <qmessagebox.h>
#include <qinputdialog.h>
#include <qspinbox.h>
#include <qtimer.h>
#include <qmenubar.h>
#include <q3popupmenu.h>
#include <qtabwidget.h>
#include <qca.h>
//Added by qt3to4:
#include <Q3PtrList>
#include <QList>
//#include <iris/xmpp.h>
#include "xmpp.h"
#include "im.h"
#include <stdlib.h>
#include <time.h>
#include "ui_ui_test.h"
#include <stdio.h>
#define AppName "xmpptest"
static QString plain2rich(const QString &plain)
{
QString rich;
int col = 0;
for(int i = 0; i < (int)plain.length(); ++i) {
if(plain[i] == '\n') {
rich += "<br>";
col = 0;
}
else if(plain[i] == '\t') {
rich += QChar::nbsp;
while(col % 4) {
rich += QChar::nbsp;
++col;
}
}
else if(plain[i].isSpace()) {
if(i > 0 && plain[i-1] == ' ')
rich += QChar::nbsp;
else
rich += ' ';
}
else if(plain[i] == '<')
rich += "&lt;";
else if(plain[i] == '>')
rich += "&gt;";
else if(plain[i] == '\"')
rich += "&quot;";
else if(plain[i] == '\'')
rich += "&apos;";
else if(plain[i] == '&')
rich += "&amp;";
else
rich += plain[i];
++col;
}
return rich;
}
/*static void showCertInfo(const QCA::Cert &cert)
{
fprintf(stderr, "-- Cert --\n");
fprintf(stderr, " CN: %s\n", cert.subject()["CN"].latin1());
fprintf(stderr, " Valid from: %s, until %s\n",
cert.notBefore().toString().latin1(),
cert.notAfter().toString().latin1());
fprintf(stderr, " PEM:\n%s\n", cert.toPEM().latin1());
}*/
static QString resultToString(int result)
{
QString s;
switch(result) {
case QCA::TLS::NoCertificate:
s = QObject::tr("No certificate presented.");
break;
case QCA::TLS::Valid:
break;
case QCA::TLS::HostMismatch:
s = QObject::tr("Hostname mismatch.");
break;
case QCA::TLS::InvalidCertificate:
s = QObject::tr("Invalid Certificate.");
break;
// TODO: Inspect why
// case QCA::TLS::Untrusted:
// s = QObject::tr("Not trusted for the specified purpose.");
// break;
// case QCA::TLS::SignatureFailed:
// s = QObject::tr("Invalid signature.");
// break;
// case QCA::TLS::InvalidCA:
// s = QObject::tr("Invalid CA certificate.");
// break;
// case QCA::TLS::InvalidPurpose:
// s = QObject::tr("Invalid certificate purpose.");
// break;
// case QCA::TLS::SelfSigned:
// s = QObject::tr("Certificate is self-signed.");
// break;
// case QCA::TLS::Revoked:
// s = QObject::tr("Certificate has been revoked.");
// break;
// case QCA::TLS::PathLengthExceeded:
// s = QObject::tr("Maximum cert chain length exceeded.");
// break;
// case QCA::TLS::Expired:
// s = QObject::tr("Certificate has expired.");
// break;
// case QCA::TLS::Unknown:
default:
s = QObject::tr("General validation error.");
break;
}
return s;
}
class TestDebug : public XMPP::Debug
{
public:
void msg(const QString &);
void outgoingTag(const QString &);
void incomingTag(const QString &);
void outgoingXml(const QDomElement &);
void incomingXml(const QDomElement &);
};
class TestDlg : public QDialog, public Ui::TestUI
{
Q_OBJECT
public:
bool active, connected;
XMPP::AdvancedConnector *conn;
QCA::TLS *tls;
XMPP::QCATLSHandler *tlsHandler;
XMPP::ClientStream *stream;
XMPP::Jid jid;
TestDlg(QWidget *parent=0) : QDialog(parent)
{
setupUi(this);
setWindowTitle(tr("XMPP Test"));
connect(ck_probe, SIGNAL(toggled(bool)), SLOT(probe_toggled(bool)));
connect(cb_proxy, SIGNAL(activated(int)), SLOT(proxy_activated(int)));
connect(pb_go, SIGNAL(clicked()), SLOT(go()));
connect(pb_send, SIGNAL(clicked()), SLOT(send()));
connect(pb_im, SIGNAL(clicked()), SLOT(sc_im()));
connect(pb_msg, SIGNAL(clicked()), SLOT(sc_msg()));
connect(pb_iqv, SIGNAL(clicked()), SLOT(sc_iqv()));
connect(pb_about, SIGNAL(clicked()), SLOT(about()));
sb_ssfmin->setMinValue(0);
sb_ssfmin->setMaxValue(256);
sb_ssfmax->setMinValue(0);
sb_ssfmax->setMaxValue(256);
pb_send->setEnabled(false);
proxy_activated(0);
ck_probe->setChecked(true);
ck_mutual->setChecked(false);
pb_go->setText(tr("&Connect"));
//le_jid->setText("psitest@jabberd.jabberstudio.org/Test");
//ck_probe->setChecked(false);
//le_host->setText("jabberd.jabberstudio.org:15222");
//ck_mutual->setChecked(false);
//le_jid->setText("sasltest@e.jabber.ru/Test");
//le_jid->setText("psitest@jabber.cz/Test");
//le_pass->setText("psitest");
//cb_proxy->setCurrentItem(3);
//le_proxyurl->setText("http://connect.jabber.cz/");
// setup xmpp
conn = new XMPP::AdvancedConnector;
connect(conn, SIGNAL(srvLookup(const QString &)), SLOT(conn_srvLookup(const QString &)));
connect(conn, SIGNAL(srvResult(bool)), SLOT(conn_srvResult(bool)));
connect(conn, SIGNAL(httpSyncStarted()), SLOT(conn_httpSyncStarted()));
connect(conn, SIGNAL(httpSyncFinished()), SLOT(conn_httpSyncFinished()));
if(QCA::isSupported("tls")) {
tls = new QCA::TLS;
tlsHandler = new XMPP::QCATLSHandler(tls);
tlsHandler->setXMPPCertCheck(true);
connect(tlsHandler, SIGNAL(tlsHandshaken()), SLOT(tls_handshaken()));
}
else {
tls = 0;
tlsHandler = 0;
}
stream = new XMPP::ClientStream(conn, tlsHandler);
//stream->setOldOnly(true);
connect(stream, SIGNAL(connected()), SLOT(cs_connected()));
connect(stream, SIGNAL(securityLayerActivated(int)), SLOT(cs_securityLayerActivated(int)));
connect(stream, SIGNAL(needAuthParams(bool, bool, bool)), SLOT(cs_needAuthParams(bool, bool, bool)));
connect(stream, SIGNAL(authenticated()), SLOT(cs_authenticated()));
connect(stream, SIGNAL(connectionClosed()), SLOT(cs_connectionClosed()));
connect(stream, SIGNAL(delayedCloseFinished()), SLOT(cs_delayedCloseFinished()));
connect(stream, SIGNAL(readyRead()), SLOT(cs_readyRead()));
connect(stream, SIGNAL(stanzaWritten()), SLOT(cs_stanzaWritten()));
connect(stream, SIGNAL(warning(int)), SLOT(cs_warning(int)));
connect(stream, SIGNAL(error(int)), SLOT(cs_error(int)));
QTimer::singleShot(0, this, SLOT(adjustLayout()));
le_jid->setFocus();
active = false;
connected = false;
}
~TestDlg()
{
delete stream;
delete tls; // this destroys the TLSHandler also
delete conn;
}
private slots:
void adjustLayout()
{
tb_main->setFixedWidth(tb_main->minimumSizeHint().width());
resize(minimumSizeHint());
show();
}
void about()
{
QMessageBox::about(this, tr("About %1").arg(AppName), tr(
"%1 v1.0\n"
"\n"
"Utility to demonstrate the Iris XMPP library.\n"
"\n"
"Currently supports:\n"
" draft-ietf-xmpp-core-21\n"
" JEP-0025\n"
"\n"
"Copyright (C) 2003 Justin Karneges").arg(AppName));
}
void probe_toggled(bool)
{
setHostState();
}
void proxy_activated(int x)
{
bool ok = (x != 0);
bool okpoll = (x == 3);
gb_proxy->setEnabled(ok);
lb_proxyurl->setEnabled(okpoll);
le_proxyurl->setEnabled(okpoll);
ck_probe->setEnabled(!okpoll);
setHostState();
}
void cleanup()
{
pb_send->setEnabled(false);
pb_go->setEnabled(true);
pb_go->setText(tr("&Connect"));
pb_go->setFocus();
gb_server->setEnabled(true);
active = false;
connected = false;
}
void start()
{
if(active)
return;
jid = XMPP::Jid(le_jid->text());
if(jid.domain().isEmpty() || jid.node().isEmpty() || jid.resource().isEmpty()) {
QMessageBox::information(this, tr("Error"), tr("Please enter the Full JID to connect with."));
return;
}
int p = cb_proxy->currentItem();
XMPP::AdvancedConnector::Proxy proxy;
if(p > 0) {
QString s = le_proxyhost->text();
QString url = le_proxyurl->text();
if(p != 3 && s.isEmpty()) {
QMessageBox::information(this, tr("Error"), tr("You must specify a host:port for the proxy."));
return;
}
if(p == 3 && s.isEmpty() && url.isEmpty()) {
QMessageBox::information(this, tr("Error"), tr("You must at least enter a URL to use http poll."));
return;
}
QString host;
int port = 0;
if(!s.isEmpty()) {
int n = s.find(':');
if(n == -1) {
QMessageBox::information(this, tr("Error"), tr("Please enter the proxy host in the form 'host:port'."));
return;
}
host = s.mid(0, n);
port = s.mid(n+1).toInt();
}
if(p == 1)
proxy.setHttpConnect(host, port);
else if(p == 2)
proxy.setSocks(host, port);
else if(p == 3) {
proxy.setHttpPoll(host, port, url);
proxy.setPollInterval(2); // fast during login
}
proxy.setUserPass(le_proxyuser->text(), le_proxypass->text());
}
bool probe = (p != 3 && ck_probe->isChecked());
bool useHost = (!probe && !le_host->text().isEmpty());
QString host;
int port = 0;
bool ssl = false;
if(useHost) {
QString s = le_host->text();
int n = s.find(':');
if(n == -1) {
QMessageBox::information(this, tr("Error"), tr("Please enter the host in the form 'host:port'."));
return;
}
host = s.mid(0, n);
port = s.mid(n+1).toInt();
if(ck_ssl->isChecked())
ssl = true;
}
if(sb_ssfmin->value() > sb_ssfmax->value()) {
QMessageBox::information(this, tr("Error"), tr("Error: SSF Min is greater than SSF Max."));
return;
}
if((probe || ssl) && !tls) {
QMessageBox::information(this, tr("Error"), tr("Error: TLS not available. Disable any TLS options."));
return;
}
// prepare
conn->setProxy(proxy);
if(useHost)
conn->setOptHostPort(host, port);
else
conn->setOptHostPort("", 0);
conn->setOptProbe(probe);
conn->setOptSSL(ssl);
if(tls) {
tls->setTrustedCertificates(QCA::systemStore());
}
stream->setNoopTime(55000); // every 55 seconds
stream->setAllowPlain(ck_plain->isChecked() ? XMPP::ClientStream::AllowPlain : XMPP::ClientStream::NoAllowPlain);
stream->setRequireMutualAuth(ck_mutual->isChecked());
stream->setSSFRange(sb_ssfmin->value(), sb_ssfmax->value());
//stream->setOldOnly(true);
stream->setCompress(true);
gb_server->setEnabled(false);
pb_go->setText(tr("&Disconnect"));
pb_go->setFocus();
active = true;
appendSysMsg("Connecting...");
stream->connectToServer(jid);
}
void stop()
{
if(!active)
return;
if(connected) {
pb_go->setEnabled(false);
appendSysMsg("Disconnecting...");
stream->close();
}
else {
stream->close();
appendSysMsg("Disconnected");
cleanup();
}
}
void go()
{
if(active)
stop();
else
start();
}
void send()
{
if(te_input->text().isEmpty())
return;
// construct a "temporary" document to parse the input
QString str = "<stream xmlns=\"jabber:client\">\n";
str += te_input->text() + '\n';
str += "</stream>";
QDomDocument doc;
QString errMsg;
int errLine, errCol;
if(!doc.setContent(str, true, &errMsg, &errLine, &errCol)) {
int lines = QStringList::split('\n', str, true).count();
--errLine; // skip the first line
if(errLine == lines-1) {
errLine = lines-2;
errCol = te_input->paragraphLength(errLine-1)+1;
errMsg = "incomplete input";
}
te_input->setCursorPosition(errLine-1, errCol-1);
QMessageBox::information(this, tr("Error"), tr("Bad XML input (%1,%2): %3\nPlease correct and try again.").arg(errCol).arg(errLine).arg(errMsg));
return;
}
QDomElement e = doc.firstChild().toElement();
int num = 0;
QDomNodeList nl = e.childNodes();
QList<XMPP::Stanza> stanzaList;
for(uint x = 0; x < nl.count(); ++x) {
QDomNode n = nl.item(x);
if(n.isElement()) {
QDomElement e = n.toElement();
XMPP::Stanza s = stream->createStanza(e);
if(s.isNull()) {
QMessageBox::information(this, tr("Error"), tr("Bad Stanza '%1'. Must be 'message', 'presence', or 'iq'").arg(e.tagName()));
return;
}
stanzaList += s;
++num;
}
}
if(num == 0) {
QMessageBox::information(this, tr("Error"), tr("You must enter at least one stanza!"));
return;
}
// out the door
for(QList<XMPP::Stanza>::ConstIterator it = stanzaList.begin(); it != stanzaList.end(); ++it) {
appendXmlOut(XMPP::Stream::xmlToString((*it).element(), true));
stream->write(*it);
}
te_input->setText("");
}
void sc_im()
{
/*XMPP::Message m("justin@andbit.net/Psi");
m.setSubject("Hi");
m.setBody("I send you this in order to have your advice.");
m.setBody("Escucha lechuga!", "es");
XMPP::Stanza stanza = m.toStanza(stream);
QString str = stanza.toString();
printf("[%s]\n", str.latin1());
XMPP::Message n;
n.fromStanza(stanza);
printf("subject: [%s]\n", n.subject().latin1());
printf("body: [%s]\n", n.body().latin1());
printf("body-es: [%s]\n", n.body("es").latin1());*/
QString s;
s += "<iq type='set' id='sess_1'>\n";
s += " <session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>\n";
s += "</iq>";
te_input->setText(s);
te_input->setFocus();
}
void sc_msg()
{
QString to = le_to->text();
QString s;
if(!to.isEmpty())
s += QString("<message to=\"%1\">\n").arg(to);
else
s += QString("<message to=\"\">\n");
s += " <body>hello world</body>\n";
s += "</message>";
te_input->setText(s);
if(!to.isEmpty()) {
te_input->setCursorPosition(1, 7);
te_input->setSelection(1, 7, 1, 18);
}
else
te_input->setCursorPosition(0, 13);
te_input->setFocus();
}
void sc_iqv()
{
QString to = le_to->text();
QString s;
if(!to.isEmpty())
s += QString("<iq to=\"%1\" type=\"get\" id=\"abcde\">\n").arg(to);
else
s += QString("<iq to=\"\" type=\"get\" id=\"abcde\">\n");
s += " <query xmlns=\"jabber:iq:version\"/>\n";
s += "</iq>";
te_input->setText(s);
if(!to.isEmpty()) {
te_input->setCursorPosition(0, 8);
te_input->setSelection(0, 8, 0, 8 + to.length());
}
else
te_input->setCursorPosition(0, 8);
te_input->setFocus();
}
void conn_srvLookup(const QString &server)
{
appendLibMsg(QString("SRV lookup on [%1]").arg(server));
}
void conn_srvResult(bool b)
{
if(b)
appendLibMsg("SRV lookup success!");
else
appendLibMsg("SRV lookup failed");
}
void conn_httpSyncStarted()
{
appendLibMsg("HttpPoll: syncing");
}
void conn_httpSyncFinished()
{
appendLibMsg("HttpPoll: done");
}
void tls_handshaken()
{
//QCA::Certificate cert = tls->peerCertificate();
int vr = tls->peerIdentityResult();
if (vr == QCA::TLS::Valid && !tlsHandler->certMatchesHostname()) vr = QCA::TLS::HostMismatch;
appendSysMsg("Successful TLS handshake.");
if(vr == QCA::TLS::Valid)
appendSysMsg("Valid certificate.");
else {
appendSysMsg(QString("Invalid certificate: %1").arg(resultToString(vr)), Qt::red);
appendSysMsg("Continuing anyway");
}
tlsHandler->continueAfterHandshake();
}
void cs_connected()
{
QString s = "Connected";
if(conn->havePeerAddress())
s += QString(" (%1:%2)").arg(conn->peerAddress().toString()).arg(conn->peerPort());
if(conn->useSSL())
s += " [ssl]";
appendSysMsg(s);
}
void cs_securityLayerActivated(int type)
{
appendSysMsg(QString("Security layer activated (%1)").arg((type == XMPP::ClientStream::LayerTLS) ? "TLS": "SASL"));
}
void cs_needAuthParams(bool user, bool pass, bool realm)
{
QString s = "Need auth parameters -";
if(user)
s += " (Username)";
if(pass)
s += " (Password)";
if(realm)
s += " (Realm)";
appendSysMsg(s);
if(user) {
if(!le_user->text().isEmpty())
stream->setUsername(le_user->text());
else
stream->setUsername(jid.node());
}
if(pass) {
if(!le_pass->text().isEmpty())
stream->setPassword(le_pass->text());
else {
conn->changePollInterval(10); // slow down during prompt
bool ok;
QString s = QInputDialog::getText(tr("Password"), tr("Enter the password for %1").arg(jid.full()), QLineEdit::Password, QString::null, &ok, this);
if(!ok) {
stop();
return;
}
stream->setPassword(s);
conn->changePollInterval(2); // resume speed
}
}
if(realm)
stream->setRealm(jid.domain());
stream->continueAfterParams();
}
void cs_authenticated()
{
connected = true;
pb_send->setEnabled(true);
conn->changePollInterval(10); // slow down after login
appendSysMsg("Authenticated");
}
void cs_connectionClosed()
{
appendSysMsg("Disconnected by peer");
cleanup();
}
void cs_delayedCloseFinished()
{
appendSysMsg("Disconnected");
cleanup();
}
void cs_readyRead()
{
while(stream->stanzaAvailable()) {
XMPP::Stanza s = stream->read();
appendXmlIn(XMPP::Stream::xmlToString(s.element(), true));
}
}
void cs_stanzaWritten()
{
appendSysMsg("Stanza sent");
}
void cs_warning(int warn)
{
if(warn == XMPP::ClientStream::WarnOldVersion) {
appendSysMsg("Warning: pre-1.0 protocol server", Qt::red);
}
else if(warn == XMPP::ClientStream::WarnNoTLS) {
appendSysMsg("Warning: TLS not available!", Qt::red);
}
stream->continueAfterWarning();
}
void cs_error(int err)
{
if(err == XMPP::ClientStream::ErrParse) {
appendErrMsg("XML parsing error");
}
else if(err == XMPP::ClientStream::ErrProtocol) {
appendErrMsg("XMPP protocol error");
}
else if(err == XMPP::ClientStream::ErrStream) {
int x = stream->errorCondition();
QString s;
if(x == XMPP::Stream::GenericStreamError)
s = "generic stream error";
else if(x == XMPP::ClientStream::Conflict)
s = "conflict (remote login replacing this one)";
else if(x == XMPP::ClientStream::ConnectionTimeout)
s = "timed out from inactivity";
else if(x == XMPP::ClientStream::InternalServerError)
s = "internal server error";
else if(x == XMPP::ClientStream::InvalidFrom)
s = "invalid from address";
else if(x == XMPP::ClientStream::InvalidXml)
s = "invalid XML";
else if(x == XMPP::ClientStream::PolicyViolation)
s = "policy violation. go to jail!";
else if(x == XMPP::ClientStream::ResourceConstraint)
s = "server out of resources";
else if(x == XMPP::ClientStream::SystemShutdown)
s = "system is shutting down NOW";
appendErrMsg(QString("XMPP stream error: %1").arg(s));
}
else if(err == XMPP::ClientStream::ErrConnection) {
int x = conn->errorCode();
QString s;
if(x == XMPP::AdvancedConnector::ErrConnectionRefused)
s = "unable to connect to server";
else if(x == XMPP::AdvancedConnector::ErrHostNotFound)
s = "host not found";
else if(x == XMPP::AdvancedConnector::ErrProxyConnect)
s = "proxy connect";
else if(x == XMPP::AdvancedConnector::ErrProxyNeg)
s = "proxy negotiating";
else if(x == XMPP::AdvancedConnector::ErrProxyAuth)
s = "proxy authorization";
else if(x == XMPP::AdvancedConnector::ErrStream)
s = "stream error";
appendErrMsg(QString("Connection error: %1").arg(s));
}
else if(err == XMPP::ClientStream::ErrNeg) {
int x = stream->errorCondition();
QString s;
if(x == XMPP::ClientStream::HostGone)
s = "host no longer hosted";
else if(x == XMPP::ClientStream::HostUnknown)
s = "host unknown";
else if(x == XMPP::ClientStream::RemoteConnectionFailed)
s = "a required remote connection failed";
else if(x == XMPP::ClientStream::SeeOtherHost)
s = QString("see other host: [%1]").arg(stream->errorText());
else if(x == XMPP::ClientStream::UnsupportedVersion)
s = "server does not support proper xmpp version";
appendErrMsg(QString("Stream negotiation error: %1").arg(s));
}
else if(err == XMPP::ClientStream::ErrTLS) {
int x = stream->errorCondition();
QString s;
if(x == XMPP::ClientStream::TLSStart)
s = "server rejected STARTTLS";
else if(x == XMPP::ClientStream::TLSFail) {
int t = tlsHandler->tlsError();
if(t == QCA::TLS::ErrorHandshake)
s = "TLS handshake error";
else
s = "broken security layer (TLS)";
}
appendErrMsg(s);
}
else if(err == XMPP::ClientStream::ErrAuth) {
int x = stream->errorCondition();
QString s;
if(x == XMPP::ClientStream::GenericAuthError)
s = "unable to login";
else if(x == XMPP::ClientStream::NoMech)
s = "no appropriate auth mechanism available for given security settings";
else if(x == XMPP::ClientStream::BadProto)
s = "bad server response";
else if(x == XMPP::ClientStream::BadServ)
s = "server failed mutual authentication";
else if(x == XMPP::ClientStream::EncryptionRequired)
s = "encryption required for chosen SASL mechanism";
else if(x == XMPP::ClientStream::InvalidAuthzid)
s = "invalid authzid";
else if(x == XMPP::ClientStream::InvalidMech)
s = "invalid SASL mechanism";
else if(x == XMPP::ClientStream::InvalidRealm)
s = "invalid realm";
else if(x == XMPP::ClientStream::MechTooWeak)
s = "SASL mechanism too weak for authzid";
else if(x == XMPP::ClientStream::NotAuthorized)
s = "not authorized";
else if(x == XMPP::ClientStream::TemporaryAuthFailure)
s = "temporary auth failure";
appendErrMsg(QString("Auth error: %1").arg(s));
}
else if(err == XMPP::ClientStream::ErrSecurityLayer)
appendErrMsg("Broken security layer (SASL)");
cleanup();
}
private:
void setHostState()
{
bool ok = false;
if(!ck_probe->isChecked() && cb_proxy->currentItem() != 3)
ok = true;
lb_host->setEnabled(ok);
le_host->setEnabled(ok);
ck_ssl->setEnabled(ok);
}
void appendSysMsg(const QString &s, const QColor &_c=QColor())
{
QString str;
QColor c;
if(_c.isValid())
c = _c;
else
c = Qt::blue;
if(c.isValid())
str += QString("<font color=\"%1\">").arg(c.name());
str += QString("*** %1").arg(s);
if(c.isValid())
str += QString("</font>");
te_log->append(str);
}
public:
void appendLibMsg(const QString &s)
{
appendSysMsg(s, Qt::magenta);
}
void appendErrMsg(const QString &s)
{
appendSysMsg(s, Qt::red);
}
void appendXmlOut(const QString &s)
{
QStringList lines = QStringList::split('\n', s, true);
QString str;
bool first = true;
for(QStringList::ConstIterator it = lines.begin(); it != lines.end(); ++it) {
if(!first)
str += "<br>";
str += QString("<font color=\"%1\">%2</font>").arg(QColor(Qt::darkGreen).name()).arg(plain2rich(*it));
first = false;
}
te_log->append(str);
}
void appendXmlIn(const QString &s)
{
QStringList lines = QStringList::split('\n', s, true);
QString str;
bool first = true;
for(QStringList::ConstIterator it = lines.begin(); it != lines.end(); ++it) {
if(!first)
str += "<br>";
str += QString("<font color=\"%1\">%2</font>").arg(QColor(Qt::darkBlue).name()).arg(plain2rich(*it));
first = false;
}
te_log->append(str);
}
};
TestDlg *td_glob = 0;
void TestDebug::msg(const QString &s)
{
if(td_glob)
td_glob->appendLibMsg(s);
}
void TestDebug::outgoingTag(const QString &s)
{
if(td_glob)
td_glob->appendXmlOut(s);
}
void TestDebug::incomingTag(const QString &s)
{
if(td_glob)
td_glob->appendXmlIn(s);
}
void TestDebug::outgoingXml(const QDomElement &e)
{
QString out = XMPP::Stream::xmlToString(e, true);
if(td_glob)
td_glob->appendXmlOut(out);
}
void TestDebug::incomingXml(const QDomElement &e)
{
QString out = XMPP::Stream::xmlToString(e, true);
if(td_glob)
td_glob->appendXmlIn(out);
}
#include "xmpptest.moc"
int main(int argc, char **argv)
{
QCA::Initializer init;
#ifdef Q_OS_WIN32
QApplication::addLibraryPath(".");
putenv("SASL_PATH=.\\sasl");
#endif
QApplication app(argc, argv);
// seed the random number generator (needed at least for HttpPoll)
srand(time(NULL));
TestDlg *w = new TestDlg(0);
td_glob = w;
TestDebug *td = new TestDebug;
XMPP::setDebug(td);
QObject::connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
app.exec();
XMPP::setDebug(0);
delete td;
delete w;
// we need this for a clean exit
QCA::unloadAllPlugins();
return 0;
}
#ifdef QCA_STATIC
#include <QtPlugin>
#ifdef HAVE_OPENSSL
Q_IMPORT_PLUGIN(qca_openssl)
#endif
#endif

View file

@ -0,0 +1,41 @@
TEMPLATE = app
CONFIG += thread
CONFIG -= app_bundle
TARGET = xmpptest
QT += xml network qt3support
DEFINES += QT_STATICPLUGIN
MOC_DIR = .moc
OBJECTS_DIR = .obj
UI_DIR = .ui
#DEFINES += CS_XMPP
DEFINES += XMPP_DEBUG
# Dependencies
include(../../../conf.pri)
windows:include(../../../conf_windows.pri)
!qca-static {
CONFIG += crypto
}
qca-static {
# QCA
DEFINES += QCA_STATIC
include(../../../third-party/qca/qca.pri)
# QCA-OpenSSL
contains(DEFINES, HAVE_OPENSSL) {
include(../../../third-party/qca/qca-openssl.pri)
}
}
include(../../../cutestuff/cutestuff.pri)
include(../../iris.pri)
irisnet {
include(../../irisnet/irisnet.pri)
}
SOURCES += xmpptest.cpp
INTERFACES += ui_test.ui