commit e2028649dc4a9e12fd90c4642dc6b72a34b092cc
parent 9226dae786375b2d3df930119ed13ceb76c56377
Author: nibble <unknown>
Date: Sat, 14 Nov 2009 13:21:39 +0100
* Fixed SSL support (finally :)
* More code refactoring in pop3.c
Diffstat:
2 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/pop3.c b/pop3.c
@@ -22,29 +22,27 @@ static char *getword () {
}
static int waitreply (int res) {
- char result[256];
- char *ch, *str = word;
+ char result[1024];
+ char *ch, *str;
int reply = -1;
- result[0] = '\0';
ftruncate (2, 0);
lseek (2, 0, SEEK_SET);
- do {
- if (sock_read (word, 512) < 1)
- break;
- if (reply==-1) {
+ result[0] = '\0';
+ while (sock_ready () && sock_read (word, 512) > 1) {
+ str = word;
+ if (reply == -1 && (reply = (word[0] == '+'))) {
if ((ch = strchr (str, '\r')) || (ch = strchr (str, '\n'))) {
- reply = (word[0] == '+');
*ch = '\0';
snprintf (result, 1023, "### %s %d \"%s\"\n", cmd, reply, str);
- str = ch+((ch[1]=='\n')?2:1);
+ str = ch + ((ch[1] == '\r' || ch[1] == '\n') ? 2 : 1);
}
}
// TODO: Fix possible \r\n issues
if ((ch = strstr (str, "\r\n.")))
*ch = '\0';
write (2, str, strlen (str));
- } while (sock_ready ());
+ }
write (2, "\n", 1);
if (res) {
if (result[0] == '\0')
diff --git a/sock.c b/sock.c
@@ -19,6 +19,7 @@ static SSL *sfd;
static int fd = -1;
int sock_ssl (int fd) {
+#if HAVE_SSL
// TODO Check certificate
SSL_library_init ();
SSL_load_error_strings ();
@@ -28,7 +29,9 @@ int sock_ssl (int fd) {
SSL_set_fd (sfd, fd);
if (SSL_connect (sfd) < 1)
return -1;
- else return fd;
+ else
+#endif
+ return fd;
}
int sock_connect(const char *host, int port, int ssl_enable) {
@@ -53,11 +56,15 @@ int sock_connect(const char *host, int port, int ssl_enable) {
}
int sock_ready() {
+#if HAVE_SSL
+ if (ssl && SSL_pending (sfd))
+ return 1;
+#endif
struct pollfd fds[1];
fds[0].fd = fd;
fds[0].events = POLLIN|POLLPRI;
fds[0].revents = POLLNVAL|POLLHUP|POLLERR;
- return poll(fds, 1, 100);
+ return poll(fds, 1, 1000);
}
void sock_close() {