173143b9aSmrg/*
273143b9aSmrg
373143b9aSmrgCopyright 1993, 1994, 1998  The Open Group
473143b9aSmrg
573143b9aSmrgPermission to use, copy, modify, distribute, and sell this software and its
673143b9aSmrgdocumentation for any purpose is hereby granted without fee, provided that
773143b9aSmrgthe above copyright notice appear in all copies and that both that
873143b9aSmrgcopyright notice and this permission notice appear in supporting
973143b9aSmrgdocumentation.
1073143b9aSmrg
1173143b9aSmrgThe above copyright notice and this permission notice shall be included
1273143b9aSmrgin all copies or substantial portions of the Software.
1373143b9aSmrg
1473143b9aSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1573143b9aSmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1673143b9aSmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
1773143b9aSmrgIN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
1873143b9aSmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1973143b9aSmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2073143b9aSmrgOTHER DEALINGS IN THE SOFTWARE.
2173143b9aSmrg
2273143b9aSmrgExcept as contained in this notice, the name of The Open Group shall
2373143b9aSmrgnot be used in advertising or otherwise to promote the sale, use or
2473143b9aSmrgother dealings in this Software without prior written authorization
2573143b9aSmrgfrom The Open Group.
2673143b9aSmrg
2773143b9aSmrg * Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
2873143b9aSmrg *
2973143b9aSmrg * All Rights Reserved
3073143b9aSmrg *
3173143b9aSmrg * Permission to use, copy, modify, and distribute this software and its
3273143b9aSmrg * documentation for any purpose and without fee is hereby granted, provided
3373143b9aSmrg * that the above copyright notice appear in all copies and that both that
3473143b9aSmrg * copyright notice and this permission notice appear in supporting
3573143b9aSmrg * documentation, and that the name NCR not be used in advertising
3673143b9aSmrg * or publicity pertaining to distribution of the software without specific,
3773143b9aSmrg * written prior permission.  NCR makes no representations about the
3873143b9aSmrg * suitability of this software for any purpose.  It is provided "as is"
3973143b9aSmrg * without express or implied warranty.
4073143b9aSmrg *
4173143b9aSmrg * NCR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
4273143b9aSmrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
4373143b9aSmrg * NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR
4473143b9aSmrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
4573143b9aSmrg * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
4673143b9aSmrg * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
4773143b9aSmrg * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
4873143b9aSmrg */
4973143b9aSmrg
5073143b9aSmrg#ifndef _XTRANS_H_
5173143b9aSmrg#define _XTRANS_H_
5273143b9aSmrg
5373143b9aSmrg#include <X11/Xfuncproto.h>
5473143b9aSmrg#include <X11/Xos.h>
553d2ed3e3Smrg#include <X11/Xmd.h>
5673143b9aSmrg
5773143b9aSmrg#ifndef WIN32
5873143b9aSmrg#include <sys/socket.h>
5973143b9aSmrg#endif
6073143b9aSmrg
61fe567363Smrg#ifdef __clang__
62fe567363Smrg/* Not all clients make use of all provided statics */
63fe567363Smrg#pragma clang diagnostic push
64fe567363Smrg#pragma clang diagnostic ignored "-Wunused-function"
65fe567363Smrg#endif
6673143b9aSmrg
6773143b9aSmrg/*
6873143b9aSmrg * Set the functions names according to where this code is being compiled.
6973143b9aSmrg */
7073143b9aSmrg
7173143b9aSmrg#ifdef X11_t
7273143b9aSmrg#define TRANS(func) _X11Trans##func
7373143b9aSmrg#ifdef XTRANSDEBUG
74fe567363Smrgstatic const char *__xtransname = "_X11Trans";
7573143b9aSmrg#endif
7673143b9aSmrg#endif /* X11_t */
7773143b9aSmrg
7873143b9aSmrg#ifdef XSERV_t
7973143b9aSmrg#define TRANS(func) _XSERVTrans##func
8073143b9aSmrg#ifdef XTRANSDEBUG
81fe567363Smrgstatic const char *__xtransname = "_XSERVTrans";
8273143b9aSmrg#endif
8373143b9aSmrg#define X11_t
8473143b9aSmrg#endif /* XSERV_t */
8573143b9aSmrg
8673143b9aSmrg#ifdef XIM_t
8773143b9aSmrg#define TRANS(func) _XimXTrans##func
8873143b9aSmrg#ifdef XTRANSDEBUG
89fe567363Smrgstatic const char *__xtransname = "_XimTrans";
9073143b9aSmrg#endif
9173143b9aSmrg#endif /* XIM_t */
9273143b9aSmrg
9373143b9aSmrg#ifdef FS_t
9473143b9aSmrg#define TRANS(func) _FSTrans##func
9573143b9aSmrg#ifdef XTRANSDEBUG
96fe567363Smrgstatic const char *__xtransname = "_FSTrans";
9773143b9aSmrg#endif
9873143b9aSmrg#endif /* FS_t */
9973143b9aSmrg
10073143b9aSmrg#ifdef FONT_t
10173143b9aSmrg#define TRANS(func) _FontTrans##func
10273143b9aSmrg#ifdef XTRANSDEBUG
103fe567363Smrgstatic const char *__xtransname = "_FontTrans";
10473143b9aSmrg#endif
10573143b9aSmrg#endif /* FONT_t */
10673143b9aSmrg
10773143b9aSmrg#ifdef ICE_t
10873143b9aSmrg#define TRANS(func) _IceTrans##func
10973143b9aSmrg#ifdef XTRANSDEBUG
110fe567363Smrgstatic const char *__xtransname = "_IceTrans";
11173143b9aSmrg#endif
11273143b9aSmrg#endif /* ICE_t */
11373143b9aSmrg
11473143b9aSmrg#if !defined(TRANS)
11573143b9aSmrg#define TRANS(func) _XTrans##func
11673143b9aSmrg#ifdef XTRANSDEBUG
117fe567363Smrgstatic const char *__xtransname = "_XTrans";
11873143b9aSmrg#endif
11973143b9aSmrg#endif /* !TRANS */
12073143b9aSmrg
121fe567363Smrg#ifdef __clang__
122fe567363Smrg#pragma clang diagnostic pop
123fe567363Smrg#endif
12473143b9aSmrg
12573143b9aSmrg/*
12673143b9aSmrg * Create a single address structure that can be used wherever
12773143b9aSmrg * an address structure is needed. struct sockaddr is not big enough
12873143b9aSmrg * to hold a sockadd_un, so we create this definition to have a single
12973143b9aSmrg * structure that is big enough for all the structures we might need.
13073143b9aSmrg *
13173143b9aSmrg * This structure needs to be independent of the socket/TLI interface used.
13273143b9aSmrg */
13373143b9aSmrg
134a1910677Smrg/* Temporary workaround for consumers whose configure scripts were
135a1910677Smrg   generated with pre-1.6 versions of xtrans.m4 */
136a1910677Smrg#if defined(IPv6) && !defined(HAVE_STRUCT_SOCKADDR_STORAGE)
137a1910677Smrg#define HAVE_STRUCT_SOCKADDR_STORAGE
138a1910677Smrg#endif
139a1910677Smrg
140a1910677Smrg#ifdef HAVE_STRUCT_SOCKADDR_STORAGE
14173143b9aSmrgtypedef struct sockaddr_storage Xtransaddr;
14273143b9aSmrg#else
14373143b9aSmrg#define XTRANS_MAX_ADDR_LEN	128	/* large enough to hold sun_path */
14473143b9aSmrg
14573143b9aSmrgtypedef	struct {
14673143b9aSmrg    unsigned char	addr[XTRANS_MAX_ADDR_LEN];
14773143b9aSmrg} Xtransaddr;
14873143b9aSmrg#endif
14973143b9aSmrg
15073143b9aSmrg#ifdef LONG64
15173143b9aSmrgtypedef int BytesReadable_t;
15273143b9aSmrg#else
15373143b9aSmrgtypedef long BytesReadable_t;
15473143b9aSmrg#endif
15573143b9aSmrg
15673143b9aSmrg
157e45ace2bSmrg#if defined(WIN32)
15873143b9aSmrg
15973143b9aSmrg/*
16073143b9aSmrg *      TRANS(Readv) and TRANS(Writev) use struct iovec, normally found
16173143b9aSmrg *      in Berkeley systems in <sys/uio.h>.  See the readv(2) and writev(2)
16273143b9aSmrg *      manual pages for details.
16373143b9aSmrg */
16473143b9aSmrg
16573143b9aSmrgstruct iovec {
16673143b9aSmrg    caddr_t iov_base;
16773143b9aSmrg    int iov_len;
16873143b9aSmrg};
16973143b9aSmrg
17073143b9aSmrg#else
17173143b9aSmrg#include <sys/uio.h>
17273143b9aSmrg#endif
17373143b9aSmrg
17473143b9aSmrgtypedef struct _XtransConnInfo *XtransConnInfo;
17573143b9aSmrg
17673143b9aSmrg
17773143b9aSmrg/*
17873143b9aSmrg * Transport Option definitions
17973143b9aSmrg */
18073143b9aSmrg
18173143b9aSmrg#define TRANS_NONBLOCKING	1
18273143b9aSmrg#define	TRANS_CLOSEONEXEC	2
18373143b9aSmrg
18473143b9aSmrg
18573143b9aSmrg/*
18673143b9aSmrg * Return values of Connect (0 is success)
18773143b9aSmrg */
18873143b9aSmrg
18973143b9aSmrg#define TRANS_CONNECT_FAILED 	-1
19073143b9aSmrg#define TRANS_TRY_CONNECT_AGAIN -2
19173143b9aSmrg#define TRANS_IN_PROGRESS	-3
19273143b9aSmrg
19373143b9aSmrg
19473143b9aSmrg/*
19573143b9aSmrg * Return values of CreateListener (0 is success)
19673143b9aSmrg */
19773143b9aSmrg
19873143b9aSmrg#define TRANS_CREATE_LISTENER_FAILED 	-1
19973143b9aSmrg#define TRANS_ADDR_IN_USE		-2
20073143b9aSmrg
20173143b9aSmrg
20273143b9aSmrg/*
20373143b9aSmrg * Return values of Accept (0 is success)
20473143b9aSmrg */
20573143b9aSmrg
20673143b9aSmrg#define TRANS_ACCEPT_BAD_MALLOC			-1
20773143b9aSmrg#define TRANS_ACCEPT_FAILED 			-2
20873143b9aSmrg#define TRANS_ACCEPT_MISC_ERROR			-3
20973143b9aSmrg
21073143b9aSmrg
21173143b9aSmrg/*
21273143b9aSmrg * ResetListener return values
21373143b9aSmrg */
21473143b9aSmrg
21573143b9aSmrg#define TRANS_RESET_NOOP	1
21673143b9aSmrg#define TRANS_RESET_NEW_FD	2
21773143b9aSmrg#define TRANS_RESET_FAILURE	3
21873143b9aSmrg
21973143b9aSmrg
22073143b9aSmrg/*
22173143b9aSmrg * Function prototypes for the exposed interface
22273143b9aSmrg */
22373143b9aSmrg
22473143b9aSmrgvoid TRANS(FreeConnInfo) (
22573143b9aSmrg    XtransConnInfo 	/* ciptr */
22673143b9aSmrg);
22773143b9aSmrg
22873143b9aSmrg#ifdef TRANS_CLIENT
22973143b9aSmrg
23073143b9aSmrgXtransConnInfo TRANS(OpenCOTSClient)(
2316a3641a6Ssnj    const char *	/* address */
23273143b9aSmrg);
23373143b9aSmrg
23473143b9aSmrg#endif /* TRANS_CLIENT */
23573143b9aSmrg
23673143b9aSmrg#ifdef TRANS_SERVER
23773143b9aSmrg
23873143b9aSmrgXtransConnInfo TRANS(OpenCOTSServer)(
2396a3641a6Ssnj    const char *	/* address */
24073143b9aSmrg);
24173143b9aSmrg
24273143b9aSmrg#endif /* TRANS_SERVER */
24373143b9aSmrg
24473143b9aSmrg#ifdef TRANS_REOPEN
24573143b9aSmrg
24673143b9aSmrgXtransConnInfo TRANS(ReopenCOTSServer)(
24773143b9aSmrg    int,		/* trans_id */
24873143b9aSmrg    int,		/* fd */
2496a3641a6Ssnj    const char *	/* port */
25073143b9aSmrg);
25173143b9aSmrg
25273143b9aSmrgint TRANS(GetReopenInfo)(
25373143b9aSmrg    XtransConnInfo,	/* ciptr */
25473143b9aSmrg    int *,		/* trans_id */
25573143b9aSmrg    int *,		/* fd */
25673143b9aSmrg    char **		/* port */
25773143b9aSmrg);
25873143b9aSmrg
25973143b9aSmrg#endif /* TRANS_REOPEN */
26073143b9aSmrg
26173143b9aSmrg
26273143b9aSmrgint TRANS(SetOption)(
26373143b9aSmrg    XtransConnInfo,	/* ciptr */
26473143b9aSmrg    int,		/* option */
26573143b9aSmrg    int			/* arg */
26673143b9aSmrg);
26773143b9aSmrg
26873143b9aSmrg#ifdef TRANS_SERVER
26973143b9aSmrg
27073143b9aSmrgint TRANS(CreateListener)(
27173143b9aSmrg    XtransConnInfo,	/* ciptr */
2726a3641a6Ssnj    const char *,	/* port */
27373143b9aSmrg    unsigned int	/* flags */
27473143b9aSmrg);
27573143b9aSmrg
27675ebec6dSmrgint TRANS(Received) (
27775ebec6dSmrg    const char*         /* protocol*/
27875ebec6dSmrg);
27975ebec6dSmrg
28073143b9aSmrgint TRANS(NoListen) (
281fe567363Smrg    const char*         /* protocol*/
28273143b9aSmrg);
28373143b9aSmrg
2846a3641a6Ssnjint TRANS(Listen) (
2856a3641a6Ssnj    const char*         /* protocol*/
2866a3641a6Ssnj);
2876a3641a6Ssnj
28875ebec6dSmrgint TRANS(IsListening) (
28975ebec6dSmrg    const char*         /* protocol*/
29075ebec6dSmrg);
29175ebec6dSmrg
29273143b9aSmrgint TRANS(ResetListener)(
29373143b9aSmrg    XtransConnInfo	/* ciptr */
29473143b9aSmrg);
29573143b9aSmrg
29673143b9aSmrgXtransConnInfo TRANS(Accept)(
29773143b9aSmrg    XtransConnInfo,	/* ciptr */
29873143b9aSmrg    int *		/* status */
29973143b9aSmrg);
30073143b9aSmrg
30173143b9aSmrg#endif /* TRANS_SERVER */
30273143b9aSmrg
30373143b9aSmrg#ifdef TRANS_CLIENT
30473143b9aSmrg
30573143b9aSmrgint TRANS(Connect)(
30673143b9aSmrg    XtransConnInfo,	/* ciptr */
3076a3641a6Ssnj    const char *	/* address */
30873143b9aSmrg);
30973143b9aSmrg
31073143b9aSmrg#endif /* TRANS_CLIENT */
31173143b9aSmrg
31273143b9aSmrgint TRANS(BytesReadable)(
31373143b9aSmrg    XtransConnInfo,	/* ciptr */
31473143b9aSmrg    BytesReadable_t *	/* pend */
31573143b9aSmrg);
31673143b9aSmrg
31773143b9aSmrgint TRANS(Read)(
31873143b9aSmrg    XtransConnInfo,	/* ciptr */
31973143b9aSmrg    char *,		/* buf */
32073143b9aSmrg    int			/* size */
32173143b9aSmrg);
32273143b9aSmrg
32373143b9aSmrgint TRANS(Write)(
32473143b9aSmrg    XtransConnInfo,	/* ciptr */
325a1910677Smrg    const char *,	/* buf */
32673143b9aSmrg    int			/* size */
32773143b9aSmrg);
32873143b9aSmrg
32973143b9aSmrgint TRANS(Readv)(
33073143b9aSmrg    XtransConnInfo,	/* ciptr */
33173143b9aSmrg    struct iovec *,	/* buf */
33273143b9aSmrg    int			/* size */
33373143b9aSmrg);
33473143b9aSmrg
33573143b9aSmrgint TRANS(Writev)(
33673143b9aSmrg    XtransConnInfo,	/* ciptr */
33773143b9aSmrg    struct iovec *,	/* buf */
33873143b9aSmrg    int			/* size */
33973143b9aSmrg);
34073143b9aSmrg
34175ebec6dSmrgint TRANS(SendFd) (XtransConnInfo ciptr, int fd, int do_close);
34275ebec6dSmrg
34375ebec6dSmrgint TRANS(RecvFd) (XtransConnInfo ciptr);
34475ebec6dSmrg
34573143b9aSmrgint TRANS(Disconnect)(
34673143b9aSmrg    XtransConnInfo	/* ciptr */
34773143b9aSmrg);
34873143b9aSmrg
34973143b9aSmrgint TRANS(Close)(
35073143b9aSmrg    XtransConnInfo	/* ciptr */
35173143b9aSmrg);
35273143b9aSmrg
35373143b9aSmrgint TRANS(CloseForCloning)(
35473143b9aSmrg    XtransConnInfo	/* ciptr */
35573143b9aSmrg);
35673143b9aSmrg
35773143b9aSmrgint TRANS(IsLocal)(
35873143b9aSmrg    XtransConnInfo	/* ciptr */
35973143b9aSmrg);
36073143b9aSmrg
36173143b9aSmrgint TRANS(GetPeerAddr)(
36273143b9aSmrg    XtransConnInfo,	/* ciptr */
36373143b9aSmrg    int *,		/* familyp */
36473143b9aSmrg    int *,		/* addrlenp */
36573143b9aSmrg    Xtransaddr **	/* addrp */
36673143b9aSmrg);
36773143b9aSmrg
36873143b9aSmrgint TRANS(GetConnectionNumber)(
36973143b9aSmrg    XtransConnInfo	/* ciptr */
37073143b9aSmrg);
37173143b9aSmrg
37273143b9aSmrg#ifdef TRANS_SERVER
37373143b9aSmrg
37473143b9aSmrgint TRANS(MakeAllCOTSServerListeners)(
3756a3641a6Ssnj    const char *,	/* port */
37673143b9aSmrg    int *,		/* partial */
37773143b9aSmrg    int *,		/* count_ret */
37873143b9aSmrg    XtransConnInfo **	/* ciptrs_ret */
37973143b9aSmrg);
38073143b9aSmrg
38173143b9aSmrg#endif /* TRANS_SERVER */
38273143b9aSmrg
38373143b9aSmrg
38473143b9aSmrg/*
38573143b9aSmrg * Function Prototypes for Utility Functions.
38673143b9aSmrg */
38773143b9aSmrg
38873143b9aSmrg#ifdef X11_t
38973143b9aSmrg
39073143b9aSmrgint TRANS(ConvertAddress)(
39173143b9aSmrg    int *,		/* familyp */
39273143b9aSmrg    int *,		/* addrlenp */
39373143b9aSmrg    Xtransaddr **	/* addrp */
39473143b9aSmrg);
39573143b9aSmrg
39673143b9aSmrg#endif /* X11_t */
39773143b9aSmrg
39873143b9aSmrg#ifdef ICE_t
39973143b9aSmrg
40073143b9aSmrgchar *
40173143b9aSmrgTRANS(GetMyNetworkId)(
40273143b9aSmrg    XtransConnInfo	/* ciptr */
40373143b9aSmrg);
40473143b9aSmrg
40573143b9aSmrgchar *
40673143b9aSmrgTRANS(GetPeerNetworkId)(
40773143b9aSmrg    XtransConnInfo	/* ciptr */
40873143b9aSmrg);
40973143b9aSmrg
41073143b9aSmrg#endif /* ICE_t */
41173143b9aSmrg
412fe567363Smrgint
41373143b9aSmrgTRANS(GetHostname) (
41473143b9aSmrg    char *	/* buf */,
41573143b9aSmrg    int 	/* maxlen */
41673143b9aSmrg);
41773143b9aSmrg
418fe567363Smrg#if defined(WIN32) && defined(TCPCONN)
41973143b9aSmrgint TRANS(WSAStartup)();
42073143b9aSmrg#endif
42173143b9aSmrg
42273143b9aSmrg#endif /* _XTRANS_H_ */
423