File indexing completed on 2025-03-13 09:29:43
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #ifndef _ICEMSG_H_
0030 #define _ICEMSG_H_
0031
0032 #include <X11/Xfuncproto.h>
0033
0034 #include <X11/ICE/ICEconn.h>
0035
0036 #include <assert.h>
0037 #if !defined(__cplusplus) && !defined(static_assert)
0038 #define static_assert(cond, msg)
0039 #endif
0040
0041 _XFUNCPROTOBEGIN
0042
0043
0044
0045
0046
0047 extern Status _IceRead (
0048 IceConn ,
0049 unsigned long ,
0050 char *
0051 );
0052
0053 extern void _IceReadSkip (
0054 IceConn ,
0055 unsigned long
0056 );
0057
0058 extern void _IceWrite (
0059 IceConn ,
0060 unsigned long ,
0061 char *
0062 );
0063
0064
0065 extern void _IceErrorBadMinor (
0066 IceConn ,
0067 int ,
0068 int ,
0069 int
0070 );
0071
0072 extern void _IceErrorBadState (
0073 IceConn ,
0074 int ,
0075 int ,
0076 int
0077 );
0078
0079 extern void _IceErrorBadLength (
0080 IceConn ,
0081 int ,
0082 int ,
0083 int
0084 );
0085
0086 extern void _IceErrorBadValue (
0087 IceConn ,
0088 int ,
0089 int ,
0090 int ,
0091 int ,
0092 IcePointer
0093 );
0094
0095 extern IcePoAuthStatus _IcePoMagicCookie1Proc (
0096 IceConn ,
0097 IcePointer * ,
0098 Bool ,
0099 Bool ,
0100 int ,
0101 IcePointer ,
0102 int * ,
0103 IcePointer * ,
0104 char **
0105 );
0106
0107 extern IcePaAuthStatus _IcePaMagicCookie1Proc (
0108 IceConn ,
0109 IcePointer * ,
0110 Bool ,
0111 int ,
0112 IcePointer ,
0113 int * ,
0114 IcePointer * ,
0115 char **
0116 );
0117
0118
0119
0120
0121
0122
0123 #define IceValidIO(_iceConn) _iceConn->io_ok
0124
0125
0126
0127
0128
0129
0130 #define IceGetHeader(_iceConn, _major, _minor, _headerSize, _msgType, _pMsg) \
0131 do { \
0132 static_assert(_headerSize <= 1024, \
0133 "Header size larger than ICE_OUTBUFSIZE"); \
0134 if ((_iceConn->outbufptr + _headerSize) > _iceConn->outbufmax) \
0135 IceFlush (_iceConn); \
0136 _pMsg = (_msgType *) _iceConn->outbufptr; \
0137 _pMsg->majorOpcode = _major; \
0138 _pMsg->minorOpcode = _minor; \
0139 _pMsg->length = (_headerSize - SIZEOF (iceMsg)) >> 3; \
0140 _iceConn->outbufptr += _headerSize; \
0141 _iceConn->send_sequence++; \
0142 } while (0)
0143
0144 #define IceGetHeaderExtra(_iceConn, _major, _minor, _headerSize, _extra, _msgType, _pMsg, _pData) \
0145 do { \
0146 static_assert(_headerSize <= 1024, \
0147 "Header size larger than ICE_OUTBUFSIZE"); \
0148 if ((_iceConn->outbufptr + \
0149 _headerSize + ((_extra) << 3)) > _iceConn->outbufmax) \
0150 IceFlush (_iceConn); \
0151 _pMsg = (_msgType *) _iceConn->outbufptr; \
0152 _iceConn->outbufptr += _headerSize; \
0153 if ((_iceConn->outbufptr + ((_extra) << 3)) <= _iceConn->outbufmax) { \
0154 _pData = _iceConn->outbufptr; \
0155 _iceConn->outbufptr += ((_extra) << 3); \
0156 } \
0157 else \
0158 _pData = NULL; \
0159 _pMsg->majorOpcode = _major; \
0160 _pMsg->minorOpcode = _minor; \
0161 _pMsg->length = ((_headerSize - SIZEOF (iceMsg)) >> 3) + (_extra); \
0162 _iceConn->send_sequence++; \
0163 } while (0)
0164
0165 #define IceSimpleMessage(_iceConn, _major, _minor) \
0166 { \
0167 iceMsg *_pMsg; \
0168 IceGetHeader (_iceConn, _major, _minor, SIZEOF (iceMsg), iceMsg, _pMsg); \
0169 }
0170
0171 #define IceErrorHeader(_iceConn, _offendingMajorOpcode, _offendingMinorOpcode, _offendingSequenceNum, _severity, _errorClass, _dataLength) \
0172 { \
0173 iceErrorMsg *_pMsg; \
0174 \
0175 IceGetHeader (_iceConn, _offendingMajorOpcode, ICE_Error, \
0176 SIZEOF (iceErrorMsg), iceErrorMsg, _pMsg); \
0177 _pMsg->length += (_dataLength); \
0178 _pMsg->offendingMinorOpcode = (CARD8) _offendingMinorOpcode; \
0179 _pMsg->severity = (CARD8) _severity; \
0180 _pMsg->offendingSequenceNum = (CARD32) _offendingSequenceNum; \
0181 _pMsg->errorClass = (CARD16) _errorClass; \
0182 }
0183
0184
0185
0186
0187
0188
0189 #define IceWriteData(_iceConn, _bytes, _data) \
0190 { \
0191 if ((_iceConn->outbufptr + (_bytes)) > _iceConn->outbufmax) \
0192 { \
0193 IceFlush (_iceConn); \
0194 _IceWrite (_iceConn, (unsigned long) (_bytes), _data); \
0195 } \
0196 else \
0197 { \
0198 memcpy (_iceConn->outbufptr, _data, _bytes); \
0199 _iceConn->outbufptr += (_bytes); \
0200 } \
0201 }
0202
0203 #define IceWriteData16(_iceConn, _bytes, _data) \
0204 IceWriteData (_iceConn, _bytes, (char *) _data)
0205
0206 #define IceWriteData32(_iceConn, _bytes, _data) \
0207 IceWriteData (_iceConn, _bytes, (char *) _data)
0208
0209
0210
0211
0212
0213
0214
0215
0216 #define IceSendData(_iceConn, _bytes, _data) \
0217 { \
0218 if (_iceConn->outbufptr > _iceConn->outbuf) \
0219 IceFlush (_iceConn); \
0220 _IceWrite (_iceConn, (unsigned long) (_bytes), _data); \
0221 }
0222
0223
0224
0225
0226
0227
0228
0229 #define IceWritePad(_iceConn, _bytes) \
0230 { \
0231 char _dummy[7] = { 0 }; \
0232 IceWriteData (_iceConn, (_bytes), _dummy); \
0233 }
0234
0235
0236
0237
0238
0239
0240 #define IceReadCompleteMessage(_iceConn, _headerSize, _msgType, _pMsg, _pData)\
0241 { \
0242 unsigned long _bytes; \
0243 IceReadMessageHeader (_iceConn, _headerSize, _msgType, _pMsg); \
0244 _bytes = (_pMsg->length << 3) - (_headerSize - SIZEOF (iceMsg)); \
0245 if ((_iceConn->inbufmax - _iceConn->inbufptr) >= _bytes) \
0246 { \
0247 _IceRead (_iceConn, _bytes, _iceConn->inbufptr); \
0248 _pData = _iceConn->inbufptr; \
0249 _iceConn->inbufptr += _bytes; \
0250 } \
0251 else \
0252 { \
0253 _pData = malloc (_bytes); \
0254 if (_pData) \
0255 _IceRead (_iceConn, _bytes, _pData); \
0256 else \
0257 _IceReadSkip (_iceConn, _bytes); \
0258 } \
0259 }
0260
0261 #define IceDisposeCompleteMessage(_iceConn, _pData) \
0262 if ((char *) _pData < _iceConn->inbuf || \
0263 (char *) _pData >= _iceConn->inbufmax) \
0264 free (_pData);
0265
0266
0267 #define IceReadSimpleMessage(_iceConn, _msgType, _pMsg) \
0268 _pMsg = (_msgType *) (_iceConn->inbuf);
0269
0270 #define IceReadMessageHeader(_iceConn, _headerSize, _msgType, _pMsg) \
0271 { \
0272 _IceRead (_iceConn, \
0273 (unsigned long) (_headerSize - SIZEOF (iceMsg)), \
0274 _iceConn->inbufptr); \
0275 _pMsg = (_msgType *) (_iceConn->inbuf); \
0276 _iceConn->inbufptr += (_headerSize - SIZEOF (iceMsg)); \
0277 }
0278
0279 #define IceReadData(_iceConn, _bytes, _pData) \
0280 _IceRead (_iceConn, (unsigned long) (_bytes), (char *) _pData); \
0281
0282 #define IceReadData16(_iceConn, _swap, _bytes, _pData) \
0283 { \
0284 _IceRead (_iceConn, (unsigned long) (_bytes), (char *) _pData); \
0285 }
0286
0287 #define IceReadData32(_iceConn, _swap, _bytes, _pData) \
0288 { \
0289 _IceRead (_iceConn, (unsigned long) (_bytes), (char *) _pData); \
0290 }
0291
0292
0293
0294
0295
0296
0297
0298 #define IceReadPad(_iceConn, _bytes) \
0299 { \
0300 char _dummy[7]; \
0301 _IceRead (_iceConn, (unsigned long) (_bytes), _dummy); \
0302 }
0303
0304 _XFUNCPROTOEND
0305
0306 #endif