1 /******************************************************************************
4 Copyright 1993, 1998 The Open Group
6 Permission to use, copy, modify, distribute, and sell this software and its
7 documentation for any purpose is hereby granted without fee, provided that
8 the above copyright notice appear in all copies and that both that
9 copyright notice and this permission notice appear in supporting
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of The Open Group shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from The Open Group.
26 Author: Ralph Mor, X Consortium
27 ******************************************************************************/
32 #include <X11/Xfuncproto.h>
34 #include <X11/ICE/ICEconn.h>
39 * Function prototypes for internal ICElib functions
42 extern Status _IceRead (
43 IceConn /* iceConn */,
44 unsigned long /* nbytes */,
48 extern void _IceReadSkip (
49 IceConn /* iceConn */,
50 unsigned long /* nbytes */
53 extern void _IceWrite (
54 IceConn /* iceConn */,
55 unsigned long /* nbytes */,
60 extern void _IceErrorBadMinor (
61 IceConn /* iceConn */,
62 int /* majorOpcode */,
63 int /* offendingMinor */,
67 extern void _IceErrorBadState (
68 IceConn /* iceConn */,
69 int /* majorOpcode */,
70 int /* offendingMinor */,
74 extern void _IceErrorBadLength (
75 IceConn /* iceConn */,
76 int /* majorOpcode */,
77 int /* offendingMinor */,
81 extern void _IceErrorBadValue (
82 IceConn /* iceConn */,
83 int /* majorOpcode */,
84 int /* offendingMinor */,
87 IcePointer /* value */
90 extern IcePoAuthStatus _IcePoMagicCookie1Proc (
91 IceConn /* iceConn */,
92 IcePointer * /* authStatePtr */,
95 int /* authDataLen */,
96 IcePointer /* authData */,
97 int * /* replyDataLenRet */,
98 IcePointer * /* replyDataRet */,
99 char ** /* errorStringRet */
102 extern IcePaAuthStatus _IcePaMagicCookie1Proc (
103 IceConn /* iceConn */,
104 IcePointer * /* authStatePtr */,
106 int /* authDataLen */,
107 IcePointer /* authData */,
108 int * /* replyDataLenRet */,
109 IcePointer * /* replyDataRet */,
110 char ** /* errorStringRet */
115 * Macro to check if IO operations are valid on an ICE connection.
118 #define IceValidIO(_iceConn) _iceConn->io_ok
122 * Macros for writing messages.
125 #define IceGetHeader(_iceConn, _major, _minor, _headerSize, _msgType, _pMsg) \
126 if ((_iceConn->outbufptr + _headerSize) > _iceConn->outbufmax) \
127 IceFlush (_iceConn); \
128 _pMsg = (_msgType *) _iceConn->outbufptr; \
129 _pMsg->majorOpcode = _major; \
130 _pMsg->minorOpcode = _minor; \
131 _pMsg->length = (_headerSize - SIZEOF (iceMsg)) >> 3; \
132 _iceConn->outbufptr += _headerSize; \
133 _iceConn->send_sequence++
135 #define IceGetHeaderExtra(_iceConn, _major, _minor, _headerSize, _extra, _msgType, _pMsg, _pData) \
136 if ((_iceConn->outbufptr + \
137 _headerSize + ((_extra) << 3)) > _iceConn->outbufmax) \
138 IceFlush (_iceConn); \
139 _pMsg = (_msgType *) _iceConn->outbufptr; \
140 if ((_iceConn->outbufptr + \
141 _headerSize + ((_extra) << 3)) <= _iceConn->outbufmax) \
142 _pData = (char *) _pMsg + _headerSize; \
145 _pMsg->majorOpcode = _major; \
146 _pMsg->minorOpcode = _minor; \
147 _pMsg->length = ((_headerSize - SIZEOF (iceMsg)) >> 3) + (_extra); \
148 _iceConn->outbufptr += (_headerSize + ((_extra) << 3)); \
149 _iceConn->send_sequence++
151 #define IceSimpleMessage(_iceConn, _major, _minor) \
154 IceGetHeader (_iceConn, _major, _minor, SIZEOF (iceMsg), iceMsg, _pMsg); \
157 #define IceErrorHeader(_iceConn, _offendingMajorOpcode, _offendingMinorOpcode, _offendingSequenceNum, _severity, _errorClass, _dataLength) \
159 iceErrorMsg *_pMsg; \
161 IceGetHeader (_iceConn, _offendingMajorOpcode, ICE_Error, \
162 SIZEOF (iceErrorMsg), iceErrorMsg, _pMsg); \
163 _pMsg->length += (_dataLength); \
164 _pMsg->offendingMinorOpcode = _offendingMinorOpcode; \
165 _pMsg->severity = _severity; \
166 _pMsg->offendingSequenceNum = _offendingSequenceNum; \
167 _pMsg->errorClass = _errorClass; \
172 * Write data into the ICE output buffer.
175 #define IceWriteData(_iceConn, _bytes, _data) \
177 if ((_iceConn->outbufptr + (_bytes)) > _iceConn->outbufmax) \
179 IceFlush (_iceConn); \
180 _IceWrite (_iceConn, (unsigned long) (_bytes), _data); \
184 memcpy (_iceConn->outbufptr, _data, _bytes); \
185 _iceConn->outbufptr += (_bytes); \
191 #define IceWriteData16(_iceConn, _bytes, _data) \
192 IceWriteData (_iceConn, _bytes, (char *) _data)
194 #define IceWriteData32(_iceConn, _bytes, _data) \
195 IceWriteData (_iceConn, _bytes, (char *) _data)
199 /* IceWriteData16 and IceWriteData32 defined in misc.c for WORD64 */
205 * The IceSendData macro bypasses copying the data to the
206 * ICE connection buffer and sends the data directly. If necessary,
207 * the ICE connection buffer is first flushed.
210 #define IceSendData(_iceConn, _bytes, _data) \
212 if (_iceConn->outbufptr > _iceConn->outbuf) \
213 IceFlush (_iceConn); \
214 _IceWrite (_iceConn, (unsigned long) (_bytes), _data); \
219 * Write pad bytes. Used to force 32 or 64 bit alignment.
220 * A maximum of 7 pad bytes can be specified.
223 #define IceWritePad(_iceConn, _bytes) \
225 if ((_iceConn->outbufptr + (_bytes)) > _iceConn->outbufmax) \
227 char _dummy[7] = { 0 }; \
228 IceFlush (_iceConn); \
229 _IceWrite (_iceConn, (unsigned long) (_bytes), _dummy); \
233 _iceConn->outbufptr += (_bytes); \
239 * Macros for reading messages.
242 #define IceReadCompleteMessage(_iceConn, _headerSize, _msgType, _pMsg, _pData)\
244 unsigned long _bytes; \
245 IceReadMessageHeader (_iceConn, _headerSize, _msgType, _pMsg); \
246 _bytes = (_pMsg->length << 3) - (_headerSize - SIZEOF (iceMsg)); \
247 if ((_iceConn->inbufmax - _iceConn->inbufptr) >= _bytes) \
249 _IceRead (_iceConn, _bytes, _iceConn->inbufptr); \
250 _pData = _iceConn->inbufptr; \
251 _iceConn->inbufptr += _bytes; \
255 _pData = (char *) malloc ((unsigned) _bytes); \
257 _IceRead (_iceConn, _bytes, _pData); \
259 _IceReadSkip (_iceConn, _bytes); \
263 #define IceDisposeCompleteMessage(_iceConn, _pData) \
264 if ((char *) _pData < _iceConn->inbuf || \
265 (char *) _pData >= _iceConn->inbufmax) \
266 free ((char *) _pData);
269 #define IceReadSimpleMessage(_iceConn, _msgType, _pMsg) \
270 _pMsg = (_msgType *) (_iceConn->inbuf);
272 #define IceReadMessageHeader(_iceConn, _headerSize, _msgType, _pMsg) \
274 _IceRead (_iceConn, \
275 (unsigned long) (_headerSize - SIZEOF (iceMsg)), \
276 _iceConn->inbufptr); \
277 _pMsg = (_msgType *) (_iceConn->inbuf); \
278 _iceConn->inbufptr += (_headerSize - SIZEOF (iceMsg)); \
281 #define IceReadData(_iceConn, _bytes, _pData) \
282 _IceRead (_iceConn, (unsigned long) (_bytes), (char *) _pData); \
286 #define IceReadData16(_iceConn, _swap, _bytes, _pData) \
288 _IceRead (_iceConn, (unsigned long) (_bytes), (char *) _pData); \
291 #define IceReadData32(_iceConn, _swap, _bytes, _pData) \
293 _IceRead (_iceConn, (unsigned long) (_bytes), (char *) _pData); \
298 /* IceReadData16 and IceReadData32 defined in misc.c for WORD64 */
304 * Read pad bytes (for 32 or 64 bit alignment).
305 * A maxium of 7 pad bytes can be specified.
308 #define IceReadPad(_iceConn, _bytes) \
311 _IceRead (_iceConn, (unsigned long) (_bytes), _dummy); \
316 #endif /* _ICEMSG_H_ */