client.h

Go to the documentation of this file.
00001 #ifndef _CP_TCP_CLIENT_H
00002 #define _CP_TCP_CLIENT_H
00003 
00013 #ifdef _WINDOWS
00014 #include <winsock2.h>
00015 #endif
00016 
00017 #include "common.h"
00018 
00019 __BEGIN_DECLS
00020 
00021 #include "config.h"
00022 
00023 #include "hashlist.h"
00024 #include "vector.h"
00025 #include "thread.h"
00026 
00027 /* this provides get_client_ssl_ctx */
00028 #include "socket.h"
00029 
00030 #if defined(unix) || defined(__unix__) || defined(__MACH__)
00031 #include <sys/time.h>
00032 #include <netinet/in.h>
00033 #endif
00034 
00035 #ifdef CP_USE_SSL
00036 #include <openssl/ssl.h>
00037 #endif
00038 
00039 #if defined(sun) || defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__)
00040 #include <sys/types.h>
00041 #include <sys/socket.h>
00042 #endif
00043 
00044 #ifdef _WINDOWS
00045 #include "Windows.h"
00046 #include "Winsock.h"
00047 #endif
00048 
00050 #define DEFAULT_CLIENT_TIMEOUT 300
00051 
00053 #define DEFAULT_RETRIES 3
00054 
00056 CPROPS_DLL
00057 void cp_client_init();
00062 CPROPS_DLL
00063 void cp_client_stop_all();
00065 CPROPS_DLL
00066 void cp_client_shutdown();
00067 
00068 #ifdef CP_USE_SSL
00069 CPROPS_DLL
00070 void cp_client_ssl_init();
00071 CPROPS_DLL
00072 void cp_client_ssl_shutdown();
00073 
00074 CPROPS_DLL
00075 char *ssl_verification_error_str(int code);
00076 #endif /* CP_USE_SSL */
00077 
00078 CPROPS_DLL
00079 void cp_client_init();
00080 
00081 CPROPS_DLL
00082 void cp_client_shutdown();
00083 
00087 CPROPS_DLL
00088 void cp_tcp_add_shutdown_callback(void (*cb)(void *), void *prm);
00089 
00090 
00091 CPROPS_DLL
00092 struct _cp_client; /* fwd declaration */
00093 
00098 typedef CPROPS_DLL struct _cp_client
00099 {
00100     int id;                       
00101     struct sockaddr_in *addr;     
00102     struct hostent *hostspec;     
00103     char *host;                   
00104     char *found_host;             
00105     int port;                     
00106     struct timeval timeout;       
00107     struct timeval created;       
00108     unsigned long bytes_read;     
00109     unsigned long bytes_sent;     
00110 #if defined(unix) || defined(__unix__) || defined(__MACH__)
00111     int fd;                       
00112 #else 
00113 #ifdef _WINDOWS
00114     SOCKET fd;
00115 #endif /* _WINDOWS */
00116 #endif /* unix */
00117     int closing;                  
00118     int retry;
00119     void *owner;
00120 #ifdef CP_USE_SSL
00121     int use_ssl;                  
00122     SSL_CTX *ctx;                 
00123     SSL *ssl;                     
00124     X509 *server_certificate;     
00125 #endif /* CP_USE_SSL */
00126 } cp_client;
00127 
00129 CPROPS_DLL
00130 cp_client *cp_client_create(char *host, int port);
00132 CPROPS_DLL
00133 cp_client *cp_client_create_addr(struct sockaddr_in *);
00134 #ifdef CP_USE_SSL
00135 
00136 CPROPS_DLL
00137 cp_client *cp_client_create_ssl(char *host, int port, 
00138                                 char *CA_file, char *CA_path, 
00139                                 int verification_mode);
00141 CPROPS_DLL
00142 cp_client *cp_client_create_ssl_addr(struct sockaddr *,
00143                                      char *CA_file, char *CA_path);
00144 #endif /* CP_USE_SSL */
00145 
00146 CPROPS_DLL
00147 void cp_client_set_timeout(cp_client *client, int sec, int usec);
00149 CPROPS_DLL
00150 void cp_client_set_retry(cp_client *client, int retry_count);
00152 CPROPS_DLL
00153 void cp_client_set_owner(cp_client *client, void *owner);
00168 CPROPS_DLL
00169 int cp_client_connect(cp_client *client);
00170 
00171 #ifdef CP_USE_SSL
00172 
00173 CPROPS_DLL
00174 int cp_client_connect_ssl(cp_client *client);
00175 #endif /* CP_USE_SSL */
00176 
00181 CPROPS_DLL
00182 int cp_client_reopen(cp_client *client, char *host, int port);
00183 
00184 #ifdef CP_USE_SSL
00185 
00186 CPROPS_DLL
00187 X509 *cp_client_get_server_certificate(cp_client *client);
00189 CPROPS_DLL
00190 int cp_client_verify_hostname(cp_client *client);
00191 #endif /* CP_USE_SSL */
00192 
00194 CPROPS_DLL
00195 int cp_client_close(cp_client *client);
00197 CPROPS_DLL
00198 void cp_client_destroy(cp_client *client);
00199 
00200 CPROPS_DLL
00201 int cp_client_read(cp_client *client, char *buf, int len);
00202 CPROPS_DLL
00203 int cp_client_read_string(cp_client *client, cp_string *str, int len);
00204 CPROPS_DLL
00205 int cp_client_write(cp_client *client, char *buf, int len);
00206 CPROPS_DLL
00207 int cp_client_write_string(cp_client *client, cp_string *str);
00208 
00209 __END_DECLS
00210 
00213 #endif /* _CP_TCP_CLIENT_H */

Generated on Mon Dec 5 23:00:21 2011 for cprops by  doxygen 1.4.7