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