pmint.h revision cf2f63c2
15c10afb9Smrg 25c10afb9Smrg/* 35c10afb9SmrgCopyright 1996, 1998 The Open Group 45c10afb9Smrg 55c10afb9SmrgPermission to use, copy, modify, distribute, and sell this software and its 65c10afb9Smrgdocumentation for any purpose is hereby granted without fee, provided that 75c10afb9Smrgthe above copyright notice appear in all copies and that both that 85c10afb9Smrgcopyright notice and this permission notice appear in supporting 95c10afb9Smrgdocumentation. 105c10afb9Smrg 115c10afb9SmrgThe above copyright notice and this permission notice shall be included 125c10afb9Smrgin all copies or substantial portions of the Software. 135c10afb9Smrg 145c10afb9SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 155c10afb9SmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 165c10afb9SmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 175c10afb9SmrgIN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 185c10afb9SmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 195c10afb9SmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 205c10afb9SmrgOTHER DEALINGS IN THE SOFTWARE. 215c10afb9Smrg 225c10afb9SmrgExcept as contained in this notice, the name of The Open Group shall 235c10afb9Smrgnot be used in advertising or otherwise to promote the sale, use or 245c10afb9Smrgother dealings in this Software without prior written authorization 255c10afb9Smrgfrom The Open Group. 265c10afb9Smrg*/ 275c10afb9Smrg 285c10afb9Smrg#ifdef HAVE_CONFIG_H 295c10afb9Smrg# include "xconfig.h" 305c10afb9Smrg#endif 315c10afb9Smrg 325c10afb9Smrg#include <stdio.h> 335c10afb9Smrg#include <X11/Xos.h> 345c10afb9Smrg#include <X11/Xfuncs.h> 355c10afb9Smrg#include <X11/Xmd.h> 365c10afb9Smrg#include <X11/ICE/ICElib.h> 375c10afb9Smrg#include <X11/Intrinsic.h> 385c10afb9Smrg 395c10afb9Smrg#define Status int 405c10afb9Smrg#define Bool int 415c10afb9Smrg#define True 1 425c10afb9Smrg#define False 0 435c10afb9Smrg 44cf2f63c2Smrgextern const char *PM_VENDOR_STRING; 45cf2f63c2Smrgextern const char *PM_VENDOR_RELEASE; 465c10afb9Smrg 475c10afb9Smrgextern int verbose; 485c10afb9Smrg 495c10afb9Smrgtypedef struct { 505c10afb9Smrg IceConn iceConn; 515c10afb9Smrg int pmOpcode; 525c10afb9Smrg int proto_major_version; 535c10afb9Smrg int proto_minor_version; 545c10afb9Smrg char *vendor; 555c10afb9Smrg char *release; 565c10afb9Smrg} PMconn; 575c10afb9Smrg 585c10afb9Smrg 595c10afb9Smrg 605c10afb9Smrgextern void ForwardRequest ( PMconn *requestor, char *serviceName, char *serverAddress, char *hostAddress, char *startOptions, int authLen, char *authName, char *authData ); 615c10afb9Smrgextern int HostBasedAuthProc ( char *hostname ); 625c10afb9Smrgextern int InitWatchProcs ( XtAppContext appContext ); 635c10afb9Smrgextern void InstallIOErrorHandler ( void ); 645c10afb9Smrgextern int main ( int argc, char **argv ); 655c10afb9Smrgextern void MyIoErrorHandler ( IceConn ice_conn ); 665c10afb9Smrgextern void NewConnectionXtProc ( XtPointer client_data, int *source, XtInputId *id ); 675c10afb9Smrgextern void PMReplyProcessMessages ( IceConn iceConn, IcePointer clientData, int opcode, unsigned long length, int swap ); 685c10afb9Smrgextern void PMSetupProcessMessages ( IceConn iceConn, IcePointer clientData, int opcode, unsigned long length, int swap, IceReplyWaitInfo *replyWait, int *replyReadyRet ); 69cf2f63c2Smrgextern void SendGetProxyAddrReply ( PMconn *requestor, int status, const char *addr, const char *error ); 705c10afb9Smrgextern void SetCloseOnExec ( int fd ); 71cf2f63c2Smrgextern void Usage ( void ) _X_NORETURN; 725c10afb9Smrgextern void _XtIceWatchProc ( IceConn ice_conn, IcePointer client_data, int opening, IcePointer *watch_data ); 735c10afb9Smrgextern void _XtProcessIceMsgProc ( XtPointer client_data, int *source, XtInputId *id ); 745c10afb9Smrg 755c10afb9Smrg 765c10afb9Smrg 775c10afb9Smrg/* 785c10afb9Smrg * Pad to a 64 bit boundary 795c10afb9Smrg */ 805c10afb9Smrg 815c10afb9Smrg#define PAD64(_bytes) ((8 - ((unsigned int) (_bytes) % 8)) % 8) 825c10afb9Smrg 835c10afb9Smrg#define PADDED_BYTES64(_bytes) (_bytes + PAD64 (_bytes)) 845c10afb9Smrg 855c10afb9Smrg 865c10afb9Smrg/* 875c10afb9Smrg * Number of 8 byte units in _bytes. 885c10afb9Smrg */ 895c10afb9Smrg 905c10afb9Smrg#define WORD64COUNT(_bytes) (((unsigned int) ((_bytes) + 7)) >> 3) 915c10afb9Smrg 925c10afb9Smrg 935c10afb9Smrg/* 945c10afb9Smrg * Compute the number of bytes for a STRING representation 955c10afb9Smrg */ 965c10afb9Smrg 975c10afb9Smrg#define STRING_BYTES(_str) (2 + (_str ? strlen (_str) : 0) + \ 985c10afb9Smrg PAD64 (2 + (_str ? strlen (_str) : 0))) 995c10afb9Smrg 1005c10afb9Smrg 1015c10afb9Smrg 1025c10afb9Smrg#define SKIP_STRING(_pBuf, _swap) \ 1035c10afb9Smrg{ \ 1045c10afb9Smrg CARD16 _len; \ 1055c10afb9Smrg EXTRACT_CARD16 (_pBuf, _swap, _len); \ 1065c10afb9Smrg _pBuf += _len; \ 1075c10afb9Smrg if (PAD64 (2 + _len)) \ 1085c10afb9Smrg _pBuf += PAD64 (2 + _len); \ 1095c10afb9Smrg} 1105c10afb9Smrg 1115c10afb9Smrg/* 1125c10afb9Smrg * STORE macros 1135c10afb9Smrg */ 1145c10afb9Smrg 1155c10afb9Smrg#define STORE_CARD16(_pBuf, _val) \ 1165c10afb9Smrg{ \ 1175c10afb9Smrg *((CARD16 *) _pBuf) = _val; \ 1185c10afb9Smrg _pBuf += 2; \ 1195c10afb9Smrg} 1205c10afb9Smrg 1215c10afb9Smrg#define STORE_STRING(_pBuf, _string) \ 1225c10afb9Smrg{ \ 1235c10afb9Smrg int _len = _string ? strlen (_string) : 0; \ 1245c10afb9Smrg STORE_CARD16 (_pBuf, _len); \ 1255c10afb9Smrg if (_len) { \ 1265c10afb9Smrg memcpy (_pBuf, _string, _len); \ 1275c10afb9Smrg _pBuf += _len; \ 1285c10afb9Smrg } \ 1295c10afb9Smrg if (PAD64 (2 + _len)) \ 1305c10afb9Smrg _pBuf += PAD64 (2 + _len); \ 1315c10afb9Smrg} 1325c10afb9Smrg 1335c10afb9Smrg 1345c10afb9Smrg/* 1355c10afb9Smrg * EXTRACT macros 1365c10afb9Smrg */ 1375c10afb9Smrg 1385c10afb9Smrg#define EXTRACT_CARD16(_pBuf, _swap, _val) \ 1395c10afb9Smrg{ \ 1405c10afb9Smrg _val = *((CARD16 *) _pBuf); \ 1415c10afb9Smrg _pBuf += 2; \ 1425c10afb9Smrg if (_swap) \ 1435c10afb9Smrg _val = lswaps (_val); \ 1445c10afb9Smrg} 1455c10afb9Smrg 1465c10afb9Smrg#define EXTRACT_STRING(_pBuf, _swap, _string) \ 1475c10afb9Smrg{ \ 1485c10afb9Smrg CARD16 _len; \ 1495c10afb9Smrg EXTRACT_CARD16 (_pBuf, _swap, _len); \ 150cf2f63c2Smrg _string = malloc (_len + 1); \ 1515c10afb9Smrg memcpy (_string, _pBuf, _len); \ 1525c10afb9Smrg _string[_len] = '\0'; \ 1535c10afb9Smrg _pBuf += _len; \ 1545c10afb9Smrg if (PAD64 (2 + _len)) \ 1555c10afb9Smrg _pBuf += PAD64 (2 + _len); \ 1565c10afb9Smrg} 1575c10afb9Smrg 1585c10afb9Smrg 1595c10afb9Smrg/* 1605c10afb9Smrg * Byte swapping 1615c10afb9Smrg */ 1625c10afb9Smrg 1635c10afb9Smrg/* byte swap a long literal */ 1645c10afb9Smrg#define lswapl(_val) ((((_val) & 0xff) << 24) |\ 1655c10afb9Smrg (((_val) & 0xff00) << 8) |\ 1665c10afb9Smrg (((_val) & 0xff0000) >> 8) |\ 1675c10afb9Smrg (((_val) >> 24) & 0xff)) 1685c10afb9Smrg 1695c10afb9Smrg/* byte swap a short literal */ 1705c10afb9Smrg#define lswaps(_val) ((((_val) & 0xff) << 8) | (((_val) >> 8) & 0xff)) 1715c10afb9Smrg 1725c10afb9Smrg 1735c10afb9Smrg#define CHECK_AT_LEAST_SIZE(_iceConn, _majorOp, _minorOp, _expected_len, _actual_len, _severity) \ 1745c10afb9Smrg if ((((_actual_len) - SIZEOF (iceMsg)) >> 3) > _expected_len) \ 1755c10afb9Smrg { \ 1765c10afb9Smrg _IceErrorBadLength (_iceConn, _majorOp, _minorOp, _severity); \ 1775c10afb9Smrg return; \ 1785c10afb9Smrg } 1795c10afb9Smrg 1805c10afb9Smrg 1815c10afb9Smrg#define CHECK_COMPLETE_SIZE(_iceConn, _majorOp, _minorOp, _expected_len, _actual_len, _pStart, _severity) \ 1825c10afb9Smrg if (((PADDED_BYTES64((_actual_len)) - SIZEOF (iceMsg)) >> 3) \ 1835c10afb9Smrg != _expected_len) \ 1845c10afb9Smrg { \ 1855c10afb9Smrg _IceErrorBadLength (_iceConn, _majorOp, _minorOp, _severity); \ 1865c10afb9Smrg IceDisposeCompleteMessage (iceConn, _pStart); \ 1875c10afb9Smrg return; \ 1885c10afb9Smrg } 189