From 0260a61e5478926ae471fbebf25f2292dfa89f86 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Sun, 19 Mar 2000 19:49:31 +0000 Subject: [PATCH] * Added support for unix domain sockets --- webcit/ChangeLog | 4 +++- webcit/README.txt | 15 +++++++++++-- webcit/tcp_sockets.c | 53 +++++++++++++++++++++++++++++++++++--------- webcit/webcit.c | 12 +++++++++- webcit/webcit.h | 7 +++--- 5 files changed, 73 insertions(+), 18 deletions(-) diff --git a/webcit/ChangeLog b/webcit/ChangeLog index 63eec9c65..5dbaf463d 100644 --- a/webcit/ChangeLog +++ b/webcit/ChangeLog @@ -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 @@ -382,4 +385,3 @@ Sun Dec 6 19:50:55 EST 1998 Art Cancro 1998-12-03 Nathan Bryant * webserver.c: warning fix - diff --git a/webcit/README.txt b/webcit/README.txt index 5d4bdd985..d914c98af 100644 --- a/webcit/README.txt +++ b/webcit/README.txt @@ -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 -------- diff --git a/webcit/tcp_sockets.c b/webcit/tcp_sockets.c index 45de6d70f..8aaf4689d 100644 --- a/webcit/tcp_sockets.c +++ b/webcit/tcp_sockets.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -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); diff --git a/webcit/webcit.c b/webcit/webcit.c index 607448709..fae5530f0 100644 --- a/webcit/webcit.c +++ b/webcit/webcit.c @@ -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(); } diff --git a/webcit/webcit.h b/webcit/webcit.h index db90505e2..b2f6da004 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -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); -- 2.39.2