"Fossies" - the Fresh Open Source Software Archive

Member "postal-0.76/basictcp.h" (26 May 2008, 2260 Bytes) of package /linux/privat/postal-0.76.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "basictcp.h" see the Fossies "Dox" file reference documentation.

    1 #ifndef BASE_TCP_H
    2 #define BASE_TCP_H
    3 
    4 using namespace std;
    5 #include "postal.h"
    6 #include <sys/poll.h>
    7 #include <string>
    8 #include <cstring>
    9 #include <sys/types.h>
   10 #include <netinet/in.h>
   11 
   12 class Logit;
   13 class address;
   14 
   15 #ifdef USE_SSL
   16 #ifdef USE_OPENSSL
   17 #ifndef TCP_BODY
   18 struct SSL_METHOD;
   19 struct SSL_CTX;
   20 struct SSL;
   21 struct X509;
   22 #else // TCP_BODY
   23 #include <openssl/crypto.h>
   24 #include <openssl/x509.h>
   25 #include <openssl/pem.h>
   26 #include <openssl/ssl.h>
   27 #include <openssl/err.h>
   28 #endif // TCP_BODY
   29 #else // USE_OPENSSL
   30 #include <gnutls/gnutls.h>
   31 #endif // USE_OPENSSL
   32 #endif
   33 
   34 class results;
   35 
   36 class base_tcp
   37 {
   38 public:
   39   base_tcp(int fd, Logit *log, Logit *debug, results *res
   40 #ifdef USE_SSL
   41     , int ssl
   42 #endif
   43   );
   44   virtual ~base_tcp();
   45 
   46   int do_stuff();
   47 
   48   int disconnect();
   49 #ifdef USE_SSL
   50   // after calling Connect() and getting high-level protocol ready call
   51   // ConnectTLS() to start TLS.
   52   int ConnectTLS();
   53   int isTLS() { return m_isTLS; }
   54 #endif
   55 
   56   // returns negative error or the number of bytes read
   57   int readLine(char *buf, int bufSize, bool stripCR = false, int timeout = 60);
   58 
   59   ERROR_TYPE sendData(CPCCHAR buf, int size);
   60   ERROR_TYPE sendCstr(CPCCHAR buf) { return sendData(buf, strlen(buf)); }
   61   ERROR_TYPE sendString(const string &s) { return sendData(s.c_str(), s.size()); }
   62   ERROR_TYPE printf(CPCCHAR fmt, ...);
   63 
   64 protected:
   65 
   66   struct sockaddr_in m_localAddr, m_remoteAddr;
   67 #ifdef USE_SSL
   68   bool m_canTLS;
   69   int m_useTLS;
   70 #endif
   71 
   72   void sentData(int bytes);
   73   virtual void receivedData(int bytes);
   74 
   75 private:
   76   int m_sock;
   77   pollfd m_poll;
   78   char m_buf[4096];
   79   int m_start;
   80   int m_end;
   81   bool m_open;
   82   Logit *m_log;
   83   // debug file management object (NULL if no debugging)
   84   // if used a new Logit object is created for each instance unlike the
   85   // m_log instance
   86   Logit *m_debug;
   87 
   88   results *m_res;
   89 
   90 #ifdef USE_SSL
   91 #ifdef USE_OPENSSL
   92   SSL_METHOD *m_sslMeth;
   93   SSL_CTX* m_sslCtx;
   94   SSL *m_ssl;
   95 #else
   96   gnutls_session_t m_gnutls_session;
   97   gnutls_anon_server_credentials_t m_anoncred;
   98   void m_generate_dh_params();
   99   void m_initialize_tls_session();
  100   static gnutls_dh_params_t m_dh_params;
  101   static int m_init_dh_params;
  102 #endif
  103   bool m_isTLS;
  104 #endif
  105 
  106   base_tcp(const base_tcp&);
  107   base_tcp & operator=(const base_tcp&);
  108 };
  109 
  110 #endif