/[libspopc]/session.c
ViewVC logotype

Diff of /session.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 5 by ben, Thu Dec 10 11:54:10 2009 UTC revision 6 by ben, Sun Apr 18 11:05:58 2010 UTC
# Line 26  Line 26 
26    
27  #ifdef WIN32  #ifdef WIN32
28  #include <winsock.h>  #include <winsock.h>
29  #include <io.h>  #include <stdio.h>
30  #else  #else
31  #include <netdb.h>  #include <netdb.h>
32  #include <unistd.h>  #include <unistd.h>
# Line 66  static int SSL_USE = SSL_USE_AUTO; Line 66  static int SSL_USE = SSL_USE_AUTO;
66    
67    
68  /* let libspopc never use SSL even connecting on port 995 */  /* let libspopc never use SSL even connecting on port 995 */
69  void pop3_ssl_never(void)  DLLIMPORT void pop3_ssl_never(void)
70  {  {
71          SSL_USE = SSL_USE_NEVER;          SSL_USE = SSL_USE_NEVER;
72  }  }
73    
74  /* let libspopc use SSL when connecting port 995 */  /* let libspopc use SSL when connecting port 995 */
75  void pop3_ssl_auto(void)  DLLIMPORT void pop3_ssl_auto(void)
76  {  {
77          SSL_USE = SSL_USE_AUTO;          SSL_USE = SSL_USE_AUTO;
78  }  }
79    
80  /* let libspopc use SSL connecting on any port, even 110 */  /* let libspopc use SSL connecting on any port, even 110 */
81  void pop3_ssl_always(void)  DLLIMPORT void pop3_ssl_always(void)
82  {  {
83          SSL_USE = SSL_USE_ALWAYS;          SSL_USE = SSL_USE_ALWAYS;
84  }  }
85    
86  /* set the filename of the certificate */  /* set the filename of the certificate */
87  void pop3_cert_setup(const char *certfile)  DLLIMPORT void pop3_cert_setup(const char *certfile)
88  {  {
89          if (SSL_CERT) free(SSL_CERT);          if (SSL_CERT) free(SSL_CERT);
90          SSL_CERT=NULL;          SSL_CERT=NULL;
# Line 94  void pop3_cert_setup(const char *certfil Line 94  void pop3_cert_setup(const char *certfil
94  /* callback for error reporting on ssl verification  /* callback for error reporting on ssl verification
95   * just return 0 on error, 1 else   * just return 0 on error, 1 else
96   */   */
97  int ssl_verify_callback(int ok, X509_STORE_CTX *ctx) {  DLLIMPORT int ssl_verify_callback(int ok, X509_STORE_CTX *ctx) {
98          if (!ok) { /* bad identification */          if (!ok) { /* bad identification */
99                  int err;                  int err;
100                  err = X509_STORE_CTX_get_error(ctx);                  err = X509_STORE_CTX_get_error(ctx);
# Line 106  int ssl_verify_callback(int ok, X509_STO Line 106  int ssl_verify_callback(int ok, X509_STO
106  /* init ssl library and context  /* init ssl library and context
107   * depending on port and SSL_USE_*   * depending on port and SSL_USE_*
108   */   */
109  pop3sock_t ssl_prepare(const int port){  DLLIMPORT pop3sock_t ssl_prepare(const int port){
110          pop3sock_t sock;          pop3sock_t sock;
111    
112          sock =(pop3sock_t)malloc(sizeof(pop3sock));          sock =(pop3sock_t)malloc(sizeof(pop3sock));
# Line 173  pop3sock_t ssl_prepare(const int port){ Line 173  pop3sock_t ssl_prepare(const int port){
173   * this way may be either ignored   * this way may be either ignored
174   * or refused on some platform   * or refused on some platform
175   */   */
176  int socket_prepare(int sock){  DLLIMPORT int socket_prepare(int sock){
177          struct timeval tv;          struct timeval tv;
178          int ret=0;          int ret=0;
179          tv.tv_sec = SOCKET_TIMEOUT;          tv.tv_sec = SOCKET_TIMEOUT;
# Line 187  int socket_prepare(int sock){ Line 187  int socket_prepare(int sock){
187  }  }
188    
189  /* prepares the pop session and returns a socket descriptor */  /* prepares the pop session and returns a socket descriptor */
190  pop3sock_t pop3_prepare(const char* servername, const int port, struct sockaddr_in* connection, struct hostent* server){  DLLIMPORT pop3sock_t pop3_prepare(const char* servername, const int port, struct sockaddr_in* connection, struct hostent* server){
191          pop3sock_t sock;          pop3sock_t sock;
192          struct hostent* hostent_buf;          struct hostent* hostent_buf;
193          int i;          int i;
# Line 208  pop3sock_t pop3_prepare(const char* serv Line 208  pop3sock_t pop3_prepare(const char* serv
208          mutex_in(&GETHOSTBYNAME);          mutex_in(&GETHOSTBYNAME);
209          hostent_buf=gethostbyname(servername);          hostent_buf=gethostbyname(servername);
210          if(!hostent_buf){          if(!hostent_buf){
211    #ifdef WIN32
212                    perror("pop3_prepare.gethostbyname");
213    #else
214                  herror("pop3_prepare.gethostbyname");                  herror("pop3_prepare.gethostbyname");
215    #endif
216                  return BAD_SOCK;                  return BAD_SOCK;
217          }          }
218          /* begin hostent deep copy */          /* begin hostent deep copy */
# Line 266  pop3sock_t pop3_prepare(const char* serv Line 270  pop3sock_t pop3_prepare(const char* serv
270  }  }
271    
272  /* connects to the server through the sock and returns server's welcome */  /* connects to the server through the sock and returns server's welcome */
273  char* pop3_connect(pop3sock_t sock, struct sockaddr_in* connection){  DLLIMPORT char* pop3_connect(pop3sock_t sock, struct sockaddr_in* connection){
274          int r;          int r;
275          char* buf;          char* buf;
276    
# Line 320  char* pop3_connect(pop3sock_t sock, stru Line 324  char* pop3_connect(pop3sock_t sock, stru
324          return buf;          return buf;
325  }  }
326    
327  void pop3_disconnect(pop3sock_t sock, struct hostent* server){  DLLIMPORT void pop3_disconnect(pop3sock_t sock, struct hostent* server){
328          int i;          int i;
329          /* close socket  */          /* close socket  */
330  #ifdef USE_SSL  #ifdef USE_SSL

Legend:
Removed from v.5  
changed lines
  Added in v.6

  ViewVC Help
Powered by ViewVC 1.1.26