diff options
author | Julian Andres Klode <jak@debian.org> | 2017-06-28 19:15:41 +0200 |
---|---|---|
committer | Julian Andres Klode <jak@debian.org> | 2017-06-28 19:15:41 +0200 |
commit | 11c3624ce3575076ca52350f66d4bd2e63db5d73 (patch) | |
tree | 5bdd7020c8d42e9bb502fb0bbb4c3dc85450d446 /methods/connect.h | |
parent | 930e2df52dc637039c1845905d79ce525faeb8ca (diff) | |
parent | 147ac0fc90d972a11f5e91521ba3d385015b5945 (diff) |
Merge branch 'feature/http-https'
Diffstat (limited to 'methods/connect.h')
-rw-r--r-- | methods/connect.h | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/methods/connect.h b/methods/connect.h index bbe1bb35d..4456d660d 100644 --- a/methods/connect.h +++ b/methods/connect.h @@ -10,12 +10,41 @@ #ifndef CONNECT_H #define CONNECT_H +#include <memory> +#include <stddef.h> #include <string> -class pkgAcqMethod; +class aptMethod; + +/** + * \brief Small representation of a file descriptor for network traffic. + * + * This provides support for TLS, SOCKS, and HTTP CONNECT proxies. + */ +struct MethodFd +{ + /// \brief Returns -1 for unusable, or an fd to select() on otherwise + virtual int Fd() = 0; + /// \brief Should behave like read(2) + virtual ssize_t Read(void *buf, size_t count) = 0; + /// \brief Should behave like write(2) + virtual ssize_t Write(void *buf, size_t count) = 0; + /// \brief Closes the file descriptor. Can be called multiple times. + virtual int Close() = 0; + /// \brief Destructor + virtual ~MethodFd(){}; + /// \brief Construct a MethodFd from a UNIX file descriptor + static std::unique_ptr<MethodFd> FromFd(int iFd); + /// \brief If there is pending data. + virtual bool HasPending(); +}; + +bool Connect(std::string To, int Port, const char *Service, int DefPort, + std::unique_ptr<MethodFd> &Fd, unsigned long TimeOut, aptMethod *Owner); + +bool UnwrapSocks(std::string To, int Port, URI Proxy, std::unique_ptr<MethodFd> &Fd, unsigned long Timeout, aptMethod *Owner); +bool UnwrapTLS(std::string To, std::unique_ptr<MethodFd> &Fd, unsigned long Timeout, aptMethod *Owner); -bool Connect(std::string To,int Port,const char *Service,int DefPort, - int &Fd,unsigned long TimeOut,pkgAcqMethod *Owner); void RotateDNS(); #endif |