Changeset 1185:b4fcbc44f0db


Ignore:
Timestamp:
03/17/09 09:27:52 (3 years ago)
Author:
niam
Branch:
default
Message:

cleaned up headers in io::network::ssl and io::ssl

Location:
trunk
Files:
16 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/include/libdodo/cgiFastExchange.h

    r1179 r1185  
    3535#ifdef FASTCGI_EXT 
    3636#include <libdodo/types.h> 
     37#include <libdodo/cgiExchange.h> 
    3738 
    3839namespace dodo 
     
    4041        namespace cgi 
    4142        { 
    42                 class exchange; 
    43  
    4443                namespace fast 
    4544                { 
  • trunk/include/libdodo/ioNetwork.h

    r1080 r1185  
    3333#include <libdodo/ioNetworkClient.h> 
    3434#include <libdodo/ioNetworkServer.h> 
     35#include <libdodo/ioNetworkExchange.h> 
    3536 
    3637#endif 
  • trunk/include/libdodo/ioNetworkServer.h

    r1164 r1185  
    3333#include <libdodo/directives.h> 
    3434 
    35 #include <sys/types.h> 
    36 #include <sys/stat.h> 
    37 #include <netinet/in.h> 
    38 #include <arpa/inet.h> 
    39 #include <netdb.h> 
    40 #include <sys/un.h> 
    41 #include <sys/socket.h> 
    42 #include <net/if.h> 
    43 #include <sys/ioctl.h> 
    44 #include <fcntl.h> 
    45  
    46 #include <libdodo/toolsFilesystem.h> 
    47 #include <libdodo/ioNetworkServerEx.h> 
    4835#include <libdodo/types.h> 
    4936#include <libdodo/ioNetworkConnection.h> 
    50 #include <libdodo/ioNetworkExchange.h> 
    5137#include <libdodo/xexec.h> 
    5238#include <libdodo/ioEventInfo.h> 
     
    6349                        }; 
    6450 
     51                        class __initialAccept; 
     52 
    6553                        /** 
    6654                         * @enum serverOperationTypeEnum defines type of operation for hook 
     
    7765 
    7866#ifndef IO_WO_XEXEC 
    79  
    8067                        /** 
    8168                         * @class __xexecIoNetworkServerCollectedData 
     
    9380                                __xexecIoNetworkServerCollectedData(xexec *executor, short execObject); 
    9481                        }; 
    95  
    9682#endif 
    9783 
     
    205191 
    206192#ifndef IO_WO_XEXEC 
    207  
    208193                                __xexecIoNetworkServerCollectedData collectedData;  ///< data collected for xexec 
    209  
    210194#endif 
    211195                        }; 
  • trunk/include/libdodo/ioNetworkSslClient.h

    r1164 r1185  
    3434 
    3535#ifdef OPENSSL_EXT 
    36  
    37 #include <sys/types.h> 
    38 #include <sys/stat.h> 
    39 #include <netinet/in.h> 
    40 #include <arpa/inet.h> 
    41 #include <netdb.h> 
    42 #include <sys/un.h> 
    43 #include <sys/socket.h> 
    44 #include <net/if.h> 
    45 #include <sys/ioctl.h> 
    46 #include <fcntl.h> 
    47 #include <openssl/ssl.h> 
    48  
    49 #include <libdodo/toolsFilesystem.h> 
    50 #include <libdodo/ioNetworkSslClientEx.h> 
    5136#include <libdodo/ioNetworkClient.h> 
    52 #include <libdodo/ioSsl.h> 
    5337#include <libdodo/types.h> 
    54 #include <libdodo/ioNetworkSslExchange.h> 
    55 #include <libdodo/xexec.h> 
    56 #include <libdodo/ioEventInfo.h> 
    5738 
    5839namespace dodo 
     
    6243                namespace network 
    6344                { 
     45                        class http; 
     46                }; 
     47 
     48                namespace ssl 
     49                { 
     50                        struct __sslHandle; 
     51                        struct __sslContext; 
     52                        struct __certificates; 
     53                }; 
     54 
     55                namespace network 
     56                { 
    6457                        namespace ssl 
    6558                        { 
     59                                class exchange; 
     60 
    6661                                /** 
    6762                                 * @class client 
     
    149144                                        virtual void connectSsl(); 
    150145 
    151                                         SSL_CTX *sslCtx;    ///< SSL context 
    152                                         SSL *sslHandle;     ///< SSL connection handle 
     146                                        io::ssl::__sslHandle *handle; ///< ssl connection handle 
     147                                        io::ssl::__sslContext *ctx; ///< ssl connection context 
    153148 
    154149                                        bool sslConnected;  ///< true if SSL connection established 
     
    158153        }; 
    159154}; 
    160  
    161155#endif 
    162156 
  • trunk/include/libdodo/ioNetworkSslExchange.h

    r1166 r1185  
    3434 
    3535#ifdef OPENSSL_EXT 
    36  
    37 #include <sys/types.h> 
    38 #include <netinet/in.h> 
    39 #include <arpa/inet.h> 
    40 #include <netdb.h> 
    41 #include <sys/un.h> 
    42 #include <sys/socket.h> 
    43 #include <net/if.h> 
    44 #include <sys/ioctl.h> 
    45 #include <fcntl.h> 
    46 #include <poll.h> 
    47 #include <openssl/ssl.h> 
    48  
    49 #include <libdodo/ioChannel.h> 
    50 #include <libdodo/ioNetworkSslExchangeEx.h> 
    5136#include <libdodo/ioNetworkExchange.h> 
    52 #include <libdodo/ioSsl.h> 
    5337#include <libdodo/types.h> 
    54 #include <libdodo/xexec.h> 
    5538 
    5639namespace dodo 
     
    6447                        namespace ssl 
    6548                        { 
     49                                struct __sslHandle; 
     50 
    6651                                /** 
    6752                                 * @class __initialAccept 
     
    8772                                        __initialAccept(__initialAccept &init); 
    8873 
     74                                        /** 
     75                                         * destructor 
     76                                         */ 
     77                                        ~__initialAccept(); 
     78 
    8979                                  private: 
    9080 
    9181                                        int socket;             ///< socket 
    9282 
    93                                         SSL *sslHandle;         ///< SSL connection handle 
     83                                        io::ssl::__sslHandle *handle;         ///< SSL connection handle 
    9484 
    9585                                        bool blocked;           ///< true if blocked 
     
    154144                                  protected: 
    155145 
    156                                         SSL *sslHandle; ///< SSL connection handle 
     146                                        io::ssl::__sslHandle *handle; ///< SSL connection handle 
    157147 
    158148                                        /** 
     
    162152                                         */ 
    163153                                        virtual void _close(int socket, 
    164                                                                                 SSL *sslHandle); 
     154                                                                                io::ssl::__sslHandle *handle); 
    165155 
    166156                                        /** 
     
    172162                                         */ 
    173163                                        virtual void init(int  socket, 
    174                                                                           SSL  *handle, 
     164                                                                          io::ssl::__sslHandle  *handle, 
    175165                                                                          bool blocked, 
    176166                                                                          bool blockInherited); 
     
    198188        }; 
    199189}; 
    200  
    201190#endif 
    202191 
  • trunk/include/libdodo/ioNetworkSslServer.h

    r1164 r1185  
    3434 
    3535#ifdef OPENSSL_EXT 
    36  
    37 #include <sys/types.h> 
    38 #include <sys/stat.h> 
    39 #include <netinet/in.h> 
    40 #include <arpa/inet.h> 
    41 #include <netdb.h> 
    42 #include <sys/un.h> 
    43 #include <sys/socket.h> 
    44 #include <net/if.h> 
    45 #include <sys/ioctl.h> 
    46 #include <fcntl.h> 
    47 #include <openssl/ssl.h> 
    48  
    49 #include <libdodo/toolsFilesystem.h> 
    50 #include <libdodo/ioNetworkSslServerEx.h> 
    5136#include <libdodo/ioNetworkServer.h> 
    52 #include <libdodo/ioSsl.h> 
    5337#include <libdodo/types.h> 
    54 #include <libdodo/ioNetworkSslExchange.h> 
    55 #include <libdodo/xexec.h> 
    56 #include <libdodo/ioEventInfo.h> 
    5738 
    5839namespace dodo 
     
    6041        namespace io 
    6142        { 
     43                namespace ssl 
     44                { 
     45                        struct __sslContext; 
     46                        struct __certificates; 
     47                }; 
     48 
    6249                namespace network 
    6350                { 
    6451                        namespace ssl 
    6552                        { 
     53                                class exchange; 
     54                                class __initialAccept; 
     55 
    6656                                /** 
    6757                                 * @class server 
     
    161151                                        virtual void acceptSsl(__initialAccept &init); 
    162152 
    163                                         SSL_CTX *sslCtx; ///< SSL context 
     153                                        io::ssl::__sslContext *ctx; ///< SSL context 
    164154                                }; 
    165155                        }; 
     
    167157        }; 
    168158}; 
    169  
    170159#endif 
    171160 
  • trunk/include/libdodo/ioSsl.h

    r1160 r1185  
    3434 
    3535#ifdef OPENSSL_EXT 
    36  
    37 #include <openssl/ssl.h> 
    38 #include <openssl/err.h> 
    39 #include <openssl/rand.h> 
    40 #include <sys/types.h> 
    41 #include <sys/stat.h> 
    42 #include <unistd.h> 
    43 #include <sys/time.h> 
    44  
    45 #include <libdodo/toolsMisc.h> 
     36#include <libdodo/types.h> 
    4637 
    4738namespace dodo 
     
    5142                namespace ssl 
    5243                { 
     44                        /** 
     45                         * @struct __sslHandle 
     46                         * @brief defines internal handlers for SSL 
     47                         */ 
     48                        struct __sslHandle; 
     49 
     50                        /** 
     51                         * @struct __sslContext 
     52                         * @brief defines internal context for SSL 
     53                         */ 
     54                        struct __sslContext; 
     55 
    5356                        enum keyTypeEnum 
    5457                        { 
     
    9093                                dodoString cipher;      ///< allowed SSL ciphers 
    9194                        }; 
    92  
    93                         /** 
    94                          * @class __openssl_init__ 
    95                          * @brief initializes openssl evironment 
    96                          */ 
    97                         class __openssl_init__ 
    98                         { 
    99                           public: 
    100  
    101                                 /** 
    102                                  * contructor 
    103                                  */ 
    104                                 __openssl_init__(); 
    105  
    106                                 /** 
    107                                  * destructor 
    108                                  */ 
    109                                 ~__openssl_init__(); 
    110  
    111                                 /** 
    112                                  * add entropy for randomness 
    113                                  */ 
    114                                 void addEntropy(); 
    115                         }; 
    116  
    117                         extern __openssl_init__ __openssl_init_object__; 
    11895                }; 
    11996        }; 
    12097}; 
    121  
    122  
    12398#endif 
    12499 
  • trunk/include/libdodo/pcProcessCollection.h

    r1160 r1185  
    3131#define _PCPROCESSCOLLECTION_H_ 1 
    3232 
     33#include <libdodo/directives.h> 
     34 
    3335#ifdef DL_EXT 
    3436 
     
    4244#include <sys/wait.h> 
    4345 
    44 #include <libdodo/directives.h> 
    4546#include <libdodo/types.h> 
    4647#include <libdodo/pcJobCollection.h> 
  • trunk/src/graphicsImage.inline

    r1181 r1185  
    4848        }; 
    4949}; 
    50  
    5150#endif 
    5251 
  • trunk/src/ioNetworkHttp.cc

    r1183 r1185  
    3434#include <sys/stat.h> 
    3535 
     36#include "ioSsl.inline" 
     37 
    3638#include <libdodo/ioNetworkHttp.h> 
    3739#include <libdodo/toolsCode.h> 
     40#include <libdodo/toolsFilesystem.h> 
    3841#include <libdodo/ioNetworkClient.h> 
    3942#include <libdodo/ioNetworkSslClient.h> 
     
    4144#include <libdodo/ioNetworkHttpEx.h> 
    4245#include <libdodo/ioNetworkClientEx.h> 
     46#include <libdodo/ioNetworkSslClientEx.h> 
    4347#include <libdodo/ioNetworkExchangeEx.h> 
     48#include <libdodo/ioNetworkSslExchangeEx.h> 
     49#include <libdodo/ioNetworkSslExchange.h> 
    4450#include <libdodo/types.h> 
    4551#include <libdodo/cgi.h> 
     
    416422                        ((ssl::client *)net)->connectSsl(); 
    417423 
    418                         ((ssl::exchange *)ex)->sslHandle = ((ssl::client *)net)->sslHandle; 
     424                        ((ssl::exchange *)ex)->handle->handle = ((ssl::client *)net)->handle->handle; 
    419425 
    420426                        ((ssl::client *)net)->socket = -1; 
    421                         ((ssl::client *)net)->sslHandle = NULL; 
     427                        ((ssl::client *)net)->handle->handle = NULL; 
    422428                } 
    423429#endif 
     
    932938                        ((ssl::client *)net)->connectSsl(); 
    933939 
    934                         ((ssl::exchange *)ex)->sslHandle = ((ssl::client *)net)->sslHandle; 
     940                        ((ssl::exchange *)ex)->handle->handle = ((ssl::client *)net)->handle->handle; 
    935941 
    936942                        ((ssl::client *)net)->socket = -1; 
    937                         ((ssl::client *)net)->sslHandle = NULL; 
     943                        ((ssl::client *)net)->handle->handle = NULL; 
    938944                } 
    939945 
  • trunk/src/ioNetworkServer.cc

    r1166 r1185  
    2828 */ 
    2929 
     30#include <libdodo/directives.h> 
     31 
     32#include <arpa/inet.h> 
     33#include <sys/un.h> 
     34#include <fcntl.h> 
     35 
    3036#include <libdodo/ioNetworkServer.h> 
     37#include <libdodo/ioNetworkServerEx.h> 
     38#include <libdodo/types.h> 
     39#include <libdodo/ioNetworkConnection.h> 
     40#include <libdodo/ioNetworkExchange.h> 
     41#include <libdodo/xexec.h> 
     42#include <libdodo/ioEventInfo.h> 
    3143 
    3244using namespace dodo::io::network; 
    3345 
    3446#ifndef IO_WO_XEXEC 
    35  
    3647__xexecIoNetworkServerCollectedData::__xexecIoNetworkServerCollectedData(xexec *a_executor, 
    3748                                                                                                                                                 short execObject) : __xexecCollectedData(a_executor, execObject) 
    3849{ 
    3950} 
    40  
    4151#endif 
    4252 
     
    4454 
    4555server::server(server &fs) 
    46  
    47 #ifndef IO_WO_XEXEC 
    48  
     56#ifndef IO_WO_XEXE 
    4957        : collectedData(this, XEXEC_OBJECT_IONETWORKSERVER) 
    50  
    5158#endif 
    5259{ 
     
    6067                                                           blockInherited(false) 
    6168#ifndef IO_WO_XEXEC 
    62  
    6369                                                           , 
    6470                                                           collectedData(this, XEXEC_OBJECT_IONETWORKSERVER) 
    65  
    6671#endif 
    6772{ 
  • trunk/src/ioNetworkSslClient.cc

    r1166 r1185  
    2828 */ 
    2929 
     30#include <libdodo/directives.h> 
     31 
     32#ifdef OPENSSL_EXT 
     33#include <sys/socket.h> 
     34#include <sys/un.h> 
     35#include <arpa/inet.h> 
     36#include <openssl/ssl.h> 
     37#include <openssl/err.h> 
     38 
     39#include "ioSsl.inline" 
     40 
    3041#include <libdodo/ioNetworkSslClient.h> 
    31  
    32 #ifdef OPENSSL_EXT 
     42#include <libdodo/toolsFilesystem.h> 
     43#include <libdodo/ioNetworkSslClientEx.h> 
     44#include <libdodo/ioSsl.h> 
     45#include <libdodo/types.h> 
     46#include <libdodo/ioNetworkSslExchange.h> 
     47#include <libdodo/xexec.h> 
     48#include <libdodo/ioEventInfo.h> 
    3349 
    3450using namespace dodo::io::network::ssl; 
     
    4359                           short a_type) : network::client(a_family, 
    4460                                                                                           a_type), 
    45                                                            sslCtx(NULL), 
    46                                                            sslHandle(NULL), 
    47                                                            sslConnected(false) 
     61                                                           sslConnected(false), 
     62                                                           handle(new io::ssl::__sslHandle), 
     63                                                           ctx(new io::ssl::__sslContext) 
    4864{ 
    4965#ifndef IO_WO_XEXEC 
    50  
    5166        collectedData.setExecObject(XEXEC_OBJECT_IONETWORKSSLCLIENT); 
    52  
    53 #endif 
     67#endif 
     68 
     69        ctx->ctx = NULL; 
     70        handle->handle = NULL; 
    5471} 
    5572 
     
    5875client::~client() 
    5976{ 
    60         if (sslHandle != NULL) 
    61         { 
    62                 if (sslConnected && SSL_shutdown(sslHandle) == 0) 
    63                 { 
    64                         SSL_shutdown(sslHandle); 
    65                 } 
    66  
    67                 SSL_free(sslHandle); 
    68         } 
    69  
    70         if (sslCtx != NULL) 
    71         { 
    72                 SSL_CTX_free(sslCtx); 
    73         } 
     77        if (handle->handle != NULL) 
     78        { 
     79                if (sslConnected && SSL_shutdown(handle->handle) == 0) 
     80                { 
     81                        SSL_shutdown(handle->handle); 
     82                } 
     83 
     84                SSL_free(handle->handle); 
     85        } 
     86 
     87        if (ctx->ctx != NULL) 
     88        { 
     89                SSL_CTX_free(ctx->ctx); 
     90        } 
     91 
     92        delete handle; 
     93        delete ctx; 
    7494} 
    7595 
     
    7999client::removeSertificates() 
    80100{ 
    81         if (sslHandle != NULL) 
     101        if (handle->handle != NULL) 
    82102        { 
    83103                if (sslConnected) 
    84104                { 
    85                         int err = SSL_shutdown(sslHandle); 
     105                        int err = SSL_shutdown(handle->handle); 
    86106                        if (err < 0) 
    87107                        { 
     
    91111                        if (err == 0) 
    92112                        { 
    93                                 err = SSL_shutdown(sslHandle); 
     113                                err = SSL_shutdown(handle->handle); 
    94114                                if (err < 0) 
    95115                                { 
     
    102122                } 
    103123 
    104                 SSL_free(sslHandle); 
    105  
    106                 sslHandle = NULL; 
    107         } 
    108  
    109         if (sslCtx != NULL) 
    110         { 
    111                 SSL_CTX_free(sslCtx); 
    112  
    113                 sslCtx = NULL; 
    114         } 
    115  
    116         sslCtx = SSL_CTX_new(SSLv23_client_method()); 
    117         if (sslCtx == NULL) 
     124                SSL_free(handle->handle); 
     125 
     126                handle->handle = NULL; 
     127        } 
     128 
     129        if (ctx->ctx != NULL) 
     130        { 
     131                SSL_CTX_free(ctx->ctx); 
     132 
     133                ctx->ctx = NULL; 
     134        } 
     135 
     136        ctx->ctx = SSL_CTX_new(SSLv23_client_method()); 
     137        if (ctx->ctx == NULL) 
    118138        { 
    119139                throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_REMOVESERTIFICATES, exception::ERRNO_LIBDODO, CLIENTEX_UNABLETOINITCONTEXT, IONETWORKSSLCLIENTEX_UNABLETOINITCONTEXT_STR, __LINE__, __FILE__); 
    120140        } 
    121141 
    122         sslHandle = SSL_new(sslCtx); 
    123         if (sslHandle == NULL) 
     142        handle->handle = SSL_new(ctx->ctx); 
     143        if (handle->handle == NULL) 
    124144        { 
    125145                throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_REMOVESERTIFICATES, exception::ERRNO_LIBDODO, CLIENTEX_UNABLETOINITSSL, IONETWORKSSLCLIENTEX_UNABLETOINITSSL_STR, __LINE__, __FILE__); 
     
    132152client::setSertificates(const io::ssl::__certificates &certs) 
    133153{ 
    134         if (sslHandle != NULL) 
     154        if (handle->handle != NULL) 
    135155        { 
    136156                if (sslConnected) 
    137157                { 
    138                         int err = SSL_shutdown(sslHandle); 
     158                        int err = SSL_shutdown(handle->handle); 
    139159                        if (err < 0) 
    140160                        { 
     
    144164                        if (err == 0) 
    145165                        { 
    146                                 err = SSL_shutdown(sslHandle); 
     166                                err = SSL_shutdown(handle->handle); 
    147167                                if (err < 0) 
    148168                                { 
     
    155175                } 
    156176 
    157                 SSL_free(sslHandle); 
    158  
    159                 sslHandle = NULL; 
    160         } 
    161  
    162         if (sslCtx != NULL) 
    163         { 
    164                 SSL_CTX_free(sslCtx); 
    165  
    166                 sslCtx = NULL; 
    167         } 
    168  
    169         sslCtx = SSL_CTX_new(SSLv23_client_method()); 
    170         if (sslCtx == NULL) 
     177                SSL_free(handle->handle); 
     178 
     179                handle->handle = NULL; 
     180        } 
     181 
     182        if (ctx->ctx != NULL) 
     183        { 
     184                SSL_CTX_free(ctx->ctx); 
     185 
     186                ctx->ctx = NULL; 
     187        } 
     188 
     189        ctx->ctx = SSL_CTX_new(SSLv23_client_method()); 
     190        if (ctx->ctx == NULL) 
    171191        { 
    172192                throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_SETSERTIFICATES, exception::ERRNO_LIBDODO, CLIENTEX_UNABLETOINITCONTEXT, IONETWORKSSLCLIENTEX_UNABLETOINITCONTEXT_STR, __LINE__, __FILE__); 
    173193        } 
    174194 
    175         if (certs.cipher.size() > 0 && SSL_CTX_set_cipher_list(sslCtx, certs.cipher.c_str()) != 1) 
     195        if (certs.cipher.size() > 0 && SSL_CTX_set_cipher_list(ctx->ctx, certs.cipher.c_str()) != 1) 
    176196        { 
    177197                unsigned long nerr = ERR_get_error(); 
     
    179199        } 
    180200 
    181         if (certs.ca.size() > 0 && SSL_CTX_use_certificate_chain_file(sslCtx, certs.ca.c_str()) != 1) 
     201        if (certs.ca.size() > 0 && SSL_CTX_use_certificate_chain_file(ctx->ctx, certs.ca.c_str()) != 1) 
    182202        { 
    183203                unsigned long nerr = ERR_get_error(); 
     
    185205        } 
    186206 
    187         if (certs.cert.size() > 0 && SSL_CTX_use_certificate_file(sslCtx, certs.cert.c_str(), SSL_FILETYPE_PEM) != 1) 
     207        if (certs.cert.size() > 0 && SSL_CTX_use_certificate_file(ctx->ctx, certs.cert.c_str(), SSL_FILETYPE_PEM) != 1) 
    188208        { 
    189209                unsigned long nerr = ERR_get_error(); 
     
    193213        if (certs.keyPassword.size() > 0) 
    194214        { 
    195                 SSL_CTX_set_default_passwd_cb_userdata(sslCtx, (void *)certs.keyPassword.c_str()); 
     215                SSL_CTX_set_default_passwd_cb_userdata(ctx->ctx, (void *)certs.keyPassword.c_str()); 
    196216        } 
    197217 
     
    204224                        case io::ssl::KEYTYPE_PKEY: 
    205225 
    206                                 if (SSL_CTX_use_PrivateKey_file(sslCtx, certs.key.c_str(), SSL_FILETYPE_PEM) != 1) 
     226                                if (SSL_CTX_use_PrivateKey_file(ctx->ctx, certs.key.c_str(), SSL_FILETYPE_PEM) != 1) 
    207227                                { 
    208228                                        unsigned long nerr = ERR_get_error(); 
     
    216236                        case io::ssl::KEYTYPE_RSA: 
    217237 
    218                                 if (SSL_CTX_use_RSAPrivateKey_file(sslCtx, certs.key.c_str(), SSL_FILETYPE_PEM) != 1) 
     238                                if (SSL_CTX_use_RSAPrivateKey_file(ctx->ctx, certs.key.c_str(), SSL_FILETYPE_PEM) != 1) 
    219239                                { 
    220240                                        unsigned long nerr = ERR_get_error(); 
     
    235255                if (certs.ca.size() > 0) 
    236256                { 
    237                         if (SSL_CTX_use_PrivateKey_file(sslCtx, certs.ca.c_str(), SSL_FILETYPE_PEM) != 1) 
     257                        if (SSL_CTX_use_PrivateKey_file(ctx->ctx, certs.ca.c_str(), SSL_FILETYPE_PEM) != 1) 
    238258                        { 
    239259                                unsigned long nerr = ERR_get_error(); 
     
    249269                if (tools::filesystem::getFileInfo(certs.caPath).type == tools::FILESYSTEM_FILETYPE_DIRECTORY) 
    250270                { 
    251                         if (SSL_CTX_load_verify_locations(sslCtx, NULL, certs.caPath.c_str()) != 1) 
     271                        if (SSL_CTX_load_verify_locations(ctx->ctx, NULL, certs.caPath.c_str()) != 1) 
    252272                        { 
    253273                                unsigned long nerr = ERR_get_error(); 
     
    257277                else 
    258278                { 
    259                         if (SSL_CTX_load_verify_locations(sslCtx, certs.caPath.c_str(), NULL) != 1) 
     279                        if (SSL_CTX_load_verify_locations(ctx->ctx, certs.caPath.c_str(), NULL) != 1) 
    260280                        { 
    261281                                unsigned long nerr = ERR_get_error(); 
     
    265285        } 
    266286 
    267         if (keySet && SSL_CTX_check_private_key(sslCtx) != 1) 
     287        if (keySet && SSL_CTX_check_private_key(ctx->ctx) != 1) 
    268288        { 
    269289                unsigned long nerr = ERR_get_error(); 
     
    271291        } 
    272292 
    273         sslHandle = SSL_new(sslCtx); 
    274         if (sslHandle == NULL) 
     293        handle->handle = SSL_new(ctx->ctx); 
     294        if (handle->handle == NULL) 
    275295        { 
    276296                throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_SETSERTIFICATES, exception::ERRNO_LIBDODO, CLIENTEX_UNABLETOINITSSL, IONETWORKSSLCLIENTEX_UNABLETOINITSSL_STR, __LINE__, __FILE__); 
     
    283303client::initSsl() 
    284304{ 
    285         if (sslCtx == NULL) 
    286         { 
    287                 sslCtx = SSL_CTX_new(SSLv23_client_method()); 
    288                 if (sslCtx == NULL) 
     305        if (ctx->ctx == NULL) 
     306        { 
     307                ctx->ctx = SSL_CTX_new(SSLv23_client_method()); 
     308                if (ctx->ctx == NULL) 
    289309                { 
    290310                        throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_INITSSL, exception::ERRNO_LIBDODO, CLIENTEX_UNABLETOINITCONTEXT, IONETWORKSSLCLIENTEX_UNABLETOINITCONTEXT_STR, __LINE__, __FILE__); 
     
    292312        } 
    293313 
    294         if (sslHandle == NULL) 
    295         { 
    296                 sslHandle = SSL_new(sslCtx); 
    297                 if (sslHandle == NULL) 
     314        if (handle->handle == NULL) 
     315        { 
     316                handle->handle = SSL_new(ctx->ctx); 
     317                if (handle->handle == NULL) 
    298318                { 
    299319                        throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_INITSSL, exception::ERRNO_LIBDODO, CLIENTEX_UNABLETOINITSSL, IONETWORKSSLCLIENTEX_UNABLETOINITSSL_STR, __LINE__, __FILE__); 
     
    311331        if (sslConnected) 
    312332        { 
    313                 int err = SSL_shutdown(sslHandle); 
     333                int err = SSL_shutdown(handle->handle); 
    314334                if (err < 0) 
    315335                { 
     
    319339                if (err == 0) 
    320340                { 
    321                         err = SSL_shutdown(sslHandle); 
     341                        err = SSL_shutdown(handle->handle); 
    322342                        if (err < 0) 
    323343                        { 
     
    330350        } 
    331351 
    332         if (SSL_clear(sslHandle) == 0) 
     352        if (SSL_clear(handle->handle) == 0) 
    333353        { 
    334354                unsigned long nerr = ERR_get_error(); 
     
    336356        } 
    337357 
    338         if (SSL_set_fd(sslHandle, socket) == 0) 
     358        if (SSL_set_fd(handle->handle, socket) == 0) 
    339359        { 
    340360                unsigned long nerr = ERR_get_error(); 
     
    342362        } 
    343363 
    344         int res = SSL_connect(sslHandle); 
     364        int res = SSL_connect(handle->handle); 
    345365        switch (res) 
    346366        { 
     
    356376                case - 1: 
    357377                { 
    358                         int nerr = SSL_get_error(sslHandle, res); 
     378                        int nerr = SSL_get_error(handle->handle, res); 
    359379                        if (nerr == SSL_ERROR_WANT_READ || nerr == SSL_ERROR_WANT_WRITE || nerr == SSL_ERROR_WANT_X509_LOOKUP) 
    360380                        { 
     
    367387                        unsigned long nerr = ERR_get_error(); 
    368388 
    369                         int err = SSL_shutdown(sslHandle); 
     389                        int err = SSL_shutdown(handle->handle); 
    370390                        if (err < 0) 
    371391                        { 
     
    375395                        if (err == 0) 
    376396                        { 
    377                                 err = SSL_shutdown(sslHandle); 
     397                                err = SSL_shutdown(handle->handle); 
    378398                                if (err < 0) 
    379399                                { 
     
    448468        connectSsl(); 
    449469 
    450         exchange.init(socket, sslHandle, blocked, blockInherited); 
     470        exchange.init(socket, handle, blocked, blockInherited); 
    451471 
    452472        socket = -1; 
    453         sslHandle = NULL; 
     473        handle->handle = NULL; 
    454474 
    455475#ifndef IO_WO_XEXEC 
     
    541561        connectSsl(); 
    542562 
    543         exchange.init(socket, sslHandle, blocked, blockInherited); 
     563        exchange.init(socket, handle, blocked, blockInherited); 
    544564 
    545565        socket = -1; 
    546         sslHandle = NULL; 
     566        handle->handle = NULL; 
    547567 
    548568#ifndef IO_WO_XEXEC 
     
    571591        if (size >= 108) 
    572592        { 
    573                 throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_CONNECT, exception::ERRNO_LIBDODO, CLIENTEX_LONGPATH, IONETWORKCLIENTEX_LONGPATH_STR, __LINE__, __FILE__); 
     593                throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_CONNECT, exception::ERRNO_LIBDODO, CLIENTEX_LONGPATH, IONETWORKSSLCLIENTEX_LONGPATH_STR, __LINE__, __FILE__); 
    574594        } 
    575595 
     
    591611        connectSsl(); 
    592612 
    593         exchange.init(socket, sslHandle, blocked, blockInherited); 
     613        exchange.init(socket, handle, blocked, blockInherited); 
    594614 
    595615        socket = -1; 
    596         sslHandle = NULL; 
     616        handle->handle = NULL; 
    597617 
    598618#ifndef IO_WO_XEXEC 
     
    602622 
    603623//------------------------------------------------------------------- 
    604  
    605 #endif 
    606  
     624#endif 
     625 
  • trunk/src/ioNetworkSslExchange.cc

    r1166 r1185  
    2828 */ 
    2929 
     30#include <libdodo/directives.h> 
     31 
     32#ifdef OPENSSL_EXT 
     33#include <poll.h> 
     34#include <openssl/ssl.h> 
     35#include <openssl/err.h> 
     36 
     37#include "ioSsl.inline" 
     38 
    3039#include <libdodo/ioNetworkSslExchange.h> 
    31  
    32 #ifdef OPENSSL_EXT 
     40#include <libdodo/ioChannel.h> 
     41#include <libdodo/ioNetworkSslExchangeEx.h> 
     42#include <libdodo/ioNetworkExchange.h> 
     43#include <libdodo/ioSsl.h> 
     44#include <libdodo/types.h> 
     45#include <libdodo/xexec.h> 
     46#include <libdodo/pcSyncProtector.h> 
    3347 
    3448using namespace dodo::io::network::ssl; 
    3549 
    3650__initialAccept::__initialAccept() : socket(-1), 
    37                                                                          sslHandle(NULL) 
    38 { 
     51                                                                         handle(new io::ssl::__sslHandle) 
     52{ 
     53        handle->handle = NULL; 
    3954} 
    4055 
     
    4257 
    4358__initialAccept::__initialAccept(__initialAccept &init) : socket(init.socket), 
    44                                                                                                                   sslHandle(init.sslHandle) 
    45 { 
     59                                                                                                                  handle(new io::ssl::__sslHandle) 
     60{ 
     61        handle->handle = init.handle->handle; 
     62 
    4663        init.socket = -1; 
    47         init.sslHandle = NULL; 
     64        init.handle = NULL; 
     65} 
     66 
     67//------------------------------------------------------------------- 
     68 
     69__initialAccept::~__initialAccept() 
     70{ 
     71        delete handle; 
    4872} 
    4973 
     
    5478{ 
    5579#ifndef IO_WO_XEXEC 
    56  
    5780        collectedData.setExecObject(XEXEC_OBJECT_IONETWORKSSLEXCHANGE); 
    58  
    59 #endif 
    60  
    61         sslHandle = fse.sslHandle; 
    62  
    63         fse.sslHandle = NULL; 
    64 } 
    65  
    66 //------------------------------------------------------------------- 
    67  
    68 exchange::exchange(short protection) : sslHandle(NULL), 
    69                                                                            channel(protection) 
     81#endif 
     82 
     83        handle = fse.handle; 
     84 
     85        fse.handle = NULL; 
     86} 
     87 
     88//------------------------------------------------------------------- 
     89 
     90exchange::exchange(short protection) : channel(protection), 
     91                                                                           handle(new io::ssl::__sslHandle) 
    7092{ 
    7193#ifndef IO_WO_XEXEC 
    72  
    7394        collectedData.setExecObject(XEXEC_OBJECT_IONETWORKSSLEXCHANGE); 
    74  
    75 #endif 
     95#endif 
     96 
     97        handle->handle = NULL; 
    7698} 
    7799 
     
    79101 
    80102exchange::exchange(__initialAccept &a_init, 
    81                                    short           protection) : channel(protection) 
     103                                   short           protection) : channel(protection), 
     104                                                                                                 handle(new io::ssl::__sslHandle) 
    82105{ 
    83106#ifndef IO_WO_XEXEC 
    84  
    85107        collectedData.setExecObject(XEXEC_OBJECT_IONETWORKSSLEXCHANGE); 
    86  
    87108#endif 
    88109 
     
    94115exchange::~exchange() 
    95116{ 
    96         if (sslHandle != NULL) 
    97         { 
    98                 if (SSL_shutdown(sslHandle) == 0) 
    99                 { 
    100                         SSL_shutdown(sslHandle); 
    101                 } 
    102  
    103                 SSL_free(sslHandle); 
    104         } 
     117        if (handle->handle != NULL) 
     118        { 
     119                if (SSL_shutdown(handle->handle) == 0) 
     120                { 
     121                        SSL_shutdown(handle->handle); 
     122                } 
     123 
     124                SSL_free(handle->handle); 
     125        } 
     126 
     127        delete handle; 
    105128} 
    106129 
     
    110133exchange::init(__initialAccept &a_init) 
    111134{ 
    112         init(a_init.socket, a_init.sslHandle, a_init.blocked, a_init.blockInherited); 
     135        init(a_init.socket, a_init.handle, a_init.blocked, a_init.blockInherited); 
    113136 
    114137        a_init.socket = -1; 
    115         a_init.sslHandle = NULL; 
     138        a_init.handle->handle = NULL; 
    116139} 
    117140 
     
    120143void 
    121144exchange::_close(int socket, 
    122                                  SSL *sslHandle) 
    123 { 
    124         int err = SSL_shutdown(sslHandle); 
     145                                 io::ssl::__sslHandle *handle) 
     146{ 
     147        int err = SSL_shutdown(handle->handle); 
    125148        if (err < 0) 
    126149        { 
     
    130153        if (err == 0) 
    131154        { 
    132                 err = SSL_shutdown(sslHandle); 
     155                err = SSL_shutdown(handle->handle); 
    133156                if (err < 0) 
    134157                { 
     
    155178        if (socket != -1) 
    156179        { 
    157                 _close(socket, sslHandle); 
     180                _close(socket, handle); 
    158181 
    159182                socket = -1; 
    160                 sslHandle = NULL; 
     183                handle->handle = NULL; 
    161184        } 
    162185 
     
    170193void 
    171194exchange::init(int  a_socket, 
    172                            SSL  *a_sslHandle, 
     195                           io::ssl::__sslHandle  *a_handle, 
    173196                           bool a_blocked, 
    174197                           bool blockInherited) 
     
    178201        if (socket != -1) 
    179202        { 
    180                 _close(socket, sslHandle); 
     203                _close(socket, handle); 
    181204 
    182205                socket = -1; 
    183                 sslHandle = NULL; 
     206                handle->handle = NULL; 
    184207        } 
    185208 
    186209        blocked = a_blocked; 
    187210        socket = a_socket; 
    188         sslHandle = a_sslHandle; 
     211        handle->handle = a_handle->handle; 
    189212 
    190213        setInBufferSize(inSocketBuffer); 
     
    237260        } 
    238261 
    239         _close(socket, sslHandle); 
     262        _close(socket, handle); 
    240263 
    241264        socket = -1; 
    242         sslHandle = NULL; 
     265        handle->handle = NULL; 
    243266 
    244267        return false; 
     
    266289                while (true) 
    267290                { 
    268                         if ((n = SSL_write(sslHandle, data, outSocketBuffer)) <= 0) 
     291                        if ((n = SSL_write(handle->handle, data, outSocketBuffer)) <= 0) 
    269292                        { 
    270                                 switch (SSL_get_error(sslHandle, n)) 
     293                                switch (SSL_get_error(handle->handle, n)) 
    271294                                { 
    272295                                        case SSL_ERROR_WANT_READ: 
     
    301324                while (true) 
    302325                { 
    303                         if ((n = SSL_write(sslHandle, data, rest)) <= 0) 
     326                        if ((n = SSL_write(handle->handle, data, rest)) <= 0) 
    304327                        { 
    305                                 switch (SSL_get_error(sslHandle, n)) 
     328                                switch (SSL_get_error(handle->handle, n)) 
    306329                                { 
    307330                                        case SSL_ERROR_WANT_READ: 
     
    354377                while (true) 
    355378                { 
    356                         if ((n = SSL_read(sslHandle, data, inSocketBuffer)) <= 0) 
     379                        if ((n = SSL_read(handle->handle, data, inSocketBuffer)) <= 0) 
    357380                        { 
    358                                 switch (SSL_get_error(sslHandle, n)) 
     381                                switch (SSL_get_error(handle->handle, n)) 
    359382                                { 
    360383                                        case SSL_ERROR_WANT_READ: 
     
    389412                while (true) 
    390413                { 
    391                         if ((n = SSL_read(sslHandle, data, rest)) <= 0) 
     414                        if ((n = SSL_read(handle->handle, data, rest)) <= 0) 
    392415                        { 
    393                                 switch (SSL_get_error(sslHandle, n)) 
     416                                switch (SSL_get_error(handle->handle, n)) 
    394417                                { 
    395418                                        case SSL_ERROR_WANT_READ: 
     
    435458        while (true) 
    436459        { 
    437                 if ((n = SSL_read(sslHandle, data, inSize)) <= 0) 
    438                 { 
    439                         switch (SSL_get_error(sslHandle, n)) 
     460                if ((n = SSL_read(handle->handle, data, inSize)) <= 0) 
     461                { 
     462                        switch (SSL_get_error(handle->handle, n)) 
    440463                        { 
    441464                                case SSL_ERROR_WANT_READ: 
  • trunk/src/ioNetworkSslServer.cc

    r1166 r1185  
    2828 */ 
    2929 
     30#include <libdodo/directives.h> 
     31 
     32#ifdef OPENSSL_EXT 
     33#include <sys/socket.h> 
     34#include <sys/un.h> 
     35#include <arpa/inet.h> 
     36#include <openssl/ssl.h> 
     37#include <openssl/err.h> 
     38 
     39#include "ioSsl.inline" 
     40 
    3041#include <libdodo/ioNetworkSslServer.h> 
    31  
    32 #ifdef OPENSSL_EXT 
     42#include <libdodo/ioNetworkSslClient.h> 
     43#include <libdodo/pcSyncProtector.h> 
     44#include <libdodo/toolsFilesystem.h> 
     45#include <libdodo/ioNetworkSslServerEx.h> 
     46#include <libdodo/ioNetworkServer.h> 
     47#include <libdodo/ioSsl.h> 
     48#include <libdodo/types.h> 
     49#include <libdodo/ioNetworkSslExchange.h> 
     50#include <libdodo/xexec.h> 
     51#include <libdodo/ioEventInfo.h> 
    3352 
    3453using namespace dodo::io::network::ssl; 
     
    4362                           short a_type) : network::server(a_family, 
    4463                                                                                           a_type), 
    45                                                            sslCtx(NULL) 
    46 { 
    47 #ifndef IO_WO_XEXEC 
    48  
     64                                                           ctx(new io::ssl::__sslContext) 
     65{ 
     66#ifndef IO_WO_XEXEC 
    4967        collectedData.setExecObject(XEXEC_OBJECT_IONETWORKSSLSERVER); 
    50  
    51 #endif 
     68#endif 
     69 
     70        ctx->ctx = NULL; 
    5271} 
    5372 
     
    5776server::~server() 
    5877{ 
    59         if (sslCtx != NULL) 
    60         { 
    61                 SSL_CTX_free(sslCtx); 
    62         } 
     78        if (ctx->ctx != NULL) 
     79        { 
     80                SSL_CTX_free(ctx->ctx); 
     81        } 
     82 
     83        delete ctx; 
    6384} 
    6485 
     
    6990server::removeSertificates() 
    7091{ 
    71         if (sslCtx != NULL) 
    72         { 
    73                 SSL_CTX_free(sslCtx); 
    74  
    75                 sslCtx = NULL; 
    76         } 
    77  
    78         sslCtx = SSL_CTX_new(SSLv23_server_method()); 
    79         if (sslCtx == NULL) 
     92        if (ctx->ctx != NULL) 
     93        { 
     94                SSL_CTX_free(ctx->ctx); 
     95 
     96                ctx->ctx = NULL; 
     97        } 
     98 
     99        ctx->ctx = SSL_CTX_new(SSLv23_server_method()); 
     100        if (ctx->ctx == NULL) 
    80101        { 
    81102                throw exception::basic(exception::ERRMODULE_IONETWORKSSLSERVER, SERVEREX_REMOVESERTIFICATES, exception::ERRNO_LIBDODO, SERVEREX_UNABLETOINITCONTEXT, IONETWORKSSLSERVEREX_UNABLETOINITCONTEXT_STR, __LINE__, __FILE__); 
     
    88109server::setSertificates(const io::ssl::__certificates &certs) 
    89110{ 
    90         if (sslCtx != NULL) 
    91         { 
    92                 SSL_CTX_free(sslCtx); 
    93         } 
    94  
    95         sslCtx = SSL_CTX_new(SSLv23_server_method()); 
    96         if (sslCtx == NULL) 
     111        if (ctx->ctx != NULL) 
     112        { 
     113                SSL_CTX_free(ctx->ctx); 
     114        } 
     115 
     116        ctx->ctx = SSL_CTX_new(SSLv23_server_method()); 
     117        if (ctx->ctx == NULL) 
    97118        { 
    98119                throw exception::basic(exception::ERRMODULE_IONETWORKSSLSERVER, SERVEREX_SETSERTIFICATES, exception::ERRNO_LIBDODO, SERVEREX_UNABLETOINITCONTEXT, IONETWORKSSLSERVEREX_UNABLETOINITCONTEXT_STR, __LINE__, __FILE__); 
    99120        } 
    100121 
    101         if (certs.cipher.size() > 0 && SSL_CTX_set_cipher_list(sslCtx, certs.cipher.c_str()) != 1) 
     122        if (certs.cipher.size() > 0 && SSL_CTX_set_cipher_list(ctx->ctx, certs.cipher.c_str()) != 1) 
    102123        { 
    103124                unsigned long nerr = ERR_get_error(); 
     
    105126        } 
    106127 
    107         if (certs.ca.size() > 0 && SSL_CTX_use_certificate_chain_file(sslCtx, certs.ca.c_str()) != 1) 
     128        if (certs.ca.size() > 0 && SSL_CTX_use_certificate_chain_file(ctx->ctx, certs.ca.c_str()) != 1) 
    108129        { 
    109130                unsigned long nerr = ERR_get_error(); 
     
    111132        } 
    112133 
    113         if (certs.cert.size() > 0 && SSL_CTX_use_certificate_file(sslCtx, certs.cert.c_str(), SSL_FILETYPE_PEM) != 1) 
     134        if (certs.cert.size() > 0 && SSL_CTX_use_certificate_file(ctx->ctx, certs.cert.c_str(), SSL_FILETYPE_PEM) != 1) 
    114135        { 
    115136                unsigned long nerr = ERR_get_error(); 
     
    119140        if (certs.keyPassword.size() > 0) 
    120141        { 
    121                 SSL_CTX_set_default_passwd_cb_userdata(sslCtx, (void *)certs.keyPassword.c_str()); 
     142                SSL_CTX_set_default_passwd_cb_userdata(ctx->ctx, (void *)certs.keyPassword.c_str()); 
    122143        } 
    123144 
     
    130151                        case io::ssl::KEYTYPE_PKEY: 
    131152 
    132                                 if (SSL_CTX_use_PrivateKey_file(sslCtx, certs.key.c_str(), SSL_FILETYPE_PEM) != 1) 
     153                                if (SSL_CTX_use_PrivateKey_file(ctx->ctx, certs.key.c_str(), SSL_FILETYPE_PEM) != 1) 
    133154                                { 
    134155                                        unsigned long nerr = ERR_get_error(); 
     
    142163                        case io::ssl::KEYTYPE_RSA: 
    143164 
    144                                 if (SSL_CTX_use_RSAPrivateKey_file(sslCtx, certs.key.c_str(), SSL_FILETYPE_PEM) != 1) 
     165                                if (SSL_CTX_use_RSAPrivateKey_file(ctx->ctx, certs.key.c_str(), SSL_FILETYPE_PEM) != 1) 
    145166                                { 
    146167                                        unsigned long nerr = ERR_get_error(); 
     
    161182                if (certs.ca.size() > 0) 
    162183                { 
    163                         if (SSL_CTX_use_PrivateKey_file(sslCtx, certs.ca.c_str(), SSL_FILETYPE_PEM) != 1) 
     184                        if (SSL_CTX_use_PrivateKey_file(ctx->ctx, certs.ca.c_str(), SSL_FILETYPE_PEM) != 1) 
    164185                        { 
    165186                                unsigned long nerr = ERR_get_error(); 
     
    175196                if (tools::filesystem::getFileInfo(certs.caPath).type == tools::FILESYSTEM_FILETYPE_DIRECTORY) 
    176197                { 
    177                         if (SSL_CTX_load_verify_locations(sslCtx, NULL, certs.caPath.c_str()) != 1) 
     198                        if (SSL_CTX_load_verify_locations(ctx->ctx, NULL, certs.caPath.c_str()) != 1) 
    178199                        { 
    179200                                unsigned long nerr = ERR_get_error(); 
     
    183204                else 
    184205                { 
    185                         if (SSL_CTX_load_verify_locations(sslCtx, certs.caPath.c_str(), NULL) != 1) 
     206                        if (SSL_CTX_load_verify_locations(ctx->ctx, certs.caPath.c_str(), NULL) != 1) 
    186207                        { 
    187208                                unsigned long nerr = ERR_get_error(); 
     
    191212        } 
    192213 
    193         if (keySet && SSL_CTX_check_private_key(sslCtx) != 1) 
     214        if (keySet && SSL_CTX_check_private_key(ctx->ctx) != 1) 
    194215        { 
    195216                unsigned long nerr = ERR_get_error(); 
     
    203224server::initSsl() 
    204225{ 
    205         if (sslCtx == NULL) 
    206         { 
    207                 sslCtx = SSL_CTX_new(SSLv23_server_method()); 
    208                 if (sslCtx == NULL) 
     226        if (ctx->ctx == NULL) 
     227        { 
     228                ctx->ctx = SSL_CTX_new(SSLv23_server_method()); 
     229                if (ctx->ctx == NULL) 
    209230                { 
    210231                        throw exception::basic(exception::ERRMODULE_IONETWORKSSLSERVER, SERVEREX_INITSSL, exception::ERRNO_LIBDODO, SERVEREX_UNABLETOINITCONTEXT, IONETWORKSSLSERVEREX_UNABLETOINITCONTEXT_STR, __LINE__, __FILE__); 
     
    220241        io::ssl::__openssl_init_object__.addEntropy(); 
    221242 
    222         init.sslHandle = SSL_new(sslCtx); 
    223         if (init.sslHandle == NULL) 
     243        init.handle->handle = SSL_new(ctx->ctx); 
     244        if (init.handle->handle == NULL) 
    224245        { 
    225246                throw exception::basic(exception::ERRMODULE_IONETWORKSSLSERVER, SERVEREX_INITSSL, exception::ERRNO_LIBDODO, SERVEREX_UNABLETOINITSSL, IONETWORKSSLSERVEREX_UNABLETOINITSSL_STR, __LINE__, __FILE__); 
    226247        } 
    227248 
    228         if (SSL_set_fd(init.sslHandle, init.socket) == 0) 
     249        if (SSL_set_fd(init.handle->handle, init.socket) == 0) 
    229250        { 
    230251                unsigned long nerr = ERR_get_error(); 
     
    232253        } 
    233254 
    234         int res = SSL_accept(init.sslHandle); 
     255        int res = SSL_accept(init.handle->handle); 
    235256        switch (res) 
    236257        { 
     
    246267                case - 1: 
    247268                { 
    248                         int nerr = SSL_get_error(init.sslHandle, res); 
     269                        int nerr = SSL_get_error(init.handle->handle, res); 
    249270                        if (nerr == SSL_ERROR_WANT_READ || nerr == SSL_ERROR_WANT_WRITE || nerr == SSL_ERROR_WANT_X509_LOOKUP) 
    250271                        { 
     
    257278                        unsigned long nerr = ERR_get_error(); 
    258279 
    259                         int err = SSL_shutdown(init.sslHandle); 
     280                        int err = SSL_shutdown(init.handle->handle); 
    260281                        if (err < 0) 
    261282                        { 
     
    265286                        if (err == 0) 
    266287                        { 
    267                                 err = SSL_shutdown(init.sslHandle); 
     288                                err = SSL_shutdown(init.handle->handle); 
    268289                                if (err < 0) 
    269290                                { 
  • trunk/src/ioSsl.cc

    r1162 r1185  
    2828 */ 
    2929 
    30 #include <libdodo/ioSsl.h> 
     30#include <libdodo/directives.h> 
    3131 
    3232#ifdef OPENSSL_EXT 
     33#include <sys/stat.h> 
     34#include <sys/time.h> 
     35#include <openssl/ssl.h> 
     36#include <openssl/rand.h> 
     37#include <openssl/err.h> 
     38 
     39#include "ioSsl.inline" 
     40 
     41#include <libdodo/ioSsl.h> 
    3342 
    3443namespace dodo 
     
    93102} 
    94103 
     104//------------------------------------------------------------------- 
     105 
    95106void 
    96107__openssl_init__::addEntropy() 
     
    123134 
    124135//------------------------------------------------------------------- 
    125  
    126136#endif 
    127137 
  • trunk/src/ioSsl.inline

    r1166 r1185  
    11/*************************************************************************** 
    2  *            ioNetworkSslClient.cc 
     2 *            ioSsl.inline 
    33 * 
    4  *  Tue Jun 10 17:00:47 2008 
    5  *  Copyright  2008  Ni@m 
     4 *  Tue Mar 17 01:48:47 2009 
     5 *  Copyright  2009  Ni@m 
    66 *  niam.niam@gmail.com 
    77 ****************************************************************************/ 
     
    2828 */ 
    2929 
    30 #include <libdodo/ioNetworkSslClient.h> 
     30#include <libdodo/directives.h> 
    3131 
    3232#ifdef OPENSSL_EXT 
     33#include <openssl/ssl.h> 
    3334 
    34 using namespace dodo::io::network::ssl; 
     35namespace dodo 
     36{ 
     37        namespace io 
     38        { 
     39                namespace ssl 
     40                { 
     41                        struct __sslHandle 
     42                        { 
     43                                SSL *handle;     ///< SSL connection handle 
     44                        }; 
    3545 
    36 client::client(client &fs) : network::client(fs) 
    37 { 
    38 } 
     46                        struct __sslContext 
     47                        { 
     48                                SSL_CTX *ctx;    ///< SSL context 
     49                        }; 
    3950 
    40 //------------------------------------------------------------------- 
     51                        /** 
     52                         * @class __openssl_init__ 
     53                         * @brief initializes openssl evironment 
     54                         */ 
     55                        class __openssl_init__ 
     56                        { 
     57                          public: 
    4158 
    42 client::client(short a_family, 
    43                            short a_type) : network::client(a_family, 
    44                                                                                            a_type), 
    45                                                            sslCtx(NULL), 
    46                                                            sslHandle(NULL), 
    47                                                            sslConnected(false) 
    48 { 
    49 #ifndef IO_WO_XEXEC 
     59                                /** 
     60                                 * contructor 
     61                                 */ 
     62                                __openssl_init__(); 
    5063 
    51         collectedData.setExecObject(XEXEC_OBJECT_IONETWORKSSLCLIENT); 
     64                                /** 
     65                                 * destructor 
     66                                 */ 
     67                                ~__openssl_init__(); 
    5268 
    53 #endif 
    54 } 
     69                                /** 
     70                                 * add entropy for randomness 
     71                                 */ 
     72                                void addEntropy(); 
     73                        }; 
    5574 
    56 //------------------------------------------------------------------- 
    57  
    58 client::~client() 
    59 { 
    60         if (sslHandle != NULL) 
    61         { 
    62                 if (sslConnected && SSL_shutdown(sslHandle) == 0) 
    63                 { 
    64                         SSL_shutdown(sslHandle); 
    65                 } 
    66  
    67                 SSL_free(sslHandle); 
    68         } 
    69  
    70         if (sslCtx != NULL) 
    71         { 
    72                 SSL_CTX_free(sslCtx); 
    73         } 
    74 } 
    75  
    76 //------------------------------------------------------------------- 
    77  
    78 void 
    79 client::removeSertificates() 
    80 { 
    81         if (sslHandle != NULL) 
    82         { 
    83                 if (sslConnected) 
    84                 { 
    85                         int err = SSL_shutdown(sslHandle); 
    86                         if (err < 0) 
    87                         { 
    88                                 unsigned long nerr = ERR_get_error(); 
    89                                 throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_REMOVESERTIFICATES, exception::ERRNO_OPENSSL, nerr, ERR_error_string(nerr, NULL), __LINE__, __FILE__); 
    90                         } 
    91                         if (err == 0) 
    92                         { 
    93                                 err = SSL_shutdown(sslHandle); 
    94                                 if (err < 0) 
    95                                 { 
    96                                         unsigned long nerr = ERR_get_error(); 
    97                                         throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_REMOVESERTIFICATES, exception::ERRNO_OPENSSL, nerr, ERR_error_string(nerr, NULL), __LINE__, __FILE__); 
    98                                 } 
    99                         } 
    100  
    101                         sslConnected = false; 
    102                 } 
    103  
    104                 SSL_free(sslHandle); 
    105  
    106                 sslHandle = NULL; 
    107         } 
    108  
    109         if (sslCtx != NULL) 
    110         { 
    111                 SSL_CTX_free(sslCtx); 
    112  
    113                 sslCtx = NULL; 
    114         } 
    115  
    116         sslCtx = SSL_CTX_new(SSLv23_client_method()); 
    117         if (sslCtx == NULL) 
    118         { 
    119                 throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_REMOVESERTIFICATES, exception::ERRNO_LIBDODO, CLIENTEX_UNABLETOINITCONTEXT, IONETWORKSSLCLIENTEX_UNABLETOINITCONTEXT_STR, __LINE__, __FILE__); 
    120         } 
    121  
    122         sslHandle = SSL_new(sslCtx); 
    123         if (sslHandle == NULL) 
    124         { 
    125                 throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_REMOVESERTIFICATES, exception::ERRNO_LIBDODO, CLIENTEX_UNABLETOINITSSL, IONETWORKSSLCLIENTEX_UNABLETOINITSSL_STR, __LINE__, __FILE__); 
    126         } 
    127 } 
    128  
    129 //------------------------------------------------------------------- 
    130  
    131 void 
    132 client::setSertificates(const io::ssl::__certificates &certs) 
    133 { 
    134         if (sslHandle != NULL) 
    135         { 
    136                 if (sslConnected) 
    137                 { 
    138                         int err = SSL_shutdown(sslHandle); 
    139                         if (err < 0) 
    140                         { 
    141                                 unsigned long nerr = ERR_get_error(); 
    142                                 throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_SETSERTIFICATES, exception::ERRNO_OPENSSL, nerr, ERR_error_string(nerr, NULL), __LINE__, __FILE__); 
    143                         } 
    144                         if (err == 0) 
    145                         { 
    146                                 err = SSL_shutdown(sslHandle); 
    147                                 if (err < 0) 
    148                                 { 
    149                                         unsigned long nerr = ERR_get_error(); 
    150                                         throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_SETSERTIFICATES, exception::ERRNO_OPENSSL, nerr, ERR_error_string(nerr, NULL), __LINE__, __FILE__); 
    151                                 } 
    152                         } 
    153  
    154                         sslConnected = false; 
    155                 } 
    156  
    157                 SSL_free(sslHandle); 
    158  
    159                 sslHandle = NULL; 
    160         } 
    161  
    162         if (sslCtx != NULL) 
    163         { 
    164                 SSL_CTX_free(sslCtx); 
    165  
    166                 sslCtx = NULL; 
    167         } 
    168  
    169         sslCtx = SSL_CTX_new(SSLv23_client_method()); 
    170         if (sslCtx == NULL) 
    171         { 
    172                 throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_SETSERTIFICATES, exception::ERRNO_LIBDODO, CLIENTEX_UNABLETOINITCONTEXT, IONETWORKSSLCLIENTEX_UNABLETOINITCONTEXT_STR, __LINE__, __FILE__); 
    173         } 
    174  
    175         if (certs.cipher.size() > 0 && SSL_CTX_set_cipher_list(sslCtx, certs.cipher.c_str()) != 1) 
    176         { 
    177                 unsigned long nerr = ERR_get_error(); 
    178                 throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_SETSERTIFICATES, exception::ERRNO_OPENSSL, nerr, ERR_error_string(nerr, NULL), __LINE__, __FILE__); 
    179         } 
    180  
    181         if (certs.ca.size() > 0 && SSL_CTX_use_certificate_chain_file(sslCtx, certs.ca.c_str()) != 1) 
    182         { 
    183                 unsigned long nerr = ERR_get_error(); 
    184                 throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_SETSERTIFICATES, exception::ERRNO_OPENSSL, nerr, ERR_error_string(nerr, NULL), __LINE__, __FILE__); 
    185         } 
    186  
    187         if (certs.cert.size() > 0 && SSL_CTX_use_certificate_file(sslCtx, certs.cert.c_str(), SSL_FILETYPE_PEM) != 1) 
    188         { 
    189                 unsigned long nerr = ERR_get_error(); 
    190                 throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_SETSERTIFICATES, exception::ERRNO_OPENSSL, nerr, ERR_error_string(nerr, NULL), __LINE__, __FILE__); 
    191         } 
    192  
    193         if (certs.keyPassword.size() > 0) 
    194         { 
    195                 SSL_CTX_set_default_passwd_cb_userdata(sslCtx, (void *)certs.keyPassword.c_str()); 
    196         } 
    197  
    198         bool keySet = false; 
    199  
    200         if (certs.key.size() > 0) 
    201         { 
    202                 switch (certs.keyType) 
    203                 { 
    204                         case io::ssl::KEYTYPE_PKEY: 
    205  
    206                                 if (SSL_CTX_use_PrivateKey_file(sslCtx, certs.key.c_str(), SSL_FILETYPE_PEM) != 1) 
    207                                 { 
    208                                         unsigned long nerr = ERR_get_error(); 
    209                                         throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_SETSERTIFICATES, exception::ERRNO_OPENSSL, nerr, ERR_error_string(nerr, NULL), __LINE__, __FILE__); 
    210                                 } 
    211  
    212                                 keySet = true; 
    213  
    214                                 break; 
    215  
    216                         case io::ssl::KEYTYPE_RSA: 
    217  
    218                                 if (SSL_CTX_use_RSAPrivateKey_file(sslCtx, certs.key.c_str(), SSL_FILETYPE_PEM) != 1) 
    219                                 { 
    220                                         unsigned long nerr = ERR_get_error(); 
    221                                         throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_SETSERTIFICATES, exception::ERRNO_OPENSSL, nerr, ERR_error_string(nerr, NULL), __LINE__, __FILE__); 
    222                                 } 
    223  
    224                                 keySet = true; 
    225  
    226                                 break; 
    227  
    228                         default: 
    229  
    230                                 throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_SETSERTIFICATES, exception::ERRNO_LIBDODO, CLIENTEX_UNKNOWNKEYTYPE, IONETWORKSSLCLIENTEX_UNKNOWNKEYTYPE_STR, __LINE__, __FILE__); 
    231                 } 
    232         } 
    233         else 
    234         { 
    235                 if (certs.ca.size() > 0) 
    236                 { 
    237                         if (SSL_CTX_use_PrivateKey_file(sslCtx, certs.ca.c_str(), SSL_FILETYPE_PEM) != 1) 
    238                         { 
    239                                 unsigned long nerr = ERR_get_error(); 
    240                                 throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_SETSERTIFICATES, exception::ERRNO_OPENSSL, nerr, ERR_error_string(nerr, NULL), __LINE__, __FILE__); 
    241                         } 
    242  
    243                         keySet = true; 
    244                 } 
    245         } 
    246  
    247         if (certs.caPath.size() > 0) 
    248         { 
    249                 if (tools::filesystem::getFileInfo(certs.caPath).type == tools::FILESYSTEM_FILETYPE_DIRECTORY) 
    250                 { 
    251                         if (SSL_CTX_load_verify_locations(sslCtx, NULL, certs.caPath.c_str()) != 1) 
    252                         { 
    253                                 unsigned long nerr = ERR_get_error(); 
    254                                 throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_SETSERTIFICATES, exception::ERRNO_OPENSSL, nerr, ERR_error_string(nerr, NULL), __LINE__, __FILE__); 
    255                         } 
    256                 } 
    257                 else 
    258                 { 
    259                         if (SSL_CTX_load_verify_locations(sslCtx, certs.caPath.c_str(), NULL) != 1) 
    260                         { 
    261                                 unsigned long nerr = ERR_get_error(); 
    262                                 throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_SETSERTIFICATES, exception::ERRNO_OPENSSL, nerr, ERR_error_string(nerr, NULL), __LINE__, __FILE__); 
    263                         } 
    264                 } 
    265         } 
    266  
    267         if (keySet && SSL_CTX_check_private_key(sslCtx) != 1) 
    268         { 
    269                 unsigned long nerr = ERR_get_error(); 
    270                 throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_SETSERTIFICATES, exception::ERRNO_OPENSSL, nerr, ERR_error_string(nerr, NULL), __LINE__, __FILE__); 
    271         } 
    272  
    273         sslHandle = SSL_new(sslCtx); 
    274         if (sslHandle == NULL) 
    275         { 
    276                 throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_SETSERTIFICATES, exception::ERRNO_LIBDODO, CLIENTEX_UNABLETOINITSSL, IONETWORKSSLCLIENTEX_UNABLETOINITSSL_STR, __LINE__, __FILE__); 
    277         } 
    278 } 
    279  
    280 //------------------------------------------------------------------- 
    281  
    282 void 
    283 client::initSsl() 
    284 { 
    285         if (sslCtx == NULL) 
    286         { 
    287                 sslCtx = SSL_CTX_new(SSLv23_client_method()); 
    288                 if (sslCtx == NULL) 
    289                 { 
    290                         throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_INITSSL, exception::ERRNO_LIBDODO, CLIENTEX_UNABLETOINITCONTEXT, IONETWORKSSLCLIENTEX_UNABLETOINITCONTEXT_STR, __LINE__, __FILE__); 
    291                 } 
    292         } 
    293  
    294         if (sslHandle == NULL) 
    295         { 
    296                 sslHandle = SSL_new(sslCtx); 
    297                 if (sslHandle == NULL) 
    298                 { 
    299                         throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_INITSSL, exception::ERRNO_LIBDODO, CLIENTEX_UNABLETOINITSSL, IONETWORKSSLCLIENTEX_UNABLETOINITSSL_STR, __LINE__, __FILE__); 
    300                 } 
    301         } 
    302 } 
    303  
    304 //------------------------------------------------------------------- 
    305  
    306 void 
    307 client::connectSsl() 
    308 { 
    309         io::ssl::__openssl_init_object__.addEntropy(); 
    310  
    311         if (sslConnected) 
    312         { 
    313                 int err = SSL_shutdown(sslHandle); 
    314                 if (err < 0) 
    315                 { 
    316                         unsigned long nerr = ERR_get_error(); 
    317                         throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_CONNECTSSL, exception::ERRNO_OPENSSL, nerr, ERR_error_string(nerr, NULL), __LINE__, __FILE__); 
    318                 } 
    319                 if (err == 0) 
    320                 { 
    321                         err = SSL_shutdown(sslHandle); 
    322                         if (err < 0) 
    323                         { 
    324                                 unsigned long nerr = ERR_get_error(); 
    325                                 throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_CONNECTSSL, exception::ERRNO_OPENSSL, nerr, ERR_error_string(nerr, NULL), __LINE__, __FILE__); 
    326                         } 
    327                 } 
    328  
    329                 sslConnected = false; 
    330         } 
    331  
    332         if (SSL_clear(sslHandle) == 0) 
    333         { 
    334                 unsigned long nerr = ERR_get_error(); 
    335                 throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_CONNECTSSL, exception::ERRNO_OPENSSL, nerr, ERR_error_string(nerr, NULL), __LINE__, __FILE__); 
    336         } 
    337  
    338         if (SSL_set_fd(sslHandle, socket) == 0) 
    339         { 
    340                 unsigned long nerr = ERR_get_error(); 
    341                 throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_CONNECTSSL, exception::ERRNO_OPENSSL, nerr, ERR_error_string(nerr, NULL), __LINE__, __FILE__); 
    342         } 
    343  
    344         int res = SSL_connect(sslHandle); 
    345         switch (res) 
    346         { 
    347                 case 1: 
    348                         break; 
    349  
    350                 case 0: 
    351                 { 
    352                         unsigned long nerr = ERR_get_error(); 
    353                         throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_CONNECTSSL, exception::ERRNO_OPENSSL, nerr, ERR_error_string(nerr, NULL), __LINE__, __FILE__); 
    354                 } 
    355  
    356                 case - 1: 
    357                 { 
    358                         int nerr = SSL_get_error(sslHandle, res); 
    359                         if (nerr == SSL_ERROR_WANT_READ || nerr == SSL_ERROR_WANT_WRITE || nerr == SSL_ERROR_WANT_X509_LOOKUP) 
    360                         { 
    361                                 break; 
    362                         } 
    363                 } 
    364  
    365                 default: 
    366                 { 
    367                         unsigned long nerr = ERR_get_error(); 
    368  
    369                         int err = SSL_shutdown(sslHandle); 
    370                         if (err < 0) 
    371                         { 
    372                                 nerr = ERR_get_error(); 
    373                                 throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_CONNECTSSL, exception::ERRNO_OPENSSL, nerr, ERR_error_string(nerr, NULL), __LINE__, __FILE__); 
    374                         } 
    375                         if (err == 0) 
    376                         { 
    377                                 err = SSL_shutdown(sslHandle); 
    378                                 if (err < 0) 
    379                                 { 
    380                                         nerr = ERR_get_error(); 
    381                                         throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_CONNECTSSL, exception::ERRNO_OPENSSL, nerr, ERR_error_string(nerr, NULL), __LINE__, __FILE__); 
    382                                 } 
    383                         } 
    384  
    385                         throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_CONNECTSSL, exception::ERRNO_OPENSSL, nerr, ERR_error_string(nerr, NULL), __LINE__, __FILE__); 
    386                 } 
    387         } 
    388  
    389         sslConnected = true; 
    390 } 
    391  
    392 //------------------------------------------------------------------- 
    393  
    394 void 
    395 client::connect(const dodoString &host, 
    396                                 int              port, 
    397                                 exchange         &exchange) 
    398 { 
    399 #ifndef IO_WO_XEXEC 
    400         operType = CLIENT_OPERATION_CONNECT; 
    401         performXExec(preExec); 
     75                        extern __openssl_init__ __openssl_init_object__; 
     76                }; 
     77        }; 
     78}; 
    40279#endif 
    40380 
    404         initSsl(); 
    405         makeSocket(); 
    406  
    407         if (family == CONNECTION_PROTO_FAMILY_IPV4) 
    408         { 
    409                 struct sockaddr_in sa; 
    410                 sa.sin_family = AF_INET; 
    411                 sa.sin_port = htons(port); 
    412                 inet_aton(host.c_str(), &sa.sin_addr); 
    413  
    414                 if (::connect(socket, (struct sockaddr *)&sa, sizeof(sa)) == -1) 
    415                 { 
    416                         if (::close(socket) == -1) 
    417                         { 
    418                                 throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_CONNECT, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    419                         } 
    420  
    421                         socket = -1; 
    422  
    423                         throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_CONNECT, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    424                 } 
    425         } 
    426         else 
    427         { 
    428                 struct sockaddr_in6 sa; 
    429                 sa.sin6_family = AF_INET6; 
    430                 sa.sin6_port = htons(port); 
    431                 sa.sin6_flowinfo = 0; 
    432                 sa.sin6_scope_id = 0; 
    433                 inet_pton(AF_INET6, host.c_str(), &sa.sin6_addr); 
    434  
    435                 if (::connect(socket, (struct sockaddr *)&sa, sizeof(sa)) == -1) 
    436                 { 
    437                         if (::close(socket) == -1) 
    438                         { 
    439                                 throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_CONNECT, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    440                         } 
    441  
    442                         socket = -1; 
    443  
    444                         throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_CONNECT, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    445                 } 
    446         } 
    447  
    448         connectSsl(); 
    449  
    450         exchange.init(socket, sslHandle, blocked, blockInherited); 
    451  
    452         socket = -1; 
    453         sslHandle = NULL; 
    454  
    455 #ifndef IO_WO_XEXEC 
    456         performXExec(postExec); 
    457 #endif 
    458 } 
    459  
    460 //------------------------------------------------------------------- 
    461  
    462 void 
    463 client::connectFrom(const dodoString &local, 
    464                                         const dodoString &host, 
    465                                         int              port, 
    466                                         exchange         &exchange) 
    467 { 
    468 #ifndef IO_WO_XEXEC 
    469         operType = CLIENT_OPERATION_CONNECTFROM; 
    470         performXExec(preExec); 
    471 #endif 
    472  
    473         initSsl(); 
    474         makeSocket(); 
    475  
    476         int sockFlag(1); 
    477         if (setsockopt(socket, SOL_SOCKET, SO_REUSEADDR, &sockFlag, sizeof(int)) == -1) 
    478         { 
    479                 throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_CONNECTFROM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    480         } 
    481  
    482         addFlag(socketOpts, 1 << CONNECTION_OPTION_REUSE_ADDRESS); 
    483  
    484         if (family == CONNECTION_PROTO_FAMILY_IPV4) 
    485         { 
    486                 struct sockaddr_in sa; 
    487                 sa.sin_family = AF_INET; 
    488                 sa.sin_port = htons(0); 
    489                 inet_aton(local.c_str(), &sa.sin_addr); 
    490  
    491                 if (::bind(socket, (struct sockaddr *)&sa, sizeof(sa)) == -1) 
    492                 { 
    493                         throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_CONNECTFROM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    494                 } 
    495  
    496                 sa.sin_port = htons(port); 
    497                 inet_aton(host.c_str(), &sa.sin_addr); 
    498  
    499                 if (::connect(socket, (struct sockaddr *)&sa, sizeof(sa)) == -1) 
    500                 { 
    501                         if (::close(socket) == -1) 
    502                         { 
    503                                 throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_CONNECTFROM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    504                         } 
    505  
    506                         socket = -1; 
    507  
    508                         throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_CONNECTFROM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    509                 } 
    510         } 
    511         else 
    512         { 
    513                 struct sockaddr_in6 sa; 
    514                 sa.sin6_family = AF_INET6; 
    515                 sa.sin6_flowinfo = 0; 
    516                 sa.sin6_scope_id = 0; 
    517                 sa.sin6_port = htons(0); 
    518                 inet_pton(AF_INET6, local.c_str(), &sa.sin6_addr); 
    519  
    520                 if (::bind(socket, (struct sockaddr *)&sa, sizeof(sa)) == -1) 
    521                 { 
    522                         throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_CONNECTFROM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    523                 } 
    524  
    525                 sa.sin6_port = htons(port); 
    526                 inet_pton(AF_INET6, host.c_str(), &sa.sin6_addr); 
    527  
    528                 if (::connect(socket, (struct sockaddr *)&sa, sizeof(sa)) == -1) 
    529                 { 
    530                         if (::close(socket) == -1) 
    531                         { 
    532                                 throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_CONNECTFROM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    533                         } 
    534  
    535                         socket = -1; 
    536  
    537                         throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_CONNECTFROM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    538                 } 
    539         } 
    540  
    541         connectSsl(); 
    542  
    543         exchange.init(socket, sslHandle, blocked, blockInherited); 
    544  
    545         socket = -1; 
    546         sslHandle = NULL; 
    547  
    548 #ifndef IO_WO_XEXEC 
    549         performXExec(postExec); 
    550 #endif 
    551 } 
    552  
    553 //------------------------------------------------------------------- 
    554  
    555 void 
    556 client::connect(const dodoString &path, 
    557                                 exchange         &exchange) 
    558 { 
    559 #ifndef IO_WO_XEXEC 
    560         operType = CLIENT_OPERATION_CONNECT_UNIX; 
    561         performXExec(preExec); 
    562 #endif 
    563  
    564         initSsl(); 
    565         makeSocket(); 
    566  
    567         struct sockaddr_un sa; 
    568  
    569         unsigned long size = path.size(); 
    570  
    571         if (size >= 108) 
    572         { 
    573                 throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_CONNECT, exception::ERRNO_LIBDODO, CLIENTEX_LONGPATH, IONETWORKCLIENTEX_LONGPATH_STR, __LINE__, __FILE__); 
    574         } 
    575  
    576         strncpy(sa.sun_path, path.c_str(), size); 
    577         sa.sun_family = AF_UNIX; 
    578  
    579         if (::connect(socket, (struct sockaddr *)&sa, path.size() + sizeof(sa.sun_family)) == -1) 
    580         { 
    581                 if (::close(socket) == -1) 
    582                 { 
    583                         throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_CONNECT, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    584                 } 
    585  
    586                 socket = -1; 
    587  
    588                 throw exception::basic(exception::ERRMODULE_IONETWORKSSLCLIENT, CLIENTEX_CONNECT, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    589         } 
    590  
    591         connectSsl(); 
    592  
    593         exchange.init(socket, sslHandle, blocked, blockInherited); 
    594  
    595         socket = -1; 
    596         sslHandle = NULL; 
    597  
    598 #ifndef IO_WO_XEXEC 
    599         performXExec(postExec); 
    600 #endif 
    601 } 
    602  
    603 //------------------------------------------------------------------- 
    604  
    605 #endif 
    606  
  • trunk/tests/ionetworkhttp_test/test.cc

    r1123 r1185  
    99#include <libdodo/ioNetworkHttp.h> 
    1010#include <libdodo/types.h> 
     11#include <libdodo/cgi.h> 
     12#include <libdodo/toolsFilesystem.h> 
    1113 
    1214#include <iostream> 
Note: See TracChangeset for help on using the changeset viewer.