Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:26:38

0001 /*
0002 
0003 Copyright 1993, 1994, 1998  The Open Group
0004 
0005 Permission to use, copy, modify, distribute, and sell this software and its
0006 documentation for any purpose is hereby granted without fee, provided that
0007 the above copyright notice appear in all copies and that both that
0008 copyright notice and this permission notice appear in supporting
0009 documentation.
0010 
0011 The above copyright notice and this permission notice shall be included
0012 in all copies or substantial portions of the Software.
0013 
0014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
0015 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0016 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
0017 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020 OTHER DEALINGS IN THE SOFTWARE.
0021 
0022 Except as contained in this notice, the name of The Open Group shall
0023 not be used in advertising or otherwise to promote the sale, use or
0024 other dealings in this Software without prior written authorization
0025 from The Open Group.
0026 
0027  * Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
0028  *
0029  * All Rights Reserved
0030  *
0031  * Permission to use, copy, modify, and distribute this software and its
0032  * documentation for any purpose and without fee is hereby granted, provided
0033  * that the above copyright notice appear in all copies and that both that
0034  * copyright notice and this permission notice appear in supporting
0035  * documentation, and that the name NCR not be used in advertising
0036  * or publicity pertaining to distribution of the software without specific,
0037  * written prior permission.  NCR makes no representations about the
0038  * suitability of this software for any purpose.  It is provided "as is"
0039  * without express or implied warranty.
0040  *
0041  * NCR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
0042  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
0043  * NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR
0044  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
0045  * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
0046  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
0047  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
0048  */
0049 
0050 #ifndef _XTRANSINT_H_
0051 #define _XTRANSINT_H_
0052 
0053 /*
0054  * XTRANSDEBUG will enable the PRMSG() macros used in the X Transport
0055  * Interface code. Each use of the PRMSG macro has a level associated with
0056  * it. XTRANSDEBUG is defined to be a level. If the invocation level is =<
0057  * the value of XTRANSDEBUG, then the message will be printed out to stderr.
0058  * Recommended levels are:
0059  *
0060  *  XTRANSDEBUG=1   Error messages
0061  *  XTRANSDEBUG=2 API Function Tracing
0062  *  XTRANSDEBUG=3 All Function Tracing
0063  *  XTRANSDEBUG=4 printing of intermediate values
0064  *  XTRANSDEBUG=5 really detailed stuff
0065 #define XTRANSDEBUG 2
0066  *
0067  * Defining XTRANSDEBUGTIMESTAMP will cause printing timestamps with each
0068  * message.
0069  */
0070 
0071 #if !defined(XTRANSDEBUG) && defined(XTRANS_TRANSPORT_C)
0072 #  define XTRANSDEBUG 1
0073 #endif
0074 
0075 #ifdef WIN32
0076 # define _WILLWINSOCK_
0077 #endif
0078 
0079 #include "Xtrans.h"
0080 
0081 #ifndef _X_UNUSED  /* Defined in Xfuncproto.h in xproto >= 7.0.22 */
0082 # define _X_UNUSED  /* */
0083 #endif
0084 
0085 #ifdef XTRANSDEBUG
0086 # include <stdio.h>
0087 #endif /* XTRANSDEBUG */
0088 
0089 #include <errno.h>
0090 
0091 #ifndef WIN32
0092 #  include <sys/socket.h>
0093 # include <netinet/in.h>
0094 # include <arpa/inet.h>
0095 
0096 /*
0097  * Moved the setting of NEED_UTSNAME to this header file from Xtrans.c,
0098  * to avoid a race condition. JKJ (6/5/97)
0099  */
0100 
0101 # if defined(_POSIX_SOURCE) || defined(SVR4) || defined(__SVR4)
0102 #  ifndef NEED_UTSNAME
0103 #   define NEED_UTSNAME
0104 #  endif
0105 #  include <sys/utsname.h>
0106 # endif
0107 
0108 #  define ESET(val) errno = val
0109 # define EGET() errno
0110 
0111 #else /* WIN32 */
0112 
0113 # include <limits.h>    /* for USHRT_MAX */
0114 
0115 # define ESET(val) WSASetLastError(val)
0116 # define EGET() WSAGetLastError()
0117 
0118 #endif /* WIN32 */
0119 
0120 #include <stddef.h>
0121 
0122 #ifdef X11_t
0123 #define X_TCP_PORT  6000
0124 #endif
0125 
0126 #if XTRANS_SEND_FDS
0127 
0128 struct _XtransConnFd {
0129     struct _XtransConnFd   *next;
0130     int                    fd;
0131     int                    do_close;
0132 };
0133 
0134 #endif
0135 
0136 struct _XtransConnInfo {
0137     struct _Xtransport     *transptr;
0138     int     index;
0139     char    *priv;
0140     int     flags;
0141     int     fd;
0142     char    *port;
0143     int     family;
0144     char    *addr;
0145     int     addrlen;
0146     char    *peeraddr;
0147     int     peeraddrlen;
0148     struct _XtransConnFd        *recv_fds;
0149     struct _XtransConnFd        *send_fds;
0150 };
0151 
0152 #define XTRANS_OPEN_COTS_CLIENT       1
0153 #define XTRANS_OPEN_COTS_SERVER       2
0154 
0155 typedef struct _Xtransport {
0156     const char  *TransName;
0157     int     flags;
0158 
0159 #ifdef TRANS_CLIENT
0160 
0161     XtransConnInfo (*OpenCOTSClient)(
0162     struct _Xtransport *,   /* transport */
0163     const char *,       /* protocol */
0164     const char *,       /* host */
0165     const char *        /* port */
0166     );
0167 
0168 #endif /* TRANS_CLIENT */
0169 
0170 #ifdef TRANS_SERVER
0171     const char **   nolisten;
0172     XtransConnInfo (*OpenCOTSServer)(
0173     struct _Xtransport *,   /* transport */
0174     const char *,       /* protocol */
0175     const char *,       /* host */
0176     const char *        /* port */
0177     );
0178 
0179 #endif /* TRANS_SERVER */
0180 
0181 #ifdef TRANS_REOPEN
0182 
0183     XtransConnInfo (*ReopenCOTSServer)(
0184     struct _Xtransport *,   /* transport */
0185         int,            /* fd */
0186         const char *        /* port */
0187     );
0188 
0189 #endif /* TRANS_REOPEN */
0190 
0191 
0192     int (*SetOption)(
0193     XtransConnInfo,     /* connection */
0194     int,            /* option */
0195     int         /* arg */
0196     );
0197 
0198 #ifdef TRANS_SERVER
0199 /* Flags */
0200 # define ADDR_IN_USE_ALLOWED    1
0201 
0202     int (*CreateListener)(
0203     XtransConnInfo,     /* connection */
0204     const char *,       /* port */
0205     unsigned int        /* flags */
0206     );
0207 
0208     int (*ResetListener)(
0209     XtransConnInfo      /* connection */
0210     );
0211 
0212     XtransConnInfo (*Accept)(
0213     XtransConnInfo,     /* connection */
0214         int *           /* status */
0215     );
0216 
0217 #endif /* TRANS_SERVER */
0218 
0219 #ifdef TRANS_CLIENT
0220 
0221     int (*Connect)(
0222     XtransConnInfo,     /* connection */
0223     const char *,       /* host */
0224     const char *        /* port */
0225     );
0226 
0227 #endif /* TRANS_CLIENT */
0228 
0229     int (*BytesReadable)(
0230     XtransConnInfo,     /* connection */
0231     BytesReadable_t *   /* pend */
0232     );
0233 
0234     int (*Read)(
0235     XtransConnInfo,     /* connection */
0236     char *,         /* buf */
0237     int         /* size */
0238     );
0239 
0240     int (*Write)(
0241     XtransConnInfo,     /* connection */
0242     char *,         /* buf */
0243     int         /* size */
0244     );
0245 
0246     int (*Readv)(
0247     XtransConnInfo,     /* connection */
0248     struct iovec *,     /* buf */
0249     int         /* size */
0250     );
0251 
0252     int (*Writev)(
0253     XtransConnInfo,     /* connection */
0254     struct iovec *,     /* buf */
0255     int         /* size */
0256     );
0257 
0258 #if XTRANS_SEND_FDS
0259     int (*SendFd)(
0260     XtransConnInfo,     /* connection */
0261         int,                    /* fd */
0262         int                     /* do_close */
0263     );
0264 
0265     int (*RecvFd)(
0266     XtransConnInfo      /* connection */
0267     );
0268 #endif
0269 
0270     int (*Disconnect)(
0271     XtransConnInfo      /* connection */
0272     );
0273 
0274     int (*Close)(
0275     XtransConnInfo      /* connection */
0276     );
0277 
0278     int (*CloseForCloning)(
0279     XtransConnInfo      /* connection */
0280     );
0281 
0282 } Xtransport;
0283 
0284 
0285 typedef struct _Xtransport_table {
0286     Xtransport  *transport;
0287     int     transport_id;
0288 } Xtransport_table;
0289 
0290 
0291 /*
0292  * Flags for the flags member of Xtransport.
0293  */
0294 
0295 #define TRANS_ALIAS (1<<0)  /* record is an alias, don't create server */
0296 #define TRANS_LOCAL (1<<1)  /* local transport */
0297 #define TRANS_DISABLED  (1<<2)  /* Don't open this one */
0298 #define TRANS_NOLISTEN  (1<<3)  /* Don't listen on this one */
0299 #define TRANS_NOUNLINK  (1<<4)  /* Don't unlink transport endpoints */
0300 #define TRANS_ABSTRACT  (1<<5)  /* This previously meant that abstract sockets should be used available.  For security
0301                                  * reasons, this is now a no-op on the client side, but it is still supported for servers.
0302                                  */
0303 #define TRANS_NOXAUTH   (1<<6)  /* Don't verify authentication (because it's secure some other way at the OS layer) */
0304 #define TRANS_RECEIVED  (1<<7)  /* The fd for this has already been opened by someone else. */
0305 
0306 /* Flags to preserve when setting others */
0307 #define TRANS_KEEPFLAGS (TRANS_NOUNLINK|TRANS_ABSTRACT)
0308 
0309 #ifdef XTRANS_TRANSPORT_C /* only provide static function prototypes when
0310                  building the transport.c file that has them in */
0311 
0312 #ifdef __clang__
0313 /* Not all clients make use of all provided statics */
0314 #pragma clang diagnostic push
0315 #pragma clang diagnostic ignored "-Wunused-function"
0316 #endif
0317 
0318 /*
0319  * readv() and writev() don't exist or don't work correctly on some
0320  * systems, so they may be emulated.
0321  */
0322 
0323 #ifdef WIN32
0324 
0325 #define READV(ciptr, iov, iovcnt)   TRANS(ReadV)(ciptr, iov, iovcnt)
0326 
0327 static  int TRANS(ReadV)(
0328     XtransConnInfo, /* ciptr */
0329     struct iovec *, /* iov */
0330     int         /* iovcnt */
0331 );
0332 
0333 #else
0334 
0335 #define READV(ciptr, iov, iovcnt)   readv(ciptr->fd, iov, iovcnt)
0336 
0337 #endif /* WIN32 */
0338 
0339 
0340 #ifdef WIN32
0341 
0342 #define WRITEV(ciptr, iov, iovcnt)  TRANS(WriteV)(ciptr, iov, iovcnt)
0343 
0344 static int TRANS(WriteV)(
0345     XtransConnInfo, /* ciptr */
0346     struct iovec *, /* iov */
0347     int         /* iovcnt */
0348 );
0349 
0350 #else
0351 
0352 #define WRITEV(ciptr, iov, iovcnt)  writev(ciptr->fd, iov, iovcnt)
0353 
0354 #endif /* WIN32 */
0355 
0356 #ifdef TRANS_SERVER
0357 static int trans_mkdir (
0358     const char *,   /* path */
0359     int         /* mode */
0360 );
0361 #endif
0362 
0363 #ifdef __clang__
0364 #pragma clang diagnostic pop
0365 #endif
0366 
0367 /*
0368  * Some XTRANSDEBUG stuff
0369  */
0370 
0371 #ifdef XTRANSDEBUG
0372 #include <stdarg.h>
0373 
0374 /*
0375  * The X server and the font server both provide ErrorF() & VErrorF(). For
0376  * other software that uses xtrans, we provide our own simple
0377  * versions.
0378  */
0379 # if (defined(XSERV_t) || defined(TRANS_HAS_ERRORF)) && defined(TRANS_SERVER)
0380 #  include "os.h"
0381 # else
0382 static inline void _X_ATTRIBUTE_PRINTF(1, 0)
0383 VErrorF(const char *f, va_list args)
0384 {
0385     vfprintf(stderr, f, args);
0386     fflush(stderr);
0387 }
0388 
0389 static inline void  _X_ATTRIBUTE_PRINTF(1, 2)
0390 ErrorF(const char *f, ...)
0391 {
0392     va_list args;
0393 
0394     va_start(args, f);
0395     VErrorF(f, args);
0396     va_end(args);
0397 }
0398 # endif /* xserver */
0399 #endif /* XTRANSDEBUG */
0400 
0401 static inline void  _X_ATTRIBUTE_PRINTF(2, 3)
0402 prmsg(int lvl, const char *f, ...)
0403 {
0404 #ifdef XTRANSDEBUG
0405     va_list args;
0406 
0407     va_start(args, f);
0408     if (lvl <= XTRANSDEBUG) {
0409     int saveerrno = errno;
0410 
0411     ErrorF("%s", __xtransname);
0412     VErrorF(f, args);
0413 
0414 # ifdef XTRANSDEBUGTIMESTAMP
0415     {
0416         struct timeval tp;
0417         gettimeofday(&tp, 0);
0418         ErrorF("timestamp (ms): %d\n",
0419            tp.tv_sec * 1000 + tp.tv_usec / 1000);
0420     }
0421 # endif
0422     errno = saveerrno;
0423     }
0424     va_end(args);
0425 #endif /* XTRANSDEBUG */
0426 }
0427 
0428 #endif /* XTRANS_TRANSPORT_C */
0429 
0430 #endif /* _XTRANSINT_H_ */