1 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net>
3 This file is part of the Trojita Qt IMAP e-mail client,
4 http://trojita.flaska.net/
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of
9 the License or (at your option) version 3 or any later version
10 accepted by the membership of KDE e.V. (or its successor approved
11 by the membership of KDE e.V.), which shall act as a proxy
12 defined in Section 14 of version 3 of the license.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #ifndef STREAMS_SOCKETFACTORY_H
24 #define STREAMS_SOCKETFACTORY_H
27 #include <QStringList>
32 /** @short Specify preference for Proxy Settings */
33 enum class ProxySettings
35 RespectSystemProxy
, /**< @short Use System Proxy Settings to connect */
36 DirectConnect
, /**< @short Connect without using any Proxy Settings */
39 /** @short Abstract interface for creating new socket that is somehow connected
40 * to the IMAP server */
41 class SocketFactory
: public QObject
47 virtual ~SocketFactory() {}
48 /** @short Create new socket and return a smart pointer to it */
49 virtual Socket
*create() = 0;
50 virtual void setProxySettings(const Streams::ProxySettings proxySettings
, const QString
&protocolTag
) = 0;
51 void setStartTlsRequired(const bool doIt
);
52 bool startTlsRequired();
54 void error(const QString
&);
57 /** @short Manufacture sockets based on QProcess */
58 class ProcessSocketFactory
: public SocketFactory
61 /** @short Name of executable file to launch */
63 /** @short Arguments to launch the process with */
66 ProcessSocketFactory(const QString
&executable
, const QStringList
&args
);
67 virtual Socket
*create();
68 virtual void setProxySettings(const Streams::ProxySettings proxySettings
, const QString
&protocolTag
);
71 /** @short Manufacture sockets based on QSslSocket */
72 class SslSocketFactory
: public SocketFactory
75 /** @short Hostname of the remote host */
77 /** @short Port number */
79 /** @short Specify Proxy Settings for connection */
80 ProxySettings m_proxySettings
;
81 /** @short Protocol for the requested connection */
82 QString m_protocolTag
;
84 SslSocketFactory(const QString
&host
, const quint16 port
);
85 virtual void setProxySettings(const Streams::ProxySettings proxySettings
, const QString
&protocolTag
);
86 virtual Socket
*create();
89 /** @short Factory for regular TCP sockets that are able to STARTTLS */
90 class TlsAbleSocketFactory
: public SocketFactory
93 /** @short Hostname of the remote host */
95 /** @short Port number */
97 /** @short Specify Proxy Settings for connection */
98 ProxySettings m_proxySettings
;
99 /** @short Protocol for the requested connection */
100 QString m_protocolTag
;
102 TlsAbleSocketFactory(const QString
&host
, const quint16 port
);
103 virtual void setProxySettings(const Streams::ProxySettings proxySettings
, const QString
&protocolTag
);
104 virtual Socket
*create();
107 /** @short A fake factory suitable for unit tests */
108 class FakeSocketFactory
: public SocketFactory
112 explicit FakeSocketFactory(const Imap::ConnectionState initialState
);
113 virtual Socket
*create();
114 /** @short Return the last created socket */
115 Socket
*lastSocket();
116 void setInitialState(const Imap::ConnectionState initialState
);
117 virtual void setProxySettings(const Streams::ProxySettings proxySettings
, const QString
&protocolTag
);
120 QPointer
<Socket
> m_last
;
121 Imap::ConnectionState m_initialState
;