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