ICEmsg.h revision c5629e66
1266e564dSmrg/* $Xorg: ICEmsg.h,v 1.4 2001/02/09 02:03:26 xorgcvs Exp $ */
2266e564dSmrg/******************************************************************************
3266e564dSmrg
4266e564dSmrg
5266e564dSmrgCopyright 1993, 1998  The Open Group
6266e564dSmrg
7266e564dSmrgPermission to use, copy, modify, distribute, and sell this software and its
8266e564dSmrgdocumentation for any purpose is hereby granted without fee, provided that
9266e564dSmrgthe above copyright notice appear in all copies and that both that
10266e564dSmrgcopyright notice and this permission notice appear in supporting
11266e564dSmrgdocumentation.
12266e564dSmrg
13266e564dSmrgThe above copyright notice and this permission notice shall be included in
14266e564dSmrgall copies or substantial portions of the Software.
15266e564dSmrg
16266e564dSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17266e564dSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18266e564dSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
19266e564dSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20266e564dSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21266e564dSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22266e564dSmrg
23266e564dSmrgExcept as contained in this notice, the name of The Open Group shall not be
24266e564dSmrgused in advertising or otherwise to promote the sale, use or other dealings
25266e564dSmrgin this Software without prior written authorization from The Open Group.
26266e564dSmrg
27266e564dSmrgAuthor: Ralph Mor, X Consortium
28266e564dSmrg******************************************************************************/
29266e564dSmrg/* $XFree86: xc/lib/ICE/ICEmsg.h,v 1.4 2001/12/20 19:40:59 tsi Exp $ */
30266e564dSmrg
31266e564dSmrg#ifndef _ICEMSG_H_
32266e564dSmrg#define _ICEMSG_H_
33266e564dSmrg
34266e564dSmrg#include <X11/Xfuncproto.h>
35266e564dSmrg
36266e564dSmrg#include <X11/ICE/ICEconn.h>
37266e564dSmrg
38266e564dSmrg_XFUNCPROTOBEGIN
39266e564dSmrg
40266e564dSmrg/*
41266e564dSmrg * Function prototypes for internal ICElib functions
42266e564dSmrg */
43266e564dSmrg
44266e564dSmrgextern Status _IceRead (
45266e564dSmrg    IceConn		/* iceConn */,
46266e564dSmrg    unsigned long	/* nbytes */,
47266e564dSmrg    char *		/* ptr */
48266e564dSmrg);
49266e564dSmrg
50266e564dSmrgextern void _IceReadSkip (
51266e564dSmrg    IceConn		/* iceConn */,
52266e564dSmrg    unsigned long	/* nbytes */
53266e564dSmrg);
54266e564dSmrg
55266e564dSmrgextern void _IceWrite (
56266e564dSmrg    IceConn		/* iceConn */,
57266e564dSmrg    unsigned long	/* nbytes */,
58266e564dSmrg    char *		/* ptr */
59266e564dSmrg);
60266e564dSmrg
61266e564dSmrg
62266e564dSmrgextern void _IceErrorBadMinor (
63266e564dSmrg    IceConn		/* iceConn */,
64266e564dSmrg    int			/* majorOpcode */,
65266e564dSmrg    int			/* offendingMinor */,
66266e564dSmrg    int			/* severity */
67266e564dSmrg);
68266e564dSmrg
69266e564dSmrgextern void _IceErrorBadState (
70266e564dSmrg    IceConn		/* iceConn */,
71266e564dSmrg    int			/* majorOpcode */,
72266e564dSmrg    int			/* offendingMinor */,
73266e564dSmrg    int			/* severity */
74266e564dSmrg);
75266e564dSmrg
76266e564dSmrgextern void _IceErrorBadLength (
77266e564dSmrg    IceConn		/* iceConn */,
78266e564dSmrg    int			/* majorOpcode */,
79266e564dSmrg    int			/* offendingMinor */,
80266e564dSmrg    int			/* severity */
81266e564dSmrg);
82266e564dSmrg
83266e564dSmrgextern void _IceErrorBadValue (
84266e564dSmrg    IceConn		/* iceConn */,
85266e564dSmrg    int			/* majorOpcode */,
86266e564dSmrg    int			/* offendingMinor */,
87266e564dSmrg    int			/* offset */,
88266e564dSmrg    int			/* length */,
89266e564dSmrg    IcePointer		/* value */
90266e564dSmrg);
91266e564dSmrg
92c5629e66Smrgextern IcePoAuthStatus _IcePoMagicCookie1Proc (
93c5629e66Smrg    IceConn		/* iceConn */,
94c5629e66Smrg    IcePointer *	/* authStatePtr */,
95c5629e66Smrg    Bool 		/* cleanUp */,
96c5629e66Smrg    Bool		/* swap */,
97c5629e66Smrg    int     		/* authDataLen */,
98c5629e66Smrg    IcePointer		/* authData */,
99c5629e66Smrg    int *		/* replyDataLenRet */,
100c5629e66Smrg    IcePointer *	/* replyDataRet */,
101c5629e66Smrg    char **		/* errorStringRet */
102c5629e66Smrg);
103c5629e66Smrg
104c5629e66Smrgextern IcePaAuthStatus _IcePaMagicCookie1Proc (
105c5629e66Smrg    IceConn		/* iceConn */,
106c5629e66Smrg    IcePointer *	/* authStatePtr */,
107c5629e66Smrg    Bool		/* swap */,
108c5629e66Smrg    int     		/* authDataLen */,
109c5629e66Smrg    IcePointer		/* authData */,
110c5629e66Smrg    int *		/* replyDataLenRet */,
111c5629e66Smrg    IcePointer *	/* replyDataRet */,
112c5629e66Smrg    char **		/* errorStringRet */
113c5629e66Smrg);
114c5629e66Smrg
115266e564dSmrg
116266e564dSmrg/*
117266e564dSmrg * Macro to check if IO operations are valid on an ICE connection.
118266e564dSmrg */
119266e564dSmrg
120266e564dSmrg#define IceValidIO(_iceConn) _iceConn->io_ok
121266e564dSmrg
122266e564dSmrg
123266e564dSmrg/*
124266e564dSmrg * Macros for writing messages.
125266e564dSmrg */
126266e564dSmrg
127266e564dSmrg#define IceGetHeader(_iceConn, _major, _minor, _headerSize, _msgType, _pMsg) \
128266e564dSmrg    if ((_iceConn->outbufptr + _headerSize) > _iceConn->outbufmax) \
129266e564dSmrg        IceFlush (_iceConn); \
130266e564dSmrg    _pMsg = (_msgType *) _iceConn->outbufptr; \
131266e564dSmrg    _pMsg->majorOpcode = _major; \
132266e564dSmrg    _pMsg->minorOpcode = _minor; \
133266e564dSmrg    _pMsg->length = (_headerSize - SIZEOF (iceMsg)) >> 3; \
134266e564dSmrg    _iceConn->outbufptr += _headerSize; \
135266e564dSmrg    _iceConn->send_sequence++
136266e564dSmrg
137266e564dSmrg#define IceGetHeaderExtra(_iceConn, _major, _minor, _headerSize, _extra, _msgType, _pMsg, _pData) \
138266e564dSmrg    if ((_iceConn->outbufptr + \
139266e564dSmrg	_headerSize + ((_extra) << 3)) > _iceConn->outbufmax) \
140266e564dSmrg        IceFlush (_iceConn); \
141266e564dSmrg    _pMsg = (_msgType *) _iceConn->outbufptr; \
142266e564dSmrg    if ((_iceConn->outbufptr + \
143266e564dSmrg	_headerSize + ((_extra) << 3)) <= _iceConn->outbufmax) \
144266e564dSmrg        _pData = (char *) _pMsg + _headerSize; \
145266e564dSmrg    else \
146266e564dSmrg        _pData = NULL; \
147266e564dSmrg    _pMsg->majorOpcode = _major; \
148266e564dSmrg    _pMsg->minorOpcode = _minor; \
149266e564dSmrg    _pMsg->length = ((_headerSize - SIZEOF (iceMsg)) >> 3) + (_extra); \
150266e564dSmrg    _iceConn->outbufptr += (_headerSize + ((_extra) << 3)); \
151266e564dSmrg    _iceConn->send_sequence++
152266e564dSmrg
153266e564dSmrg#define IceSimpleMessage(_iceConn, _major, _minor) \
154266e564dSmrg{ \
155266e564dSmrg    iceMsg *_pMsg; \
156266e564dSmrg    IceGetHeader (_iceConn, _major, _minor, SIZEOF (iceMsg), iceMsg, _pMsg); \
157266e564dSmrg}
158266e564dSmrg
159266e564dSmrg#define IceErrorHeader(_iceConn, _offendingMajorOpcode, _offendingMinorOpcode, _offendingSequenceNum, _severity, _errorClass, _dataLength) \
160266e564dSmrg{ \
161266e564dSmrg    iceErrorMsg	*_pMsg; \
162266e564dSmrg\
163266e564dSmrg    IceGetHeader (_iceConn, _offendingMajorOpcode, ICE_Error, \
164266e564dSmrg	SIZEOF (iceErrorMsg), iceErrorMsg, _pMsg); \
165266e564dSmrg    _pMsg->length += (_dataLength); \
166266e564dSmrg    _pMsg->offendingMinorOpcode = _offendingMinorOpcode; \
167266e564dSmrg    _pMsg->severity = _severity; \
168266e564dSmrg    _pMsg->offendingSequenceNum = _offendingSequenceNum; \
169266e564dSmrg    _pMsg->errorClass = _errorClass; \
170266e564dSmrg}
171266e564dSmrg
172266e564dSmrg
173266e564dSmrg/*
174266e564dSmrg * Write data into the ICE output buffer.
175266e564dSmrg */
176266e564dSmrg
177266e564dSmrg#define IceWriteData(_iceConn, _bytes, _data) \
178266e564dSmrg{ \
179266e564dSmrg    if ((_iceConn->outbufptr + (_bytes)) > _iceConn->outbufmax) \
180266e564dSmrg    { \
181266e564dSmrg	IceFlush (_iceConn); \
182266e564dSmrg        _IceWrite (_iceConn, (unsigned long) (_bytes), _data); \
183266e564dSmrg    } \
184266e564dSmrg    else \
185266e564dSmrg    { \
186266e564dSmrg        memcpy (_iceConn->outbufptr, _data, _bytes); \
187266e564dSmrg        _iceConn->outbufptr += (_bytes); \
188266e564dSmrg    } \
189266e564dSmrg}
190266e564dSmrg
191266e564dSmrg#ifndef WORD64
192266e564dSmrg
193266e564dSmrg#define IceWriteData16(_iceConn, _bytes, _data) \
194266e564dSmrg    IceWriteData (_iceConn, _bytes, (char *) _data)
195266e564dSmrg
196266e564dSmrg#define IceWriteData32(_iceConn, _bytes, _data) \
197266e564dSmrg    IceWriteData (_iceConn, _bytes, (char *) _data)
198266e564dSmrg
199266e564dSmrg#else /* WORD64 */
200266e564dSmrg
201266e564dSmrg/* IceWriteData16 and IceWriteData32 defined in misc.c for WORD64 */
202266e564dSmrg
203266e564dSmrg#endif /* WORD64 */
204266e564dSmrg
205266e564dSmrg
206266e564dSmrg/*
207266e564dSmrg * The IceSendData macro bypasses copying the data to the
208266e564dSmrg * ICE connection buffer and sends the data directly.  If necessary,
209266e564dSmrg * the ICE connection buffer is first flushed.
210266e564dSmrg */
211266e564dSmrg
212266e564dSmrg#define IceSendData(_iceConn, _bytes, _data) \
213266e564dSmrg{ \
214266e564dSmrg    if (_iceConn->outbufptr > _iceConn->outbuf) \
215266e564dSmrg	IceFlush (_iceConn); \
216266e564dSmrg    _IceWrite (_iceConn, (unsigned long) (_bytes), _data); \
217266e564dSmrg}
218266e564dSmrg
219266e564dSmrg
220266e564dSmrg/*
221266e564dSmrg * Write pad bytes.  Used to force 32 or 64 bit alignment.
222266e564dSmrg * A maxium of 7 pad bytes can be specified.
223266e564dSmrg */
224266e564dSmrg
225266e564dSmrg#define IceWritePad(_iceConn, _bytes) \
226266e564dSmrg{ \
227266e564dSmrg    if ((_iceConn->outbufptr + (_bytes)) > _iceConn->outbufmax) \
228266e564dSmrg    { \
229266e564dSmrg        char _dummy[7]; \
230266e564dSmrg	IceFlush (_iceConn); \
231266e564dSmrg        _IceWrite (_iceConn, (unsigned long) (_bytes), _dummy); \
232266e564dSmrg    } \
233266e564dSmrg    else \
234266e564dSmrg    { \
235266e564dSmrg        _iceConn->outbufptr += (_bytes); \
236266e564dSmrg    } \
237266e564dSmrg}
238266e564dSmrg
239266e564dSmrg
240266e564dSmrg/*
241266e564dSmrg * Macros for reading messages.
242266e564dSmrg */
243266e564dSmrg
244266e564dSmrg#define IceReadCompleteMessage(_iceConn, _headerSize, _msgType, _pMsg, _pData)\
245266e564dSmrg{ \
246266e564dSmrg    unsigned long _bytes; \
247266e564dSmrg    IceReadMessageHeader (_iceConn, _headerSize, _msgType, _pMsg); \
248266e564dSmrg    _bytes = (_pMsg->length << 3) - (_headerSize - SIZEOF (iceMsg)); \
249266e564dSmrg    if ((_iceConn->inbufmax - _iceConn->inbufptr) >= _bytes) \
250266e564dSmrg    { \
251266e564dSmrg	_IceRead (_iceConn, _bytes, _iceConn->inbufptr); \
252266e564dSmrg	_pData = _iceConn->inbufptr; \
253266e564dSmrg	_iceConn->inbufptr += _bytes; \
254266e564dSmrg    } \
255266e564dSmrg    else \
256266e564dSmrg    { \
257266e564dSmrg	_pData = (char *) malloc ((unsigned) _bytes); \
258266e564dSmrg        if (_pData) \
259266e564dSmrg	    _IceRead (_iceConn, _bytes, _pData); \
260266e564dSmrg        else \
261266e564dSmrg	    _IceReadSkip (_iceConn, _bytes); \
262266e564dSmrg    } \
263266e564dSmrg}
264266e564dSmrg
265266e564dSmrg#define IceDisposeCompleteMessage(_iceConn, _pData) \
266266e564dSmrg    if ((char *) _pData < _iceConn->inbuf || \
267266e564dSmrg	(char *) _pData >= _iceConn->inbufmax) \
268266e564dSmrg        free ((char *) _pData);
269266e564dSmrg
270266e564dSmrg
271266e564dSmrg#define IceReadSimpleMessage(_iceConn, _msgType, _pMsg) \
272266e564dSmrg    _pMsg = (_msgType *) (_iceConn->inbuf);
273266e564dSmrg
274266e564dSmrg#define IceReadMessageHeader(_iceConn, _headerSize, _msgType, _pMsg) \
275266e564dSmrg{ \
276266e564dSmrg    _IceRead (_iceConn, \
277266e564dSmrg	(unsigned long) (_headerSize - SIZEOF (iceMsg)), \
278266e564dSmrg	_iceConn->inbufptr); \
279266e564dSmrg    _pMsg = (_msgType *) (_iceConn->inbuf); \
280266e564dSmrg    _iceConn->inbufptr += (_headerSize - SIZEOF (iceMsg)); \
281266e564dSmrg}
282266e564dSmrg
283266e564dSmrg#define IceReadData(_iceConn, _bytes, _pData) \
284266e564dSmrg    _IceRead (_iceConn, (unsigned long) (_bytes), (char *) _pData); \
285266e564dSmrg
286266e564dSmrg#ifndef WORD64
287266e564dSmrg
288266e564dSmrg#define IceReadData16(_iceConn, _swap, _bytes, _pData) \
289266e564dSmrg{ \
290266e564dSmrg    _IceRead (_iceConn, (unsigned long) (_bytes), (char *) _pData); \
291266e564dSmrg}
292266e564dSmrg
293266e564dSmrg#define IceReadData32(_iceConn, _swap, _bytes, _pData) \
294266e564dSmrg{ \
295266e564dSmrg    _IceRead (_iceConn, (unsigned long) (_bytes), (char *) _pData); \
296266e564dSmrg}
297266e564dSmrg
298266e564dSmrg#else /* WORD64 */
299266e564dSmrg
300266e564dSmrg/* IceReadData16 and IceReadData32 defined in misc.c for WORD64 */
301266e564dSmrg
302266e564dSmrg#endif /* WORD64 */
303266e564dSmrg
304266e564dSmrg
305266e564dSmrg/*
306266e564dSmrg * Read pad bytes (for 32 or 64 bit alignment).
307266e564dSmrg * A maxium of 7 pad bytes can be specified.
308266e564dSmrg */
309266e564dSmrg
310266e564dSmrg#define IceReadPad(_iceConn, _bytes) \
311266e564dSmrg{ \
312266e564dSmrg    char _dummy[7]; \
313266e564dSmrg    _IceRead (_iceConn, (unsigned long) (_bytes), _dummy); \
314266e564dSmrg}
315266e564dSmrg
316266e564dSmrg_XFUNCPROTOEND
317266e564dSmrg
318266e564dSmrg#endif /* _ICEMSG_H_ */
319