Xtransint.h revision af928962
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# define XTRANSDEBUG 1 73#endif 74 75#ifdef WIN32 76# define _WILLWINSOCK_ 77#endif 78 79#include "Xtrans.h" 80 81#ifdef XTRANSDEBUG 82# include <stdio.h> 83#endif /* XTRANSDEBUG */ 84 85#include <errno.h> 86 87#ifndef WIN32 88# include <sys/socket.h> 89# include <netinet/in.h> 90# include <arpa/inet.h> 91 92/* 93 * Moved the setting of NEED_UTSNAME to this header file from Xtrans.c, 94 * to avoid a race condition. JKJ (6/5/97) 95 */ 96 97# if defined(_POSIX_SOURCE) || defined(USG) || defined(SVR4) || defined(__SVR4) || defined(__SCO__) 98# ifndef NEED_UTSNAME 99# define NEED_UTSNAME 100# endif 101# include <sys/utsname.h> 102# endif 103 104# define ESET(val) errno = val 105# define EGET() errno 106 107#else /* WIN32 */ 108 109# include <limits.h> /* for USHRT_MAX */ 110 111# define ESET(val) WSASetLastError(val) 112# define EGET() WSAGetLastError() 113 114#endif /* WIN32 */ 115 116#include <stddef.h> 117 118#ifdef X11_t 119#define X_TCP_PORT 6000 120#endif 121 122struct _XtransConnInfo { 123 struct _Xtransport *transptr; 124 int index; 125 char *priv; 126 int flags; 127 int fd; 128 char *port; 129 int family; 130 char *addr; 131 int addrlen; 132 char *peeraddr; 133 int peeraddrlen; 134}; 135 136#define XTRANS_OPEN_COTS_CLIENT 1 137#define XTRANS_OPEN_COTS_SERVER 2 138#define XTRANS_OPEN_CLTS_CLIENT 3 139#define XTRANS_OPEN_CLTS_SERVER 4 140 141 142typedef struct _Xtransport { 143 char *TransName; 144 int flags; 145 146#ifdef TRANS_CLIENT 147 148 XtransConnInfo (*OpenCOTSClient)( 149 struct _Xtransport *, /* transport */ 150 char *, /* protocol */ 151 char *, /* host */ 152 char * /* port */ 153 ); 154 155#endif /* TRANS_CLIENT */ 156 157#ifdef TRANS_SERVER 158 char ** nolisten; 159 XtransConnInfo (*OpenCOTSServer)( 160 struct _Xtransport *, /* transport */ 161 char *, /* protocol */ 162 char *, /* host */ 163 char * /* port */ 164 ); 165 166#endif /* TRANS_SERVER */ 167 168#ifdef TRANS_CLIENT 169 170 XtransConnInfo (*OpenCLTSClient)( 171 struct _Xtransport *, /* transport */ 172 char *, /* protocol */ 173 char *, /* host */ 174 char * /* port */ 175 ); 176 177#endif /* TRANS_CLIENT */ 178 179#ifdef TRANS_SERVER 180 181 XtransConnInfo (*OpenCLTSServer)( 182 struct _Xtransport *, /* transport */ 183 char *, /* protocol */ 184 char *, /* host */ 185 char * /* port */ 186 ); 187 188#endif /* TRANS_SERVER */ 189 190 191#ifdef TRANS_REOPEN 192 193 XtransConnInfo (*ReopenCOTSServer)( 194 struct _Xtransport *, /* transport */ 195 int, /* fd */ 196 char * /* port */ 197 ); 198 199 XtransConnInfo (*ReopenCLTSServer)( 200 struct _Xtransport *, /* transport */ 201 int, /* fd */ 202 char * /* port */ 203 ); 204 205#endif /* TRANS_REOPEN */ 206 207 208 int (*SetOption)( 209 XtransConnInfo, /* connection */ 210 int, /* option */ 211 int /* arg */ 212 ); 213 214#ifdef TRANS_SERVER 215/* Flags */ 216# define ADDR_IN_USE_ALLOWED 1 217 218 int (*CreateListener)( 219 XtransConnInfo, /* connection */ 220 char *, /* port */ 221 unsigned int /* flags */ 222 ); 223 224 int (*ResetListener)( 225 XtransConnInfo /* connection */ 226 ); 227 228 XtransConnInfo (*Accept)( 229 XtransConnInfo, /* connection */ 230 int * /* status */ 231 ); 232 233#endif /* TRANS_SERVER */ 234 235#ifdef TRANS_CLIENT 236 237 int (*Connect)( 238 XtransConnInfo, /* connection */ 239 char *, /* host */ 240 char * /* port */ 241 ); 242 243#endif /* TRANS_CLIENT */ 244 245 int (*BytesReadable)( 246 XtransConnInfo, /* connection */ 247 BytesReadable_t * /* pend */ 248 ); 249 250 int (*Read)( 251 XtransConnInfo, /* connection */ 252 char *, /* buf */ 253 int /* size */ 254 ); 255 256 int (*Write)( 257 XtransConnInfo, /* connection */ 258 char *, /* buf */ 259 int /* size */ 260 ); 261 262 int (*Readv)( 263 XtransConnInfo, /* connection */ 264 struct iovec *, /* buf */ 265 int /* size */ 266 ); 267 268 int (*Writev)( 269 XtransConnInfo, /* connection */ 270 struct iovec *, /* buf */ 271 int /* size */ 272 ); 273 274 int (*Disconnect)( 275 XtransConnInfo /* connection */ 276 ); 277 278 int (*Close)( 279 XtransConnInfo /* connection */ 280 ); 281 282 int (*CloseForCloning)( 283 XtransConnInfo /* connection */ 284 ); 285 286} Xtransport; 287 288 289typedef struct _Xtransport_table { 290 Xtransport *transport; 291 int transport_id; 292} Xtransport_table; 293 294 295/* 296 * Flags for the flags member of Xtransport. 297 */ 298 299#define TRANS_ALIAS (1<<0) /* record is an alias, don't create server */ 300#define TRANS_LOCAL (1<<1) /* local transport */ 301#define TRANS_DISABLED (1<<2) /* Don't open this one */ 302#define TRANS_NOLISTEN (1<<3) /* Don't listen on this one */ 303#define TRANS_NOUNLINK (1<<4) /* Don't unlink transport endpoints */ 304#define TRANS_ABSTRACT (1<<5) /* Use abstract sockets if available */ 305#define TRANS_NOXAUTH (1<<6) /* Don't verify authentication (because it's secure some other way at the OS layer) */ 306 307/* Flags to preserve when setting others */ 308#define TRANS_KEEPFLAGS (TRANS_NOUNLINK|TRANS_ABSTRACT) 309 310/* 311 * readv() and writev() don't exist or don't work correctly on some 312 * systems, so they may be emulated. 313 */ 314 315#if defined(SYSV) && defined(__i386__) && !defined(__SCO__) && !defined(sun) || defined(WIN32) 316 317#define READV(ciptr, iov, iovcnt) TRANS(ReadV)(ciptr, iov, iovcnt) 318 319static int TRANS(ReadV)( 320 XtransConnInfo, /* ciptr */ 321 struct iovec *, /* iov */ 322 int /* iovcnt */ 323); 324 325#else 326 327#define READV(ciptr, iov, iovcnt) readv(ciptr->fd, iov, iovcnt) 328 329#endif /* CRAY || (SYSV && __i386__) || WIN32 || __sxg__ || */ 330 331 332#if defined(SYSV) && defined(__i386__) && !defined(__SCO__) && !defined(sun) || defined(WIN32) 333 334#define WRITEV(ciptr, iov, iovcnt) TRANS(WriteV)(ciptr, iov, iovcnt) 335 336static int TRANS(WriteV)( 337 XtransConnInfo, /* ciptr */ 338 struct iovec *, /* iov */ 339 int /* iovcnt */ 340); 341 342#else 343 344#define WRITEV(ciptr, iov, iovcnt) writev(ciptr->fd, iov, iovcnt) 345 346#endif /* CRAY || WIN32 || __sxg__ */ 347 348 349static int is_numeric ( 350 const char * /* str */ 351); 352 353#ifdef TRANS_SERVER 354static int trans_mkdir ( 355 const char *, /* path */ 356 int /* mode */ 357); 358#endif 359 360/* 361 * Some XTRANSDEBUG stuff 362 */ 363 364#if defined(XTRANSDEBUG) 365/* add hack to the format string to avoid warnings about extra arguments 366 * to fprintf. 367 */ 368#ifdef XTRANSDEBUGTIMESTAMP 369#if defined(XSERV_t) && defined(TRANS_SERVER) 370/* Use ErrorF() for the X server */ 371#define PRMSG(lvl,x,a,b,c) if (lvl <= XTRANSDEBUG){ \ 372 int hack= 0, saveerrno=errno; \ 373 struct timeval tp;\ 374 gettimeofday(&tp,0); \ 375 ErrorF("%s",__xtransname); \ 376 ErrorF(x+hack,a,b,c); \ 377 ErrorF("timestamp (ms): %d\n",tp.tv_sec*1000+tp.tv_usec/1000); \ 378 errno=saveerrno; \ 379 } else ((void)0) 380#else 381#define PRMSG(lvl,x,a,b,c) if (lvl <= XTRANSDEBUG){ \ 382 int hack= 0, saveerrno=errno; \ 383 struct timeval tp;\ 384 gettimeofday(&tp,0); \ 385 fprintf(stderr, "%s", __xtransname); fflush(stderr); \ 386 fprintf(stderr, x+hack,a,b,c); fflush(stderr); \ 387 fprintf(stderr, "timestamp (ms): %d\n",tp.tv_sec*1000+tp.tv_usec/1000); \ 388 fflush(stderr); \ 389 errno=saveerrno; \ 390 } else ((void)0) 391#endif /* XSERV_t && TRANS_SERVER */ 392#else /* XTRANSDEBUGTIMESTAMP */ 393#if defined(XSERV_t) && defined(TRANS_SERVER) 394/* Use ErrorF() for the X server */ 395#define PRMSG(lvl,x,a,b,c) if (lvl <= XTRANSDEBUG){ \ 396 int hack= 0, saveerrno=errno; \ 397 ErrorF("%s",__xtransname); \ 398 ErrorF(x+hack,a,b,c); \ 399 errno=saveerrno; \ 400 } else ((void)0) 401#else 402#define PRMSG(lvl,x,a,b,c) if (lvl <= XTRANSDEBUG){ \ 403 int hack= 0, saveerrno=errno; \ 404 fprintf(stderr, "%s", __xtransname); fflush(stderr); \ 405 fprintf(stderr, x+hack,a,b,c); fflush(stderr); \ 406 errno=saveerrno; \ 407 } else ((void)0) 408#endif /* XSERV_t && TRANS_SERVER */ 409#endif /* XTRANSDEBUGTIMESTAMP */ 410#else 411#define PRMSG(lvl,x,a,b,c) ((void)0) 412#endif /* XTRANSDEBUG */ 413 414#endif /* _XTRANSINT_H_ */ 415