/[imapfilter]/imapfilter/socket.c
ViewVC logotype

Diff of /imapfilter/socket.c

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

revision 1.12 by lefcha, Sat Nov 10 19:39:22 2001 UTC revision 1.13 by lefcha, Sun Nov 18 13:07:47 2001 UTC
# Line 15  Line 15 
15  #include <openssl/ssl.h>  #include <openssl/ssl.h>
16  #include <openssl/err.h>  #include <openssl/err.h>
17  #include <openssl/x509.h>  #include <openssl/x509.h>
18    #endif
19    
20    
21  static SSL *ssl;  extern long timeout;
 #endif  
22    
23  static int sock;  static int sock;
24    
25    #ifdef SSL_TLS
26    static SSL *ssl;
27    #endif
28    
29    
30  /*  /*
31   * Connect to mail server.   * Connect to mail server.
# Line 43  int init_connection(char *serv, unsigned Line 47  int init_connection(char *serv, unsigned
47          error("imapfilter: create socket; %s\n", strerror(errno));          error("imapfilter: create socket; %s\n", strerror(errno));
48          return ERROR_NETWORK;          return ERROR_NETWORK;
49      }      }
   
50      if (!(he = gethostbyname(serv))) {      if (!(he = gethostbyname(serv))) {
51          error("imapfilter: get network host entry of %s; %s\n", serv,          error("imapfilter: get network host entry of %s; %s\n", serv,
52                strerror(errno));                strerror(errno));
# Line 119  int ssl_init(unsigned int protocol) Line 122  int ssl_init(unsigned int protocol)
122    
123      e = SSL_connect(ssl);      e = SSL_connect(ssl);
124    
125      if (e <= 0) {      if (e < 0) {
126          error("imapfilter: initiating SSL connection; %s",          error("imapfilter: initiating SSL connection; %s",
127                ERR_error_string(e, NULL));                ERR_error_string(e, NULL));
128          return ERROR_SSL;          return ERROR_SSL;
# Line 183  int socket_read(char *buf) Line 186  int socket_read(char *buf)
186      int flags, r, s;      int flags, r, s;
187      fd_set fds;      fd_set fds;
188      struct timeval tv;      struct timeval tv;
189        struct timeval *tvp = NULL;
190    
191      r = 0;      r = 0;
192      s = 1;      s = 1;
193    
194      memset(buf, 0, RESPONSE_BUF);      memset(buf, 0, RESPONSE_BUF);
195    
196      tv.tv_sec = 60;      if (timeout) {
197      tv.tv_usec = 0;          tv.tv_sec = timeout;
198            tv.tv_usec = 0;
199            tvp = &tv;
200        }
201      flags = fcntl(sock, F_GETFL, 0);      flags = fcntl(sock, F_GETFL, 0);
202      fcntl(sock, F_SETFL, flags | O_NONBLOCK);      fcntl(sock, F_SETFL, flags | O_NONBLOCK);
203    
# Line 201  int socket_read(char *buf) Line 207  int socket_read(char *buf)
207  #ifdef SSL_TLS  #ifdef SSL_TLS
208      if (ssl) {      if (ssl) {
209          if (SSL_pending(ssl)          if (SSL_pending(ssl)
210              || ((s = select(sock + 1, &fds, NULL, NULL, &tv)) > 0              || ((s = select(sock + 1, &fds, NULL, NULL, tvp)) > 0
211                  && FD_ISSET(sock, &fds)))                  && FD_ISSET(sock, &fds)))
212              r = SSL_read(ssl, buf, RESPONSE_BUF - 1);              r = SSL_read(ssl, buf, RESPONSE_BUF - 1);
213      } else      } else
214  #endif  #endif
215          if ((s = select(sock + 1, &fds, NULL, NULL, &tv)) > 0          if ((s = select(sock + 1, &fds, NULL, NULL, tvp)) > 0
216              && FD_ISSET(sock, &fds))              && FD_ISSET(sock, &fds))
217          r = read(sock, buf, RESPONSE_BUF - 1);          r = read(sock, buf, RESPONSE_BUF - 1);
218    

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26