Documentation

Generated on Thu Aug 31 00:02:28 2006

 

Connection.h

Go to the documentation of this file.
00001 
00002 // $Id: Connection.h,v 1.19 2005/09/01 20:48:22 klas Exp $
00003 //
00004 // Usage: Connection class. is inherited to user and data.
00005 //
00006 //  A part of babyftpd, licensed under the GNU GPL, see the file
00007 //    LICENSE for complete information.
00009 
00010 #ifndef CONNECTION_H
00011 #define CONNECTION_H
00012 
00013 #ifdef CONNECTION_CPP
00014 #include "generic.h"
00015 #include "Utilities.h"
00016 #include "Configuration.h"
00017 #include "Log.h"
00018 #endif // CONNECTION_CPP
00019 
00020 // for settings()
00021 enum bits { B_SET, B_RESET, B_FLIP };
00022 
00023 enum sets { // for mlsx
00024   FACT_TYPE, FACT_SIZE, FACT_MODIFY, FACT_UNIQUE, FACT_U_MODE, FACT_U_UID,
00025   FACT_U_GID, FACT_U_LINK, FACT_PERM,
00026   DATA_ACCT, BINARY, COMPRESSED, PASSIVE, ANONYMOUS, DATA_OPEN, EPSV_ONLY,
00027   RETR_TRANS, PAM_DONE, FAILURE
00028 #ifdef USE_TLS
00029     , TLS_ENABLED, TLS_INITED, TLS_PBSZ, TLS_PROT_D
00030 #endif // USE_TLS
00031 };
00032 
00033 const int LAST_FACT = 8;
00034 
00035 // keep an eye on these.. different depending on TLS or not...
00036 #ifdef USE_TLS
00037 const int TOTAL_U_BIT = 23;
00038 #else
00039 const int TOTAL_U_BIT = 19;
00040 #endif // USE_TLS
00041 
00042 // macro that builds get and set functions for us.
00043 #define MEMBER(func, type)  private: type _##func; \
00044   public: type func(void){ \
00045             BABY_RDLOCK(this->lock); \
00046             type t = _##func; \
00047             BABY_UNLOCK(this->lock); \
00048             return t;} \
00049   public: void func(type var){ \
00050             BABY_WRLOCK(this->lock); \
00051             this->_##func = var; \
00052             BABY_UNLOCK(this->lock); \
00053           }
00054 
00055 class Connection
00056 {
00057   public:
00058     pthread_rwlock_t lock;
00059     ssize_t send(const char*, size_t);
00060     ssize_t receive(char*, size_t);
00061     Connection &operator<<(long long int num);
00062     Connection &operator<<(string message);
00063 #ifdef USE_TLS
00064     bool engage_tls();
00065     bool disengage_tls();
00066     bool verify_cert();
00067 #endif // USE_TLS
00068     bitset<TOTAL_U_BIT> settings() const
00069     {
00070       return _settings;
00071     }
00072     bool settings(int bit)
00073     {
00074       assert(bit < TOTAL_U_BIT);
00075       BABY_RDLOCK(this->lock);
00076       bool b = this->_settings.test(bit);
00077       BABY_UNLOCK(this->lock);
00078       return(b);
00079     }
00080     void settings(int bit, int way)
00081     {
00082       BABY_WRLOCK(this->lock);
00083       if(way == B_SET)
00084         this->_settings.set(bit);
00085       else if(way == B_RESET)
00086         this->_settings.reset(bit);
00087       else if(way == B_FLIP)
00088         this->_settings.flip(bit);
00089       BABY_UNLOCK(this->lock);
00090     }
00091   protected:
00092     Connection();
00093     ~Connection();
00094     bitset<TOTAL_U_BIT> _settings;
00095     MEMBER(thread_id, pthread_t);
00096     MEMBER(host_name, string);
00097     MEMBER(socket_id, int);
00098     MEMBER(addr, struct sockaddr_in);
00099     MEMBER(packet_size, size_t);
00100     MEMBER(timeout, struct timeval);
00101     MEMBER(user_name, string);
00102     MEMBER(transfered, unsigned long long);
00103   private:
00104 #ifdef USE_TLS
00105     gnutls_session session;
00106 #endif // USE_TLS
00107 };
00108 
00109 const int READ_SIZE = 16384;
00110 
00111 extern vector<pthread_t> cleanup_list;
00112 extern sem_t cleanup_list_lock;
00113 #ifdef USE_TLS
00114 extern gnutls_certificate_credentials x509_cred;
00115 extern int tls_db_store(void*, gnutls_datum, gnutls_datum);
00116 extern gnutls_datum tls_db_fetch(void*, gnutls_datum);
00117 extern int tls_db_delete(void*, gnutls_datum);
00118 #endif // USE_TLS
00119 
00120 #endif // CONNECTION_H