diff options
Diffstat (limited to 'X11/xtrans')
-rw-r--r-- | X11/xtrans/Xtrans.c | 2738 | ||||
-rw-r--r-- | X11/xtrans/Xtrans.h | 900 | ||||
-rw-r--r-- | X11/xtrans/Xtransint.h | 848 | ||||
-rw-r--r-- | X11/xtrans/configure.ac | 128 | ||||
-rw-r--r-- | X11/xtrans/doc/Makefile.am | 26 | ||||
-rw-r--r-- | X11/xtrans/transport.c | 156 |
6 files changed, 2398 insertions, 2398 deletions
diff --git a/X11/xtrans/Xtrans.c b/X11/xtrans/Xtrans.c index caf1ff68e..895b707f1 100644 --- a/X11/xtrans/Xtrans.c +++ b/X11/xtrans/Xtrans.c @@ -1,1369 +1,1369 @@ -/*
-
-Copyright 1993, 1994, 1998 The Open Group
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation.
-
-The above copyright notice and this permission notice shall be included
-in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
-OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall
-not be used in advertising or otherwise to promote the sale, use or
-other dealings in this Software without prior written authorization
-from The Open Group.
-
- * Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
- *
- * All Rights Reserved
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name NCR not be used in advertising
- * or publicity pertaining to distribution of the software without specific,
- * written prior permission. NCR makes no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- *
- * NCR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
- * NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
- * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
- * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <ctype.h>
-#include <unistd.h>
-
-#ifdef _MSC_VER
-#include <X11\Xwinsock.h>
-#endif
-/*
- * The transport table contains a definition for every transport (protocol)
- * family. All operations that can be made on the transport go through this
- * table.
- *
- * Each transport is assigned a unique transport id.
- *
- * New transports can be added by adding an entry in this table.
- * For compatiblity, the transport ids should never be renumbered.
- * Always add to the end of the list.
- */
-
-#define TRANS_TLI_INET_INDEX 1
-#define TRANS_TLI_TCP_INDEX 2
-#define TRANS_TLI_TLI_INDEX 3
-#define TRANS_SOCKET_UNIX_INDEX 4
-#define TRANS_SOCKET_LOCAL_INDEX 5
-#define TRANS_SOCKET_INET_INDEX 6
-#define TRANS_SOCKET_TCP_INDEX 7
-#define TRANS_DNET_INDEX 8
-#define TRANS_LOCAL_LOCAL_INDEX 9
-#define TRANS_LOCAL_PTS_INDEX 10
-#define TRANS_LOCAL_NAMED_INDEX 11
-/* 12 used to be ISC, but that's gone. */
-#define TRANS_LOCAL_SCO_INDEX 13
-#define TRANS_SOCKET_INET6_INDEX 14
-#define TRANS_LOCAL_PIPE_INDEX 15
-
-
-static
-Xtransport_table Xtransports[] = {
-#if defined(STREAMSCONN)
- { &TRANS(TLITCPFuncs), TRANS_TLI_TCP_INDEX },
- { &TRANS(TLIINETFuncs), TRANS_TLI_INET_INDEX },
- { &TRANS(TLITLIFuncs), TRANS_TLI_TLI_INDEX },
-#endif /* STREAMSCONN */
-#if defined(TCPCONN)
- { &TRANS(SocketTCPFuncs), TRANS_SOCKET_TCP_INDEX },
-#if defined(IPv6) && defined(AF_INET6)
- { &TRANS(SocketINET6Funcs), TRANS_SOCKET_INET6_INDEX },
-#endif /* IPv6 */
- { &TRANS(SocketINETFuncs), TRANS_SOCKET_INET_INDEX },
-#endif /* TCPCONN */
-#if defined(UNIXCONN)
-#if !defined(LOCALCONN)
- { &TRANS(SocketLocalFuncs), TRANS_SOCKET_LOCAL_INDEX },
-#endif /* !LOCALCONN */
- { &TRANS(SocketUNIXFuncs), TRANS_SOCKET_UNIX_INDEX },
-#endif /* UNIXCONN */
-#if defined(LOCALCONN)
- { &TRANS(LocalFuncs), TRANS_LOCAL_LOCAL_INDEX },
-#ifndef sun
- { &TRANS(PTSFuncs), TRANS_LOCAL_PTS_INDEX },
-#endif /* sun */
-#if defined(SVR4) || defined(__SVR4)
- { &TRANS(NAMEDFuncs), TRANS_LOCAL_NAMED_INDEX },
-#endif
-#ifdef sun
- { &TRANS(PIPEFuncs), TRANS_LOCAL_PIPE_INDEX },
-#endif /* sun */
-#if defined(__SCO__) || defined(__UNIXWARE__)
- { &TRANS(SCOFuncs), TRANS_LOCAL_SCO_INDEX },
-#endif /* __SCO__ || __UNIXWARE__ */
-#endif /* LOCALCONN */
- { NULL, 0}
-};
-
-#define NUMTRANS (sizeof(Xtransports)/sizeof(Xtransport_table)-1)
-
-
-#ifdef WIN32
-#define ioctl ioctlsocket
-#endif
-
-
-
-/*
- * These are a few utility function used by the public interface functions.
- */
-
-void
-TRANS(FreeConnInfo) (XtransConnInfo ciptr)
-
-{
- PRMSG (3,"FreeConnInfo(%p)\n", ciptr, 0, 0);
-
- if (ciptr->addr)
- xfree (ciptr->addr);
-
- if (ciptr->peeraddr)
- xfree (ciptr->peeraddr);
-
- if (ciptr->port)
- xfree (ciptr->port);
-
- xfree ((char *) ciptr);
-}
-
-
-#define PROTOBUFSIZE 20
-
-static Xtransport *
-TRANS(SelectTransport) (char *protocol)
-
-{
- char protobuf[PROTOBUFSIZE];
- int i;
-
- PRMSG (3,"SelectTransport(%s)\n", protocol, 0, 0);
-
- /*
- * Force Protocol to be lowercase as a way of doing
- * a case insensitive match.
- */
-
- strncpy (protobuf, protocol, PROTOBUFSIZE - 1);
- protobuf[PROTOBUFSIZE-1] = '\0';
-
- for (i = 0; i < PROTOBUFSIZE && protobuf[i] != '\0'; i++)
- if (isupper (protobuf[i]))
- protobuf[i] = tolower (protobuf[i]);
-
- /* Look at all of the configured protocols */
-
- for (i = 0; i < NUMTRANS; i++)
- {
- if (!strcmp (protobuf, Xtransports[i].transport->TransName))
- return Xtransports[i].transport;
- }
-
- return NULL;
-}
-
-#ifndef TEST_t
-static
-#endif /* TEST_t */
-int
-TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
-
-{
- /*
- * For the font library, the address is a string formatted
- * as "protocol/host:port[/catalogue]". Note that the catologue
- * is optional. At this time, the catologue info is ignored, but
- * we have to parse it anyways.
- *
- * Other than fontlib, the address is a string formatted
- * as "protocol/host:port".
- *
- * If the protocol part is missing, then assume TCP.
- * If the protocol part and host part are missing, then assume local.
- * If a "::" is found then assume DNET.
- */
-
- char *mybuf, *tmpptr;
- char *_protocol, *_host, *_port;
- char hostnamebuf[256];
- int _host_len;
-
- PRMSG (3,"ParseAddress(%s)\n", address, 0, 0);
-
- /* Copy the string so it can be changed */
-
- tmpptr = mybuf = (char *) xalloc (strlen (address) + 1);
- strcpy (mybuf, address);
-
- /* Parse the string to get each component */
-
- /* Get the protocol part */
-
- _protocol = mybuf;
-
-
- if ( ((mybuf = strchr (mybuf,'/')) == NULL) &&
- ((mybuf = strrchr (tmpptr,':')) == NULL) )
- {
- /* address is in a bad format */
- *protocol = NULL;
- *host = NULL;
- *port = NULL;
- xfree (tmpptr);
- return 0;
- }
-
- if (*mybuf == ':')
- {
- /*
- * If there is a hostname, then assume tcp, otherwise
- * it must be local.
- */
- if (mybuf == tmpptr)
- {
- /* There is neither a protocol or host specified */
- _protocol = "local";
- }
- else
- {
- /* There is a hostname specified */
- _protocol = "tcp";
- mybuf = tmpptr; /* reset to the begining of the host ptr */
- }
- }
- else
- {
- /* *mybuf == '/' */
-
- *mybuf ++= '\0'; /* put a null at the end of the protocol */
-
- if (strlen(_protocol) == 0)
- {
- /*
- * If there is a hostname, then assume tcp, otherwise
- * it must be local.
- */
- if (*mybuf != ':')
- _protocol = "tcp";
- else
- _protocol = "local";
- }
- }
-
- /* Get the host part */
-
- _host = mybuf;
-
- if ((mybuf = strrchr (mybuf,':')) == NULL)
- {
- *protocol = NULL;
- *host = NULL;
- *port = NULL;
- xfree (tmpptr);
- return 0;
- }
-
- *mybuf ++= '\0';
-
- _host_len = strlen(_host);
- if (_host_len == 0)
- {
- TRANS(GetHostname) (hostnamebuf, sizeof (hostnamebuf));
- _host = hostnamebuf;
- }
-#if defined(IPv6) && defined(AF_INET6)
- /* hostname in IPv6 [numeric_addr]:0 form? */
- else if ( (_host_len > 3) &&
- ((strcmp(_protocol, "tcp") == 0) || (strcmp(_protocol, "inet6") == 0))
- && (*_host == '[') && (*(_host + _host_len - 1) == ']') ) {
- struct sockaddr_in6 sin6;
-
- *(_host + _host_len - 1) = '\0';
-
- /* Verify address is valid IPv6 numeric form */
- if (inet_pton(AF_INET6, _host + 1, &sin6) == 1) {
- /* It is. Use it as such. */
- _host++;
- _protocol = "inet6";
- } else {
- /* It's not, restore it just in case some other code can use it. */
- *(_host + _host_len - 1) = ']';
- }
- }
-#endif
-
-
- /* Get the port */
-
- _port = mybuf;
-
-#if defined(FONT_t) || defined(FS_t)
- /*
- * Is there an optional catalogue list?
- */
-
- if ((mybuf = strchr (mybuf,'/')) != NULL)
- *mybuf ++= '\0';
-
- /*
- * The rest, if any, is the (currently unused) catalogue list.
- *
- * _catalogue = mybuf;
- */
-#endif
-
-#ifdef HAVE_LAUNCHD
- /* launchd sockets will look like 'local//tmp/launch-XgkNns/:0' */
- if(address != NULL && strlen(address)>8 && (!strncmp(address,"local//",7))) {
- _protocol="local";
- _host="";
- _port=address+6;
- }
-#endif
-
- /*
- * Now that we have all of the components, allocate new
- * string space for them.
- */
-
- if ((*protocol = (char *) xalloc(strlen (_protocol) + 1)) == NULL)
- {
- /* Malloc failed */
- *port = NULL;
- *host = NULL;
- *protocol = NULL;
- xfree (tmpptr);
- return 0;
- }
- else
- strcpy (*protocol, _protocol);
-
- if ((*host = (char *) xalloc (strlen (_host) + 1)) == NULL)
- {
- /* Malloc failed */
- *port = NULL;
- *host = NULL;
- xfree (*protocol);
- *protocol = NULL;
- xfree (tmpptr);
- return 0;
- }
- else
- strcpy (*host, _host);
-
- if ((*port = (char *) xalloc (strlen (_port) + 1)) == NULL)
- {
- /* Malloc failed */
- *port = NULL;
- xfree (*host);
- *host = NULL;
- xfree (*protocol);
- *protocol = NULL;
- xfree (tmpptr);
- return 0;
- }
- else
- strcpy (*port, _port);
-
- xfree (tmpptr);
-
- return 1;
-}
-
-
-/*
- * TRANS(Open) does all of the real work opening a connection. The only
- * funny part about this is the type parameter which is used to decide which
- * type of open to perform.
- */
-
-static XtransConnInfo
-TRANS(Open) (int type, char *address)
-
-{
- char *protocol = NULL, *host = NULL, *port = NULL;
- XtransConnInfo ciptr = NULL;
- Xtransport *thistrans;
-
- PRMSG (2,"Open(%d,%s)\n", type, address, 0);
-
-#if defined(WIN32) && defined(TCPCONN)
- if (TRANS(WSAStartup)())
- {
- PRMSG (1,"Open: WSAStartup failed\n", 0, 0, 0);
- return NULL;
- }
-#endif
-
- /* Parse the Address */
-
- if (TRANS(ParseAddress) (address, &protocol, &host, &port) == 0)
- {
- PRMSG (1,"Open: Unable to Parse address %s\n", address, 0, 0);
- return NULL;
- }
-
- /* Determine the transport type */
-
- if ((thistrans = TRANS(SelectTransport) (protocol)) == NULL)
- {
- PRMSG (1,"Open: Unable to find transport for %s\n",
- protocol, 0, 0);
-
- xfree (protocol);
- xfree (host);
- xfree (port);
- return NULL;
- }
-
- /* Open the transport */
-
- switch (type)
- {
- case XTRANS_OPEN_COTS_CLIENT:
-#ifdef TRANS_CLIENT
- ciptr = thistrans->OpenCOTSClient(thistrans, protocol, host, port);
-#endif /* TRANS_CLIENT */
- break;
- case XTRANS_OPEN_COTS_SERVER:
-#ifdef TRANS_SERVER
- ciptr = thistrans->OpenCOTSServer(thistrans, protocol, host, port);
-#endif /* TRANS_SERVER */
- break;
- case XTRANS_OPEN_CLTS_CLIENT:
-#ifdef TRANS_CLIENT
- ciptr = thistrans->OpenCLTSClient(thistrans, protocol, host, port);
-#endif /* TRANS_CLIENT */
- break;
- case XTRANS_OPEN_CLTS_SERVER:
-#ifdef TRANS_SERVER
- ciptr = thistrans->OpenCLTSServer(thistrans, protocol, host, port);
-#endif /* TRANS_SERVER */
- break;
- default:
- PRMSG (1,"Open: Unknown Open type %d\n", type, 0, 0);
- }
-
- if (ciptr == NULL)
- {
- if (!(thistrans->flags & TRANS_DISABLED))
- {
- PRMSG (1,"Open: transport open failed for %s/%s:%s\n",
- protocol, host, port);
- }
- xfree (protocol);
- xfree (host);
- xfree (port);
- return NULL;
- }
-
- ciptr->transptr = thistrans;
- ciptr->port = port; /* We need this for TRANS(Reopen) */
-
- xfree (protocol);
- xfree (host);
-
- return ciptr;
-}
-
-
-#ifdef TRANS_REOPEN
-
-/*
- * We might want to create an XtransConnInfo object based on a previously
- * opened connection. For example, the font server may clone itself and
- * pass file descriptors to the parent.
- */
-
-static XtransConnInfo
-TRANS(Reopen) (int type, int trans_id, int fd, char *port)
-
-{
- XtransConnInfo ciptr = NULL;
- Xtransport *thistrans = NULL;
- char *save_port;
- int i;
-
- PRMSG (2,"Reopen(%d,%d,%s)\n", trans_id, fd, port);
-
- /* Determine the transport type */
-
- for (i = 0; i < NUMTRANS; i++)
- if (Xtransports[i].transport_id == trans_id)
- {
- thistrans = Xtransports[i].transport;
- break;
- }
-
- if (thistrans == NULL)
- {
- PRMSG (1,"Reopen: Unable to find transport id %d\n",
- trans_id, 0, 0);
-
- return NULL;
- }
-
- if ((save_port = (char *) xalloc (strlen (port) + 1)) == NULL)
- {
- PRMSG (1,"Reopen: Unable to malloc port string\n", 0, 0, 0);
-
- return NULL;
- }
-
- strcpy (save_port, port);
-
- /* Get a new XtransConnInfo object */
-
- switch (type)
- {
- case XTRANS_OPEN_COTS_SERVER:
- ciptr = thistrans->ReopenCOTSServer(thistrans, fd, port);
- break;
- case XTRANS_OPEN_CLTS_SERVER:
- ciptr = thistrans->ReopenCLTSServer(thistrans, fd, port);
- break;
- default:
- PRMSG (1,"Reopen: Bad Open type %d\n", type, 0, 0);
- }
-
- if (ciptr == NULL)
- {
- PRMSG (1,"Reopen: transport open failed\n", 0, 0, 0);
- return NULL;
- }
-
- ciptr->transptr = thistrans;
- ciptr->port = save_port;
-
- return ciptr;
-}
-
-#endif /* TRANS_REOPEN */
-
-
-
-/*
- * These are the public interfaces to this Transport interface.
- * These are the only functions that should have knowledge of the transport
- * table.
- */
-
-#ifdef TRANS_CLIENT
-
-XtransConnInfo
-TRANS(OpenCOTSClient) (char *address)
-
-{
- PRMSG (2,"OpenCOTSClient(%s)\n", address, 0, 0);
- return TRANS(Open) (XTRANS_OPEN_COTS_CLIENT, address);
-}
-
-#endif /* TRANS_CLIENT */
-
-
-#ifdef TRANS_SERVER
-
-XtransConnInfo
-TRANS(OpenCOTSServer) (char *address)
-
-{
- PRMSG (2,"OpenCOTSServer(%s)\n", address, 0, 0);
- return TRANS(Open) (XTRANS_OPEN_COTS_SERVER, address);
-}
-
-#endif /* TRANS_SERVER */
-
-
-#ifdef TRANS_CLIENT
-
-XtransConnInfo
-TRANS(OpenCLTSClient) (char *address)
-
-{
- PRMSG (2,"OpenCLTSClient(%s)\n", address, 0, 0);
- return TRANS(Open) (XTRANS_OPEN_CLTS_CLIENT, address);
-}
-
-#endif /* TRANS_CLIENT */
-
-
-#ifdef TRANS_SERVER
-
-XtransConnInfo
-TRANS(OpenCLTSServer) (char *address)
-
-{
- PRMSG (2,"OpenCLTSServer(%s)\n", address, 0, 0);
- return TRANS(Open) (XTRANS_OPEN_CLTS_SERVER, address);
-}
-
-#endif /* TRANS_SERVER */
-
-
-#ifdef TRANS_REOPEN
-
-XtransConnInfo
-TRANS(ReopenCOTSServer) (int trans_id, int fd, char *port)
-
-{
- PRMSG (2,"ReopenCOTSServer(%d, %d, %s)\n", trans_id, fd, port);
- return TRANS(Reopen) (XTRANS_OPEN_COTS_SERVER, trans_id, fd, port);
-}
-
-XtransConnInfo
-TRANS(ReopenCLTSServer) (int trans_id, int fd, char *port)
-
-{
- PRMSG (2,"ReopenCLTSServer(%d, %d, %s)\n", trans_id, fd, port);
- return TRANS(Reopen) (XTRANS_OPEN_CLTS_SERVER, trans_id, fd, port);
-}
-
-
-int
-TRANS(GetReopenInfo) (XtransConnInfo ciptr,
- int *trans_id, int *fd, char **port)
-
-{
- int i;
-
- for (i = 0; i < NUMTRANS; i++)
- if (Xtransports[i].transport == ciptr->transptr)
- {
- *trans_id = Xtransports[i].transport_id;
- *fd = ciptr->fd;
-
- if ((*port = (char *) xalloc (strlen (ciptr->port) + 1)) == NULL)
- return 0;
- else
- {
- strcpy (*port, ciptr->port);
- return 1;
- }
- }
-
- return 0;
-}
-
-#endif /* TRANS_REOPEN */
-
-
-int
-TRANS(SetOption) (XtransConnInfo ciptr, int option, int arg)
-
-{
- int fd = ciptr->fd;
- int ret = 0;
-
- PRMSG (2,"SetOption(%d,%d,%d)\n", fd, option, arg);
-
- /*
- * For now, all transport type use the same stuff for setting options.
- * As long as this is true, we can put the common code here. Once a more
- * complicated transport such as shared memory or an OSI implementation
- * that uses the session and application libraries is implemented, this
- * code may have to move to a transport dependent function.
- *
- * ret = ciptr->transptr->SetOption (ciptr, option, arg);
- */
-
- switch (option)
- {
- case TRANS_NONBLOCKING:
- switch (arg)
- {
- case 0:
- /* Set to blocking mode */
- break;
- case 1: /* Set to non-blocking mode */
-
-#if defined(O_NONBLOCK) && !defined(SCO325)
- ret = fcntl (fd, F_GETFL, 0);
- if (ret != -1)
- ret = fcntl (fd, F_SETFL, ret | O_NONBLOCK);
-#else
-#ifdef FIOSNBIO
- {
- int arg;
- arg = 1;
- ret = ioctl (fd, FIOSNBIO, &arg);
- }
-#else
-#if defined(WIN32)
- {
-#ifdef WIN32
- unsigned long arg;
-#else
- int arg;
-#endif
- arg = 1;
-/* IBM TCP/IP understands this option too well: it causes TRANS(Read) to fail
- * eventually with EWOULDBLOCK */
- ret = ioctl (fd, FIONBIO, &arg);
- }
-#else
- ret = fcntl (fd, F_GETFL, 0);
-#ifdef FNDELAY
- ret = fcntl (fd, F_SETFL, ret | FNDELAY);
-#else
- ret = fcntl (fd, F_SETFL, ret | O_NDELAY);
-#endif
-#endif /* AIXV3 || uniosu */
-#endif /* FIOSNBIO */
-#endif /* O_NONBLOCK */
- break;
- default:
- /* Unknown option */
- break;
- }
- break;
- case TRANS_CLOSEONEXEC:
-#ifdef F_SETFD
-#ifdef FD_CLOEXEC
- ret = fcntl (fd, F_SETFD, FD_CLOEXEC);
-#else
- ret = fcntl (fd, F_SETFD, 1);
-#endif /* FD_CLOEXEC */
-#endif /* F_SETFD */
- break;
- }
-
- return ret;
-}
-
-#ifdef TRANS_SERVER
-
-int
-TRANS(CreateListener) (XtransConnInfo ciptr, char *port, unsigned int flags)
-
-{
- return ciptr->transptr->CreateListener (ciptr, port, flags);
-}
-
-int
-TRANS(NoListen) (char * protocol)
-
-{
- Xtransport *trans;
- int i = 0, ret = 0;
-
- if ((trans = TRANS(SelectTransport)(protocol)) == NULL)
- {
- PRMSG (1,"TransNoListen: unable to find transport: %s\n",
- protocol, 0, 0);
-
- return -1;
- }
- if (trans->flags & TRANS_ALIAS) {
- if (trans->nolisten)
- while (trans->nolisten[i]) {
- ret |= TRANS(NoListen)(trans->nolisten[i]);
- i++;
- }
- }
-
- trans->flags |= TRANS_NOLISTEN;
- return ret;
-}
-
-int
-TRANS(ResetListener) (XtransConnInfo ciptr)
-
-{
- if (ciptr->transptr->ResetListener)
- return ciptr->transptr->ResetListener (ciptr);
- else
- return TRANS_RESET_NOOP;
-}
-
-
-XtransConnInfo
-TRANS(Accept) (XtransConnInfo ciptr, int *status)
-
-{
- XtransConnInfo newciptr;
-
- PRMSG (2,"Accept(%d)\n", ciptr->fd, 0, 0);
-
- newciptr = ciptr->transptr->Accept (ciptr, status);
-
- if (newciptr)
- newciptr->transptr = ciptr->transptr;
-
- return newciptr;
-}
-
-#endif /* TRANS_SERVER */
-
-
-#ifdef TRANS_CLIENT
-
-int
-TRANS(Connect) (XtransConnInfo ciptr, char *address)
-
-{
- char *protocol;
- char *host;
- char *port;
- int ret;
-
- PRMSG (2,"Connect(%d,%s)\n", ciptr->fd, address, 0);
-
- if (TRANS(ParseAddress) (address, &protocol, &host, &port) == 0)
- {
- PRMSG (1,"Connect: Unable to Parse address %s\n",
- address, 0, 0);
- return -1;
- }
-
-#ifdef HAVE_LAUNCHD
- if (!host) host=strdup("");
-#endif
-
- if (!port || !*port)
- {
- PRMSG (1,"Connect: Missing port specification in %s\n",
- address, 0, 0);
- if (protocol) xfree (protocol);
- if (host) xfree (host);
- return -1;
- }
-
- ret = ciptr->transptr->Connect (ciptr, host, port);
-
- if (protocol) xfree (protocol);
- if (host) xfree (host);
- if (port) xfree (port);
-
- return ret;
-}
-
-#endif /* TRANS_CLIENT */
-
-
-int
-TRANS(BytesReadable) (XtransConnInfo ciptr, BytesReadable_t *pend)
-
-{
- return ciptr->transptr->BytesReadable (ciptr, pend);
-}
-
-int
-TRANS(Read) (XtransConnInfo ciptr, char *buf, int size)
-
-{
- return ciptr->transptr->Read (ciptr, buf, size);
-}
-
-int
-TRANS(Write) (XtransConnInfo ciptr, char *buf, int size)
-
-{
- return ciptr->transptr->Write (ciptr, buf, size);
-}
-
-int
-TRANS(Readv) (XtransConnInfo ciptr, struct iovec *buf, int size)
-
-{
- return ciptr->transptr->Readv (ciptr, buf, size);
-}
-
-int
-TRANS(Writev) (XtransConnInfo ciptr, struct iovec *buf, int size)
-
-{
- return ciptr->transptr->Writev (ciptr, buf, size);
-}
-
-int
-TRANS(Disconnect) (XtransConnInfo ciptr)
-
-{
- return ciptr->transptr->Disconnect (ciptr);
-}
-
-int
-TRANS(Close) (XtransConnInfo ciptr)
-
-{
- int ret;
-
- PRMSG (2,"Close(%d)\n", ciptr->fd, 0, 0);
-
- ret = ciptr->transptr->Close (ciptr);
-
- TRANS(FreeConnInfo) (ciptr);
-
- return ret;
-}
-
-int
-TRANS(CloseForCloning) (XtransConnInfo ciptr)
-
-{
- int ret;
-
- PRMSG (2,"CloseForCloning(%d)\n", ciptr->fd, 0, 0);
-
- ret = ciptr->transptr->CloseForCloning (ciptr);
-
- TRANS(FreeConnInfo) (ciptr);
-
- return ret;
-}
-
-int
-TRANS(IsLocal) (XtransConnInfo ciptr)
-
-{
- return (ciptr->family == AF_UNIX);
-}
-
-
-int
-TRANS(GetMyAddr) (XtransConnInfo ciptr, int *familyp, int *addrlenp,
- Xtransaddr **addrp)
-
-{
- PRMSG (2,"GetMyAddr(%d)\n", ciptr->fd, 0, 0);
-
- *familyp = ciptr->family;
- *addrlenp = ciptr->addrlen;
-
- if ((*addrp = (Xtransaddr *) xalloc (ciptr->addrlen)) == NULL)
- {
- PRMSG (1,"GetMyAddr: malloc failed\n", 0, 0, 0);
- return -1;
- }
- memcpy(*addrp, ciptr->addr, ciptr->addrlen);
-
- return 0;
-}
-
-int
-TRANS(GetPeerAddr) (XtransConnInfo ciptr, int *familyp, int *addrlenp,
- Xtransaddr **addrp)
-
-{
- PRMSG (2,"GetPeerAddr(%d)\n", ciptr->fd, 0, 0);
-
- *familyp = ciptr->family;
- *addrlenp = ciptr->peeraddrlen;
-
- if ((*addrp = (Xtransaddr *) xalloc (ciptr->peeraddrlen)) == NULL)
- {
- PRMSG (1,"GetPeerAddr: malloc failed\n", 0, 0, 0);
- return -1;
- }
- memcpy(*addrp, ciptr->peeraddr, ciptr->peeraddrlen);
-
- return 0;
-}
-
-
-int
-TRANS(GetConnectionNumber) (XtransConnInfo ciptr)
-
-{
- return ciptr->fd;
-}
-
-
-/*
- * These functions are really utility functions, but they require knowledge
- * of the internal data structures, so they have to be part of the Transport
- * Independant API.
- */
-
-#ifdef TRANS_SERVER
-
-static int
-complete_network_count (void)
-
-{
- int count = 0;
- int found_local = 0;
- int i;
-
- /*
- * For a complete network, we only need one LOCALCONN transport to work
- */
-
- for (i = 0; i < NUMTRANS; i++)
- {
- if (Xtransports[i].transport->flags & TRANS_ALIAS
- || Xtransports[i].transport->flags & TRANS_NOLISTEN)
- continue;
-
- if (Xtransports[i].transport->flags & TRANS_LOCAL)
- found_local = 1;
- else
- count++;
- }
-
- return (count + found_local);
-}
-
-
-#ifdef XQUARTZ_EXPORTS_LAUNCHD_FD
-extern int xquartz_launchd_fd;
-#endif
-
-int
-TRANS(MakeAllCOTSServerListeners) (char *port, int *partial, int *count_ret,
- XtransConnInfo **ciptrs_ret)
-
-{
- char buffer[256]; /* ??? What size ?? */
- XtransConnInfo ciptr, temp_ciptrs[NUMTRANS];
- int status, i, j;
-
-#if defined(IPv6) && defined(AF_INET6)
- int ipv6_succ = 0;
-#endif
- PRMSG (2,"MakeAllCOTSServerListeners(%s,%p)\n",
- port ? port : "NULL", ciptrs_ret, 0);
-
- *count_ret = 0;
-
-#ifdef XQUARTZ_EXPORTS_LAUNCHD_FD
- fprintf(stderr, "Launchd socket fd: %d\n", xquartz_launchd_fd);
- if(xquartz_launchd_fd != -1) {
- if((ciptr = TRANS(ReopenCOTSServer(TRANS_SOCKET_LOCAL_INDEX,
- xquartz_launchd_fd, getenv("DISPLAY"))))==NULL)
- fprintf(stderr,"Got NULL while trying to Reopen launchd port\n");
- else
- temp_ciptrs[(*count_ret)++] = ciptr;
- }
-#endif
-
- for (i = 0; i < NUMTRANS; i++)
- {
- Xtransport *trans = Xtransports[i].transport;
- unsigned int flags = 0;
-
- if (trans->flags&TRANS_ALIAS || trans->flags&TRANS_NOLISTEN)
- continue;
-
- snprintf(buffer, sizeof(buffer), "%s/:%s",
- trans->TransName, port ? port : "");
-
- PRMSG (5,"MakeAllCOTSServerListeners: opening %s\n",
- buffer, 0, 0);
-
- if ((ciptr = TRANS(OpenCOTSServer(buffer))) == NULL)
- {
- if (trans->flags & TRANS_DISABLED)
- continue;
-
- PRMSG (1,
- "MakeAllCOTSServerListeners: failed to open listener for %s\n",
- trans->TransName, 0, 0);
- continue;
- }
-#if defined(IPv6) && defined(AF_INET6)
- if ((Xtransports[i].transport_id == TRANS_SOCKET_INET_INDEX
- && ipv6_succ))
- flags |= ADDR_IN_USE_ALLOWED;
-#endif
-
- if ((status = TRANS(CreateListener (ciptr, port, flags))) < 0)
- {
- if (status == TRANS_ADDR_IN_USE)
- {
- /*
- * We failed to bind to the specified address because the
- * address is in use. It must be that a server is already
- * running at this address, and this function should fail.
- */
-
- PRMSG (1,
- "MakeAllCOTSServerListeners: server already running\n",
- 0, 0, 0);
-
- for (j = 0; j < *count_ret; j++)
- TRANS(Close) (temp_ciptrs[j]);
-
- *count_ret = 0;
- *ciptrs_ret = NULL;
- *partial = 0;
- return -1;
- }
- else
- {
- PRMSG (1,
- "MakeAllCOTSServerListeners: failed to create listener for %s\n",
- trans->TransName, 0, 0);
-
- continue;
- }
- }
-
-#if defined(IPv6) && defined(AF_INET6)
- if (Xtransports[i].transport_id == TRANS_SOCKET_INET6_INDEX)
- ipv6_succ = 1;
-#endif
-
- PRMSG (5,
- "MakeAllCOTSServerListeners: opened listener for %s, %d\n",
- trans->TransName, ciptr->fd, 0);
-
- temp_ciptrs[*count_ret] = ciptr;
- (*count_ret)++;
- }
-
- *partial = (*count_ret < complete_network_count());
-
- PRMSG (5,
- "MakeAllCOTSServerListeners: partial=%d, actual=%d, complete=%d \n",
- *partial, *count_ret, complete_network_count());
-
- if (*count_ret > 0)
- {
- if ((*ciptrs_ret = (XtransConnInfo *) xalloc (
- *count_ret * sizeof (XtransConnInfo))) == NULL)
- {
- return -1;
- }
-
- for (i = 0; i < *count_ret; i++)
- {
- (*ciptrs_ret)[i] = temp_ciptrs[i];
- }
- }
- else
- *ciptrs_ret = NULL;
-
- return 0;
-}
-
-int
-TRANS(MakeAllCLTSServerListeners) (char *port, int *partial, int *count_ret,
- XtransConnInfo **ciptrs_ret)
-
-{
- char buffer[256]; /* ??? What size ?? */
- XtransConnInfo ciptr, temp_ciptrs[NUMTRANS];
- int status, i, j;
-
- PRMSG (2,"MakeAllCLTSServerListeners(%s,%p)\n",
- port ? port : "NULL", ciptrs_ret, 0);
-
- *count_ret = 0;
-
- for (i = 0; i < NUMTRANS; i++)
- {
- Xtransport *trans = Xtransports[i].transport;
-
- if (trans->flags&TRANS_ALIAS || trans->flags&TRANS_NOLISTEN)
- continue;
-
- snprintf(buffer, sizeof(buffer), "%s/:%s",
- trans->TransName, port ? port : "");
-
- PRMSG (5,"MakeAllCLTSServerListeners: opening %s\n",
- buffer, 0, 0);
-
- if ((ciptr = TRANS(OpenCLTSServer (buffer))) == NULL)
- {
- PRMSG (1,
- "MakeAllCLTSServerListeners: failed to open listener for %s\n",
- trans->TransName, 0, 0);
- continue;
- }
-
- if ((status = TRANS(CreateListener (ciptr, port, 0))) < 0)
- {
- if (status == TRANS_ADDR_IN_USE)
- {
- /*
- * We failed to bind to the specified address because the
- * address is in use. It must be that a server is already
- * running at this address, and this function should fail.
- */
-
- PRMSG (1,
- "MakeAllCLTSServerListeners: server already running\n",
- 0, 0, 0);
-
- for (j = 0; j < *count_ret; j++)
- TRANS(Close) (temp_ciptrs[j]);
-
- *count_ret = 0;
- *ciptrs_ret = NULL;
- *partial = 0;
- return -1;
- }
- else
- {
- PRMSG (1,
- "MakeAllCLTSServerListeners: failed to create listener for %s\n",
- trans->TransName, 0, 0);
-
- continue;
- }
- }
-
- PRMSG (5,
- "MakeAllCLTSServerListeners: opened listener for %s, %d\n",
- trans->TransName, ciptr->fd, 0);
- temp_ciptrs[*count_ret] = ciptr;
- (*count_ret)++;
- }
-
- *partial = (*count_ret < complete_network_count());
-
- PRMSG (5,
- "MakeAllCLTSServerListeners: partial=%d, actual=%d, complete=%d \n",
- *partial, *count_ret, complete_network_count());
-
- if (*count_ret > 0)
- {
- if ((*ciptrs_ret = (XtransConnInfo *) xalloc (
- *count_ret * sizeof (XtransConnInfo))) == NULL)
- {
- return -1;
- }
-
- for (i = 0; i < *count_ret; i++)
- {
- (*ciptrs_ret)[i] = temp_ciptrs[i];
- }
- }
- else
- *ciptrs_ret = NULL;
-
- return 0;
-}
-
-#endif /* TRANS_SERVER */
-
-
-
-/*
- * These routines are not part of the X Transport Interface, but they
- * may be used by it.
- */
-
-
-#if defined(SYSV) && defined(__i386__) && !defined(__SCO__) && !defined(sun) || defined(WIN32)
-
-/*
- * emulate readv
- */
-
-static int TRANS(ReadV) (XtransConnInfo ciptr, struct iovec *iov, int iovcnt)
-
-{
- int i, len, total;
- char *base;
-
- ESET(0);
- for (i = 0, total = 0; i < iovcnt; i++, iov++) {
- len = iov->iov_len;
- base = iov->iov_base;
- while (len > 0) {
- register int nbytes;
- nbytes = TRANS(Read) (ciptr, base, len);
- if (nbytes < 0 && total == 0) return -1;
- if (nbytes <= 0) return total;
- ESET(0);
- len -= nbytes;
- total += nbytes;
- base += nbytes;
- }
- }
- return total;
-}
-
-#endif /* SYSV && __i386__ || WIN32 || __sxg__ */
-
-#if defined(SYSV) && defined(__i386__) && !defined(__SCO__) && !defined(sun) || defined(WIN32)
-
-/*
- * emulate writev
- */
-
-static int TRANS(WriteV) (XtransConnInfo ciptr, struct iovec *iov, int iovcnt)
-
-{
- int i, len, total;
- char *base;
-
- ESET(0);
- for (i = 0, total = 0; i < iovcnt; i++, iov++) {
- len = iov->iov_len;
- base = iov->iov_base;
- while (len > 0) {
- register int nbytes;
- nbytes = TRANS(Write) (ciptr, base, len);
- if (nbytes < 0 && total == 0) return -1;
- if (nbytes <= 0) return total;
- ESET(0);
- len -= nbytes;
- total += nbytes;
- base += nbytes;
- }
- }
- return total;
-}
-
-#endif /* SYSV && __i386__ || WIN32 || __sxg__ */
-
-
-#if defined(_POSIX_SOURCE) || defined(USG) || defined(SVR4) || defined(__SVR4) || defined(__SCO__)
-#ifndef NEED_UTSNAME
-#define NEED_UTSNAME
-#endif
-#include <sys/utsname.h>
-#endif
-
-/*
- * TRANS(GetHostname) - similar to gethostname but allows special processing.
- */
-
-int TRANS(GetHostname) (char *buf, int maxlen)
-
-{
- int len;
-
-#ifdef NEED_UTSNAME
- struct utsname name;
-
- uname (&name);
- len = strlen (name.nodename);
- if (len >= maxlen) len = maxlen - 1;
- strncpy (buf, name.nodename, len);
- buf[len] = '\0';
-#else
- buf[0] = '\0';
- (void) gethostname (buf, maxlen);
- buf [maxlen - 1] = '\0';
- len = strlen(buf);
-#endif /* NEED_UTSNAME */
- return len;
-}
+/* + +Copyright 1993, 1994, 1998 The Open Group + +Permission to use, copy, modify, distribute, and sell this software and its +documentation for any purpose is hereby granted without fee, provided that +the above copyright notice appear in all copies and that both that +copyright notice and this permission notice appear in supporting +documentation. + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall +not be used in advertising or otherwise to promote the sale, use or +other dealings in this Software without prior written authorization +from The Open Group. + + * Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA + * + * All Rights Reserved + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name NCR not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. NCR makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * NCR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <ctype.h> +#include <unistd.h> + +#ifdef _MSC_VER +#include <X11\Xwinsock.h> +#endif +/* + * The transport table contains a definition for every transport (protocol) + * family. All operations that can be made on the transport go through this + * table. + * + * Each transport is assigned a unique transport id. + * + * New transports can be added by adding an entry in this table. + * For compatiblity, the transport ids should never be renumbered. + * Always add to the end of the list. + */ + +#define TRANS_TLI_INET_INDEX 1 +#define TRANS_TLI_TCP_INDEX 2 +#define TRANS_TLI_TLI_INDEX 3 +#define TRANS_SOCKET_UNIX_INDEX 4 +#define TRANS_SOCKET_LOCAL_INDEX 5 +#define TRANS_SOCKET_INET_INDEX 6 +#define TRANS_SOCKET_TCP_INDEX 7 +#define TRANS_DNET_INDEX 8 +#define TRANS_LOCAL_LOCAL_INDEX 9 +#define TRANS_LOCAL_PTS_INDEX 10 +#define TRANS_LOCAL_NAMED_INDEX 11 +/* 12 used to be ISC, but that's gone. */ +#define TRANS_LOCAL_SCO_INDEX 13 +#define TRANS_SOCKET_INET6_INDEX 14 +#define TRANS_LOCAL_PIPE_INDEX 15 + + +static +Xtransport_table Xtransports[] = { +#if defined(STREAMSCONN) + { &TRANS(TLITCPFuncs), TRANS_TLI_TCP_INDEX }, + { &TRANS(TLIINETFuncs), TRANS_TLI_INET_INDEX }, + { &TRANS(TLITLIFuncs), TRANS_TLI_TLI_INDEX }, +#endif /* STREAMSCONN */ +#if defined(TCPCONN) + { &TRANS(SocketTCPFuncs), TRANS_SOCKET_TCP_INDEX }, +#if defined(IPv6) && defined(AF_INET6) + { &TRANS(SocketINET6Funcs), TRANS_SOCKET_INET6_INDEX }, +#endif /* IPv6 */ + { &TRANS(SocketINETFuncs), TRANS_SOCKET_INET_INDEX }, +#endif /* TCPCONN */ +#if defined(UNIXCONN) +#if !defined(LOCALCONN) + { &TRANS(SocketLocalFuncs), TRANS_SOCKET_LOCAL_INDEX }, +#endif /* !LOCALCONN */ + { &TRANS(SocketUNIXFuncs), TRANS_SOCKET_UNIX_INDEX }, +#endif /* UNIXCONN */ +#if defined(LOCALCONN) + { &TRANS(LocalFuncs), TRANS_LOCAL_LOCAL_INDEX }, +#ifndef sun + { &TRANS(PTSFuncs), TRANS_LOCAL_PTS_INDEX }, +#endif /* sun */ +#if defined(SVR4) || defined(__SVR4) + { &TRANS(NAMEDFuncs), TRANS_LOCAL_NAMED_INDEX }, +#endif +#ifdef sun + { &TRANS(PIPEFuncs), TRANS_LOCAL_PIPE_INDEX }, +#endif /* sun */ +#if defined(__SCO__) || defined(__UNIXWARE__) + { &TRANS(SCOFuncs), TRANS_LOCAL_SCO_INDEX }, +#endif /* __SCO__ || __UNIXWARE__ */ +#endif /* LOCALCONN */ + { NULL, 0} +}; + +#define NUMTRANS (sizeof(Xtransports)/sizeof(Xtransport_table)-1) + + +#ifdef WIN32 +#define ioctl ioctlsocket +#endif + + + +/* + * These are a few utility function used by the public interface functions. + */ + +void +TRANS(FreeConnInfo) (XtransConnInfo ciptr) + +{ + PRMSG (3,"FreeConnInfo(%p)\n", ciptr, 0, 0); + + if (ciptr->addr) + xfree (ciptr->addr); + + if (ciptr->peeraddr) + xfree (ciptr->peeraddr); + + if (ciptr->port) + xfree (ciptr->port); + + xfree ((char *) ciptr); +} + + +#define PROTOBUFSIZE 20 + +static Xtransport * +TRANS(SelectTransport) (char *protocol) + +{ + char protobuf[PROTOBUFSIZE]; + int i; + + PRMSG (3,"SelectTransport(%s)\n", protocol, 0, 0); + + /* + * Force Protocol to be lowercase as a way of doing + * a case insensitive match. + */ + + strncpy (protobuf, protocol, PROTOBUFSIZE - 1); + protobuf[PROTOBUFSIZE-1] = '\0'; + + for (i = 0; i < PROTOBUFSIZE && protobuf[i] != '\0'; i++) + if (isupper (protobuf[i])) + protobuf[i] = tolower (protobuf[i]); + + /* Look at all of the configured protocols */ + + for (i = 0; i < NUMTRANS; i++) + { + if (!strcmp (protobuf, Xtransports[i].transport->TransName)) + return Xtransports[i].transport; + } + + return NULL; +} + +#ifndef TEST_t +static +#endif /* TEST_t */ +int +TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port) + +{ + /* + * For the font library, the address is a string formatted + * as "protocol/host:port[/catalogue]". Note that the catologue + * is optional. At this time, the catologue info is ignored, but + * we have to parse it anyways. + * + * Other than fontlib, the address is a string formatted + * as "protocol/host:port". + * + * If the protocol part is missing, then assume TCP. + * If the protocol part and host part are missing, then assume local. + * If a "::" is found then assume DNET. + */ + + char *mybuf, *tmpptr; + char *_protocol, *_host, *_port; + char hostnamebuf[256]; + int _host_len; + + PRMSG (3,"ParseAddress(%s)\n", address, 0, 0); + + /* Copy the string so it can be changed */ + + tmpptr = mybuf = (char *) xalloc (strlen (address) + 1); + strcpy (mybuf, address); + + /* Parse the string to get each component */ + + /* Get the protocol part */ + + _protocol = mybuf; + + + if ( ((mybuf = strchr (mybuf,'/')) == NULL) && + ((mybuf = strrchr (tmpptr,':')) == NULL) ) + { + /* address is in a bad format */ + *protocol = NULL; + *host = NULL; + *port = NULL; + xfree (tmpptr); + return 0; + } + + if (*mybuf == ':') + { + /* + * If there is a hostname, then assume tcp, otherwise + * it must be local. + */ + if (mybuf == tmpptr) + { + /* There is neither a protocol or host specified */ + _protocol = "local"; + } + else + { + /* There is a hostname specified */ + _protocol = "tcp"; + mybuf = tmpptr; /* reset to the begining of the host ptr */ + } + } + else + { + /* *mybuf == '/' */ + + *mybuf ++= '\0'; /* put a null at the end of the protocol */ + + if (strlen(_protocol) == 0) + { + /* + * If there is a hostname, then assume tcp, otherwise + * it must be local. + */ + if (*mybuf != ':') + _protocol = "tcp"; + else + _protocol = "local"; + } + } + + /* Get the host part */ + + _host = mybuf; + + if ((mybuf = strrchr (mybuf,':')) == NULL) + { + *protocol = NULL; + *host = NULL; + *port = NULL; + xfree (tmpptr); + return 0; + } + + *mybuf ++= '\0'; + + _host_len = strlen(_host); + if (_host_len == 0) + { + TRANS(GetHostname) (hostnamebuf, sizeof (hostnamebuf)); + _host = hostnamebuf; + } +#if defined(IPv6) && defined(AF_INET6) + /* hostname in IPv6 [numeric_addr]:0 form? */ + else if ( (_host_len > 3) && + ((strcmp(_protocol, "tcp") == 0) || (strcmp(_protocol, "inet6") == 0)) + && (*_host == '[') && (*(_host + _host_len - 1) == ']') ) { + struct sockaddr_in6 sin6; + + *(_host + _host_len - 1) = '\0'; + + /* Verify address is valid IPv6 numeric form */ + if (inet_pton(AF_INET6, _host + 1, &sin6) == 1) { + /* It is. Use it as such. */ + _host++; + _protocol = "inet6"; + } else { + /* It's not, restore it just in case some other code can use it. */ + *(_host + _host_len - 1) = ']'; + } + } +#endif + + + /* Get the port */ + + _port = mybuf; + +#if defined(FONT_t) || defined(FS_t) + /* + * Is there an optional catalogue list? + */ + + if ((mybuf = strchr (mybuf,'/')) != NULL) + *mybuf ++= '\0'; + + /* + * The rest, if any, is the (currently unused) catalogue list. + * + * _catalogue = mybuf; + */ +#endif + +#ifdef HAVE_LAUNCHD + /* launchd sockets will look like 'local//tmp/launch-XgkNns/:0' */ + if(address != NULL && strlen(address)>8 && (!strncmp(address,"local//",7))) { + _protocol="local"; + _host=""; + _port=address+6; + } +#endif + + /* + * Now that we have all of the components, allocate new + * string space for them. + */ + + if ((*protocol = (char *) xalloc(strlen (_protocol) + 1)) == NULL) + { + /* Malloc failed */ + *port = NULL; + *host = NULL; + *protocol = NULL; + xfree (tmpptr); + return 0; + } + else + strcpy (*protocol, _protocol); + + if ((*host = (char *) xalloc (strlen (_host) + 1)) == NULL) + { + /* Malloc failed */ + *port = NULL; + *host = NULL; + xfree (*protocol); + *protocol = NULL; + xfree (tmpptr); + return 0; + } + else + strcpy (*host, _host); + + if ((*port = (char *) xalloc (strlen (_port) + 1)) == NULL) + { + /* Malloc failed */ + *port = NULL; + xfree (*host); + *host = NULL; + xfree (*protocol); + *protocol = NULL; + xfree (tmpptr); + return 0; + } + else + strcpy (*port, _port); + + xfree (tmpptr); + + return 1; +} + + +/* + * TRANS(Open) does all of the real work opening a connection. The only + * funny part about this is the type parameter which is used to decide which + * type of open to perform. + */ + +static XtransConnInfo +TRANS(Open) (int type, char *address) + +{ + char *protocol = NULL, *host = NULL, *port = NULL; + XtransConnInfo ciptr = NULL; + Xtransport *thistrans; + + PRMSG (2,"Open(%d,%s)\n", type, address, 0); + +#if defined(WIN32) && defined(TCPCONN) + if (TRANS(WSAStartup)()) + { + PRMSG (1,"Open: WSAStartup failed\n", 0, 0, 0); + return NULL; + } +#endif + + /* Parse the Address */ + + if (TRANS(ParseAddress) (address, &protocol, &host, &port) == 0) + { + PRMSG (1,"Open: Unable to Parse address %s\n", address, 0, 0); + return NULL; + } + + /* Determine the transport type */ + + if ((thistrans = TRANS(SelectTransport) (protocol)) == NULL) + { + PRMSG (1,"Open: Unable to find transport for %s\n", + protocol, 0, 0); + + xfree (protocol); + xfree (host); + xfree (port); + return NULL; + } + + /* Open the transport */ + + switch (type) + { + case XTRANS_OPEN_COTS_CLIENT: +#ifdef TRANS_CLIENT + ciptr = thistrans->OpenCOTSClient(thistrans, protocol, host, port); +#endif /* TRANS_CLIENT */ + break; + case XTRANS_OPEN_COTS_SERVER: +#ifdef TRANS_SERVER + ciptr = thistrans->OpenCOTSServer(thistrans, protocol, host, port); +#endif /* TRANS_SERVER */ + break; + case XTRANS_OPEN_CLTS_CLIENT: +#ifdef TRANS_CLIENT + ciptr = thistrans->OpenCLTSClient(thistrans, protocol, host, port); +#endif /* TRANS_CLIENT */ + break; + case XTRANS_OPEN_CLTS_SERVER: +#ifdef TRANS_SERVER + ciptr = thistrans->OpenCLTSServer(thistrans, protocol, host, port); +#endif /* TRANS_SERVER */ + break; + default: + PRMSG (1,"Open: Unknown Open type %d\n", type, 0, 0); + } + + if (ciptr == NULL) + { + if (!(thistrans->flags & TRANS_DISABLED)) + { + PRMSG (1,"Open: transport open failed for %s/%s:%s\n", + protocol, host, port); + } + xfree (protocol); + xfree (host); + xfree (port); + return NULL; + } + + ciptr->transptr = thistrans; + ciptr->port = port; /* We need this for TRANS(Reopen) */ + + xfree (protocol); + xfree (host); + + return ciptr; +} + + +#ifdef TRANS_REOPEN + +/* + * We might want to create an XtransConnInfo object based on a previously + * opened connection. For example, the font server may clone itself and + * pass file descriptors to the parent. + */ + +static XtransConnInfo +TRANS(Reopen) (int type, int trans_id, int fd, char *port) + +{ + XtransConnInfo ciptr = NULL; + Xtransport *thistrans = NULL; + char *save_port; + int i; + + PRMSG (2,"Reopen(%d,%d,%s)\n", trans_id, fd, port); + + /* Determine the transport type */ + + for (i = 0; i < NUMTRANS; i++) + if (Xtransports[i].transport_id == trans_id) + { + thistrans = Xtransports[i].transport; + break; + } + + if (thistrans == NULL) + { + PRMSG (1,"Reopen: Unable to find transport id %d\n", + trans_id, 0, 0); + + return NULL; + } + + if ((save_port = (char *) xalloc (strlen (port) + 1)) == NULL) + { + PRMSG (1,"Reopen: Unable to malloc port string\n", 0, 0, 0); + + return NULL; + } + + strcpy (save_port, port); + + /* Get a new XtransConnInfo object */ + + switch (type) + { + case XTRANS_OPEN_COTS_SERVER: + ciptr = thistrans->ReopenCOTSServer(thistrans, fd, port); + break; + case XTRANS_OPEN_CLTS_SERVER: + ciptr = thistrans->ReopenCLTSServer(thistrans, fd, port); + break; + default: + PRMSG (1,"Reopen: Bad Open type %d\n", type, 0, 0); + } + + if (ciptr == NULL) + { + PRMSG (1,"Reopen: transport open failed\n", 0, 0, 0); + return NULL; + } + + ciptr->transptr = thistrans; + ciptr->port = save_port; + + return ciptr; +} + +#endif /* TRANS_REOPEN */ + + + +/* + * These are the public interfaces to this Transport interface. + * These are the only functions that should have knowledge of the transport + * table. + */ + +#ifdef TRANS_CLIENT + +XtransConnInfo +TRANS(OpenCOTSClient) (char *address) + +{ + PRMSG (2,"OpenCOTSClient(%s)\n", address, 0, 0); + return TRANS(Open) (XTRANS_OPEN_COTS_CLIENT, address); +} + +#endif /* TRANS_CLIENT */ + + +#ifdef TRANS_SERVER + +XtransConnInfo +TRANS(OpenCOTSServer) (char *address) + +{ + PRMSG (2,"OpenCOTSServer(%s)\n", address, 0, 0); + return TRANS(Open) (XTRANS_OPEN_COTS_SERVER, address); +} + +#endif /* TRANS_SERVER */ + + +#ifdef TRANS_CLIENT + +XtransConnInfo +TRANS(OpenCLTSClient) (char *address) + +{ + PRMSG (2,"OpenCLTSClient(%s)\n", address, 0, 0); + return TRANS(Open) (XTRANS_OPEN_CLTS_CLIENT, address); +} + +#endif /* TRANS_CLIENT */ + + +#ifdef TRANS_SERVER + +XtransConnInfo +TRANS(OpenCLTSServer) (char *address) + +{ + PRMSG (2,"OpenCLTSServer(%s)\n", address, 0, 0); + return TRANS(Open) (XTRANS_OPEN_CLTS_SERVER, address); +} + +#endif /* TRANS_SERVER */ + + +#ifdef TRANS_REOPEN + +XtransConnInfo +TRANS(ReopenCOTSServer) (int trans_id, int fd, char *port) + +{ + PRMSG (2,"ReopenCOTSServer(%d, %d, %s)\n", trans_id, fd, port); + return TRANS(Reopen) (XTRANS_OPEN_COTS_SERVER, trans_id, fd, port); +} + +XtransConnInfo +TRANS(ReopenCLTSServer) (int trans_id, int fd, char *port) + +{ + PRMSG (2,"ReopenCLTSServer(%d, %d, %s)\n", trans_id, fd, port); + return TRANS(Reopen) (XTRANS_OPEN_CLTS_SERVER, trans_id, fd, port); +} + + +int +TRANS(GetReopenInfo) (XtransConnInfo ciptr, + int *trans_id, int *fd, char **port) + +{ + int i; + + for (i = 0; i < NUMTRANS; i++) + if (Xtransports[i].transport == ciptr->transptr) + { + *trans_id = Xtransports[i].transport_id; + *fd = ciptr->fd; + + if ((*port = (char *) xalloc (strlen (ciptr->port) + 1)) == NULL) + return 0; + else + { + strcpy (*port, ciptr->port); + return 1; + } + } + + return 0; +} + +#endif /* TRANS_REOPEN */ + + +int +TRANS(SetOption) (XtransConnInfo ciptr, int option, int arg) + +{ + int fd = ciptr->fd; + int ret = 0; + + PRMSG (2,"SetOption(%d,%d,%d)\n", fd, option, arg); + + /* + * For now, all transport type use the same stuff for setting options. + * As long as this is true, we can put the common code here. Once a more + * complicated transport such as shared memory or an OSI implementation + * that uses the session and application libraries is implemented, this + * code may have to move to a transport dependent function. + * + * ret = ciptr->transptr->SetOption (ciptr, option, arg); + */ + + switch (option) + { + case TRANS_NONBLOCKING: + switch (arg) + { + case 0: + /* Set to blocking mode */ + break; + case 1: /* Set to non-blocking mode */ + +#if defined(O_NONBLOCK) && !defined(SCO325) + ret = fcntl (fd, F_GETFL, 0); + if (ret != -1) + ret = fcntl (fd, F_SETFL, ret | O_NONBLOCK); +#else +#ifdef FIOSNBIO + { + int arg; + arg = 1; + ret = ioctl (fd, FIOSNBIO, &arg); + } +#else +#if defined(WIN32) + { +#ifdef WIN32 + unsigned long arg; +#else + int arg; +#endif + arg = 1; +/* IBM TCP/IP understands this option too well: it causes TRANS(Read) to fail + * eventually with EWOULDBLOCK */ + ret = ioctl (fd, FIONBIO, &arg); + } +#else + ret = fcntl (fd, F_GETFL, 0); +#ifdef FNDELAY + ret = fcntl (fd, F_SETFL, ret | FNDELAY); +#else + ret = fcntl (fd, F_SETFL, ret | O_NDELAY); +#endif +#endif /* AIXV3 || uniosu */ +#endif /* FIOSNBIO */ +#endif /* O_NONBLOCK */ + break; + default: + /* Unknown option */ + break; + } + break; + case TRANS_CLOSEONEXEC: +#ifdef F_SETFD +#ifdef FD_CLOEXEC + ret = fcntl (fd, F_SETFD, FD_CLOEXEC); +#else + ret = fcntl (fd, F_SETFD, 1); +#endif /* FD_CLOEXEC */ +#endif /* F_SETFD */ + break; + } + + return ret; +} + +#ifdef TRANS_SERVER + +int +TRANS(CreateListener) (XtransConnInfo ciptr, char *port, unsigned int flags) + +{ + return ciptr->transptr->CreateListener (ciptr, port, flags); +} + +int +TRANS(NoListen) (char * protocol) + +{ + Xtransport *trans; + int i = 0, ret = 0; + + if ((trans = TRANS(SelectTransport)(protocol)) == NULL) + { + PRMSG (1,"TransNoListen: unable to find transport: %s\n", + protocol, 0, 0); + + return -1; + } + if (trans->flags & TRANS_ALIAS) { + if (trans->nolisten) + while (trans->nolisten[i]) { + ret |= TRANS(NoListen)(trans->nolisten[i]); + i++; + } + } + + trans->flags |= TRANS_NOLISTEN; + return ret; +} + +int +TRANS(ResetListener) (XtransConnInfo ciptr) + +{ + if (ciptr->transptr->ResetListener) + return ciptr->transptr->ResetListener (ciptr); + else + return TRANS_RESET_NOOP; +} + + +XtransConnInfo +TRANS(Accept) (XtransConnInfo ciptr, int *status) + +{ + XtransConnInfo newciptr; + + PRMSG (2,"Accept(%d)\n", ciptr->fd, 0, 0); + + newciptr = ciptr->transptr->Accept (ciptr, status); + + if (newciptr) + newciptr->transptr = ciptr->transptr; + + return newciptr; +} + +#endif /* TRANS_SERVER */ + + +#ifdef TRANS_CLIENT + +int +TRANS(Connect) (XtransConnInfo ciptr, char *address) + +{ + char *protocol; + char *host; + char *port; + int ret; + + PRMSG (2,"Connect(%d,%s)\n", ciptr->fd, address, 0); + + if (TRANS(ParseAddress) (address, &protocol, &host, &port) == 0) + { + PRMSG (1,"Connect: Unable to Parse address %s\n", + address, 0, 0); + return -1; + } + +#ifdef HAVE_LAUNCHD + if (!host) host=strdup(""); +#endif + + if (!port || !*port) + { + PRMSG (1,"Connect: Missing port specification in %s\n", + address, 0, 0); + if (protocol) xfree (protocol); + if (host) xfree (host); + return -1; + } + + ret = ciptr->transptr->Connect (ciptr, host, port); + + if (protocol) xfree (protocol); + if (host) xfree (host); + if (port) xfree (port); + + return ret; +} + +#endif /* TRANS_CLIENT */ + + +int +TRANS(BytesReadable) (XtransConnInfo ciptr, BytesReadable_t *pend) + +{ + return ciptr->transptr->BytesReadable (ciptr, pend); +} + +int +TRANS(Read) (XtransConnInfo ciptr, char *buf, int size) + +{ + return ciptr->transptr->Read (ciptr, buf, size); +} + +int +TRANS(Write) (XtransConnInfo ciptr, char *buf, int size) + +{ + return ciptr->transptr->Write (ciptr, buf, size); +} + +int +TRANS(Readv) (XtransConnInfo ciptr, struct iovec *buf, int size) + +{ + return ciptr->transptr->Readv (ciptr, buf, size); +} + +int +TRANS(Writev) (XtransConnInfo ciptr, struct iovec *buf, int size) + +{ + return ciptr->transptr->Writev (ciptr, buf, size); +} + +int +TRANS(Disconnect) (XtransConnInfo ciptr) + +{ + return ciptr->transptr->Disconnect (ciptr); +} + +int +TRANS(Close) (XtransConnInfo ciptr) + +{ + int ret; + + PRMSG (2,"Close(%d)\n", ciptr->fd, 0, 0); + + ret = ciptr->transptr->Close (ciptr); + + TRANS(FreeConnInfo) (ciptr); + + return ret; +} + +int +TRANS(CloseForCloning) (XtransConnInfo ciptr) + +{ + int ret; + + PRMSG (2,"CloseForCloning(%d)\n", ciptr->fd, 0, 0); + + ret = ciptr->transptr->CloseForCloning (ciptr); + + TRANS(FreeConnInfo) (ciptr); + + return ret; +} + +int +TRANS(IsLocal) (XtransConnInfo ciptr) + +{ + return (ciptr->family == AF_UNIX); +} + + +int +TRANS(GetMyAddr) (XtransConnInfo ciptr, int *familyp, int *addrlenp, + Xtransaddr **addrp) + +{ + PRMSG (2,"GetMyAddr(%d)\n", ciptr->fd, 0, 0); + + *familyp = ciptr->family; + *addrlenp = ciptr->addrlen; + + if ((*addrp = (Xtransaddr *) xalloc (ciptr->addrlen)) == NULL) + { + PRMSG (1,"GetMyAddr: malloc failed\n", 0, 0, 0); + return -1; + } + memcpy(*addrp, ciptr->addr, ciptr->addrlen); + + return 0; +} + +int +TRANS(GetPeerAddr) (XtransConnInfo ciptr, int *familyp, int *addrlenp, + Xtransaddr **addrp) + +{ + PRMSG (2,"GetPeerAddr(%d)\n", ciptr->fd, 0, 0); + + *familyp = ciptr->family; + *addrlenp = ciptr->peeraddrlen; + + if ((*addrp = (Xtransaddr *) xalloc (ciptr->peeraddrlen)) == NULL) + { + PRMSG (1,"GetPeerAddr: malloc failed\n", 0, 0, 0); + return -1; + } + memcpy(*addrp, ciptr->peeraddr, ciptr->peeraddrlen); + + return 0; +} + + +int +TRANS(GetConnectionNumber) (XtransConnInfo ciptr) + +{ + return ciptr->fd; +} + + +/* + * These functions are really utility functions, but they require knowledge + * of the internal data structures, so they have to be part of the Transport + * Independant API. + */ + +#ifdef TRANS_SERVER + +static int +complete_network_count (void) + +{ + int count = 0; + int found_local = 0; + int i; + + /* + * For a complete network, we only need one LOCALCONN transport to work + */ + + for (i = 0; i < NUMTRANS; i++) + { + if (Xtransports[i].transport->flags & TRANS_ALIAS + || Xtransports[i].transport->flags & TRANS_NOLISTEN) + continue; + + if (Xtransports[i].transport->flags & TRANS_LOCAL) + found_local = 1; + else + count++; + } + + return (count + found_local); +} + + +#ifdef XQUARTZ_EXPORTS_LAUNCHD_FD +extern int xquartz_launchd_fd; +#endif + +int +TRANS(MakeAllCOTSServerListeners) (char *port, int *partial, int *count_ret, + XtransConnInfo **ciptrs_ret) + +{ + char buffer[256]; /* ??? What size ?? */ + XtransConnInfo ciptr, temp_ciptrs[NUMTRANS]; + int status, i, j; + +#if defined(IPv6) && defined(AF_INET6) + int ipv6_succ = 0; +#endif + PRMSG (2,"MakeAllCOTSServerListeners(%s,%p)\n", + port ? port : "NULL", ciptrs_ret, 0); + + *count_ret = 0; + +#ifdef XQUARTZ_EXPORTS_LAUNCHD_FD + fprintf(stderr, "Launchd socket fd: %d\n", xquartz_launchd_fd); + if(xquartz_launchd_fd != -1) { + if((ciptr = TRANS(ReopenCOTSServer(TRANS_SOCKET_LOCAL_INDEX, + xquartz_launchd_fd, getenv("DISPLAY"))))==NULL) + fprintf(stderr,"Got NULL while trying to Reopen launchd port\n"); + else + temp_ciptrs[(*count_ret)++] = ciptr; + } +#endif + + for (i = 0; i < NUMTRANS; i++) + { + Xtransport *trans = Xtransports[i].transport; + unsigned int flags = 0; + + if (trans->flags&TRANS_ALIAS || trans->flags&TRANS_NOLISTEN) + continue; + + snprintf(buffer, sizeof(buffer), "%s/:%s", + trans->TransName, port ? port : ""); + + PRMSG (5,"MakeAllCOTSServerListeners: opening %s\n", + buffer, 0, 0); + + if ((ciptr = TRANS(OpenCOTSServer(buffer))) == NULL) + { + if (trans->flags & TRANS_DISABLED) + continue; + + PRMSG (1, + "MakeAllCOTSServerListeners: failed to open listener for %s\n", + trans->TransName, 0, 0); + continue; + } +#if defined(IPv6) && defined(AF_INET6) + if ((Xtransports[i].transport_id == TRANS_SOCKET_INET_INDEX + && ipv6_succ)) + flags |= ADDR_IN_USE_ALLOWED; +#endif + + if ((status = TRANS(CreateListener (ciptr, port, flags))) < 0) + { + if (status == TRANS_ADDR_IN_USE) + { + /* + * We failed to bind to the specified address because the + * address is in use. It must be that a server is already + * running at this address, and this function should fail. + */ + + PRMSG (1, + "MakeAllCOTSServerListeners: server already running\n", + 0, 0, 0); + + for (j = 0; j < *count_ret; j++) + TRANS(Close) (temp_ciptrs[j]); + + *count_ret = 0; + *ciptrs_ret = NULL; + *partial = 0; + return -1; + } + else + { + PRMSG (1, + "MakeAllCOTSServerListeners: failed to create listener for %s\n", + trans->TransName, 0, 0); + + continue; + } + } + +#if defined(IPv6) && defined(AF_INET6) + if (Xtransports[i].transport_id == TRANS_SOCKET_INET6_INDEX) + ipv6_succ = 1; +#endif + + PRMSG (5, + "MakeAllCOTSServerListeners: opened listener for %s, %d\n", + trans->TransName, ciptr->fd, 0); + + temp_ciptrs[*count_ret] = ciptr; + (*count_ret)++; + } + + *partial = (*count_ret < complete_network_count()); + + PRMSG (5, + "MakeAllCOTSServerListeners: partial=%d, actual=%d, complete=%d \n", + *partial, *count_ret, complete_network_count()); + + if (*count_ret > 0) + { + if ((*ciptrs_ret = (XtransConnInfo *) xalloc ( + *count_ret * sizeof (XtransConnInfo))) == NULL) + { + return -1; + } + + for (i = 0; i < *count_ret; i++) + { + (*ciptrs_ret)[i] = temp_ciptrs[i]; + } + } + else + *ciptrs_ret = NULL; + + return 0; +} + +int +TRANS(MakeAllCLTSServerListeners) (char *port, int *partial, int *count_ret, + XtransConnInfo **ciptrs_ret) + +{ + char buffer[256]; /* ??? What size ?? */ + XtransConnInfo ciptr, temp_ciptrs[NUMTRANS]; + int status, i, j; + + PRMSG (2,"MakeAllCLTSServerListeners(%s,%p)\n", + port ? port : "NULL", ciptrs_ret, 0); + + *count_ret = 0; + + for (i = 0; i < NUMTRANS; i++) + { + Xtransport *trans = Xtransports[i].transport; + + if (trans->flags&TRANS_ALIAS || trans->flags&TRANS_NOLISTEN) + continue; + + snprintf(buffer, sizeof(buffer), "%s/:%s", + trans->TransName, port ? port : ""); + + PRMSG (5,"MakeAllCLTSServerListeners: opening %s\n", + buffer, 0, 0); + + if ((ciptr = TRANS(OpenCLTSServer (buffer))) == NULL) + { + PRMSG (1, + "MakeAllCLTSServerListeners: failed to open listener for %s\n", + trans->TransName, 0, 0); + continue; + } + + if ((status = TRANS(CreateListener (ciptr, port, 0))) < 0) + { + if (status == TRANS_ADDR_IN_USE) + { + /* + * We failed to bind to the specified address because the + * address is in use. It must be that a server is already + * running at this address, and this function should fail. + */ + + PRMSG (1, + "MakeAllCLTSServerListeners: server already running\n", + 0, 0, 0); + + for (j = 0; j < *count_ret; j++) + TRANS(Close) (temp_ciptrs[j]); + + *count_ret = 0; + *ciptrs_ret = NULL; + *partial = 0; + return -1; + } + else + { + PRMSG (1, + "MakeAllCLTSServerListeners: failed to create listener for %s\n", + trans->TransName, 0, 0); + + continue; + } + } + + PRMSG (5, + "MakeAllCLTSServerListeners: opened listener for %s, %d\n", + trans->TransName, ciptr->fd, 0); + temp_ciptrs[*count_ret] = ciptr; + (*count_ret)++; + } + + *partial = (*count_ret < complete_network_count()); + + PRMSG (5, + "MakeAllCLTSServerListeners: partial=%d, actual=%d, complete=%d \n", + *partial, *count_ret, complete_network_count()); + + if (*count_ret > 0) + { + if ((*ciptrs_ret = (XtransConnInfo *) xalloc ( + *count_ret * sizeof (XtransConnInfo))) == NULL) + { + return -1; + } + + for (i = 0; i < *count_ret; i++) + { + (*ciptrs_ret)[i] = temp_ciptrs[i]; + } + } + else + *ciptrs_ret = NULL; + + return 0; +} + +#endif /* TRANS_SERVER */ + + + +/* + * These routines are not part of the X Transport Interface, but they + * may be used by it. + */ + + +#if defined(SYSV) && defined(__i386__) && !defined(__SCO__) && !defined(sun) || defined(WIN32) + +/* + * emulate readv + */ + +static int TRANS(ReadV) (XtransConnInfo ciptr, struct iovec *iov, int iovcnt) + +{ + int i, len, total; + char *base; + + ESET(0); + for (i = 0, total = 0; i < iovcnt; i++, iov++) { + len = iov->iov_len; + base = iov->iov_base; + while (len > 0) { + register int nbytes; + nbytes = TRANS(Read) (ciptr, base, len); + if (nbytes < 0 && total == 0) return -1; + if (nbytes <= 0) return total; + ESET(0); + len -= nbytes; + total += nbytes; + base += nbytes; + } + } + return total; +} + +#endif /* SYSV && __i386__ || WIN32 || __sxg__ */ + +#if defined(SYSV) && defined(__i386__) && !defined(__SCO__) && !defined(sun) || defined(WIN32) + +/* + * emulate writev + */ + +static int TRANS(WriteV) (XtransConnInfo ciptr, struct iovec *iov, int iovcnt) + +{ + int i, len, total; + char *base; + + ESET(0); + for (i = 0, total = 0; i < iovcnt; i++, iov++) { + len = iov->iov_len; + base = iov->iov_base; + while (len > 0) { + register int nbytes; + nbytes = TRANS(Write) (ciptr, base, len); + if (nbytes < 0 && total == 0) return -1; + if (nbytes <= 0) return total; + ESET(0); + len -= nbytes; + total += nbytes; + base += nbytes; + } + } + return total; +} + +#endif /* SYSV && __i386__ || WIN32 || __sxg__ */ + + +#if defined(_POSIX_SOURCE) || defined(USG) || defined(SVR4) || defined(__SVR4) || defined(__SCO__) +#ifndef NEED_UTSNAME +#define NEED_UTSNAME +#endif +#include <sys/utsname.h> +#endif + +/* + * TRANS(GetHostname) - similar to gethostname but allows special processing. + */ + +int TRANS(GetHostname) (char *buf, int maxlen) + +{ + int len; + +#ifdef NEED_UTSNAME + struct utsname name; + + uname (&name); + len = strlen (name.nodename); + if (len >= maxlen) len = maxlen - 1; + strncpy (buf, name.nodename, len); + buf[len] = '\0'; +#else + buf[0] = '\0'; + (void) gethostname (buf, maxlen); + buf [maxlen - 1] = '\0'; + len = strlen(buf); +#endif /* NEED_UTSNAME */ + return len; +} diff --git a/X11/xtrans/Xtrans.h b/X11/xtrans/Xtrans.h index 7470c1c04..5eac908d0 100644 --- a/X11/xtrans/Xtrans.h +++ b/X11/xtrans/Xtrans.h @@ -1,450 +1,450 @@ -/*
-
-Copyright 1993, 1994, 1998 The Open Group
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation.
-
-The above copyright notice and this permission notice shall be included
-in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
-OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall
-not be used in advertising or otherwise to promote the sale, use or
-other dealings in this Software without prior written authorization
-from The Open Group.
-
- * Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
- *
- * All Rights Reserved
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name NCR not be used in advertising
- * or publicity pertaining to distribution of the software without specific,
- * written prior permission. NCR makes no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- *
- * NCR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
- * NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
- * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
- * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#ifndef _XTRANS_H_
-#define _XTRANS_H_
-
-#include <X11/Xfuncproto.h>
-#include <X11/Xos.h>
-
-#ifndef WIN32
-#include <sys/socket.h>
-#endif
-
-#ifdef __clang__
-/* Not all clients make use of all provided statics */
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wunused-function"
-#endif
-
-/*
- * Set the functions names according to where this code is being compiled.
- */
-
-#ifdef X11_t
-#define TRANS(func) _X11Trans##func
-#ifdef XTRANSDEBUG
-static char* __xtransname = "_X11Trans";
-#endif
-#endif /* X11_t */
-
-#ifdef XSERV_t
-#define TRANS(func) _XSERVTrans##func
-#ifdef XTRANSDEBUG
-static char* __xtransname = "_XSERVTrans";
-#endif
-#define X11_t
-#endif /* XSERV_t */
-
-#ifdef XIM_t
-#define TRANS(func) _XimXTrans##func
-#ifdef XTRANSDEBUG
-static char* __xtransname = "_XimTrans";
-#endif
-#endif /* XIM_t */
-
-#ifdef FS_t
-#define TRANS(func) _FSTrans##func
-#ifdef XTRANSDEBUG
-static char* __xtransname = "_FSTrans";
-#endif
-#endif /* FS_t */
-
-#ifdef FONT_t
-#define TRANS(func) _FontTrans##func
-#ifdef XTRANSDEBUG
-static char* __xtransname = "_FontTrans";
-#endif
-#endif /* FONT_t */
-
-#ifdef ICE_t
-#define TRANS(func) _IceTrans##func
-#ifdef XTRANSDEBUG
-static char* __xtransname = "_IceTrans";
-#endif
-#endif /* ICE_t */
-
-#ifdef TEST_t
-#define TRANS(func) _TESTTrans##func
-#ifdef XTRANSDEBUG
-static char* __xtransname = "_TESTTrans";
-#endif
-#endif /* TEST_t */
-
-#ifdef LBXPROXY_t
-#define TRANS(func) _LBXPROXYTrans##func
-#define X11_t /* The server defines this - so should the LBX proxy */
-#ifdef XTRANSDEBUG
-static char* __xtransname = "_LBXPROXYTrans";
-#endif
-#endif /* LBXPROXY_t */
-
-#if !defined(TRANS)
-#define TRANS(func) _XTrans##func
-#ifdef XTRANSDEBUG
-static char* __xtransname = "_XTrans";
-#endif
-#endif /* !TRANS */
-
-#ifdef __clang__
-#pragma clang diagnostic pop
-#endif
-
-/*
- * Create a single address structure that can be used wherever
- * an address structure is needed. struct sockaddr is not big enough
- * to hold a sockadd_un, so we create this definition to have a single
- * structure that is big enough for all the structures we might need.
- *
- * This structure needs to be independent of the socket/TLI interface used.
- */
-
-#if defined(IPv6) && defined(AF_INET6)
-typedef struct sockaddr_storage Xtransaddr;
-#else
-#define XTRANS_MAX_ADDR_LEN 128 /* large enough to hold sun_path */
-
-typedef struct {
- unsigned char addr[XTRANS_MAX_ADDR_LEN];
-} Xtransaddr;
-#endif
-
-#ifdef LONG64
-typedef int BytesReadable_t;
-#else
-typedef long BytesReadable_t;
-#endif
-
-
-#if defined(WIN32) || defined(USG)
-
-/*
- * TRANS(Readv) and TRANS(Writev) use struct iovec, normally found
- * in Berkeley systems in <sys/uio.h>. See the readv(2) and writev(2)
- * manual pages for details.
- */
-
-struct iovec {
- caddr_t iov_base;
- int iov_len;
-};
-
-#else
-#include <sys/uio.h>
-#endif
-
-typedef struct _XtransConnInfo *XtransConnInfo;
-
-
-/*
- * Transport Option definitions
- */
-
-#define TRANS_NONBLOCKING 1
-#define TRANS_CLOSEONEXEC 2
-
-
-/*
- * Return values of Connect (0 is success)
- */
-
-#define TRANS_CONNECT_FAILED -1
-#define TRANS_TRY_CONNECT_AGAIN -2
-#define TRANS_IN_PROGRESS -3
-
-
-/*
- * Return values of CreateListener (0 is success)
- */
-
-#define TRANS_CREATE_LISTENER_FAILED -1
-#define TRANS_ADDR_IN_USE -2
-
-
-/*
- * Return values of Accept (0 is success)
- */
-
-#define TRANS_ACCEPT_BAD_MALLOC -1
-#define TRANS_ACCEPT_FAILED -2
-#define TRANS_ACCEPT_MISC_ERROR -3
-
-
-/*
- * ResetListener return values
- */
-
-#define TRANS_RESET_NOOP 1
-#define TRANS_RESET_NEW_FD 2
-#define TRANS_RESET_FAILURE 3
-
-
-/*
- * Function prototypes for the exposed interface
- */
-
-void TRANS(FreeConnInfo) (
- XtransConnInfo /* ciptr */
-);
-
-#ifdef TRANS_CLIENT
-
-XtransConnInfo TRANS(OpenCOTSClient)(
- char * /* address */
-);
-
-#endif /* TRANS_CLIENT */
-
-#ifdef TRANS_SERVER
-
-XtransConnInfo TRANS(OpenCOTSServer)(
- char * /* address */
-);
-
-#endif /* TRANS_SERVER */
-
-#ifdef TRANS_CLIENT
-
-XtransConnInfo TRANS(OpenCLTSClient)(
- char * /* address */
-);
-
-#endif /* TRANS_CLIENT */
-
-#ifdef TRANS_SERVER
-
-XtransConnInfo TRANS(OpenCLTSServer)(
- char * /* address */
-);
-
-#endif /* TRANS_SERVER */
-
-#ifdef TRANS_REOPEN
-
-XtransConnInfo TRANS(ReopenCOTSServer)(
- int, /* trans_id */
- int, /* fd */
- char * /* port */
-);
-
-XtransConnInfo TRANS(ReopenCLTSServer)(
- int, /* trans_id */
- int, /* fd */
- char * /* port */
-);
-
-int TRANS(GetReopenInfo)(
- XtransConnInfo, /* ciptr */
- int *, /* trans_id */
- int *, /* fd */
- char ** /* port */
-);
-
-#endif /* TRANS_REOPEN */
-
-
-int TRANS(SetOption)(
- XtransConnInfo, /* ciptr */
- int, /* option */
- int /* arg */
-);
-
-#ifdef TRANS_SERVER
-
-int TRANS(CreateListener)(
- XtransConnInfo, /* ciptr */
- char *, /* port */
- unsigned int /* flags */
-);
-
-int TRANS(NoListen) (
- char* /* protocol*/
-);
-
-int TRANS(ResetListener)(
- XtransConnInfo /* ciptr */
-);
-
-XtransConnInfo TRANS(Accept)(
- XtransConnInfo, /* ciptr */
- int * /* status */
-);
-
-#endif /* TRANS_SERVER */
-
-#ifdef TRANS_CLIENT
-
-int TRANS(Connect)(
- XtransConnInfo, /* ciptr */
- char * /* address */
-);
-
-#endif /* TRANS_CLIENT */
-
-int TRANS(BytesReadable)(
- XtransConnInfo, /* ciptr */
- BytesReadable_t * /* pend */
-);
-
-int TRANS(Read)(
- XtransConnInfo, /* ciptr */
- char *, /* buf */
- int /* size */
-);
-
-int TRANS(Write)(
- XtransConnInfo, /* ciptr */
- char *, /* buf */
- int /* size */
-);
-
-int TRANS(Readv)(
- XtransConnInfo, /* ciptr */
- struct iovec *, /* buf */
- int /* size */
-);
-
-int TRANS(Writev)(
- XtransConnInfo, /* ciptr */
- struct iovec *, /* buf */
- int /* size */
-);
-
-int TRANS(Disconnect)(
- XtransConnInfo /* ciptr */
-);
-
-int TRANS(Close)(
- XtransConnInfo /* ciptr */
-);
-
-int TRANS(CloseForCloning)(
- XtransConnInfo /* ciptr */
-);
-
-int TRANS(IsLocal)(
- XtransConnInfo /* ciptr */
-);
-
-int TRANS(GetMyAddr)(
- XtransConnInfo, /* ciptr */
- int *, /* familyp */
- int *, /* addrlenp */
- Xtransaddr ** /* addrp */
-);
-
-int TRANS(GetPeerAddr)(
- XtransConnInfo, /* ciptr */
- int *, /* familyp */
- int *, /* addrlenp */
- Xtransaddr ** /* addrp */
-);
-
-int TRANS(GetConnectionNumber)(
- XtransConnInfo /* ciptr */
-);
-
-#ifdef TRANS_SERVER
-
-int TRANS(MakeAllCOTSServerListeners)(
- char *, /* port */
- int *, /* partial */
- int *, /* count_ret */
- XtransConnInfo ** /* ciptrs_ret */
-);
-
-int TRANS(MakeAllCLTSServerListeners)(
- char *, /* port */
- int *, /* partial */
- int *, /* count_ret */
- XtransConnInfo ** /* ciptrs_ret */
-);
-
-#endif /* TRANS_SERVER */
-
-
-/*
- * Function Prototypes for Utility Functions.
- */
-
-#ifdef X11_t
-
-int TRANS(ConvertAddress)(
- int *, /* familyp */
- int *, /* addrlenp */
- Xtransaddr ** /* addrp */
-);
-
-#endif /* X11_t */
-
-#ifdef ICE_t
-
-char *
-TRANS(GetMyNetworkId)(
- XtransConnInfo /* ciptr */
-);
-
-char *
-TRANS(GetPeerNetworkId)(
- XtransConnInfo /* ciptr */
-);
-
-#endif /* ICE_t */
-
-int
-TRANS(GetHostname) (
- char * /* buf */,
- int /* maxlen */
-);
-
-#if defined(WIN32) && defined(TCPCONN)
-int TRANS(WSAStartup)();
-#endif
-
-#endif /* _XTRANS_H_ */
+/* + +Copyright 1993, 1994, 1998 The Open Group + +Permission to use, copy, modify, distribute, and sell this software and its +documentation for any purpose is hereby granted without fee, provided that +the above copyright notice appear in all copies and that both that +copyright notice and this permission notice appear in supporting +documentation. + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall +not be used in advertising or otherwise to promote the sale, use or +other dealings in this Software without prior written authorization +from The Open Group. + + * Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA + * + * All Rights Reserved + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name NCR not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. NCR makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * NCR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _XTRANS_H_ +#define _XTRANS_H_ + +#include <X11/Xfuncproto.h> +#include <X11/Xos.h> + +#ifndef WIN32 +#include <sys/socket.h> +#endif + +#ifdef __clang__ +/* Not all clients make use of all provided statics */ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-function" +#endif + +/* + * Set the functions names according to where this code is being compiled. + */ + +#ifdef X11_t +#define TRANS(func) _X11Trans##func +#ifdef XTRANSDEBUG +static char* __xtransname = "_X11Trans"; +#endif +#endif /* X11_t */ + +#ifdef XSERV_t +#define TRANS(func) _XSERVTrans##func +#ifdef XTRANSDEBUG +static char* __xtransname = "_XSERVTrans"; +#endif +#define X11_t +#endif /* XSERV_t */ + +#ifdef XIM_t +#define TRANS(func) _XimXTrans##func +#ifdef XTRANSDEBUG +static char* __xtransname = "_XimTrans"; +#endif +#endif /* XIM_t */ + +#ifdef FS_t +#define TRANS(func) _FSTrans##func +#ifdef XTRANSDEBUG +static char* __xtransname = "_FSTrans"; +#endif +#endif /* FS_t */ + +#ifdef FONT_t +#define TRANS(func) _FontTrans##func +#ifdef XTRANSDEBUG +static char* __xtransname = "_FontTrans"; +#endif +#endif /* FONT_t */ + +#ifdef ICE_t +#define TRANS(func) _IceTrans##func +#ifdef XTRANSDEBUG +static char* __xtransname = "_IceTrans"; +#endif +#endif /* ICE_t */ + +#ifdef TEST_t +#define TRANS(func) _TESTTrans##func +#ifdef XTRANSDEBUG +static char* __xtransname = "_TESTTrans"; +#endif +#endif /* TEST_t */ + +#ifdef LBXPROXY_t +#define TRANS(func) _LBXPROXYTrans##func +#define X11_t /* The server defines this - so should the LBX proxy */ +#ifdef XTRANSDEBUG +static char* __xtransname = "_LBXPROXYTrans"; +#endif +#endif /* LBXPROXY_t */ + +#if !defined(TRANS) +#define TRANS(func) _XTrans##func +#ifdef XTRANSDEBUG +static char* __xtransname = "_XTrans"; +#endif +#endif /* !TRANS */ + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + +/* + * Create a single address structure that can be used wherever + * an address structure is needed. struct sockaddr is not big enough + * to hold a sockadd_un, so we create this definition to have a single + * structure that is big enough for all the structures we might need. + * + * This structure needs to be independent of the socket/TLI interface used. + */ + +#if defined(IPv6) && defined(AF_INET6) +typedef struct sockaddr_storage Xtransaddr; +#else +#define XTRANS_MAX_ADDR_LEN 128 /* large enough to hold sun_path */ + +typedef struct { + unsigned char addr[XTRANS_MAX_ADDR_LEN]; +} Xtransaddr; +#endif + +#ifdef LONG64 +typedef int BytesReadable_t; +#else +typedef long BytesReadable_t; +#endif + + +#if defined(WIN32) || defined(USG) + +/* + * TRANS(Readv) and TRANS(Writev) use struct iovec, normally found + * in Berkeley systems in <sys/uio.h>. See the readv(2) and writev(2) + * manual pages for details. + */ + +struct iovec { + caddr_t iov_base; + int iov_len; +}; + +#else +#include <sys/uio.h> +#endif + +typedef struct _XtransConnInfo *XtransConnInfo; + + +/* + * Transport Option definitions + */ + +#define TRANS_NONBLOCKING 1 +#define TRANS_CLOSEONEXEC 2 + + +/* + * Return values of Connect (0 is success) + */ + +#define TRANS_CONNECT_FAILED -1 +#define TRANS_TRY_CONNECT_AGAIN -2 +#define TRANS_IN_PROGRESS -3 + + +/* + * Return values of CreateListener (0 is success) + */ + +#define TRANS_CREATE_LISTENER_FAILED -1 +#define TRANS_ADDR_IN_USE -2 + + +/* + * Return values of Accept (0 is success) + */ + +#define TRANS_ACCEPT_BAD_MALLOC -1 +#define TRANS_ACCEPT_FAILED -2 +#define TRANS_ACCEPT_MISC_ERROR -3 + + +/* + * ResetListener return values + */ + +#define TRANS_RESET_NOOP 1 +#define TRANS_RESET_NEW_FD 2 +#define TRANS_RESET_FAILURE 3 + + +/* + * Function prototypes for the exposed interface + */ + +void TRANS(FreeConnInfo) ( + XtransConnInfo /* ciptr */ +); + +#ifdef TRANS_CLIENT + +XtransConnInfo TRANS(OpenCOTSClient)( + char * /* address */ +); + +#endif /* TRANS_CLIENT */ + +#ifdef TRANS_SERVER + +XtransConnInfo TRANS(OpenCOTSServer)( + char * /* address */ +); + +#endif /* TRANS_SERVER */ + +#ifdef TRANS_CLIENT + +XtransConnInfo TRANS(OpenCLTSClient)( + char * /* address */ +); + +#endif /* TRANS_CLIENT */ + +#ifdef TRANS_SERVER + +XtransConnInfo TRANS(OpenCLTSServer)( + char * /* address */ +); + +#endif /* TRANS_SERVER */ + +#ifdef TRANS_REOPEN + +XtransConnInfo TRANS(ReopenCOTSServer)( + int, /* trans_id */ + int, /* fd */ + char * /* port */ +); + +XtransConnInfo TRANS(ReopenCLTSServer)( + int, /* trans_id */ + int, /* fd */ + char * /* port */ +); + +int TRANS(GetReopenInfo)( + XtransConnInfo, /* ciptr */ + int *, /* trans_id */ + int *, /* fd */ + char ** /* port */ +); + +#endif /* TRANS_REOPEN */ + + +int TRANS(SetOption)( + XtransConnInfo, /* ciptr */ + int, /* option */ + int /* arg */ +); + +#ifdef TRANS_SERVER + +int TRANS(CreateListener)( + XtransConnInfo, /* ciptr */ + char *, /* port */ + unsigned int /* flags */ +); + +int TRANS(NoListen) ( + char* /* protocol*/ +); + +int TRANS(ResetListener)( + XtransConnInfo /* ciptr */ +); + +XtransConnInfo TRANS(Accept)( + XtransConnInfo, /* ciptr */ + int * /* status */ +); + +#endif /* TRANS_SERVER */ + +#ifdef TRANS_CLIENT + +int TRANS(Connect)( + XtransConnInfo, /* ciptr */ + char * /* address */ +); + +#endif /* TRANS_CLIENT */ + +int TRANS(BytesReadable)( + XtransConnInfo, /* ciptr */ + BytesReadable_t * /* pend */ +); + +int TRANS(Read)( + XtransConnInfo, /* ciptr */ + char *, /* buf */ + int /* size */ +); + +int TRANS(Write)( + XtransConnInfo, /* ciptr */ + char *, /* buf */ + int /* size */ +); + +int TRANS(Readv)( + XtransConnInfo, /* ciptr */ + struct iovec *, /* buf */ + int /* size */ +); + +int TRANS(Writev)( + XtransConnInfo, /* ciptr */ + struct iovec *, /* buf */ + int /* size */ +); + +int TRANS(Disconnect)( + XtransConnInfo /* ciptr */ +); + +int TRANS(Close)( + XtransConnInfo /* ciptr */ +); + +int TRANS(CloseForCloning)( + XtransConnInfo /* ciptr */ +); + +int TRANS(IsLocal)( + XtransConnInfo /* ciptr */ +); + +int TRANS(GetMyAddr)( + XtransConnInfo, /* ciptr */ + int *, /* familyp */ + int *, /* addrlenp */ + Xtransaddr ** /* addrp */ +); + +int TRANS(GetPeerAddr)( + XtransConnInfo, /* ciptr */ + int *, /* familyp */ + int *, /* addrlenp */ + Xtransaddr ** /* addrp */ +); + +int TRANS(GetConnectionNumber)( + XtransConnInfo /* ciptr */ +); + +#ifdef TRANS_SERVER + +int TRANS(MakeAllCOTSServerListeners)( + char *, /* port */ + int *, /* partial */ + int *, /* count_ret */ + XtransConnInfo ** /* ciptrs_ret */ +); + +int TRANS(MakeAllCLTSServerListeners)( + char *, /* port */ + int *, /* partial */ + int *, /* count_ret */ + XtransConnInfo ** /* ciptrs_ret */ +); + +#endif /* TRANS_SERVER */ + + +/* + * Function Prototypes for Utility Functions. + */ + +#ifdef X11_t + +int TRANS(ConvertAddress)( + int *, /* familyp */ + int *, /* addrlenp */ + Xtransaddr ** /* addrp */ +); + +#endif /* X11_t */ + +#ifdef ICE_t + +char * +TRANS(GetMyNetworkId)( + XtransConnInfo /* ciptr */ +); + +char * +TRANS(GetPeerNetworkId)( + XtransConnInfo /* ciptr */ +); + +#endif /* ICE_t */ + +int +TRANS(GetHostname) ( + char * /* buf */, + int /* maxlen */ +); + +#if defined(WIN32) && defined(TCPCONN) +int TRANS(WSAStartup)(); +#endif + +#endif /* _XTRANS_H_ */ diff --git a/X11/xtrans/Xtransint.h b/X11/xtrans/Xtransint.h index 3a4ad1788..ff3fd0b03 100644 --- a/X11/xtrans/Xtransint.h +++ b/X11/xtrans/Xtransint.h @@ -1,424 +1,424 @@ -/*
-
-Copyright 1993, 1994, 1998 The Open Group
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation.
-
-The above copyright notice and this permission notice shall be included
-in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
-OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall
-not be used in advertising or otherwise to promote the sale, use or
-other dealings in this Software without prior written authorization
-from The Open Group.
-
- * Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
- *
- * All Rights Reserved
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name NCR not be used in advertising
- * or publicity pertaining to distribution of the software without specific,
- * written prior permission. NCR makes no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- *
- * NCR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
- * NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
- * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
- * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#ifndef _XTRANSINT_H_
-#define _XTRANSINT_H_
-
-/*
- * XTRANSDEBUG will enable the PRMSG() macros used in the X Transport
- * Interface code. Each use of the PRMSG macro has a level associated with
- * it. XTRANSDEBUG is defined to be a level. If the invocation level is =<
- * the value of XTRANSDEBUG, then the message will be printed out to stderr.
- * Recommended levels are:
- *
- * XTRANSDEBUG=1 Error messages
- * XTRANSDEBUG=2 API Function Tracing
- * XTRANSDEBUG=3 All Function Tracing
- * XTRANSDEBUG=4 printing of intermediate values
- * XTRANSDEBUG=5 really detailed stuff
-#define XTRANSDEBUG 2
- *
- * Defining XTRANSDEBUGTIMESTAMP will cause printing timestamps with each
- * message.
- */
-
-#ifndef XTRANSDEBUG
-# define XTRANSDEBUG 1
-#endif
-
-#ifdef WIN32
-# define _WILLWINSOCK_
-#endif
-
-#include "Xtrans.h"
-
-#ifdef XTRANSDEBUG
-# include <stdio.h>
-#endif /* XTRANSDEBUG */
-
-#include <errno.h>
-
-#ifndef WIN32
-# include <sys/socket.h>
-# include <netinet/in.h>
-# include <arpa/inet.h>
-
-/*
- * Moved the setting of NEED_UTSNAME to this header file from Xtrans.c,
- * to avoid a race condition. JKJ (6/5/97)
- */
-
-# if defined(_POSIX_SOURCE) || defined(USG) || defined(SVR4) || defined(__SVR4) || defined(__SCO__)
-# ifndef NEED_UTSNAME
-# define NEED_UTSNAME
-# endif
-# include <sys/utsname.h>
-# endif
-
-# define ESET(val) errno = val
-# define EGET() errno
-
-#else /* WIN32 */
-
-# include <limits.h> /* for USHRT_MAX */
-
-# define ESET(val) WSASetLastError(val)
-# define EGET() WSAGetLastError()
-
-#endif /* WIN32 */
-
-#include <stddef.h>
-
-#ifdef X11_t
-#define X_TCP_PORT 6000
-#endif
-
-struct _XtransConnInfo {
- struct _Xtransport *transptr;
- int index;
- char *priv;
- int flags;
- int fd;
- char *port;
- int family;
- char *addr;
- int addrlen;
- char *peeraddr;
- int peeraddrlen;
-};
-
-#define XTRANS_OPEN_COTS_CLIENT 1
-#define XTRANS_OPEN_COTS_SERVER 2
-#define XTRANS_OPEN_CLTS_CLIENT 3
-#define XTRANS_OPEN_CLTS_SERVER 4
-
-
-typedef struct _Xtransport {
- char *TransName;
- int flags;
-
-#ifdef TRANS_CLIENT
-
- XtransConnInfo (*OpenCOTSClient)(
- struct _Xtransport *, /* transport */
- char *, /* protocol */
- char *, /* host */
- char * /* port */
- );
-
-#endif /* TRANS_CLIENT */
-
-#ifdef TRANS_SERVER
- char ** nolisten;
- XtransConnInfo (*OpenCOTSServer)(
- struct _Xtransport *, /* transport */
- char *, /* protocol */
- char *, /* host */
- char * /* port */
- );
-
-#endif /* TRANS_SERVER */
-
-#ifdef TRANS_CLIENT
-
- XtransConnInfo (*OpenCLTSClient)(
- struct _Xtransport *, /* transport */
- char *, /* protocol */
- char *, /* host */
- char * /* port */
- );
-
-#endif /* TRANS_CLIENT */
-
-#ifdef TRANS_SERVER
-
- XtransConnInfo (*OpenCLTSServer)(
- struct _Xtransport *, /* transport */
- char *, /* protocol */
- char *, /* host */
- char * /* port */
- );
-
-#endif /* TRANS_SERVER */
-
-
-#ifdef TRANS_REOPEN
-
- XtransConnInfo (*ReopenCOTSServer)(
- struct _Xtransport *, /* transport */
- int, /* fd */
- char * /* port */
- );
-
- XtransConnInfo (*ReopenCLTSServer)(
- struct _Xtransport *, /* transport */
- int, /* fd */
- char * /* port */
- );
-
-#endif /* TRANS_REOPEN */
-
-
- int (*SetOption)(
- XtransConnInfo, /* connection */
- int, /* option */
- int /* arg */
- );
-
-#ifdef TRANS_SERVER
-/* Flags */
-# define ADDR_IN_USE_ALLOWED 1
-
- int (*CreateListener)(
- XtransConnInfo, /* connection */
- char *, /* port */
- unsigned int /* flags */
- );
-
- int (*ResetListener)(
- XtransConnInfo /* connection */
- );
-
- XtransConnInfo (*Accept)(
- XtransConnInfo, /* connection */
- int * /* status */
- );
-
-#endif /* TRANS_SERVER */
-
-#ifdef TRANS_CLIENT
-
- int (*Connect)(
- XtransConnInfo, /* connection */
- char *, /* host */
- char * /* port */
- );
-
-#endif /* TRANS_CLIENT */
-
- int (*BytesReadable)(
- XtransConnInfo, /* connection */
- BytesReadable_t * /* pend */
- );
-
- int (*Read)(
- XtransConnInfo, /* connection */
- char *, /* buf */
- int /* size */
- );
-
- int (*Write)(
- XtransConnInfo, /* connection */
- char *, /* buf */
- int /* size */
- );
-
- int (*Readv)(
- XtransConnInfo, /* connection */
- struct iovec *, /* buf */
- int /* size */
- );
-
- int (*Writev)(
- XtransConnInfo, /* connection */
- struct iovec *, /* buf */
- int /* size */
- );
-
- int (*Disconnect)(
- XtransConnInfo /* connection */
- );
-
- int (*Close)(
- XtransConnInfo /* connection */
- );
-
- int (*CloseForCloning)(
- XtransConnInfo /* connection */
- );
-
-} Xtransport;
-
-
-typedef struct _Xtransport_table {
- Xtransport *transport;
- int transport_id;
-} Xtransport_table;
-
-
-/*
- * Flags for the flags member of Xtransport.
- */
-
-#define TRANS_ALIAS (1<<0) /* record is an alias, don't create server */
-#define TRANS_LOCAL (1<<1) /* local transport */
-#define TRANS_DISABLED (1<<2) /* Don't open this one */
-#define TRANS_NOLISTEN (1<<3) /* Don't listen on this one */
-#define TRANS_NOUNLINK (1<<4) /* Don't unlink transport endpoints */
-#define TRANS_ABSTRACT (1<<5) /* Use abstract sockets if available */
-#define TRANS_NOXAUTH (1<<6) /* Don't verify authentication (because it's secure some other way at the OS layer) */
-
-/* Flags to preserve when setting others */
-#define TRANS_KEEPFLAGS (TRANS_NOUNLINK|TRANS_ABSTRACT)
-
-#ifdef __clang__
-/* Not all clients make use of all provided statics */
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wunused-function"
-#endif
-
-/*
- * readv() and writev() don't exist or don't work correctly on some
- * systems, so they may be emulated.
- */
-
-#if defined(SYSV) && defined(__i386__) && !defined(__SCO__) && !defined(sun) || defined(WIN32)
-
-#define READV(ciptr, iov, iovcnt) TRANS(ReadV)(ciptr, iov, iovcnt)
-
-static int TRANS(ReadV)(
- XtransConnInfo, /* ciptr */
- struct iovec *, /* iov */
- int /* iovcnt */
-);
-
-#else
-
-#define READV(ciptr, iov, iovcnt) readv(ciptr->fd, iov, iovcnt)
-
-#endif /* CRAY || (SYSV && __i386__) || WIN32 || __sxg__ || */
-
-
-#if defined(SYSV) && defined(__i386__) && !defined(__SCO__) && !defined(sun) || defined(WIN32)
-
-#define WRITEV(ciptr, iov, iovcnt) TRANS(WriteV)(ciptr, iov, iovcnt)
-
-static int TRANS(WriteV)(
- XtransConnInfo, /* ciptr */
- struct iovec *, /* iov */
- int /* iovcnt */
-);
-
-#else
-
-#define WRITEV(ciptr, iov, iovcnt) writev(ciptr->fd, iov, iovcnt)
-
-#endif /* CRAY || WIN32 || __sxg__ */
-
-
-static int is_numeric (
- const char * /* str */
-);
-
-#ifdef TRANS_SERVER
-static int trans_mkdir (
- const char *, /* path */
- int /* mode */
-);
-#endif
-
-#ifdef __clang__
-#pragma clang diagnostic pop
-#endif
-
-/*
- * Some XTRANSDEBUG stuff
- */
-
-#if defined(XTRANSDEBUG)
-/* add hack to the format string to avoid warnings about extra arguments
- * to fprintf.
- */
-#ifdef XTRANSDEBUGTIMESTAMP
-#if defined(XSERV_t) && defined(TRANS_SERVER)
-/* Use ErrorF() for the X server */
-#define PRMSG(lvl,x,a,b,c) if (lvl <= XTRANSDEBUG){ \
- int hack= 0, saveerrno=errno; \
- struct timeval tp;\
- gettimeofday(&tp,0); \
- ErrorF("%s",__xtransname); \
- ErrorF(x+hack,a,b,c); \
- ErrorF("timestamp (ms): %d\n",tp.tv_sec*1000+tp.tv_usec/1000); \
- errno=saveerrno; \
- } else ((void)0)
-#else
-#define PRMSG(lvl,x,a,b,c) if (lvl <= XTRANSDEBUG){ \
- int hack= 0, saveerrno=errno; \
- struct timeval tp;\
- gettimeofday(&tp,0); \
- fprintf(stderr, "%s", __xtransname); fflush(stderr); \
- fprintf(stderr, x+hack,a,b,c); fflush(stderr); \
- fprintf(stderr, "timestamp (ms): %d\n",tp.tv_sec*1000+tp.tv_usec/1000); \
- fflush(stderr); \
- errno=saveerrno; \
- } else ((void)0)
-#endif /* XSERV_t && TRANS_SERVER */
-#else /* XTRANSDEBUGTIMESTAMP */
-#if defined(XSERV_t) && defined(TRANS_SERVER)
-/* Use ErrorF() for the X server */
-#define PRMSG(lvl,x,a,b,c) if (lvl <= XTRANSDEBUG){ \
- int hack= 0, saveerrno=errno; \
- ErrorF("%s",__xtransname); \
- ErrorF(x+hack,a,b,c); \
- errno=saveerrno; \
- } else ((void)0)
-#else
-#define PRMSG(lvl,x,a,b,c) if (lvl <= XTRANSDEBUG){ \
- int hack= 0, saveerrno=errno; \
- fprintf(stderr, "%s", __xtransname); fflush(stderr); \
- fprintf(stderr, x+hack,a,b,c); fflush(stderr); \
- errno=saveerrno; \
- } else ((void)0)
-#endif /* XSERV_t && TRANS_SERVER */
-#endif /* XTRANSDEBUGTIMESTAMP */
-#else
-#define PRMSG(lvl,x,a,b,c) ((void)0)
-#endif /* XTRANSDEBUG */
-
-#endif /* _XTRANSINT_H_ */
+/* + +Copyright 1993, 1994, 1998 The Open Group + +Permission to use, copy, modify, distribute, and sell this software and its +documentation for any purpose is hereby granted without fee, provided that +the above copyright notice appear in all copies and that both that +copyright notice and this permission notice appear in supporting +documentation. + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall +not be used in advertising or otherwise to promote the sale, use or +other dealings in this Software without prior written authorization +from The Open Group. + + * Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA + * + * All Rights Reserved + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name NCR not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. NCR makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * NCR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _XTRANSINT_H_ +#define _XTRANSINT_H_ + +/* + * XTRANSDEBUG will enable the PRMSG() macros used in the X Transport + * Interface code. Each use of the PRMSG macro has a level associated with + * it. XTRANSDEBUG is defined to be a level. If the invocation level is =< + * the value of XTRANSDEBUG, then the message will be printed out to stderr. + * Recommended levels are: + * + * XTRANSDEBUG=1 Error messages + * XTRANSDEBUG=2 API Function Tracing + * XTRANSDEBUG=3 All Function Tracing + * XTRANSDEBUG=4 printing of intermediate values + * XTRANSDEBUG=5 really detailed stuff +#define XTRANSDEBUG 2 + * + * Defining XTRANSDEBUGTIMESTAMP will cause printing timestamps with each + * message. + */ + +#ifndef XTRANSDEBUG +# define XTRANSDEBUG 1 +#endif + +#ifdef WIN32 +# define _WILLWINSOCK_ +#endif + +#include "Xtrans.h" + +#ifdef XTRANSDEBUG +# include <stdio.h> +#endif /* XTRANSDEBUG */ + +#include <errno.h> + +#ifndef WIN32 +# include <sys/socket.h> +# include <netinet/in.h> +# include <arpa/inet.h> + +/* + * Moved the setting of NEED_UTSNAME to this header file from Xtrans.c, + * to avoid a race condition. JKJ (6/5/97) + */ + +# if defined(_POSIX_SOURCE) || defined(USG) || defined(SVR4) || defined(__SVR4) || defined(__SCO__) +# ifndef NEED_UTSNAME +# define NEED_UTSNAME +# endif +# include <sys/utsname.h> +# endif + +# define ESET(val) errno = val +# define EGET() errno + +#else /* WIN32 */ + +# include <limits.h> /* for USHRT_MAX */ + +# define ESET(val) WSASetLastError(val) +# define EGET() WSAGetLastError() + +#endif /* WIN32 */ + +#include <stddef.h> + +#ifdef X11_t +#define X_TCP_PORT 6000 +#endif + +struct _XtransConnInfo { + struct _Xtransport *transptr; + int index; + char *priv; + int flags; + int fd; + char *port; + int family; + char *addr; + int addrlen; + char *peeraddr; + int peeraddrlen; +}; + +#define XTRANS_OPEN_COTS_CLIENT 1 +#define XTRANS_OPEN_COTS_SERVER 2 +#define XTRANS_OPEN_CLTS_CLIENT 3 +#define XTRANS_OPEN_CLTS_SERVER 4 + + +typedef struct _Xtransport { + char *TransName; + int flags; + +#ifdef TRANS_CLIENT + + XtransConnInfo (*OpenCOTSClient)( + struct _Xtransport *, /* transport */ + char *, /* protocol */ + char *, /* host */ + char * /* port */ + ); + +#endif /* TRANS_CLIENT */ + +#ifdef TRANS_SERVER + char ** nolisten; + XtransConnInfo (*OpenCOTSServer)( + struct _Xtransport *, /* transport */ + char *, /* protocol */ + char *, /* host */ + char * /* port */ + ); + +#endif /* TRANS_SERVER */ + +#ifdef TRANS_CLIENT + + XtransConnInfo (*OpenCLTSClient)( + struct _Xtransport *, /* transport */ + char *, /* protocol */ + char *, /* host */ + char * /* port */ + ); + +#endif /* TRANS_CLIENT */ + +#ifdef TRANS_SERVER + + XtransConnInfo (*OpenCLTSServer)( + struct _Xtransport *, /* transport */ + char *, /* protocol */ + char *, /* host */ + char * /* port */ + ); + +#endif /* TRANS_SERVER */ + + +#ifdef TRANS_REOPEN + + XtransConnInfo (*ReopenCOTSServer)( + struct _Xtransport *, /* transport */ + int, /* fd */ + char * /* port */ + ); + + XtransConnInfo (*ReopenCLTSServer)( + struct _Xtransport *, /* transport */ + int, /* fd */ + char * /* port */ + ); + +#endif /* TRANS_REOPEN */ + + + int (*SetOption)( + XtransConnInfo, /* connection */ + int, /* option */ + int /* arg */ + ); + +#ifdef TRANS_SERVER +/* Flags */ +# define ADDR_IN_USE_ALLOWED 1 + + int (*CreateListener)( + XtransConnInfo, /* connection */ + char *, /* port */ + unsigned int /* flags */ + ); + + int (*ResetListener)( + XtransConnInfo /* connection */ + ); + + XtransConnInfo (*Accept)( + XtransConnInfo, /* connection */ + int * /* status */ + ); + +#endif /* TRANS_SERVER */ + +#ifdef TRANS_CLIENT + + int (*Connect)( + XtransConnInfo, /* connection */ + char *, /* host */ + char * /* port */ + ); + +#endif /* TRANS_CLIENT */ + + int (*BytesReadable)( + XtransConnInfo, /* connection */ + BytesReadable_t * /* pend */ + ); + + int (*Read)( + XtransConnInfo, /* connection */ + char *, /* buf */ + int /* size */ + ); + + int (*Write)( + XtransConnInfo, /* connection */ + char *, /* buf */ + int /* size */ + ); + + int (*Readv)( + XtransConnInfo, /* connection */ + struct iovec *, /* buf */ + int /* size */ + ); + + int (*Writev)( + XtransConnInfo, /* connection */ + struct iovec *, /* buf */ + int /* size */ + ); + + int (*Disconnect)( + XtransConnInfo /* connection */ + ); + + int (*Close)( + XtransConnInfo /* connection */ + ); + + int (*CloseForCloning)( + XtransConnInfo /* connection */ + ); + +} Xtransport; + + +typedef struct _Xtransport_table { + Xtransport *transport; + int transport_id; +} Xtransport_table; + + +/* + * Flags for the flags member of Xtransport. + */ + +#define TRANS_ALIAS (1<<0) /* record is an alias, don't create server */ +#define TRANS_LOCAL (1<<1) /* local transport */ +#define TRANS_DISABLED (1<<2) /* Don't open this one */ +#define TRANS_NOLISTEN (1<<3) /* Don't listen on this one */ +#define TRANS_NOUNLINK (1<<4) /* Don't unlink transport endpoints */ +#define TRANS_ABSTRACT (1<<5) /* Use abstract sockets if available */ +#define TRANS_NOXAUTH (1<<6) /* Don't verify authentication (because it's secure some other way at the OS layer) */ + +/* Flags to preserve when setting others */ +#define TRANS_KEEPFLAGS (TRANS_NOUNLINK|TRANS_ABSTRACT) + +#ifdef __clang__ +/* Not all clients make use of all provided statics */ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-function" +#endif + +/* + * readv() and writev() don't exist or don't work correctly on some + * systems, so they may be emulated. + */ + +#if defined(SYSV) && defined(__i386__) && !defined(__SCO__) && !defined(sun) || defined(WIN32) + +#define READV(ciptr, iov, iovcnt) TRANS(ReadV)(ciptr, iov, iovcnt) + +static int TRANS(ReadV)( + XtransConnInfo, /* ciptr */ + struct iovec *, /* iov */ + int /* iovcnt */ +); + +#else + +#define READV(ciptr, iov, iovcnt) readv(ciptr->fd, iov, iovcnt) + +#endif /* CRAY || (SYSV && __i386__) || WIN32 || __sxg__ || */ + + +#if defined(SYSV) && defined(__i386__) && !defined(__SCO__) && !defined(sun) || defined(WIN32) + +#define WRITEV(ciptr, iov, iovcnt) TRANS(WriteV)(ciptr, iov, iovcnt) + +static int TRANS(WriteV)( + XtransConnInfo, /* ciptr */ + struct iovec *, /* iov */ + int /* iovcnt */ +); + +#else + +#define WRITEV(ciptr, iov, iovcnt) writev(ciptr->fd, iov, iovcnt) + +#endif /* CRAY || WIN32 || __sxg__ */ + + +static int is_numeric ( + const char * /* str */ +); + +#ifdef TRANS_SERVER +static int trans_mkdir ( + const char *, /* path */ + int /* mode */ +); +#endif + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + +/* + * Some XTRANSDEBUG stuff + */ + +#if defined(XTRANSDEBUG) +/* add hack to the format string to avoid warnings about extra arguments + * to fprintf. + */ +#ifdef XTRANSDEBUGTIMESTAMP +#if defined(XSERV_t) && defined(TRANS_SERVER) +/* Use ErrorF() for the X server */ +#define PRMSG(lvl,x,a,b,c) if (lvl <= XTRANSDEBUG){ \ + int hack= 0, saveerrno=errno; \ + struct timeval tp;\ + gettimeofday(&tp,0); \ + ErrorF("%s",__xtransname); \ + ErrorF(x+hack,a,b,c); \ + ErrorF("timestamp (ms): %d\n",tp.tv_sec*1000+tp.tv_usec/1000); \ + errno=saveerrno; \ + } else ((void)0) +#else +#define PRMSG(lvl,x,a,b,c) if (lvl <= XTRANSDEBUG){ \ + int hack= 0, saveerrno=errno; \ + struct timeval tp;\ + gettimeofday(&tp,0); \ + fprintf(stderr, "%s", __xtransname); fflush(stderr); \ + fprintf(stderr, x+hack,a,b,c); fflush(stderr); \ + fprintf(stderr, "timestamp (ms): %d\n",tp.tv_sec*1000+tp.tv_usec/1000); \ + fflush(stderr); \ + errno=saveerrno; \ + } else ((void)0) +#endif /* XSERV_t && TRANS_SERVER */ +#else /* XTRANSDEBUGTIMESTAMP */ +#if defined(XSERV_t) && defined(TRANS_SERVER) +/* Use ErrorF() for the X server */ +#define PRMSG(lvl,x,a,b,c) if (lvl <= XTRANSDEBUG){ \ + int hack= 0, saveerrno=errno; \ + ErrorF("%s",__xtransname); \ + ErrorF(x+hack,a,b,c); \ + errno=saveerrno; \ + } else ((void)0) +#else +#define PRMSG(lvl,x,a,b,c) if (lvl <= XTRANSDEBUG){ \ + int hack= 0, saveerrno=errno; \ + fprintf(stderr, "%s", __xtransname); fflush(stderr); \ + fprintf(stderr, x+hack,a,b,c); fflush(stderr); \ + errno=saveerrno; \ + } else ((void)0) +#endif /* XSERV_t && TRANS_SERVER */ +#endif /* XTRANSDEBUGTIMESTAMP */ +#else +#define PRMSG(lvl,x,a,b,c) ((void)0) +#endif /* XTRANSDEBUG */ + +#endif /* _XTRANSINT_H_ */ diff --git a/X11/xtrans/configure.ac b/X11/xtrans/configure.ac index 7e0451e32..3b38d29de 100644 --- a/X11/xtrans/configure.ac +++ b/X11/xtrans/configure.ac @@ -1,64 +1,64 @@ -# Copyright © 2003 Keith Packard, Noah Levitt
-#
-# Permission to use, copy, modify, distribute, and sell this software and its
-# documentation for any purpose is hereby granted without fee, provided that
-# the above copyright notice appear in all copies and that both that
-# copyright notice and this permission notice appear in supporting
-# documentation, and that the name of Keith Packard not be used in
-# advertising or publicity pertaining to distribution of the software without
-# specific, written prior permission. Keith Packard makes no
-# representations about the suitability of this software for any purpose. It
-# is provided "as is" without express or implied warranty.
-#
-# KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
-# EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
-# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
-# DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
-# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-# PERFORMANCE OF THIS SOFTWARE.
-#
-
-# Initialize Autoconf
-AC_PREREQ([2.60])
-AC_INIT([xtrans], [1.2.6],
- [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], [xtrans])
-AC_CONFIG_SRCDIR([Makefile.am])
-
-# Initialize Automake
-AM_INIT_AUTOMAKE([foreign dist-bzip2])
-AM_MAINTAINER_MODE
-
-# Require xorg-macros minimum of 1.12 for DocBook external references
-m4_ifndef([XORG_MACROS_VERSION],
- [m4_fatal([must install xorg-macros 1.12 or later before running autoconf/autogen])])
-XORG_MACROS_VERSION(1.12)
-XORG_DEFAULT_OPTIONS
-XORG_ENABLE_DOCS
-XORG_WITH_XMLTO(0.0.22)
-XORG_WITH_FOP
-XORG_WITH_XSLTPROC
-XORG_CHECK_SGML_DOCTOOLS(1.8)
-
-# Because xtrans is included into other modules rather than being linked
-# with, these defines have to be added to the cflags line
-
-# fchown()
-
-AC_CHECK_FUNC(fchown, [fchown_define="-DHAS_FCHOWN"], [fchown_define=""])
-
-AC_SUBST(fchown_define)
-
-# sticky bit
-#
-# if any system exists without sticky dir bits this
-# needs to be redone with a real autoconf test
-
-sticky_bit_define="-DHAS_STICKY_DIR_BIT"
-
-AC_SUBST(sticky_bit_define)
-
-AC_CONFIG_FILES([Makefile
- doc/Makefile
- xtrans.pc])
-AC_OUTPUT
+# Copyright © 2003 Keith Packard, Noah Levitt +# +# Permission to use, copy, modify, distribute, and sell this software and its +# documentation for any purpose is hereby granted without fee, provided that +# the above copyright notice appear in all copies and that both that +# copyright notice and this permission notice appear in supporting +# documentation, and that the name of Keith Packard not be used in +# advertising or publicity pertaining to distribution of the software without +# specific, written prior permission. Keith Packard makes no +# representations about the suitability of this software for any purpose. It +# is provided "as is" without express or implied warranty. +# +# KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO +# EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR +# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, +# DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. +# + +# Initialize Autoconf +AC_PREREQ([2.60]) +AC_INIT([xtrans], [1.2.6], + [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], [xtrans]) +AC_CONFIG_SRCDIR([Makefile.am]) + +# Initialize Automake +AM_INIT_AUTOMAKE([foreign dist-bzip2]) +AM_MAINTAINER_MODE + +# Require xorg-macros minimum of 1.12 for DocBook external references +m4_ifndef([XORG_MACROS_VERSION], + [m4_fatal([must install xorg-macros 1.12 or later before running autoconf/autogen])]) +XORG_MACROS_VERSION(1.12) +XORG_DEFAULT_OPTIONS +XORG_ENABLE_DOCS +XORG_WITH_XMLTO(0.0.22) +XORG_WITH_FOP +XORG_WITH_XSLTPROC +XORG_CHECK_SGML_DOCTOOLS(1.8) + +# Because xtrans is included into other modules rather than being linked +# with, these defines have to be added to the cflags line + +# fchown() + +AC_CHECK_FUNC(fchown, [fchown_define="-DHAS_FCHOWN"], [fchown_define=""]) + +AC_SUBST(fchown_define) + +# sticky bit +# +# if any system exists without sticky dir bits this +# needs to be redone with a real autoconf test + +sticky_bit_define="-DHAS_STICKY_DIR_BIT" + +AC_SUBST(sticky_bit_define) + +AC_CONFIG_FILES([Makefile + doc/Makefile + xtrans.pc]) +AC_OUTPUT diff --git a/X11/xtrans/doc/Makefile.am b/X11/xtrans/doc/Makefile.am index 1b67837f1..014c956ae 100644 --- a/X11/xtrans/doc/Makefile.am +++ b/X11/xtrans/doc/Makefile.am @@ -1,13 +1,13 @@ -
-if ENABLE_DOCS
-
-# Main DocBook/XML files (DOCTYPE book)
-docbook = xtrans.xml
-
-# The location where the DocBook/XML files and their generated formats are installed
-shelfdir = $(docdir)
-
-# Generate DocBook/XML output formats with or without stylesheets
-include $(top_srcdir)/docbook.am
-
-endif ENABLE_DOCS
+ +if ENABLE_DOCS + +# Main DocBook/XML files (DOCTYPE book) +docbook = xtrans.xml + +# The location where the DocBook/XML files and their generated formats are installed +shelfdir = $(docdir) + +# Generate DocBook/XML output formats with or without stylesheets +include $(top_srcdir)/docbook.am + +endif ENABLE_DOCS diff --git a/X11/xtrans/transport.c b/X11/xtrans/transport.c index 246a7e2a1..0013b01d8 100644 --- a/X11/xtrans/transport.c +++ b/X11/xtrans/transport.c @@ -1,78 +1,78 @@ -/*
-
-Copyright 1993, 1994, 1998 The Open Group
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation.
-
-The above copyright notice and this permission notice shall be included
-in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
-OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall
-not be used in advertising or otherwise to promote the sale, use or
-other dealings in this Software without prior written authorization
-from The Open Group.
-
- * Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
- *
- * All Rights Reserved
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name NCR not be used in advertising
- * or publicity pertaining to distribution of the software without specific,
- * written prior permission. NCR makes no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- *
- * NCR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
- * NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
- * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
- * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <stdlib.h>
-#define xalloc(_size) malloc(_size)
-#define xcalloc(_num,_size) calloc(_num,_size)
-#define xrealloc(_ptr,_size) realloc(_ptr,_size)
-#define xfree(_ptr) free(_ptr)
-
-#include "Xtransint.h"
-
-#ifdef __clang__
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wformat-nonliteral"
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
-#endif
-
-#ifdef LOCALCONN
-#include "Xtranslcl.c"
-#endif
-#if defined(TCPCONN) || defined(UNIXCONN)
-#include "Xtranssock.c"
-#endif
-#ifdef STREAMSCONN
-#include "Xtranstli.c"
-#endif
-#include "Xtrans.c"
-#include "Xtransutil.c"
-
-#ifdef __clang__
-#pragma clang diagnostic pop
-#endif
+/* + +Copyright 1993, 1994, 1998 The Open Group + +Permission to use, copy, modify, distribute, and sell this software and its +documentation for any purpose is hereby granted without fee, provided that +the above copyright notice appear in all copies and that both that +copyright notice and this permission notice appear in supporting +documentation. + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall +not be used in advertising or otherwise to promote the sale, use or +other dealings in this Software without prior written authorization +from The Open Group. + + * Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA + * + * All Rights Reserved + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name NCR not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. NCR makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * NCR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <stdlib.h> +#define xalloc(_size) malloc(_size) +#define xcalloc(_num,_size) calloc(_num,_size) +#define xrealloc(_ptr,_size) realloc(_ptr,_size) +#define xfree(_ptr) free(_ptr) + +#include "Xtransint.h" + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wformat-nonliteral" +#pragma clang diagnostic ignored "-Wdeprecated-declarations" +#endif + +#ifdef LOCALCONN +#include "Xtranslcl.c" +#endif +#if defined(TCPCONN) || defined(UNIXCONN) +#include "Xtranssock.c" +#endif +#ifdef STREAMSCONN +#include "Xtranstli.c" +#endif +#include "Xtrans.c" +#include "Xtransutil.c" + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif |