cb83196f12c3f75107a884b11e613e574dab72e8
[framework/uifw/xorg/lib/xtrans.git] / Xtrans.h
1 /*
2
3 Copyright 1993, 1994, 1998  The Open Group
4
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation.
10
11 The above copyright notice and this permission notice shall be included
12 in all copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 OTHER DEALINGS IN THE SOFTWARE.
21
22 Except as contained in this notice, the name of The Open Group shall
23 not be used in advertising or otherwise to promote the sale, use or
24 other dealings in this Software without prior written authorization
25 from 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 _XTRANS_H_
51 #define _XTRANS_H_
52
53 #include <X11/Xfuncproto.h>
54 #include <X11/Xos.h>
55
56 #ifndef WIN32
57 #include <sys/socket.h>
58 #endif
59
60
61 /*
62  * Set the functions names according to where this code is being compiled.
63  */
64
65 #ifdef X11_t
66 #if !defined(UNIXCPP) || defined(ANSICPP)
67 #define TRANS(func) _X11Trans##func
68 #else
69 #define TRANS(func) _X11Trans/**/func
70 #endif
71 #ifdef XTRANSDEBUG
72 static char* __xtransname = "_X11Trans";
73 #endif
74 #endif /* X11_t */
75
76 #ifdef XSERV_t
77 #if !defined(UNIXCPP) || defined(ANSICPP)
78 #define TRANS(func) _XSERVTrans##func
79 #else
80 #define TRANS(func) _XSERVTrans/**/func
81 #endif
82 #ifdef XTRANSDEBUG
83 static char* __xtransname = "_XSERVTrans";
84 #endif
85 #define X11_t
86 #endif /* XSERV_t */
87
88 #ifdef XIM_t
89 #if !defined(UNIXCPP) || defined(ANSICPP)
90 #define TRANS(func) _XimXTrans##func
91 #else
92 #define TRANS(func) _XimXTrans/**/func
93 #endif
94 #ifdef XTRANSDEBUG
95 static char* __xtransname = "_XimTrans";
96 #endif
97 #endif /* XIM_t */
98
99 #ifdef FS_t
100 #if !defined(UNIXCPP) || defined(ANSICPP)
101 #define TRANS(func) _FSTrans##func
102 #else
103 #define TRANS(func) _FSTrans/**/func
104 #endif
105 #ifdef XTRANSDEBUG
106 static char* __xtransname = "_FSTrans";
107 #endif
108 #endif /* FS_t */
109
110 #ifdef FONT_t
111 #if !defined(UNIXCPP) || defined(ANSICPP)
112 #define TRANS(func) _FontTrans##func
113 #else
114 #define TRANS(func) _FontTrans/**/func
115 #endif
116 #ifdef XTRANSDEBUG
117 static char* __xtransname = "_FontTrans";
118 #endif
119 #endif /* FONT_t */
120
121 #ifdef ICE_t
122 #if !defined(UNIXCPP) || defined(ANSICPP)
123 #define TRANS(func) _IceTrans##func
124 #else
125 #define TRANS(func) _IceTrans/**/func
126 #endif
127 #ifdef XTRANSDEBUG
128 static char* __xtransname = "_IceTrans";
129 #endif
130 #endif /* ICE_t */
131
132 #ifdef TEST_t
133 #if !defined(UNIXCPP) || defined(ANSICPP)
134 #define TRANS(func) _TESTTrans##func
135 #else
136 #define TRANS(func) _TESTTrans/**/func
137 #endif
138 #ifdef XTRANSDEBUG
139 static char* __xtransname = "_TESTTrans";
140 #endif
141 #endif /* TEST_t */
142
143 #ifdef LBXPROXY_t
144 #if !defined(UNIXCPP) || defined(ANSICPP)
145 #define TRANS(func) _LBXPROXYTrans##func
146 #else
147 #define TRANS(func) _LBXPROXYTrans/**/func
148 #endif
149 #define X11_t           /* The server defines this - so should the LBX proxy */
150 #ifdef XTRANSDEBUG
151 static char* __xtransname = "_LBXPROXYTrans";
152 #endif
153 #endif /* LBXPROXY_t */
154
155 #if !defined(TRANS)
156 #if !defined(UNIXCPP) || defined(ANSICPP)
157 #define TRANS(func) _XTrans##func
158 #else
159 #define TRANS(func) _XTrans/**/func
160 #endif
161 #ifdef XTRANSDEBUG
162 static char* __xtransname = "_XTrans";
163 #endif
164 #endif /* !TRANS */
165
166
167 /*
168  * Create a single address structure that can be used wherever
169  * an address structure is needed. struct sockaddr is not big enough
170  * to hold a sockadd_un, so we create this definition to have a single
171  * structure that is big enough for all the structures we might need.
172  *
173  * This structure needs to be independent of the socket/TLI interface used.
174  */
175
176 #if defined(IPv6) && defined(AF_INET6)
177 typedef struct sockaddr_storage Xtransaddr;
178 #else
179 #define XTRANS_MAX_ADDR_LEN     128     /* large enough to hold sun_path */
180
181 typedef struct {
182     unsigned char       addr[XTRANS_MAX_ADDR_LEN];
183 } Xtransaddr;
184 #endif
185
186 #ifdef LONG64
187 typedef int BytesReadable_t;
188 #else
189 typedef long BytesReadable_t;
190 #endif
191
192
193 #if defined(WIN32) || defined(USG) 
194
195 /*
196  *      TRANS(Readv) and TRANS(Writev) use struct iovec, normally found
197  *      in Berkeley systems in <sys/uio.h>.  See the readv(2) and writev(2)
198  *      manual pages for details.
199  */
200
201 struct iovec {
202     caddr_t iov_base;
203     int iov_len;
204 };
205
206 #else
207 #include <sys/uio.h>
208 #endif
209
210 typedef struct _XtransConnInfo *XtransConnInfo;
211
212
213 /*
214  * Transport Option definitions
215  */
216
217 #define TRANS_NONBLOCKING       1
218 #define TRANS_CLOSEONEXEC       2
219
220
221 /*
222  * Return values of Connect (0 is success)
223  */
224
225 #define TRANS_CONNECT_FAILED    -1
226 #define TRANS_TRY_CONNECT_AGAIN -2
227 #define TRANS_IN_PROGRESS       -3
228
229
230 /*
231  * Return values of CreateListener (0 is success)
232  */
233
234 #define TRANS_CREATE_LISTENER_FAILED    -1
235 #define TRANS_ADDR_IN_USE               -2
236
237
238 /*
239  * Return values of Accept (0 is success)
240  */
241
242 #define TRANS_ACCEPT_BAD_MALLOC                 -1
243 #define TRANS_ACCEPT_FAILED                     -2
244 #define TRANS_ACCEPT_MISC_ERROR                 -3
245
246
247 /*
248  * ResetListener return values
249  */
250
251 #define TRANS_RESET_NOOP        1
252 #define TRANS_RESET_NEW_FD      2
253 #define TRANS_RESET_FAILURE     3
254
255
256 /*
257  * Function prototypes for the exposed interface
258  */
259
260 void TRANS(FreeConnInfo) (
261     XtransConnInfo      /* ciptr */
262 );
263
264 #ifdef TRANS_CLIENT
265
266 XtransConnInfo TRANS(OpenCOTSClient)(
267     char *              /* address */
268 );
269
270 #endif /* TRANS_CLIENT */
271
272 #ifdef TRANS_SERVER
273
274 XtransConnInfo TRANS(OpenCOTSServer)(
275     char *              /* address */
276 );
277
278 #endif /* TRANS_SERVER */
279
280 #ifdef TRANS_CLIENT
281
282 XtransConnInfo TRANS(OpenCLTSClient)(
283     char *              /* address */
284 );
285
286 #endif /* TRANS_CLIENT */
287
288 #ifdef TRANS_SERVER
289
290 XtransConnInfo TRANS(OpenCLTSServer)(
291     char *              /* address */
292 );
293
294 #endif /* TRANS_SERVER */
295
296 #ifdef TRANS_REOPEN
297
298 XtransConnInfo TRANS(ReopenCOTSServer)(
299     int,                /* trans_id */
300     int,                /* fd */
301     char *              /* port */
302 );
303
304 XtransConnInfo TRANS(ReopenCLTSServer)(
305     int,                /* trans_id */
306     int,                /* fd */
307     char *              /* port */
308 );
309
310 int TRANS(GetReopenInfo)(
311     XtransConnInfo,     /* ciptr */
312     int *,              /* trans_id */
313     int *,              /* fd */
314     char **             /* port */
315 );
316
317 #endif /* TRANS_REOPEN */
318
319
320 int TRANS(SetOption)(
321     XtransConnInfo,     /* ciptr */
322     int,                /* option */
323     int                 /* arg */
324 );
325
326 #ifdef TRANS_SERVER
327
328 int TRANS(CreateListener)(
329     XtransConnInfo,     /* ciptr */
330     char *,             /* port */
331     unsigned int        /* flags */
332 );
333
334 int TRANS(NoListen) (
335     char*               /* protocol*/
336 );
337
338 int TRANS(ResetListener)(
339     XtransConnInfo      /* ciptr */
340 );
341
342 XtransConnInfo TRANS(Accept)(
343     XtransConnInfo,     /* ciptr */
344     int *               /* status */
345 );
346
347 #endif /* TRANS_SERVER */
348
349 #ifdef TRANS_CLIENT
350
351 int TRANS(Connect)(
352     XtransConnInfo,     /* ciptr */
353     char *              /* address */
354 );
355
356 #endif /* TRANS_CLIENT */
357
358 int TRANS(BytesReadable)(
359     XtransConnInfo,     /* ciptr */
360     BytesReadable_t *   /* pend */
361 );
362
363 int TRANS(Read)(
364     XtransConnInfo,     /* ciptr */
365     char *,             /* buf */
366     int                 /* size */
367 );
368
369 int TRANS(Write)(
370     XtransConnInfo,     /* ciptr */
371     char *,             /* buf */
372     int                 /* size */
373 );
374
375 int TRANS(Readv)(
376     XtransConnInfo,     /* ciptr */
377     struct iovec *,     /* buf */
378     int                 /* size */
379 );
380
381 int TRANS(Writev)(
382     XtransConnInfo,     /* ciptr */
383     struct iovec *,     /* buf */
384     int                 /* size */
385 );
386
387 int TRANS(Disconnect)(
388     XtransConnInfo      /* ciptr */
389 );
390
391 int TRANS(Close)(
392     XtransConnInfo      /* ciptr */
393 );
394
395 int TRANS(CloseForCloning)(
396     XtransConnInfo      /* ciptr */
397 );
398
399 int TRANS(IsLocal)(
400     XtransConnInfo      /* ciptr */
401 );
402
403 int TRANS(GetMyAddr)(
404     XtransConnInfo,     /* ciptr */
405     int *,              /* familyp */
406     int *,              /* addrlenp */
407     Xtransaddr **       /* addrp */
408 );
409
410 int TRANS(GetPeerAddr)(
411     XtransConnInfo,     /* ciptr */
412     int *,              /* familyp */
413     int *,              /* addrlenp */
414     Xtransaddr **       /* addrp */
415 );
416
417 int TRANS(GetConnectionNumber)(
418     XtransConnInfo      /* ciptr */
419 );
420
421 #ifdef TRANS_SERVER
422
423 int TRANS(MakeAllCOTSServerListeners)(
424     char *,             /* port */
425     int *,              /* partial */
426     int *,              /* count_ret */
427     XtransConnInfo **   /* ciptrs_ret */
428 );
429
430 int TRANS(MakeAllCLTSServerListeners)(
431     char *,             /* port */
432     int *,              /* partial */
433     int *,              /* count_ret */
434     XtransConnInfo **   /* ciptrs_ret */
435 );
436
437 #endif /* TRANS_SERVER */
438
439
440 /*
441  * Function Prototypes for Utility Functions.
442  */
443
444 #ifdef X11_t
445
446 int TRANS(ConvertAddress)(
447     int *,              /* familyp */
448     int *,              /* addrlenp */
449     Xtransaddr **       /* addrp */
450 );
451
452 #endif /* X11_t */
453
454 #ifdef ICE_t
455
456 char *
457 TRANS(GetMyNetworkId)(
458     XtransConnInfo      /* ciptr */
459 );
460
461 char *
462 TRANS(GetPeerNetworkId)(
463     XtransConnInfo      /* ciptr */
464 );
465
466 #endif /* ICE_t */
467
468 int 
469 TRANS(GetHostname) (
470     char *      /* buf */,
471     int         /* maxlen */
472 );
473
474 #if defined(WIN32) && defined(TCPCONN) 
475 int TRANS(WSAStartup)();
476 #endif
477
478 #endif /* _XTRANS_H_ */