changeset 15102:ed550d0805ca

[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.
author Richard M. Stallman <rms@gnu.org>
date Sun, 28 Apr 1996 19:08:33 +0000
parents f86169152e74
children 00d52ba071ea
files lib-src/pop.c
diffstat 1 files changed, 48 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/lib-src/pop.c	Sun Apr 28 19:07:35 1996 +0000
+++ b/lib-src/pop.c	Sun Apr 28 19:08:33 1996 +0000
@@ -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 @@
 #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 @@
 #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 @@
 #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 @@
   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 @@
   return (ret);
 }
 
+#ifdef WINDOWSNT
+static int have_winsock = 0;
+#endif
+
 /*
  * Function: socket_connection
  *
@@ -982,6 +1002,14 @@
 
   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 @@
      
   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 @@
 	  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 @@
 	  if (err_ret)
 	    krb5_free_error (err_ret);
 
-	  (void) close (sock);
+	  (void) closesocket (sock);
 	  return (-1);
 	}
 #else  /* ! KRB5 */	  
@@ -1151,7 +1179,7 @@
 	  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 @@
 	      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 @@
   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 @@
 {
   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 @@
 	  server->buffer = 0;
 	}
     }
+
+#ifdef WINDOWSNT
+  if (have_winsock)
+    WSACleanup ();
+#endif
 }
 
 /* Return a pointer to the first CRLF in IN_STRING,