Home | History | Annotate | Download | only in Xtrans
      1 /*  DO NOT EDIT THIS FILE.
      2 
      3     It has been auto-edited by fixincludes from:
      4 
      5 	"/usr/include/X11/Xtrans/Xtransint.h"
      6 
      7     This had to be done to correct non-standard usages in the
      8     original, manufacturer supplied header file.  */
      9 
     10 /* $XdotOrg: xc/lib/xtrans/Xtransint.h,v 1.2 2004/04/23 18:44:27 eich Exp $ */
     11 /* $Xorg: Xtransint.h,v 1.4 2001/02/09 02:04:06 xorgcvs Exp $ */
     12 /*
     13 
     14 Copyright 1993, 1994, 1998  The Open Group
     15 
     16 Permission to use, copy, modify, distribute, and sell this software and its
     17 documentation for any purpose is hereby granted without fee, provided that
     18 the above copyright notice appear in all copies and that both that
     19 copyright notice and this permission notice appear in supporting
     20 documentation.
     21 
     22 The above copyright notice and this permission notice shall be included
     23 in all copies or substantial portions of the Software.
     24 
     25 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
     26 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     27 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
     28 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
     29 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     30 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     31 OTHER DEALINGS IN THE SOFTWARE.
     32 
     33 Except as contained in this notice, the name of The Open Group shall
     34 not be used in advertising or otherwise to promote the sale, use or
     35 other dealings in this Software without prior written authorization
     36 from The Open Group.
     37 
     38 */
     39 /* $XFree86: xc/lib/xtrans/Xtransint.h,v 3.41 2003/08/28 00:35:23 tsi Exp $ */
     40 
     41 /* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
     42  *
     43  * All Rights Reserved
     44  *
     45  * Permission to use, copy, modify, and distribute this software and its
     46  * documentation for any purpose and without fee is hereby granted, provided
     47  * that the above copyright notice appear in all copies and that both that
     48  * copyright notice and this permission notice appear in supporting
     49  * documentation, and that the name NCR not be used in advertising
     50  * or publicity pertaining to distribution of the software without specific,
     51  * written prior permission.  NCR makes no representations about the
     52  * suitability of this software for any purpose.  It is provided "as is"
     53  * without express or implied warranty.
     54  *
     55  * NCR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
     56  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
     57  * NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR
     58  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
     59  * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
     60  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
     61  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     62  */
     63 
     64 #ifndef _XTRANSINT_H_
     65 #define _XTRANSINT_H_
     66 
     67 /*
     68  * XTRANSDEBUG will enable the PRMSG() macros used in the X Transport
     69  * Interface code. Each use of the PRMSG macro has a level associated with
     70  * it. XTRANSDEBUG is defined to be a level. If the invocation level is =<
     71  * the value of XTRANSDEBUG, then the message will be printed out to stderr.
     72  * Recommended levels are:
     73  *
     74  *	XTRANSDEBUG=1	Error messages
     75  *	XTRANSDEBUG=2 API Function Tracing
     76  *	XTRANSDEBUG=3 All Function Tracing
     77  *	XTRANSDEBUG=4 printing of intermediate values
     78  *	XTRANSDEBUG=5 really detailed stuff
     79 #define XTRANSDEBUG 2
     80  *
     81  * Defining XTRANSDEBUGTIMESTAMP will cause printing timestamps with each
     82  * message.
     83  */
     84 
     85 #ifndef XTRANSDEBUG
     86 # ifndef __UNIXOS2__
     87 #  define XTRANSDEBUG 1
     88 # else
     89 #  define XTRANSDEBUG 1
     90 # endif
     91 #endif
     92 
     93 #ifdef WIN32
     94 # define _WILLWINSOCK_
     95 #endif
     96 
     97 #include "Xtrans.h"
     98 
     99 #ifdef XTRANSDEBUG
    100 # include <stdio.h>
    101 #endif /* XTRANSDEBUG */
    102 
    103 #include <errno.h>
    104 
    105 #ifndef WIN32
    106 # ifndef Lynx
    107 #  include <sys/socket.h>
    108 # else
    109 #  include <socket.h>
    110 # endif
    111 # include <netinet/in.h>
    112 # include <arpa/inet.h>
    113 # ifdef __UNIXOS2__
    114 #  include <sys/ioctl.h>
    115 # endif
    116 
    117 /*
    118  * Moved the setting of NEED_UTSNAME to this header file from Xtrans.c,
    119  * to avoid a race condition. JKJ (6/5/97)
    120  */
    121 
    122 # if (defined(_POSIX_SOURCE) && !defined(AIXV3) && !defined(__QNX__)) || defined(hpux) || defined(USG) || defined(SVR4) || defined(__SCO__)
    123 #  ifndef NEED_UTSNAME
    124 #   define NEED_UTSNAME
    125 #  endif
    126 #  include <sys/utsname.h>
    127 # endif
    128 
    129 /*
    130  * makedepend screws up on #undef OPEN_MAX, so we define a new symbol
    131  */
    132 
    133 # ifndef TRANS_OPEN_MAX
    134 
    135 #  ifndef X_NOT_POSIX
    136 #   ifdef _POSIX_SOURCE
    137 #    include <limits.h>
    138 #   else
    139 #    define _POSIX_SOURCE
    140 #    include <limits.h>
    141 #    undef _POSIX_SOURCE
    142 #   endif
    143 #  endif
    144 #  ifndef OPEN_MAX
    145 #   if defined(_SC_OPEN_MAX) && !defined(__UNIXOS2__)
    146 #    define OPEN_MAX (sysconf(_SC_OPEN_MAX))
    147 #   else
    148 #    ifdef SVR4
    149 #     define OPEN_MAX 256
    150 #    else
    151 #     include <sys/param.h>
    152 #     ifndef OPEN_MAX
    153 #      ifdef __OSF1__
    154 #       define OPEN_MAX 256
    155 #      else
    156 #       ifdef NOFILE
    157 #        define OPEN_MAX NOFILE
    158 #       else
    159 #        if !defined(__UNIXOS2__) && !defined(__QNX__)
    160 #         define OPEN_MAX NOFILES_MAX
    161 #        else
    162 #         define OPEN_MAX 256
    163 #        endif
    164 #       endif
    165 #      endif
    166 #     endif
    167 #    endif
    168 #   endif
    169 #  endif
    170 #  if defined(_SC_OPEN_MAX)
    171 #   define TRANS_OPEN_MAX OPEN_MAX
    172 #  else /* !__GNU__ */
    173 #   if OPEN_MAX > 256
    174 #    define TRANS_OPEN_MAX 256
    175 #   else
    176 #    define TRANS_OPEN_MAX OPEN_MAX
    177 #   endif
    178 #  endif /*__GNU__*/
    179 
    180 # endif /* TRANS_OPEN_MAX */
    181 
    182 # ifdef __UNIXOS2__
    183 #  define ESET(val)
    184 # else
    185 #  define ESET(val) errno = val
    186 # endif
    187 # define EGET() errno
    188 
    189 #else /* WIN32 */
    190 
    191 # include <limits.h>	/* for USHRT_MAX */
    192 
    193 # define ESET(val) WSASetLastError(val)
    194 # define EGET() WSAGetLastError()
    195 
    196 #endif /* WIN32 */
    197 
    198 #include <stddef.h>
    199 
    200 #ifdef X11_t
    201 #define X_TCP_PORT	6000
    202 #endif
    203 
    204 struct _XtransConnInfo {
    205     struct _Xtransport     *transptr;
    206     int		index;
    207     char	*priv;
    208     int		flags;
    209     int		fd;
    210     char	*port;
    211     int		family;
    212     char	*addr;
    213     int		addrlen;
    214     char	*peeraddr;
    215     int		peeraddrlen;
    216 };
    217 
    218 #define XTRANS_OPEN_COTS_CLIENT       1
    219 #define XTRANS_OPEN_COTS_SERVER       2
    220 #define XTRANS_OPEN_CLTS_CLIENT       3
    221 #define XTRANS_OPEN_CLTS_SERVER       4
    222 
    223 
    224 typedef struct _Xtransport {
    225     char	*TransName;
    226     int		flags;
    227 
    228 #ifdef TRANS_CLIENT
    229 
    230     XtransConnInfo (*OpenCOTSClient)(
    231 	struct _Xtransport *,	/* transport */
    232 	char *,			/* protocol */
    233 	char *,			/* host */
    234 	char *			/* port */
    235     );
    236 
    237 #endif /* TRANS_CLIENT */
    238 
    239 #ifdef TRANS_SERVER
    240     char **	nolisten;
    241     XtransConnInfo (*OpenCOTSServer)(
    242 	struct _Xtransport *,	/* transport */
    243 	char *,			/* protocol */
    244 	char *,			/* host */
    245 	char *			/* port */
    246     );
    247 
    248 #endif /* TRANS_SERVER */
    249 
    250 #ifdef TRANS_CLIENT
    251 
    252     XtransConnInfo (*OpenCLTSClient)(
    253 	struct _Xtransport *,	/* transport */
    254 	char *,			/* protocol */
    255 	char *,			/* host */
    256 	char *			/* port */
    257     );
    258 
    259 #endif /* TRANS_CLIENT */
    260 
    261 #ifdef TRANS_SERVER
    262 
    263     XtransConnInfo (*OpenCLTSServer)(
    264 	struct _Xtransport *,	/* transport */
    265 	char *,			/* protocol */
    266 	char *,			/* host */
    267 	char *			/* port */
    268     );
    269 
    270 #endif /* TRANS_SERVER */
    271 
    272 
    273 #ifdef TRANS_REOPEN
    274 
    275     XtransConnInfo (*ReopenCOTSServer)(
    276 	struct _Xtransport *,	/* transport */
    277         int,			/* fd */
    278         char *			/* port */
    279     );
    280 
    281     XtransConnInfo (*ReopenCLTSServer)(
    282 	struct _Xtransport *,	/* transport */
    283         int,			/* fd */
    284         char *			/* port */
    285     );
    286 
    287 #endif /* TRANS_REOPEN */
    288 
    289 
    290     int	(*SetOption)(
    291 	XtransConnInfo,		/* connection */
    292 	int,			/* option */
    293 	int			/* arg */
    294     );
    295 
    296 #ifdef TRANS_SERVER
    297 /* Flags */
    298 # define ADDR_IN_USE_ALLOWED	1
    299 
    300     int	(*CreateListener)(
    301 	XtransConnInfo,		/* connection */
    302 	char *,			/* port */
    303 	unsigned int		/* flags */
    304     );
    305 
    306     int	(*ResetListener)(
    307 	XtransConnInfo		/* connection */
    308     );
    309 
    310     XtransConnInfo (*Accept)(
    311 	XtransConnInfo,		/* connection */
    312         int *			/* status */
    313     );
    314 
    315 #endif /* TRANS_SERVER */
    316 
    317 #ifdef TRANS_CLIENT
    318 
    319     int	(*Connect)(
    320 	XtransConnInfo,		/* connection */
    321 	char *,			/* host */
    322 	char *			/* port */
    323     );
    324 
    325 #endif /* TRANS_CLIENT */
    326 
    327     int	(*BytesReadable)(
    328 	XtransConnInfo,		/* connection */
    329 	BytesReadable_t *	/* pend */
    330     );
    331 
    332     int	(*Read)(
    333 	XtransConnInfo,		/* connection */
    334 	char *,			/* buf */
    335 	int			/* size */
    336     );
    337 
    338     int	(*Write)(
    339 	XtransConnInfo,		/* connection */
    340 	char *,			/* buf */
    341 	int			/* size */
    342     );
    343 
    344     int	(*Readv)(
    345 	XtransConnInfo,		/* connection */
    346 	struct iovec *,		/* buf */
    347 	int			/* size */
    348     );
    349 
    350     int	(*Writev)(
    351 	XtransConnInfo,		/* connection */
    352 	struct iovec *,		/* buf */
    353 	int			/* size */
    354     );
    355 
    356     int	(*Disconnect)(
    357 	XtransConnInfo		/* connection */
    358     );
    359 
    360     int	(*Close)(
    361 	XtransConnInfo		/* connection */
    362     );
    363 
    364     int	(*CloseForCloning)(
    365 	XtransConnInfo		/* connection */
    366     );
    367 
    368 } Xtransport;
    369 
    370 
    371 typedef struct _Xtransport_table {
    372     Xtransport	*transport;
    373     int		transport_id;
    374 } Xtransport_table;
    375 
    376 
    377 /*
    378  * Flags for the flags member of Xtransport.
    379  */
    380 
    381 #define TRANS_ALIAS	(1<<0)	/* record is an alias, don't create server */
    382 #define TRANS_LOCAL	(1<<1)	/* local transport */
    383 #define TRANS_DISABLED	(1<<2)	/* Don't open this one */
    384 #define TRANS_NOLISTEN  (1<<3)  /* Don't listen on this one */
    385 #define TRANS_NOUNLINK	(1<<4)	/* Dont unlink transport endpoints */
    386 
    387 /* Flags to preserve when setting others */
    388 #define TRANS_KEEPFLAGS	(TRANS_NOUNLINK)
    389 
    390 /*
    391  * readv() and writev() don't exist or don't work correctly on some
    392  * systems, so they may be emulated.
    393  */
    394 
    395 #if defined(CRAY) || (defined(SYSV) && defined(__i386__) && !defined(__SCO__)) || defined(WIN32) || defined(__sxg__) || defined(__UNIXOS2__)
    396 
    397 #define READV(ciptr, iov, iovcnt)	TRANS(ReadV)(ciptr, iov, iovcnt)
    398 
    399 static	int TRANS(ReadV)(
    400     XtransConnInfo,	/* ciptr */
    401     struct iovec *,	/* iov */
    402     int			/* iovcnt */
    403 );
    404 
    405 #else
    406 
    407 #define READV(ciptr, iov, iovcnt)	readv(ciptr->fd, iov, iovcnt)
    408 
    409 #endif /* CRAY || (SYSV && i386) || WIN32 || __sxg__ || */
    410 
    411 
    412 #if defined(CRAY) || (defined(SYSV) && defined(__i386__) && !defined(__SCO__)) || defined(WIN32) || defined(__sxg__) || defined(__UNIXOS2__)
    413 
    414 #define WRITEV(ciptr, iov, iovcnt)	TRANS(WriteV)(ciptr, iov, iovcnt)
    415 
    416 static int TRANS(WriteV)(
    417     XtransConnInfo,	/* ciptr */
    418     struct iovec *,	/* iov */
    419     int 		/* iovcnt */
    420 );
    421 
    422 #else
    423 
    424 #define WRITEV(ciptr, iov, iovcnt)	writev(ciptr->fd, iov, iovcnt)
    425 
    426 #endif /* CRAY || WIN32 || __sxg__ */
    427 
    428 
    429 static int is_numeric (
    430     char *		/* str */
    431 );
    432 
    433 #ifdef TRANS_SERVER
    434 static int trans_mkdir (
    435     char *,		/* path */
    436     int			/* mode */
    437 );
    438 #endif
    439 
    440 /*
    441  * Some XTRANSDEBUG stuff
    442  */
    443 
    444 #if defined(XTRANSDEBUG)
    445 /* add hack to the format string to avoid warnings about extra arguments
    446  * to fprintf.
    447  */
    448 #ifdef XTRANSDEBUGTIMESTAMP
    449 #if defined(XSERV_t) && defined(TRANS_SERVER)
    450 /* Use ErrorF() for the X server */
    451 #define PRMSG(lvl,x,a,b,c)	if (lvl <= XTRANSDEBUG){ \
    452 			int hack= 0, saveerrno=errno; \
    453                         struct timeval tp;\
    454                         gettimeofday(&tp,0); \
    455 			ErrorF(__xtransname); \
    456 			ErrorF(x+hack,a,b,c); \
    457                         ErrorF("timestamp (ms): %d\n",tp.tv_sec*1000+tp.tv_usec/1000); \
    458 			errno=saveerrno; \
    459 			} else ((void)0)
    460 #else
    461 #define PRMSG(lvl,x,a,b,c)	if (lvl <= XTRANSDEBUG){ \
    462 			int hack= 0, saveerrno=errno; \
    463                         struct timeval tp;\
    464                         gettimeofday(&tp,0); \
    465 			fprintf(stderr, __xtransname); fflush(stderr); \
    466 			fprintf(stderr, x+hack,a,b,c); fflush(stderr); \
    467                         fprintf(stderr, "timestamp (ms): %d\n",tp.tv_sec*1000+tp.tv_usec/1000); \
    468                         fflush(stderr); \
    469 			errno=saveerrno; \
    470 			} else ((void)0)
    471 #endif /* XSERV_t && TRANS_SERVER */
    472 #else /* XTRANSDEBUGTIMESTAMP */
    473 #if defined(XSERV_t) && defined(TRANS_SERVER)
    474 /* Use ErrorF() for the X server */
    475 #define PRMSG(lvl,x,a,b,c)	if (lvl <= XTRANSDEBUG){ \
    476 			int hack= 0, saveerrno=errno; \
    477 			ErrorF(__xtransname); \
    478 			ErrorF(x+hack,a,b,c); \
    479 			errno=saveerrno; \
    480 			} else ((void)0)
    481 #else
    482 #define PRMSG(lvl,x,a,b,c)	if (lvl <= XTRANSDEBUG){ \
    483 			int hack= 0, saveerrno=errno; \
    484 			fprintf(stderr, __xtransname); fflush(stderr); \
    485 			fprintf(stderr, x+hack,a,b,c); fflush(stderr); \
    486 			errno=saveerrno; \
    487 			} else ((void)0)
    488 #endif /* XSERV_t && TRANS_SERVER */
    489 #endif /* XTRANSDEBUGTIMESTAMP */
    490 #else
    491 #define PRMSG(lvl,x,a,b,c)	((void)0)
    492 #endif /* XTRANSDEBUG */
    493 
    494 #endif /* _XTRANSINT_H_ */
    495