jpayne@69: /****************************************************************************** jpayne@69: jpayne@69: jpayne@69: Copyright 1993, 1998 The Open Group jpayne@69: jpayne@69: Permission to use, copy, modify, distribute, and sell this software and its jpayne@69: documentation for any purpose is hereby granted without fee, provided that jpayne@69: the above copyright notice appear in all copies and that both that jpayne@69: copyright notice and this permission notice appear in supporting jpayne@69: documentation. jpayne@69: jpayne@69: The above copyright notice and this permission notice shall be included in jpayne@69: all copies or substantial portions of the Software. jpayne@69: jpayne@69: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR jpayne@69: IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, jpayne@69: FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE jpayne@69: OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN jpayne@69: AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN jpayne@69: CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. jpayne@69: jpayne@69: Except as contained in this notice, the name of The Open Group shall not be jpayne@69: used in advertising or otherwise to promote the sale, use or other dealings jpayne@69: in this Software without prior written authorization from The Open Group. jpayne@69: jpayne@69: Author: Ralph Mor, X Consortium jpayne@69: ******************************************************************************/ jpayne@69: jpayne@69: #ifndef _ICEMSG_H_ jpayne@69: #define _ICEMSG_H_ jpayne@69: jpayne@69: #include jpayne@69: jpayne@69: #include jpayne@69: jpayne@69: #include jpayne@69: #if !defined(__cplusplus) && !defined(static_assert) jpayne@69: #define static_assert(cond, msg) /* skip for non-C11 compilers */ jpayne@69: #endif jpayne@69: jpayne@69: _XFUNCPROTOBEGIN jpayne@69: jpayne@69: /* jpayne@69: * Function prototypes for internal ICElib functions jpayne@69: */ jpayne@69: jpayne@69: extern Status _IceRead ( jpayne@69: IceConn /* iceConn */, jpayne@69: unsigned long /* nbytes */, jpayne@69: char * /* ptr */ jpayne@69: ); jpayne@69: jpayne@69: extern void _IceReadSkip ( jpayne@69: IceConn /* iceConn */, jpayne@69: unsigned long /* nbytes */ jpayne@69: ); jpayne@69: jpayne@69: extern void _IceWrite ( jpayne@69: IceConn /* iceConn */, jpayne@69: unsigned long /* nbytes */, jpayne@69: char * /* ptr */ jpayne@69: ); jpayne@69: jpayne@69: jpayne@69: extern void _IceErrorBadMinor ( jpayne@69: IceConn /* iceConn */, jpayne@69: int /* majorOpcode */, jpayne@69: int /* offendingMinor */, jpayne@69: int /* severity */ jpayne@69: ); jpayne@69: jpayne@69: extern void _IceErrorBadState ( jpayne@69: IceConn /* iceConn */, jpayne@69: int /* majorOpcode */, jpayne@69: int /* offendingMinor */, jpayne@69: int /* severity */ jpayne@69: ); jpayne@69: jpayne@69: extern void _IceErrorBadLength ( jpayne@69: IceConn /* iceConn */, jpayne@69: int /* majorOpcode */, jpayne@69: int /* offendingMinor */, jpayne@69: int /* severity */ jpayne@69: ); jpayne@69: jpayne@69: extern void _IceErrorBadValue ( jpayne@69: IceConn /* iceConn */, jpayne@69: int /* majorOpcode */, jpayne@69: int /* offendingMinor */, jpayne@69: int /* offset */, jpayne@69: int /* length */, jpayne@69: IcePointer /* value */ jpayne@69: ); jpayne@69: jpayne@69: extern IcePoAuthStatus _IcePoMagicCookie1Proc ( jpayne@69: IceConn /* iceConn */, jpayne@69: IcePointer * /* authStatePtr */, jpayne@69: Bool /* cleanUp */, jpayne@69: Bool /* swap */, jpayne@69: int /* authDataLen */, jpayne@69: IcePointer /* authData */, jpayne@69: int * /* replyDataLenRet */, jpayne@69: IcePointer * /* replyDataRet */, jpayne@69: char ** /* errorStringRet */ jpayne@69: ); jpayne@69: jpayne@69: extern IcePaAuthStatus _IcePaMagicCookie1Proc ( jpayne@69: IceConn /* iceConn */, jpayne@69: IcePointer * /* authStatePtr */, jpayne@69: Bool /* swap */, jpayne@69: int /* authDataLen */, jpayne@69: IcePointer /* authData */, jpayne@69: int * /* replyDataLenRet */, jpayne@69: IcePointer * /* replyDataRet */, jpayne@69: char ** /* errorStringRet */ jpayne@69: ); jpayne@69: jpayne@69: jpayne@69: /* jpayne@69: * Macro to check if IO operations are valid on an ICE connection. jpayne@69: */ jpayne@69: jpayne@69: #define IceValidIO(_iceConn) _iceConn->io_ok jpayne@69: jpayne@69: jpayne@69: /* jpayne@69: * Macros for writing messages. jpayne@69: */ jpayne@69: jpayne@69: #define IceGetHeader(_iceConn, _major, _minor, _headerSize, _msgType, _pMsg) \ jpayne@69: do { \ jpayne@69: static_assert(_headerSize <= 1024, \ jpayne@69: "Header size larger than ICE_OUTBUFSIZE"); \ jpayne@69: if ((_iceConn->outbufptr + _headerSize) > _iceConn->outbufmax) \ jpayne@69: IceFlush (_iceConn); \ jpayne@69: _pMsg = (_msgType *) _iceConn->outbufptr; \ jpayne@69: _pMsg->majorOpcode = _major; \ jpayne@69: _pMsg->minorOpcode = _minor; \ jpayne@69: _pMsg->length = (_headerSize - SIZEOF (iceMsg)) >> 3; \ jpayne@69: _iceConn->outbufptr += _headerSize; \ jpayne@69: _iceConn->send_sequence++; \ jpayne@69: } while (0) jpayne@69: jpayne@69: #define IceGetHeaderExtra(_iceConn, _major, _minor, _headerSize, _extra, _msgType, _pMsg, _pData) \ jpayne@69: do { \ jpayne@69: static_assert(_headerSize <= 1024, \ jpayne@69: "Header size larger than ICE_OUTBUFSIZE"); \ jpayne@69: if ((_iceConn->outbufptr + \ jpayne@69: _headerSize + ((_extra) << 3)) > _iceConn->outbufmax) \ jpayne@69: IceFlush (_iceConn); \ jpayne@69: _pMsg = (_msgType *) _iceConn->outbufptr; \ jpayne@69: _iceConn->outbufptr += _headerSize; \ jpayne@69: if ((_iceConn->outbufptr + ((_extra) << 3)) <= _iceConn->outbufmax) { \ jpayne@69: _pData = _iceConn->outbufptr; \ jpayne@69: _iceConn->outbufptr += ((_extra) << 3); \ jpayne@69: } \ jpayne@69: else \ jpayne@69: _pData = NULL; \ jpayne@69: _pMsg->majorOpcode = _major; \ jpayne@69: _pMsg->minorOpcode = _minor; \ jpayne@69: _pMsg->length = ((_headerSize - SIZEOF (iceMsg)) >> 3) + (_extra); \ jpayne@69: _iceConn->send_sequence++; \ jpayne@69: } while (0) jpayne@69: jpayne@69: #define IceSimpleMessage(_iceConn, _major, _minor) \ jpayne@69: { \ jpayne@69: iceMsg *_pMsg; \ jpayne@69: IceGetHeader (_iceConn, _major, _minor, SIZEOF (iceMsg), iceMsg, _pMsg); \ jpayne@69: } jpayne@69: jpayne@69: #define IceErrorHeader(_iceConn, _offendingMajorOpcode, _offendingMinorOpcode, _offendingSequenceNum, _severity, _errorClass, _dataLength) \ jpayne@69: { \ jpayne@69: iceErrorMsg *_pMsg; \ jpayne@69: \ jpayne@69: IceGetHeader (_iceConn, _offendingMajorOpcode, ICE_Error, \ jpayne@69: SIZEOF (iceErrorMsg), iceErrorMsg, _pMsg); \ jpayne@69: _pMsg->length += (_dataLength); \ jpayne@69: _pMsg->offendingMinorOpcode = (CARD8) _offendingMinorOpcode; \ jpayne@69: _pMsg->severity = (CARD8) _severity; \ jpayne@69: _pMsg->offendingSequenceNum = (CARD32) _offendingSequenceNum; \ jpayne@69: _pMsg->errorClass = (CARD16) _errorClass; \ jpayne@69: } jpayne@69: jpayne@69: jpayne@69: /* jpayne@69: * Write data into the ICE output buffer. jpayne@69: */ jpayne@69: jpayne@69: #define IceWriteData(_iceConn, _bytes, _data) \ jpayne@69: { \ jpayne@69: if ((_iceConn->outbufptr + (_bytes)) > _iceConn->outbufmax) \ jpayne@69: { \ jpayne@69: IceFlush (_iceConn); \ jpayne@69: _IceWrite (_iceConn, (unsigned long) (_bytes), _data); \ jpayne@69: } \ jpayne@69: else \ jpayne@69: { \ jpayne@69: memcpy (_iceConn->outbufptr, _data, _bytes); \ jpayne@69: _iceConn->outbufptr += (_bytes); \ jpayne@69: } \ jpayne@69: } jpayne@69: jpayne@69: #define IceWriteData16(_iceConn, _bytes, _data) \ jpayne@69: IceWriteData (_iceConn, _bytes, (char *) _data) jpayne@69: jpayne@69: #define IceWriteData32(_iceConn, _bytes, _data) \ jpayne@69: IceWriteData (_iceConn, _bytes, (char *) _data) jpayne@69: jpayne@69: jpayne@69: /* jpayne@69: * The IceSendData macro bypasses copying the data to the jpayne@69: * ICE connection buffer and sends the data directly. If necessary, jpayne@69: * the ICE connection buffer is first flushed. jpayne@69: */ jpayne@69: jpayne@69: #define IceSendData(_iceConn, _bytes, _data) \ jpayne@69: { \ jpayne@69: if (_iceConn->outbufptr > _iceConn->outbuf) \ jpayne@69: IceFlush (_iceConn); \ jpayne@69: _IceWrite (_iceConn, (unsigned long) (_bytes), _data); \ jpayne@69: } jpayne@69: jpayne@69: jpayne@69: /* jpayne@69: * Write pad bytes. Used to force 32 or 64 bit alignment. jpayne@69: * A maximum of 7 pad bytes can be specified. jpayne@69: */ jpayne@69: jpayne@69: #define IceWritePad(_iceConn, _bytes) \ jpayne@69: { \ jpayne@69: char _dummy[7] = { 0 }; \ jpayne@69: IceWriteData (_iceConn, (_bytes), _dummy); \ jpayne@69: } jpayne@69: jpayne@69: jpayne@69: /* jpayne@69: * Macros for reading messages. jpayne@69: */ jpayne@69: jpayne@69: #define IceReadCompleteMessage(_iceConn, _headerSize, _msgType, _pMsg, _pData)\ jpayne@69: { \ jpayne@69: unsigned long _bytes; \ jpayne@69: IceReadMessageHeader (_iceConn, _headerSize, _msgType, _pMsg); \ jpayne@69: _bytes = (_pMsg->length << 3) - (_headerSize - SIZEOF (iceMsg)); \ jpayne@69: if ((_iceConn->inbufmax - _iceConn->inbufptr) >= _bytes) \ jpayne@69: { \ jpayne@69: _IceRead (_iceConn, _bytes, _iceConn->inbufptr); \ jpayne@69: _pData = _iceConn->inbufptr; \ jpayne@69: _iceConn->inbufptr += _bytes; \ jpayne@69: } \ jpayne@69: else \ jpayne@69: { \ jpayne@69: _pData = malloc (_bytes); \ jpayne@69: if (_pData) \ jpayne@69: _IceRead (_iceConn, _bytes, _pData); \ jpayne@69: else \ jpayne@69: _IceReadSkip (_iceConn, _bytes); \ jpayne@69: } \ jpayne@69: } jpayne@69: jpayne@69: #define IceDisposeCompleteMessage(_iceConn, _pData) \ jpayne@69: if ((char *) _pData < _iceConn->inbuf || \ jpayne@69: (char *) _pData >= _iceConn->inbufmax) \ jpayne@69: free (_pData); jpayne@69: jpayne@69: jpayne@69: #define IceReadSimpleMessage(_iceConn, _msgType, _pMsg) \ jpayne@69: _pMsg = (_msgType *) (_iceConn->inbuf); jpayne@69: jpayne@69: #define IceReadMessageHeader(_iceConn, _headerSize, _msgType, _pMsg) \ jpayne@69: { \ jpayne@69: _IceRead (_iceConn, \ jpayne@69: (unsigned long) (_headerSize - SIZEOF (iceMsg)), \ jpayne@69: _iceConn->inbufptr); \ jpayne@69: _pMsg = (_msgType *) (_iceConn->inbuf); \ jpayne@69: _iceConn->inbufptr += (_headerSize - SIZEOF (iceMsg)); \ jpayne@69: } jpayne@69: jpayne@69: #define IceReadData(_iceConn, _bytes, _pData) \ jpayne@69: _IceRead (_iceConn, (unsigned long) (_bytes), (char *) _pData); \ jpayne@69: jpayne@69: #define IceReadData16(_iceConn, _swap, _bytes, _pData) \ jpayne@69: { \ jpayne@69: _IceRead (_iceConn, (unsigned long) (_bytes), (char *) _pData); \ jpayne@69: } jpayne@69: jpayne@69: #define IceReadData32(_iceConn, _swap, _bytes, _pData) \ jpayne@69: { \ jpayne@69: _IceRead (_iceConn, (unsigned long) (_bytes), (char *) _pData); \ jpayne@69: } jpayne@69: jpayne@69: jpayne@69: /* jpayne@69: * Read pad bytes (for 32 or 64 bit alignment). jpayne@69: * A maximum of 7 pad bytes can be specified. jpayne@69: */ jpayne@69: jpayne@69: #define IceReadPad(_iceConn, _bytes) \ jpayne@69: { \ jpayne@69: char _dummy[7]; \ jpayne@69: _IceRead (_iceConn, (unsigned long) (_bytes), _dummy); \ jpayne@69: } jpayne@69: jpayne@69: _XFUNCPROTOEND jpayne@69: jpayne@69: #endif /* _ICEMSG_H_ */