Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-03-13 09:29:43

0001 /******************************************************************************
0002 
0003 
0004 Copyright 1993, 1998  The Open Group
0005 
0006 Permission to use, copy, modify, distribute, and sell this software and its
0007 documentation for any purpose is hereby granted without fee, provided that
0008 the above copyright notice appear in all copies and that both that
0009 copyright notice and this permission notice appear in supporting
0010 documentation.
0011 
0012 The above copyright notice and this permission notice shall be included in
0013 all copies or substantial portions of the Software.
0014 
0015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
0018 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
0019 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
0020 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0021 
0022 Except as contained in this notice, the name of The Open Group shall not be
0023 used in advertising or otherwise to promote the sale, use or other dealings
0024 in this Software without prior written authorization from The Open Group.
0025 
0026 Author: Ralph Mor, X Consortium
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) /* skip for non-C11 compilers */
0039 #endif
0040 
0041 _XFUNCPROTOBEGIN
0042 
0043 /*
0044  * Function prototypes for internal ICElib functions
0045  */
0046 
0047 extern Status _IceRead (
0048     IceConn     /* iceConn */,
0049     unsigned long   /* nbytes */,
0050     char *      /* ptr */
0051 );
0052 
0053 extern void _IceReadSkip (
0054     IceConn     /* iceConn */,
0055     unsigned long   /* nbytes */
0056 );
0057 
0058 extern void _IceWrite (
0059     IceConn     /* iceConn */,
0060     unsigned long   /* nbytes */,
0061     char *      /* ptr */
0062 );
0063 
0064 
0065 extern void _IceErrorBadMinor (
0066     IceConn     /* iceConn */,
0067     int         /* majorOpcode */,
0068     int         /* offendingMinor */,
0069     int         /* severity */
0070 );
0071 
0072 extern void _IceErrorBadState (
0073     IceConn     /* iceConn */,
0074     int         /* majorOpcode */,
0075     int         /* offendingMinor */,
0076     int         /* severity */
0077 );
0078 
0079 extern void _IceErrorBadLength (
0080     IceConn     /* iceConn */,
0081     int         /* majorOpcode */,
0082     int         /* offendingMinor */,
0083     int         /* severity */
0084 );
0085 
0086 extern void _IceErrorBadValue (
0087     IceConn     /* iceConn */,
0088     int         /* majorOpcode */,
0089     int         /* offendingMinor */,
0090     int         /* offset */,
0091     int         /* length */,
0092     IcePointer      /* value */
0093 );
0094 
0095 extern IcePoAuthStatus _IcePoMagicCookie1Proc (
0096     IceConn     /* iceConn */,
0097     IcePointer *    /* authStatePtr */,
0098     Bool        /* cleanUp */,
0099     Bool        /* swap */,
0100     int             /* authDataLen */,
0101     IcePointer      /* authData */,
0102     int *       /* replyDataLenRet */,
0103     IcePointer *    /* replyDataRet */,
0104     char **     /* errorStringRet */
0105 );
0106 
0107 extern IcePaAuthStatus _IcePaMagicCookie1Proc (
0108     IceConn     /* iceConn */,
0109     IcePointer *    /* authStatePtr */,
0110     Bool        /* swap */,
0111     int             /* authDataLen */,
0112     IcePointer      /* authData */,
0113     int *       /* replyDataLenRet */,
0114     IcePointer *    /* replyDataRet */,
0115     char **     /* errorStringRet */
0116 );
0117 
0118 
0119 /*
0120  * Macro to check if IO operations are valid on an ICE connection.
0121  */
0122 
0123 #define IceValidIO(_iceConn) _iceConn->io_ok
0124 
0125 
0126 /*
0127  * Macros for writing messages.
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  * Write data into the ICE output buffer.
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  * The IceSendData macro bypasses copying the data to the
0212  * ICE connection buffer and sends the data directly.  If necessary,
0213  * the ICE connection buffer is first flushed.
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  * Write pad bytes.  Used to force 32 or 64 bit alignment.
0226  * A maximum of 7 pad bytes can be specified.
0227  */
0228 
0229 #define IceWritePad(_iceConn, _bytes) \
0230 { \
0231     char _dummy[7] = { 0 }; \
0232     IceWriteData (_iceConn, (_bytes), _dummy); \
0233 }
0234 
0235 
0236 /*
0237  * Macros for reading messages.
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  * Read pad bytes (for 32 or 64 bit alignment).
0295  * A maximum of 7 pad bytes can be specified.
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 /* _ICEMSG_H_ */