ICElibint.h revision c5629e66
1/* $Xorg: ICElibint.h,v 1.4 2001/02/09 02:03:26 xorgcvs Exp $ */ 2/****************************************************************************** 3 4 5Copyright 1993, 1998 The Open Group 6 7Permission to use, copy, modify, distribute, and sell this software and its 8documentation for any purpose is hereby granted without fee, provided that 9the above copyright notice appear in all copies and that both that 10copyright notice and this permission notice appear in supporting 11documentation. 12 13The above copyright notice and this permission notice shall be included in 14all copies or substantial portions of the Software. 15 16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 20AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 23Except as contained in this notice, the name of The Open Group shall not be 24used in advertising or otherwise to promote the sale, use or other dealings 25in this Software without prior written authorization from The Open Group. 26 27Author: Ralph Mor, X Consortium 28******************************************************************************/ 29/* $XFree86: xc/lib/ICE/ICElibint.h,v 1.6 2001/12/14 19:53:35 dawes Exp $ */ 30 31#ifndef _ICELIBINT_H_ 32#define _ICELIBINT_H_ 33 34#include <X11/Xos.h> 35#include <X11/Xfuncs.h> 36#include <X11/Xmd.h> 37#include <X11/ICE/ICEproto.h> 38#include <X11/ICE/ICEconn.h> 39#include <X11/ICE/ICEmsg.h> 40#ifdef WIN32 41#include <X11/Xwindows.h> 42#endif 43 44#include <stdlib.h> 45#include <stddef.h> 46 47 48/* 49 * Vendor & Release 50 */ 51 52#define IceVendorString "MIT" 53#define IceReleaseString "1.0" 54 55 56/* 57 * Pad to a 64 bit boundary 58 */ 59 60#define PAD64(_bytes) ((8 - ((unsigned int) (_bytes) % 8)) % 8) 61 62#define PADDED_BYTES64(_bytes) (_bytes + PAD64 (_bytes)) 63 64 65/* 66 * Pad to 32 bit boundary 67 */ 68 69#define PAD32(_bytes) ((4 - ((unsigned int) (_bytes) % 4)) % 4) 70 71#define PADDED_BYTES32(_bytes) (_bytes + PAD32 (_bytes)) 72 73 74/* 75 * Number of 8 byte units in _bytes. 76 */ 77 78#define WORD64COUNT(_bytes) (((unsigned int) ((_bytes) + 7)) >> 3) 79 80 81/* 82 * Number of 4 byte units in _bytes. 83 */ 84 85#define WORD32COUNT(_bytes) (((unsigned int) ((_bytes) + 3)) >> 2) 86 87 88/* 89 * Given a string, compute the number of bytes for the STRING representation 90 */ 91 92#define STRING_BYTES(_string) \ 93 (2 + strlen (_string) + PAD32 (2 + strlen (_string))) 94 95 96/* 97 * Size of ICE input/output buffers 98 */ 99 100#define ICE_INBUFSIZE 1024 101 102#define ICE_OUTBUFSIZE 1024 103 104 105/* 106 * Maxium number of ICE authentication methods allowed, and maxiumum 107 * number of authentication data entries allowed to be set in the 108 * IceSetPaAuthData function. 109 * 110 * We should use linked lists, but this is easier and should suffice. 111 */ 112 113#define MAX_ICE_AUTH_NAMES 32 114#define ICE_MAX_AUTH_DATA_ENTRIES 100 115 116 117/* 118 * ICE listen object 119 */ 120 121struct _IceListenObj { 122 struct _XtransConnInfo *trans_conn; /* transport connection object */ 123 char *network_id; 124 IceHostBasedAuthProc host_based_auth_proc; 125}; 126 127 128/* 129 * Some internal data structures for processing ICE messages. 130 */ 131 132typedef void (*_IceProcessCoreMsgProc) ( 133 IceConn /* iceConn */, 134 int /* opcode */, 135 unsigned long /* length */, 136 Bool /* swap */, 137 IceReplyWaitInfo * /* replyWait */, 138 Bool * /* replyReadyRet */, 139 Bool * /* connectionClosedRet */ 140); 141 142typedef struct { 143 int major_version; 144 int minor_version; 145 _IceProcessCoreMsgProc process_core_msg_proc; 146} _IceVersion; 147 148 149/* 150 * STORE FOO 151 */ 152 153#define STORE_CARD8(_pBuf, _val) \ 154{ \ 155 *((CARD8 *) _pBuf) = _val; \ 156 _pBuf += 1; \ 157} 158 159#ifndef WORD64 160 161#define STORE_CARD16(_pBuf, _val) \ 162{ \ 163 *((CARD16 *) _pBuf) = _val; \ 164 _pBuf += 2; \ 165} 166 167#define STORE_CARD32(_pBuf, _val) \ 168{ \ 169 *((CARD32 *) _pBuf) = _val; \ 170 _pBuf += 4; \ 171} 172 173#else /* WORD64 */ 174 175#define STORE_CARD16(_pBuf, _val) \ 176{ \ 177 struct { \ 178 int value :16; \ 179 int pad :16; \ 180 } _d; \ 181 _d.value = _val; \ 182 memcpy (_pBuf, &_d, 2); \ 183 _pBuf += 2; \ 184} 185 186#define STORE_CARD32(_pBuf, _val) \ 187{ \ 188 struct { \ 189 int value :32; \ 190 } _d; \ 191 _d.value = _val; \ 192 memcpy (_pBuf, &_d, 4); \ 193 _pBuf += 4; \ 194} 195 196#endif /* WORD64 */ 197 198#define STORE_STRING(_pBuf, _string) \ 199{ \ 200 CARD16 _len = strlen (_string); \ 201 STORE_CARD16 (_pBuf, _len); \ 202 memcpy (_pBuf, _string, _len); \ 203 _pBuf += _len; \ 204 if (PAD32 (2 + _len)) \ 205 _pBuf += PAD32 (2 + _len); \ 206} 207 208 209/* 210 * EXTRACT FOO 211 */ 212 213#define EXTRACT_CARD8(_pBuf, _val) \ 214{ \ 215 _val = *((CARD8 *) _pBuf); \ 216 _pBuf += 1; \ 217} 218 219#ifndef WORD64 220 221#define EXTRACT_CARD16(_pBuf, _swap, _val) \ 222{ \ 223 _val = *((CARD16 *) _pBuf); \ 224 _pBuf += 2; \ 225 if (_swap) \ 226 _val = lswaps (_val); \ 227} 228 229#define EXTRACT_CARD32(_pBuf, _swap, _val) \ 230{ \ 231 _val = *((CARD32 *) _pBuf); \ 232 _pBuf += 4; \ 233 if (_swap) \ 234 _val = lswapl (_val); \ 235} 236 237#else /* WORD64 */ 238 239#define EXTRACT_CARD16(_pBuf, _swap, _val) \ 240{ \ 241 _val = *(_pBuf + 0) & 0xff; /* 0xff incase _pBuf is signed */ \ 242 _val <<= 8; \ 243 _val |= *(_pBuf + 1) & 0xff;\ 244 _pBuf += 2; \ 245 if (_swap) \ 246 _val = lswaps (_val); \ 247} 248 249#define EXTRACT_CARD32(_pBuf, _swap, _val) \ 250{ \ 251 _val = *(_pBuf + 0) & 0xff; /* 0xff incase _pBuf is signed */ \ 252 _val <<= 8; \ 253 _val |= *(_pBuf + 1) & 0xff;\ 254 _val <<= 8; \ 255 _val |= *(_pBuf + 2) & 0xff;\ 256 _val <<= 8; \ 257 _val |= *(_pBuf + 3) & 0xff;\ 258 _pBuf += 4; \ 259 if (_swap) \ 260 _val = lswapl (_val); \ 261} 262 263#endif /* WORD64 */ 264 265#define EXTRACT_STRING(_pBuf, _swap, _string) \ 266{ \ 267 CARD16 _len; \ 268 EXTRACT_CARD16 (_pBuf, _swap, _len); \ 269 _string = (char *) malloc (_len + 1); \ 270 memcpy (_string, _pBuf, _len); \ 271 _pBuf += _len; \ 272 _string[_len] = '\0'; \ 273 if (PAD32 (2 + _len)) \ 274 _pBuf += PAD32 (2 + _len); \ 275} 276 277#define EXTRACT_LISTOF_STRING(_pBuf, _swap, _count, _strings) \ 278{ \ 279 int _i; \ 280 for (_i = 0; _i < _count; _i++) \ 281 EXTRACT_STRING (_pBuf, _swap, _strings[_i]); \ 282} 283 284 285#define SKIP_STRING(_pBuf, _swap, _end, _bail) \ 286{ \ 287 CARD16 _len; \ 288 EXTRACT_CARD16 (_pBuf, _swap, _len); \ 289 _pBuf += _len + PAD32(2+_len); \ 290 if (_pBuf > _end) { \ 291 _bail; \ 292 } \ 293} 294 295#define SKIP_LISTOF_STRING(_pBuf, _swap, _count, _end, _bail) \ 296{ \ 297 int _i; \ 298 for (_i = 0; _i < _count; _i++) \ 299 SKIP_STRING (_pBuf, _swap, _end, _bail); \ 300} 301 302 303 304/* 305 * Byte swapping 306 */ 307 308/* byte swap a long literal */ 309#define lswapl(_val) ((((_val) & 0xff) << 24) |\ 310 (((_val) & 0xff00) << 8) |\ 311 (((_val) & 0xff0000) >> 8) |\ 312 (((_val) >> 24) & 0xff)) 313 314/* byte swap a short literal */ 315#define lswaps(_val) ((((_val) & 0xff) << 8) | (((_val) >> 8) & 0xff)) 316 317 318 319/* 320 * ICE replies (not processed via callbacks because we block) 321 */ 322 323#define ICE_CONNECTION_REPLY 1 324#define ICE_CONNECTION_ERROR 2 325#define ICE_PROTOCOL_REPLY 3 326#define ICE_PROTOCOL_ERROR 4 327 328typedef struct { 329 int type; 330 int version_index; 331 char *vendor; 332 char *release; 333} _IceConnectionReply; 334 335typedef struct { 336 int type; 337 char *error_message; 338} _IceConnectionError; 339 340typedef struct { 341 int type; 342 int major_opcode; 343 int version_index; 344 char *vendor; 345 char *release; 346} _IceProtocolReply; 347 348typedef struct { 349 int type; 350 char *error_message; 351} _IceProtocolError; 352 353 354typedef union { 355 int type; 356 _IceConnectionReply connection_reply; 357 _IceConnectionError connection_error; 358 _IceProtocolReply protocol_reply; 359 _IceProtocolError protocol_error; 360} _IceReply; 361 362 363/* 364 * Watch for ICE connection create/destroy. 365 */ 366 367typedef struct _IceWatchedConnection { 368 IceConn iceConn; 369 IcePointer watch_data; 370 struct _IceWatchedConnection *next; 371} _IceWatchedConnection; 372 373typedef struct _IceWatchProc { 374 IceWatchProc watch_proc; 375 IcePointer client_data; 376 _IceWatchedConnection *watched_connections; 377 struct _IceWatchProc *next; 378} _IceWatchProc; 379 380 381/* 382 * Locking 383 */ 384 385#define IceLockConn(_iceConn) 386#define IceUnlockConn(_iceConn) 387 388 389/* 390 * Extern declarations 391 */ 392 393extern IceConn _IceConnectionObjs[]; 394extern char *_IceConnectionStrings[]; 395extern int _IceConnectionCount; 396 397extern _IceProtocol _IceProtocols[]; 398extern int _IceLastMajorOpcode; 399 400extern int _IceAuthCount; 401extern char *_IceAuthNames[]; 402extern IcePoAuthProc _IcePoAuthProcs[]; 403extern IcePaAuthProc _IcePaAuthProcs[]; 404 405extern int _IceVersionCount; 406extern _IceVersion _IceVersions[]; 407 408extern _IceWatchProc *_IceWatchProcs; 409 410extern IceErrorHandler _IceErrorHandler; 411extern IceIOErrorHandler _IceIOErrorHandler; 412 413 414extern void _IceErrorBadMajor ( 415 IceConn /* iceConn */, 416 int /* offendingMajor */, 417 int /* offendingMinor */, 418 int /* severity */ 419); 420 421extern void _IceErrorNoAuthentication ( 422 IceConn /* iceConn */, 423 int /* offendingMinor */ 424); 425 426extern void _IceErrorNoVersion ( 427 IceConn /* iceConn */, 428 int /* offendingMinor */ 429); 430 431extern void _IceErrorSetupFailed ( 432 IceConn /* iceConn */, 433 int /* offendingMinor */, 434 char * /* reason */ 435); 436 437extern void _IceErrorAuthenticationRejected ( 438 IceConn /* iceConn */, 439 int /* offendingMinor */, 440 char * /* reason */ 441); 442 443extern void _IceErrorAuthenticationFailed ( 444 IceConn /* iceConn */, 445 int /* offendingMinor */, 446 char * /* reason */ 447); 448 449extern void _IceErrorProtocolDuplicate ( 450 IceConn /* iceConn */, 451 char * /* protocolName */ 452); 453 454extern void _IceErrorMajorOpcodeDuplicate ( 455 IceConn /* iceConn */, 456 int /* majorOpcode */ 457); 458 459extern void _IceErrorUnknownProtocol ( 460 IceConn /* iceConn */, 461 char * /* protocolName */ 462); 463 464extern void _IceAddOpcodeMapping ( 465 IceConn /* iceConn */, 466 int /* hisOpcode */, 467 int /* myOpcode */ 468); 469 470extern char *_IceGetPeerName ( 471 IceConn /* iceConn */ 472); 473 474extern void _IceFreeConnection ( 475 IceConn /* iceConn */ 476); 477 478extern void _IceAddReplyWait ( 479 IceConn /* iceConn */, 480 IceReplyWaitInfo * /* replyWait */ 481); 482 483extern IceReplyWaitInfo *_IceSearchReplyWaits ( 484 IceConn /* iceConn */, 485 int /* majorOpcode */ 486); 487 488extern void _IceSetReplyReady ( 489 IceConn /* iceConn */, 490 IceReplyWaitInfo * /* replyWait */ 491); 492 493extern Bool _IceCheckReplyReady ( 494 IceConn /* iceConn */, 495 IceReplyWaitInfo * /* replyWait */ 496); 497 498extern void _IceConnectionOpened ( 499 IceConn /* iceConn */ 500); 501 502extern void _IceConnectionClosed ( 503 IceConn /* iceConn */ 504); 505 506extern void _IceGetPoAuthData ( 507 char * /* protocol_name */, 508 char * /* address */, 509 char * /* auth_name */, 510 unsigned short * /* auth_data_length_ret */, 511 char ** /* auth_data_ret */ 512); 513 514extern void _IceGetPaAuthData ( 515 char * /* protocol_name */, 516 char * /* address */, 517 char * /* auth_name */, 518 unsigned short * /* auth_data_length_ret */, 519 char ** /* auth_data_ret */ 520); 521 522extern void _IceGetPoValidAuthIndices ( 523 char * /* protocol_name */, 524 char * /* address */, 525 int /* num_auth_names */, 526 char ** /* auth_names */, 527 int * /* num_indices_ret */, 528 int * /* indices_ret */ 529); 530 531extern void _IceGetPaValidAuthIndices ( 532 char * /* protocol_name */, 533 char * /* address */, 534 int /* num_auth_names */, 535 char ** /* auth_names */, 536 int * /* num_indices_ret */, 537 int * /* indices_ret */ 538); 539 540#endif /* _ICELIBINT_H_ */ 541