source: filezilla/trunk/fuentes/src/include/notification.h @ 130

Last change on this file since 130 was 130, checked in by jrpelegrina, 3 years ago

First release to xenial

File size: 12.3 KB
RevLine 
[130]1#ifndef __NOTIFICATION_H__
2#define __NOTIFICATION_H__
3
4// Notification overview
5// ---------------------
6
7// To inform the application about what's happening, the engine sends
8// some notifications to the application using events.
9// For example the event table entry could look like this:
10//     EVT_FZ_NOTIFICATION(wxID_ANY, CMainFrame::OnEngineEvent)
11// and the handler function has the following declaration:
12//     void OnEngineEvent(wxFzEvent& event);
13// You can get the engine which sent the event by reading
14//     event.engine_
15// Whenever you get a notification event,
16// CFileZillaEngine::GetNextNotification has to be called until it returns 0,
17// or you will lose important notifications or your memory will fill with
18// pending notifications.
19
20// A special class of notifications are the asynchronous requests. These
21// requests have to be answered. Once proessed, call
22// CFileZillaEngine::SetAsyncRequestReply to continue the current operation.
23
24#include "local_path.h"
25#include "timeex.h"
26
27class CFileZillaEngine;
28class wxFzEvent final : public wxEvent
29{
30public:
31        wxFzEvent();
32
33        explicit wxFzEvent(int id);
34        explicit wxFzEvent(CFileZillaEngine const* engine);
35
36        virtual wxEvent *Clone() const;
37
38        CFileZillaEngine const* engine_;
39};
40
41wxDECLARE_EVENT(fzEVT_NOTIFICATION, wxFzEvent);
42
43#define EVT_FZ_NOTIFICATION(id, func) \
44        wx__DECLARE_EVT1(fzEVT_NOTIFICATION, id, &func)
45
46enum NotificationId
47{
48        nId_logmsg,                             // notification about new messages for the message log
49        nId_operation,                  // operation reply codes
50        nId_connection,                 // connection information: connects, disconnects, timeouts etc..
51        nId_transferstatus,             // transfer information: bytes transferes, transfer speed and such
52        nId_listing,                    // directory listings
53        nId_asyncrequest,               // asynchronous request
54        nId_active,                             // sent if data gets either received or sent
55        nId_data,                               // for memory downloads, indicates that new data is available.
56        nId_sftp_encryption,    // information about key exchange, encryption algorithms and so on for SFTP
57        nId_local_dir_created   // local directory has been created
58};
59
60// Async request IDs
61enum RequestId
62{
63        reqId_fileexists,               // Target file already exists, awaiting further instructions
64        reqId_interactiveLogin, // gives a challenge prompt for a password
65        reqId_hostkey,                  // used only by SSH/SFTP to indicate new host key
66        reqId_hostkeyChanged,   // used only by SSH/SFTP to indicate changed host key
67        reqId_certificate               // sent after a successful TLS handshake to allow certificate
68                                                        // validation
69};
70
71class CNotification
72{
73public:
74        virtual ~CNotification() {}; // TODO: One GCC >= 4.8 is in Debian Stable (Jessie by then), make default and add testcase to configure.
75        virtual NotificationId GetID() const = 0;
76
77protected:
78        CNotification() = default;
79        CNotification(CNotification const&) = default;
80        CNotification& operator=(CNotification const&) = default;
81};
82
83template<NotificationId id>
84class CNotificationHelper : public CNotification
85{
86public:
87        virtual NotificationId GetID() const final { return id; }
88
89protected:
90        CNotificationHelper<id>() = default;
91        CNotificationHelper<id>(CNotificationHelper<id> const&) = default;
92        CNotificationHelper<id>& operator=(CNotificationHelper<id> const&) = default;
93};
94
95class CLogmsgNotification final : public CNotificationHelper<nId_logmsg>
96{
97public:
98        explicit CLogmsgNotification(MessageType t)
99                : msgType(t)
100        {}
101
102        template<typename String>
103        CLogmsgNotification(MessageType t, String && m)
104                : msg(std::forward<String>(m))
105                , msgType(t)
106        {
107        }
108
109        wxString msg;
110        MessageType msgType{MessageType::Status}; // Type of message, see logging.h for details
111};
112
113// If CFileZillaEngine does return with FZ_REPLY_WOULDBLOCK, you will receive
114// a nId_operation notification once the operation ends.
115class COperationNotification final : public CNotificationHelper<nId_operation>
116{
117public:
118        int nReplyCode{};
119        Command commandId{Command::none};
120};
121
122// You get this type of notification everytime a directory listing has been
123// requested explicitely or when a directory listing was retrieved implicitely
124// during another operation, e.g. file transfers.
125class CDirectoryListing;
126class CDirectoryListingNotification final : public CNotificationHelper<nId_listing>
127{
128public:
129        explicit CDirectoryListingNotification(const CServerPath& path, const bool modified = false, const bool failed = false);
130        bool Modified() const { return m_modified; }
131        bool Failed() const { return m_failed; }
132        const CServerPath GetPath() const { return m_path; }
133
134protected:
135        bool m_modified{};
136        bool m_failed{};
137        CServerPath m_path;
138};
139
140class CAsyncRequestNotification : public CNotificationHelper<nId_asyncrequest>
141{
142public:
143        virtual enum RequestId GetRequestID() const = 0;
144        unsigned int requestNumber{}; // Do never change this
145
146protected:
147        CAsyncRequestNotification() = default;
148        CAsyncRequestNotification(CAsyncRequestNotification const&) = default;
149        CAsyncRequestNotification& operator=(CAsyncRequestNotification const&) = default;
150};
151
152class CFileExistsNotification final : public CAsyncRequestNotification
153{
154public:
155        virtual enum RequestId GetRequestID() const;
156
157        bool download{};
158
159        wxString localFile;
160        int64_t localSize{-1};
161        CDateTime localTime;
162
163        wxString remoteFile;
164        CServerPath remotePath;
165        int64_t remoteSize{-1};
166        CDateTime remoteTime;
167
168        bool ascii{};
169
170        bool canResume{};
171
172        // overwriteAction will be set by the request handler
173        enum OverwriteAction : signed char
174        {
175                unknown = -1,
176                ask,
177                overwrite,
178                overwriteNewer, // Overwrite if source file is newer than target file
179                overwriteSize,  // Overwrite if source file is is different in size than target file
180                overwriteSizeOrNewer,   // Overwrite if source file is different in size or newer than target file
181                resume, // Overwrites if cannot be resumed
182                rename,
183                skip,
184
185                ACTION_COUNT
186        };
187
188        // Set overwriteAction to the desired action
189        OverwriteAction overwriteAction{unknown};
190
191        // Set to new filename if overwriteAction is rename. Might trigger further
192        // file exists notifications if new target file exists as well.
193        wxString newName;
194};
195
196class CInteractiveLoginNotification final : public CAsyncRequestNotification
197{
198public:
199        enum type {
200                interactive,
201                keyfile
202        };
203
204        CInteractiveLoginNotification(type t, const wxString& challenge, bool repeated);
205        virtual enum RequestId GetRequestID() const;
206
207        // Set to true if you have set a password
208        bool passwordSet{};
209
210        // Set password by calling server.SetUser
211        CServer server;
212
213        const wxString& GetChallenge() const { return m_challenge; }
214
215        type GetType() const { return m_type; }
216
217        bool IsRepeated() const { return m_repeated; }
218
219protected:
220        // Password prompt string as given by the server
221        wxString const m_challenge;
222
223        type const m_type;
224
225        bool const m_repeated;
226};
227
228// Indicate network action.
229class CActiveNotification final : public CNotificationHelper<nId_active>
230{
231public:
232        explicit CActiveNotification(int direction);
233
234        int GetDirection() const { return m_direction; }
235protected:
236        const int m_direction;
237};
238
239class CTransferStatus final
240{
241public:
242        CTransferStatus() {}
243        CTransferStatus(wxFileOffset total, wxFileOffset start, bool l)
244                : totalSize(total)
245                , startOffset(start)
246                , currentOffset(start)
247                , list(l)
248        {}
249
250        CDateTime started;
251        wxFileOffset totalSize{-1};             // Total size of the file to transfer, -1 if unknown
252        wxFileOffset startOffset{-1};
253        wxFileOffset currentOffset{-1};
254
255        void clear() { startOffset = -1; }
256        bool empty() const { return startOffset < 0; }
257
258        explicit operator bool() const { return !empty(); }
259
260        // True on download notifications iff currentOffset != startOffset.
261        // True on FTP upload notifications iff currentOffset != startOffset
262        // AND after the first accepted data after the first wxSOCKET_WOULDBLOCK.
263        // SFTP uploads: Set to true if currentOffset >= startOffset + 65536.
264        bool madeProgress{};
265
266        bool list{};
267};
268
269class CTransferStatusNotification final : public CNotificationHelper<nId_transferstatus>
270{
271public:
272        CTransferStatusNotification() {}
273        CTransferStatusNotification(CTransferStatus const& status);
274
275        CTransferStatus const& GetStatus() const;
276
277protected:
278        CTransferStatus const status_;
279};
280
281// Notification about new or changed hostkeys, only used by SSH/SFTP transfers.
282// GetRequestID() returns either reqId_hostkey or reqId_hostkeyChanged
283class CHostKeyNotification final : public CAsyncRequestNotification
284{
285public:
286        CHostKeyNotification(wxString host, int port, wxString fingerprint, bool changed = false);
287        virtual enum RequestId GetRequestID() const;
288
289        wxString GetHost() const;
290        int GetPort() const;
291        wxString GetFingerprint() const;
292
293        // Set to true if you trust the server
294        bool m_trust{};
295
296        // If m_truest is true, set this to true to always trust this server
297        // in future.
298        bool m_alwaysTrust{};
299
300protected:
301
302        const wxString m_host;
303        const int m_port;
304        const wxString m_fingerprint;
305        const bool m_changed;
306};
307
308class CDataNotification final : public CNotificationHelper<nId_data>
309{
310public:
311        CDataNotification(char* pData, int len);
312        virtual ~CDataNotification();
313
314        char* Detach(int& len);
315
316protected:
317        char* m_pData;
318        unsigned int m_len;
319};
320
321class CCertificate final
322{
323public:
324        CCertificate() = default;
325        CCertificate(
326                unsigned char const* rawData, unsigned int len,
327                CDateTime const& activationTime, CDateTime const& expirationTime,
328                wxString const& serial,
329                wxString const& pkalgoname, unsigned int bits,
330                wxString const& signalgoname,
331                wxString const& fingerprint_sha256,
332                wxString const& fingerprint_sha1,
333                wxString const& issuer,
334                wxString const& subject,
335                std::vector<wxString> const& altSubjectNames);
336
337        CCertificate(CCertificate const& op);
338        ~CCertificate();
339
340        const unsigned char* GetRawData(unsigned int& len) const { len = m_len; return m_rawData; }
341        CDateTime GetActivationTime() const { return m_activationTime; }
342        CDateTime GetExpirationTime() const { return m_expirationTime; }
343
344        const wxString& GetSerial() const { return m_serial; }
345        const wxString& GetPkAlgoName() const { return m_pkalgoname; }
346        unsigned int GetPkAlgoBits() const { return m_pkalgobits; }
347
348        const wxString& GetSignatureAlgorithm() const { return m_signalgoname; }
349
350        const wxString& GetFingerPrintSHA256() const { return m_fingerprint_sha256; }
351        const wxString& GetFingerPrintSHA1() const { return m_fingerprint_sha1; }
352
353        const wxString& GetSubject() const { return m_subject; }
354        const wxString& GetIssuer() const { return m_issuer; }
355
356        CCertificate& operator=(CCertificate const& op);
357
358        std::vector<wxString> const& GetAltSubjectNames() const { return m_altSubjectNames; }
359
360private:
361        CDateTime m_activationTime;
362        CDateTime m_expirationTime;
363
364        unsigned char* m_rawData{};
365        unsigned int m_len{};
366
367        wxString m_serial;
368        wxString m_pkalgoname;
369        unsigned int m_pkalgobits{};
370
371        wxString m_signalgoname;
372
373        wxString m_fingerprint_sha256;
374        wxString m_fingerprint_sha1;
375
376        wxString m_issuer;
377        wxString m_subject;
378
379        std::vector<wxString> m_altSubjectNames;
380};
381
382class CCertificateNotification final : public CAsyncRequestNotification
383{
384public:
385        CCertificateNotification(const wxString& host, unsigned int port,
386                const wxString& protocol,
387                const wxString& keyExchange,
388                const wxString& sessionCipher,
389                const wxString& sessionMac,
390                int algorithmWarnings,
391                const std::vector<CCertificate> &certificates);
392        virtual enum RequestId GetRequestID() const { return reqId_certificate; }
393
394        const wxString& GetHost() const { return m_host; }
395        unsigned int GetPort() const { return m_port; }
396
397        const wxString& GetSessionCipher() const { return m_sessionCipher; }
398        const wxString& GetSessionMac() const { return m_sessionMac; }
399
400        bool m_trusted{};
401
402        const std::vector<CCertificate> GetCertificates() const { return m_certificates; }
403
404        const wxString& GetProtocol() const { return m_protocol; }
405        const wxString& GetKeyExchange() const { return m_keyExchange; }
406
407        enum algorithm_warnings_t
408        {
409                tlsver = 1,
410                cipher = 2,
411                mac = 4,
412                kex = 8
413        };
414
415        int GetAlgorithmWarnings() const { return m_algorithmWarnings; }
416
417private:
418        wxString m_host;
419        unsigned int m_port{};
420
421        wxString m_protocol;
422        wxString m_keyExchange;
423        wxString m_sessionCipher;
424        wxString m_sessionMac;
425        int m_algorithmWarnings{};
426
427        std::vector<CCertificate> m_certificates;
428};
429
430class CSftpEncryptionNotification : public CNotificationHelper<nId_sftp_encryption>
431{
432public:
433        wxString hostKey;
434        wxString kexAlgorithm;
435        wxString kexHash;
436        wxString kexCurve;
437        wxString cipherClientToServer;
438        wxString cipherServerToClient;
439        wxString macClientToServer;
440        wxString macServerToClient;
441};
442
443class CLocalDirCreatedNotification : public CNotificationHelper<nId_local_dir_created>
444{
445public:
446        CLocalPath dir;
447};
448
449#endif
Note: See TracBrowser for help on using the repository browser.