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