jpayne@69
|
1 /******************************************************************************
|
jpayne@69
|
2
|
jpayne@69
|
3
|
jpayne@69
|
4 Copyright 1993, 1998 The Open Group
|
jpayne@69
|
5
|
jpayne@69
|
6 Permission to use, copy, modify, distribute, and sell this software and its
|
jpayne@69
|
7 documentation for any purpose is hereby granted without fee, provided that
|
jpayne@69
|
8 the above copyright notice appear in all copies and that both that
|
jpayne@69
|
9 copyright notice and this permission notice appear in supporting
|
jpayne@69
|
10 documentation.
|
jpayne@69
|
11
|
jpayne@69
|
12 The above copyright notice and this permission notice shall be included in
|
jpayne@69
|
13 all copies or substantial portions of the Software.
|
jpayne@69
|
14
|
jpayne@69
|
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
jpayne@69
|
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
jpayne@69
|
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
jpayne@69
|
18 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
jpayne@69
|
19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
jpayne@69
|
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
jpayne@69
|
21
|
jpayne@69
|
22 Except as contained in this notice, the name of The Open Group shall not be
|
jpayne@69
|
23 used in advertising or otherwise to promote the sale, use or other dealings
|
jpayne@69
|
24 in this Software without prior written authorization from The Open Group.
|
jpayne@69
|
25
|
jpayne@69
|
26 Author: Ralph Mor, X Consortium
|
jpayne@69
|
27 ******************************************************************************/
|
jpayne@69
|
28
|
jpayne@69
|
29 #ifndef _ICEMSG_H_
|
jpayne@69
|
30 #define _ICEMSG_H_
|
jpayne@69
|
31
|
jpayne@69
|
32 #include <X11/Xfuncproto.h>
|
jpayne@69
|
33
|
jpayne@69
|
34 #include <X11/ICE/ICEconn.h>
|
jpayne@69
|
35
|
jpayne@69
|
36 #include <assert.h>
|
jpayne@69
|
37 #if !defined(__cplusplus) && !defined(static_assert)
|
jpayne@69
|
38 #define static_assert(cond, msg) /* skip for non-C11 compilers */
|
jpayne@69
|
39 #endif
|
jpayne@69
|
40
|
jpayne@69
|
41 _XFUNCPROTOBEGIN
|
jpayne@69
|
42
|
jpayne@69
|
43 /*
|
jpayne@69
|
44 * Function prototypes for internal ICElib functions
|
jpayne@69
|
45 */
|
jpayne@69
|
46
|
jpayne@69
|
47 extern Status _IceRead (
|
jpayne@69
|
48 IceConn /* iceConn */,
|
jpayne@69
|
49 unsigned long /* nbytes */,
|
jpayne@69
|
50 char * /* ptr */
|
jpayne@69
|
51 );
|
jpayne@69
|
52
|
jpayne@69
|
53 extern void _IceReadSkip (
|
jpayne@69
|
54 IceConn /* iceConn */,
|
jpayne@69
|
55 unsigned long /* nbytes */
|
jpayne@69
|
56 );
|
jpayne@69
|
57
|
jpayne@69
|
58 extern void _IceWrite (
|
jpayne@69
|
59 IceConn /* iceConn */,
|
jpayne@69
|
60 unsigned long /* nbytes */,
|
jpayne@69
|
61 char * /* ptr */
|
jpayne@69
|
62 );
|
jpayne@69
|
63
|
jpayne@69
|
64
|
jpayne@69
|
65 extern void _IceErrorBadMinor (
|
jpayne@69
|
66 IceConn /* iceConn */,
|
jpayne@69
|
67 int /* majorOpcode */,
|
jpayne@69
|
68 int /* offendingMinor */,
|
jpayne@69
|
69 int /* severity */
|
jpayne@69
|
70 );
|
jpayne@69
|
71
|
jpayne@69
|
72 extern void _IceErrorBadState (
|
jpayne@69
|
73 IceConn /* iceConn */,
|
jpayne@69
|
74 int /* majorOpcode */,
|
jpayne@69
|
75 int /* offendingMinor */,
|
jpayne@69
|
76 int /* severity */
|
jpayne@69
|
77 );
|
jpayne@69
|
78
|
jpayne@69
|
79 extern void _IceErrorBadLength (
|
jpayne@69
|
80 IceConn /* iceConn */,
|
jpayne@69
|
81 int /* majorOpcode */,
|
jpayne@69
|
82 int /* offendingMinor */,
|
jpayne@69
|
83 int /* severity */
|
jpayne@69
|
84 );
|
jpayne@69
|
85
|
jpayne@69
|
86 extern void _IceErrorBadValue (
|
jpayne@69
|
87 IceConn /* iceConn */,
|
jpayne@69
|
88 int /* majorOpcode */,
|
jpayne@69
|
89 int /* offendingMinor */,
|
jpayne@69
|
90 int /* offset */,
|
jpayne@69
|
91 int /* length */,
|
jpayne@69
|
92 IcePointer /* value */
|
jpayne@69
|
93 );
|
jpayne@69
|
94
|
jpayne@69
|
95 extern IcePoAuthStatus _IcePoMagicCookie1Proc (
|
jpayne@69
|
96 IceConn /* iceConn */,
|
jpayne@69
|
97 IcePointer * /* authStatePtr */,
|
jpayne@69
|
98 Bool /* cleanUp */,
|
jpayne@69
|
99 Bool /* swap */,
|
jpayne@69
|
100 int /* authDataLen */,
|
jpayne@69
|
101 IcePointer /* authData */,
|
jpayne@69
|
102 int * /* replyDataLenRet */,
|
jpayne@69
|
103 IcePointer * /* replyDataRet */,
|
jpayne@69
|
104 char ** /* errorStringRet */
|
jpayne@69
|
105 );
|
jpayne@69
|
106
|
jpayne@69
|
107 extern IcePaAuthStatus _IcePaMagicCookie1Proc (
|
jpayne@69
|
108 IceConn /* iceConn */,
|
jpayne@69
|
109 IcePointer * /* authStatePtr */,
|
jpayne@69
|
110 Bool /* swap */,
|
jpayne@69
|
111 int /* authDataLen */,
|
jpayne@69
|
112 IcePointer /* authData */,
|
jpayne@69
|
113 int * /* replyDataLenRet */,
|
jpayne@69
|
114 IcePointer * /* replyDataRet */,
|
jpayne@69
|
115 char ** /* errorStringRet */
|
jpayne@69
|
116 );
|
jpayne@69
|
117
|
jpayne@69
|
118
|
jpayne@69
|
119 /*
|
jpayne@69
|
120 * Macro to check if IO operations are valid on an ICE connection.
|
jpayne@69
|
121 */
|
jpayne@69
|
122
|
jpayne@69
|
123 #define IceValidIO(_iceConn) _iceConn->io_ok
|
jpayne@69
|
124
|
jpayne@69
|
125
|
jpayne@69
|
126 /*
|
jpayne@69
|
127 * Macros for writing messages.
|
jpayne@69
|
128 */
|
jpayne@69
|
129
|
jpayne@69
|
130 #define IceGetHeader(_iceConn, _major, _minor, _headerSize, _msgType, _pMsg) \
|
jpayne@69
|
131 do { \
|
jpayne@69
|
132 static_assert(_headerSize <= 1024, \
|
jpayne@69
|
133 "Header size larger than ICE_OUTBUFSIZE"); \
|
jpayne@69
|
134 if ((_iceConn->outbufptr + _headerSize) > _iceConn->outbufmax) \
|
jpayne@69
|
135 IceFlush (_iceConn); \
|
jpayne@69
|
136 _pMsg = (_msgType *) _iceConn->outbufptr; \
|
jpayne@69
|
137 _pMsg->majorOpcode = _major; \
|
jpayne@69
|
138 _pMsg->minorOpcode = _minor; \
|
jpayne@69
|
139 _pMsg->length = (_headerSize - SIZEOF (iceMsg)) >> 3; \
|
jpayne@69
|
140 _iceConn->outbufptr += _headerSize; \
|
jpayne@69
|
141 _iceConn->send_sequence++; \
|
jpayne@69
|
142 } while (0)
|
jpayne@69
|
143
|
jpayne@69
|
144 #define IceGetHeaderExtra(_iceConn, _major, _minor, _headerSize, _extra, _msgType, _pMsg, _pData) \
|
jpayne@69
|
145 do { \
|
jpayne@69
|
146 static_assert(_headerSize <= 1024, \
|
jpayne@69
|
147 "Header size larger than ICE_OUTBUFSIZE"); \
|
jpayne@69
|
148 if ((_iceConn->outbufptr + \
|
jpayne@69
|
149 _headerSize + ((_extra) << 3)) > _iceConn->outbufmax) \
|
jpayne@69
|
150 IceFlush (_iceConn); \
|
jpayne@69
|
151 _pMsg = (_msgType *) _iceConn->outbufptr; \
|
jpayne@69
|
152 _iceConn->outbufptr += _headerSize; \
|
jpayne@69
|
153 if ((_iceConn->outbufptr + ((_extra) << 3)) <= _iceConn->outbufmax) { \
|
jpayne@69
|
154 _pData = _iceConn->outbufptr; \
|
jpayne@69
|
155 _iceConn->outbufptr += ((_extra) << 3); \
|
jpayne@69
|
156 } \
|
jpayne@69
|
157 else \
|
jpayne@69
|
158 _pData = NULL; \
|
jpayne@69
|
159 _pMsg->majorOpcode = _major; \
|
jpayne@69
|
160 _pMsg->minorOpcode = _minor; \
|
jpayne@69
|
161 _pMsg->length = ((_headerSize - SIZEOF (iceMsg)) >> 3) + (_extra); \
|
jpayne@69
|
162 _iceConn->send_sequence++; \
|
jpayne@69
|
163 } while (0)
|
jpayne@69
|
164
|
jpayne@69
|
165 #define IceSimpleMessage(_iceConn, _major, _minor) \
|
jpayne@69
|
166 { \
|
jpayne@69
|
167 iceMsg *_pMsg; \
|
jpayne@69
|
168 IceGetHeader (_iceConn, _major, _minor, SIZEOF (iceMsg), iceMsg, _pMsg); \
|
jpayne@69
|
169 }
|
jpayne@69
|
170
|
jpayne@69
|
171 #define IceErrorHeader(_iceConn, _offendingMajorOpcode, _offendingMinorOpcode, _offendingSequenceNum, _severity, _errorClass, _dataLength) \
|
jpayne@69
|
172 { \
|
jpayne@69
|
173 iceErrorMsg *_pMsg; \
|
jpayne@69
|
174 \
|
jpayne@69
|
175 IceGetHeader (_iceConn, _offendingMajorOpcode, ICE_Error, \
|
jpayne@69
|
176 SIZEOF (iceErrorMsg), iceErrorMsg, _pMsg); \
|
jpayne@69
|
177 _pMsg->length += (_dataLength); \
|
jpayne@69
|
178 _pMsg->offendingMinorOpcode = (CARD8) _offendingMinorOpcode; \
|
jpayne@69
|
179 _pMsg->severity = (CARD8) _severity; \
|
jpayne@69
|
180 _pMsg->offendingSequenceNum = (CARD32) _offendingSequenceNum; \
|
jpayne@69
|
181 _pMsg->errorClass = (CARD16) _errorClass; \
|
jpayne@69
|
182 }
|
jpayne@69
|
183
|
jpayne@69
|
184
|
jpayne@69
|
185 /*
|
jpayne@69
|
186 * Write data into the ICE output buffer.
|
jpayne@69
|
187 */
|
jpayne@69
|
188
|
jpayne@69
|
189 #define IceWriteData(_iceConn, _bytes, _data) \
|
jpayne@69
|
190 { \
|
jpayne@69
|
191 if ((_iceConn->outbufptr + (_bytes)) > _iceConn->outbufmax) \
|
jpayne@69
|
192 { \
|
jpayne@69
|
193 IceFlush (_iceConn); \
|
jpayne@69
|
194 _IceWrite (_iceConn, (unsigned long) (_bytes), _data); \
|
jpayne@69
|
195 } \
|
jpayne@69
|
196 else \
|
jpayne@69
|
197 { \
|
jpayne@69
|
198 memcpy (_iceConn->outbufptr, _data, _bytes); \
|
jpayne@69
|
199 _iceConn->outbufptr += (_bytes); \
|
jpayne@69
|
200 } \
|
jpayne@69
|
201 }
|
jpayne@69
|
202
|
jpayne@69
|
203 #define IceWriteData16(_iceConn, _bytes, _data) \
|
jpayne@69
|
204 IceWriteData (_iceConn, _bytes, (char *) _data)
|
jpayne@69
|
205
|
jpayne@69
|
206 #define IceWriteData32(_iceConn, _bytes, _data) \
|
jpayne@69
|
207 IceWriteData (_iceConn, _bytes, (char *) _data)
|
jpayne@69
|
208
|
jpayne@69
|
209
|
jpayne@69
|
210 /*
|
jpayne@69
|
211 * The IceSendData macro bypasses copying the data to the
|
jpayne@69
|
212 * ICE connection buffer and sends the data directly. If necessary,
|
jpayne@69
|
213 * the ICE connection buffer is first flushed.
|
jpayne@69
|
214 */
|
jpayne@69
|
215
|
jpayne@69
|
216 #define IceSendData(_iceConn, _bytes, _data) \
|
jpayne@69
|
217 { \
|
jpayne@69
|
218 if (_iceConn->outbufptr > _iceConn->outbuf) \
|
jpayne@69
|
219 IceFlush (_iceConn); \
|
jpayne@69
|
220 _IceWrite (_iceConn, (unsigned long) (_bytes), _data); \
|
jpayne@69
|
221 }
|
jpayne@69
|
222
|
jpayne@69
|
223
|
jpayne@69
|
224 /*
|
jpayne@69
|
225 * Write pad bytes. Used to force 32 or 64 bit alignment.
|
jpayne@69
|
226 * A maximum of 7 pad bytes can be specified.
|
jpayne@69
|
227 */
|
jpayne@69
|
228
|
jpayne@69
|
229 #define IceWritePad(_iceConn, _bytes) \
|
jpayne@69
|
230 { \
|
jpayne@69
|
231 char _dummy[7] = { 0 }; \
|
jpayne@69
|
232 IceWriteData (_iceConn, (_bytes), _dummy); \
|
jpayne@69
|
233 }
|
jpayne@69
|
234
|
jpayne@69
|
235
|
jpayne@69
|
236 /*
|
jpayne@69
|
237 * Macros for reading messages.
|
jpayne@69
|
238 */
|
jpayne@69
|
239
|
jpayne@69
|
240 #define IceReadCompleteMessage(_iceConn, _headerSize, _msgType, _pMsg, _pData)\
|
jpayne@69
|
241 { \
|
jpayne@69
|
242 unsigned long _bytes; \
|
jpayne@69
|
243 IceReadMessageHeader (_iceConn, _headerSize, _msgType, _pMsg); \
|
jpayne@69
|
244 _bytes = (_pMsg->length << 3) - (_headerSize - SIZEOF (iceMsg)); \
|
jpayne@69
|
245 if ((_iceConn->inbufmax - _iceConn->inbufptr) >= _bytes) \
|
jpayne@69
|
246 { \
|
jpayne@69
|
247 _IceRead (_iceConn, _bytes, _iceConn->inbufptr); \
|
jpayne@69
|
248 _pData = _iceConn->inbufptr; \
|
jpayne@69
|
249 _iceConn->inbufptr += _bytes; \
|
jpayne@69
|
250 } \
|
jpayne@69
|
251 else \
|
jpayne@69
|
252 { \
|
jpayne@69
|
253 _pData = malloc (_bytes); \
|
jpayne@69
|
254 if (_pData) \
|
jpayne@69
|
255 _IceRead (_iceConn, _bytes, _pData); \
|
jpayne@69
|
256 else \
|
jpayne@69
|
257 _IceReadSkip (_iceConn, _bytes); \
|
jpayne@69
|
258 } \
|
jpayne@69
|
259 }
|
jpayne@69
|
260
|
jpayne@69
|
261 #define IceDisposeCompleteMessage(_iceConn, _pData) \
|
jpayne@69
|
262 if ((char *) _pData < _iceConn->inbuf || \
|
jpayne@69
|
263 (char *) _pData >= _iceConn->inbufmax) \
|
jpayne@69
|
264 free (_pData);
|
jpayne@69
|
265
|
jpayne@69
|
266
|
jpayne@69
|
267 #define IceReadSimpleMessage(_iceConn, _msgType, _pMsg) \
|
jpayne@69
|
268 _pMsg = (_msgType *) (_iceConn->inbuf);
|
jpayne@69
|
269
|
jpayne@69
|
270 #define IceReadMessageHeader(_iceConn, _headerSize, _msgType, _pMsg) \
|
jpayne@69
|
271 { \
|
jpayne@69
|
272 _IceRead (_iceConn, \
|
jpayne@69
|
273 (unsigned long) (_headerSize - SIZEOF (iceMsg)), \
|
jpayne@69
|
274 _iceConn->inbufptr); \
|
jpayne@69
|
275 _pMsg = (_msgType *) (_iceConn->inbuf); \
|
jpayne@69
|
276 _iceConn->inbufptr += (_headerSize - SIZEOF (iceMsg)); \
|
jpayne@69
|
277 }
|
jpayne@69
|
278
|
jpayne@69
|
279 #define IceReadData(_iceConn, _bytes, _pData) \
|
jpayne@69
|
280 _IceRead (_iceConn, (unsigned long) (_bytes), (char *) _pData); \
|
jpayne@69
|
281
|
jpayne@69
|
282 #define IceReadData16(_iceConn, _swap, _bytes, _pData) \
|
jpayne@69
|
283 { \
|
jpayne@69
|
284 _IceRead (_iceConn, (unsigned long) (_bytes), (char *) _pData); \
|
jpayne@69
|
285 }
|
jpayne@69
|
286
|
jpayne@69
|
287 #define IceReadData32(_iceConn, _swap, _bytes, _pData) \
|
jpayne@69
|
288 { \
|
jpayne@69
|
289 _IceRead (_iceConn, (unsigned long) (_bytes), (char *) _pData); \
|
jpayne@69
|
290 }
|
jpayne@69
|
291
|
jpayne@69
|
292
|
jpayne@69
|
293 /*
|
jpayne@69
|
294 * Read pad bytes (for 32 or 64 bit alignment).
|
jpayne@69
|
295 * A maximum of 7 pad bytes can be specified.
|
jpayne@69
|
296 */
|
jpayne@69
|
297
|
jpayne@69
|
298 #define IceReadPad(_iceConn, _bytes) \
|
jpayne@69
|
299 { \
|
jpayne@69
|
300 char _dummy[7]; \
|
jpayne@69
|
301 _IceRead (_iceConn, (unsigned long) (_bytes), _dummy); \
|
jpayne@69
|
302 }
|
jpayne@69
|
303
|
jpayne@69
|
304 _XFUNCPROTOEND
|
jpayne@69
|
305
|
jpayne@69
|
306 #endif /* _ICEMSG_H_ */
|