forked from uroni/urbackup_backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OpenSSLPipe.h
72 lines (44 loc) · 1.58 KB
/
OpenSSLPipe.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#pragma once
#ifdef WITH_OPENSSL
#include <openssl/opensslv.h>
#if OPENSSL_VERSION_NUMBER < 0x10002000L
#warning "OpenSSL version too old (<1.0.2). Not supported. Compiling without OpenSSL"
#undef WITH_OPENSSL
#endif
#endif //WITH_OPENSSL
#ifdef WITH_OPENSSL
#include "Interface/Pipe.h"
#include "StreamPipe.h"
#include <memory>
#include <openssl/bio.h>
class OpenSSLPipe : public IPipe
{
public:
OpenSSLPipe(CStreamPipe* bpipe);
~OpenSSLPipe();
static void init();
bool ssl_connect(const std::string& p_hostname, int timeoutms);
// Inherited via IPipe
virtual size_t Read(char * buffer, size_t bsize, int timeoutms = -1);
virtual bool Write(const char * buffer, size_t bsize, int timeoutms = -1, bool flush = true);
virtual size_t Read(std::string * ret, int timeoutms = -1);
virtual bool Write(const std::string & str, int timeoutms = -1, bool flush = true);
virtual bool Flush(int timeoutms = -1);
virtual bool isWritable(int timeoutms = 0);
virtual bool isReadable(int timeoutms = 0);
virtual bool hasError(void);
virtual void shutdown(void);
virtual size_t getNumWaiters();
virtual size_t getNumElements(void);
virtual void addThrottler(IPipeThrottler * throttler);
virtual void addOutgoingThrottler(IPipeThrottler * throttler);
virtual void addIncomingThrottler(IPipeThrottler * throttler);
virtual _i64 getTransferedBytes(void);
virtual void resetTransferedBytes(void);
private:
std::unique_ptr<CStreamPipe> bpipe;
BIO* bbio;
SSL_CTX* ctx;
bool has_error;
};
#endif //WITH_OPENSSL