* Added support for unix domain sockets
authorArt Cancro <ajc@citadel.org>
Sun, 19 Mar 2000 19:49:31 +0000 (19:49 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 19 Mar 2000 19:49:31 +0000 (19:49 +0000)
webcit/ChangeLog
webcit/README.txt
webcit/tcp_sockets.c
webcit/webcit.c
webcit/webcit.h

index 63eec9c656f3651987e5e55214c5b70cc0b36fd0..5dbaf463dbea59792f6a6b1988de93a649e60288 100644 (file)
@@ -1,4 +1,7 @@
 $Log$
+Revision 211.4  2000/03/19 19:49:31  ajc
+* Added support for unix domain sockets
+
 Revision 211.3  2000/02/11 23:45:04  nbryant
 * Makefile.in, configure.in: add, like, some *more* code for FreeBSD
 * tcp_sockets.c: include <arpa/inet.h>
@@ -382,4 +385,3 @@ Sun Dec  6 19:50:55 EST 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
 
 1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
        * webserver.c: warning fix
-
index 5d4bdd98524a6f497f7a77d8e6b39c7a44c2fc3b..d914c98af1eede440980829feeb2003e8f0c5f51 100644 (file)
@@ -1,7 +1,7 @@
                       WEBCIT for the Citadel/UX System
-                               version 2.11
+                               version 2.12
  
-   Copyright (C) 1996-1999 by Art Cancro, Nathan Bryant, and Nick Grossman
+   Copyright (C) 1996-2000 by Art Cancro, Nathan Bryant, and Nick Grossman
 This program is free software released under the terms of the GNU General
 Public License.  Please read COPYING.txt for more licensing information.
  
@@ -56,6 +56,10 @@ the "webserver" program:
   
  webserver [-p localport] [-t tracefile] [remotehost [remoteport]]
  
+   *or*
+ webserver [-p localport] [-t tracefile] uds /your/citadel/directory
  Explained: 
   
   -> localport: the TCP port on which you wish your WebCit server to run.
@@ -75,6 +79,13 @@ the "webserver" program:
   -> remoteport: the port number on which your Citadel/UX server is running.
      The default is port 504, the IANA-designated standard port for Citadel.
  
+  -> "uds" is a keyword which tells WebCit that you wish to connect to a
+     Citadel server running on the same computer, rather than using a TCP/IP
+     socket.  /your/citadel/directory should be set to the actual name of the
+     directory in which you have Citadel installed
+     (such as /usr/local/citadel).  If you run Citadel and WebCit on the same
+     computer, you should set it up this way; it runs a bit faster.
  
  GRAPHICS
  --------
index 45de6d70f522b6a59f8aef4268e955d0072ab556..8aaf4689db51d67bb7ddaa699d282f4fe9b27184 100644 (file)
@@ -20,6 +20,7 @@
 #include <limits.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#include <sys/un.h>
 #include <netdb.h>
 #include <string.h>
 #include <pwd.h>
@@ -39,18 +40,52 @@ RETSIGTYPE timeout(int signum)
        exit(3);
 }
 
-int connectsock(char *host, char *service, char *protocol)
+
+
+/*
+ * Connect a unix domain socket
+ */
+int uds_connectsock(char *sockpath)
+{
+       struct sockaddr_un sun;
+       int s;
+
+       memset(&sun, 0, sizeof(sun));
+       sun.sun_family = AF_UNIX;
+       strncpy(sun.sun_path, sockpath, sizeof sun.sun_path);
+
+       s = socket(AF_UNIX, SOCK_STREAM, 0);
+       if (s < 0) {
+               fprintf(stderr, "Can't create socket: %s\n",
+                       strerror(errno));
+               return(-1);
+       }
+
+       if (connect(s, (struct sockaddr *) &sun, sizeof(sun)) < 0) {
+               fprintf(stderr, "can't connect: %s\n",
+                       strerror(errno));
+               return(-1);
+       }
+
+       return s;
+}
+
+
+/*
+ * Connect a TCP/IP socket
+ */
+int tcp_connectsock(char *host, char *service)
 {
        struct hostent *phe;
        struct servent *pse;
        struct protoent *ppe;
        struct sockaddr_in sin;
-       int s, type;
+       int s;
 
        bzero((char *) &sin, sizeof(sin));
        sin.sin_family = AF_INET;
 
-       pse = getservbyname(service, protocol);
+       pse = getservbyname(service, "tcp");
        if (pse) {
                sin.sin_port = pse->s_port;
        } else if ((sin.sin_port = htons((u_short) atoi(service))) == 0) {
@@ -65,17 +100,13 @@ int connectsock(char *host, char *service, char *protocol)
                        host, strerror(errno));
                return (-1);
        }
-       if ((ppe = getprotobyname(protocol)) == 0) {
-               fprintf(stderr, "Can't get %s protocol entry: %s\n",
-                       protocol, strerror(errno));
+       if ((ppe = getprotobyname("tcp")) == 0) {
+               fprintf(stderr, "Can't get TCP protocol entry: %s\n",
+                       strerror(errno));
                return (-1);
        }
-       if (!strcmp(protocol, "udp"))
-               type = SOCK_DGRAM;
-       else
-               type = SOCK_STREAM;
 
-       s = socket(PF_INET, type, ppe->p_proto);
+       s = socket(PF_INET, SOCK_STREAM, ppe->p_proto);
        if (s < 0) {
                fprintf(stderr, "Can't create socket: %s\n", strerror(errno));
                return (-1);
index 607448709b2e22757ffbf06cf575a20b5c3ebaeb..fae5530f0c0d51c12148ed35c2ec524f2d16762f 100644 (file)
@@ -663,7 +663,17 @@ void session_loop(struct httprequest *req)
                        strcpy(c_host, bstr("host"));
                if (strlen(bstr("port")) > 0)
                        strcpy(c_port, bstr("port"));
-               WC->serv_sock = connectsock(c_host, c_port, "tcp");
+
+               if (!strcasecmp(c_host, "uds")) {
+                       /* unix domain socket */
+                       sprintf(buf, "%s/citadel.socket", c_port);
+                       WC->serv_sock = uds_connectsock(buf);
+               }
+               else {
+                       /* tcp socket */
+                       WC->serv_sock = tcp_connectsock(c_host, c_port);
+               }
+
                if (WC->serv_sock < 0) {
                        do_logout();
                }
index db90505e218962b29b5938300f828ff42deac6be..b2f6da004b19effa37a7631b0c3086d37b59e11b 100644 (file)
@@ -3,10 +3,10 @@
 #define SLEEPING               180             /* TCP connection timeout */
 #define WEBCIT_TIMEOUT         900             /* WebCit session timeout */
 #define PORT_NUM               2000            /* port number to listen on */
-#define SERVER                 "WebCit v2.11"  /* who's in da house */
+#define SERVER                 "WebCit v2.12"  /* who's in da house */
 #define DEVELOPER_ID           0
 #define CLIENT_ID              4
-#define CLIENT_VERSION         211
+#define CLIENT_VERSION         212
 #define DEFAULT_HOST           "localhost"     /* Default Citadel server */
 #define DEFAULT_PORT           "504"
 #define LB                     (1)             /* Internal escape chars */
@@ -154,7 +154,8 @@ void slrp_highest(void);
 void gotonext(void);
 void ungoto(void);
 void get_serv_info(char *, char *);
-int connectsock(char *host, char *service, char *protocol);
+int uds_connectsock(char *);
+int tcp_connectsock(char *, char *);
 void serv_gets(char *strbuf);
 void serv_puts(char *string);
 void whobbs(void);