~ubuntu-branches/ubuntu/dapper/psi/dapper

« back to all changes in this revision

Viewing changes to iris/xmpp-core/tlshandler.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2004-06-15 00:10:41 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040615001041-enywb6pcpe4sjsw6
Tags: 0.9.2-1
* New upstream release
* Set KDEDIR for ./configure so kde specific files get installed
* Don't install libpsiwidgets.so. It got installed in /usr/share
  where it doesn't belong. May be included (at a better location)
  later.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * tlshandler.cpp - abstract wrapper for TLS
 
3
 * Copyright (C) 2003  Justin Karneges
 
4
 *
 
5
 * This library is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU Lesser General Public
 
7
 * License as published by the Free Software Foundation; either
 
8
 * version 2.1 of the License, or (at your option) any later version.
 
9
 *
 
10
 * This library is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
 * Lesser General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU Lesser General Public
 
16
 * License along with this library; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 *
 
19
 */
 
20
 
 
21
#include"xmpp.h"
 
22
 
 
23
#include<qtimer.h>
 
24
#include"qca.h"
 
25
 
 
26
using namespace XMPP;
 
27
 
 
28
//----------------------------------------------------------------------------
 
29
// TLSHandler
 
30
//----------------------------------------------------------------------------
 
31
TLSHandler::TLSHandler(QObject *parent)
 
32
:QObject(parent)
 
33
{
 
34
}
 
35
 
 
36
TLSHandler::~TLSHandler()
 
37
{
 
38
}
 
39
 
 
40
 
 
41
//----------------------------------------------------------------------------
 
42
// QCATLSHandler
 
43
//----------------------------------------------------------------------------
 
44
class QCATLSHandler::Private
 
45
{
 
46
public:
 
47
        QCA::TLS *tls;
 
48
        int state, err;
 
49
};
 
50
 
 
51
QCATLSHandler::QCATLSHandler(QCA::TLS *parent)
 
52
:TLSHandler(parent)
 
53
{
 
54
        d = new Private;
 
55
        d->tls = parent;
 
56
        connect(d->tls, SIGNAL(handshaken()), SLOT(tls_handshaken()));
 
57
        connect(d->tls, SIGNAL(readyRead()), SLOT(tls_readyRead()));
 
58
        connect(d->tls, SIGNAL(readyReadOutgoing(int)), SLOT(tls_readyReadOutgoing(int)));
 
59
        connect(d->tls, SIGNAL(closed()), SLOT(tls_closed()));
 
60
        connect(d->tls, SIGNAL(error(int)), SLOT(tls_error(int)));
 
61
        d->state = 0;
 
62
        d->err = -1;
 
63
}
 
64
 
 
65
QCATLSHandler::~QCATLSHandler()
 
66
{
 
67
        delete d;
 
68
}
 
69
 
 
70
QCA::TLS *QCATLSHandler::tls() const
 
71
{
 
72
        return d->tls;
 
73
}
 
74
 
 
75
int QCATLSHandler::tlsError() const
 
76
{
 
77
        return d->err;
 
78
}
 
79
 
 
80
void QCATLSHandler::reset()
 
81
{
 
82
        d->tls->reset();
 
83
        d->state = 0;
 
84
}
 
85
 
 
86
void QCATLSHandler::startClient(const QString &host)
 
87
{
 
88
        d->state = 0;
 
89
        d->err = -1;
 
90
        if(!d->tls->startClient(host))
 
91
                QTimer::singleShot(0, this, SIGNAL(fail()));
 
92
}
 
93
 
 
94
void QCATLSHandler::write(const QByteArray &a)
 
95
{
 
96
        d->tls->write(a);
 
97
}
 
98
 
 
99
void QCATLSHandler::writeIncoming(const QByteArray &a)
 
100
{
 
101
        d->tls->writeIncoming(a);
 
102
}
 
103
 
 
104
void QCATLSHandler::continueAfterHandshake()
 
105
{
 
106
        if(d->state == 2) {
 
107
                success();
 
108
                d->state = 3;
 
109
        }
 
110
}
 
111
 
 
112
void QCATLSHandler::tls_handshaken()
 
113
{
 
114
        d->state = 2;
 
115
        tlsHandshaken();
 
116
}
 
117
 
 
118
void QCATLSHandler::tls_readyRead()
 
119
{
 
120
        readyRead(d->tls->read());
 
121
}
 
122
 
 
123
void QCATLSHandler::tls_readyReadOutgoing(int plainBytes)
 
124
{
 
125
        readyReadOutgoing(d->tls->readOutgoing(), plainBytes);
 
126
}
 
127
 
 
128
void QCATLSHandler::tls_closed()
 
129
{
 
130
        closed();
 
131
}
 
132
 
 
133
void QCATLSHandler::tls_error(int x)
 
134
{
 
135
        d->err = x;
 
136
        d->state = 0;
 
137
        fail();
 
138
}