]> granicus.if.org Git - postgresql/blobdiff - src/backend/libpq/pqcomm.c
From: Dan McGuirk <mcguirk@indirect.com>
[postgresql] / src / backend / libpq / pqcomm.c
index f78f4186364cf57a175af08e97df36dd35e96bc5..6b8ecdac28bc0d5673acd6f84ba6ae303324e8d3 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *    $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.4 1996/10/31 10:37:52 scrappy Exp $
+ *    $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.12 1997/03/12 21:17:58 scrappy Exp $
  *
  *-------------------------------------------------------------------------
  */
  *     the postgres backend.
  *
  */
-
-#include "postgres.h"
-
-#include "libpq/pqsignal.h"    /* substitute for <signal.h> */
 #include <stdio.h>
 #include <string.h>
-#ifndef WIN32
+#include <signal.h>
+#include <errno.h>
+#include <fcntl.h>
 #include <unistd.h>            /* for ttyname() */
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netdb.h>
 #include <netinet/in.h>
-#else
-#include <winsock.h>
-#endif /* WIN32 */
-#include <errno.h>
-#include <fcntl.h>
+#include <arpa/inet.h>
 
 #if defined(linux)
 #ifndef SOMAXCONN
 #endif /* SOMAXCONN */
 #endif /* linux */
 
-#include "libpq/auth.h"
-#include "libpq/libpq.h"       /* where the declarations go */
-#include "libpq/pqcomm.h"
+#include <postgres.h>
+
+#include <libpq/pqsignal.h>
+#include <libpq/auth.h>
+#include <libpq/libpq.h>       /* where the declarations go */
 
 /* ----------------
  *     declarations
@@ -77,17 +73,8 @@ int PQAsyncNotifyWaiting;    /* for async. notification */
 void
 pq_init(int fd)
 {
-#ifdef WIN32
-    int in, out;
-
-    in = _open_osfhandle(fd, _O_RDONLY);
-    out = _open_osfhandle(fd, _O_APPEND);
-    Pfin = fdopen(in, "rb");
-    Pfout = fdopen(out, "wb");
-#else
     Pfin = fdopen(fd, "r");
     Pfout = fdopen(dup(fd), "w");
-#endif /* WIN32 */
     if (!Pfin || !Pfout)
        elog(FATAL, "pq_init: Couldn't initialize socket connection");
     PQnotifies_init();
@@ -139,7 +126,7 @@ pq_getport()
     
     if (envport)
        return(atoi(envport));
-    return(atoi(POSTPORT));
+    return(atoi(DEF_PGPORT));
 }
 
 /* --------------------------------
@@ -180,7 +167,7 @@ pq_flush()
 int
 pq_getstr(char *s, int maxlen)
 {
-    int        c;
+    int        c = '\0';
     
     if (Pfin == (FILE *) NULL) {
 /*     elog(DEBUG, "Input descriptor is null"); */
@@ -265,7 +252,7 @@ PQputline(char *s)
 int
 pq_getnchar(char *s, int off, int maxlen)
 {
-    int        c;
+    int        c = '\0';
     
     if (Pfin == (FILE *) NULL) {
 /*     elog(DEBUG, "Input descriptor is null"); */
@@ -487,26 +474,19 @@ pq_getinserv(struct sockaddr_in *sin, char *host, char *serv)
 void
 pq_regoob(void (*fptr)())
 {
-#ifdef WIN32
-    /* Who knows what to do here? */
-    return;
-#else
     int fd = fileno(Pfout);
 #if defined(hpux)
     ioctl(fd, FIOSSAIOOWN, getpid());
 #else /* hpux */
     fcntl(fd, F_SETOWN, getpid());
 #endif /* hpux */
-    (void) signal(SIGURG,fptr);
-#endif /* WIN32 */    
+    (void) pqsignal(SIGURG,fptr);
 }
 
 void
 pq_unregoob()
 {
-#ifndef WIN32
-    signal(SIGURG,SIG_DFL);
-#endif /* WIN32 */    
+    pqsignal(SIGURG,SIG_DFL);
 }
 
 
@@ -554,15 +534,6 @@ StreamServerPort(char *hostName, short portName, int *fdP)
     int                        fd;
     int                 one = 1;
     
-#ifdef WIN32
-    /* This is necessary to make it possible for a backend to use
-    ** stdio to read from the socket.
-    */
-    int optionvalue = SO_SYNCHRONOUS_NONALERT;
-
-    setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, (char *)&optionvalue,
-              sizeof(optionvalue));
-#endif /* WIN32 */
 
     if (! hostName)
        hostName = "localhost";
@@ -648,10 +619,8 @@ StreamConnection(int server_fd, Port *port)
     
     port->mask = 1 << port->sock;
 
-#ifndef WIN32    
     /* reset to non-blocking */
     fcntl(port->sock, F_SETFL, 1);
-#endif /* WIN32 */    
     
     return(STATUS_OK);
 }
@@ -734,3 +703,29 @@ StreamOpen(char *hostName, short portName, Port *port)
     
     return(STATUS_OK);
 }
+
+static char *authentication_type_name[] = {
+    0, 0, 0, 0, 0, 0, 0, 
+    "the default authentication type", 
+    0, 0,
+    "Kerberos v4",
+    "Kerberos v5",
+    "host-based authentication",
+    "unauthenication",
+    "plaintext password authentication"
+};
+
+char *name_of_authentication_type(int type)
+{
+    char *result = 0;
+
+    if(type >= 1 && type <= LAST_AUTHENTICATION_TYPE) {
+       result = authentication_type_name[type];
+    }
+
+    if(result == 0) {
+       result = "<unknown authentication type>";
+    }
+
+    return result;
+}