diff options
author | Richard M. Stallman <rms@gnu.org> | 1996-04-28 19:08:33 +0000 |
---|---|---|
committer | Richard M. Stallman <rms@gnu.org> | 1996-04-28 19:08:33 +0000 |
commit | 122b5ace344ffa634025c87808466bac7e0c9ab1 (patch) | |
tree | 9e9974cface6215c19fd817e4795ec9b1fda0ddf /lib-src | |
parent | 0cebf55daaba9eef84de292db73256f5cdeea0f2 (diff) | |
download | emacs-122b5ace344ffa634025c87808466bac7e0c9ab1.tar.gz |
[WINDOWSNT]: Include winsock.h and ntlib.h.
Macro SOCKET_ERROR undefined.
Don't declare h_errno.
[!WINDOWSNT]: Define macros recv and send.
[!WINDOWSNT] (POP_SERVICE): Change to pop3.
(pop_open) [WINDOWSNT]: Initialize trash_started.
(have_winsock) [WINDOWSNT]: New variable.
(socket_connection) [WINDOWSNT]: Initialize winsock.
(socket_connection): Use closesocket instead of close.
(getline): Use recv instead of read.
(fullwrite): Use send instead of write.
(pop_trash): Use closesocket instead of close.
(pop_trash) [WINDOWSNT]: Cleanup winsock.
Check if being called recursively by sendline.
Diffstat (limited to 'lib-src')
-rw-r--r-- | lib-src/pop.c | 57 |
1 files changed, 48 insertions, 9 deletions
diff --git a/lib-src/pop.c b/lib-src/pop.c index 77d7595801b..ac67abd08b1 100644 --- a/lib-src/pop.c +++ b/lib-src/pop.c @@ -1,5 +1,5 @@ /* pop.c: client routines for talking to a POP3-protocol post-office server - Copyright (c) 1991,1993 Free Software Foundation, Inc. + Copyright (c) 1991, 1993, 1996 Free Software Foundation, Inc. Written by Jonathan Kamens, jik@security.ov.com. This file is part of GNU Emacs. @@ -37,8 +37,17 @@ Boston, MA 02111-1307, USA. */ #endif #include <sys/types.h> +#ifdef WINDOWSNT +#include "ntlib.h" +#include <winsock.h> +#undef SOCKET_ERROR +#else #include <netinet/in.h> #include <sys/socket.h> +#define recv(s,buf,len,flags) read(s,buf,len) +#define send(s,buf,len,flags) write(s,buf,len) +#define closesocket close +#endif #include <pop.h> #ifdef sun @@ -88,9 +97,11 @@ extern char *krb_realmofhost (/* char * */); #endif /* ! KRB5 */ #endif /* KERBEROS */ +#ifndef WINDOWSNT #if !defined(HAVE_H_ERRNO) || !defined(HAVE_CONFIG_H) extern int h_errno; #endif +#endif static int socket_connection (/* char *, int */); static char *getline (/* popserver */); @@ -106,7 +117,11 @@ static char *find_crlf (/* char * */); #define ERROR_MAX 80 /* a pretty arbitrary size */ #define POP_PORT 110 #define KPOP_PORT 1109 +#ifdef WINDOWSNT +#define POP_SERVICE "pop3" /* we don't want the POP2 port! */ +#else #define POP_SERVICE "pop" +#endif #ifdef KERBEROS #ifdef KRB5 #define KPOP_SERVICE "k5pop"; @@ -269,6 +284,7 @@ pop_open (host, username, password, flags) server->buffer_index = 0; server->buffer_size = GETLINE_MIN; server->in_multi = 0; + server->trash_started = 0; if (getok (server)) return (0); @@ -939,6 +955,10 @@ pop_quit (server) return (ret); } +#ifdef WINDOWSNT +static int have_winsock = 0; +#endif + /* * Function: socket_connection * @@ -982,6 +1002,14 @@ socket_connection (host, flags) int try_count = 0; +#ifdef WINDOWSNT + { + WSADATA winsockData; + if (WSAStartup (0x101, &winsockData) == 0) + have_winsock = 1; + } +#endif + do { hostent = gethostbyname (host); @@ -1056,7 +1084,7 @@ socket_connection (host, flags) if (! *hostent->h_addr_list) { - (void) close (sock); + (void) closesocket (sock); strcpy (pop_error, CONNECT_ERROR); strncat (pop_error, strerror (errno), ERROR_MAX - sizeof (CONNECT_ERROR)); @@ -1077,7 +1105,7 @@ socket_connection (host, flags) strcpy (pop_error, KRB_ERROR); strncat (pop_error, error_message (rem), ERROR_MAX - sizeof(KRB_ERROR)); - (void) close (sock); + (void) closesocket (sock); return (-1); } @@ -1134,7 +1162,7 @@ socket_connection (host, flags) if (err_ret) krb5_free_error (err_ret); - (void) close (sock); + (void) closesocket (sock); return (-1); } #else /* ! KRB5 */ @@ -1151,7 +1179,7 @@ socket_connection (host, flags) strcpy (pop_error, KRB_ERROR); strncat (pop_error, krb_err_txt[rem], ERROR_MAX - sizeof (KRB_ERROR)); - (void) close (sock); + (void) closesocket (sock); return (-1); } #endif /* KRB5 */ @@ -1243,8 +1271,8 @@ getline (server) return (0); } } - ret = read (server->file, server->buffer + server->data, - server->buffer_size - server->data - 1); + ret = recv (server->file, server->buffer + server->data, + server->buffer_size - server->data - 1, 0); if (ret < 0) { strcpy (pop_error, GETLINE_ERROR); @@ -1349,7 +1377,7 @@ fullwrite (fd, buf, nbytes) int ret; cp = buf; - while ((ret = write (fd, cp, nbytes)) > 0) + while ((ret = send (fd, cp, nbytes, 0)) > 0) { cp += ret; nbytes -= ret; @@ -1468,10 +1496,16 @@ pop_trash (server) { if (server->file >= 0) { +#ifdef WINDOWSNT + /* avoid recursion; sendline can call pop_trash */ + if (server->trash_started) + return; + server->trash_started = 1; +#endif sendline (server, "RSET"); sendline (server, "QUIT"); - close (server->file); + closesocket (server->file); server->file = -1; if (server->buffer) { @@ -1479,6 +1513,11 @@ pop_trash (server) server->buffer = 0; } } + +#ifdef WINDOWSNT + if (have_winsock) + WSACleanup (); +#endif } /* Return a pointer to the first CRLF in IN_STRING, |