~ubuntu-branches/ubuntu/saucy/kopete/saucy-proposed

« back to all changes in this revision

Viewing changes to protocols/groupwise/libgroupwise/qcatlshandler.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-06-21 02:22:39 UTC
  • Revision ID: package-import@ubuntu.com-20130621022239-63l3zc8p0nf26pt6
Tags: upstream-4.10.80
ImportĀ upstreamĀ versionĀ 4.10.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    qcatlshandler.cpp - Kopete Groupwise Protocol
 
3
  
 
4
    Copyright (c) 2006      Novell, Inc                  http://www.opensuse.org
 
5
    Copyright (c) 2004      SUSE Linux AG                http://www.suse.com
 
6
    
 
7
    Based on Iris, Copyright (C) 2003  Justin Karneges <justin@affinix.com>
 
8
    
 
9
    Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org>
 
10
 
 
11
    *************************************************************************
 
12
    *                                                                       *
 
13
    * This library is free software; you can redistribute it and/or         *
 
14
    * modify it under the terms of the GNU Lesser General Public            *
 
15
    * License as published by the Free Software Foundation; either          *
 
16
    * version 2 of the License, or (at your option) any later version.      *
 
17
    *                                                                       *
 
18
    *************************************************************************
 
19
*/
 
20
 
 
21
#include <qtimer.h>
 
22
 
 
23
#include <QtCrypto>
 
24
 
 
25
#include "qcatlshandler.h"
 
26
 
 
27
class QCATLSHandler::Private
 
28
{
 
29
public:
 
30
        QCA::TLS *tls;
 
31
        int state, err;
 
32
};
 
33
 
 
34
QCATLSHandler::QCATLSHandler(QCA::TLS *parent)
 
35
:TLSHandler(parent), d(new Private())
 
36
{
 
37
        d->tls = parent;
 
38
        connect(d->tls, SIGNAL(handshaken()), SLOT(tls_handshaken()));
 
39
        connect(d->tls, SIGNAL(readyRead()), SLOT(tls_readyRead()));
 
40
        connect(d->tls, SIGNAL(readyReadOutgoing()), SLOT(tls_readyReadOutgoing()));
 
41
        connect(d->tls, SIGNAL(closed()), SLOT(tls_closed()));
 
42
        connect(d->tls, SIGNAL(error()), SLOT(tls_error()));
 
43
        d->state = 0;
 
44
        d->err = -1;
 
45
}
 
46
 
 
47
QCATLSHandler::~QCATLSHandler()
 
48
{
 
49
        delete d;
 
50
}
 
51
 
 
52
QCA::TLS *QCATLSHandler::tls() const
 
53
{
 
54
        return d->tls;
 
55
}
 
56
 
 
57
int QCATLSHandler::tlsError() const
 
58
{
 
59
        return d->err;
 
60
}
 
61
 
 
62
void QCATLSHandler::reset()
 
63
{
 
64
        d->tls->reset();
 
65
        d->state = 0;
 
66
}
 
67
 
 
68
void QCATLSHandler::startClient(const QString &host)
 
69
{
 
70
        d->state = 0;
 
71
        d->err = -1;
 
72
        d->tls->startClient(host);
 
73
}
 
74
 
 
75
void QCATLSHandler::write(const QByteArray &a)
 
76
{
 
77
        d->tls->write(a);
 
78
}
 
79
 
 
80
void QCATLSHandler::writeIncoming(const QByteArray &a)
 
81
{
 
82
        d->tls->writeIncoming(a);
 
83
}
 
84
 
 
85
void QCATLSHandler::continueAfterHandshake()
 
86
{
 
87
        if(d->state == 2) {
 
88
                d->tls->continueAfterStep();
 
89
                success();
 
90
                d->state = 3;
 
91
        }
 
92
}
 
93
 
 
94
void QCATLSHandler::tls_handshaken()
 
95
{
 
96
        d->state = 2;
 
97
        tlsHandshaken();
 
98
}
 
99
 
 
100
void QCATLSHandler::tls_readyRead()
 
101
{
 
102
        readyRead(d->tls->read());
 
103
}
 
104
 
 
105
void QCATLSHandler::tls_readyReadOutgoing()
 
106
{
 
107
        int plainBytes;
 
108
        QByteArray buf = d->tls->readOutgoing(&plainBytes);
 
109
        readyReadOutgoing(buf, plainBytes);
 
110
}
 
111
 
 
112
void QCATLSHandler::tls_closed()
 
113
{
 
114
        closed();
 
115
}
 
116
 
 
117
void QCATLSHandler::tls_error()
 
118
{
 
119
        d->err = d->tls->errorCode();
 
120
        d->state = 0;
 
121
        fail();
 
122
}
 
123
 
 
124
#include "qcatlshandler.moc"