xfindproxy.h revision b8f75c19
1/* $Xorg: xfindproxy.h,v 1.4 2001/02/09 02:05:42 xorgcvs Exp $ */ 2 3/* 4Copyright 1996, 1998 The Open Group 5 6Permission to use, copy, modify, distribute, and sell this software and its 7documentation for any purpose is hereby granted without fee, provided that 8the above copyright notice appear in all copies and that both that 9copyright notice and this permission notice appear in supporting 10documentation. 11 12The above copyright notice and this permission notice shall be included 13in all copies or substantial portions of the Software. 14 15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 19OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 21OTHER DEALINGS IN THE SOFTWARE. 22 23Except as contained in this notice, the name of The Open Group shall 24not be used in advertising or otherwise to promote the sale, use or 25other dealings in this Software without prior written authorization 26from The Open Group. 27*/ 28 29 30/* 31 * Pad to a 64 bit boundary 32 */ 33 34#define PAD64(_bytes) ((8 - ((unsigned int) (_bytes) % 8)) % 8) 35 36#define PADDED_BYTES64(_bytes) (_bytes + PAD64 (_bytes)) 37 38 39/* 40 * Number of 8 byte units in _bytes. 41 */ 42 43#define WORD64COUNT(_bytes) (((unsigned int) ((_bytes) + 7)) >> 3) 44 45 46/* 47 * Compute the number of bytes for a STRING representation 48 */ 49 50#define STRING_BYTES(_str) (2 + (_str ? strlen (_str) : 0) + \ 51 PAD64 (2 + (_str ? strlen (_str) : 0))) 52 53 54 55#define SKIP_STRING(_pBuf, _swap) \ 56{ \ 57 CARD16 _len; \ 58 EXTRACT_CARD16 (_pBuf, _swap, _len); \ 59 _pBuf += _len; \ 60 if (PAD64 (2 + _len)) \ 61 _pBuf += PAD64 (2 + _len); \ 62} 63 64/* 65 * STORE macros 66 */ 67 68#define STORE_CARD16(_pBuf, _val) \ 69{ \ 70 *((CARD16 *) _pBuf) = _val; \ 71 _pBuf += 2; \ 72} 73 74#define STORE_STRING(_pBuf, _string) \ 75{ \ 76 int _len = _string ? strlen (_string) : 0; \ 77 STORE_CARD16 (_pBuf, _len); \ 78 if (_len) { \ 79 memcpy (_pBuf, _string, _len); \ 80 _pBuf += _len; \ 81 } \ 82 if (PAD64 (2 + _len)) \ 83 _pBuf += PAD64 (2 + _len); \ 84} 85 86 87/* 88 * EXTRACT macros 89 */ 90 91#define EXTRACT_CARD16(_pBuf, _swap, _val) \ 92{ \ 93 _val = *((CARD16 *) _pBuf); \ 94 _pBuf += 2; \ 95 if (_swap) \ 96 _val = lswaps (_val); \ 97} 98 99#define EXTRACT_STRING(_pBuf, _swap, _string) \ 100{ \ 101 CARD16 _len; \ 102 EXTRACT_CARD16 (_pBuf, _swap, _len); \ 103 _string = (char *) malloc (_len + 1); \ 104 memcpy (_string, _pBuf, _len); \ 105 _string[_len] = '\0'; \ 106 _pBuf += _len; \ 107 if (PAD64 (2 + _len)) \ 108 _pBuf += PAD64 (2 + _len); \ 109} 110 111 112/* 113 * Byte swapping 114 */ 115 116/* byte swap a long literal */ 117#define lswapl(_val) ((((_val) & 0xff) << 24) |\ 118 (((_val) & 0xff00) << 8) |\ 119 (((_val) & 0xff0000) >> 8) |\ 120 (((_val) >> 24) & 0xff)) 121 122/* byte swap a short literal */ 123#define lswaps(_val) ((((_val) & 0xff) << 8) | (((_val) >> 8) & 0xff)) 124 125 126#define CHECK_AT_LEAST_SIZE(_iceConn, _majorOp, _minorOp, _expected_len, _actual_len, _severity) \ 127 if ((((_actual_len) - SIZEOF (iceMsg)) >> 3) > _expected_len) \ 128 { \ 129 _IceErrorBadLength (_iceConn, _majorOp, _minorOp, _severity); \ 130 return; \ 131 } 132 133 134#define CHECK_COMPLETE_SIZE(_iceConn, _majorOp, _minorOp, _expected_len, _actual_len, _pStart, _severity) \ 135 if (((PADDED_BYTES64((_actual_len)) - SIZEOF (iceMsg)) >> 3) \ 136 != _expected_len) \ 137 { \ 138 _IceErrorBadLength (_iceConn, _majorOp, _minorOp, _severity); \ 139 IceDisposeCompleteMessage (iceConn, _pStart); \ 140 return; \ 141 } 142