diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | ce4a32fe52ef09d8f5ff1dd22c001110902b60a2 (patch) | |
tree | 5ac38a06f3dde268dc7927dc155896926aaf7012 /dcop/KDE-ICE | |
download | tdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.tar.gz tdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'dcop/KDE-ICE')
36 files changed, 15094 insertions, 0 deletions
diff --git a/dcop/KDE-ICE/ICE-def.cpp b/dcop/KDE-ICE/ICE-def.cpp new file mode 100644 index 000000000..df1d9ea58 --- /dev/null +++ b/dcop/KDE-ICE/ICE-def.cpp @@ -0,0 +1,66 @@ +LIBRARY ICE +VERSION LIBRARY_VERSION +EXPORTS + IceAcceptConnection + IceAddConnectionWatch + IceAllocScratch + IceAppLockConn + IceAppUnlockConn + IceAuthFileName + IceCheckShutdownNegotiation + IceCloseConnection + IceComposeNetworkIdList + IceConnectionNumber + IceConnectionStatus + IceConnectionString + IceFlush + IceFreeAuthFileEntry + IceFreeListenObjs + IceGenerateMagicCookie + IceGetAuthFileEntry + IceGetConnectionContext + IceGetInBufSize + IceGetListenConnectionNumber + IceGetListenConnectionString + IceGetOutBufSize + IceInitThreads + IceLastReceivedSequenceNumber + IceLastSentSequenceNumber + IceListenForConnections + IceLockAuthFile + IceOpenConnection + IcePing + IceProcessMessages + IceProtocolRevision + IceProtocolSetup + IceProtocolShutdown + IceProtocolVersion + IceReadAuthFileEntry + IceRegisterForProtocolReply + IceRegisterForProtocolSetup + IceRelease + IceRemoveConnectionWatch + IceSetErrorHandler + IceSetHostBasedAuthProc + IceSetIOErrorHandler + IceSetPaAuthData + IceSetShutdownNegotiation + IceSwapping + IceUnlockAuthFile + IceVendor + IceWriteAuthFileEntry + _IceTransGetPeerAddr + _IceTransGetPeerNetworkId + _IceErrorBadMinor + _IceErrorBadLength + _IceErrorBadState + _IceErrorBadValue + _IcePaMagicCookie1Proc + _IcePoMagicCookie1Proc + _IceRead + _IceReadSkip + _IceWrite + IceListenForWellKnownConnections + _IceTransGetHostname +/* $Xorg: ICE-def.cpp,v 1.3 2000/08/21 16:42:31 coskrey Exp $ */ +/* $XFree86: xc/lib/ICE/ICE-def.cpp,v 1.4 2001/01/17 19:41:29 dawes Exp $ */ diff --git a/dcop/KDE-ICE/ICE.h b/dcop/KDE-ICE/ICE.h new file mode 100644 index 000000000..f7ede88d1 --- /dev/null +++ b/dcop/KDE-ICE/ICE.h @@ -0,0 +1,98 @@ +/* $Xorg: ICE.h,v 1.3 2000/08/17 19:44:08 cpqbld Exp $ */ +/****************************************************************************** + + +Copyright 1993, 1998 The Open Group + +All Rights Reserved. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + +Author: Ralph Mor, X Consortium + +******************************************************************************/ + +#ifndef _ICE_H_ +#define _ICE_H_ + +/* + * Protocol Version + */ + +#define IceProtoMajor 1 +#define IceProtoMinor 0 + + +/* + * Byte Order + */ + +#define IceLSBfirst 0 +#define IceMSBfirst 1 + + +/* + * ICE minor opcodes + */ + +#define ICE_Error 0 +#define ICE_ByteOrder 1 +#define ICE_ConnectionSetup 2 +#define ICE_AuthRequired 3 +#define ICE_AuthReply 4 +#define ICE_AuthNextPhase 5 +#define ICE_ConnectionReply 6 +#define ICE_ProtocolSetup 7 +#define ICE_ProtocolReply 8 +#define ICE_Ping 9 +#define ICE_PingReply 10 +#define ICE_WantToClose 11 +#define ICE_NoClose 12 + + +/* + * Error severity + */ + +#define IceCanContinue 0 +#define IceFatalToProtocol 1 +#define IceFatalToConnection 2 + + +/* + * ICE error classes that are common to all protocols + */ + +#define IceBadMinor 0x8000 +#define IceBadState 0x8001 +#define IceBadLength 0x8002 +#define IceBadValue 0x8003 + + +/* + * ICE error classes that are specific to the ICE protocol + */ + +#define IceBadMajor 0 +#define IceNoAuth 1 +#define IceNoVersion 2 +#define IceSetupFailed 3 +#define IceAuthRejected 4 +#define IceAuthFailed 5 +#define IceProtocolDuplicate 6 +#define IceMajorOpcodeDuplicate 7 +#define IceUnknownProtocol 8 + +#endif /* _ICE_H_ */ diff --git a/dcop/KDE-ICE/ICEconn.h b/dcop/KDE-ICE/ICEconn.h new file mode 100644 index 000000000..85dd7ca10 --- /dev/null +++ b/dcop/KDE-ICE/ICEconn.h @@ -0,0 +1,247 @@ +/* $Xorg: ICEconn.h,v 1.4 2000/08/17 19:44:10 cpqbld Exp $ */ +/****************************************************************************** + + +Copyright 1993, 1998 The Open Group + +All Rights Reserved. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + +Author: Ralph Mor, X Consortium +******************************************************************************/ + +#ifndef _ICECONN_H_ +#define _ICECONN_H_ + +#include "KDE-ICE/ICElib.h" + +/* + * Data structures for ICE connection object + */ + +typedef struct _IceSavedReplyWait { + IceReplyWaitInfo *reply_wait; + Bool reply_ready; + struct _IceSavedReplyWait *next; +} _IceSavedReplyWait; + +typedef struct _IcePingWait { + IcePingReplyProc ping_reply_proc; + IcePointer client_data; + struct _IcePingWait *next; +} _IcePingWait; + +typedef struct { + char *vendor; + char *release; + int version_count; + IcePoVersionRec *version_recs; + int auth_count; + char **auth_names; + IcePoAuthProc *auth_procs; + IceIOErrorProc io_error_proc; +} _IcePoProtocol; + +typedef struct { + char *vendor; + char *release; + int version_count; + IcePaVersionRec *version_recs; + IceProtocolSetupProc protocol_setup_proc; + IceProtocolActivateProc protocol_activate_proc; + int auth_count; + char **auth_names; + IcePaAuthProc *auth_procs; + IceHostBasedAuthProc host_based_auth_proc; + IceIOErrorProc io_error_proc; +} _IcePaProtocol; + +typedef struct { + char *protocol_name; + _IcePoProtocol *orig_client; + _IcePaProtocol *accept_client; +} _IceProtocol; + +typedef struct { + Bool in_use; + int my_opcode; + _IceProtocol *protocol; + IcePointer client_data; + Bool accept_flag; + union { + IcePaProcessMsgProc accept_client; + IcePoProcessMsgProc orig_client; + } process_msg_proc; +} _IceProcessMsgInfo; + +typedef struct { + int his_version_index; + int my_version_index; + char *his_vendor; + char *his_release; + char my_auth_index; + IcePointer my_auth_state; + Bool must_authenticate; +} _IceConnectToMeInfo; + +typedef struct { + int his_opcode; + int my_opcode; + int his_version_index; + int my_version_index; + char *his_vendor; + char *his_release; + char my_auth_index; + IcePointer my_auth_state; + Bool must_authenticate; +} _IceProtoSetupToMeInfo; + +typedef struct { + Bool auth_active; + char my_auth_index; + IcePointer my_auth_state; +} _IceConnectToYouInfo; + +typedef struct { + int my_opcode; + int my_auth_count; + int *my_auth_indices; + Bool auth_active; + char my_auth_index; + IcePointer my_auth_state; +} _IceProtoSetupToYouInfo; + + +struct _IceConn { + + unsigned int io_ok : 1; /* did an IO error occur? */ + unsigned int swap : 1; /* do we need to swap on reads? */ + unsigned int waiting_for_byteorder : 1; /* waiting for a ByteOrder msg? */ + unsigned int skip_want_to_close : 1; /* avoid shutdown negotiation? */ + unsigned int want_to_close : 1; /* did we send a WantToClose? */ + unsigned int free_asap : 1; /* free as soon as possible */ + unsigned int unused1 : 2; /* future use */ + unsigned int unused2 : 8; /* future use */ + + IceConnectStatus connection_status; /* pending, accepted, rejected */ + + unsigned char my_ice_version_index; /* which version are we using? */ + + struct _XtransConnInfo *trans_conn; /* transport connection object */ + unsigned long send_sequence; /* Sequence # of last msg sent */ + unsigned long receive_sequence; /* Sequence # of last msg received */ + + char *connection_string; /* network connection string */ + char *vendor; /* other client's vendor */ + char *release; /* other client's release */ + + char *inbuf; /* Input buffer starting address */ + char *inbufptr; /* Input buffer index pointer */ + char *inbufmax; /* Input buffer maximum+1 address */ + + char *outbuf; /* Output buffer starting address */ + char *outbufptr; /* Output buffer index pointer */ + char *outbufmax; /* Output buffer maximum+1 address */ + + char *scratch; /* scratch buffer */ + unsigned long scratch_size; /* scratch size */ + + int dispatch_level; /* IceProcessMessages dispatch level */ + + IcePointer context; /* context associated with caller + of IceOpenConnection */ + + /* + * Before we read a message, the major opcode of the message must be + * mapped to our corresponding major opcode (the two clients can use + * different opcodes for the same protocol). In order to save space, + * we keep track of the mininum and maximum major opcodes used by the + * other client. To get the information on how to process this message, + * we do the following... + * + * processMsgInfo = iceConn->process_msg_info[ + * message->majorOpcode - iceConn->his_min_opcode] + * + * Note that the number of elements in the iceConn->process_msg_info + * array is always (iceConn->his_max_opcode - iceConn->his_min_opcode + 1). + * We check process_msg_info->in_use to see if the opcode is being used. + */ + + _IceProcessMsgInfo *process_msg_info; + char his_min_opcode; /* [1..255] */ + char his_max_opcode; /* [1..255] */ + + + /* + * Number of times this iceConn was returned in IceOpenConnection + * or IceAcceptConnection. + */ + + unsigned char open_ref_count; + + + /* + * Number of active protocols. + */ + + unsigned char proto_ref_count; + + + /* + * If this ICE connection was created with IceAcceptConnection, + * the listen_obj field is set to the listen object. Otherwise, + * the listen_obj field is NULL. + */ + + IceListenObj listen_obj; + + + + + /* + * We need to keep track of all the replies we're waiting for. + * Check the comments in process.c for how this works. + */ + + _IceSavedReplyWait *saved_reply_waits; + + + /* + * We keep track of all Pings sent from the client. When the Ping reply + * arrives, we remove it from the list. + */ + + _IcePingWait *ping_waits; + + + /* + * Some state for a client doing a Connection/Protocol Setup + */ + + _IceConnectToYouInfo *connect_to_you; + _IceProtoSetupToYouInfo *protosetup_to_you; + + + /* + * Some state for a client receiving a Connection/Protocol Setup + */ + + _IceConnectToMeInfo *connect_to_me; + _IceProtoSetupToMeInfo *protosetup_to_me; + +}; + +#endif /* _ICECONN_H_ */ diff --git a/dcop/KDE-ICE/ICElib.h b/dcop/KDE-ICE/ICElib.h new file mode 100644 index 000000000..69c2c2228 --- /dev/null +++ b/dcop/KDE-ICE/ICElib.h @@ -0,0 +1,631 @@ +/* $XConsortium: ICElib.h /main/41 1996/11/29 13:30:19 swick $ */ +/* $XFree86: xc/lib/ICE/ICElib.h,v 3.1 1996/12/23 05:58:57 dawes Exp $ */ +/****************************************************************************** + + +Copyright (c) 1993 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from the X Consortium. + +Author: Ralph Mor, X Consortium +******************************************************************************/ + +#ifndef _ICELIB_H_ +#define _ICELIB_H_ + +#include <KDE-ICE/ICE.h> +#include <KDE-ICE/Xfuncproto.h> +#ifndef SIZEOF +#define _SIZEOF(x) sz_##x +#define SIZEOF(x) _SIZEOF(x) +#endif + +#define Bool int +#define Status int +#define True 1 +#define False 0 + +#if NeedFunctionPrototypes +typedef void *IcePointer; +#else +typedef char *IcePointer; +#endif + +typedef enum { + IcePoAuthHaveReply, + IcePoAuthRejected, + IcePoAuthFailed, + IcePoAuthDoneCleanup +} IcePoAuthStatus; + +typedef enum { + IcePaAuthContinue, + IcePaAuthAccepted, + IcePaAuthRejected, + IcePaAuthFailed +} IcePaAuthStatus; + +typedef enum { + IceConnectPending, + IceConnectAccepted, + IceConnectRejected, + IceConnectIOError +} IceConnectStatus; + +typedef enum { + IceProtocolSetupSuccess, + IceProtocolSetupFailure, + IceProtocolSetupIOError, + IceProtocolAlreadyActive +} IceProtocolSetupStatus; + +typedef enum { + IceAcceptSuccess, + IceAcceptFailure, + IceAcceptBadMalloc +} IceAcceptStatus; + +typedef enum { + IceClosedNow, + IceClosedASAP, + IceConnectionInUse, + IceStartedShutdownNegotiation +} IceCloseStatus; + +typedef enum { + IceProcessMessagesSuccess, + IceProcessMessagesIOError, + IceProcessMessagesConnectionClosed +} IceProcessMessagesStatus; + +typedef struct { + unsigned long sequence_of_request; + int major_opcode_of_request; + int minor_opcode_of_request; + IcePointer reply; +} IceReplyWaitInfo; + +typedef struct _IceConn *IceConn; +typedef struct _IceListenObj *IceListenObj; + +typedef void (*IceWatchProc) ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + IcePointer /* clientData */, + Bool /* opening */, + IcePointer * /* watchData */ +#endif +); + +typedef void (*IcePoProcessMsgProc) ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + IcePointer /* clientData */, + int /* opcode */, + unsigned long /* length */, + Bool /* swap */, + IceReplyWaitInfo * /* replyWait */, + Bool * /* replyReadyRet */ +#endif +); + +typedef void (*IcePaProcessMsgProc) ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + IcePointer /* clientData */, + int /* opcode */, + unsigned long /* length */, + Bool /* swap */ +#endif +); + +typedef struct { + int major_version; + int minor_version; + IcePoProcessMsgProc process_msg_proc; +} IcePoVersionRec; + +typedef struct { + int major_version; + int minor_version; + IcePaProcessMsgProc process_msg_proc; +} IcePaVersionRec; + +typedef IcePoAuthStatus (*IcePoAuthProc) ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + IcePointer * /* authStatePtr */, + Bool /* cleanUp */, + Bool /* swap */, + int /* authDataLen */, + IcePointer /* authData */, + int * /* replyDataLenRet */, + IcePointer * /* replyDataRet */, + char ** /* errorStringRet */ +#endif +); + +typedef IcePaAuthStatus (*IcePaAuthProc) ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + IcePointer * /* authStatePtr */, + Bool /* swap */, + int /* authDataLen */, + IcePointer /* authData */, + int * /* replyDataLenRet */, + IcePointer * /* replyDataRet */, + char ** /* errorStringRet */ +#endif +); + +typedef Bool (*IceHostBasedAuthProc) ( +#if NeedFunctionPrototypes + char * /* hostName */ +#endif +); + +typedef Status (*IceProtocolSetupProc) ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + int /* majorVersion */, + int /* minorVersion */, + char * /* vendor */, + char * /* release */, + IcePointer * /* clientDataRet */, + char ** /* failureReasonRet */ +#endif +); + +typedef void (*IceProtocolActivateProc) ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + IcePointer /* clientData */ +#endif +); + +typedef void (*IceWriteHandler) ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + unsigned long /* nbytes */, + char * /* ptr */ +#endif +); + +typedef void (*IceIOErrorProc) ( +#if NeedFunctionPrototypes + IceConn /* iceConn */ +#endif +); + +typedef void (*IcePingReplyProc) ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + IcePointer /* clientData */ +#endif +); + +typedef void (*IceErrorHandler) ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + Bool /* swap */, + int /* offendingMinorOpcode */, + unsigned long /* offendingSequence */, + int /* errorClass */, + int /* severity */, + IcePointer /* values */ +#endif +); + +typedef void (*IceIOErrorHandler) ( +#if NeedFunctionPrototypes + IceConn /* iceConn */ +#endif +); + + +/* + * Function prototypes + */ + +_XFUNCPROTOBEGIN + +#define IceRegisterForProtocolSetup KDE_IceRegisterForProtocolSetup + +extern int IceRegisterForProtocolSetup ( +#if NeedFunctionPrototypes + char * /* protocolName */, + char * /* vendor */, + char * /* release */, + int /* versionCount */, + IcePoVersionRec * /* versionRecs */, + int /* authCount */, + char ** /* authNames */, + IcePoAuthProc * /* authProcs */, + IceIOErrorProc /* IOErrorProc */ +#endif +); + +#define IceRegisterForProtocolReply KDE_IceRegisterForProtocolReply + +extern int IceRegisterForProtocolReply ( +#if NeedFunctionPrototypes + char * /* protocolName */, + char * /* vendor */, + char * /* release */, + int /* versionCount */, + IcePaVersionRec * /* versionRecs */, + int /* authCount */, + char ** /* authNames */, + IcePaAuthProc * /* authProcs */, + IceHostBasedAuthProc /* hostBasedAuthProc */, + IceProtocolSetupProc /* protocolSetupProc */, + IceProtocolActivateProc /* protocolActivateProc */, + IceIOErrorProc /* IOErrorProc */ +#endif +); + +#define IceOpenConnection KDE_IceOpenConnection + +extern IceConn IceOpenConnection ( +#if NeedFunctionPrototypes + char * /* networkIdsList */, + IcePointer /* context */, + Bool /* mustAuthenticate */, + int /* majorOpcodeCheck */, + int /* errorLength */, + char * /* errorStringRet */ +#endif +); + +#define IceGetConnectionContext KDE_IceGetConnectionContext + +extern IcePointer IceGetConnectionContext ( +#if NeedFunctionPrototypes + IceConn /* iceConn */ +#endif +); + +#define IceListenForConnections KDE_IceListenForConnections + +extern Status IceListenForConnections ( +#if NeedFunctionPrototypes + int * /* countRet */, + IceListenObj ** /* listenObjsRet */, + int /* errorLength */, + char * /* errorStringRet */ +#endif +); + +#define IceListenForWellKnownConnections KDE_IceListenForWellKnownConnections + +extern Status IceListenForWellKnownConnections ( +#if NeedFunctionPrototypes + char * /* port */, + int * /* countRet */, + IceListenObj ** /* listenObjsRet */, + int /* errorLength */, + char * /* errorStringRet */ +#endif +); + +#define IceGetListenConnectionNumber KDE_IceGetListenConnectionNumber + +extern int IceGetListenConnectionNumber ( +#if NeedFunctionPrototypes + IceListenObj /* listenObj */ +#endif +); + +#define IceGetListenConnectionString KDE_IceGetListenConnectionString + +extern char *IceGetListenConnectionString ( +#if NeedFunctionPrototypes + IceListenObj /* listenObj */ +#endif +); + +#define IceComposeNetworkIdList KDE_IceComposeNetworkIdList + +extern char *IceComposeNetworkIdList ( +#if NeedFunctionPrototypes + int /* count */, + IceListenObj * /* listenObjs */ +#endif +); + +#define IceFreeListenObjs KDE_IceFreeListenObjs + +extern void IceFreeListenObjs ( +#if NeedFunctionPrototypes + int /* count */, + IceListenObj * /* listenObjs */ +#endif +); + +#define IceSetHostBasedAuthProc KDE_IceSetHostBasedAuthProc + +extern void IceSetHostBasedAuthProc ( +#if NeedFunctionPrototypes + IceListenObj /* listenObj */, + IceHostBasedAuthProc /* hostBasedAuthProc */ +#endif +); + +#define IceAcceptConnection KDE_IceAcceptConnection + +extern IceConn IceAcceptConnection ( +#if NeedFunctionPrototypes + IceListenObj /* listenObj */, + IceAcceptStatus * /* statusRet */ +#endif +); + +#define IceSetShutdownNegotiation KDE_IceSetShutdownNegotiation + +extern void IceSetShutdownNegotiation ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + Bool /* negotiate */ +#endif +); + +#define IceCheckShutdownNegotiation KDE_IceCheckShutdownNegotiation + +extern Bool IceCheckShutdownNegotiation ( +#if NeedFunctionPrototypes + IceConn /* iceConn */ +#endif +); + +#define IceCloseConnection KDE_IceCloseConnection + +extern IceCloseStatus IceCloseConnection ( +#if NeedFunctionPrototypes + IceConn /* iceConn */ +#endif +); + +#define IceAddConnectionWatch KDE_IceAddConnectionWatch + +extern Status IceAddConnectionWatch ( +#if NeedFunctionPrototypes + IceWatchProc /* watchProc */, + IcePointer /* clientData */ +#endif +); + +#define IceRemoveConnectionWatch KDE_IceRemoveConnectionWatch + +extern void IceRemoveConnectionWatch ( +#if NeedFunctionPrototypes + IceWatchProc /* watchProc */, + IcePointer /* clientData */ +#endif +); + +#define IceProtocolSetup KDE_IceProtocolSetup + +extern IceProtocolSetupStatus IceProtocolSetup ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + int /* myOpcode */, + IcePointer /* clientData */, + Bool /* mustAuthenticate */, + int * /* majorVersionRet */, + int * /* minorVersionRet */, + char ** /* vendorRet */, + char ** /* releaseRet */, + int /* errorLength */, + char * /* errorStringRet */ +#endif +); + +#define IceProtocolShutdown KDE_IceProtocolShutdown + +extern Status IceProtocolShutdown ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + int /* majorOpcode */ +#endif +); + +#define IceProcessMessages KDE_IceProcessMessages + +extern IceProcessMessagesStatus IceProcessMessages ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + IceReplyWaitInfo * /* replyWait */, + Bool * /* replyReadyRet */ +#endif +); + +#define IcePing KDE_IcePing + +extern Status IcePing ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + IcePingReplyProc /* pingReplyProc */, + IcePointer /* clientData */ +#endif +); + +#define IceAllocScratch KDE_IceAllocScratch + +extern char *IceAllocScratch ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + unsigned long /* size */ +#endif +); + +#define IceFlush KDE_IceFlush + +extern void IceFlush ( +#if NeedFunctionPrototypes + IceConn /* iceConn */ +#endif +); + +#define IceGetOutBufSize KDE_IceGetOutBufSize + +extern int IceGetOutBufSize ( +#if NeedFunctionPrototypes + IceConn /* iceConn */ +#endif +); + +#define IceGetInBufSize KDE_IceGetInBufSize + +extern int IceGetInBufSize ( +#if NeedFunctionPrototypes + IceConn /* iceConn */ +#endif +); + +#define IceConnectionStatus KDE_IceConnectionStatus + +extern IceConnectStatus IceConnectionStatus ( +#if NeedFunctionPrototypes + IceConn /* iceConn */ +#endif +); + +#define IceVendor KDE_IceVendor + +extern char *IceVendor ( +#if NeedFunctionPrototypes + IceConn /* iceConn */ +#endif +); + +#define IceRelease KDE_IceRelease + +extern char *IceRelease ( +#if NeedFunctionPrototypes + IceConn /* iceConn */ +#endif +); + +#define IceProtocolVersion KDE_IceProtocolVersion + +extern int IceProtocolVersion ( +#if NeedFunctionPrototypes + IceConn /* iceConn */ +#endif +); + +#define IceProtocolRevision KDE_IceProtocolRevision + +extern int IceProtocolRevision ( +#if NeedFunctionPrototypes + IceConn /* iceConn */ +#endif +); + +#define IceConnectionNumber KDE_IceConnectionNumber + +extern int IceConnectionNumber ( +#if NeedFunctionPrototypes + IceConn /* iceConn */ +#endif +); + +#define IceConnectionString KDE_IceConnectionString + +extern char *IceConnectionString ( +#if NeedFunctionPrototypes + IceConn /* iceConn */ +#endif +); + +#define IceLastSentSequenceNumber KDE_IceLastSentSequenceNumber + +extern unsigned long IceLastSentSequenceNumber ( +#if NeedFunctionPrototypes + IceConn /* iceConn */ +#endif +); + +#define IceLastReceivedSequenceNumber KDE_IceLastReceivedSequenceNumber + +extern unsigned long IceLastReceivedSequenceNumber ( +#if NeedFunctionPrototypes + IceConn /* iceConn */ +#endif +); + +#define IceSwapping KDE_IceSwapping + +extern Bool IceSwapping ( +#if NeedFunctionPrototypes + IceConn /* iceConn */ +#endif +); + +#define IceSetErrorHandler KDE_IceSetErrorHandler + +extern IceErrorHandler IceSetErrorHandler ( +#if NeedFunctionPrototypes + IceErrorHandler /* handler */ +#endif +); + +#define IceSetIOErrorHandler KDE_IceSetIOErrorHandler + +extern IceIOErrorHandler IceSetIOErrorHandler ( +#if NeedFunctionPrototypes + IceIOErrorHandler /* handler */ +#endif +); + + +/* + * Multithread Routines + */ + +#define IceInitThreads KDE_IceInitThreads + +extern Status IceInitThreads ( +#if NeedFunctionPrototypes + void +#endif +); + +#define IceAppLockConn KDE_IceAppLockConn + +extern void IceAppLockConn ( +#if NeedFunctionPrototypes + IceConn /* iceConn */ +#endif +); + +#define IceAppUnlockConn KDE_IceAppUnlockConn + +extern void IceAppUnlockConn ( +#if NeedFunctionPrototypes + IceConn /* iceConn */ +#endif +); + +_XFUNCPROTOEND + +#endif /* _ICELIB_H_ */ diff --git a/dcop/KDE-ICE/ICElibint.h b/dcop/KDE-ICE/ICElibint.h new file mode 100644 index 000000000..f36ab7acc --- /dev/null +++ b/dcop/KDE-ICE/ICElibint.h @@ -0,0 +1,626 @@ +/* $Xorg: ICElibint.h,v 1.3 2000/08/17 19:44:10 cpqbld Exp $ */ +/****************************************************************************** + + +Copyright (c) 1993, 1998 The Open Group + +All Rights Reserved. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + +Author: Ralph Mor, X Consortium +******************************************************************************/ +/* $XFree86: xc/lib/ICE/ICElibint.h,v 1.4 2001/01/17 19:41:29 dawes Exp $ */ +#ifndef _ICELIBINT_H_ +#define _ICELIBINT_H_ + +#include "config.h" +#if defined Q_WS_X11 && ! defined K_WS_QTONLY +#include <X11/Xos.h> +#include <X11/Xfuncs.h> +#include <X11/Xmd.h> //schroder +#else +#define _SIZEOF(x) sz_##x +#define SIZEOF(x) _SIZEOF(x) +#endif +#include <KDE-ICE/ICEproto.h> +#include <KDE-ICE/ICEconn.h> +#include <KDE-ICE/ICEmsg.h> + +#ifndef X_NOT_STDC_ENV +#include <stdlib.h> +#else +char *malloc(); +#endif + +#ifndef NULL +#define NULL 0 +#endif + + +/* + * Vendor & Release + */ + +#define IceVendorString "MIT" +#define IceReleaseString "1.0" + + +/* + * Pad to a 64 bit boundary + */ + +#define PAD64(_bytes) ((8 - ((unsigned int) (_bytes) % 8)) % 8) + +#define PADDED_BYTES64(_bytes) (_bytes + PAD64 (_bytes)) + + +/* + * Pad to 32 bit boundary + */ + +#define PAD32(_bytes) ((4 - ((unsigned int) (_bytes) % 4)) % 4) + +#define PADDED_BYTES32(_bytes) (_bytes + PAD32 (_bytes)) + + +/* + * Number of 8 byte units in _bytes. + */ + +#define WORD64COUNT(_bytes) (((unsigned int) ((_bytes) + 7)) >> 3) + + +/* + * Number of 4 byte units in _bytes. + */ + +#define WORD32COUNT(_bytes) (((unsigned int) ((_bytes) + 3)) >> 2) + + +/* + * Given a string, compute the number of bytes for the STRING representation + */ + +#define STRING_BYTES(_string) \ + (2 + strlen (_string) + PAD32 (2 + strlen (_string))) + + +/* + * Size of ICE input/output buffers + */ + +#define ICE_INBUFSIZE 1024 + +#define ICE_OUTBUFSIZE 1024 + + +/* + * Maxium number of ICE authentication methods allowed, and maxiumum + * number of authentication data entries allowed to be set in the + * IceSetPaAuthData function. + * + * We should use linked lists, but this is easier and should suffice. + */ + +#define MAX_ICE_AUTH_NAMES 32 +#define ICE_MAX_AUTH_DATA_ENTRIES 100 + + +/* + * ICE listen object + */ + +struct _IceListenObj { + struct _XtransConnInfo *trans_conn; /* transport connection object */ + char *network_id; + IceHostBasedAuthProc host_based_auth_proc; +}; + + +/* + * Some internal data structures for processing ICE messages. + */ + +typedef void (*_IceProcessCoreMsgProc) ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + int /* opcode */, + unsigned long /* length */, + Bool /* swap */, + IceReplyWaitInfo * /* replyWait */, + Bool * /* replyReadyRet */, + Bool * /* connectionClosedRet */ +#endif +); + +typedef struct { + int major_version; + int minor_version; + _IceProcessCoreMsgProc process_core_msg_proc; +} _IceVersion; + + +/* + * STORE FOO + */ + +#define STORE_CARD8(_pBuf, _val) \ +{ \ + *((CARD8 *) _pBuf) = _val; \ + _pBuf += 1; \ +} + +#ifndef WORD64 + +#define STORE_CARD16(_pBuf, _val) \ +{ \ + *((CARD16 *) _pBuf) = _val; \ + _pBuf += 2; \ +} + +#define STORE_CARD32(_pBuf, _val) \ +{ \ + *((CARD32 *) _pBuf) = _val; \ + _pBuf += 4; \ +} + +#else /* WORD64 */ + +#define STORE_CARD16(_pBuf, _val) \ +{ \ + struct { \ + int value :16; \ + int pad :16; \ + } _d; \ + _d.value = _val; \ + memcpy (_pBuf, &_d, 2); \ + _pBuf += 2; \ +} + +#define STORE_CARD32(_pBuf, _val) \ +{ \ + struct { \ + int value :32; \ + } _d; \ + _d.value = _val; \ + memcpy (_pBuf, &_d, 4); \ + _pBuf += 4; \ +} + +#endif /* WORD64 */ + +#define STORE_STRING(_pBuf, _string) \ +{ \ + CARD16 _len = strlen (_string); \ + STORE_CARD16 (_pBuf, _len); \ + memcpy (_pBuf, _string, _len); \ + _pBuf += _len; \ + if (PAD32 (2 + _len)) \ + _pBuf += PAD32 (2 + _len); \ +} + + +/* + * EXTRACT FOO + */ + +#define EXTRACT_CARD8(_pBuf, _val) \ +{ \ + _val = *((CARD8 *) _pBuf); \ + _pBuf += 1; \ +} + +#ifndef WORD64 + +#define EXTRACT_CARD16(_pBuf, _swap, _val) \ +{ \ + _val = *((CARD16 *) _pBuf); \ + _pBuf += 2; \ + if (_swap) \ + _val = lswaps (_val); \ +} + +#define EXTRACT_CARD32(_pBuf, _swap, _val) \ +{ \ + _val = *((CARD32 *) _pBuf); \ + _pBuf += 4; \ + if (_swap) \ + _val = lswapl (_val); \ +} + +#else /* WORD64 */ + +#define EXTRACT_CARD16(_pBuf, _swap, _val) \ +{ \ + _val = *(_pBuf + 0) & 0xff; /* 0xff incase _pBuf is signed */ \ + _val <<= 8; \ + _val |= *(_pBuf + 1) & 0xff;\ + _pBuf += 2; \ + if (_swap) \ + _val = lswaps (_val); \ +} + +#define EXTRACT_CARD32(_pBuf, _swap, _val) \ +{ \ + _val = *(_pBuf + 0) & 0xff; /* 0xff incase _pBuf is signed */ \ + _val <<= 8; \ + _val |= *(_pBuf + 1) & 0xff;\ + _val <<= 8; \ + _val |= *(_pBuf + 2) & 0xff;\ + _val <<= 8; \ + _val |= *(_pBuf + 3) & 0xff;\ + _pBuf += 4; \ + if (_swap) \ + _val = lswapl (_val); \ +} + +#endif /* WORD64 */ + +#define EXTRACT_STRING(_pBuf, _swap, _string) \ +{ \ + CARD16 _len; \ + EXTRACT_CARD16 (_pBuf, _swap, _len); \ + _string = (char *) malloc (_len + 1); \ + memcpy (_string, _pBuf, _len); \ + _pBuf += _len; \ + _string[_len] = '\0'; \ + if (PAD32 (2 + _len)) \ + _pBuf += PAD32 (2 + _len); \ +} + +#define EXTRACT_LISTOF_STRING(_pBuf, _swap, _count, _strings) \ +{ \ + int _i; \ + for (_i = 0; _i < _count; _i++) \ + EXTRACT_STRING (_pBuf, _swap, _strings[_i]); \ +} + + +#define SKIP_STRING(_pBuf, _swap, _end, _bail) \ +{ \ + CARD16 _len; \ + EXTRACT_CARD16 (_pBuf, _swap, _len); \ + _pBuf += _len + PAD32(2+_len); \ + if (_pBuf > _end) { \ + _bail; \ + } \ +} + +#define SKIP_LISTOF_STRING(_pBuf, _swap, _count, _end, _bail) \ +{ \ + int _i; \ + for (_i = 0; _i < _count; _i++) \ + SKIP_STRING (_pBuf, _swap, _end, _bail); \ +} + + + +/* + * Byte swapping + */ + +/* byte swap a long literal */ +#define lswapl(_val) ((((_val) & 0xff) << 24) |\ + (((_val) & 0xff00) << 8) |\ + (((_val) & 0xff0000) >> 8) |\ + (((_val) >> 24) & 0xff)) + +/* byte swap a short literal */ +#define lswaps(_val) ((((_val) & 0xff) << 8) | (((_val) >> 8) & 0xff)) + + + +/* + * ICE replies (not processed via callbacks because we block) + */ + +#define ICE_CONNECTION_REPLY 1 +#define ICE_CONNECTION_ERROR 2 +#define ICE_PROTOCOL_REPLY 3 +#define ICE_PROTOCOL_ERROR 4 + +typedef struct { + int type; + int version_index; + char *vendor; + char *release; +} _IceConnectionReply; + +typedef struct { + int type; + char *error_message; +} _IceConnectionError; + +typedef struct { + int type; + int major_opcode; + int version_index; + char *vendor; + char *release; +} _IceProtocolReply; + +typedef struct { + int type; + char *error_message; +} _IceProtocolError; + + +typedef union { + int type; + _IceConnectionReply connection_reply; + _IceConnectionError connection_error; + _IceProtocolReply protocol_reply; + _IceProtocolError protocol_error; +} _IceReply; + + +/* + * Watch for ICE connection create/destroy. + */ + +typedef struct _IceWatchedConnection { + IceConn iceConn; + IcePointer watch_data; + struct _IceWatchedConnection *next; +} _IceWatchedConnection; + +typedef struct _IceWatchProc { + IceWatchProc watch_proc; + IcePointer client_data; + _IceWatchedConnection *watched_connections; + struct _IceWatchProc *next; +} _IceWatchProc; + + +/* + * Locking + */ + +#define IceLockConn(_iceConn) +#define IceUnlockConn(_iceConn) + + +/* + * Extern declarations + */ + +extern IceConn _IceConnectionObjs[]; +extern char *_IceConnectionStrings[]; +extern int _IceConnectionCount; + +extern int _IceAuthCount; +extern const char *_IceAuthNames[]; +extern IcePoAuthProc _IcePoAuthProcs[]; +extern IcePaAuthProc _IcePaAuthProcs[]; + +extern int _IceVersionCount; + +#define _IceErrorBadMajor _kde_IceErrorBadMajor + + +extern void _IceErrorBadMajor ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + int /* offendingMajor */, + int /* offendingMinor */, + int /* severity */ +#endif +); + +#define _IceErrorNoAuthentication _kde_IceErrorNoAuthentication + +extern void _IceErrorNoAuthentication ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + int /* offendingMinor */ +#endif +); + +#define _IceErrorNoVersion _kde_IceErrorNoVersion + +extern void _IceErrorNoVersion ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + int /* offendingMinor */ +#endif +); + +#define _IceErrorSetupFailed _kde_IceErrorSetupFailed + +extern void _IceErrorSetupFailed ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + int /* offendingMinor */, + const char * /* reason */ +#endif +); + +#define _IceErrorAuthenticationRejected _kde_IceErrorAuthenticationRejected + +extern void _IceErrorAuthenticationRejected ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + int /* offendingMinor */, + const char * /* reason */ +#endif +); + +#define _IceErrorAuthenticationFailed _kde_IceErrorAuthenticationFailed + +extern void _IceErrorAuthenticationFailed ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + int /* offendingMinor */, + const char * /* reason */ +#endif +); + +#define _IceErrorProtocolDuplicate _kde_IceErrorProtocolDuplicate + +extern void _IceErrorProtocolDuplicate ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + const char * /* protocolName */ +#endif +); + +#define _IceErrorMajorOpcodeDuplicate _kde_IceErrorMajorOpcodeDuplicate + +extern void _IceErrorMajorOpcodeDuplicate ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + int /* majorOpcode */ +#endif +); + +#define _IceErrorUnknownProtocol _kde_IceErrorUnknownProtocol + +extern void _IceErrorUnknownProtocol ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + const char * /* protocolName */ +#endif +); + +#define _IceAddOpcodeMapping _kde_IceAddOpcodeMapping + +extern void _IceAddOpcodeMapping ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + int /* hisOpcode */, + int /* myOpcode */ +#endif +); + +#define _IceGetPeerName _kde_IceGetPeerName + +extern char *_IceGetPeerName ( +#if NeedFunctionPrototypes + IceConn /* iceConn */ +#endif +); + +#define _IceFreeConnection _kde_IceFreeConnection + +extern void _IceFreeConnection ( +#if NeedFunctionPrototypes + IceConn /* iceConn */ +#endif +); + +#define _IceAddReplyWait _kde_IceAddReplyWait + +extern void _IceAddReplyWait ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + IceReplyWaitInfo * /* replyWait */ +#endif +); + +#define _IceSearchReplyWaits _kde_IceSearchReplyWaits + +extern IceReplyWaitInfo *_IceSearchReplyWaits ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + int /* majorOpcode */ +#endif +); + +#define _IceSetReplyReady _kde_IceSetReplyReady + +extern void _IceSetReplyReady ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + IceReplyWaitInfo * /* replyWait */ +#endif +); + +#define _IceCheckReplyReady _kde_IceCheckReplyReady + +extern Bool _IceCheckReplyReady ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + IceReplyWaitInfo * /* replyWait */ +#endif +); + +#define _IceConnectionOpened _kde_IceConnectionOpened + +extern void _IceConnectionOpened ( +#if NeedFunctionPrototypes + IceConn /* iceConn */ +#endif +); + +#define _IceConnectionClosed _kde_IceConnectionClosed + +extern void _IceConnectionClosed ( +#if NeedFunctionPrototypes + IceConn /* iceConn */ +#endif +); + +#define _IceGetPoAuthData _kde_IceGetPoAuthData + +extern void _IceGetPoAuthData ( +#if NeedFunctionPrototypes + const char * /* protocol_name */, + const char * /* address */, + const char * /* auth_name */, + unsigned short * /* auth_data_length_ret */, + char ** /* auth_data_ret */ +#endif +); + +#define _IceGetPaAuthData _kde_IceGetPaAuthData + +extern void _IceGetPaAuthData ( +#if NeedFunctionPrototypes + const char * /* protocol_name */, + const char * /* address */, + const char * /* auth_name */, + unsigned short * /* auth_data_length_ret */, + char ** /* auth_data_ret */ +#endif +); + +#define _IceGetPoValidAuthIndices _kde_IceGetPoValidAuthIndices + +extern void _IceGetPoValidAuthIndices ( +#if NeedFunctionPrototypes + const char * /* protocol_name */, + const char * /* address */, + int /* num_auth_names */, + const char ** /* auth_names */, + int * /* num_indices_ret */, + int * /* indices_ret */ +#endif +); + +#define _IceGetPaValidAuthIndices _kde_IceGetPaValidAuthIndices + +extern void _IceGetPaValidAuthIndices ( +#if NeedFunctionPrototypes + const char * /* protocol_name */, + const char * /* address */, + int /* num_auth_names */, + const char ** /* auth_names */, + int * /* num_indices_ret */, + int * /* indices_ret */ +#endif +); + +#endif /* _ICELIBINT_H_ */ diff --git a/dcop/KDE-ICE/ICEmsg.h b/dcop/KDE-ICE/ICEmsg.h new file mode 100644 index 000000000..cf4d98975 --- /dev/null +++ b/dcop/KDE-ICE/ICEmsg.h @@ -0,0 +1,319 @@ +/* $XConsortium: ICEmsg.h,v 1.5 94/04/17 20:15:26 mor Exp $ */ +/****************************************************************************** + + +Copyright (c) 1993 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from the X Consortium. + +Author: Ralph Mor, X Consortium +******************************************************************************/ + +#ifndef _ICEMSG_H_ +#define _ICEMSG_H_ + +#include <KDE-ICE/ICEconn.h> + +/* + * Function prototypes for internal ICElib functions + */ + +#define _IceRead _kde_IceRead + +extern Status _IceRead ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + unsigned long /* nbytes */, + char * /* ptr */ +#endif +); + +#define _IceReadSkip _kde_IceReadSkip + +extern void _IceReadSkip ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + unsigned long /* nbytes */ +#endif +); + +#define _IceWrite _kde_IceWrite + +extern void _IceWrite ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + unsigned long /* nbytes */, + char * /* ptr */ +#endif +); + +#define _IceWriteHandler _kde_IceWriteHandler +extern IceWriteHandler _IceWriteHandler; + +#define _IceErrorBadMinor _kde_IceErrorBadMinor + +extern void _IceErrorBadMinor ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + int /* majorOpcode */, + int /* offendingMinor */, + int /* severity */ +#endif +); + +#define _IceErrorBadState _kde_IceErrorBadState + +extern void _IceErrorBadState ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + int /* majorOpcode */, + int /* offendingMinor */, + int /* severity */ +#endif +); + +#define _IceErrorBadLength _kde_IceErrorBadLength + +extern void _IceErrorBadLength ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + int /* majorOpcode */, + int /* offendingMinor */, + int /* severity */ +#endif +); + +#define _IceErrorBadValue _kde_IceErrorBadValue + +extern void _IceErrorBadValue ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + int /* majorOpcode */, + int /* offendingMinor */, + int /* offset */, + int /* length */, + IcePointer /* value */ +#endif +); + + +/* + * Macro to check if IO operations are valid on an ICE connection. + */ + +#define IceValidIO(_iceConn) _iceConn->io_ok + + +/* + * Macros for writing messages. + */ + +#define IceGetHeader(_iceConn, _major, _minor, _headerSize, _msgType, _pMsg) \ + if ((_iceConn->outbufptr + _headerSize) > _iceConn->outbufmax) \ + IceFlush (_iceConn); \ + _pMsg = (_msgType *) _iceConn->outbufptr; \ + _pMsg->majorOpcode = _major; \ + _pMsg->minorOpcode = _minor; \ + _pMsg->length = (_headerSize - SIZEOF (iceMsg)) >> 3; \ + _iceConn->outbufptr += _headerSize; \ + _iceConn->send_sequence++ + +#define IceGetHeaderExtra(_iceConn, _major, _minor, _headerSize, _extra, _msgType, _pMsg, _pData) \ + if ((_iceConn->outbufptr + \ + _headerSize + ((_extra) << 3)) > _iceConn->outbufmax) \ + IceFlush (_iceConn); \ + _pMsg = (_msgType *) _iceConn->outbufptr; \ + if ((_iceConn->outbufptr + \ + _headerSize + ((_extra) << 3)) <= _iceConn->outbufmax) \ + _pData = (char *) _pMsg + _headerSize; \ + else \ + _pData = NULL; \ + _pMsg->majorOpcode = _major; \ + _pMsg->minorOpcode = _minor; \ + _pMsg->length = ((_headerSize - SIZEOF (iceMsg)) >> 3) + (_extra); \ + _iceConn->outbufptr += (_headerSize + ((_extra) << 3)); \ + _iceConn->send_sequence++ + +#define IceSimpleMessage(_iceConn, _major, _minor) \ +{ \ + iceMsg *_pMsg; \ + IceGetHeader (_iceConn, _major, _minor, SIZEOF (iceMsg), iceMsg, _pMsg); \ +} + +#define IceErrorHeader(_iceConn, _offendingMajorOpcode, _offendingMinorOpcode, _offendingSequenceNum, _severity, _errorClass, _dataLength) \ +{ \ + iceErrorMsg *_pMsg; \ +\ + IceGetHeader (_iceConn, _offendingMajorOpcode, ICE_Error, \ + SIZEOF (iceErrorMsg), iceErrorMsg, _pMsg); \ + _pMsg->length += (_dataLength); \ + _pMsg->offendingMinorOpcode = _offendingMinorOpcode; \ + _pMsg->severity = _severity; \ + _pMsg->offendingSequenceNum = _offendingSequenceNum; \ + _pMsg->errorClass = _errorClass; \ +} + + +/* + * Write data into the ICE output buffer. + */ + +#define IceWriteData(_iceConn, _bytes, _data) \ +{ \ + if ((_iceConn->outbufptr + (_bytes)) > _iceConn->outbufmax) \ + { \ + IceFlush (_iceConn); \ + (*_IceWriteHandler) (_iceConn, (unsigned long) (_bytes), _data); \ + } \ + else \ + { \ + memcpy (_iceConn->outbufptr, _data, _bytes); \ + _iceConn->outbufptr += (_bytes); \ + } \ +} + +#ifndef WORD64 + +#define IceWriteData16(_iceConn, _bytes, _data) \ + IceWriteData (_iceConn, _bytes, (char *) _data) + +#define IceWriteData32(_iceConn, _bytes, _data) \ + IceWriteData (_iceConn, _bytes, (char *) _data) + +#else /* WORD64 */ + +/* IceWriteData16 and IceWriteData32 defined in misc.c for WORD64 */ + +#endif /* WORD64 */ + + +/* + * The IceSendData macro bypasses copying the data to the + * ICE connection buffer and sends the data directly. If necessary, + * the ICE connection buffer is first flushed. + */ + +#define IceSendData(_iceConn, _bytes, _data) \ +{ \ + if (_iceConn->outbufptr > _iceConn->outbuf) \ + IceFlush (_iceConn); \ + (*_IceWriteHandler) (_iceConn, (unsigned long) (_bytes), _data); \ +} + + +/* + * Write pad bytes. Used to force 32 or 64 bit alignment. + * A maxium of 7 pad bytes can be specified. + */ + +#define IceWritePad(_iceConn, _bytes) \ +{ \ + if ((_iceConn->outbufptr + (_bytes)) > _iceConn->outbufmax) \ + { \ + char _dummy[7]; \ + IceFlush (_iceConn); \ + (*_IceWriteHandler) (_iceConn, (unsigned long) (_bytes), _dummy); \ + } \ + else \ + { \ + _iceConn->outbufptr += (_bytes); \ + } \ +} + + +/* + * Macros for reading messages. + */ + +#define IceReadCompleteMessage(_iceConn, _headerSize, _msgType, _pMsg, _pData)\ +{ \ + unsigned long _bytes; \ + IceReadMessageHeader (_iceConn, _headerSize, _msgType, _pMsg); \ + _bytes = (_pMsg->length << 3) - (_headerSize - SIZEOF (iceMsg)); \ + if ((unsigned long)(_iceConn->inbufmax - _iceConn->inbufptr) >= _bytes) \ + { \ + _IceRead (_iceConn, _bytes, _iceConn->inbufptr); \ + _pData = _iceConn->inbufptr; \ + _iceConn->inbufptr += _bytes; \ + } \ + else \ + { \ + _pData = (char *) malloc ((unsigned) _bytes); \ + if (_pData) \ + _IceRead (_iceConn, _bytes, _pData); \ + else \ + _IceReadSkip (_iceConn, _bytes); \ + } \ +} + +#define IceDisposeCompleteMessage(_iceConn, _pData) \ + if ((char *) _pData < _iceConn->inbuf || \ + (char *) _pData >= _iceConn->inbufmax) \ + free ((char *) _pData); + + +#define IceReadSimpleMessage(_iceConn, _msgType, _pMsg) \ + _pMsg = (_msgType *) (_iceConn->inbuf); + +#define IceReadMessageHeader(_iceConn, _headerSize, _msgType, _pMsg) \ +{ \ + _IceRead (_iceConn, \ + (unsigned long) (_headerSize - SIZEOF (iceMsg)), \ + _iceConn->inbufptr); \ + _pMsg = (_msgType *) (_iceConn->inbuf); \ + _iceConn->inbufptr += (_headerSize - SIZEOF (iceMsg)); \ +} + +#define IceReadData(_iceConn, _bytes, _pData) \ + _IceRead (_iceConn, (unsigned long) (_bytes), (char *) _pData); \ + +#ifndef WORD64 + +#define IceReadData16(_iceConn, _swap, _bytes, _pData) \ +{ \ + _IceRead (_iceConn, (unsigned long) (_bytes), (char *) _pData); \ +} + +#define IceReadData32(_iceConn, _swap, _bytes, _pData) \ +{ \ + _IceRead (_iceConn, (unsigned long) (_bytes), (char *) _pData); \ +} + +#else /* WORD64 */ + +/* IceReadData16 and IceReadData32 defined in misc.c for WORD64 */ + +#endif /* WORD64 */ + + +/* + * Read pad bytes (for 32 or 64 bit alignment). + * A maxium of 7 pad bytes can be specified. + */ + +#define IceReadPad(_iceConn, _bytes) \ +{ \ + char _dummy[7]; \ + _IceRead (_iceConn, (unsigned long) (_bytes), _dummy); \ +} + +#endif /* _ICEMSG_H_ */ diff --git a/dcop/KDE-ICE/ICEproto.h b/dcop/KDE-ICE/ICEproto.h new file mode 100644 index 000000000..ff848df04 --- /dev/null +++ b/dcop/KDE-ICE/ICEproto.h @@ -0,0 +1,186 @@ +/* $Xorg: ICEproto.h,v 1.4 2000/08/17 19:44:11 cpqbld Exp $ */ +/****************************************************************************** + + +Copyright 1993, 1998 The Open Group + +All Rights Reserved. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + +Author: Ralph Mor, X Consortium +******************************************************************************/ + +#ifndef _ICEPROTO_H_ +#define _ICEPROTO_H_ + +#include "config.h" +#if defined Q_WS_X11 && ! defined K_WS_QTONLY +#include <X11/Xmd.h> +#else +#if defined(__alpha__) || defined(__ia64__) || defined(__s390x__) +typedef unsigned int CARD32; +#else +typedef unsigned long CARD32; +#endif +typedef unsigned short CARD16; +typedef unsigned char CARD8; +#define B32 :32 +#define B16 :16 +#include <unistd.h> +#endif + +typedef struct { + CARD8 majorOpcode; + CARD8 minorOpcode; + CARD8 data[2]; + CARD32 length B32; +} iceMsg; + +typedef struct { + CARD8 majorOpcode; + CARD8 minorOpcode; + CARD16 errorClass B16; + CARD32 length B32; + CARD8 offendingMinorOpcode; + CARD8 severity; + CARD16 unused B16; + CARD32 offendingSequenceNum B32; + /* n varying values */ + /* p p = pad (n, 8) */ +} iceErrorMsg; + +typedef struct { + CARD8 majorOpcode; + CARD8 minorOpcode; + CARD8 byteOrder; + CARD8 unused; + CARD32 length B32; +} iceByteOrderMsg; + +typedef struct { + CARD8 majorOpcode; + CARD8 minorOpcode; + CARD8 versionCount; + CARD8 authCount; + CARD32 length B32; + CARD8 mustAuthenticate; + CARD8 unused[7]; + /* i STRING vendor */ + /* j STRING release */ + /* k LIST of STRING authentication-protocol-names */ + /* m LIST of VERSION version-list */ + /* p p = pad (i+j+k+m, 8) */ +} iceConnectionSetupMsg; + +typedef struct { + CARD8 majorOpcode; + CARD8 minorOpcode; + CARD8 authIndex; + CARD8 unused1; + CARD32 length B32; + CARD16 authDataLength B16; + CARD8 unused2[6]; + /* n varying data */ + /* p p = pad (n, 8) */ +} iceAuthRequiredMsg; + +typedef struct { + CARD8 majorOpcode; + CARD8 minorOpcode; + CARD8 unused1[2]; + CARD32 length B32; + CARD16 authDataLength B16; + CARD8 unused2[6]; + /* n varying data */ + /* p p = pad (n, 8) */ +} iceAuthReplyMsg; + +typedef struct { + CARD8 majorOpcode; + CARD8 minorOpcode; + CARD8 unused1[2]; + CARD32 length B32; + CARD16 authDataLength B16; + CARD8 unused2[6]; + /* n varying data */ + /* p p = pad (n, 8) */ +} iceAuthNextPhaseMsg; + +typedef struct { + CARD8 majorOpcode; + CARD8 minorOpcode; + CARD8 versionIndex; + CARD8 unused; + CARD32 length B32; + /* i STRING vendor */ + /* j STRING release */ + /* p p = pad (i+j, 8) */ +} iceConnectionReplyMsg; + +typedef struct { + CARD8 majorOpcode; + CARD8 minorOpcode; + CARD8 protocolOpcode; + CARD8 mustAuthenticate; + CARD32 length B32; + CARD8 versionCount; + CARD8 authCount; + CARD8 unused[6]; + /* i STRING protocol-name */ + /* j STRING vendor */ + /* k STRING release */ + /* m LIST of STRING authentication-protocol-names */ + /* n LIST of VERSION version-list */ + /* p p = pad (i+j+k+m+n, 8) */ +} iceProtocolSetupMsg; + +typedef struct { + CARD8 majorOpcode; + CARD8 minorOpcode; + CARD8 versionIndex; + CARD8 protocolOpcode; + CARD32 length B32; + /* i STRING vendor */ + /* j STRING release */ + /* p p = pad (i+j, 8) */ +} iceProtocolReplyMsg; + +typedef iceMsg icePingMsg; +typedef iceMsg icePingReplyMsg; +typedef iceMsg iceWantToCloseMsg; +typedef iceMsg iceNoCloseMsg; + + +/* + * SIZEOF values. These better be multiples of 8. + */ + +#define sz_iceMsg 8 +#define sz_iceErrorMsg 16 +#define sz_iceByteOrderMsg 8 +#define sz_iceConnectionSetupMsg 16 +#define sz_iceAuthRequiredMsg 16 +#define sz_iceAuthReplyMsg 16 +#define sz_iceAuthNextPhaseMsg 16 +#define sz_iceConnectionReplyMsg 8 +#define sz_iceProtocolSetupMsg 16 +#define sz_iceProtocolReplyMsg 8 +#define sz_icePingMsg 8 +#define sz_icePingReplyMsg 8 +#define sz_iceWantToCloseMsg 8 +#define sz_iceNoCloseMsg 8 + +#endif /* _ICEPROTO_H_ */ diff --git a/dcop/KDE-ICE/ICEutil.h b/dcop/KDE-ICE/ICEutil.h new file mode 100644 index 000000000..dd32fe620 --- /dev/null +++ b/dcop/KDE-ICE/ICEutil.h @@ -0,0 +1,156 @@ +/* $XConsortium: ICEutil.h,v 1.5 94/04/17 20:15:27 mor Exp $ */ +/****************************************************************************** + + +Copyright (c) 1993 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from the X Consortium. + +Author: Ralph Mor, X Consortium +******************************************************************************/ + +#ifndef _ICEUTIL_H_ +#define _ICEUTIL_H_ + +#include <stdio.h> + +/* + * Data structure for entry in ICE authority file + */ + +typedef struct { + char *protocol_name; + unsigned short protocol_data_length; + char *protocol_data; + char *network_id; + char *auth_name; + unsigned short auth_data_length; + char *auth_data; +} IceAuthFileEntry; + + +/* + * Authentication data maintained in memory. + */ + +typedef struct { + char *protocol_name; + char *network_id; + char *auth_name; + unsigned short auth_data_length; + char *auth_data; +} IceAuthDataEntry; + + +/* + * Return values from IceLockAuthFile + */ + +#define IceAuthLockSuccess 0 /* lock succeeded */ +#define IceAuthLockError 1 /* lock unexpectely failed, check errno */ +#define IceAuthLockTimeout 2 /* lock failed, timeouts expired */ + + +/* + * Function Prototypes + */ + +#define IceAuthFileName KDE_IceAuthFileName + +extern char *IceAuthFileName ( +#if NeedFunctionPrototypes + void +#endif +); + +#define IceLockAuthFile KDE_IceLockAuthFile + +extern int IceLockAuthFile ( +#if NeedFunctionPrototypes + char * /* file_name */, + int /* retries */, + int /* timeout */, + long /* dead */ +#endif +); + +#define IceUnlockAuthFile KDE_IceUnlockAuthFile + +extern void IceUnlockAuthFile ( +#if NeedFunctionPrototypes + char * /* file_name */ +#endif +); + +#define IceReadAuthFileEntry KDE_IceReadAuthFileEntry + +extern IceAuthFileEntry *IceReadAuthFileEntry ( +#if NeedFunctionPrototypes + FILE * /* auth_file */ +#endif +); + +#define IceFreeAuthFileEntry KDE_IceFreeAuthFileEntry + +extern void IceFreeAuthFileEntry ( +#if NeedFunctionPrototypes + IceAuthFileEntry * /* auth */ +#endif +); + +#define IceWriteAuthFileEntry KDE_IceWriteAuthFileEntry + +extern Status KDE_IceWriteAuthFileEntry ( +#if NeedFunctionPrototypes + FILE * /* auth_file */, + IceAuthFileEntry * /* auth */ +#endif +); + +#define IceGetAuthFileEntry KDE_IceGetAuthFileEntry + +extern IceAuthFileEntry *IceGetAuthFileEntry ( +#if NeedFunctionPrototypes + const char * /* protocol_name */, + const char * /* network_id */, + const char * /* auth_name */ +#endif +); + +#define IceGenerateMagicCookie KDE_IceGenerateMagicCookie + +extern char *IceGenerateMagicCookie ( +#if NeedFunctionPrototypes + int /* len */ +#endif +); + +#define IceSetPaAuthData KDE_IceSetPaAuthData + +extern void IceSetPaAuthData ( +#if NeedFunctionPrototypes + int /* numEntries */, + IceAuthDataEntry * /* entries */ +#endif +); + +#endif /* _ICEUTIL_H_ */ diff --git a/dcop/KDE-ICE/Makefile.am b/dcop/KDE-ICE/Makefile.am new file mode 100644 index 000000000..b75fc0a13 --- /dev/null +++ b/dcop/KDE-ICE/Makefile.am @@ -0,0 +1,38 @@ + +AM_CFLAGS = -DICE_t -DTRANS_SERVER -DTRANS_CLIENT -DUNIXCONN -DANSICPP +INCLUDES = $(all_includes) + +noinst_LTLIBRARIES = libkICE.la + +noinst_HEADERS = ICE.h \ + ICEconn.h \ + ICElib.h \ + ICElibint.h \ + ICEmsg.h \ + ICEproto.h \ + ICEutil.h \ + Xtrans.h \ + Xtransint.h \ + Xfuncproto.h \ + globals.h + +libkICE_la_SOURCES = accept.c \ + authutil.c \ + connect.c \ + error.c \ + getauth.c \ + iceauth.c \ + listen.c \ + listenwk.c \ + locking.c \ + misc.c \ + ping.c \ + process.c \ + protosetup.c \ + register.c \ + replywait.c \ + setauth.c \ + shutdown.c \ + watch.c \ + transport.c \ + globals.c diff --git a/dcop/KDE-ICE/Xfuncproto.h b/dcop/KDE-ICE/Xfuncproto.h new file mode 100644 index 000000000..e434e7257 --- /dev/null +++ b/dcop/KDE-ICE/Xfuncproto.h @@ -0,0 +1,83 @@ +/* $Xorg: Xfuncproto.h,v 1.3 2000/08/18 04:05:44 coskrey Exp $ */ +/* + * +Copyright 1989, 1991, 1998 The Open Group + +All Rights Reserved. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + * + */ + +/* Definitions to make function prototypes manageable */ + +#ifndef _XFUNCPROTO_H_ +#define _XFUNCPROTO_H_ + +#ifndef NeedFunctionPrototypes +#if defined(FUNCPROTO) || defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus) +#define NeedFunctionPrototypes 1 +#else +#define NeedFunctionPrototypes 0 +#endif +#endif /* NeedFunctionPrototypes */ + +#ifndef NeedVarargsPrototypes +#if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus) || (FUNCPROTO&2) +#define NeedVarargsPrototypes 1 +#else +#define NeedVarargsPrototypes 0 +#endif +#endif /* NeedVarargsPrototypes */ + +#if NeedFunctionPrototypes + +#ifndef NeedNestedPrototypes +#if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus) || (FUNCPROTO&8) +#define NeedNestedPrototypes 1 +#else +#define NeedNestedPrototypes 0 +#endif +#endif /* NeedNestedPrototypes */ + +#ifndef _Xconst +#if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus) || (FUNCPROTO&4) +#define _Xconst const +#else +#define _Xconst +#endif +#endif /* _Xconst */ + +#ifndef NeedWidePrototypes +#ifdef NARROWPROTO +#define NeedWidePrototypes 0 +#else +#define NeedWidePrototypes 1 /* default to make interropt. easier */ +#endif +#endif /* NeedWidePrototypes */ + +#endif /* NeedFunctionPrototypes */ + +#ifndef _XFUNCPROTOBEGIN +#ifdef __cplusplus /* for C++ V2.0 */ +#define _XFUNCPROTOBEGIN extern "C" { /* do not leave open across includes */ +#define _XFUNCPROTOEND } +#else +#define _XFUNCPROTOBEGIN +#define _XFUNCPROTOEND +#endif +#endif /* _XFUNCPROTOBEGIN */ + +#endif /* _XFUNCPROTO_H_ */ diff --git a/dcop/KDE-ICE/Xtrans.c b/dcop/KDE-ICE/Xtrans.c new file mode 100644 index 000000000..371752919 --- /dev/null +++ b/dcop/KDE-ICE/Xtrans.c @@ -0,0 +1,1343 @@ +/* $TOG: Xtrans.c /main/34 1998/02/06 15:55:15 kaleb $ */ +/* + +Copyright 1993, 1994, 1998 The Open Group + +All Rights Reserved. + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall +not be used in advertising or otherwise to promote the sale, use or +other dealings in this Software without prior written authorization +from The Open Group. + +*/ +/* $XFree86: xc/lib/xtrans/Xtrans.c,v 3.22 1999/12/27 00:39:28 robin Exp $ */ + +/* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA + * + * All Rights Reserved + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name NCR not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. NCR makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * NCR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <ctype.h> +#ifdef _AIX +extern char *strpbrk(const char *, const char *); +extern char *strchr(const char *, int); +#endif + +/* + * The transport table contains a definition for every transport (protocol) + * family. All operations that can be made on the transport go through this + * table. + * + * Each transport is assigned a unique transport id. + * + * New transports can be added by adding an entry in this table. + * For compatibility, the transport ids should never be renumbered. + * Always add to the end of the list. + */ + +#define TRANS_TLI_INET_INDEX 1 +#define TRANS_TLI_TCP_INDEX 2 +#define TRANS_TLI_TLI_INDEX 3 +#define TRANS_SOCKET_UNIX_INDEX 4 +#define TRANS_SOCKET_LOCAL_INDEX 5 +#define TRANS_SOCKET_INET_INDEX 6 +#define TRANS_SOCKET_TCP_INDEX 7 +#define TRANS_DNET_INDEX 8 +#define TRANS_LOCAL_LOCAL_INDEX 9 +#define TRANS_LOCAL_PTS_INDEX 10 +#define TRANS_LOCAL_NAMED_INDEX 11 +#define TRANS_LOCAL_ISC_INDEX 12 +#define TRANS_LOCAL_SCO_INDEX 13 +#define TRANS_AMOEBA_INDEX 14 +#define TRANS_MNX_INET_INDEX 15 +#define TRANS_MNX_TCP_INDEX 16 + + +static +Xtransport_table Xtransports[] = { +#if defined(STREAMSCONN) + { &TRANS(TLITCPFuncs), TRANS_TLI_TCP_INDEX }, + { &TRANS(TLIINETFuncs), TRANS_TLI_INET_INDEX }, + { &TRANS(TLITLIFuncs), TRANS_TLI_TLI_INDEX }, +#endif /* STREAMSCONN */ +#if defined(TCPCONN) + { &TRANS(SocketTCPFuncs), TRANS_SOCKET_TCP_INDEX }, + { &TRANS(SocketINETFuncs), TRANS_SOCKET_INET_INDEX }, +#endif /* TCPCONN */ +#if defined(DNETCONN) + { &TRANS(DNETFuncs), TRANS_DNET_INDEX }, +#endif /* DNETCONN */ +#if defined(UNIXCONN) +#if !defined(LOCALCONN) + { &TRANS(SocketLocalFuncs), TRANS_SOCKET_LOCAL_INDEX }, +#endif /* !LOCALCONN */ + { &TRANS(SocketUNIXFuncs), TRANS_SOCKET_UNIX_INDEX }, +#endif /* UNIXCONN */ +#if defined(OS2PIPECONN) + { &TRANS(OS2LocalFuncs), TRANS_LOCAL_LOCAL_INDEX }, +#endif /* OS2PIPECONN */ +#if defined(LOCALCONN) + { &TRANS(LocalFuncs), TRANS_LOCAL_LOCAL_INDEX }, +#ifndef sun + { &TRANS(PTSFuncs), TRANS_LOCAL_PTS_INDEX }, +#endif /* sun */ +#ifdef SVR4 + { &TRANS(NAMEDFuncs), TRANS_LOCAL_NAMED_INDEX }, +#endif +#ifndef sun + { &TRANS(ISCFuncs), TRANS_LOCAL_ISC_INDEX }, + { &TRANS(SCOFuncs), TRANS_LOCAL_SCO_INDEX }, +#endif /* sun */ +#endif /* LOCALCONN */ +#if defined(AMRPCCONN) || defined(AMTCPCONN) + { &TRANS(AmConnFuncs), TRANS_AMOEBA_INDEX }, +#endif /* AMRPCCONN || AMTCPCONN */ +#if defined(MNX_TCPCONN) + { &TRANS(MnxINETFuncs), TRANS_MNX_INET_INDEX }, + { &TRANS(MnxTCPFuncs), TRANS_MNX_TCP_INDEX }, +#endif /* MNX_TCPCONN */ +}; + +#define NUMTRANS (sizeof(Xtransports)/sizeof(Xtransport_table)) + + +#ifdef _WIN32 +#define ioctl ioctlsocket +#endif + + +/* + * These are a few utility function used by the public interface functions. + */ + +void +TRANS(FreeConnInfo) (XtransConnInfo ciptr) + +{ + PRMSG (3,"FreeConnInfo(%x)\n", ciptr, 0, 0); + + if (ciptr->addr) + xfree (ciptr->addr); + + if (ciptr->peeraddr) + xfree (ciptr->peeraddr); + + if (ciptr->port) + xfree (ciptr->port); + + xfree ((char *) ciptr); +} + + +#define PROTOBUFSIZE 20 + +static Xtransport * +TRANS(SelectTransport) (char *protocol) + +{ + char protobuf[PROTOBUFSIZE]; + int i; + + PRMSG (3,"SelectTransport(%s)\n", protocol, 0, 0); + + /* + * Force Protocol to be lowercase as a way of doing + * a case insensitive match. + */ + + strncpy (protobuf, protocol, PROTOBUFSIZE - 1); + protobuf[PROTOBUFSIZE-1] = '\0'; + + for (i = 0; i < PROTOBUFSIZE && protobuf[i] != '\0'; i++) + if (isupper (protobuf[i])) + protobuf[i] = tolower (protobuf[i]); + + /* Look at all of the configured protocols */ + + for (i = 0; i < (int) NUMTRANS; i++) + { + if (!strcmp (protobuf, Xtransports[i].transport->TransName)) + return Xtransports[i].transport; + } + + return NULL; +} + +#ifndef TEST_t +static +#endif /* TEST_t */ +int +TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port) + +{ + /* + * For the font library, the address is a string formatted + * as "protocol/host:port[/catalog]". Note that the catalog + * is optional. At this time, the catalog info is ignored, but + * we have to parse it anyways. + * + * Other than fontlib, the address is a string formatted + * as "protocol/host:port". + * + * If the protocol part is missing, then assume INET. + * If the protocol part and host part are missing, then assume local. + */ + + char *mybuf, *tmpptr; + char *_protocol, *_host, *_port; + char hostnamebuf[256]; + + PRMSG (3,"ParseAddress(%s)\n", address, 0, 0); + + /* Copy the string so it can be changed */ + + tmpptr = mybuf = (char *) xalloc (strlen (address) + 1); + strcpy (mybuf, address); + + /* Parse the string to get each component */ + + /* Get the protocol part */ + + _protocol = mybuf; + + + if ( ((mybuf = strchr (mybuf,'/')) == NULL) && + ((mybuf = strrchr (tmpptr,':')) == NULL) ) + { + /* address is in a bad format */ + *protocol = NULL; + *host = NULL; + *port = NULL; + xfree (tmpptr); + return 0; + } + + if (*mybuf == ':') + { + /* + * If there is a hostname, then assume tcp, otherwise + * it must be local. + */ + if (mybuf == tmpptr) + { + /* There is neither a protocol or host specified */ + _protocol = (char*)"local"; + } + else + { + /* Ther is a hostname specified */ + _protocol = (char*)"inet"; + mybuf = tmpptr; /* reset to the begining of the host ptr */ + } + } + else + { + /* *mybuf == '/' */ + + *mybuf ++= '\0'; /* put a null at the end of the protocol */ + + if (strlen(_protocol) == 0) + { + /* + * If there is a hostname, then assume inet, otherwise + * it must be local. + */ + if (*mybuf != ':') + _protocol = (char*)"inet"; + else + _protocol = (char*)"local"; + } + } + + /* Get the host part */ + + _host = mybuf; + + if ((mybuf = strrchr (mybuf,':')) == NULL) + { + *protocol = NULL; + *host = NULL; + *port = NULL; + xfree (tmpptr); + return 0; + } + + *mybuf ++= '\0'; + + if (strlen(_host) == 0) + { + TRANS(GetHostname) (hostnamebuf, sizeof (hostnamebuf)); + _host = hostnamebuf; + } + + /* Get the port */ + + _port = mybuf; + +#if defined(FONT_t) || defined(FS_t) + /* + * Is there an optional catalog list? + */ + + if ((mybuf = strchr (mybuf,'/')) != NULL) + *mybuf ++= '\0'; + + /* + * The rest, if any, is the (currently unused) catalog list. + * + * _catalogue = mybuf; + */ +#endif + + /* + * Now that we have all of the components, allocate new + * string space for them. + */ + + if ((*protocol = (char *) xalloc(strlen (_protocol) + 1)) == NULL) + { + /* Malloc failed */ + *port = NULL; + *host = NULL; + *protocol = NULL; + xfree (tmpptr); + return 0; + } + else + strcpy (*protocol, _protocol); + + if ((*host = (char *) xalloc (strlen (_host) + 1)) == NULL) + { + /* Malloc failed */ + *port = NULL; + *host = NULL; + xfree (*protocol); + *protocol = NULL; + xfree (tmpptr); + return 0; + } + else + strcpy (*host, _host); + + if ((*port = (char *) xalloc (strlen (_port) + 1)) == NULL) + { + /* Malloc failed */ + *port = NULL; + xfree (*host); + *host = NULL; + xfree (*protocol); + *protocol = NULL; + xfree (tmpptr); + return 0; + } + else + strcpy (*port, _port); + + xfree (tmpptr); + + return 1; +} + + +/* + * TRANS(Open) does all of the real work opening a connection. The only + * funny part about this is the type parameter which is used to decide which + * type of open to perform. + */ + +static XtransConnInfo +TRANS(Open) (int type, char *address) + +{ + char *protocol = NULL, *host = NULL, *port = NULL; + XtransConnInfo ciptr = NULL; + Xtransport *thistrans; + + PRMSG (2,"Open(%d,%s)\n", type, address, 0); + +#if defined(_WIN32) && (defined(TCPCONN) || defined(DNETCONN)) + if (TRANS(WSAStartup)()) + { + PRMSG (1,"Open: WSAStartup failed\n", 0, 0, 0); + return NULL; + } +#endif + + /* Parse the Address */ + + if (TRANS(ParseAddress) (address, &protocol, &host, &port) == 0) + { + PRMSG (1,"Open: Unable to Parse address %s\n", address, 0, 0); + return NULL; + } + + /* Determine the transport type */ + + if ((thistrans = TRANS(SelectTransport) (protocol)) == NULL) + { + PRMSG (1,"Open: Unable to find transport for %s\n", + protocol, 0, 0); + + xfree (protocol); + xfree (host); + xfree (port); + return NULL; + } + + /* Open the transport */ + + switch (type) + { + case XTRANS_OPEN_COTS_CLIENT: +#ifdef TRANS_CLIENT + ciptr = thistrans->OpenCOTSClient(thistrans, protocol, host, port); +#endif /* TRANS_CLIENT */ + break; + case XTRANS_OPEN_COTS_SERVER: +#ifdef TRANS_SERVER + ciptr = thistrans->OpenCOTSServer(thistrans, protocol, host, port); +#endif /* TRANS_SERVER */ + break; + case XTRANS_OPEN_CLTS_CLIENT: +#ifdef TRANS_CLIENT + ciptr = thistrans->OpenCLTSClient(thistrans, protocol, host, port); +#endif /* TRANS_CLIENT */ + break; + case XTRANS_OPEN_CLTS_SERVER: +#ifdef TRANS_SERVER + ciptr = thistrans->OpenCLTSServer(thistrans, protocol, host, port); +#endif /* TRANS_SERVER */ + break; + default: + PRMSG (1,"Open: Unknown Open type %d\n", type, 0, 0); + } + + if (ciptr == NULL) + { + if (!(thistrans->flags & TRANS_DISABLED)) + { + PRMSG (1,"Open: transport open failed for %s/%s:%s\n", + protocol, host, port); + } + xfree (protocol); + xfree (host); + xfree (port); + return NULL; + } + + ciptr->transptr = thistrans; + ciptr->port = port; /* We need this for TRANS(Reopen) */ + + xfree (protocol); + xfree (host); + + return ciptr; +} + + +#ifdef TRANS_REOPEN + +/* + * We might want to create an XtransConnInfo object based on a previously + * opened connection. For example, the font server may clone itself and + * pass file descriptors to the parent. + */ + +static XtransConnInfo +TRANS(Reopen) (int type, int trans_id, int fd, char *port) + +{ + XtransConnInfo ciptr = NULL; + Xtransport *thistrans = NULL; + char *save_port; + int i; + + PRMSG (2,"Reopen(%d,%d,%s)\n", trans_id, fd, port); + + /* Determine the transport type */ + + for (i = 0; i < NUMTRANS; i++) + if (Xtransports[i].transport_id == trans_id) + { + thistrans = Xtransports[i].transport; + break; + } + + if (thistrans == NULL) + { + PRMSG (1,"Reopen: Unable to find transport id %d\n", + trans_id, 0, 0); + + return NULL; + } + + if ((save_port = (char *) xalloc (strlen (port) + 1)) == NULL) + { + PRMSG (1,"Reopen: Unable to malloc port string\n", 0, 0, 0); + + return NULL; + } + + strcpy (save_port, port); + + /* Get a new XtransConnInfo object */ + + switch (type) + { + case XTRANS_OPEN_COTS_SERVER: + ciptr = thistrans->ReopenCOTSServer(thistrans, fd, port); + break; + case XTRANS_OPEN_CLTS_SERVER: + ciptr = thistrans->ReopenCLTSServer(thistrans, fd, port); + break; + default: + PRMSG (1,"Reopen: Bad Open type %d\n", type, 0, 0); + } + + if (ciptr == NULL) + { + PRMSG (1,"Reopen: transport open failed\n", 0, 0, 0); + return NULL; + } + + ciptr->transptr = thistrans; + ciptr->port = save_port; + + return ciptr; +} + +#endif /* TRANS_REOPEN */ + + + +/* + * These are the public interfaces to this Transport interface. + * These are the only functions that should have knowledge of the transport + * table. + */ + +#ifdef TRANS_CLIENT + +XtransConnInfo +TRANS(OpenCOTSClient) (char *address) + +{ + PRMSG (2,"OpenCOTSClient(%s)\n", address, 0, 0); + return TRANS(Open) (XTRANS_OPEN_COTS_CLIENT, address); +} + +#endif /* TRANS_CLIENT */ + + +#ifdef TRANS_SERVER + +XtransConnInfo +TRANS(OpenCOTSServer) (char *address) + +{ + PRMSG (2,"OpenCOTSServer(%s)\n", address, 0, 0); + return TRANS(Open) (XTRANS_OPEN_COTS_SERVER, address); +} + +#endif /* TRANS_SERVER */ + + +#ifdef TRANS_CLIENT + +XtransConnInfo +TRANS(OpenCLTSClient) (char *address) + +{ + PRMSG (2,"OpenCLTSClient(%s)\n", address, 0, 0); + return TRANS(Open) (XTRANS_OPEN_CLTS_CLIENT, address); +} + +#endif /* TRANS_CLIENT */ + + +#ifdef TRANS_SERVER + +XtransConnInfo +TRANS(OpenCLTSServer) (char *address) + +{ + PRMSG (2,"OpenCLTSServer(%s)\n", address, 0, 0); + return TRANS(Open) (XTRANS_OPEN_CLTS_SERVER, address); +} + +#endif /* TRANS_SERVER */ + + +#ifdef TRANS_REOPEN + +XtransConnInfo +TRANS(ReopenCOTSServer) (int trans_id, int fd, char *port) + +{ + PRMSG (2,"ReopenCOTSServer(%d, %d, %s)\n", trans_id, fd, port); + return TRANS(Reopen) (XTRANS_OPEN_COTS_SERVER, trans_id, fd, port); +} + +XtransConnInfo +TRANS(ReopenCLTSServer) (int trans_id, int fd, char *port) + +{ + PRMSG (2,"ReopenCLTSServer(%d, %d, %s)\n", trans_id, fd, port); + return TRANS(Reopen) (XTRANS_OPEN_CLTS_SERVER, trans_id, fd, port); +} + + +int +TRANS(GetReopenInfo) (XtransConnInfo ciptr, + int *trans_id, int *fd, char **port) + +{ + int i; + + for (i = 0; i < NUMTRANS; i++) + if (Xtransports[i].transport == ciptr->transptr) + { + *trans_id = Xtransports[i].transport_id; + *fd = ciptr->fd; + + if ((*port = (char *) xalloc (strlen (ciptr->port) + 1)) == NULL) + return 0; + else + { + strcpy (*port, ciptr->port); + return 1; + } + } + + return 0; +} + +#endif /* TRANS_REOPEN */ + + +int +TRANS(SetOption) (XtransConnInfo ciptr, int option, int arg) + +{ + int fd = ciptr->fd; + int ret = 0; + + PRMSG (2,"SetOption(%d,%d,%d)\n", fd, option, arg); + + /* + * For now, all transport type use the same stuff for setting options. + * As long as this is true, we can put the common code here. Once a more + * complicated transport such as shared memory or an OSI implementation + * that uses the session and application libraries is implemented, this + * code may have to move to a transport dependent function. + * + * ret = ciptr->transptr->SetOption (ciptr, option, arg); + */ + +#ifdef MINIX + return ciptr->transptr->SetOption(ciptr, option, arg); +#else /* !MINIX */ + + switch (option) + { + case TRANS_NONBLOCKING: + switch (arg) + { + case 0: + /* Set to blocking mode */ + break; + case 1: /* Set to non-blocking mode */ + +#if defined(O_NONBLOCK) && (!defined(ultrix) && !defined(hpux) && !defined(AIXV3) && !defined(uniosu) && !defined(__EMX__) && !defined(SCO)) && !defined(__QNX__) + ret = fcntl (fd, F_GETFL, 0); + if (ret != -1) + ret = fcntl (fd, F_SETFL, ret | O_NONBLOCK); +#else +#ifdef FIOSNBIO + { + int arg; + arg = 1; + ret = ioctl (fd, FIOSNBIO, &arg); + } +#else +#if (defined(AIXV3) || defined(uniosu) || defined(_WIN32) || defined(__EMX__) || defined(__QNX__)) && defined(FIONBIO) + { + int arg; + arg = 1; +/* IBM TCP/IP understands this option too well: it causes TRANS(Read) to fail + * eventually with EWOULDBLOCK */ +#ifndef __EMX__ + ret = ioctl (fd, FIONBIO, &arg); +#else +/* ret = ioctl(fd, FIONBIO, &arg, sizeof(int));*/ +#endif + } +#else + ret = fcntl (fd, F_GETFL, 0); +#ifdef FNDELAY + ret = fcntl (fd, F_SETFL, ret | FNDELAY); +#else + ret = fcntl (fd, F_SETFL, ret | O_NDELAY); +#endif +#endif /* AIXV3 || uniosu */ +#endif /* FIOSNBIO */ +#endif /* O_NONBLOCK */ + break; + default: + /* Unknown option */ + break; + } + break; + case TRANS_CLOSEONEXEC: +#ifdef F_SETFD +#ifdef FD_CLOEXEC + ret = fcntl (fd, F_SETFD, FD_CLOEXEC); +#else + ret = fcntl (fd, F_SETFD, 1); +#endif /* FD_CLOEXEC */ +#endif /* F_SETFD */ + break; + } + + return ret; +#endif /* MINIX */ +} + +#ifdef TRANS_SERVER + +int +TRANS(CreateListener) (XtransConnInfo ciptr, char *port) + +{ + return ciptr->transptr->CreateListener (ciptr, port); +} + +int +TRANS(NoListen) (char * protocol) + +{ + Xtransport *trans; + + if ((trans = TRANS(SelectTransport)(protocol)) == NULL) + { + PRMSG (1,"TRANS(TransNoListen): unable to find transport: %s\n", + protocol, 0, 0); + + return -1; + } + + trans->flags |= TRANS_NOLISTEN; + return 0; +} + +int +TRANS(ResetListener) (XtransConnInfo ciptr) + +{ + if (ciptr->transptr->ResetListener) + return ciptr->transptr->ResetListener (ciptr); + else + return TRANS_RESET_NOOP; +} + + +XtransConnInfo +TRANS(Accept) (XtransConnInfo ciptr, int *status) + +{ + XtransConnInfo newciptr; + + PRMSG (2,"Accept(%d)\n", ciptr->fd, 0, 0); + + newciptr = ciptr->transptr->Accept (ciptr, status); + + if (newciptr) + newciptr->transptr = ciptr->transptr; + + return newciptr; +} + +#endif /* TRANS_SERVER */ + + +#ifdef TRANS_CLIENT + +int +TRANS(Connect) (XtransConnInfo ciptr, char *address) + +{ + char *protocol; + char *host; + char *port; + int ret; + + PRMSG (2,"Connect(%d,%s)\n", ciptr->fd, address, 0); + + if (TRANS(ParseAddress) (address, &protocol, &host, &port) == 0) + { + PRMSG (1,"Connect: Unable to Parse address %s\n", + address, 0, 0); + return -1; + } + + if (!port || !*port) + { + PRMSG (1,"Connect: Missing port specification in %s\n", + address, 0, 0); + if (protocol) xfree (protocol); + if (host) xfree (host); + return -1; + } + + ret = ciptr->transptr->Connect (ciptr, host, port); + + if (protocol) xfree (protocol); + if (host) xfree (host); + if (port) xfree (port); + + return ret; +} + +#endif /* TRANS_CLIENT */ + + +int +TRANS(BytesReadable) (XtransConnInfo ciptr, BytesReadable_t *pend) + +{ + return ciptr->transptr->BytesReadable (ciptr, pend); +} + +int +TRANS(Read) (XtransConnInfo ciptr, char *buf, int size) + +{ + return ciptr->transptr->Read (ciptr, buf, size); +} + +int +TRANS(Write) (XtransConnInfo ciptr, char *buf, int size) + +{ + return ciptr->transptr->Write (ciptr, buf, size); +} + +int +TRANS(Readv) (XtransConnInfo ciptr, struct iovec *buf, int size) + +{ + return ciptr->transptr->Readv (ciptr, buf, size); +} + +int +TRANS(Writev) (XtransConnInfo ciptr, struct iovec *buf, int size) + +{ + return ciptr->transptr->Writev (ciptr, buf, size); +} + +int +TRANS(Disconnect) (XtransConnInfo ciptr) + +{ + return ciptr->transptr->Disconnect (ciptr); +} + +int +TRANS(Close) (XtransConnInfo ciptr) + +{ + int ret; + + PRMSG (2,"Close(%d)\n", ciptr->fd, 0, 0); + + ret = ciptr->transptr->Close (ciptr); + + TRANS(FreeConnInfo) (ciptr); + + return ret; +} + +int +TRANS(CloseForCloning) (XtransConnInfo ciptr) + +{ + int ret; + + PRMSG (2,"CloseForCloning(%d)\n", ciptr->fd, 0, 0); + + ret = ciptr->transptr->CloseForCloning (ciptr); + + TRANS(FreeConnInfo) (ciptr); + + return ret; +} + +int +TRANS(IsLocal) (XtransConnInfo ciptr) + +{ + return (ciptr->family == AF_UNIX); +} + + +int +TRANS(GetMyAddr) (XtransConnInfo ciptr, int *familyp, int *addrlenp, + Xtransaddr **addrp) + +{ + PRMSG (2,"GetMyAddr(%d)\n", ciptr->fd, 0, 0); + + *familyp = ciptr->family; + *addrlenp = ciptr->addrlen; + + if ((*addrp = (Xtransaddr *) xalloc (ciptr->addrlen)) == NULL) + { + PRMSG (1,"GetMyAddr: malloc failed\n", 0, 0, 0); + return -1; + } + memcpy(*addrp, ciptr->addr, ciptr->addrlen); + + return 0; +} + +int +TRANS(GetPeerAddr) (XtransConnInfo ciptr, int *familyp, int *addrlenp, + Xtransaddr **addrp) + +{ + PRMSG (2,"GetPeerAddr(%d)\n", ciptr->fd, 0, 0); + + *familyp = ciptr->family; + *addrlenp = ciptr->peeraddrlen; + + if ((*addrp = (Xtransaddr *) xalloc (ciptr->peeraddrlen)) == NULL) + { + PRMSG (1,"GetPeerAddr: malloc failed\n", 0, 0, 0); + return -1; + } + memcpy(*addrp, ciptr->peeraddr, ciptr->peeraddrlen); + + return 0; +} + + +int +TRANS(GetConnectionNumber) (XtransConnInfo ciptr) + +{ + return ciptr->fd; +} + + +/* + * These functions are really utility functions, but they require knowledge + * of the internal data structures, so they have to be part of the Transport + * Independant API. + */ + +#ifdef TRANS_SERVER + +static int +complete_network_count (void) + +{ + int count = 0; + int found_local = 0; + int i; + + /* + * For a complete network, we only need one LOCALCONN transport to work + */ + + for (i = 0; i < (int) NUMTRANS; i++) + { + if (Xtransports[i].transport->flags & TRANS_ALIAS + || Xtransports[i].transport->flags & TRANS_NOLISTEN) + continue; + + if (Xtransports[i].transport->flags & TRANS_LOCAL) + found_local = 1; + else + count++; + } + + return (count + found_local); +} + + + +int +TRANS(MakeAllCOTSServerListeners) (char *port, int *partial, int *count_ret, + XtransConnInfo **ciptrs_ret) + +{ + char buffer[256]; /* ??? What size ?? */ + XtransConnInfo ciptr, temp_ciptrs[NUMTRANS]; + int status, i, j; + + PRMSG (2,"MakeAllCOTSServerListeners(%s,%x)\n", + port ? port : "NULL", ciptrs_ret, 0); + + *count_ret = 0; + + for (i = 0; i < (int) NUMTRANS; i++) + { + Xtransport *trans = Xtransports[i].transport; + + if (trans->flags&TRANS_ALIAS || trans->flags&TRANS_NOLISTEN) + continue; + + snprintf(buffer, sizeof(buffer), "%s/:%s", trans->TransName, port ? port : ""); + + PRMSG (5,"MakeAllCOTSServerListeners: opening %s\n", + buffer, 0, 0); + + if ((ciptr = TRANS(OpenCOTSServer(buffer))) == NULL) + { + if (trans->flags & TRANS_DISABLED) + continue; + + PRMSG (1, + "MakeAllCOTSServerListeners: failed to open listener for %s\n", + trans->TransName, 0, 0); + continue; + } + + if ((status = TRANS(CreateListener (ciptr, port))) < 0) + { + if (status == TRANS_ADDR_IN_USE) + { + /* + * We failed to bind to the specified address because the + * address is in use. It must be that a server is already + * running at this address, and this function should fail. + */ + + PRMSG (1, + "MakeAllCOTSServerListeners: server already running\n", + 0, 0, 0); + + for (j = 0; j < *count_ret; j++) + TRANS(Close) (temp_ciptrs[j]); + + *count_ret = 0; + *ciptrs_ret = NULL; + *partial = 0; + return -1; + } + else + { + PRMSG (1, + "MakeAllCOTSServerListeners: failed to create listener for %s\n", + trans->TransName, 0, 0); + + continue; + } + } + + PRMSG (5, + "MakeAllCOTSServerListeners: opened listener for %s, %d\n", + trans->TransName, ciptr->fd, 0); + + temp_ciptrs[*count_ret] = ciptr; + (*count_ret)++; + } + + *partial = (*count_ret < complete_network_count()); + + PRMSG (5, + "MakeAllCLTSServerListeners: partial=%d, actual=%d, complete=%d \n", + *partial, *count_ret, complete_network_count()); + + if (*count_ret > 0) + { + if ((*ciptrs_ret = (XtransConnInfo *) xalloc ( + *count_ret * sizeof (XtransConnInfo))) == NULL) + { + return -1; + } + + for (i = 0; i < *count_ret; i++) + { + (*ciptrs_ret)[i] = temp_ciptrs[i]; + } + } + else + *ciptrs_ret = NULL; + + return 0; +} + +int +TRANS(MakeAllCLTSServerListeners) (char *port, int *partial, int *count_ret, + XtransConnInfo **ciptrs_ret) + +{ + char buffer[256]; /* ??? What size ?? */ + XtransConnInfo ciptr, temp_ciptrs[NUMTRANS]; + int status, i, j; + + PRMSG (2,"MakeAllCLTSServerListeners(%s,%x)\n", + port ? port : "NULL", ciptrs_ret, 0); + + *count_ret = 0; + + for (i = 0; i < (int) NUMTRANS; i++) + { + Xtransport *trans = Xtransports[i].transport; + + if (trans->flags&TRANS_ALIAS || trans->flags&TRANS_NOLISTEN) + continue; + + snprintf(buffer, sizeof(buffer), "%s/:%s", trans->TransName, port ? port : ""); + + PRMSG (5,"MakeAllCLTSServerListeners: opening %s\n", + buffer, 0, 0); + + if ((ciptr = TRANS(OpenCLTSServer (buffer))) == NULL) + { + PRMSG (1, + "MakeAllCLTSServerListeners: failed to open listener for %s\n", + trans->TransName, 0, 0); + continue; + } + + if ((status = TRANS(CreateListener (ciptr, port))) < 0) + { + if (status == TRANS_ADDR_IN_USE) + { + /* + * We failed to bind to the specified address because the + * address is in use. It must be that a server is already + * running at this address, and this function should fail. + */ + + PRMSG (1, + "MakeAllCLTSServerListeners: server already running\n", + 0, 0, 0); + + for (j = 0; j < *count_ret; j++) + TRANS(Close) (temp_ciptrs[j]); + + *count_ret = 0; + *ciptrs_ret = NULL; + *partial = 0; + return -1; + } + else + { + PRMSG (1, + "MakeAllCLTSServerListeners: failed to create listener for %s\n", + trans->TransName, 0, 0); + + continue; + } + } + + PRMSG (5, + "MakeAllCLTSServerListeners: opened listener for %s, %d\n", + trans->TransName, ciptr->fd, 0); + temp_ciptrs[*count_ret] = ciptr; + (*count_ret)++; + } + + *partial = (*count_ret < complete_network_count()); + + PRMSG (5, + "MakeAllCLTSServerListeners: partial=%d, actual=%d, complete=%d \n", + *partial, *count_ret, complete_network_count()); + + if (*count_ret > 0) + { + if ((*ciptrs_ret = (XtransConnInfo *) xalloc ( + *count_ret * sizeof (XtransConnInfo))) == NULL) + { + return -1; + } + + for (i = 0; i < *count_ret; i++) + { + (*ciptrs_ret)[i] = temp_ciptrs[i]; + } + } + else + *ciptrs_ret = NULL; + + return 0; +} + +#endif /* TRANS_SERVER */ + + + +/* + * These routines are not part of the X Transport Interface, but they + * may be used by it. + */ + +#ifdef CRAY + +/* + * Cray UniCOS does not have readv and writev so we emulate + */ + +static int TRANS(ReadV) (XtransConnInfo ciptr, struct iovec *iov, int iovcnt) + +{ + struct msghdr hdr; + + hdr.msg_iov = iov; + hdr.msg_iovlen = iovcnt; + hdr.msg_accrights = 0; + hdr.msg_accrightslen = 0; + hdr.msg_name = 0; + hdr.msg_namelen = 0; + + return (recvmsg (ciptr->fd, &hdr, 0)); +} + +static int TRANS(WriteV) (XtransConnInfo ciptr, struct iovec *iov, int iovcnt) + +{ + struct msghdr hdr; + + hdr.msg_iov = iov; + hdr.msg_iovlen = iovcnt; + hdr.msg_accrights = 0; + hdr.msg_accrightslen = 0; + hdr.msg_name = 0; + hdr.msg_namelen = 0; + + return (sendmsg (ciptr->fd, &hdr, 0)); +} + +#endif /* CRAY */ + +#if (defined(SYSV) && defined(i386) && !defined(SCO325)) || defined(_WIN32) || defined(__sxg__) || defined(__EMX__) + +/* + * emulate readv + */ + +static int TRANS(ReadV) (XtransConnInfo ciptr, struct iovec *iov, int iovcnt) + +{ + int i, len, total; + char *base; + + ESET(0); + for (i = 0, total = 0; i < iovcnt; i++, iov++) { + len = iov->iov_len; + base = iov->iov_base; + while (len > 0) { + register int nbytes; + nbytes = TRANS(Read) (ciptr, base, len); + if (nbytes < 0 && total == 0) return -1; + if (nbytes <= 0) return total; + ESET(0); + len -= nbytes; + total += nbytes; + base += nbytes; + } + } + return total; +} + +#endif /* SYSV && i386 || _WIN32 || __sxg__ */ + +#if (defined(SYSV) && defined(i386) && !defined(SCO325)) || defined(_WIN32) || defined(__sxg__) || defined(__EMX__) + +/* + * emulate writev + */ + +static int TRANS(WriteV) (XtransConnInfo ciptr, struct iovec *iov, int iovcnt) + +{ + int i, len, total; + char *base; + + ESET(0); + for (i = 0, total = 0; i < iovcnt; i++, iov++) { + len = iov->iov_len; + base = iov->iov_base; + while (len > 0) { + register int nbytes; + nbytes = TRANS(Write) (ciptr, base, len); + if (nbytes < 0 && total == 0) return -1; + if (nbytes <= 0) return total; + ESET(0); + len -= nbytes; + total += nbytes; + base += nbytes; + } + } + return total; +} + +#endif /* SYSV && i386 || _WIN32 || __sxg__ */ + + +#if (defined(_POSIX_SOURCE) && !defined(AIXV3) && !defined(__QNX__)) || defined(hpux) || defined(USG) || defined(SVR4) || defined(SCO) +#ifndef NEED_UTSNAME +#define NEED_UTSNAME +#endif +#include <sys/utsname.h> +#endif + +/* + * TRANS(GetHostname) - similar to gethostname but allows special processing. + */ + +int TRANS(GetHostname) (char *buf, int maxlen) + +{ + int len; + +#ifdef NEED_UTSNAME + struct utsname name; + + uname (&name); + len = strlen (name.nodename); + if (len >= maxlen) len = maxlen - 1; + strncpy (buf, name.nodename, len); + buf[len] = '\0'; +#else + buf[0] = '\0'; + (void) gethostname (buf, maxlen); + buf [maxlen - 1] = '\0'; + len = strlen(buf); +#endif /* NEED_UTSNAME */ + return len; +} diff --git a/dcop/KDE-ICE/Xtrans.h b/dcop/KDE-ICE/Xtrans.h new file mode 100644 index 000000000..95c817fa1 --- /dev/null +++ b/dcop/KDE-ICE/Xtrans.h @@ -0,0 +1,479 @@ +/* $TOG: Xtrans.h /main/31 1998/02/06 15:55:22 kaleb $ */ +/* + +Copyright 1993, 1994, 1998 The Open Group + +All Rights Reserved. + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall +not be used in advertising or otherwise to promote the sale, use or +other dealings in this Software without prior written authorization +from The Open Group. + +*/ +/* $XFree86: xc/lib/xtrans/Xtrans.h,v 3.14 1999/12/13 02:52:54 robin Exp $ */ + +/* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA + * + * All Rights Reserved + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name NCR not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. NCR makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * NCR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _XTRANS_H_ +#define _XTRANS_H_ + +#include "config.h" +#if defined Q_WS_X11 && ! defined K_WS_QTONLY +#include <X11/Xfuncproto.h> +#include <X11/Xos.h> +#else +#include <KDE-ICE/Xfuncproto.h> +#include <fcntl.h> +#endif + +/* + * Set the functions names according to where this code is being compiled. + */ + +#ifdef X11_t +#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP) +#define TRANS(func) _X11Trans##func +#else +#define TRANS(func) _X11Trans/**/func +#endif +#ifdef XTRANSDEBUG +static char* __xtransname = "_X11Trans"; +#endif +#endif /* X11_t */ + +#ifdef XSERV_t +#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP) +#define TRANS(func) _XSERVTrans##func +#else +#define TRANS(func) _XSERVTrans/**/func +#endif +#ifdef XTRANSDEBUG +static char* __xtransname = "_XSERVTrans"; +#endif +#define X11_t +#endif /* X11_t */ + +#ifdef XIM_t +#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP) +#define TRANS(func) _XimXTrans##func +#else +#define TRANS(func) _XimXTrans/**/func +#endif +#ifdef XTRANSDEBUG +static char* __xtransname = "_XimTrans"; +#endif +#endif /* XIM_t */ + +#ifdef FS_t +#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP) +#define TRANS(func) _FSTrans##func +#else +#define TRANS(func) _FSTrans/**/func +#endif +#ifdef XTRANSDEBUG +static char* __xtransname = "_FSTrans"; +#endif +#endif /* FS_t */ + +#ifdef FONT_t +#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP) +#define TRANS(func) _FontTrans##func +#else +#define TRANS(func) _FontTrans/**/func +#endif +#ifdef XTRANSDEBUG +static char* __xtransname = "_FontTrans"; +#endif +#endif /* FONT_t */ + +#ifdef ICE_t +#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP) +#define TRANS(func) _kde_IceTrans##func +#else +#define TRANS(func) _kde_IceTrans/**/func +#endif +#ifdef XTRANSDEBUG +static char* __xtransname = (char *)"_kde_IceTrans"; +#endif +#endif /* ICE_t */ + +#ifdef TEST_t +#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP) +#define TRANS(func) _TESTTrans##func +#else +#define TRANS(func) _TESTTrans/**/func +#endif +#ifdef XTRANSDEBUG +static char* __xtransname = "_TESTTrans"; +#endif +#endif /* TEST_t */ + +#ifdef LBXPROXY_t +#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP) +#define TRANS(func) _LBXPROXYTrans##func +#else +#define TRANS(func) _LBXPROXYTrans/**/func +#endif +#define X11_t /* The server defines this - so should the LBX proxy */ +#ifdef XTRANSDEBUG +static char* __xtransname = "_LBXPROXYTrans"; +#endif +#endif /* LBXPROXY_t */ + +#if !defined(TRANS) +#if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP) +#define TRANS(func) _XTrans##func +#else +#define TRANS(func) _XTrans/**/func +#endif +#ifdef XTRANSDEBUG +static char* __xtransname = "_XTrans"; +#endif +#endif /* !TRANS */ + + +/* + * Create a single address structure that can be used wherever + * an address structure is needed. struct sockaddr is not big enough + * to hold a sockadd_un, so we create this definition to have a single + * structure that is big enough for all the structures we might need. + * + * This structure needs to be independent of the socket/TLI interface used. + */ + +#define XTRANS_MAX_ADDR_LEN 128 /* large enough to hold sun_path */ + +typedef struct { + unsigned char addr[XTRANS_MAX_ADDR_LEN]; +} Xtransaddr; + + +#ifdef LONG64 +typedef int BytesReadable_t; +#else +typedef long BytesReadable_t; +#endif + + +#if defined(_WIN32) || (defined(USG) && !defined(CRAY) && !defined(umips) && !defined(MOTOROLA) && !defined(uniosu) && !defined(__sxg__)) || defined(MINIX) + +/* + * TRANS(Readv) and TRANS(Writev) use struct iovec, normally found + * in Berkeley systems in <sys/uio.h>. See the readv(2) and writev(2) + * manual pages for details. + */ + +struct iovec { + caddr_t iov_base; + int iov_len; +}; + +#else +#ifndef Lynx +#include <sys/uio.h> +#else +#include <uio.h> +#endif +#endif + +typedef struct _XtransConnInfo *XtransConnInfo; + + +/* + * Transport Option definitions + */ + +#define TRANS_NONBLOCKING 1 +#define TRANS_CLOSEONEXEC 2 + + +/* + * Return values of Connect (0 is success) + */ + +#define TRANS_CONNECT_FAILED -1 +#define TRANS_TRY_CONNECT_AGAIN -2 +#define TRANS_IN_PROGRESS -3 + + +/* + * Return values of CreateListener (0 is success) + */ + +#define TRANS_CREATE_LISTENER_FAILED -1 +#define TRANS_ADDR_IN_USE -2 + + +/* + * Return values of Accept (0 is success) + */ + +#define TRANS_ACCEPT_BAD_MALLOC -1 +#define TRANS_ACCEPT_FAILED -2 +#define TRANS_ACCEPT_MISC_ERROR -3 + + +/* + * ResetListener return values + */ + +#define TRANS_RESET_NOOP 1 +#define TRANS_RESET_NEW_FD 2 +#define TRANS_RESET_FAILURE 3 + + +/* + * Function prototypes for the exposed interface + */ + +void TRANS(FreeConnInfo) ( + XtransConnInfo /* ciptr */ +); + +#ifdef TRANS_CLIENT + +XtransConnInfo TRANS(OpenCOTSClient)( + char * /* address */ +); + +#endif /* TRANS_CLIENT */ + +#ifdef TRANS_SERVER + +XtransConnInfo TRANS(OpenCOTSServer)( + char * /* address */ +); + +#endif /* TRANS_SERVER */ + +#ifdef TRANS_CLIENT + +XtransConnInfo TRANS(OpenCLTSClient)( + char * /* address */ +); + +#endif /* TRANS_CLIENT */ + +#ifdef TRANS_SERVER + +XtransConnInfo TRANS(OpenCLTSServer)( + char * /* address */ +); + +#endif /* TRANS_SERVER */ + +#ifdef TRANS_REOPEN + +XtransConnInfo TRANS(ReopenCOTSServer)( + int, /* trans_id */ + int, /* fd */ + char * /* port */ +); + +XtransConnInfo TRANS(ReopenCLTSServer)( + int, /* trans_id */ + int, /* fd */ + char * /* port */ +); + +int TRANS(GetReopenInfo)( + XtransConnInfo, /* ciptr */ + int *, /* trans_id */ + int *, /* fd */ + char ** /* port */ +); + +#endif /* TRANS_REOPEN */ + + +int TRANS(SetOption)( + XtransConnInfo, /* ciptr */ + int, /* option */ + int /* arg */ +); + +#ifdef TRANS_SERVER + +int TRANS(CreateListener)( + XtransConnInfo, /* ciptr */ + char * /* port */ +); + +int TRANS(NoListen) ( + char* /* protocol*/ +); + +int TRANS(ResetListener)( + XtransConnInfo /* ciptr */ +); + +XtransConnInfo TRANS(Accept)( + XtransConnInfo, /* ciptr */ + int * /* status */ +); + +#endif /* TRANS_SERVER */ + +#ifdef TRANS_CLIENT + +int TRANS(Connect)( + XtransConnInfo, /* ciptr */ + char * /* address */ +); + +#endif /* TRANS_CLIENT */ + +int TRANS(BytesReadable)( + XtransConnInfo, /* ciptr */ + BytesReadable_t * /* pend */ +); + +int TRANS(Read)( + XtransConnInfo, /* ciptr */ + char *, /* buf */ + int /* size */ +); + +int TRANS(Write)( + XtransConnInfo, /* ciptr */ + char *, /* buf */ + int /* size */ +); + +int TRANS(Readv)( + XtransConnInfo, /* ciptr */ + struct iovec *, /* buf */ + int /* size */ +); + +int TRANS(Writev)( + XtransConnInfo, /* ciptr */ + struct iovec *, /* buf */ + int /* size */ +); + +int TRANS(Disconnect)( + XtransConnInfo /* ciptr */ +); + +int TRANS(Close)( + XtransConnInfo /* ciptr */ +); + +int TRANS(CloseForCloning)( + XtransConnInfo /* ciptr */ +); + +int TRANS(IsLocal)( + XtransConnInfo /* ciptr */ +); + +int TRANS(GetMyAddr)( + XtransConnInfo, /* ciptr */ + int *, /* familyp */ + int *, /* addrlenp */ + Xtransaddr ** /* addrp */ +); + +int TRANS(GetPeerAddr)( + XtransConnInfo, /* ciptr */ + int *, /* familyp */ + int *, /* addrlenp */ + Xtransaddr ** /* addrp */ +); + +int TRANS(GetConnectionNumber)( + XtransConnInfo /* ciptr */ +); + +#ifdef TRANS_SERVER + +int TRANS(MakeAllCOTSServerListeners)( + char *, /* port */ + int *, /* partial */ + int *, /* count_ret */ + XtransConnInfo ** /* ciptrs_ret */ +); + +int TRANS(MakeAllCLTSServerListeners)( + char *, /* port */ + int *, /* partial */ + int *, /* count_ret */ + XtransConnInfo ** /* ciptrs_ret */ +); + +#endif /* TRANS_SERVER */ + + +/* + * Function Prototypes for Utility Functions. + */ + +#ifdef X11_t + +int TRANS(ConvertAddress)( + int *, /* familyp */ + int *, /* addrlenp */ + Xtransaddr ** /* addrp */ +); + +#endif /* X11_t */ + +#if defined(ICE_t) + +char * +TRANS(GetMyNetworkId)( + XtransConnInfo /* ciptr */ +); + +char * +TRANS(GetPeerNetworkId)( + XtransConnInfo /* ciptr */ +); + +#endif /* ICE_t */ + +int +TRANS(GetHostname) ( + char * /* buf */, + int /* maxlen */ +); + +#if defined(_WIN32) && (defined(TCPCONN) || defined(DNETCONN)) +int TRANS(WSAStartup)(); +#endif + +#endif /* _XTRANS_H_ */ diff --git a/dcop/KDE-ICE/Xtransint.h b/dcop/KDE-ICE/Xtransint.h new file mode 100644 index 000000000..3678e48bf --- /dev/null +++ b/dcop/KDE-ICE/Xtransint.h @@ -0,0 +1,477 @@ +/* $TOG: Xtransint.h /main/27 1998/02/06 15:54:39 kaleb $ */ +/* + +Copyright 1993, 1994, 1998 The Open Group + +All Rights Reserved. + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall +not be used in advertising or otherwise to promote the sale, use or +other dealings in this Software without prior written authorization +from The Open Group. + +*/ +/* $XFree86: xc/lib/xtrans/Xtransint.h,v 3.27 1999/12/27 00:39:28 robin Exp $ */ + +/* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA + * + * All Rights Reserved + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name NCR not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. NCR makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * NCR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _XTRANSINT_H_ +#define _XTRANSINT_H_ + +/* + * XTRANSDEBUG will enable the PRMSG() macros used in the X Transport + * Interface code. Each use of the PRMSG macro has a level associated with + * it. XTRANSDEBUG is defined to be a level. If the invocation level is =< + * the value of XTRANSDEBUG, then the message will be printed out to stderr. + * Recommended levels are: + * + * XTRANSDEBUG=1 Error messages + * XTRANSDEBUG=2 API Function Tracing + * XTRANSDEBUG=3 All Function Tracing + * XTRANSDEBUG=4 printing of intermediate values + * XTRANSDEBUG=5 really detailed stuff +#define XTRANSDEBUG 2 + * + * Defining XTRANSDEBUGTIMESTAMP will cause printing timestamps with each + * message. + */ + +#ifndef __EMX__ +# define XTRANSDEBUG 1 +#else +#define XTRANSDEBUG 1 +#endif + +#ifdef _WIN32 +#define _WILLWINSOCK_ +#endif + +#include "Xtrans.h" + +#ifdef XTRANSDEBUG +#include <stdio.h> +#endif /* XTRANSDEBUG */ + +#include <errno.h> +#ifdef X_NOT_STDC_ENV +extern int errno; /* Internal system error number. */ +#endif + +#ifndef _WIN32 +#ifndef MINIX +#ifndef Lynx +#include <sys/socket.h> +#else +#include <socket.h> +#endif +#include <netinet/in.h> +#include <arpa/inet.h> +#endif +#ifdef __EMX__ +#include <sys/ioctl.h> +#endif + +/* + * Moved the setting of NEED_UTSNAME to this header file from Xtrans.c, + * to avoid a race condition. JKJ (6/5/97) + */ + +#if (defined(_POSIX_SOURCE) && !defined(AIXV3) && !defined(__QNX__)) || defined(hpux) || defined(USG) || defined(SVR4) || defined(SCO) +#ifndef NEED_UTSNAME +#define NEED_UTSNAME +#endif +#include <sys/utsname.h> +#endif + +/* + * makedepend screws up on #undef OPEN_MAX, so we define a new symbol + */ + +#ifndef TRANS_OPEN_MAX + +#ifndef X_NOT_POSIX +#ifdef _POSIX_SOURCE +#include <limits.h> +#else +#define _POSIX_SOURCE +#include <limits.h> +#undef _POSIX_SOURCE +#endif +#endif +#ifndef OPEN_MAX +#ifdef __GNU__ +#define OPEN_MAX (sysconf(_SC_OPEN_MAX)) +#endif +#ifdef SVR4 +#define OPEN_MAX 256 +#else +#include <sys/param.h> +#ifndef OPEN_MAX +#if defined(__OSF1__) || defined(__osf__) +#define OPEN_MAX 256 +#else +#ifdef NOFILE +#define OPEN_MAX NOFILE +#else +#if !defined(__EMX__) && !defined(__QNX__) +#define OPEN_MAX NOFILES_MAX +#else +#define OPEN_MAX 256 +#endif +#endif +#endif +#endif +#endif +#endif +#ifdef __GNU__ +#define TRANS_OPEN_MAX OPEN_MAX +#else /* !__GNU__ */ +#if OPEN_MAX > 256 +#define TRANS_OPEN_MAX 256 +#else +#define TRANS_OPEN_MAX OPEN_MAX +#endif +#endif /*__GNU__*/ + +#endif /* TRANS_OPEN_MAX */ + +#ifdef __EMX__ +#define ESET(val) +#else +#define ESET(val) errno = val +#endif +#define EGET() errno + +#else /* _WIN32 */ + +#include <limits.h> /* for USHRT_MAX */ + +#define ESET(val) WSASetLastError(val) +#define EGET() WSAGetLastError() + +#endif /* _WIN32 */ + +#ifndef NULL +#define NULL 0 +#endif + +#ifdef X11_t +#define X_TCP_PORT 6000 +#endif + +struct _XtransConnInfo { + struct _Xtransport *transptr; + int index; + char *priv; + int flags; + int fd; + char *port; + int family; + char *addr; + int addrlen; + char *peeraddr; + int peeraddrlen; +}; + +#define XTRANS_OPEN_COTS_CLIENT 1 +#define XTRANS_OPEN_COTS_SERVER 2 +#define XTRANS_OPEN_CLTS_CLIENT 3 +#define XTRANS_OPEN_CLTS_SERVER 4 + + +typedef struct _Xtransport { + char *TransName; + int flags; + +#ifdef TRANS_CLIENT + + XtransConnInfo (*OpenCOTSClient)( + struct _Xtransport *, /* transport */ + char *, /* protocol */ + char *, /* host */ + char * /* port */ + ); + +#endif /* TRANS_CLIENT */ + +#ifdef TRANS_SERVER + + XtransConnInfo (*OpenCOTSServer)( + struct _Xtransport *, /* transport */ + char *, /* protocol */ + char *, /* host */ + char * /* port */ + ); + +#endif /* TRANS_SERVER */ + +#ifdef TRANS_CLIENT + + XtransConnInfo (*OpenCLTSClient)( + struct _Xtransport *, /* transport */ + char *, /* protocol */ + char *, /* host */ + char * /* port */ + ); + +#endif /* TRANS_CLIENT */ + +#ifdef TRANS_SERVER + + XtransConnInfo (*OpenCLTSServer)( + struct _Xtransport *, /* transport */ + char *, /* protocol */ + char *, /* host */ + char * /* port */ + ); + +#endif /* TRANS_SERVER */ + + +#ifdef TRANS_REOPEN + + XtransConnInfo (*ReopenCOTSServer)( + struct _Xtransport *, /* transport */ + int, /* fd */ + char * /* port */ + ); + + XtransConnInfo (*ReopenCLTSServer)( + struct _Xtransport *, /* transport */ + int, /* fd */ + char * /* port */ + ); + +#endif /* TRANS_REOPEN */ + + + int (*SetOption)( + XtransConnInfo, /* connection */ + int, /* option */ + int /* arg */ + ); + +#ifdef TRANS_SERVER + + int (*CreateListener)( + XtransConnInfo, /* connection */ + char * /* port */ + ); + + int (*ResetListener)( + XtransConnInfo /* connection */ + ); + + XtransConnInfo (*Accept)( + XtransConnInfo, /* connection */ + int * /* status */ + ); + +#endif /* TRANS_SERVER */ + +#ifdef TRANS_CLIENT + + int (*Connect)( + XtransConnInfo, /* connection */ + char *, /* host */ + char * /* port */ + ); + +#endif /* TRANS_CLIENT */ + + int (*BytesReadable)( + XtransConnInfo, /* connection */ + BytesReadable_t * /* pend */ + ); + + int (*Read)( + XtransConnInfo, /* connection */ + char *, /* buf */ + int /* size */ + ); + + int (*Write)( + XtransConnInfo, /* connection */ + char *, /* buf */ + int /* size */ + ); + + int (*Readv)( + XtransConnInfo, /* connection */ + struct iovec *, /* buf */ + int /* size */ + ); + + int (*Writev)( + XtransConnInfo, /* connection */ + struct iovec *, /* buf */ + int /* size */ + ); + + int (*Disconnect)( + XtransConnInfo /* connection */ + ); + + int (*Close)( + XtransConnInfo /* connection */ + ); + + int (*CloseForCloning)( + XtransConnInfo /* connection */ + ); + +} Xtransport; + + +typedef struct _Xtransport_table { + Xtransport *transport; + int transport_id; +} Xtransport_table; + + +/* + * Flags for the flags member of Xtransport. + */ + +#define TRANS_ALIAS (1<<0) /* record is an alias, don't create server */ +#define TRANS_LOCAL (1<<1) /* local transport */ +#define TRANS_DISABLED (1<<2) /* Don't open this one */ +#define TRANS_NOLISTEN (1<<3) /* Don't listen on this one */ + + +/* + * readv() and writev() don't exist or don't work correctly on some + * systems, so they may be emulated. + */ + +#if defined(CRAY) || (defined(SYSV) && defined(i386) && !defined(SCO325)) || defined(_WIN32) || defined(__sxg__) || defined(__EMX__) + +#define READV(ciptr, iov, iovcnt) TRANS(ReadV)(ciptr, iov, iovcnt) + +static int TRANS(ReadV)( + XtransConnInfo, /* ciptr */ + struct iovec *, /* iov */ + int /* iovcnt */ +); + +#else + +#define READV(ciptr, iov, iovcnt) readv(ciptr->fd, iov, iovcnt) + +#endif /* CRAY || (SYSV && i386) || _WIN32 || __sxg__ || */ + + +#if defined(CRAY) || (defined(SYSV) && defined(i386) && !defined(SCO325)) || defined(_WIN32) || defined(__sxg__) || defined(__EMX__) + +#define WRITEV(ciptr, iov, iovcnt) TRANS(WriteV)(ciptr, iov, iovcnt) + +static int TRANS(WriteV)( + XtransConnInfo, /* ciptr */ + struct iovec *, /* iov */ + int /* iovcnt */ +); + +#else + +#define WRITEV(ciptr, iov, iovcnt) writev(ciptr->fd, iov, iovcnt) + +#endif /* CRAY || _WIN32 || __sxg__ */ + + +static int is_numeric ( + char * /* str */ +); + +#ifdef TRANS_SERVER +static int trans_mkdir ( + char *, /* path */ + int /* mode */ +); +#endif + +/* + * Some XTRANSDEBUG stuff + */ + +#if defined(XTRANSDEBUG) +/* add hack to the format string to avoid warnings about extra arguments + * to fprintf. + */ +#ifdef XTRANSDEBUGTIMESTAMP +#if defined(XSERV_t) && defined(TRANS_SERVER) +/* Use ErrorF() for the X server */ +#define PRMSG(lvl,x,a,b,c) if (lvl <= XTRANSDEBUG){ \ + int hack= 0, saveerrno=errno; \ + struct timeval tp;\ + gettimeofday(&tp,0); \ + ErrorF(__xtransname); \ + ErrorF(x+hack,a,b,c); \ + ErrorF("timestamp (ms): %d\n",tp.tv_sec*1000+tp.tv_usec/1000); \ + errno=saveerrno; \ + } else ((void)0) +#else +#define PRMSG(lvl,x,a,b,c) if (lvl <= XTRANSDEBUG){ \ + int hack= 0, saveerrno=errno; \ + struct timeval tp;\ + gettimeofday(&tp,0); \ + fprintf(stderr, __xtransname); fflush(stderr); \ + fprintf(stderr, x+hack,a,b,c); fflush(stderr); \ + fprintf(stderr, "timestamp (ms): %d\n",tp.tv_sec*1000+tp.tv_usec/1000); \ + fflush(stderr); \ + errno=saveerrno; \ + } else ((void)0) +#endif /* XSERV_t && TRANS_SERVER */ +#else /* XTRANSDEBUGTIMESTAMP */ +#if defined(XSERV_t) && defined(TRANS_SERVER) +/* Use ErrorF() for the X server */ +#define PRMSG(lvl,x,a,b,c) if (lvl <= XTRANSDEBUG){ \ + int hack= 0, saveerrno=errno; \ + ErrorF(__xtransname); \ + ErrorF(x+hack,a,b,c); \ + errno=saveerrno; \ + } else ((void)0) +#else +#define PRMSG(lvl,x,a,b,c) if (lvl <= XTRANSDEBUG){ \ + int hack= 0, saveerrno=errno; \ + fprintf(stderr, (const char*)(x+hack),a,b,c); fflush(stderr); \ + errno=saveerrno; \ + } else ((void)0) +#endif /* XSERV_t && TRANS_SERVER */ +#endif /* XTRANSDEBUGTIMESTAMP */ +#else +#define PRMSG(lvl,x,a,b,c) ((void)0) +#endif /* XTRANSDEBUG */ + +#endif /* _XTRANSINT_H_ */ diff --git a/dcop/KDE-ICE/Xtranssock.c b/dcop/KDE-ICE/Xtranssock.c new file mode 100644 index 000000000..100d218b1 --- /dev/null +++ b/dcop/KDE-ICE/Xtranssock.c @@ -0,0 +1,1990 @@ +/* $TOG: Xtranssock.c /main/61 1998/02/06 15:54:53 kaleb $ */ +/* + +Copyright 1993, 1994, 1998 The Open Group + +All Rights Reserved. + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall +not be used in advertising or otherwise to promote the sale, use or +other dealings in this Software without prior written authorization +from The Open Group. + +*/ +/* $XFree86: xc/lib/xtrans/Xtranssock.c,v 3.45 1999/12/27 00:39:29 robin Exp $ */ + +/* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA + * + * All Rights Reserved + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name NCR not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. NCR makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * NCR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <ctype.h> +#include <unistd.h> +#include <stdlib.h> +#include <stdio.h> +#ifndef _WIN32 + +#if defined(TCPCONN) || defined(UNIXCONN) +#include <netinet/in.h> +#else +#ifdef ESIX +#include <lan/in.h> +#endif +#endif +#if defined(TCPCONN) || defined(UNIXCONN) +#include <netdb.h> +#endif + +#ifdef UNIXCONN +#ifndef X_NO_SYS_UN +#ifndef Lynx +#include <sys/un.h> +#else +#include <un.h> +#endif +#endif +#include <sys/stat.h> +#endif + +#if defined(hpux) || defined(__EMX__) +#define NO_TCP_H +#endif /* hpux */ +#ifdef MOTOROLA +#ifdef SYSV +#define NO_TCP_H +#endif /* SYSV */ +#endif /* MOTOROLA */ +#ifndef NO_TCP_H +#ifdef __osf__ +#include <sys/param.h> +#endif /* osf */ +#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) +#include <machine/endian.h> +#endif /* __NetBSD__ || __OpenBSD__ || __FreeBSD__ */ +#include <netinet/tcp.h> +#endif /* !NO_TCP_H */ +#include <sys/ioctl.h> +#if (defined(SVR4) || defined(__SVR4)) && !defined(SCO325) && !defined(DGUX) +#include <sys/filio.h> +#endif +#if (defined(i386) && defined(SYSV)) || defined(_SEQUENT_) +#if !defined(_SEQUENT_) && !defined(ESIX) && !defined(sco) +#include <net/errno.h> +#endif /* _SEQUENT_ || ESIX || SCO */ +#if !defined(ISC) || !defined(I_NREAD) || defined(SCO325) +#include <sys/stropts.h> +#endif +#endif /* i386 && SYSV || _SEQUENT_ */ + +#else /* !_WIN32 */ + +#ifdef _WIN32 +#if !defined(WIN32_LEAN_AND_MEAN) +#define WIN32_LEAN_AND_MEAN +#endif +#include <winsock2.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <io.h> +#else +#include <X11/Xwinsock.h> +#include <X11/Xw32defs.h> +#endif +#undef close +#define close closesocket +#define ECONNREFUSED WSAECONNREFUSED +#define EADDRINUSE WSAEADDRINUSE +#define EPROTOTYPE WSAEPROTOTYPE +#define EINPROGRESS WSAEINPROGRESS +#undef EWOULDBLOCK +#define EWOULDBLOCK WSAEWOULDBLOCK +#undef EINTR +#define EINTR WSAEINTR +#include <netdb.h> +#endif /* _WIN32 */ + +#if defined(SO_DONTLINGER) && defined(SO_LINGER) +#undef SO_DONTLINGER +#endif + +#if defined(__EMX__) +#if defined(NOT_EMX09A) +static int IBMsockInit = 0; +#define SocketInitOnce()\ + if (!IBMsockInit) {\ + sock_init();\ + IBMsockInit = 1;\ + } +#undef EINTR +#define EINTR SOCEINTR +#undef EINVAL +#define EINVAL SOCEINVAL +#undef errno +#define errno sock_errno() +#undef close +#define close soclose +#undef ioctl +#define ioctl sockioctl +#else +#define SocketInitOnce() /**/ +#endif +/* this is still not there */ +#define SOCKET int +#else +/* others don't need this */ +#define SocketInitOnce() /**/ +#endif + +#define MIN_BACKLOG 128 +#ifdef SOMAXCONN +#if SOMAXCONN > MIN_BACKLOG +#define BACKLOG SOMAXCONN +#endif +#endif +#ifndef BACKLOG +#define BACKLOG MIN_BACKLOG +#endif +/* + * This is the Socket implementation of the X Transport service layer + * + * This file contains the implementation for both the UNIX and INET domains, + * and can be built for either one, or both. + * + */ + +typedef struct _Sockettrans2dev { + char *transname; + int family; + int devcotsname; + int devcltsname; + int protocol; +} Sockettrans2dev; + +static Sockettrans2dev Sockettrans2devtab[] = { +#ifdef TCPCONN + {(char *)"inet",AF_INET,SOCK_STREAM,SOCK_DGRAM,0}, + {(char *)"tcp",AF_INET,SOCK_STREAM,SOCK_DGRAM,0}, +#endif /* TCPCONN */ +#ifdef UNIXCONN + {(char *)"unix",AF_UNIX,SOCK_STREAM,SOCK_DGRAM,0}, +#if !defined(LOCALCONN) + {(char *)"local",AF_UNIX,SOCK_STREAM,SOCK_DGRAM,0}, +#endif /* !LOCALCONN */ +#endif /* UNIXCONN */ +}; + +#define NUMSOCKETFAMILIES (sizeof(Sockettrans2devtab)/sizeof(Sockettrans2dev)) + + +#ifdef UNIXCONN + +#ifdef hpux + +#if defined(X11_t) +#define UNIX_PATH "/usr/spool/sockets/X11/" +#define UNIX_DIR "/usr/spool/sockets/X11" +#define OLD_UNIX_PATH "/tmp/.X11-unix/X" +#endif /* X11_t */ +#if defined(XIM_t) +#define UNIX_PATH "/usr/spool/sockets/XIM/" +#define UNIX_DIR "/usr/spool/sockets/XIM" +#define OLD_UNIX_PATH "/tmp/.XIM-unix/XIM" +#endif /* XIM_t */ +#if defined(FS_t) || defined(FONT_t) +#define UNIX_PATH "/usr/spool/sockets/fontserv/" +#define UNIX_DIR "/usr/spool/sockets/fontserv" +#endif /* FS_t || FONT_t */ +#if defined(ICE_t) +#define UNIX_PATH "/usr/spool/sockets/ICE/" +#define UNIX_DIR "/usr/spool/sockets/ICE" +#endif /* ICE_t */ +#if defined(TEST_t) +#define UNIX_PATH "/usr/spool/sockets/xtrans_test/" +#define UNIX_DIR "/usr/spool/sockets/xtrans_test" +#endif +#if defined(LBXPROXY_t) +#define UNIX_PATH "/usr/spool/sockets/X11/" +#define UNIX_DIR "/usr/spool/sockets/X11" +#endif + +#else /* !hpux */ + +#if defined(X11_t) +#define UNIX_PATH "/tmp/.X11-unix/X" +#define UNIX_DIR "/tmp/.X11-unix" +#endif /* X11_t */ +#if defined(XIM_t) +#define UNIX_PATH "/tmp/.XIM-unix/XIM" +#define UNIX_DIR "/tmp/.XIM-unix" +#endif /* XIM_t */ +#if defined(FS_t) || defined(FONT_t) +#define UNIX_PATH "/tmp/.font-unix/fs" +#define UNIX_DIR "/tmp/.font-unix" +#endif /* FS_t || FONT_t */ +#if defined(ICE_t) +#define UNIX_PATH "/tmp/.ICE-unix/" +#define UNIX_DIR "/tmp/.ICE-unix" +#endif /* ICE_t */ +#if defined(TEST_t) +#define UNIX_PATH "/tmp/.Test-unix/test" +#define UNIX_DIR "/tmp/.Test-unix" +#endif +#if defined(LBXPROXY_t) +#define UNIX_PATH "/tmp/.X11-unix/X" +#define UNIX_DIR "/tmp/.X11-unix" +#endif + +#endif /* hpux */ + +#endif /* UNIXCONN */ + +#define PORTBUFSIZE 32 + +/* + * These are some utility function used by the real interface function below. + */ + +static int +TRANS(SocketSelectFamily) (char *family) + +{ + int i; + + PRMSG (3,(const char*)"SocketSelectFamily(%s)\n", family, 0, 0); + + for (i = 0; i < (int) NUMSOCKETFAMILIES;i++) + { + if (!strcmp (family, Sockettrans2devtab[i].transname)) + return i; + } + + return -1; +} + + +/* + * This function gets the local address of the socket and stores it in the + * XtransConnInfo structure for the connection. + */ +#ifdef TCPCONN +static int +TRANS(SocketINETGetAddr) (XtransConnInfo ciptr) + +{ + struct sockaddr_in sockname; +#if defined(SVR4) || defined(SCO325) + size_t namelen = sizeof sockname; +#else + int namelen = sizeof sockname; +#endif + + PRMSG (3,"SocketINETGetAddr(%x)\n", ciptr, 0, 0); + + if (getsockname (ciptr->fd,(struct sockaddr *) &sockname, &namelen) < 0) + { + PRMSG (1,"SocketINETGetAddr: getsockname() failed: %d\n", + EGET(),0, 0); + return -1; + } + + /* + * Everything looks good: fill in the XtransConnInfo structure. + */ + + if ((ciptr->addr = (char *) xalloc (namelen)) == NULL) + { + PRMSG (1, + "SocketINETGetAddr: Can't allocate space for the addr\n", + 0, 0, 0); + return -1; + } + + ciptr->family = sockname.sin_family; + ciptr->addrlen = namelen; + memcpy (ciptr->addr, &sockname, ciptr->addrlen); + + return 0; +} + + +/* + * This function gets the remote address of the socket and stores it in the + * XtransConnInfo structure for the connection. + */ + +static int +TRANS(SocketINETGetPeerAddr) (XtransConnInfo ciptr) + +{ + struct sockaddr_in sockname; +#if defined(SVR4) || defined(SCO325) + size_t namelen = sizeof sockname; +#else + int namelen = sizeof sockname; +#endif + + PRMSG (3,"SocketINETGetPeerAddr(%x)\n", ciptr, 0, 0); + + if (getpeername (ciptr->fd, (struct sockaddr *) &sockname, &namelen) < 0) + { + PRMSG (1,"SocketINETGetPeerAddr: getpeername() failed: %d\n", + EGET(), 0, 0); + return -1; + } + + /* + * Everything looks good: fill in the XtransConnInfo structure. + */ + + if ((ciptr->peeraddr = (char *) xalloc (namelen)) == NULL) + { + PRMSG (1, + "SocketINETGetPeerAddr: Can't allocate space for the addr\n", + 0, 0, 0); + return -1; + } + + ciptr->peeraddrlen = namelen; + memcpy (ciptr->peeraddr, &sockname, ciptr->peeraddrlen); + + return 0; +} +#endif /* TCPCONN */ + +static XtransConnInfo +TRANS(SocketOpen) (int i, int type) + +{ + XtransConnInfo ciptr; + + PRMSG (3,"SocketOpen(%d,%d)\n", i, type, 0); + + if ((ciptr = (XtransConnInfo) xcalloc ( + 1, sizeof(struct _XtransConnInfo))) == NULL) + { + PRMSG (1, "SocketOpen: malloc failed\n", 0, 0, 0); + return NULL; + } + + if ((ciptr->fd = socket(Sockettrans2devtab[i].family, type, + Sockettrans2devtab[i].protocol)) < 0 + ) { + PRMSG (1, "SocketOpen: socket() failed for %s\n", + Sockettrans2devtab[i].transname, 0, 0); + + xfree ((char *) ciptr); + return NULL; + } + +#ifdef TCP_NODELAY + if (Sockettrans2devtab[i].family == AF_INET) + { + /* + * turn off TCP coalescence for INET sockets + */ + + int tmp = 1; + setsockopt (ciptr->fd, IPPROTO_TCP, TCP_NODELAY, + (char *) &tmp, sizeof (int)); + } +#endif + + return ciptr; +} + + +#ifdef TRANS_REOPEN + +static XtransConnInfo +TRANS(SocketReopen) (int i, int type, int fd, char *port) + +{ + XtransConnInfo ciptr; + + PRMSG (3,"SocketReopen(%d,%d,%s)\n", type, fd, port); + + if ((ciptr = (XtransConnInfo) xcalloc ( + 1, sizeof(struct _XtransConnInfo))) == NULL) + { + PRMSG (1, "SocketReopen: malloc failed\n", 0, 0, 0); + return NULL; + } + + ciptr->fd = fd; + + return ciptr; +} + +#endif /* TRANS_REOPEN */ + + +/* + * These functions are the interface supplied in the Xtransport structure + */ + +#ifdef TRANS_CLIENT + +static XtransConnInfo +TRANS(SocketOpenCOTSClient) (Xtransport *thistrans, char *protocol, + char *host, char *port) + +{ + XtransConnInfo ciptr; + int i; + + PRMSG (2, "SocketOpenCOTSClient(%s,%s,%s)\n", + protocol, host, port); + + SocketInitOnce(); + + if ((i = TRANS(SocketSelectFamily) (thistrans->TransName)) < 0) + { + PRMSG (1, + "SocketOpenCOTSClient: Unable to determine socket type for %s\n", + thistrans->TransName, 0, 0); + return NULL; + } + + if ((ciptr = TRANS(SocketOpen) ( + i, Sockettrans2devtab[i].devcotsname)) == NULL) + { + PRMSG (1,"SocketOpenCOTSClient: Unable to open socket for %s\n", + thistrans->TransName, 0, 0); + return NULL; + } + + /* Save the index for later use */ + + ciptr->index = i; + + return ciptr; +} + +#endif /* TRANS_CLIENT */ + + +#ifdef TRANS_SERVER + +static XtransConnInfo +TRANS(SocketOpenCOTSServer) (Xtransport *thistrans, char *protocol, + char *host, char *port) + +{ + XtransConnInfo ciptr; + int i; + + PRMSG (2,"SocketOpenCOTSServer(%s,%s,%s)\n", protocol, host, port); + + SocketInitOnce(); + + if ((i = TRANS(SocketSelectFamily) (thistrans->TransName)) < 0) + { + PRMSG (1, + "SocketOpenCOTSServer: Unable to determine socket type for %s\n", + thistrans->TransName, 0, 0); + return NULL; + } + + if ((ciptr = TRANS(SocketOpen) ( + i, Sockettrans2devtab[i].devcotsname)) == NULL) + { + PRMSG (1,"SocketOpenCOTSServer: Unable to open socket for %s\n", + thistrans->TransName, 0, 0); + return NULL; + } + + /* + * Using this prevents the bind() check for an existing server listening + * on the same port, but it is required for other reasons. + */ +#ifdef SO_REUSEADDR + + /* + * SO_REUSEADDR only applied to AF_INET + */ + + if (Sockettrans2devtab[i].family == AF_INET) + { + int one = 1; + setsockopt (ciptr->fd, SOL_SOCKET, SO_REUSEADDR, + (char *) &one, sizeof (int)); + } +#endif + + /* Save the index for later use */ + + ciptr->index = i; + + return ciptr; +} + +#endif /* TRANS_SERVER */ + + +#ifdef TRANS_CLIENT + +static XtransConnInfo +TRANS(SocketOpenCLTSClient) (Xtransport *thistrans, char *protocol, + char *host, char *port) + +{ + XtransConnInfo ciptr; + int i; + + PRMSG (2,"SocketOpenCLTSClient(%s,%s,%s)\n", protocol, host, port); + + SocketInitOnce(); + + if ((i = TRANS(SocketSelectFamily) (thistrans->TransName)) < 0) + { + PRMSG (1, + "SocketOpenCLTSClient: Unable to determine socket type for %s\n", + thistrans->TransName, 0, 0); + return NULL; + } + + if ((ciptr = TRANS(SocketOpen) ( + i, Sockettrans2devtab[i].devcotsname)) == NULL) + { + PRMSG (1,"SocketOpenCLTSClient: Unable to open socket for %s\n", + thistrans->TransName, 0, 0); + return NULL; + } + + /* Save the index for later use */ + + ciptr->index = i; + + return ciptr; +} + +#endif /* TRANS_CLIENT */ + + +#ifdef TRANS_SERVER + +static XtransConnInfo +TRANS(SocketOpenCLTSServer) (Xtransport *thistrans, char *protocol, + char *host, char *port) + +{ + XtransConnInfo ciptr; + int i; + + PRMSG (2,"SocketOpenCLTSServer(%s,%s,%s)\n", protocol, host, port); + + SocketInitOnce(); + + if ((i = TRANS(SocketSelectFamily) (thistrans->TransName)) < 0) + { + PRMSG (1, + "SocketOpenCLTSServer: Unable to determine socket type for %s\n", + thistrans->TransName, 0, 0); + return NULL; + } + + if ((ciptr = TRANS(SocketOpen) ( + i, Sockettrans2devtab[i].devcotsname)) == NULL) + { + PRMSG (1,"SocketOpenCLTSServer: Unable to open socket for %s\n", + thistrans->TransName, 0, 0); + return NULL; + } + + /* Save the index for later use */ + + ciptr->index = i; + + return ciptr; +} + +#endif /* TRANS_SERVER */ + + +#ifdef TRANS_REOPEN + +static XtransConnInfo +TRANS(SocketReopenCOTSServer) (Xtransport *thistrans, int fd, char *port) + +{ + XtransConnInfo ciptr; + int i; + + PRMSG (2, + "SocketReopenCOTSServer(%d, %s)\n", fd, port, 0); + + SocketInitOnce(); + + if ((i = TRANS(SocketSelectFamily) (thistrans->TransName)) < 0) + { + PRMSG (1, + "SocketReopenCOTSServer: Unable to determine socket type for %s\n", + thistrans->TransName, 0, 0); + return NULL; + } + + if ((ciptr = TRANS(SocketReopen) ( + i, Sockettrans2devtab[i].devcotsname, fd, port)) == NULL) + { + PRMSG (1, + "SocketReopenCOTSServer: Unable to reopen socket for %s\n", + thistrans->TransName, 0, 0); + return NULL; + } + + /* Save the index for later use */ + + ciptr->index = i; + + return ciptr; +} + +static XtransConnInfo +TRANS(SocketReopenCLTSServer) (Xtransport *thistrans, int fd, char *port) + +{ + XtransConnInfo ciptr; + int i; + + PRMSG (2, + "SocketReopenCLTSServer(%d, %s)\n", fd, port, 0); + + SocketInitOnce(); + + if ((i = TRANS(SocketSelectFamily) (thistrans->TransName)) < 0) + { + PRMSG (1, + "SocketReopenCLTSServer: Unable to determine socket type for %s\n", + thistrans->TransName, 0, 0); + return NULL; + } + + if ((ciptr = TRANS(SocketReopen) ( + i, Sockettrans2devtab[i].devcotsname, fd, port)) == NULL) + { + PRMSG (1, + "SocketReopenCLTSServer: Unable to reopen socket for %s\n", + thistrans->TransName, 0, 0); + return NULL; + } + + /* Save the index for later use */ + + ciptr->index = i; + + return ciptr; +} + +#endif /* TRANS_REOPEN */ + + +static int +TRANS(SocketSetOption) (XtransConnInfo ciptr, int option, int arg) + +{ + PRMSG (2,"SocketSetOption(%d,%d,%d)\n", ciptr->fd, option, arg); + + return -1; +} + +#ifdef UNIXCONN +static int +set_sun_path(const char *port, const char *upath, char *path) +{ + struct sockaddr_un s; + unsigned int maxlen = sizeof(s.sun_path) - 1; + + if (!port || !*port || !path) + return -1; + + if (*port == '/') { /* a full pathname */ + if (strlen(port) > maxlen) + return -1; + sprintf(path, "%s", port); + } else { + if (strlen(port) + strlen(upath) > maxlen) + return -1; + sprintf(path, "%s%s", upath, port); + } + return 0; +} +#endif + +#ifdef TRANS_SERVER + +static int +TRANS(SocketCreateListener) (XtransConnInfo ciptr, + struct sockaddr *sockname, int socknamelen) + +{ + int namelen = socknamelen; + int fd = ciptr->fd; + int retry; + + PRMSG (3, "SocketCreateListener(%x,%d)\n", ciptr, fd, 0); + + if (Sockettrans2devtab[ciptr->index].family == AF_INET) + retry = 20; + else + retry = 0; + + while (bind (fd, (struct sockaddr *) sockname, namelen) < 0) + { + if (errno == EADDRINUSE) + return TRANS_ADDR_IN_USE; + + if (retry-- == 0) { + PRMSG (1, "SocketCreateListener: failed to bind listener\n", + 0, 0, 0); + close (fd); + return TRANS_CREATE_LISTENER_FAILED; + } +#ifdef SO_REUSEADDR + sleep (1); +#else + sleep (10); +#endif /* SO_REUSEDADDR */ + } + + if (Sockettrans2devtab[ciptr->index].family == AF_INET) { +#ifdef SO_DONTLINGER + setsockopt (fd, SOL_SOCKET, SO_DONTLINGER, (char *) NULL, 0); +#else +#ifdef SO_LINGER + { + static int linger[2] = { 0, 0 }; + setsockopt (fd, SOL_SOCKET, SO_LINGER, + (char *) linger, sizeof (linger)); + } +#endif +#endif +} + + if (listen (fd, BACKLOG) < 0) + { + PRMSG (1, "SocketCreateListener: listen() failed\n", 0, 0, 0); + close (fd); + return TRANS_CREATE_LISTENER_FAILED; + } + + /* Set a flag to indicate that this connection is a listener */ + + ciptr->flags = 1; + + return 0; +} + +#ifdef TCPCONN +static int +TRANS(SocketINETCreateListener) (XtransConnInfo ciptr, char *port) + +{ + struct sockaddr_in sockname; + int namelen = sizeof(sockname); + int status; + long tmpport; + struct servent *servp; + +#ifdef X11_t + char portbuf[PORTBUFSIZE]; +#endif + + PRMSG (2, "SocketINETCreateListener(%s)\n", port, 0, 0); + +#ifdef X11_t + /* + * X has a well known port, that is transport dependent. It is easier + * to handle it here, than try and come up with a transport independent + * representation that can be passed in and resolved the usual way. + * + * The port that is passed here is really a string containing the idisplay + * from ConnectDisplay(). + */ + + if (is_numeric (port)) + { + /* fixup the server port address */ + tmpport = X_TCP_PORT + strtol (port, (char**)NULL, 10); + sprintf (portbuf,"%lu", tmpport); + port = portbuf; + } +#endif + + if (port && *port) + { + /* Check to see if the port string is just a number (handles X11) */ + + if (!is_numeric (port)) + { + if ((servp = getservbyname (port,"tcp")) == NULL) + { + PRMSG (1, + "SocketINETCreateListener: Unable to get service for %s\n", + port, 0, 0); + return TRANS_CREATE_LISTENER_FAILED; + } + /* we trust getservbyname to return a valid number */ + sockname.sin_port = htons (servp->s_port); + } + else + { + tmpport = strtol (port, (char**)NULL, 10); + /* + * check that somehow the port address isn't negative or in + * the range of reserved port addresses. This can happen and + * be very bad if the server is suid-root and the user does + * something (dumb) like `X :60049`. + */ + if (tmpport < 1024 || tmpport > USHRT_MAX) + return TRANS_CREATE_LISTENER_FAILED; + + sockname.sin_port = htons (((unsigned short) tmpport)); + } + } + else + sockname.sin_port = htons (0); + +#ifdef BSD44SOCKETS + sockname.sin_len = sizeof (sockname); +#endif + sockname.sin_family = AF_INET; + sockname.sin_addr.s_addr = htonl (INADDR_ANY); + + if ((status = TRANS(SocketCreateListener) (ciptr, + (struct sockaddr *) &sockname, namelen)) < 0) + { + PRMSG (1, + "SocketINETCreateListener: ...SocketCreateListener() failed\n", + 0, 0, 0); + return status; + } + + if (TRANS(SocketINETGetAddr) (ciptr) < 0) + { + PRMSG (1, + "SocketINETCreateListener: ...SocketINETGetAddr() failed\n", + 0, 0, 0); + return TRANS_CREATE_LISTENER_FAILED; + } + + return 0; +} + +#endif /* SOCKCONN */ + + +#ifdef UNIXCONN + +static int +TRANS(SocketUNIXCreateListener) (XtransConnInfo ciptr, char *port) + +{ + struct sockaddr_un sockname; + int namelen; + int oldUmask; + int status; + unsigned int mode; + + PRMSG (2, "SocketUNIXCreateListener(%s)\n", + port ? port : "NULL", 0, 0); + + /* Make sure the directory is created */ + + oldUmask = umask (0); + +#ifdef UNIX_DIR +#ifdef HAS_STICKY_DIR_BIT + mode = 01777; +#else + mode = 0777; +#endif + if (trans_mkdir((char*)UNIX_DIR, mode) == -1) { + PRMSG (1, "SocketUNIXCreateListener: mkdir(%s) failed, errno = %d\n", + UNIX_DIR, errno, 0); + (void) umask (oldUmask); + return TRANS_CREATE_LISTENER_FAILED; + } +#endif + + sockname.sun_family = AF_UNIX; + + if (port && *port) { + if (set_sun_path(port, UNIX_PATH, sockname.sun_path) != 0) { + PRMSG (1, "SocketUNIXCreateListener: path too long\n", 0, 0, 0); + return TRANS_CREATE_LISTENER_FAILED; + } + } else { + sprintf (sockname.sun_path, "%s%d", UNIX_PATH, getpid()); + } + + namelen = sizeof( sockname ) - sizeof( sockname.sun_path ) + strlen( sockname.sun_path ) + 1; +#if defined(BSD44SOCKETS) + sockname.sun_len = namelen; +#endif + + unlink (sockname.sun_path); + (void) umask (oldUmask); + + if ((status = TRANS(SocketCreateListener) (ciptr, + (struct sockaddr *) &sockname, namelen)) < 0) + { + PRMSG (1, + "SocketUNIXCreateListener: ...SocketCreateListener() failed\n", + 0, 0, 0); + return status; + } + + /* + * Now that the listener is esablished, create the addr info for + * this connection. getpeername() doesn't work for UNIX Domain Sockets + * on some systems (hpux at least), so we will just do it manually, instead + * of calling something like TRANS(SocketUNIXGetAddr). + */ + + namelen = sizeof (sockname); /* this will always make it the same size */ + + if ((ciptr->addr = (char *) xalloc (namelen)) == NULL) + { + PRMSG (1, + "SocketUNIXCreateListener: Can't allocate space for the addr\n", + 0, 0, 0); + return TRANS_CREATE_LISTENER_FAILED; + } + + ciptr->family = sockname.sun_family; + ciptr->addrlen = namelen; + memcpy (ciptr->addr, &sockname, ciptr->addrlen); + + return 0; +} + + +static int +TRANS(SocketUNIXResetListener) (XtransConnInfo ciptr) + +{ + /* + * See if the unix domain socket has disappeared. If it has, recreate it. + */ + + struct sockaddr_un *unsock = (struct sockaddr_un *) ciptr->addr; + struct stat statb; + int status = TRANS_RESET_NOOP; + unsigned int mode; + + PRMSG (3, "SocketUNIXResetListener(%x,%d)\n", ciptr, ciptr->fd, 0); + + if (stat (unsock->sun_path, &statb) == -1 || + ((statb.st_mode & S_IFMT) != +#if (defined (sun) && defined(SVR4)) || defined(NCR) || defined(SCO) || defined(sco) || !defined(S_IFSOCK) + S_IFIFO)) +#else + S_IFSOCK)) +#endif + { + int oldUmask = umask (0); + +#ifdef UNIX_DIR +#ifdef HAS_STICKY_DIR_BIT + mode = 01777; +#else + mode = 0777; +#endif + if (trans_mkdir((char*)UNIX_DIR, mode) == -1) { + PRMSG (1, "SocketUNIXResetListener: mkdir(%s) failed, errno = %d\n", + UNIX_DIR, errno, 0); + (void) umask (oldUmask); + return TRANS_RESET_FAILURE; + } +#endif + + close (ciptr->fd); + unlink (unsock->sun_path); + + if ((ciptr->fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) + { + TRANS(FreeConnInfo) (ciptr); + (void) umask (oldUmask); + return TRANS_RESET_FAILURE; + } + + if (bind (ciptr->fd, (struct sockaddr *) unsock, ciptr->addrlen) < 0) + { + close (ciptr->fd); + TRANS(FreeConnInfo) (ciptr); + return TRANS_RESET_FAILURE; + } + + if (listen (ciptr->fd, BACKLOG) < 0) + { + close (ciptr->fd); + TRANS(FreeConnInfo) (ciptr); + (void) umask (oldUmask); + return TRANS_RESET_FAILURE; + } + + umask (oldUmask); + + status = TRANS_RESET_NEW_FD; + } + + return status; +} + +#endif /* UNIXCONN */ + + +#ifdef TCPCONN + +static XtransConnInfo +TRANS(SocketINETAccept) (XtransConnInfo ciptr, int *status) + +{ + XtransConnInfo newciptr; + struct sockaddr_in sockname; +#if defined(SVR4) || defined(SCO325) + size_t namelen = sizeof sockname; +#else + int namelen = sizeof(sockname); +#endif + + PRMSG (2, "SocketINETAccept(%p,%d)\n", ciptr, ciptr->fd, 0); + + if ((newciptr = (XtransConnInfo) xcalloc ( + 1, sizeof(struct _XtransConnInfo))) == NULL) + { + PRMSG (1, "SocketINETAccept: malloc failed\n", 0, 0, 0); + *status = TRANS_ACCEPT_BAD_MALLOC; + return NULL; + } + + if ((newciptr->fd = accept (ciptr->fd, + (struct sockaddr *) &sockname, &namelen)) < 0) + { + PRMSG (1, "SocketINETAccept: accept() failed\n", 0, 0, 0); + xfree (newciptr); + *status = TRANS_ACCEPT_FAILED; + return NULL; + } + +#ifdef TCP_NODELAY + { + /* + * turn off TCP coalescence for INET sockets + */ + + int tmp = 1; + setsockopt (newciptr->fd, IPPROTO_TCP, TCP_NODELAY, + (char *) &tmp, sizeof (int)); + } +#endif + + /* + * Get this address again because the transport may give a more + * specific address now that a connection is established. + */ + + if (TRANS(SocketINETGetAddr) (newciptr) < 0) + { + PRMSG (1, + "SocketINETAccept: ...SocketINETGetAddr() failed:\n", + 0, 0, 0); + close (newciptr->fd); + xfree (newciptr); + *status = TRANS_ACCEPT_MISC_ERROR; + return NULL; + } + + if (TRANS(SocketINETGetPeerAddr) (newciptr) < 0) + { + PRMSG (1, + "SocketINETAccept: ...SocketINETGetPeerAddr() failed:\n", + 0, 0, 0); + close (newciptr->fd); + if (newciptr->addr) xfree (newciptr->addr); + xfree (newciptr); + *status = TRANS_ACCEPT_MISC_ERROR; + return NULL; + } + + *status = 0; + + return newciptr; +} + +#endif /* TCPCONN */ + + +#ifdef UNIXCONN +static XtransConnInfo +TRANS(SocketUNIXAccept) (XtransConnInfo ciptr, int *status) + +{ + XtransConnInfo newciptr; + struct sockaddr_un sockname; +#if defined(SVR4) || defined(SCO325) + size_t namelen = sizeof sockname; +#else + int namelen = sizeof sockname; +#endif + + PRMSG (2, "SocketUNIXAccept(%p,%d)\n", ciptr, ciptr->fd, 0); + + if ((newciptr = (XtransConnInfo) xcalloc ( + 1, sizeof(struct _XtransConnInfo))) == NULL) + { + PRMSG (1, "SocketUNIXAccept: malloc() failed\n", 0, 0, 0); + *status = TRANS_ACCEPT_BAD_MALLOC; + return NULL; + } + + if ((newciptr->fd = accept (ciptr->fd, + (struct sockaddr *) &sockname, &namelen)) < 0) + { + PRMSG (1, "SocketUNIXAccept: accept() failed\n", 0, 0, 0); + xfree (newciptr); + *status = TRANS_ACCEPT_FAILED; + return NULL; + } + + /* + * Get the socket name and the peer name from the listener socket, + * since this is unix domain. + */ + + if ((newciptr->addr = (char *) xalloc (ciptr->addrlen)) == NULL) + { + PRMSG (1, + "SocketUNIXAccept: Can't allocate space for the addr\n", + 0, 0, 0); + close (newciptr->fd); + xfree (newciptr); + *status = TRANS_ACCEPT_BAD_MALLOC; + return NULL; + } + + + newciptr->addrlen = ciptr->addrlen; + memcpy (newciptr->addr, ciptr->addr, newciptr->addrlen); + + if ((newciptr->peeraddr = (char *) xalloc (ciptr->addrlen)) == NULL) + { + PRMSG (1, + "SocketUNIXAccept: Can't allocate space for the addr\n", + 0, 0, 0); + close (newciptr->fd); + if (newciptr->addr) xfree (newciptr->addr); + xfree (newciptr); + *status = TRANS_ACCEPT_BAD_MALLOC; + return NULL; + } + + newciptr->peeraddrlen = ciptr->addrlen; + memcpy (newciptr->peeraddr, ciptr->addr, newciptr->addrlen); + + newciptr->family = AF_UNIX; + + *status = 0; + + return newciptr; +} + +#endif /* UNIXCONN */ + +#endif /* TRANS_SERVER */ + + +#ifdef TRANS_CLIENT + +#ifdef TCPCONN +static int +TRANS(SocketINETConnect) (XtransConnInfo ciptr, char *host, char *port) + +{ + struct sockaddr_in sockname; +#if defined(SVR4) || defined(SCO325) + size_t namelen = sizeof sockname; +#else + int namelen = sizeof sockname; +#endif + struct hostent *hostp; + struct servent *servp; + +#ifdef X11_t + char portbuf[PORTBUFSIZE]; +#endif + + long tmpport; + unsigned long tmpaddr; + char hostnamebuf[256]; /* tmp space */ + + PRMSG (2,"SocketINETConnect(%d,%s,%s)\n", ciptr->fd, host, port); + + if (!host) + { + hostnamebuf[0] = '\0'; + (void) TRANS(GetHostname) (hostnamebuf, sizeof hostnamebuf); + host = hostnamebuf; + } + +#ifdef X11_t + /* + * X has a well known port, that is transport dependent. It is easier + * to handle it here, than try and come up with a transport independent + * representation that can be passed in and resolved the usual way. + * + * The port that is passed here is really a string containing the idisplay + * from ConnectDisplay(). + */ + + if (is_numeric (port)) + { + tmpport = X_TCP_PORT + strtol (port, (char**)NULL, 10); + sprintf (portbuf, "%lu", tmpport); + port = portbuf; + } +#endif + + /* + * Build the socket name. + */ + +#ifdef BSD44SOCKETS + sockname.sin_len = sizeof (struct sockaddr_in); +#endif + sockname.sin_family = AF_INET; + + /* + * fill in sin_addr + */ + + /* check for ww.xx.yy.zz host string */ + + if (isascii (host[0]) && isdigit (host[0])) { + tmpaddr = inet_addr (host); /* returns network byte order */ + } else { + tmpaddr = -1; + } + + PRMSG (4,"SocketINETConnect: inet_addr(%s) = %x\n", + host, tmpaddr, 0); + + if (tmpaddr == -1) + { +#ifdef _WIN32 + if ((hostp = gethostbyname(host)) == NULL) +#else + if ((hostp = gethostbyname(host,hparams)) == NULL) +#endif + { + PRMSG (1,"SocketINETConnect: Can't get address for %s\n", + host, 0, 0); + ESET(EINVAL); + return TRANS_CONNECT_FAILED; + } + if (hostp->h_addrtype != AF_INET) /* is IP host? */ + { + PRMSG (1,"SocketINETConnect: not INET host%s\n", + host, 0, 0); + ESET(EPROTOTYPE); + return TRANS_CONNECT_FAILED; + } + +#if defined(CRAY) && defined(OLDTCP) + /* Only Cray UNICOS3 and UNICOS4 will define this */ + { + long t; + memcpy ((char *)&t, (char *) hostp->h_addr, sizeof (t)); + sockname.sin_addr = t; + } +#else + memcpy ((char *) &sockname.sin_addr, (char *) hostp->h_addr, + sizeof (sockname.sin_addr)); +#endif /* CRAY and OLDTCP */ + + } +else + { +#if defined(CRAY) && defined(OLDTCP) + /* Only Cray UNICOS3 and UNICOS4 will define this */ + sockname.sin_addr = tmpaddr; +#else + sockname.sin_addr.s_addr = tmpaddr; +#endif /* CRAY and OLDTCP */ + } + + /* + * fill in sin_port + */ + + /* Check for number in the port string */ + + if (!is_numeric (port)) + { + if ((servp = getservbyname (port,"tcp")) == NULL) + { + PRMSG (1,"SocketINETConnect: can't get service for %s\n", + port, 0, 0); + return TRANS_CONNECT_FAILED; + } + sockname.sin_port = htons (servp->s_port); + } + else + { + tmpport = strtol (port, (char**)NULL, 10); + if (tmpport < 1024 || tmpport > USHRT_MAX) + return TRANS_CONNECT_FAILED; + sockname.sin_port = htons (((unsigned short) tmpport)); + } + + PRMSG (4,"SocketINETConnect: sockname.sin_port = %d\n", + ntohs(sockname.sin_port), 0, 0); + + /* + * Do the connect() + */ + + if (connect (ciptr->fd, (struct sockaddr *) &sockname, namelen) < 0) + { +#ifdef _WIN32 + int olderrno = WSAGetLastError(); +#else + int olderrno = errno; +#endif + + /* + * If the error was ECONNREFUSED, the server may be overloaded + * and we should try again. + * + * If the error was EWOULDBLOCK or EINPROGRESS then the socket + * was non-blocking and we should poll using select + * + * If the error was EINTR, the connect was interrupted and we + * should try again. + */ + + if (olderrno == ECONNREFUSED || olderrno == EINTR) + return TRANS_TRY_CONNECT_AGAIN; + else if (olderrno == EWOULDBLOCK || olderrno == EINPROGRESS) + return TRANS_IN_PROGRESS; + else + { + PRMSG (2,"SocketINETConnect: Can't connect: errno = %d\n", + olderrno,0, 0); + + return TRANS_CONNECT_FAILED; + } + } + + + /* + * Sync up the address fields of ciptr. + */ + + if (TRANS(SocketINETGetAddr) (ciptr) < 0) + { + PRMSG (1, + "SocketINETConnect: ...SocketINETGetAddr() failed:\n", + 0, 0, 0); + return TRANS_CONNECT_FAILED; + } + + if (TRANS(SocketINETGetPeerAddr) (ciptr) < 0) + { + PRMSG (1, + "SocketINETConnect: ...SocketINETGetPeerAddr() failed:\n", + 0, 0, 0); + return TRANS_CONNECT_FAILED; + } + + return 0; +} + +#endif /* TCPCONN */ + + + +#ifdef UNIXCONN + +/* + * Make sure 'host' is really local. + */ + +static int +UnixHostReallyLocal (char *host) + +{ + char hostnamebuf[256]; + + TRANS(GetHostname) (hostnamebuf, sizeof (hostnamebuf)); + + if (strcmp (hostnamebuf, host) == 0) + { + return (1); + } + else + { + /* + * A host may have more than one network address. If any of the + * network addresses of 'host' (specified to the connect call) + * match any of the network addresses of 'hostname' (determined + * by TRANS(GetHostname)), then the two hostnames are equivalent, + * and we know that 'host' is really a local host. + */ + char specified_local_addr_list[10][4]; + int scount, equiv, i, j; + struct hostent *hostp; + + if ((hostp = gethostbyname (host)) == NULL) + return (0); + + scount = 0; + while (hostp->h_addr_list[scount] && scount <= 8) + { + /* + * The 2nd call to gethostname() overrides the data + * from the 1st call, so we must save the address list. + */ + + specified_local_addr_list[scount][0] = + hostp->h_addr_list[scount][0]; + specified_local_addr_list[scount][1] = + hostp->h_addr_list[scount][1]; + specified_local_addr_list[scount][2] = + hostp->h_addr_list[scount][2]; + specified_local_addr_list[scount][3] = + hostp->h_addr_list[scount][3]; + scount++; + } + if ((hostp = gethostbyname (hostnamebuf)) == NULL) + return (0); + + equiv = 0; + i = 0; + + while (i < scount && !equiv) + { + j = 0; + + while (hostp->h_addr_list[j]) + { + if ((specified_local_addr_list[i][0] == + hostp->h_addr_list[j][0]) && + (specified_local_addr_list[i][1] == + hostp->h_addr_list[j][1]) && + (specified_local_addr_list[i][2] == + hostp->h_addr_list[j][2]) && + (specified_local_addr_list[i][3] == + hostp->h_addr_list[j][3])) + { + /* They're equal, so we're done */ + + equiv = 1; + break; + } + + j++; + } + + i++; + } + + return (equiv); + } +} + +static int +TRANS(SocketUNIXConnect) (XtransConnInfo ciptr, char *host, char *port) + +{ + struct sockaddr_un sockname; + int namelen; + +#if defined(hpux) && defined(X11_t) + struct sockaddr_un old_sockname; + int old_namelen; +#endif + + + PRMSG (2,"SocketUNIXConnect(%d,%s,%s)\n", ciptr->fd, host, port); + + /* + * Make sure 'host' is really local. If not, we return failure. + * The reason we make this check is because a process may advertise + * a "local" network ID for which it can accept connections, but if + * a process on a remote machine tries to connect to this network ID, + * we know for sure it will fail. + */ + + if (strcmp (host, "unix") != 0 && !UnixHostReallyLocal (host)) + { + PRMSG (1, + "SocketUNIXConnect: Cannot connect to non-local host %s\n", + host, 0, 0); + return TRANS_CONNECT_FAILED; + } + + + /* + * Check the port. + */ + + if (!port || !*port) + { + PRMSG (1,"SocketUNIXConnect: Missing port specification\n", + 0, 0, 0); + return TRANS_CONNECT_FAILED; + } + + /* + * Build the socket name. + */ + + sockname.sun_family = AF_UNIX; + + if (set_sun_path(port, UNIX_PATH, sockname.sun_path) != 0) { + PRMSG (1, "SocketUNIXConnect: path too long\n", 0, 0, 0); + return TRANS_CONNECT_FAILED; + } + + namelen = sizeof( sockname ) - sizeof( sockname.sun_path ) + strlen( sockname.sun_path ) + 1; +#if defined(BSD44SOCKETS) + sockname.sun_len = namelen; +#endif + +#if defined(hpux) && defined(X11_t) + /* + * This is gross, but it was in Xlib + */ + old_sockname.sun_family = AF_UNIX; + if (set_sun_path(port, OLD_UNIX_PATH, old_sockname.sun_path) != 0) { + PRMSG (1, "SocketUNIXConnect: path too long\n", 0, 0, 0); + return TRANS_CONNECT_FAILED; + } + old_namelen = strlen (old_sockname.sun_path) + + sizeof (old_sockname.sun_family); +#endif + + + /* + * Do the connect() + */ + + if (connect (ciptr->fd, (struct sockaddr *) &sockname, namelen) < 0) + { + int olderrno = errno; + int connected = 0; + +#if defined(hpux) && defined(X11_t) + if (olderrno == ENOENT) + { + if (connect (ciptr->fd, + (struct sockaddr *) &old_sockname, old_namelen) >= 0) + { + connected = 1; + } + else + olderrno = errno; + } +#endif + if (!connected) + { + errno = olderrno; + + /* + * If the error was ENOENT, the server may be starting up + * and we should try again. + * + * If the error was EWOULDBLOCK or EINPROGRESS then the socket + * was non-blocking and we should poll using select + * + * If the error was EINTR, the connect was interrupted and we + * should try again. + */ + + if (olderrno == ENOENT || olderrno == EINTR) + return TRANS_TRY_CONNECT_AGAIN; + else if (olderrno == EWOULDBLOCK || olderrno == EINPROGRESS) + return TRANS_IN_PROGRESS; + else + { + PRMSG (2,"SocketUNIXConnect: Can't connect: errno = %d\n", + EGET(),0, 0); + + return TRANS_CONNECT_FAILED; + } + } + } + + /* + * Get the socket name and the peer name from the connect socket, + * since this is unix domain. + */ + + if ((ciptr->addr = (char *) xalloc(namelen)) == NULL || + (ciptr->peeraddr = (char *) xalloc(namelen)) == NULL) + { + PRMSG (1, + "SocketUNIXCreateListener: Can't allocate space for the addr\n", + 0, 0, 0); + return TRANS_CONNECT_FAILED; + } + + ciptr->family = AF_UNIX; + ciptr->addrlen = namelen; + ciptr->peeraddrlen = namelen; + memcpy (ciptr->addr, &sockname, ciptr->addrlen); + memcpy (ciptr->peeraddr, &sockname, ciptr->peeraddrlen); + + return 0; +} + +#endif /* UNIXCONN */ + +#endif /* TRANS_CLIENT */ + + +static int +TRANS(SocketBytesReadable) (XtransConnInfo ciptr, BytesReadable_t *pend) + +{ + PRMSG (2,"SocketBytesReadable(%x,%d,%x)\n", + ciptr, ciptr->fd, pend); +#if defined(QNX4) + *pend = 0L; /* FIONREAD only returns a short. Zero out upper bits */ +#endif +#ifdef _WIN32 + return ioctlsocket ((SOCKET) ciptr->fd, FIONREAD, (u_long *) pend); +#else +#if (defined(i386) && defined(SYSV)) || defined(_SEQUENT_) + return ioctl (ciptr->fd, I_NREAD, (char *) pend); +#else +#if defined(__EMX__) + return ioctl (ciptr->fd, FIONREAD, (char*) pend, sizeof(int)); +#else + return ioctl (ciptr->fd, FIONREAD, (char *) pend); +#endif /* __EMX__ */ +#endif /* i386 && SYSV && !SCO || _SEQUENT_ */ +#endif /* _WIN32 */ +} + + +static int +TRANS(SocketRead) (XtransConnInfo ciptr, char *buf, int size) + +{ + PRMSG (2,"SocketRead(%d,%x,%d)\n", ciptr->fd, buf, size); + +#if defined(_WIN32) || defined(__EMX__) + return recv ((SOCKET)ciptr->fd, buf, size, 0); +#else + return read (ciptr->fd, buf, size); +#endif /* _WIN32 */ +} + + +static int +TRANS(SocketWrite) (XtransConnInfo ciptr, char *buf, int size) + +{ + PRMSG (2,"SocketWrite(%d,%x,%d)\n", ciptr->fd, buf, size); + +#if defined(_WIN32) || defined(__EMX__) + return send ((SOCKET)ciptr->fd, buf, size, 0); +#else + return write (ciptr->fd, buf, size); +#endif /* _WIN32 */ +} + + +static int +TRANS(SocketReadv) (XtransConnInfo ciptr, struct iovec *buf, int size) + +{ + PRMSG (2,"SocketReadv(%d,%x,%d)\n", ciptr->fd, buf, size); + + return READV (ciptr, buf, size); +} + + +static int +TRANS(SocketWritev) (XtransConnInfo ciptr, struct iovec *buf, int size) + +{ + PRMSG (2,"SocketWritev(%d,%x,%d)\n", ciptr->fd, buf, size); + + return WRITEV (ciptr, buf, size); +} + + +static int +TRANS(SocketDisconnect) (XtransConnInfo ciptr) + +{ + PRMSG (2,"SocketDisconnect(%x,%d)\n", ciptr, ciptr->fd, 0); + + return shutdown (ciptr->fd, 2); /* disallow further sends and receives */ +} + + +#ifdef TCPCONN +static int +TRANS(SocketINETClose) (XtransConnInfo ciptr) + +{ + PRMSG (2,"SocketINETClose(%x,%d)\n", ciptr, ciptr->fd, 0); + + return close (ciptr->fd); +} + +#endif /* TCPCONN */ + + +#ifdef UNIXCONN +static int +TRANS(SocketUNIXClose) (XtransConnInfo ciptr) + +{ + /* + * If this is the server side, then once the socket is closed, + * it must be unlinked to completely close it + */ + + struct sockaddr_un *sockname = (struct sockaddr_un *) ciptr->addr; + char path[200]; /* > sizeof sun_path +1 */ + int ret; + + PRMSG (2,"SocketUNIXClose(%x,%d)\n", ciptr, ciptr->fd, 0); + + ret = close(ciptr->fd); + + if (ciptr->flags + && sockname + && sockname->sun_family == AF_UNIX + && sockname->sun_path[0]) + { + strncpy (path, sockname->sun_path, + ciptr->addrlen - sizeof (sockname->sun_family)); + unlink (path); + } + + return ret; +} + +static int +TRANS(SocketUNIXCloseForCloning) (XtransConnInfo ciptr) + +{ + /* + * Don't unlink path. + */ + + int ret; + + PRMSG (2,"SocketUNIXCloseForCloning(%x,%d)\n", + ciptr, ciptr->fd, 0); + + ret = close(ciptr->fd); + + return ret; +} + +#endif /* UNIXCONN */ + + +#ifdef TCPCONN +Xtransport TRANS(SocketTCPFuncs) = { + /* Socket Interface */ + "tcp", + 0, +#ifdef TRANS_CLIENT + TRANS(SocketOpenCOTSClient), +#endif /* TRANS_CLIENT */ +#ifdef TRANS_SERVER + TRANS(SocketOpenCOTSServer), +#endif /* TRANS_SERVER */ +#ifdef TRANS_CLIENT + TRANS(SocketOpenCLTSClient), +#endif /* TRANS_CLIENT */ +#ifdef TRANS_SERVER + TRANS(SocketOpenCLTSServer), +#endif /* TRANS_SERVER */ +#ifdef TRANS_REOPEN + TRANS(SocketReopenCOTSServer), + TRANS(SocketReopenCLTSServer), +#endif + TRANS(SocketSetOption), +#ifdef TRANS_SERVER + TRANS(SocketINETCreateListener), + NULL, /* ResetListener */ + TRANS(SocketINETAccept), +#endif /* TRANS_SERVER */ +#ifdef TRANS_CLIENT + TRANS(SocketINETConnect), +#endif /* TRANS_CLIENT */ + TRANS(SocketBytesReadable), + TRANS(SocketRead), + TRANS(SocketWrite), + TRANS(SocketReadv), + TRANS(SocketWritev), + TRANS(SocketDisconnect), + TRANS(SocketINETClose), + TRANS(SocketINETClose), + }; + +Xtransport TRANS(SocketINETFuncs) = { + /* Socket Interface */ + "inet", + TRANS_ALIAS, +#ifdef TRANS_CLIENT + TRANS(SocketOpenCOTSClient), +#endif /* TRANS_CLIENT */ +#ifdef TRANS_SERVER + TRANS(SocketOpenCOTSServer), +#endif /* TRANS_SERVER */ +#ifdef TRANS_CLIENT + TRANS(SocketOpenCLTSClient), +#endif /* TRANS_CLIENT */ +#ifdef TRANS_SERVER + TRANS(SocketOpenCLTSServer), +#endif /* TRANS_SERVER */ +#ifdef TRANS_REOPEN + TRANS(SocketReopenCOTSServer), + TRANS(SocketReopenCLTSServer), +#endif + TRANS(SocketSetOption), +#ifdef TRANS_SERVER + TRANS(SocketINETCreateListener), + NULL, /* ResetListener */ + TRANS(SocketINETAccept), +#endif /* TRANS_SERVER */ +#ifdef TRANS_CLIENT + TRANS(SocketINETConnect), +#endif /* TRANS_CLIENT */ + TRANS(SocketBytesReadable), + TRANS(SocketRead), + TRANS(SocketWrite), + TRANS(SocketReadv), + TRANS(SocketWritev), + TRANS(SocketDisconnect), + TRANS(SocketINETClose), + TRANS(SocketINETClose), + }; + +#endif /* TCPCONN */ + +#ifdef UNIXCONN +#if !defined(LOCALCONN) +Xtransport TRANS(SocketLocalFuncs) = { + /* Socket Interface */ + (char*)"local", + 0, +#ifdef TRANS_CLIENT + TRANS(SocketOpenCOTSClient), +#endif /* TRANS_CLIENT */ +#ifdef TRANS_SERVER + TRANS(SocketOpenCOTSServer), +#endif /* TRANS_SERVER */ +#ifdef TRANS_CLIENT + TRANS(SocketOpenCLTSClient), +#endif /* TRANS_CLIENT */ +#ifdef TRANS_SERVER + TRANS(SocketOpenCLTSServer), +#endif /* TRANS_SERVER */ +#ifdef TRANS_REOPEN + TRANS(SocketReopenCOTSServer), + TRANS(SocketReopenCLTSServer), +#endif + TRANS(SocketSetOption), +#ifdef TRANS_SERVER + TRANS(SocketUNIXCreateListener), + TRANS(SocketUNIXResetListener), + TRANS(SocketUNIXAccept), +#endif /* TRANS_SERVER */ +#ifdef TRANS_CLIENT + TRANS(SocketUNIXConnect), +#endif /* TRANS_CLIENT */ + TRANS(SocketBytesReadable), + TRANS(SocketRead), + TRANS(SocketWrite), + TRANS(SocketReadv), + TRANS(SocketWritev), + TRANS(SocketDisconnect), + TRANS(SocketUNIXClose), + TRANS(SocketUNIXCloseForCloning), + }; +#endif /* !LOCALCONN */ + +Xtransport TRANS(SocketUNIXFuncs) = { + /* Socket Interface */ + (char*)"unix", +#if !defined(LOCALCONN) + TRANS_ALIAS, +#else + 0, +#endif +#ifdef TRANS_CLIENT + TRANS(SocketOpenCOTSClient), +#endif /* TRANS_CLIENT */ +#ifdef TRANS_SERVER + TRANS(SocketOpenCOTSServer), +#endif /* TRANS_SERVER */ +#ifdef TRANS_CLIENT + TRANS(SocketOpenCLTSClient), +#endif /* TRANS_CLIENT */ +#ifdef TRANS_SERVER + TRANS(SocketOpenCLTSServer), +#endif /* TRANS_SERVER */ +#ifdef TRANS_REOPEN + TRANS(SocketReopenCOTSServer), + TRANS(SocketReopenCLTSServer), +#endif + TRANS(SocketSetOption), +#ifdef TRANS_SERVER + TRANS(SocketUNIXCreateListener), + TRANS(SocketUNIXResetListener), + TRANS(SocketUNIXAccept), +#endif /* TRANS_SERVER */ +#ifdef TRANS_CLIENT + TRANS(SocketUNIXConnect), +#endif /* TRANS_CLIENT */ + TRANS(SocketBytesReadable), + TRANS(SocketRead), + TRANS(SocketWrite), + TRANS(SocketReadv), + TRANS(SocketWritev), + TRANS(SocketDisconnect), + TRANS(SocketUNIXClose), + TRANS(SocketUNIXCloseForCloning), + }; + +#endif /* UNIXCONN */ diff --git a/dcop/KDE-ICE/Xtransutil.c b/dcop/KDE-ICE/Xtransutil.c new file mode 100644 index 000000000..bad9aae53 --- /dev/null +++ b/dcop/KDE-ICE/Xtransutil.c @@ -0,0 +1,549 @@ +/* $TOG: Xtransutil.c /main/33 1998/02/06 15:55:10 kaleb $ */ +/* + +Copyright 1993, 1994, 1998 The Open Group + +All Rights Reserved. + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall +not be used in advertising or otherwise to promote the sale, use or +other dealings in this Software without prior written authorization +from The Open Group. + +*/ +/* $XFree86: xc/lib/xtrans/Xtransutil.c,v 3.14 1999/06/20 08:41:24 dawes Exp $ */ + +/* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA + * + * All Rights Reserved + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name NCR not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. NCR makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * NCRS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * These are some utility functions created for convenience or to provide + * an interface that is similar to an existing interface. These are built + * only using the Transport Independant API, and have no knowledge of + * the internal implementation. + */ + +#ifdef X11_t + +/* + * These values come from X.h and Xauth.h, and MUST match them. Some + * of these values are also defined by the ChangeHost protocol message. + */ + +#define FamilyInternet 0 /* IPv4 */ +#define FamilyDECnet 1 +#define FamilyChaos 2 +#define FamilyInternet6 6 +#define FamilyAmoeba 33 +#define FamilyLocalHost 252 +#define FamilyKrb5Principal 253 +#define FamilyNetname 254 +#define FamilyLocal 256 +#define FamilyWild 65535 + +/* + * TRANS(ConvertAddress) converts a sockaddr based address to an + * X authorization based address. Some of this is defined as part of + * the ChangeHost protocol. The rest is just doen in a consistent manner. + */ + +int +TRANS(ConvertAddress)(int *familyp, int *addrlenp, Xtransaddr **addrp) + +{ + + PRMSG(2,"ConvertAddress(%d,%d,%x)\n",*familyp,*addrlenp,*addrp); + + switch( *familyp ) + { +#if defined(TCPCONN) || defined(STREAMSCONN) || defined(MNX_TCPCONN) + case AF_INET: + { + /* + * Check for the BSD hack localhost address 127.0.0.1. + * In this case, we are really FamilyLocal. + */ + + struct sockaddr_in saddr; +#ifdef CRAY +#ifdef OLDTCP + int len = sizeof(saddr.sin_addr); +#else + int len = SIZEOF_in_addr; +#endif /* OLDTCP */ + char *cp = (char *) &saddr.sin_addr; +#else /* else not CRAY */ + int len = sizeof(saddr.sin_addr.s_addr); + char *cp = (char *) &saddr.sin_addr.s_addr; +#endif /* CRAY */ + + memcpy (&saddr, *addrp, sizeof (struct sockaddr_in)); + + if ((len == 4) && (cp[0] == 127) && (cp[1] == 0) && + (cp[2] == 0) && (cp[3] == 1)) + { + *familyp=FamilyLocal; + } + else + { + *familyp=FamilyInternet; + *addrlenp=len; + memcpy(*addrp,&saddr.sin_addr,len); + } + break; + } +#endif /* defined(TCPCONN) || defined(STREAMSCONN) || MNX_TCPCONN */ + +#if defined(DNETCONN) + case AF_DECnet: + { + struct sockaddr_dn saddr; + + memcpy (&saddr, *addrp, sizeof (struct sockaddr_dn)); + + *familyp=FamilyDECnet; + *addrlenp=sizeof(struct dn_naddr); + memcpy(*addrp,&saddr.sdn_add,*addrlenp); + + break; + } +#endif /* defined(DNETCONN) */ + +#if defined(UNIXCONN) || defined(LOCALCONN) || defined(OS2PIPECONN) + case AF_UNIX: + { + *familyp=FamilyLocal; + break; + } +#endif /* defined(UNIXCONN) || defined(LOCALCONN) || defined(OS2PIPECONN)*/ + +#if defined(AMRPCCONN) + case AF_AMOEBA: + { + *familyp=FamilyAmoeba; + break; + } +#endif +#if defined(AMTCPCONN) && !(defined(TCPCONN) || defined(STREAMSCONN)) + case AF_INET: + { + *familyp=FamilyInternet; + break; + } +#endif + + default: + PRMSG(1,"ConvertAddress: Unknown family type %d\n", + *familyp, 0,0 ); + return -1; + } + + + if (*familyp == FamilyLocal) + { + /* + * In the case of a local connection, we need to get the + * host name for authentication. + */ + + char hostnamebuf[256]; + int len = TRANS(GetHostname) (hostnamebuf, sizeof hostnamebuf); + + if (len > 0) { + if (*addrp && *addrlenp < (len + 1)) + { + xfree ((char *) *addrp); + *addrp = NULL; + } + if (!*addrp) + *addrp = (Xtransaddr *) xalloc (len + 1); + if (*addrp) { + strcpy ((char *) *addrp, hostnamebuf); + *addrlenp = len; + } else { + *addrlenp = 0; + } + } + else + { + if (*addrp) + xfree ((char *) *addrp); + *addrp = NULL; + *addrlenp = 0; + } + } + + return 0; +} + +#endif /* X11_t */ + +#ifdef ICE_t + +#include <signal.h> + +char * +TRANS(GetMyNetworkId) (XtransConnInfo ciptr) + +{ + int family = ciptr->family; + char *addr = ciptr->addr; + char hostnamebuf[256]; + char *networkId = NULL; + char *transName = ciptr->transptr->TransName; + + if (gethostname (hostnamebuf, sizeof (hostnamebuf)) < 0) + { + return (NULL); + } + hostnamebuf[sizeof(hostnamebuf)-1] = '\0'; + + switch (family) + { +#if defined(UNIXCONN) || defined(STREAMSCONN) || defined(LOCALCONN) || defined(OS2PIPECONN) + case AF_UNIX: + { + struct sockaddr_un *saddr = (struct sockaddr_un *) addr; + networkId = (char *) xalloc (3 + strlen (transName) + + strlen (hostnamebuf) + strlen (saddr->sun_path)); + sprintf (networkId, "%s/%s:%s", transName, + hostnamebuf, saddr->sun_path); + break; + } +#endif /* defined(UNIXCONN) || defined(STREAMSCONN) || defined(LOCALCONN) || defined(OS2PIPECONN) +*/ + +#if defined(TCPCONN) || defined(STREAMSCONN) || defined(MNX_TCPCONN) + case AF_INET: + { + struct sockaddr_in *saddr = (struct sockaddr_in *) addr; + char portnumbuf[10]; + + sprintf (portnumbuf, "%d", ntohs (saddr->sin_port)); + networkId = (char *) xalloc (3 + strlen (transName) + + strlen (hostnamebuf) + strlen (portnumbuf)); + sprintf (networkId, "%s/%s:%s", transName, hostnamebuf, portnumbuf); + break; + } +#endif /* defined(TCPCONN) || defined(STREAMSCONN) || MNX_TCPCONN */ + +#if defined(DNETCONN) + case AF_DECnet: + { + struct sockaddr_dn *saddr = (struct sockaddr_dn *) addr; + + networkId = (char *) xalloc ( + 13 + strlen (hostnamebuf) + saddr->sdn_objnamel); + sprintf (networkId, "dnet/%s::%s", + hostnamebuf, saddr->sdn_objname); + break; + } +#endif /* defined(DNETCONN) */ + + default: + break; + } + + return (networkId); +} + +#include <setjmp.h> +static jmp_buf env; + +#ifdef SIGALRM +static volatile int nameserver_timedout = 0; + +static +#ifdef SIGNALRETURNSINT +int +#else +void +#endif +nameserver_lost(int sig) +{ + (void)sig;/*unused*/ + nameserver_timedout = 1; + longjmp (env, -1); + /* NOTREACHED */ +#ifdef SIGNALRETURNSINT + return -1; /* for picky compilers */ +#endif +} +#endif /* SIGALARM */ + + +char * +TRANS(GetPeerNetworkId) (XtransConnInfo ciptr) + +{ + int family = ciptr->family; + char *hostname; + char addrbuf[256]; + char *addr = NULL; + + switch (family) + { + case AF_UNSPEC: +#if defined(UNIXCONN) || defined(STREAMSCONN) || defined(LOCALCONN) || defined(OS2PIPECONN) + case AF_UNIX: + { + if (gethostname (addrbuf, sizeof (addrbuf)) == 0) { + addrbuf[sizeof(addrbuf)-1] = '\0'; + addr = addrbuf; + } + break; + } +#endif /* defined(UNIXCONN) || defined(STREAMSCONN) || defined(LOCALCONN) || defined(OS2PIPECONN) +*/ + +#if defined(TCPCONN) || defined(STREAMSCONN) || defined(MNX_TCPCONN) + case AF_INET: + { + char *peer_addr = ciptr->peeraddr; + struct sockaddr_in *saddr = (struct sockaddr_in *) peer_addr; + struct hostent * hostp = NULL; + +#if defined(SIGALRM) && !defined(_WIN32) + /* + * gethostbyaddr can take a LONG time if the host does not exist. + * Assume that if it does not respond in NAMESERVER_TIMEOUT seconds + * that something is wrong and do not make the user wait. + * gethostbyaddr will continue after a signal, so we have to + * jump out of it. + */ + + nameserver_timedout = 0; + signal (SIGALRM, nameserver_lost); + alarm (4); + if (setjmp(env) == 0) { +#endif + hostp = gethostbyaddr ((char *) &saddr->sin_addr, + sizeof (saddr->sin_addr), AF_INET); +#if defined(SIGALRM) && !defined(_WIN32) + } + alarm (0); +#endif + if (hostp != NULL) + addr = hostp->h_name; + else + addr = inet_ntoa (saddr->sin_addr); + break; + } + +#endif /* defined(TCPCONN) || defined(STREAMSCONN) || MNX_TCPCONN */ + +#if defined(DNETCONN) + case AF_DECnet: + { + char *peer_addr = ciptr->peeraddr; + struct sockaddr_dn *saddr = (struct sockaddr_dn *) peer_addr; + struct nodeent *np; + + if (np = getnodebyaddr(saddr->sdn_add.a_addr, + saddr->sdn_add.a_len, AF_DECnet)) { + snprintf(addrbuf, sizeof(addrbuf), "%s:", np->n_name); + } else { + snprintf(addrbuf, sizeof(addrbuf), "%s:", dnet_htoa(&saddr->sdn_add)); + } + addr = addrbuf; + break; + } +#endif /* defined(DNETCONN) */ + +#if defined(AMRPCCONN) + case AF_AMOEBA: + { + addr = "Amoeba"; /* not really used */ + break; + } +#endif +#if defined(AMTCPCONN) && !(defined(TCPCONN) || defined(STREAMSCONN)) + case AF_INET: + { + if (gethostname (addrbuf, sizeof (addrbuf)) == 0) { + addrbuf[sizeof(addrbuf)-1] = '\0'; + addr = addrbuf; + } else { + addr = ""; + } + break; + } +#endif + + default: + return (NULL); + } + + + hostname = (char *) xalloc ( + strlen (ciptr->transptr->TransName) + strlen (addr) + 2); + strcpy (hostname, ciptr->transptr->TransName); + strcat (hostname, "/"); + if (addr) + strcat (hostname, addr); + + return (hostname); +} + +#endif /* ICE_t */ + + +#if defined(_WIN32) && (defined(TCPCONN) || defined(DNETCONN)) +int +TRANS(WSAStartup) (void) +{ + static WSADATA wsadata; + + PRMSG (2,"WSAStartup()\n", 0, 0, 0); + + if (!wsadata.wVersion && WSAStartup(MAKEWORD(1,1), &wsadata)) + return 1; + return 0; +} +#endif + + +static int +is_numeric (char *str) + +{ + int i; + + for (i = 0; i < (int) strlen (str); i++) + if (!isdigit (str[i])) + return (0); + + return (1); +} + +#ifdef TRANS_SERVER +#include <sys/types.h> +#include <sys/stat.h> +#include <errno.h> + +#if !defined(S_IFLNK) && !defined(S_ISLNK) +#define lstat(a,b) stat(a,b) +#endif + +static int +trans_mkdir(char *path, int mode) +{ + struct stat buf; + + if (mkdir(path, mode) == 0) { + chmod(path, mode); + return 0; + } + /* If mkdir failed with EEXIST, test if it is a directory with + the right modes, else fail */ + if (errno == EEXIST) { + if (lstat(path, &buf) != 0) { + PRMSG(1, "mkdir: (l)stat failed for %s (%d)\n", + path, errno, 0); + return -1; + } + if (S_ISDIR(buf.st_mode)) { + int updateOwner = 0; + int updateMode = 0; + int updatedOwner = 0; + int updatedMode = 0; + /* Check if the directory's ownership is OK. */ + if (buf.st_uid != 0) + updateOwner = 1; + /* + * Check if the directory's mode is OK. An exact match isn't + * required, just a mode that isn't more permissive than the + * one requested. + */ + if ((~mode) & 0077 & buf.st_mode) + updateMode = 1; + if ((mode & 01000) && + (buf.st_mode & 0002) && !(buf.st_mode & 01000)) + updateMode = 1; +#ifdef HAS_FCHOWN + /* + * If fchown(2) and fchmod(2) are available, try to correct the + * directory's owner and mode. Otherwise it isn't safe to attempt + * to do this. + */ + if (updateMode || updateOwner) { + int fd = -1; + struct stat fbuf; + if ((fd = open(path, O_RDONLY)) != -1) { + if (fstat(fd, &fbuf) == -1) { + PRMSG(1, "mkdir: fstat failed for %s (%d)\n", + path, errno, 0); + close(fd); + return -1; + } + /* + * Verify that we've opened the same directory as was + * checked above. + */ + if (!S_ISDIR(fbuf.st_mode) || + buf.st_dev != fbuf.st_dev || + buf.st_ino != fbuf.st_ino) { + PRMSG(1, "mkdir: inode for %s changed\n", + path, 0, 0); + close(fd); + return -1; + } + if (updateOwner && fchown(fd, 0, 0) == 0) + updatedOwner = 1; + if (updateMode && fchmod(fd, mode) == 0) + updatedMode = 1; + close(fd); + } + } +#endif +#ifndef __CYGWIN__ + if (updateOwner && !updatedOwner) { + PRMSG(1, "mkdir: Owner of %s should be set to root\n", + path, 0, 0); +/* sleep(5); */ + } + if (updateMode && !updatedMode) { + PRMSG(1, "mkdir: Mode of %s should be set to %04o\n", + path, mode, 0); +/* sleep(5); */ + } +#endif + return 0; + } + } + /* In all other cases, fail */ + return -1; +} + +#endif /* TRANS_SERVER */ diff --git a/dcop/KDE-ICE/accept.c b/dcop/KDE-ICE/accept.c new file mode 100644 index 000000000..59d63d191 --- /dev/null +++ b/dcop/KDE-ICE/accept.c @@ -0,0 +1,189 @@ +/* $XConsortium: accept.c,v 1.24 94/12/20 17:50:13 mor Exp $ */ +/****************************************************************************** + + +Copyright (c) 1993 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from the X Consortium. + +Author: Ralph Mor, X Consortium +******************************************************************************/ + +#include <string.h> + +#include "KDE-ICE/ICElib.h" +#include "KDE-ICE/ICElibint.h" +#include "KDE-ICE/Xtrans.h" +#include "KDE-ICE/globals.h" + +IceConn +IceAcceptConnection (listenObj, statusRet) + +IceListenObj listenObj; +IceAcceptStatus *statusRet; + +{ + IceConn iceConn; + XtransConnInfo newconn; + iceByteOrderMsg *pMsg; + int endian, status; + + /* + * Accept the connection. + */ + + if ((newconn = (XtransConnInfo)_kde_IceTransAccept (listenObj->trans_conn, &status)) == 0) + { + if (status == TRANS_ACCEPT_BAD_MALLOC) + *statusRet = IceAcceptBadMalloc; + else + *statusRet = IceAcceptFailure; + return (NULL); + } + + + /* + * Set close-on-exec so that programs that fork() don't get confused. + */ + + _kde_IceTransSetOption (newconn, TRANS_CLOSEONEXEC, 1); + + + /* + * Create an ICE object for this connection. + */ + + if ((iceConn = (IceConn) malloc (sizeof (struct _IceConn))) == NULL) + { + _kde_IceTransClose (newconn); + *statusRet = IceAcceptBadMalloc; + return (NULL); + } + + iceConn->listen_obj = listenObj; + + iceConn->waiting_for_byteorder = True; + iceConn->connection_status = IceConnectPending; + iceConn->io_ok = True; + iceConn->dispatch_level = 0; + iceConn->context = NULL; + iceConn->my_ice_version_index = 0; + + iceConn->trans_conn = newconn; + iceConn->send_sequence = 0; + iceConn->receive_sequence = 0; + + iceConn->connection_string = (char *) malloc ( + strlen (listenObj->network_id) + 1); + + if (iceConn->connection_string == NULL) + { + _kde_IceTransClose (newconn); + free ((char *) iceConn); + *statusRet = IceAcceptBadMalloc; + return (NULL); + } + else + strcpy (iceConn->connection_string, listenObj->network_id); + + iceConn->vendor = NULL; + iceConn->release = NULL; + + if ((iceConn->inbuf = iceConn->inbufptr = + (char *) malloc (ICE_INBUFSIZE)) != NULL) + { + iceConn->inbufmax = iceConn->inbuf + ICE_INBUFSIZE; + } + else + { + _kde_IceTransClose (newconn); + free ((char *) iceConn); + *statusRet = IceAcceptBadMalloc; + return (NULL); + } + + if ((iceConn->outbuf = iceConn->outbufptr = + (char *) malloc (ICE_OUTBUFSIZE)) != NULL) + { + memset(iceConn->outbuf, 0, ICE_OUTBUFSIZE); + iceConn->outbufmax = iceConn->outbuf + ICE_OUTBUFSIZE; + } + else + { + _kde_IceTransClose (newconn); + free (iceConn->inbuf); + free ((char *) iceConn); + *statusRet = IceAcceptBadMalloc; + return (NULL); + } + + iceConn->scratch = NULL; + iceConn->scratch_size = 0; + + iceConn->open_ref_count = 1; + iceConn->proto_ref_count = 0; + + iceConn->skip_want_to_close = False; + iceConn->want_to_close = False; + iceConn->free_asap = False; + + iceConn->saved_reply_waits = NULL; + iceConn->ping_waits = NULL; + + iceConn->process_msg_info = NULL; + + iceConn->connect_to_you = NULL; + iceConn->protosetup_to_you = NULL; + + iceConn->connect_to_me = NULL; + iceConn->protosetup_to_me = NULL; + + + /* + * Send our byte order. + */ + + IceGetHeader (iceConn, 0, ICE_ByteOrder, + SIZEOF (iceByteOrderMsg), iceByteOrderMsg, pMsg); + + endian = 1; + if (*(char *) &endian) + pMsg->byteOrder = IceLSBfirst; + else + pMsg->byteOrder = IceMSBfirst; + + IceFlush (iceConn); + + + if (_IceWatchProcs) + { + /* + * Notify the watch procedures that an iceConn was opened. + */ + + _IceConnectionOpened (iceConn); + } + + *statusRet = IceAcceptSuccess; + + return (iceConn); +} diff --git a/dcop/KDE-ICE/authutil.c b/dcop/KDE-ICE/authutil.c new file mode 100644 index 000000000..41a2eefaa --- /dev/null +++ b/dcop/KDE-ICE/authutil.c @@ -0,0 +1,524 @@ +/* $XConsortium: authutil.c /main/16 1996/09/28 16:33:00 rws $ */ +/* $XFree86: xc/lib/ICE/authutil.c,v 3.2 1997/01/05 11:51:53 dawes Exp $ */ +/****************************************************************************** + + +Copyright (c) 1993 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from the X Consortium. + +Author: Ralph Mor, X Consortium +******************************************************************************/ + +#include <KDE-ICE/ICElib.h> +#include "KDE-ICE/ICElibint.h" +#include <KDE-ICE/ICEutil.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <string.h> +#include <errno.h> +#include <string.h> + +#if defined(X_NOT_STDC_ENV) && !defined(__EMX__) +extern int errno; +extern long time (); +extern char *getenv(); +#define Time_t long +#else +#include <time.h> +#define Time_t time_t +#ifdef __EMX__ +extern char* getenv(const char*); +#define link rename +#endif +#endif +#ifndef X_NOT_POSIX +#include <unistd.h> +#else +#ifndef _WIN32 +extern unsigned sleep (); +#else +#define link rename +#endif +#endif + +static Status read_short (FILE *file, unsigned short *shortp); +static Status read_string (FILE *file, char **stringp); +static Status read_counted_string (FILE *file, unsigned short *countp, char **stringp); +static Status write_short (FILE *file, unsigned short s); +static Status write_string (FILE *file, char *string); +static Status write_counted_string (FILE *file, unsigned short count, char *string); + + + +/* + * The following routines are for manipulating the .ICEauthority file + * These are utility functions - they are not part of the standard + * ICE library specification. + */ + +char * +IceAuthFileName () + +{ +#ifdef _WIN32 + static char slashDotICEauthority[] = "\\.ICEauthority"; +#else + static char slashDotICEauthority[] = "/.ICEauthority"; +#endif + char *name; + static char *buf; + static int bsize; + int size; +#if defined(_WIN32) || defined(__EMX__) + char dir[128]; +#endif + + name = getenv ("ICEAUTHORITY"); + if ( name ) + return (name); + + name = getenv ("HOME"); + + if (!name) + { +#ifdef _WIN32 + if(name = getenv ("HOMEDRIVE")) + { + strcpy (dir, name); + if(name = getenv ("HOMEPATH")) + strcat (dir, name); + } + else + { + if(name = getenv ("USERPROFILE")) + strcpy (dir, name); + } + name = dir; + if (!name) +#endif +#ifdef __EMX__ + strcpy (dir,"c:"); + name = dir; + if (!name) +#endif + return (NULL); + } + + size = strlen (name) + strlen (&slashDotICEauthority[1]) + 2; + + if (size > bsize) + { + if (buf) + free (buf); + buf = malloc ((unsigned) size); + if (!buf) + return (NULL); + bsize = size; + } + + strcpy (buf, name); + strcat (buf, slashDotICEauthority + (name[1] == '\0' ? 1 : 0)); + + return (buf); +} + + + +int +IceLockAuthFile (file_name, retries, timeout, dead) + +char *file_name; +int retries; +int timeout; +long dead; + +{ + char creat_name[1025], link_name[1025]; + struct stat statb; + Time_t now; + int creat_fd = -1; + + if ((int) strlen (file_name) > 1022) + return (IceAuthLockError); + + strcpy (creat_name, file_name); + strcat (creat_name, "-c"); + strcpy (link_name, file_name); + strcat (link_name, "-l"); + + if (stat (creat_name, &statb) != -1) + { + now = time ((Time_t *) 0); + + /* + * NFS may cause ctime to be before now, special + * case a 0 deadtime to force lock removal + */ + + if (dead == 0 || now - statb.st_ctime > dead) + { + unlink (creat_name); + unlink (link_name); + } + } + + while (retries > 0) + { + if (creat_fd == -1) + { + creat_fd = creat (creat_name, 0666); + + if (creat_fd == -1) + { + if (errno != EACCES) + return (IceAuthLockError); + } + else + close (creat_fd); + } + + if (creat_fd != -1) + { + if (link (creat_name, link_name) != -1) + return (IceAuthLockSuccess); + + if (errno == ENOENT) + { + creat_fd = -1; /* force re-creat next time around */ + continue; + } + + if (errno != EEXIST) + return (IceAuthLockError); + } + + sleep ((unsigned) timeout); + --retries; + } + + return (IceAuthLockTimeout); +} + + + +void +IceUnlockAuthFile (file_name) + +char *file_name; + +{ +#ifndef _WIN32 + char creat_name[1025]; +#endif + char link_name[1025]; + + if ((int) strlen (file_name) > 1022) + return; + +#ifndef _WIN32 + strcpy (creat_name, file_name); + strcat (creat_name, "-c"); +#endif + strcpy (link_name, file_name); + strcat (link_name, "-l"); + +#ifndef _WIN32 + unlink (creat_name); +#endif + unlink (link_name); +} + + + +IceAuthFileEntry * +IceReadAuthFileEntry (auth_file) + +FILE *auth_file; + +{ + IceAuthFileEntry local; + IceAuthFileEntry *ret; + + local.protocol_name = NULL; + local.protocol_data = NULL; + local.network_id = NULL; + local.auth_name = NULL; + local.auth_data = NULL; + + if (!read_string (auth_file, &local.protocol_name)) + return (NULL); + + if (!read_counted_string (auth_file, + &local.protocol_data_length, &local.protocol_data)) + goto bad; + + if (!read_string (auth_file, &local.network_id)) + goto bad; + + if (!read_string (auth_file, &local.auth_name)) + goto bad; + + if (!read_counted_string (auth_file, + &local.auth_data_length, &local.auth_data)) + goto bad; + + if (!(ret = (IceAuthFileEntry *) malloc (sizeof (IceAuthFileEntry)))) + goto bad; + + *ret = local; + + return (ret); + + bad: + + if (local.protocol_name) free (local.protocol_name); + if (local.protocol_data) free (local.protocol_data); + if (local.network_id) free (local.network_id); + if (local.auth_name) free (local.auth_name); + if (local.auth_data) free (local.auth_data); + + return (NULL); +} + + + +void +IceFreeAuthFileEntry (auth) + +IceAuthFileEntry *auth; + +{ + if (auth) + { + if (auth->protocol_name) free (auth->protocol_name); + if (auth->protocol_data) free (auth->protocol_data); + if (auth->network_id) free (auth->network_id); + if (auth->auth_name) free (auth->auth_name); + if (auth->auth_data) free (auth->auth_data); + free ((char *) auth); + } +} + + + +Status +IceWriteAuthFileEntry (auth_file, auth) + +FILE *auth_file; +IceAuthFileEntry *auth; + +{ + if (!write_string (auth_file, auth->protocol_name)) + return (0); + + if (!write_counted_string (auth_file, + auth->protocol_data_length, auth->protocol_data)) + return (0); + + if (!write_string (auth_file, auth->network_id)) + return (0); + + if (!write_string (auth_file, auth->auth_name)) + return (0); + + if (!write_counted_string (auth_file, + auth->auth_data_length, auth->auth_data)) + return (0); + + return (1); +} + + + +IceAuthFileEntry * +IceGetAuthFileEntry (protocol_name, network_id, auth_name) + +const char *protocol_name; +const char *network_id; +const char *auth_name; + +{ + FILE *auth_file; + char *filename; + IceAuthFileEntry *entry; + + if (!(filename = IceAuthFileName ())) + return (NULL); + + if (access (filename, R_OK) != 0) /* checks REAL id */ + return (NULL); + + if (!(auth_file = fopen (filename, "rb"))) + return (NULL); + + for (;;) + { + if (!(entry = IceReadAuthFileEntry (auth_file))) + break; + + if (strcmp (protocol_name, entry->protocol_name) == 0 && + strcmp (network_id, entry->network_id) == 0 && + strcmp (auth_name, entry->auth_name) == 0) + { + break; + } + + IceFreeAuthFileEntry (entry); + } + + fclose (auth_file); + + return (entry); +} + + + +/* + * local routines + */ + +static Status +read_short (FILE *file, unsigned short *shortp) +{ + unsigned char file_short[2]; + + if (fread ((char *) file_short, (int) sizeof (file_short), 1, file) != 1) + return (0); + + *shortp = file_short[0] * 256 + file_short[1]; + return (1); +} + + +static Status +read_string (FILE *file, char **stringp) +{ + unsigned short len; + char *data; + + if (!read_short (file, &len)) + return (0); + + if (len == 0) + { + data = malloc ( 1 ); + *data = 0; + } + else + { + data = malloc ((unsigned) len + 1); + + if (!data) + return (0); + + if (fread (data, (int) sizeof (char), (int) len, file) != len) + { + free (data); + return (0); + } + + data[len] = '\0'; + } + + *stringp = data; + + return (1); +} + + +static Status +read_counted_string (FILE *file, unsigned short *countp, char **stringp) +{ + unsigned short len; + char *data; + + if (!read_short (file, &len)) + return (0); + + if (len == 0) + { + data = 0; + } + else + { + data = malloc ((unsigned) len); + + if (!data) + return (0); + + if (fread (data, (int) sizeof (char), (int) len, file) != len) + { + free (data); + return (0); + } + } + + *stringp = data; + *countp = len; + + return (1); +} + + +static Status +write_short (FILE *file, unsigned short s) +{ + unsigned char file_short[2]; + + file_short[0] = (s & (unsigned) 0xff00) >> 8; + file_short[1] = s & 0xff; + + if (fwrite ((char *) file_short, (int) sizeof (file_short), 1, file) != 1) + return (0); + + return (1); +} + + +static Status +write_string (FILE *file, char *string) +{ + unsigned short count = strlen (string); + + if (!write_short (file, count)) + return (0); + + if (fwrite (string, (int) sizeof (char), (int) count, file) != count) + return (0); + + return (1); +} + + +static Status +write_counted_string (FILE *file, unsigned short count, char *string) +{ + if (!write_short (file, count)) + return (0); + + if (fwrite (string, (int) sizeof (char), (int) count, file) != count) + return (0); + + return (1); +} diff --git a/dcop/KDE-ICE/connect.c b/dcop/KDE-ICE/connect.c new file mode 100644 index 000000000..99c947b38 --- /dev/null +++ b/dcop/KDE-ICE/connect.c @@ -0,0 +1,547 @@ +/* $XConsortium: connect.c /main/32 1996/12/10 15:58:34 swick $ */ +/****************************************************************************** + + +Copyright (c) 1993 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from the X Consortium. + +Author: Ralph Mor, X Consortium +******************************************************************************/ +/* $XFree86: xc/lib/ICE/connect.c,v 3.2.2.2 1998/05/19 14:21:32 dawes Exp $ */ + +#include "KDE-ICE/ICElib.h" +#include "KDE-ICE/ICElibint.h" +#include "KDE-ICE/Xtrans.h" +#include "globals.h" +#include <string.h> + +static XtransConnInfo ConnectToPeer(char *networkIdsList, char **actualConnectionRet); + +#ifndef X_NOT_STDC_ENV +#define Strstr strstr +#else +static char *Strstr(s1, s2) + char *s1, *s2; +{ + int n1, n2; + + n1 = strlen(s1); + n2 = strlen(s2); + for ( ; n1 >= n2; s1++, n1--) { + if (!strncmp(s1, s2, n2)) + return s1; + } + return NULL; +} +#endif + +IceConn +IceOpenConnection (networkIdsList, context, mustAuthenticate, majorOpcodeCheck, + errorLength, errorStringRet) + +char *networkIdsList; +IcePointer context; +Bool mustAuthenticate; +int majorOpcodeCheck; +int errorLength; +char *errorStringRet; + +{ + IceConn iceConn; + int extra, i, j; + int endian; + Bool gotReply, ioErrorOccured; + unsigned long setup_sequence; + iceByteOrderMsg *pByteOrderMsg; + iceConnectionSetupMsg *pSetupMsg; + char *pData; + IceReplyWaitInfo replyWait; + _IceReply reply; + int authUsableCount; + int authUsableFlags[MAX_ICE_AUTH_NAMES]; + int authIndices[MAX_ICE_AUTH_NAMES]; + + if (errorStringRet && errorLength > 0) + *errorStringRet = '\0'; + + if (networkIdsList == NULL || *networkIdsList == '\0') + { + strncpy (errorStringRet, + "networkIdsList argument is NULL", errorLength); + return (NULL); + } + + /* + * Check to see if we can use a previously created ICE connection. + * + * If iceConn->want_to_close is True, or iceConn->free_asap is True, + * we can not use the iceConn. + * + * If 'context' is non-NULL, we will only use a previously opened ICE + * connection if the specified 'context' is equal to the context + * associated with the ICE connection, or if the context associated + * with the ICE connection is NULL. + * + * If 'majorOpcodeCheck' is non-zero, it will contain a protocol major + * opcode that we should make sure is not already active on the ICE + * connection. Some clients will want two seperate connections for the + * same protocol to the same destination client. + */ + + for (i = 0; i < _IceConnectionCount; i++) + { + char *strptr; + if ((strptr = (char *) Strstr ( + networkIdsList, _IceConnectionStrings[i])) != NULL) + { + char ch = *(strptr + strlen (_IceConnectionStrings[i])); + if (ch == ',' || ch == '\0') + { + /* + * OK, we found a connection. Make sure we can reuse it. + */ + + IceConn newIceConn = _IceConnectionObjs[i]; + + if (newIceConn->want_to_close || newIceConn->free_asap || + (context && newIceConn->context && + newIceConn->context != context)) + { + /* force a new connection to be created */ + break; + } + + if (majorOpcodeCheck) + { + for (j = newIceConn->his_min_opcode; + j <= newIceConn->his_max_opcode; j++) + { + if (newIceConn->process_msg_info[ + j - newIceConn->his_min_opcode].in_use && + newIceConn->process_msg_info[ + j - newIceConn->his_min_opcode].my_opcode == + majorOpcodeCheck) + break; + } + + if (j <= newIceConn->his_max_opcode || + (newIceConn->protosetup_to_you && + newIceConn->protosetup_to_you->my_opcode == + majorOpcodeCheck)) + { + /* force a new connection to be created */ + break; + } + } + + newIceConn->open_ref_count++; + if (context && !newIceConn->context) + newIceConn->context = context; + return (newIceConn); + } + } + } + + if ((iceConn = (IceConn) malloc (sizeof (struct _IceConn))) == NULL) + { + strncpy (errorStringRet, "Can't malloc", errorLength); + return (NULL); + } + + + /* + * Open a network connection with the peer client. + */ + + if ((iceConn->trans_conn = ConnectToPeer (networkIdsList, + &iceConn->connection_string)) == NULL) + { + free ((char *) iceConn); + strncpy (errorStringRet, "Could not open network socket", errorLength); + return (NULL); + } + + /* + * Set close-on-exec so that programs that fork() don't get confused. + */ + + _kde_IceTransSetOption (iceConn->trans_conn, TRANS_CLOSEONEXEC, 1); + + iceConn->listen_obj = NULL; + + iceConn->connection_status = IceConnectPending; + iceConn->io_ok = True; + iceConn->dispatch_level = 0; + iceConn->context = context; + iceConn->my_ice_version_index = 0; + iceConn->send_sequence = 0; + iceConn->receive_sequence = 0; + + iceConn->vendor = NULL; + iceConn->release = NULL; + iceConn->outbuf = NULL; + + iceConn->scratch = NULL; + iceConn->scratch_size = 0; + + iceConn->process_msg_info = NULL; + + iceConn->connect_to_you = NULL; + iceConn->protosetup_to_you = NULL; + + iceConn->connect_to_me = NULL; + iceConn->protosetup_to_me = NULL; + + if ((iceConn->inbuf = iceConn->inbufptr = + (char *) malloc (ICE_INBUFSIZE)) == NULL) + { + _IceFreeConnection (iceConn); + strncpy (errorStringRet, "Can't malloc", errorLength); + return (NULL); + } + memset (iceConn->inbuf, 0, ICE_INBUFSIZE); + + iceConn->inbufmax = iceConn->inbuf + ICE_INBUFSIZE; + + if ((iceConn->outbuf = iceConn->outbufptr = + (char *) malloc (ICE_OUTBUFSIZE)) == NULL) + { + _IceFreeConnection (iceConn); + strncpy (errorStringRet, "Can't malloc", errorLength); + return (NULL); + } + memset (iceConn->outbuf, 0, ICE_OUTBUFSIZE); + + iceConn->outbufmax = iceConn->outbuf + ICE_OUTBUFSIZE; + + iceConn->open_ref_count = 1; + iceConn->proto_ref_count = 0; + + iceConn->skip_want_to_close = False; + iceConn->want_to_close = False; + iceConn->free_asap = False; + + iceConn->saved_reply_waits = NULL; + iceConn->ping_waits = NULL; + + iceConn->connect_to_you = (_IceConnectToYouInfo *) malloc ( + sizeof (_IceConnectToYouInfo)); + iceConn->connect_to_you->auth_active = 0; + + /* + * Send our byte order. + */ + + IceGetHeader (iceConn, 0, ICE_ByteOrder, + SIZEOF (iceByteOrderMsg), iceByteOrderMsg, pByteOrderMsg); + + endian = 1; + if (*(char *) &endian) + pByteOrderMsg->byteOrder = IceLSBfirst; + else + pByteOrderMsg->byteOrder = IceMSBfirst; + + IceFlush (iceConn); + + + /* + * Now read the ByteOrder message from the other client. + * iceConn->swap should be set to the appropriate boolean + * value after the call to IceProcessMessages. + */ + + iceConn->waiting_for_byteorder = True; + + ioErrorOccured = False; + while (iceConn->waiting_for_byteorder == True && !ioErrorOccured) + { + ioErrorOccured = (IceProcessMessages ( + iceConn, NULL, NULL) == IceProcessMessagesIOError); + } + + if (ioErrorOccured) + { + _IceFreeConnection (iceConn); + strncpy (errorStringRet, "IO error occurred opening connection", + errorLength); + return (NULL); + } + + if (iceConn->connection_status == IceConnectRejected) + { + /* + * We failed to get the required ByteOrder message. + */ + + _IceFreeConnection (iceConn); + strncpy (errorStringRet, + "Internal error - did not receive the expected ByteOrder message", + errorLength); + return (NULL); + } + + + /* + * Determine which authentication methods are available for + * the Connection Setup authentication. + */ + + _IceGetPoValidAuthIndices ( + "ICE", iceConn->connection_string, + _IceAuthCount, _IceAuthNames, &authUsableCount, authIndices); + + for (i = 0; i < _IceAuthCount; i++) + { + authUsableFlags[i] = 0; + for (j = 0; j < authUsableCount && !authUsableFlags[i]; j++) + authUsableFlags[i] = (authIndices[j] == i); + } + + + /* + * Now send a Connection Setup message. + */ + + extra = STRING_BYTES (IceVendorString) + STRING_BYTES (IceReleaseString); + + for (i = 0; i < _IceAuthCount; i++) + if (authUsableFlags[i]) + { + extra += STRING_BYTES (_IceAuthNames[i]); + } + + extra += (_IceVersionCount * 4); + + IceGetHeaderExtra (iceConn, 0, ICE_ConnectionSetup, + SIZEOF (iceConnectionSetupMsg), WORD64COUNT (extra), + iceConnectionSetupMsg, pSetupMsg, pData); + + setup_sequence = iceConn->send_sequence; + + pSetupMsg->versionCount = _IceVersionCount; + pSetupMsg->authCount = authUsableCount; + pSetupMsg->mustAuthenticate = mustAuthenticate; + + STORE_STRING (pData, IceVendorString); + STORE_STRING (pData, IceReleaseString); + + for (i = 0; i < _IceAuthCount; i++) + if (authUsableFlags[i]) + { + STORE_STRING (pData, _IceAuthNames[i]); + } + + for (i = 0; i < _IceVersionCount; i++) + { + STORE_CARD16 (pData, _IceVersions[i].major_version); + STORE_CARD16 (pData, _IceVersions[i].minor_version); + } + + IceFlush (iceConn); + + + /* + * Process messages until we get a Connection Reply or an Error Message. + * Authentication will take place behind the scenes. + */ + + replyWait.sequence_of_request = setup_sequence; + replyWait.major_opcode_of_request = 0; + replyWait.minor_opcode_of_request = ICE_ConnectionSetup; + replyWait.reply = (IcePointer) &reply; + + gotReply = False; + ioErrorOccured = False; + + while (!gotReply && !ioErrorOccured) + { + ioErrorOccured = (IceProcessMessages ( + iceConn, &replyWait, &gotReply) == IceProcessMessagesIOError); + + if (ioErrorOccured) + { + strncpy (errorStringRet, "IO error occurred opening connection", + errorLength); + _IceFreeConnection (iceConn); + iceConn = NULL; + } + else if (gotReply) + { + if (reply.type == ICE_CONNECTION_REPLY) + { + if (reply.connection_reply.version_index >= _IceVersionCount) + { + strncpy (errorStringRet, + "Got a bad version index in the Connection Reply", + errorLength); + + free (reply.connection_reply.vendor); + free (reply.connection_reply.release); + _IceFreeConnection (iceConn); + iceConn = NULL; + } + else + { + iceConn->my_ice_version_index = + reply.connection_reply.version_index; + iceConn->vendor = reply.connection_reply.vendor; + iceConn->release = reply.connection_reply.release; + + _IceConnectionObjs[_IceConnectionCount] = iceConn; + _IceConnectionStrings[_IceConnectionCount] = + iceConn->connection_string; + _IceConnectionCount++; + + free ((char *) iceConn->connect_to_you); + iceConn->connect_to_you = NULL; + + iceConn->connection_status = IceConnectAccepted; + } + } + else /* reply.type == ICE_CONNECTION_ERROR */ + { + /* Connection failed */ + + strncpy (errorStringRet, reply.connection_error.error_message, + errorLength); + + free (reply.connection_error.error_message); + + _IceFreeConnection (iceConn); + iceConn = NULL; + } + } + } + + if (iceConn && _IceWatchProcs) + { +#ifdef MINIX + _kde_IceTransSetOption(iceConn->trans_conn, TRANS_NONBLOCKING, 1); +#endif + /* + * Notify the watch procedures that an iceConn was opened. + */ + + _IceConnectionOpened (iceConn); + } + + return (iceConn); +} + + + +IcePointer +IceGetConnectionContext (iceConn) + +IceConn iceConn; + +{ + return (iceConn->context); +} + + + +/* ------------------------------------------------------------------------- * + * local routines * + * ------------------------------------------------------------------------- */ + +#define ICE_CONNECTION_RETRIES 5 + + +static XtransConnInfo +ConnectToPeer (char *networkIdsList, char **actualConnectionRet) +{ + char address[256]; + char *ptr, *endptr, *delim; + int madeConnection = 0; + int len, retry; + int connect_stat; + XtransConnInfo trans_conn = NULL; + + *actualConnectionRet = NULL; + + ptr = networkIdsList; + endptr = networkIdsList + strlen (networkIdsList); + + while (ptr < endptr && !madeConnection) + { + if ((delim = (char *) strchr (ptr, ',')) == NULL) + delim = endptr; + + len = delim - ptr; + if (len > (int) sizeof(address) - 1) + len = sizeof(address) - 1; + strncpy (address, ptr, len); + address[len] = '\0'; + + ptr = delim + 1; + + for (retry = ICE_CONNECTION_RETRIES; retry >= 0; retry--) + { + if ((trans_conn = (XtransConnInfo)_kde_IceTransOpenCOTSClient (address)) == NULL) + { + break; + } + + if ((connect_stat = _kde_IceTransConnect (trans_conn, address)) < 0) + { + _kde_IceTransClose (trans_conn); + + if (connect_stat == TRANS_TRY_CONNECT_AGAIN) + { + sleep(1); + continue; + } + else + break; + } + else + { + madeConnection = 1; + break; + } + } + } + + + if (madeConnection) + { + /* + * We need to return the actual network connection string + */ + + *actualConnectionRet = (char *) malloc (strlen (address) + 1); + strcpy (*actualConnectionRet, address); + + + /* + * Return the file descriptor + */ + + return (trans_conn); + } + else + { + return (NULL); + } +} diff --git a/dcop/KDE-ICE/error.c b/dcop/KDE-ICE/error.c new file mode 100644 index 000000000..c187d7cd7 --- /dev/null +++ b/dcop/KDE-ICE/error.c @@ -0,0 +1,650 @@ +/* $XConsortium: error.c /main/16 1995/09/15 13:54:01 mor $ */ +/****************************************************************************** + + +Copyright (c) 1993 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from the X Consortium. + +Author: Ralph Mor, X Consortium +******************************************************************************/ + +#include "KDE-ICE/ICElib.h" +#include "KDE-ICE/ICElibint.h" +#include "KDE-ICE/globals.h" + +#include <stdio.h> +#include <string.h> +#include <errno.h> + +#ifdef X_NOT_STDC_ENV +extern int errno; +#endif + + +void +_IceErrorBadMinor (iceConn, majorOpcode, offendingMinor, severity) + +IceConn iceConn; +int majorOpcode; +int offendingMinor; +int severity; + +{ + IceErrorHeader (iceConn, + majorOpcode, offendingMinor, + iceConn->receive_sequence, + severity, + IceBadMinor, + 0); + + IceFlush (iceConn); +} + + +void +_IceErrorBadState (iceConn, majorOpcode, offendingMinor, severity) + +IceConn iceConn; +int majorOpcode; +int offendingMinor; +int severity; + +{ + IceErrorHeader (iceConn, + majorOpcode, offendingMinor, + iceConn->receive_sequence, + severity, + IceBadState, + 0); + + IceFlush (iceConn); +} + + +void +_IceErrorBadLength (iceConn, majorOpcode, offendingMinor, severity) + +IceConn iceConn; +int majorOpcode; +int offendingMinor; +int severity; + +{ + IceErrorHeader (iceConn, + majorOpcode, offendingMinor, + iceConn->receive_sequence, + severity, + IceBadLength, + 0); + + IceFlush (iceConn); +} + + +void +_IceErrorBadValue (iceConn, majorOpcode, offendingMinor, offset, length, value) + +IceConn iceConn; +int majorOpcode; +int offendingMinor; +int offset; +int length; /* in bytes */ +IcePointer value; + +{ + IceErrorHeader (iceConn, + majorOpcode, offendingMinor, + iceConn->receive_sequence, + IceCanContinue, + IceBadValue, + WORD64COUNT (8 + length)); + + IceWriteData32 (iceConn, 4, &offset); + IceWriteData32 (iceConn, 4, &length); + IceWriteData (iceConn, length, (char *) value); + + if (PAD64 (length)) + IceWritePad (iceConn, PAD64 (length)); + + IceFlush (iceConn); +} + + +void +_IceErrorNoAuthentication (iceConn, offendingMinor) + +IceConn iceConn; +int offendingMinor; + +{ + int severity = (offendingMinor == ICE_ConnectionSetup) ? + IceFatalToConnection : IceFatalToProtocol; + + IceErrorHeader (iceConn, + 0, offendingMinor, + iceConn->receive_sequence, + severity, + IceNoAuth, + 0); + + IceFlush (iceConn); +} + + +void +_IceErrorNoVersion (iceConn, offendingMinor) + +IceConn iceConn; +int offendingMinor; + +{ + int severity = (offendingMinor == ICE_ConnectionSetup) ? + IceFatalToConnection : IceFatalToProtocol; + + IceErrorHeader (iceConn, + 0, offendingMinor, + iceConn->receive_sequence, + severity, + IceNoVersion, + 0); + + IceFlush (iceConn); +} + + +void +_IceErrorSetupFailed (iceConn, offendingMinor, reason) + +IceConn iceConn; +int offendingMinor; +const char *reason; + +{ + char *pBuf, *pStart; + int bytes; + int severity = (offendingMinor == ICE_ConnectionSetup) ? + IceFatalToConnection : IceFatalToProtocol; + + if (!reason) + reason = ""; + bytes = STRING_BYTES (reason); + + IceErrorHeader (iceConn, + 0, offendingMinor, + iceConn->receive_sequence, + severity, + IceSetupFailed, + WORD64COUNT (bytes)); + + pBuf = pStart = IceAllocScratch (iceConn, PADDED_BYTES64 (bytes)); + STORE_STRING (pBuf, reason); + + IceWriteData (iceConn, PADDED_BYTES64 (bytes), pStart); + IceFlush (iceConn); +} + + +void +_IceErrorAuthenticationRejected (iceConn, offendingMinor, reason) + +IceConn iceConn; +int offendingMinor; +const char *reason; + +{ + char *pBuf, *pStart; + int bytes; + + if (!reason) + reason = ""; + bytes = STRING_BYTES (reason); + + IceErrorHeader (iceConn, + 0, offendingMinor, + iceConn->receive_sequence, + IceFatalToProtocol, + IceAuthRejected, + WORD64COUNT (bytes)); + + pBuf = pStart = IceAllocScratch (iceConn, PADDED_BYTES64 (bytes)); + STORE_STRING (pBuf, reason); + + IceWriteData (iceConn, PADDED_BYTES64 (bytes), pStart); + IceFlush (iceConn); +} + + +void +_IceErrorAuthenticationFailed (iceConn, offendingMinor, reason) + +IceConn iceConn; +int offendingMinor; +const char *reason; + +{ + char *pBuf, *pStart; + int bytes; + + if (!reason) + reason = ""; + bytes = STRING_BYTES (reason); + + IceErrorHeader (iceConn, + 0, offendingMinor, + iceConn->receive_sequence, + IceFatalToProtocol, + IceAuthFailed, + WORD64COUNT (bytes)); + + pBuf = pStart = IceAllocScratch (iceConn, PADDED_BYTES64 (bytes)); + STORE_STRING (pBuf, reason); + + IceWriteData (iceConn, PADDED_BYTES64 (bytes), pStart); + IceFlush (iceConn); +} + + +void +_IceErrorProtocolDuplicate (iceConn, protocolName) + +IceConn iceConn; +const char *protocolName; + +{ + char *pBuf, *pStart; + int bytes; + + if (!protocolName) + protocolName = ""; + bytes = STRING_BYTES (protocolName); + + IceErrorHeader (iceConn, + 0, ICE_ProtocolSetup, + iceConn->receive_sequence, + IceFatalToProtocol, + IceProtocolDuplicate, + WORD64COUNT (bytes)); + + pBuf = pStart = IceAllocScratch (iceConn, PADDED_BYTES64 (bytes)); + STORE_STRING (pBuf, protocolName); + + IceWriteData (iceConn, PADDED_BYTES64 (bytes), pStart); + IceFlush (iceConn); +} + + +void +_IceErrorMajorOpcodeDuplicate (iceConn, majorOpcode) + +IceConn iceConn; +int majorOpcode; + +{ + char mOp[8]; + mOp[0] = (char) majorOpcode; + mOp[1] = mOp[2] = mOp[3] = mOp[4] = mOp[5] = mOp[6] = mOp[7] = 0; + + IceErrorHeader (iceConn, + 0, ICE_ProtocolSetup, + iceConn->receive_sequence, + IceFatalToProtocol, + IceMajorOpcodeDuplicate, + 1 /* length */); + + IceWriteData (iceConn, 8, mOp); + IceFlush (iceConn); +} + + +void +_IceErrorUnknownProtocol (iceConn, protocolName) + +IceConn iceConn; +const char *protocolName; + +{ + char *pBuf, *pStart; + int bytes; + + if (!protocolName) + protocolName = ""; + bytes = STRING_BYTES (protocolName); + + IceErrorHeader (iceConn, + 0, ICE_ProtocolSetup, + iceConn->receive_sequence, + IceFatalToProtocol, + IceUnknownProtocol, + WORD64COUNT (bytes)); + + pBuf = pStart = IceAllocScratch (iceConn, PADDED_BYTES64 (bytes)); + STORE_STRING (pBuf, protocolName); + + IceWriteData (iceConn, PADDED_BYTES64 (bytes), pStart); + IceFlush (iceConn); +} + + +void +_IceErrorBadMajor (iceConn, offendingMajor, offendingMinor, severity) + +IceConn iceConn; +int offendingMajor; +int offendingMinor; +int severity; + +{ + char maj[8]; + maj[0] = (char) offendingMajor; + maj[1] = maj[2] = maj[3] = maj[4] = maj[5] = maj[6] = maj[7] = 0; + + IceErrorHeader (iceConn, + 0, offendingMinor, + iceConn->receive_sequence, + severity, + IceBadMajor, + 1 /* length */); + + IceWriteData (iceConn, 8, maj); + IceFlush (iceConn); +} + + + +/* + * Default error handler. + */ + +void +_IceDefaultErrorHandler (iceConn, swap, + offendingMinorOpcode, offendingSequence, errorClass, severity, values) + +IceConn iceConn; +Bool swap; +int offendingMinorOpcode; +unsigned long offendingSequence; +int errorClass; +int severity; +IcePointer values; + +{ + char *str; + char *pData = (char *) values; + (void)iceConn;/*unused*/ + + switch (offendingMinorOpcode) + { + case ICE_ConnectionSetup: + str = (char *)"ConnectionSetup"; + break; + case ICE_AuthRequired: + str = (char *)"AuthRequired"; + break; + case ICE_AuthReply: + str = (char *)"AuthReply"; + break; + case ICE_AuthNextPhase: + str = (char *)"AuthNextPhase"; + break; + case ICE_ConnectionReply: + str = (char *)"ConnectionReply"; + break; + case ICE_ProtocolSetup: + str = (char *)"ProtocolSetup"; + break; + case ICE_ProtocolReply: + str = (char *)"ProtocolReply"; + break; + case ICE_Ping: + str = (char *)"Ping"; + break; + case ICE_PingReply: + str = (char *)"PingReply"; + break; + case ICE_WantToClose: + str = (char *)"WantToClose"; + break; + case ICE_NoClose: + str = (char *)"NoClose"; + break; + default: + str = (char *)""; + } + + fprintf (stderr, "\n"); + + fprintf (stderr, "ICE error: Offending minor opcode = %d (%s)\n", + offendingMinorOpcode, str); + + fprintf (stderr, " Offending sequence number = %ld\n", + offendingSequence); + + switch (errorClass) + { + case IceBadMinor: + str = (char *)"BadMinor"; + break; + case IceBadState: + str = (char *)"BadState"; + break; + case IceBadLength: + str = (char *)"BadLength"; + break; + case IceBadValue: + str = (char *)"BadValue"; + break; + case IceBadMajor: + str = (char *)"BadMajor"; + break; + case IceNoAuth: + str = (char *)"NoAuthentication"; + break; + case IceNoVersion: + str = (char *)"NoVersion"; + break; + case IceSetupFailed: + str = (char *)"SetupFailed"; + break; + case IceAuthRejected: + str = (char *)"AuthenticationRejected"; + break; + case IceAuthFailed: + str = (char *)"AuthenticationFailed"; + break; + case IceProtocolDuplicate: + str = (char *)"ProtocolDuplicate"; + break; + case IceMajorOpcodeDuplicate: + str = (char *)"MajorOpcodeDuplicate"; + break; + case IceUnknownProtocol: + str = (char *)"UnknownProtocol"; + break; + default: + str = (char *)"???"; + } + + fprintf (stderr, " Error class = %s\n", str); + + if (severity == IceCanContinue) + str = (char *)"CanContinue"; + else if (severity == IceFatalToProtocol) + str = (char *)"FatalToProtocol"; + else if (severity == IceFatalToConnection) + str = (char *)"FatalToConnection"; + else + str = (char *)"???"; + + fprintf (stderr, " Severity = %s\n", str); + + switch (errorClass) + { + case IceBadValue: + { + int offset, length, val; + + EXTRACT_CARD32 (pData, swap, offset); + EXTRACT_CARD32 (pData, swap, length); + + fprintf (stderr, + " BadValue Offset = %d\n", offset); + fprintf (stderr, + " BadValue Length = %d\n", length); + + if (length <= 4) + { + if (length == 1) + val = (int) *pData; + else if (length == 2) + { + EXTRACT_CARD16 (pData, swap, val); + } + else + { + EXTRACT_CARD32 (pData, swap, val); + } + + fprintf (stderr, + " BadValue = %d\n", val); + } + break; + } + + case IceBadMajor: + + fprintf (stderr, "Major opcode : %d\n", (int) *pData); + break; + + case IceSetupFailed: + + EXTRACT_STRING (pData, swap, str); + fprintf (stderr, "Reason : %s\n", str); + break; + + case IceAuthRejected: + + EXTRACT_STRING (pData, swap, str); + fprintf (stderr, "Reason : %s\n", str); + break; + + case IceAuthFailed: + + EXTRACT_STRING (pData, swap, str); + fprintf (stderr, "Reason : %s\n", str); + break; + + case IceProtocolDuplicate: + + EXTRACT_STRING (pData, swap, str); + fprintf (stderr, "Protocol name : %s\n", str); + break; + + case IceMajorOpcodeDuplicate: + + fprintf (stderr, "Major opcode : %d\n", (int) *pData); + break; + + case IceUnknownProtocol: + + EXTRACT_STRING (pData, swap, str); + fprintf (stderr, "Protocol name : %s\n", str); + break; + + default: + break; + } + + fprintf (stderr, "\n"); + + if (severity != IceCanContinue) + exit (1); +} + + + +/* + * This procedure sets the ICE error handler to be the specified + * routine. If NULL is passed in the default error handler is restored. + * The function's return value is the previous error handler. + */ + +IceErrorHandler +IceSetErrorHandler (handler) + +IceErrorHandler handler; + +{ + IceErrorHandler oldHandler = _IceErrorHandler; + + if (handler != NULL) + _IceErrorHandler = handler; + else + _IceErrorHandler = _IceDefaultErrorHandler; + + return (oldHandler); +} + + + +/* + * Default IO error handler. + */ + +void +_IceDefaultIOErrorHandler (iceConn) + +IceConn iceConn; + +{ + (void)iceConn;/*unused*/ + fprintf (stderr, + "ICE default IO error handler doing an exit(), pid = %d, errno = %d\n", + getpid(), errno); + + exit (1); +} + + + +/* + * This procedure sets the ICE fatal I/O error handler to be the + * specified routine. If NULL is passed in the default error + * handler is restored. The function's return value is the + * previous error handler. + */ + +IceIOErrorHandler +IceSetIOErrorHandler (handler) + +IceIOErrorHandler handler; + +{ + IceIOErrorHandler oldHandler = _IceIOErrorHandler; + + if (handler != NULL) + _IceIOErrorHandler = handler; + else + _IceIOErrorHandler = _IceDefaultIOErrorHandler; + + return (oldHandler); +} diff --git a/dcop/KDE-ICE/getauth.c b/dcop/KDE-ICE/getauth.c new file mode 100644 index 000000000..8699d6563 --- /dev/null +++ b/dcop/KDE-ICE/getauth.c @@ -0,0 +1,269 @@ +/* $XConsortium: getauth.c,v 1.8 94/04/17 20:15:33 mor Exp $ */ +/****************************************************************************** + + +Copyright (c) 1993 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from the X Consortium. + +Author: Ralph Mor, X Consortium +******************************************************************************/ + +#include "KDE-ICE/ICElib.h" +#include "KDE-ICE/ICElibint.h" +#include "KDE-ICE/ICEutil.h" +#include "KDE-ICE/globals.h" +#include <string.h> +#ifdef _AIX +#include <sys/access.h> +#endif + +static Bool auth_valid (const char *auth_name, int num_auth_names, const char **auth_names, int *index_ret); + +extern IceAuthDataEntry _IcePaAuthDataEntries[]; + + +/* + * The functions in this file are not a standard part of ICElib. + * + * The sample implementation uses an .ICEauthority to manipulate + * authentication data. + * + * For the client that initiates a Protocol Setup, we look in the + * .ICEauthority file to get the data. + * + * For the client accepting the Protocol Setup, we get the data + * from an in-memory database of authentication data (set by the + * application calling IceSetPaAuthData). We have to get the data + * from memory because getting it directly from the .ICEauthority + * file is not secure - someone can just modify the contents of the + * .ICEauthority file behind our back. + */ + +void +_IceGetPoAuthData (protocolName, networkId, authName, + authDataLenRet, authDataRet) + +const char *protocolName; +const char *networkId; +const char *authName; +unsigned short *authDataLenRet; +char **authDataRet; + +{ + IceAuthFileEntry *entry; + + entry = IceGetAuthFileEntry (protocolName, networkId, authName); + + if (entry) + { + *authDataLenRet = entry->auth_data_length; + + if ((*authDataRet = (char *) malloc (entry->auth_data_length)) != NULL) + memcpy (*authDataRet, entry->auth_data, entry->auth_data_length); + } + else + { + *authDataLenRet = 0; + *authDataRet = NULL; + } + + IceFreeAuthFileEntry (entry); +} + + + +void +_IceGetPaAuthData (protocolName, networkId, authName, + authDataLenRet, authDataRet) + +const char *protocolName; +const char *networkId; +const char *authName; +unsigned short *authDataLenRet; +char **authDataRet; + +{ + IceAuthDataEntry *entry = NULL; + int found = 0; + int i; + + for (i = 0; i < _IcePaAuthDataEntryCount && !found; i++) + { + entry = &_IcePaAuthDataEntries[i]; + + found = + strcmp (protocolName, entry->protocol_name) == 0 && + strcmp (networkId, entry->network_id) == 0 && + strcmp (authName, entry->auth_name) == 0; + } + + if (found) + { + *authDataLenRet = entry->auth_data_length; + + if ((*authDataRet = (char *) malloc (entry->auth_data_length)) != NULL) + memcpy (*authDataRet, entry->auth_data, entry->auth_data_length); + } + else + { + *authDataLenRet = 0; + *authDataRet = NULL; + } +} + + + +void +_IceGetPoValidAuthIndices (protocol_name, network_id, + num_auth_names, auth_names, num_indices_ret, indices_ret) + +const char *protocol_name; +const char *network_id; +int num_auth_names; +const char **auth_names; +int *num_indices_ret; +int *indices_ret; /* in/out arg */ + +{ + FILE *auth_file; + char *filename; + IceAuthFileEntry *entry; + int index_ret, i; + + *num_indices_ret = 0; + + if (!(filename = IceAuthFileName ())) + return; + + if (access (filename, R_OK) != 0) /* checks REAL id */ + return; + + if (!(auth_file = fopen (filename, "rb"))) + return; + + for (;;) + { + if (!(entry = IceReadAuthFileEntry (auth_file))) + break; + + if (strcmp (protocol_name, entry->protocol_name) == 0 && + strcmp (network_id, entry->network_id) == 0 && + auth_valid (entry->auth_name, num_auth_names, + auth_names, &index_ret)) + { + /* + * Make sure we didn't store this index already. + */ + + for (i = 0; i < *num_indices_ret; i++) + if (index_ret == indices_ret[i]) + break; + + if (i >= *num_indices_ret) + { + indices_ret[*num_indices_ret] = index_ret; + *num_indices_ret += 1; + } + } + + IceFreeAuthFileEntry (entry); + } + + fclose (auth_file); +} + + + +void +_IceGetPaValidAuthIndices (protocol_name, network_id, + num_auth_names, auth_names, num_indices_ret, indices_ret) + +const char *protocol_name; +const char *network_id; +int num_auth_names; +const char **auth_names; +int *num_indices_ret; +int *indices_ret; /* in/out arg */ + +{ + int index_ret; + int i, j; + IceAuthDataEntry *entry; + + *num_indices_ret = 0; + + for (i = 0; i < _IcePaAuthDataEntryCount; i++) + { + entry = &_IcePaAuthDataEntries[i]; + + if (strcmp (protocol_name, entry->protocol_name) == 0 && + strcmp (network_id, entry->network_id) == 0 && + auth_valid (entry->auth_name, num_auth_names, + auth_names, &index_ret)) + { + /* + * Make sure we didn't store this index already. + */ + + for (j = 0; j < *num_indices_ret; j++) + if (index_ret == indices_ret[j]) + break; + + if (j >= *num_indices_ret) + { + indices_ret[*num_indices_ret] = index_ret; + *num_indices_ret += 1; + } + } + } +} + + + +/* + * local routines + */ + +static Bool +auth_valid (const char *auth_name, int num_auth_names, const char **auth_names, int *index_ret) +{ + /* + * Check if auth_name is in auth_names. Return index. + */ + + int i; + + for (i = 0; i < num_auth_names; i++) + if (strcmp (auth_name, auth_names[i]) == 0) + { + break; + } + + if (i < num_auth_names) + { + *index_ret = i; + return (1); + } + else + return (0); +} diff --git a/dcop/KDE-ICE/globals.c b/dcop/KDE-ICE/globals.c new file mode 100644 index 000000000..84114918b --- /dev/null +++ b/dcop/KDE-ICE/globals.c @@ -0,0 +1,56 @@ +/* $XConsortium: globals.h,v 1.14 94/04/17 20:15:33 mor Exp $ */ +/****************************************************************************** + + +Copyright (c) 1993 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from the X Consortium. + +Author: Ralph Mor, X Consortium +******************************************************************************/ +/* $XFree86: xc/lib/ICE/globals.h,v 1.1.1.1.12.2 1998/10/19 20:57:04 hohndel Exp $ */ + +#include "KDE-ICE/ICElib.h" +#include "KDE-ICE/ICElibint.h" +#include "KDE-ICE/globals.h" + +IceConn _IceConnectionObjs[256]; +char *_IceConnectionStrings[256]; +int _IceConnectionCount = 0; + +_IceProtocol _IceProtocols[255]; +int _IceLastMajorOpcode = 0; + +int _IceAuthCount = 1; +const char *_IceAuthNames[] = {"MIT-MAGIC-COOKIE-1"}; +IcePoAuthProc _IcePoAuthProcs[] = {_IcePoMagicCookie1Proc}; +IcePaAuthProc _IcePaAuthProcs[] = {_IcePaMagicCookie1Proc}; + +int _IceVersionCount = 1; +_IceVersion _IceVersions[] = { + {IceProtoMajor, IceProtoMinor, _IceProcessCoreMessage}}; + +_IceWatchProc *_IceWatchProcs = NULL; + +IceErrorHandler _IceErrorHandler = _IceDefaultErrorHandler; +IceIOErrorHandler _IceIOErrorHandler = _IceDefaultIOErrorHandler; +IceWriteHandler _IceWriteHandler = _IceWrite; diff --git a/dcop/KDE-ICE/globals.h b/dcop/KDE-ICE/globals.h new file mode 100644 index 000000000..814e8980c --- /dev/null +++ b/dcop/KDE-ICE/globals.h @@ -0,0 +1,146 @@ +/* $XConsortium: globals.h,v 1.14 94/04/17 20:15:33 mor Exp $ */ +/****************************************************************************** + + +Copyright (c) 1993 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from the X Consortium. + +Author: Ralph Mor, X Consortium +******************************************************************************/ +/* $XFree86: xc/lib/ICE/globals.h,v 1.1.1.1.12.2 1998/10/19 20:57:04 hohndel Exp $ */ + +#include "KDE-ICE/ICElib.h" +#include "KDE-ICE/ICElibint.h" +#include "KDE-ICE/ICEutil.h" + +#define _IceDefaultErrorHandler _kde_IceDefaultErrorHandler + +extern void _IceDefaultErrorHandler ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + Bool /* swap */, + int /* offendingMinorOpcode */, + unsigned long /* offendingSequence */, + int /* errorClass */, + int /* severity */, + IcePointer /* values */ +#endif +); + +#define _IceDefaultIOErrorHandler _kde_IceDefaultIOErrorHandler + +extern void _IceDefaultIOErrorHandler ( +#if NeedFunctionPrototypes + IceConn /* iceConn */ +#endif +); + +#define _IcePoMagicCookie1Proc _kde_IcePoMagicCookie1Proc + +extern IcePoAuthStatus _IcePoMagicCookie1Proc ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + IcePointer * /* authStatePtr */, + Bool /* cleanUp */, + Bool /* swap */, + int /* authDataLen */, + IcePointer /* authData */, + int * /* replyDataLenRet */, + IcePointer * /* replyDataRet */, + char ** /* errorStringRet */ +#endif +); + +#define _IcePaMagicCookie1Proc _kde_IcePaMagicCookie1Proc + +extern IcePaAuthStatus _IcePaMagicCookie1Proc ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + IcePointer * /* authStatePtr */, + Bool /* swap */, + int /* authDataLen */, + IcePointer /* authData */, + int * /* replyDataLenRet */, + IcePointer * /* replyDataRet */, + char ** /* errorStringRet */ +#endif +); + +#define _IceProcessCoreMessage _kde_IceProcessCoreMessage + +extern void _IceProcessCoreMessage ( +#if NeedFunctionPrototypes + IceConn /* iceConn */, + int /* opcode */, + unsigned long /* length */, + Bool /* swap */, + IceReplyWaitInfo * /* replyWait */, + Bool * /* replyReadyRet */, + Bool * /* connectionClosedRet */ +#endif +); + +#define _IceConnectionObjs _kde_IceConnectionObjs +#define _IceConnectionStrings _kde_IceConnectionStrings +#define _IceConnectionCount _kde_IceConnectionCount + +extern IceConn _IceConnectionObjs[256]; +extern char *_IceConnectionStrings[256]; +extern int _IceConnectionCount; + +#define _IceProtocols _kde_IceProtocols +#define _IceLastMajorOpcode _kde_IceLastMajorOpcode + +extern _IceProtocol _IceProtocols[255]; +extern int _IceLastMajorOpcode; + +#define _IceAuthCount _kde_IceAuthCount +#define _IceAuthNames _kde_IceAuthNames +#define _IcePoAuthProcs _kde_IcePoAuthProcs +#define _IcePaAuthProcs _kde_IcePaAuthProcs + +extern int _IceAuthCount; +extern const char *_IceAuthNames[]; +extern IcePoAuthProc _IcePoAuthProcs[]; +extern IcePaAuthProc _IcePaAuthProcs[]; + +#define _IceVersionCount _kde_IceVersionCount +#define _IceVersions _kde_IceVersions +#define _IceWatchProcs _kde_IceWatchProcs + +extern int _IceVersionCount; +extern _IceVersion _IceVersions[]; + +extern _IceWatchProc *_IceWatchProcs; + +#define _IceErrorHandler _kde_IceErrorHandler +#define _IceIOErrorHandler _kde_IceIOErrorHandler + +extern IceErrorHandler _IceErrorHandler; +extern IceIOErrorHandler _IceIOErrorHandler; + +#define _IcePaAuthDataEntryCount _kde_IcePaAuthDataEntryCount +#define _IcePaAuthDataEntries _kde_IcePaAuthDataEntries + +extern int _IcePaAuthDataEntryCount; +extern IceAuthDataEntry _IcePaAuthDataEntries[]; diff --git a/dcop/KDE-ICE/iceauth.c b/dcop/KDE-ICE/iceauth.c new file mode 100644 index 000000000..72297ceb5 --- /dev/null +++ b/dcop/KDE-ICE/iceauth.c @@ -0,0 +1,273 @@ +/* $XConsortium: iceauth.c,v 1.21 94/12/20 16:49:58 mor Exp $ */ +/* $XFree86: xc/lib/ICE/iceauth.c,v 3.1 1995/01/27 04:44:52 dawes Exp $ */ +/****************************************************************************** + + +Copyright (c) 1993 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from the X Consortium. + +Author: Ralph Mor, X Consortium +******************************************************************************/ + +#include "KDE-ICE/ICElib.h" +#include "KDE-ICE/ICElibint.h" +#include "KDE-ICE/ICEutil.h" +#include "KDE-ICE/globals.h" + +#include <sys/time.h> +#include <string.h> + +#if defined(X_NOT_STDC_ENV) && !defined(__EMX__) +#define Time_t long +extern Time_t time (); +#else +#include <time.h> +#define Time_t time_t +#endif + +static int binaryEqual (register const char *a, register const char *b, register unsigned len); + +static int was_called_state; + +/* + * MIT-MAGIC-COOKIE-1 is a sample authentication method implemented by + * the SI. It is not part of standard ICElib. + */ + + +char * +IceGenerateMagicCookie (len) + +int len; + +{ + char *auth; + long ldata[2]; + int seed; + int value; + int i; + + if ((auth = (char *) malloc (len + 1)) == NULL) + return (NULL); + + { + struct timeval now; + gettimeofday(&now, 0); + ldata[0] = now.tv_sec; + ldata[1] = now.tv_usec; + } + seed = (ldata[0]) + (ldata[1] << 16); + srand (seed); + for (i = 0; i < len; i++) + { + value = rand (); + auth[i] = value & 0xff; + } + auth[len] = '\0'; + + return (auth); +} + + +IcePoAuthStatus +_IcePoMagicCookie1Proc (iceConn, authStatePtr, cleanUp, swap, + authDataLen, authData, replyDataLenRet, replyDataRet, errorStringRet) + +IceConn iceConn; +IcePointer *authStatePtr; +Bool cleanUp; +Bool swap; +int authDataLen; +IcePointer authData; +int *replyDataLenRet; +IcePointer *replyDataRet; +char **errorStringRet; + +{ + (void)swap;/*unused*/ + (void)authDataLen;/*unused*/ + (void)authData;/*unused*/ + if (cleanUp) + { + /* + * We didn't allocate any state. We're done. + */ + + return (IcePoAuthDoneCleanup); + } + + *errorStringRet = NULL; + + if (*authStatePtr == NULL) + { + /* + * This is the first time we're being called. Search the + * authentication data for the first occurrence of + * MIT-MAGIC-COOKIE-1 that matches iceConn->connection_string. + */ + + unsigned short length; + char *data; + + _IceGetPoAuthData ("ICE", iceConn->connection_string, + "MIT-MAGIC-COOKIE-1", &length, &data); + + if (!data) + { + const char *tempstr = + "Could not find correct MIT-MAGIC-COOKIE-1 authentication"; + + *errorStringRet = (char *) malloc (strlen (tempstr) + 1); + if (*errorStringRet) + strcpy (*errorStringRet, tempstr); + + return (IcePoAuthFailed); + } + else + { + *authStatePtr = (IcePointer) &was_called_state; + + *replyDataLenRet = length; + *replyDataRet = data; + + return (IcePoAuthHaveReply); + } + } + else + { + /* + * We should never get here for MIT-MAGIC-COOKIE-1 since it is + * a single pass authentication method. + */ + + const char *tempstr = "MIT-MAGIC-COOKIE-1 authentication internal error"; + + *errorStringRet = (char *) malloc (strlen (tempstr) + 1); + if (*errorStringRet) + strcpy (*errorStringRet, tempstr); + + return (IcePoAuthFailed); + } +} + + + +IcePaAuthStatus +_IcePaMagicCookie1Proc (iceConn, authStatePtr, swap, + authDataLen, authData, replyDataLenRet, replyDataRet, errorStringRet) + +IceConn iceConn; +IcePointer *authStatePtr; +Bool swap; +int authDataLen; +IcePointer authData; +int *replyDataLenRet; +IcePointer *replyDataRet; +char **errorStringRet; + +{ + (void)swap;/*unused*/ + *errorStringRet = NULL; + *replyDataLenRet = 0; + *replyDataRet = NULL; + + if (*authStatePtr == NULL) + { + /* + * This is the first time we're being called. We don't have + * any data to pass to the other client. + */ + + *authStatePtr = (IcePointer) &was_called_state; + + return (IcePaAuthContinue); + } + else + { + /* + * Search the authentication data for the first occurrence of + * MIT-MAGIC-COOKIE-1 that matches iceConn->connection_string. + */ + + unsigned short length; + char *data; + + _IceGetPaAuthData ("ICE", iceConn->connection_string, + "MIT-MAGIC-COOKIE-1", &length, &data); + + if (data) + { + IcePaAuthStatus status; + + if (authDataLen == length && + binaryEqual ((char *) authData, data, authDataLen)) + { + status = IcePaAuthAccepted; + } + else + { + const char *tempstr = "MIT-MAGIC-COOKIE-1 authentication rejected"; + + *errorStringRet = (char *) malloc (strlen (tempstr) + 1); + if (*errorStringRet) + strcpy (*errorStringRet, tempstr); + + status = IcePaAuthRejected; + } + + free (data); + return (status); + } + else + { + /* + * We should never get here because in the ConnectionReply + * we should have passed all the valid methods. So we should + * always find a valid entry. + */ + + const char *tempstr = + "MIT-MAGIC-COOKIE-1 authentication internal error"; + + *errorStringRet = (char *) malloc (strlen (tempstr) + 1); + if (*errorStringRet) + strcpy (*errorStringRet, tempstr); + + return (IcePaAuthFailed); + } + } +} + + + +/* + * local routines + */ + +static int binaryEqual (register const char *a, register const char *b, register unsigned len) +{ + while (len--) + if (*a++ != *b++) + return 0; + return 1; +} diff --git a/dcop/KDE-ICE/listen.c b/dcop/KDE-ICE/listen.c new file mode 100644 index 000000000..03b715c27 --- /dev/null +++ b/dcop/KDE-ICE/listen.c @@ -0,0 +1,297 @@ +/* $XConsortium: listen.c,v 1.15 94/05/02 11:22:36 mor Exp $ */ +/****************************************************************************** + + +Copyright (c) 1993 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from the X Consortium. + +Author: Ralph Mor, X Consortium +******************************************************************************/ + +#include <KDE-ICE/ICElib.h> +#include "KDE-ICE/ICElibint.h" +#include "KDE-ICE/Xtrans.h" +#include <stdio.h> +#include <time.h> +#include <string.h> + + +Status +IceListenForConnections (countRet, listenObjsRet, errorLength, errorStringRet) + +int *countRet; +IceListenObj **listenObjsRet; +int errorLength; +char *errorStringRet; + +{ + struct _IceListenObj *listenObjs; + char *networkId; + int transCount, partial, i, j; + int result = -1; + int count = 0; + Status status = 1; + XtransConnInfo *transConns = NULL; + + while ((result < 0) && (count < 5)) + { + char port[128]; +#ifdef _WIN32 + int nTCPPort = ((getpid() + time(NULL) + count) % 32768) + 1024; + sprintf(port, "%d", nTCPPort); +#else + sprintf(port, "dcop%d-%ld", getpid(), time(NULL)+count); +#endif + result = _kde_IceTransMakeAllCOTSServerListeners (port, &partial, + &transCount, &transConns); + count++; + } + + if ((result < 0) || (transCount < 1)) + { + *listenObjsRet = NULL; + *countRet = 0; + + strncpy (errorStringRet, + "Cannot establish any listening sockets", errorLength); + + return (0); + } + + if ((listenObjs = (struct _IceListenObj *) malloc ( + transCount * sizeof (struct _IceListenObj))) == NULL) + { + for (i = 0; i < transCount; i++) + _kde_IceTransClose (transConns[i]); + free ((char *) transConns); + return (0); + } + + *countRet = 0; + + for (i = 0; i < transCount; i++) + { + networkId = (char*)_kde_IceTransGetMyNetworkId (transConns[i]); + + if (networkId) + { + listenObjs[*countRet].trans_conn = transConns[i]; + listenObjs[*countRet].network_id = networkId; + + (*countRet)++; + } + } + + if (*countRet == 0) + { + *listenObjsRet = NULL; + + strncpy (errorStringRet, + "Cannot establish any listening sockets", errorLength); + + status = 0; + } + else + { + *listenObjsRet = (IceListenObj *) malloc ( + *countRet * sizeof (IceListenObj)); + + if (*listenObjsRet == NULL) + { + strncpy (errorStringRet, "Malloc failed", errorLength); + + status = 0; + } + else + { + for (i = 0; i < *countRet; i++) + { + (*listenObjsRet)[i] = (IceListenObj) malloc ( + sizeof (struct _IceListenObj)); + + if ((*listenObjsRet)[i] == NULL) + { + strncpy (errorStringRet, "Malloc failed", errorLength); + + for (j = 0; j < i; j++) + free ((char *) (*listenObjsRet)[j]); + + free ((char *) *listenObjsRet); + + status = 0; + } + else + { + *((*listenObjsRet)[i]) = listenObjs[i]; + } + } + } + } + + if (status == 1) + { + if (errorStringRet && errorLength > 0) + *errorStringRet = '\0'; + + for (i = 0; i < *countRet; i++) + { + (*listenObjsRet)[i]->host_based_auth_proc = NULL; + } + } + else + { + for (i = 0; i < transCount; i++) + _kde_IceTransClose (transConns[i]); + } + + free ((char *) listenObjs); + free ((char *) transConns); + + return (status); +} + + + +int +IceGetListenConnectionNumber (listenObj) + +IceListenObj listenObj; + +{ + return (_kde_IceTransGetConnectionNumber (listenObj->trans_conn)); +} + + + +char * +IceGetListenConnectionString (listenObj) + +IceListenObj listenObj; + +{ + char *networkId; + + networkId = (char *) malloc (strlen (listenObj->network_id) + 1); + + if (networkId) + strcpy (networkId, listenObj->network_id); + + return (networkId); +} + + + +char * +IceComposeNetworkIdList (count, listenObjs) + +int count; +IceListenObj *listenObjs; + +{ + char *list; + int len = 0; + int i; + + if (count < 1 || listenObjs == NULL) + return (NULL); + + for (i = 0; i < count; i++) + len += (strlen (listenObjs[i]->network_id) + 1); + + list = (char *) malloc (len); + + if (list == NULL) + return (NULL); + else + { + int doneCount = 0; + + list[0] = '\0'; + + for (i = 0; i < count; i++) + { + if (_kde_IceTransIsLocal (listenObjs[i]->trans_conn)) + { + strcat (list, listenObjs[i]->network_id); + doneCount++; + if (doneCount < count) + strcat (list, ","); + } + } + + if (doneCount < count) + { + for (i = 0; i < count; i++) + { + if (!_kde_IceTransIsLocal (listenObjs[i]->trans_conn)) + { + strcat (list, listenObjs[i]->network_id); + doneCount++; + if (doneCount < count) + strcat (list, ","); + } + } + } + + return (list); + } +} + + + +void +IceFreeListenObjs (count, listenObjs) + +int count; +IceListenObj *listenObjs; + +{ + int i; + + for (i = 0; i < count; i++) + { + free (listenObjs[i]->network_id); + _kde_IceTransClose (listenObjs[i]->trans_conn); + free ((char *) listenObjs[i]); + } + + free ((char *) listenObjs); +} + + + +/* + * Allow host based authentication for the ICE Connection Setup. + * Do not confuse with the host based authentication callbacks that + * can be set up in IceRegisterForProtocolReply. + */ + +void +IceSetHostBasedAuthProc (listenObj, hostBasedAuthProc) + +IceListenObj listenObj; +IceHostBasedAuthProc hostBasedAuthProc; + +{ + listenObj->host_based_auth_proc = hostBasedAuthProc; +} diff --git a/dcop/KDE-ICE/listenwk.c b/dcop/KDE-ICE/listenwk.c new file mode 100644 index 000000000..80ff1dbae --- /dev/null +++ b/dcop/KDE-ICE/listenwk.c @@ -0,0 +1,155 @@ +/* $Xorg: listenwk.c,v 1.4 2000/08/17 19:44:15 cpqbld Exp $ */ + +/* + +Copyright 1996, 1998 The Open Group + +All Rights Reserved. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + +*/ +/* $XFree86: xc/lib/ICE/listenwk.c,v 1.3 2001/01/17 19:41:29 dawes Exp $ */ + + +/* Author: Ralph Mor, X Consortium */ + +#include "KDE-ICE/ICElib.h" +#include "KDE-ICE/ICElibint.h" +#include <KDE-ICE/Xtrans.h> +#include <stdio.h> +#include <string.h> + + +Status +IceListenForWellKnownConnections (port, countRet, listenObjsRet, errorLength, errorStringRet) + +char *port; +int *countRet; +IceListenObj **listenObjsRet; +int errorLength; +char *errorStringRet; + +{ + struct _IceListenObj *listenObjs; + char *networkId; + int transCount, partial, i, j; + Status status = 1; + XtransConnInfo *transConns = NULL; + + + if ((_kde_IceTransMakeAllCOTSServerListeners (port, &partial, + &transCount, &transConns) < 0) || (transCount < 1)) + { + *listenObjsRet = NULL; + *countRet = 0; + + strncpy (errorStringRet, + "Cannot establish any listening sockets", errorLength); + + return (0); + } + + if ((listenObjs = (struct _IceListenObj *) malloc ( + transCount * sizeof (struct _IceListenObj))) == NULL) + { + for (i = 0; i < transCount; i++) + _kde_IceTransClose (transConns[i]); + free ((char *) transConns); + return (0); + } + + *countRet = 0; + + for (i = 0; i < transCount; i++) + { + networkId = (char *)_kde_IceTransGetMyNetworkId (transConns[i]); + + if (networkId) + { + listenObjs[*countRet].trans_conn = transConns[i]; + listenObjs[*countRet].network_id = networkId; + + (*countRet)++; + } + } + + if (*countRet == 0) + { + *listenObjsRet = NULL; + + strncpy (errorStringRet, + "Cannot establish any listening sockets", errorLength); + + status = 0; + } + else + { + *listenObjsRet = (IceListenObj *) malloc ( + *countRet * sizeof (IceListenObj)); + + if (*listenObjsRet == NULL) + { + strncpy (errorStringRet, "Malloc failed", errorLength); + + status = 0; + } + else + { + for (i = 0; i < *countRet; i++) + { + (*listenObjsRet)[i] = (IceListenObj) malloc ( + sizeof (struct _IceListenObj)); + + if ((*listenObjsRet)[i] == NULL) + { + strncpy (errorStringRet, "Malloc failed", errorLength); + + for (j = 0; j < i; j++) + free ((char *) (*listenObjsRet)[j]); + + free ((char *) *listenObjsRet); + + status = 0; + } + else + { + *((*listenObjsRet)[i]) = listenObjs[i]; + } + } + } + } + + if (status == 1) + { + if (errorStringRet && errorLength > 0) + *errorStringRet = '\0'; + + for (i = 0; i < *countRet; i++) + { + (*listenObjsRet)[i]->host_based_auth_proc = NULL; + } + } + else + { + for (i = 0; i < transCount; i++) + _kde_IceTransClose (transConns[i]); + } + + free ((char *) listenObjs); + free ((char *) transConns); + + return (status); +} diff --git a/dcop/KDE-ICE/locking.c b/dcop/KDE-ICE/locking.c new file mode 100644 index 000000000..0acce8368 --- /dev/null +++ b/dcop/KDE-ICE/locking.c @@ -0,0 +1,62 @@ +/* $Xorg: locking.c,v 1.3 2000/08/17 19:44:15 cpqbld Exp $ */ +/****************************************************************************** + + +Copyright 1993, 1998 The Open Group + +All Rights Reserved. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + +Author: Ralph Mor, X Consortium +******************************************************************************/ + +#include <KDE-ICE/ICElib.h> +#include "KDE-ICE/ICElibint.h" + + +/* + * NOT IMPLEMENTED YET + */ + + +Status +IceInitThreads () + +{ + return (0); +} + + +void +IceAppLockConn (iceConn) + +IceConn iceConn; + +{ + (void)iceConn;/*unused in the macro*/ + IceLockConn (iceConn); +} + + +void +IceAppUnlockConn (iceConn) + +IceConn iceConn; + +{ + (void)iceConn;/*unused in the macro*/ + IceUnlockConn (iceConn); +} diff --git a/dcop/KDE-ICE/misc.c b/dcop/KDE-ICE/misc.c new file mode 100644 index 000000000..0dbbf24b7 --- /dev/null +++ b/dcop/KDE-ICE/misc.c @@ -0,0 +1,619 @@ +/* $XConsortium: misc.c /main/29 1996/11/13 14:43:55 lehors $ */ +/****************************************************************************** + + +Copyright (c) 1993 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from the X Consortium. + +Author: Ralph Mor, X Consortium +******************************************************************************/ + +#include "KDE-ICE/ICElib.h" +#include "KDE-ICE/ICElibint.h" +#include "KDE-ICE/Xtrans.h" +#include "KDE-ICE/globals.h" +#include <stdio.h> +#include <errno.h> +#include <string.h> + + +/* + * scratch buffer + */ + +char * +IceAllocScratch (iceConn, size) + +IceConn iceConn; +unsigned long size; + +{ + if (!iceConn->scratch || size > iceConn->scratch_size) + { + if (iceConn->scratch) + free (iceConn->scratch); + + iceConn->scratch = (char *) malloc ((unsigned) size); + iceConn->scratch_size = size; + } + + return (iceConn->scratch); +} + + + +/* + * Output/Input buffer functions + */ + +void IceFlush (IceConn iceConn) +{ + (*_IceWriteHandler) (iceConn, + (unsigned long) (iceConn->outbufptr - iceConn->outbuf), + iceConn->outbuf); + + iceConn->outbufptr = iceConn->outbuf; +} + + +int +IceGetOutBufSize (iceConn) + +IceConn iceConn; + +{ + return (iceConn->outbufmax - iceConn->outbuf); +} + + +int +IceGetInBufSize (iceConn) + +IceConn iceConn; + +{ + return (iceConn->inbufmax - iceConn->inbuf); +} + + + +/* + * informational functions + */ + +IceConnectStatus +IceConnectionStatus (iceConn) + +IceConn iceConn; + +{ + return (iceConn->connection_status); +} + + +char * +IceVendor (iceConn) + +IceConn iceConn; + +{ + char *string = (char *) malloc (strlen (iceConn->vendor) + 1); + + if (string) + strcpy (string, iceConn->vendor); + + return (string); +} + + +char * +IceRelease (iceConn) + +IceConn iceConn; + +{ + char *string = (char *) malloc (strlen (iceConn->release) + 1); + + if (string) + strcpy (string, iceConn->release); + + return (string); +} + + +int +IceProtocolVersion (iceConn) + +IceConn iceConn; + +{ + return (_IceVersions[iceConn->my_ice_version_index].major_version); +} + + +int +IceProtocolRevision (iceConn) + +IceConn iceConn; + +{ + return (_IceVersions[iceConn->my_ice_version_index].minor_version); +} + + +int +IceConnectionNumber (iceConn) + +IceConn iceConn; + +{ + return (_kde_IceTransGetConnectionNumber (iceConn->trans_conn)); +} + + +char * +IceConnectionString (iceConn) + +IceConn iceConn; + +{ + if (iceConn->connection_string) + { + char *string = (char *) malloc ( + strlen (iceConn->connection_string) + 1); + + if (string) + strcpy (string, iceConn->connection_string); + + return (string); + } + else + return (NULL); +} + + +unsigned long +IceLastSentSequenceNumber (iceConn) + +IceConn iceConn; + +{ + return (iceConn->send_sequence); +} + + +unsigned long +IceLastReceivedSequenceNumber (iceConn) + +IceConn iceConn; + +{ + return (iceConn->receive_sequence); +} + + +Bool +IceSwapping (iceConn) + +IceConn iceConn; + +{ + return (iceConn->swap); +} + + + +/* + * Read "n" bytes from a connection. + * + * Return Status 0 if we detected an EXPECTED closed connection. + * + */ + +Status +_IceRead (iceConn, nbytes, ptr) + +register IceConn iceConn; +unsigned long nbytes; +register char *ptr; + +{ + register unsigned long nleft; + + nleft = nbytes; + while (nleft > 0) + { + int nread; + + if (iceConn->io_ok) + nread = _kde_IceTransRead (iceConn->trans_conn, ptr, (int) nleft); + else + return (1); + + if (nread <= 0) + { +#ifdef _WIN32 + errno = WSAGetLastError(); +#endif + if( nread < 0 && errno == EINTR ) + continue; + if (iceConn->want_to_close) + { + /* + * We sent a WantToClose message and now we detected that + * the other side closed the connection. + */ + + _IceConnectionClosed (iceConn); /* invoke watch procs */ + _IceFreeConnection (iceConn); + + return (0); + } + else + { + /* + * Fatal IO error. First notify each protocol's IceIOErrorProc + * callback, then invoke the application IO error handler. + */ + + iceConn->io_ok = False; + + if (iceConn->connection_status == IceConnectPending) + { + /* + * Don't invoke IO error handler if we are in the + * middle of a connection setup. + */ + + return (1); + } + + if (iceConn->process_msg_info) + { + int i; + + for (i = iceConn->his_min_opcode; + i <= iceConn->his_max_opcode; i++) + { + _IceProcessMsgInfo *process; + + process = &iceConn->process_msg_info[ + i - iceConn->his_min_opcode]; + + if (process->in_use) + { + IceIOErrorProc IOErrProc = process->accept_flag ? + process->protocol->accept_client->io_error_proc : + process->protocol->orig_client->io_error_proc; + + if (IOErrProc) + (*IOErrProc) (iceConn); + } + } + } + + (*_IceIOErrorHandler) (iceConn); + return (1); + } + } + + nleft -= nread; + ptr += nread; + } + + return (1); +} + + + +/* + * If we read a message header with a bad major or minor opcode, + * we need to advance to the end of the message. This way, the next + * message can be processed correctly. + */ + +void +_IceReadSkip (iceConn, nbytes) + +register IceConn iceConn; +register unsigned long nbytes; + +{ + char temp[512]; + + while (nbytes > 0) + { + unsigned long rbytes = nbytes > 512 ? 512 : nbytes; + + _IceRead (iceConn, rbytes, temp); + nbytes -= rbytes; + } +} + + + +/* + * Write "n" bytes to a connection. + */ + +void +_IceWrite (iceConn, nbytes, ptr) + +register IceConn iceConn; +unsigned long nbytes; +register char *ptr; + +{ + register unsigned long nleft; + + nleft = nbytes; + while (nleft > 0) + { + int nwritten; + + if (iceConn->io_ok) + nwritten = _kde_IceTransWrite (iceConn->trans_conn, ptr, (int) nleft); + else + return; + + + if (nwritten <= 0) + { +#ifdef _WIN32 + errno = WSAGetLastError(); +#endif + if( nwritten < 0 && errno == EINTR ) + continue; + /* + * Fatal IO error. First notify each protocol's IceIOErrorProc + * callback, then invoke the application IO error handler. + */ + + iceConn->io_ok = False; + + if (iceConn->connection_status == IceConnectPending) + { + /* + * Don't invoke IO error handler if we are in the + * middle of a connection setup. + */ + + return; + } + + if (iceConn->process_msg_info) + { + int i; + + for (i = iceConn->his_min_opcode; + i <= iceConn->his_max_opcode; i++) + { + _IceProcessMsgInfo *process; + + process = &iceConn->process_msg_info[ + i - iceConn->his_min_opcode]; + + if (process->in_use) + { + IceIOErrorProc IOErrProc = process->accept_flag ? + process->protocol->accept_client->io_error_proc : + process->protocol->orig_client->io_error_proc; + + if (IOErrProc) + (*IOErrProc) (iceConn); + } + } + } + + (*_IceIOErrorHandler) (iceConn); + return; + } + + nleft -= nwritten; + ptr += nwritten; + } +} + +#ifdef WORD64 + +IceWriteData16 (iceConn, nbytes, data) + +IceConn iceConn; +unsigned long nbytes; +short *data; + +{ + int numShorts = nbytes / 2; + int index = 0; + + while (index < numShorts) + { + int spaceLeft, count, i; + int shortsLeft = numShorts - index; + + spaceLeft = iceConn->outbufmax - iceConn->outbufptr - 1; + + if (spaceLeft < 2) + { + IceFlush (iceConn); + spaceLeft = iceConn->outbufmax - iceConn->outbufptr - 1; + } + + count = (shortsLeft < spaceLeft / 2) ? shortsLeft : spaceLeft / 2; + + for (i = 0; i < count; i++) + STORE_CARD16 (iceConn->outbufptr, data[index++]); + } +} + + +IceWriteData32 (iceConn, nbytes, data) + +IceConn iceConn; +unsigned long nbytes; +int *data; + +{ + int numLongs = nbytes / 4; + int index = 0; + + while (index < numLongs) + { + int spaceLeft, count, i; + int longsLeft = numLongs - index; + + spaceLeft = iceConn->outbufmax - iceConn->outbufptr - 1; + + if (spaceLeft < 4) + { + IceFlush (iceConn); + spaceLeft = iceConn->outbufmax - iceConn->outbufptr - 1; + } + + count = (longsLeft < spaceLeft / 4) ? longsLeft : spaceLeft / 4; + + for (i = 0; i < count; i++) + STORE_CARD32 (iceConn->outbufptr, data[index++]); + } +} + + +IceReadData16 (iceConn, swap, nbytes, data) + +IceConn iceConn; +Bool swap; +unsigned long nbytes; +short *data; + +{ + /* NOT IMPLEMENTED YET */ +} + + +IceReadData32 (iceConn, swap, nbytes, data) + +IceConn iceConn; +Bool swap; +unsigned long nbytes; +int *data; + +{ + /* NOT IMPLEMENTED YET */ +} + +#endif /* WORD64 */ + + + +void +_IceAddOpcodeMapping (iceConn, hisOpcode, myOpcode) + +IceConn iceConn; +int hisOpcode; +int myOpcode; + +{ + if (hisOpcode <= 0 || hisOpcode > 255) + { + return; + } + else if (iceConn->process_msg_info == NULL) + { + iceConn->process_msg_info = (_IceProcessMsgInfo *) malloc ( + sizeof (_IceProcessMsgInfo)); + iceConn->his_min_opcode = iceConn->his_max_opcode = hisOpcode; + } + else if (hisOpcode < iceConn->his_min_opcode) + { + _IceProcessMsgInfo *oldVec = iceConn->process_msg_info; + int oldsize = iceConn->his_max_opcode - iceConn->his_min_opcode + 1; + int newsize = iceConn->his_max_opcode - hisOpcode + 1; + int i; + + iceConn->process_msg_info = (_IceProcessMsgInfo *) malloc ( + newsize * sizeof (_IceProcessMsgInfo)); + + memcpy (&iceConn->process_msg_info[ + iceConn->his_min_opcode - hisOpcode], oldVec, + oldsize * sizeof (_IceProcessMsgInfo)); + + free ((char *) oldVec); + + for (i = hisOpcode + 1; i < iceConn->his_min_opcode; i++) + { + iceConn->process_msg_info[i - + iceConn->his_min_opcode].in_use = False; + + iceConn->process_msg_info[i - + iceConn->his_min_opcode].protocol = NULL; + } + + iceConn->his_min_opcode = hisOpcode; + } + else if (hisOpcode > iceConn->his_max_opcode) + { + _IceProcessMsgInfo *oldVec = iceConn->process_msg_info; + int oldsize = iceConn->his_max_opcode - iceConn->his_min_opcode + 1; + int newsize = hisOpcode - iceConn->his_min_opcode + 1; + int i; + + iceConn->process_msg_info = (_IceProcessMsgInfo *) malloc ( + newsize * sizeof (_IceProcessMsgInfo)); + + memcpy (iceConn->process_msg_info, oldVec, + oldsize * sizeof (_IceProcessMsgInfo)); + + free ((char *) oldVec); + + for (i = iceConn->his_max_opcode + 1; i < hisOpcode; i++) + { + iceConn->process_msg_info[i - + iceConn->his_min_opcode].in_use = False; + + iceConn->process_msg_info[i - + iceConn->his_min_opcode].protocol = NULL; + } + + iceConn->his_max_opcode = hisOpcode; + } + + iceConn->process_msg_info[hisOpcode - + iceConn->his_min_opcode].in_use = True; + + iceConn->process_msg_info[hisOpcode - + iceConn->his_min_opcode].my_opcode = myOpcode; + + iceConn->process_msg_info[hisOpcode - + iceConn->his_min_opcode].protocol = &_IceProtocols[myOpcode - 1]; +} + + + +char * +_IceGetPeerName (iceConn) + +IceConn iceConn; + +{ + return ((char*)_kde_IceTransGetPeerNetworkId (iceConn->trans_conn)); +} diff --git a/dcop/KDE-ICE/ping.c b/dcop/KDE-ICE/ping.c new file mode 100644 index 000000000..5c0c601d6 --- /dev/null +++ b/dcop/KDE-ICE/ping.c @@ -0,0 +1,59 @@ +/* $Xorg: ping.c,v 1.3 2000/08/17 19:44:15 cpqbld Exp $ */ +/****************************************************************************** + + +Copyright 1993, 1998 The Open Group + +All Rights Reserved. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + +Author: Ralph Mor, X Consortium +******************************************************************************/ + +#include <KDE-ICE/ICElib.h> +#include "KDE-ICE/ICElibint.h" + +Status +IcePing (iceConn, pingReplyProc, clientData) + +IceConn iceConn; +IcePingReplyProc pingReplyProc; +IcePointer clientData; + +{ + _IcePingWait *newping = (_IcePingWait *) malloc (sizeof (_IcePingWait)); + _IcePingWait *ptr = iceConn->ping_waits; + + if (newping == NULL) + return (0); + + newping->ping_reply_proc = pingReplyProc; + newping->client_data = clientData; + newping->next = NULL; + + while (ptr && ptr->next) + ptr = ptr->next; + + if (ptr == NULL) + iceConn->ping_waits = newping; + else + ptr->next = newping; + + IceSimpleMessage (iceConn, 0, ICE_Ping); + IceFlush (iceConn); + + return (1); +} diff --git a/dcop/KDE-ICE/process.c b/dcop/KDE-ICE/process.c new file mode 100644 index 000000000..5769946ec --- /dev/null +++ b/dcop/KDE-ICE/process.c @@ -0,0 +1,2545 @@ +/* $Xorg: process.c,v 1.3 2000/08/17 19:44:16 cpqbld Exp $ */ +/****************************************************************************** + + +Copyright 1993, 1998 The Open Group + +All Rights Reserved. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + +Author: Ralph Mor, X Consortium +******************************************************************************/ +/* $XFree86: xc/lib/ICE/process.c,v 3.5 2001/01/17 19:41:29 dawes Exp $ */ + +#include "KDE-ICE/ICElib.h" +#include "KDE-ICE/ICElibint.h" +#include "KDE-ICE/globals.h" + +#include <string.h> +#include <stdio.h> /* sprintf */ + +#ifdef MINIX +#include <KDE-ICE/Xtrans.h> +#endif + +/* + * Check for bad length + */ + +#define CHECK_SIZE_MATCH(_iceConn, _opcode, _expected_len, _actual_len, _severity) \ + if ((((_actual_len) - SIZEOF (iceMsg)) >> 3) != _expected_len) \ + { \ + _IceErrorBadLength (_iceConn, 0, _opcode, _severity); \ + return (0); \ + } + +#define CHECK_AT_LEAST_SIZE(_iceConn, _opcode, _expected_len, _actual_len, _severity) \ + if ((((_actual_len) - SIZEOF (iceMsg)) >> 3) > (long)_expected_len) \ + { \ + _IceErrorBadLength (_iceConn, 0, _opcode, _severity); \ + return (0); \ + } + +#define CHECK_COMPLETE_SIZE(_iceConn, _opcode, _expected_len, _actual_len, _pStart, _severity) \ + if (((PADDED_BYTES64((_actual_len)) - SIZEOF (iceMsg)) >> 3) \ + != _expected_len) \ + { \ + _IceErrorBadLength (_iceConn, 0, _opcode, _severity); \ + IceDisposeCompleteMessage (iceConn, _pStart); \ + return (0); \ + } + +#define BAIL_STRING(_iceConn, _opcode, _pStart) {\ + _IceErrorBadLength (_iceConn, 0, _opcode, IceFatalToConnection);\ + IceDisposeCompleteMessage (_iceConn, _pStart);\ + return (0);\ +} + +/* + * IceProcessMessages: + * + * If replyWait == NULL, the client is not waiting for a reply. + * + * If replyWait != NULL, the client is waiting for a reply... + * + * - replyWait->sequence_of_request is the sequence number of the + * message for which the client is waiting a reply. This is needed + * to determine if an error matches a replyWait. + * + * - replyWait->major_opcode_of_request is the major opcode of the + * message for which we are waiting a reply. + * + * - replyWait->minor_opcode_of_request is the minor opcode of the + * message for which we are waiting a reply. + * + * - replyWait->reply is a pointer to the reply message which will be + * filled in when the reply is ready (the protocol library should + * cast this IcePointer to the appropriate reply type). In most cases, + * the reply will have some fixed-size part, and the sender function + * will have provided a pointer to a structure (e.g.) to hold this + * fixed-size data. If there is variable-length data, it would be + * expected that the reply function will have to allocate additional + * memory and store pointer(s) to that memory in the fixed-size + * structure. If the entire data is variable length (e.g., a single + * variable-length string), then the sender function would probably + * just pass a pointer to fixed-size space to hold a pointer, and the + * reply function would allocate the storage and store the pointer. + * It is the responsibility of the client receiving the reply to + * free up any memory allocated on it's behalf. + * + * We might be waiting for several different replies (a function can wait + * for a reply, and while calling IceProcessMessages, a callback can be + * invoked which will wait for another reply). We take advantage of the + * fact that for a given protocol, we are guaranteed that messages are + * processed in the order we sent them. So, every time we have a new + * replyWait, we add it to the END of the 'saved_reply_waits' list. When + * we read a message and want to see if it matches a replyWait, we use the + * FIRST replyWait in the list with the major opcode of the message. If the + * reply is ready, we remove that replyWait from the list. + * + * If the reply/error is ready for the replyWait passed in to + * IceProcessMessages, *replyReadyRet is set to True. + * + * The return value of IceProcessMessages is one of the following: + * + * IceProcessMessagesSuccess - the message was processed successfully. + * IceProcessMessagesIOError - an IO error occurred. The caller should + * invoked IceCloseConnection. + * IceProcessMessagesConnectionClosed - the connection was closed as a + * result of shutdown negotiation. + */ + +IceProcessMessagesStatus +IceProcessMessages (iceConn, replyWait, replyReadyRet) + +IceConn iceConn; +IceReplyWaitInfo *replyWait; +Bool *replyReadyRet; + +{ + iceMsg *header; + Bool replyReady = False; + IceReplyWaitInfo *useThisReplyWait = NULL; + IceProcessMessagesStatus retStatus = IceProcessMessagesSuccess; + + if (replyWait) + *replyReadyRet = False; + + /* + * Each time IceProcessMessages is entered, we increment the dispatch + * level. Each time we leave it, we decrement the dispatch level. + */ + + iceConn->dispatch_level++; + + + /* + * Read the ICE message header. + */ + + if (!_IceRead (iceConn, (unsigned long) SIZEOF (iceMsg), iceConn->inbuf)) + { + /* + * If we previously sent a WantToClose and now we detected + * that the connection was closed, _IceRead returns status 0. + * Since the connection was closed, we just want to return here. + */ + + return (IceProcessMessagesConnectionClosed); + } + + if (!iceConn->io_ok) + { + /* + * An unexpected IO error occurred. The caller of IceProcessMessages + * should call IceCloseConnection which will cause the watch procedures + * to be invoked and the ICE connection to be freed. + */ + + iceConn->dispatch_level--; + iceConn->connection_status = IceConnectIOError; + return (IceProcessMessagesIOError); + } + + header = (iceMsg *) iceConn->inbuf; + iceConn->inbufptr = iceConn->inbuf + SIZEOF (iceMsg); + + iceConn->receive_sequence++; + + if (iceConn->waiting_for_byteorder) + { + if (header->majorOpcode == 0 && + header->minorOpcode == ICE_ByteOrder) + { + char byteOrder = ((iceByteOrderMsg *) header)->byteOrder; + int endian = 1; + + CHECK_SIZE_MATCH (iceConn, ICE_ByteOrder, + header->length, SIZEOF (iceByteOrderMsg), + IceFatalToConnection); + + if (byteOrder != IceMSBfirst && byteOrder != IceLSBfirst) + { + _IceErrorBadValue (iceConn, 0, + ICE_ByteOrder, 2, 1, &byteOrder); + + iceConn->connection_status = IceConnectRejected; + } + else + { + iceConn->swap = + (((*(char *) &endian) && byteOrder == IceMSBfirst) || + (!(*(char *) &endian) && byteOrder == IceLSBfirst)); + + iceConn->waiting_for_byteorder = 0; + } + } + else + { + if (header->majorOpcode != 0) + { + _IceErrorBadMajor (iceConn, header->majorOpcode, + header->minorOpcode, IceFatalToConnection); + } + else + { + _IceErrorBadState (iceConn, 0, + header->minorOpcode, IceFatalToConnection); + } + + iceConn->connection_status = IceConnectRejected; + } + + iceConn->dispatch_level--; + if (!iceConn->io_ok) + { + iceConn->connection_status = IceConnectIOError; + retStatus = IceProcessMessagesIOError; + } + + return (retStatus); + } + + if (iceConn->swap) + { + /* swap the length field */ + + header->length = lswapl (header->length); + } + + if (replyWait) + { + /* + * Add to the list of replyWaits (only if it doesn't exist + * in the list already. + */ + + _IceAddReplyWait (iceConn, replyWait); + + + /* + * Note that there are two different replyWaits. The first is + * the one passed into IceProcessMessages, and is the replyWait + * for the message the client is blocking on. The second is + * the replyWait for the message currently being processed + * by IceProcessMessages. We call it "useThisReplyWait". + */ + + useThisReplyWait = _IceSearchReplyWaits (iceConn, header->majorOpcode); + } + + if (header->majorOpcode == 0) + { + /* + * ICE protocol + */ + + Bool connectionClosed; + + _IceProcessCoreMsgProc processIce = + _IceVersions[iceConn->my_ice_version_index].process_core_msg_proc; + + (*processIce) (iceConn, header->minorOpcode, + header->length, iceConn->swap, + useThisReplyWait, &replyReady, &connectionClosed); + + if (connectionClosed) + { + /* + * As a result of shutdown negotiation, the connection was closed. + */ + + return (IceProcessMessagesConnectionClosed); + } + } + else + { + /* + * Sub protocol + */ + + if ((int) header->majorOpcode < iceConn->his_min_opcode || + (int) header->majorOpcode > iceConn->his_max_opcode || + !(iceConn->process_msg_info[header->majorOpcode - + iceConn->his_min_opcode].in_use)) + { + /* + * The protocol of the message we just read is not supported. + */ + + _IceErrorBadMajor (iceConn, header->majorOpcode, + header->minorOpcode, IceCanContinue); + + _IceReadSkip (iceConn, header->length << 3); + } + else + { + _IceProcessMsgInfo *processMsgInfo = &iceConn->process_msg_info[ + header->majorOpcode - iceConn->his_min_opcode]; + + if (processMsgInfo->accept_flag) + { + IcePaProcessMsgProc processProc = + processMsgInfo->process_msg_proc.accept_client; + + (*processProc) (iceConn, processMsgInfo->client_data, + header->minorOpcode, header->length, iceConn->swap); + } + else + { + IcePoProcessMsgProc processProc = + processMsgInfo->process_msg_proc.orig_client; + + (*processProc) (iceConn, + processMsgInfo->client_data, header->minorOpcode, + header->length, iceConn->swap, + useThisReplyWait, &replyReady); + } + } + } + + if (replyReady) + { + _IceSetReplyReady (iceConn, useThisReplyWait); + } + + + /* + * Now we check if the reply is ready for the replyWait passed + * into IceProcessMessages. The replyWait is removed from the + * replyWait list if it is ready. + */ + + if (replyWait) + *replyReadyRet = _IceCheckReplyReady (iceConn, replyWait); + + + /* + * Decrement the dispatch level. If we reach level 0, and the + * free_asap bit is set, free the connection now. Also check for + * possible bad IO status. + */ + + iceConn->dispatch_level--; + + if (iceConn->dispatch_level == 0 && iceConn->free_asap) + { + _IceFreeConnection (iceConn); + retStatus = IceProcessMessagesConnectionClosed; + } + else if (!iceConn->io_ok) + { + iceConn->connection_status = IceConnectIOError; + retStatus = IceProcessMessagesIOError; + } + + return (retStatus); +} + + + +static void +AuthRequired (iceConn, authIndex, authDataLen, authData) + +IceConn iceConn; +int authIndex; +int authDataLen; +IcePointer authData; + +{ + iceAuthRequiredMsg *pMsg; + + IceGetHeader (iceConn, 0, ICE_AuthRequired, + SIZEOF (iceAuthRequiredMsg), iceAuthRequiredMsg, pMsg); + + pMsg->authIndex = authIndex; + pMsg->authDataLength = authDataLen; + pMsg->length += WORD64COUNT (authDataLen); + + IceWriteData (iceConn, authDataLen, (char *) authData); + + if (PAD64 (authDataLen)) + IceWritePad (iceConn, PAD64 (authDataLen)); + + IceFlush (iceConn); +} + + + +static void +AuthReply (iceConn, authDataLen, authData) + +IceConn iceConn; +int authDataLen; +IcePointer authData; + +{ + iceAuthReplyMsg *pMsg; + + IceGetHeader (iceConn, 0, ICE_AuthReply, + SIZEOF (iceAuthReplyMsg), iceAuthReplyMsg, pMsg); + + pMsg->authDataLength = authDataLen; + pMsg->length += WORD64COUNT (authDataLen); + + IceWriteData (iceConn, authDataLen, (char *) authData); + + if (PAD64 (authDataLen)) + IceWritePad (iceConn, PAD64 (authDataLen)); + + IceFlush (iceConn); +} + + + +static void +AuthNextPhase (iceConn, authDataLen, authData) + +IceConn iceConn; +int authDataLen; +IcePointer authData; + +{ + iceAuthNextPhaseMsg *pMsg; + + IceGetHeader (iceConn, 0, ICE_AuthNextPhase, + SIZEOF (iceAuthNextPhaseMsg), iceAuthNextPhaseMsg, pMsg); + + pMsg->authDataLength = authDataLen; + pMsg->length += WORD64COUNT (authDataLen); + + IceWriteData (iceConn, authDataLen, (char *) authData); + + if (PAD64 (authDataLen)) + IceWritePad (iceConn, PAD64 (authDataLen)); + + IceFlush (iceConn); +} + + + +static void +AcceptConnection (iceConn, versionIndex) + +IceConn iceConn; +int versionIndex; + +{ + iceConnectionReplyMsg *pMsg; + char *pData; + int extra; + + extra = STRING_BYTES (IceVendorString) + STRING_BYTES (IceReleaseString); + + IceGetHeaderExtra (iceConn, 0, ICE_ConnectionReply, + SIZEOF (iceConnectionReplyMsg), WORD64COUNT (extra), + iceConnectionReplyMsg, pMsg, pData); + + pMsg->versionIndex = versionIndex; + + STORE_STRING (pData, IceVendorString); + STORE_STRING (pData, IceReleaseString); + + IceFlush (iceConn); + + iceConn->connection_status = IceConnectAccepted; +} + + + +static void +AcceptProtocol (iceConn, hisOpcode, myOpcode, versionIndex, vendor, release) + +IceConn iceConn; +int hisOpcode; +int myOpcode; +int versionIndex; +char *vendor; +char *release; + +{ + iceProtocolReplyMsg *pMsg; + char *pData; + int extra; + + extra = STRING_BYTES (vendor) + STRING_BYTES (release); + + IceGetHeaderExtra (iceConn, 0, ICE_ProtocolReply, + SIZEOF (iceProtocolReplyMsg), WORD64COUNT (extra), + iceProtocolReplyMsg, pMsg, pData); + + pMsg->protocolOpcode = myOpcode; + pMsg->versionIndex = versionIndex; + + STORE_STRING (pData, vendor); + STORE_STRING (pData, release); + + IceFlush (iceConn); + + + /* + * We may be using a different major opcode for this protocol + * than the other client. Whenever we get a message, we must + * map to our own major opcode. + */ + + _IceAddOpcodeMapping (iceConn, hisOpcode, myOpcode); +} + + + +static void +PingReply (iceConn) + +IceConn iceConn; + +{ + IceSimpleMessage (iceConn, 0, ICE_PingReply); + IceFlush (iceConn); +} + + + +static Bool +ProcessError (iceConn, length, swap, replyWait) + +IceConn iceConn; +unsigned long length; +Bool swap; +IceReplyWaitInfo *replyWait; + +{ + int invokeHandler = 0; + Bool errorReturned = False; + iceErrorMsg *message; + char *pData, *pStart; + char severity; + + CHECK_AT_LEAST_SIZE (iceConn, ICE_Error, + length, SIZEOF (iceErrorMsg), + (iceConn->connect_to_you || iceConn->connect_to_me) ? + IceFatalToConnection : IceFatalToProtocol); + + IceReadCompleteMessage (iceConn, SIZEOF (iceErrorMsg), + iceErrorMsg, message, pStart); + + if (!IceValidIO (iceConn)) + { + IceDisposeCompleteMessage (iceConn, pStart); + return (0); + } + + severity = message->severity; + + if (severity != IceCanContinue && severity != IceFatalToProtocol && + severity != IceFatalToConnection) + { + _IceErrorBadValue (iceConn, 0, + ICE_Error, 9, 1, &severity); + IceDisposeCompleteMessage (iceConn, pStart); + return (0); + } + + pData = pStart; + + if (swap) + { + message->errorClass = lswaps (message->errorClass); + message->offendingSequenceNum = lswapl (message->offendingSequenceNum); + } + + if (!replyWait || + message->offendingSequenceNum != replyWait->sequence_of_request) + { + invokeHandler = 1; + } + else + { + if (iceConn->connect_to_you && + ((!iceConn->connect_to_you->auth_active && + message->offendingMinorOpcode == ICE_ConnectionSetup) || + (iceConn->connect_to_you->auth_active && + message->offendingMinorOpcode == ICE_AuthReply))) + { + _IceConnectionError *errorReply = + &(((_IceReply *) (replyWait->reply))->connection_error); + char *errorStr = NULL; + char *tempstr; + char *prefix, *temp; + + invokeHandler = 0; + errorReturned = True; + + switch (message->errorClass) + { + case IceNoVersion: + + tempstr = + (char *)"None of the ICE versions specified are supported"; + errorStr = (char *) malloc (strlen (tempstr) + 1); + strcpy (errorStr, tempstr); + break; + + case IceNoAuth: + + tempstr = + (char *)"None of the authentication protocols specified are supported"; + errorStr = (char *) malloc (strlen (tempstr) + 1); + strcpy (errorStr, tempstr); + break; + + case IceSetupFailed: + + prefix = (char *)"Connection Setup Failed, reason : "; + + EXTRACT_STRING (pData, swap, temp); + errorStr = (char *) malloc ( + strlen (prefix) + strlen (temp) + 1); + sprintf (errorStr, "%s%s", prefix, temp); + free (temp); + break; + + case IceAuthRejected: + + prefix = (char *)"Authentication Rejected, reason : "; + EXTRACT_STRING (pData, swap, temp); + errorStr = (char *) malloc ( + strlen (prefix) + strlen (temp) + 1); + sprintf (errorStr, "%s%s", prefix, temp); + free (temp); + break; + + case IceAuthFailed: + + prefix = (char *)"Authentication Failed, reason : "; + EXTRACT_STRING (pData, swap, temp); + errorStr = (char *) malloc ( + strlen (prefix) + strlen (temp) + 1); + sprintf (errorStr, "%s%s", prefix, temp); + free (temp); + break; + + default: + invokeHandler = 1; + } + + errorReply->type = ICE_CONNECTION_ERROR; + errorReply->error_message = errorStr; + } + else if (iceConn->protosetup_to_you && + ((!iceConn->protosetup_to_you->auth_active && + message->offendingMinorOpcode == ICE_ProtocolSetup) || + (iceConn->protosetup_to_you->auth_active && + message->offendingMinorOpcode == ICE_AuthReply))) + { + _IceProtocolError *errorReply = + &(((_IceReply *) (replyWait->reply))->protocol_error); + char *errorStr = (char *)""; + char *prefix, *temp; + + invokeHandler = 0; + errorReturned = True; + + switch (message->errorClass) + { + case IceNoVersion: + + temp = + (char *)"None of the protocol versions specified are supported"; + errorStr = (char *) malloc (strlen (temp) + 1); + strcpy (errorStr, temp); + break; + + case IceNoAuth: + + temp = + (char *)"None of the authentication protocols specified are supported"; + errorStr = (char *) malloc (strlen (temp) + 1); + strcpy (errorStr, temp); + break; + + case IceSetupFailed: + + prefix = (char *)"Protocol Setup Failed, reason : "; + + EXTRACT_STRING (pData, swap, temp); + errorStr = (char *) malloc ( + strlen (prefix) + strlen (temp) + 1); + sprintf (errorStr, "%s%s", prefix, temp); + free (temp); + break; + + case IceAuthRejected: + + prefix = (char *)"Authentication Rejected, reason : "; + EXTRACT_STRING (pData, swap, temp); + errorStr = (char *) malloc ( + strlen (prefix) + strlen (temp) + 1); + sprintf (errorStr, "%s%s", prefix, temp); + free (temp); + break; + + case IceAuthFailed: + + prefix = (char *)"Authentication Failed, reason : "; + EXTRACT_STRING (pData, swap, temp); + errorStr = (char *) malloc ( + strlen (prefix) + strlen (temp) + 1); + sprintf (errorStr, "%s%s", prefix, temp); + free (temp); + break; + + case IceProtocolDuplicate: + + prefix = (char *)"Protocol was already registered : "; + EXTRACT_STRING (pData, swap, temp); + errorStr = (char *) malloc ( + strlen (prefix) + strlen (temp) + 1); + sprintf (errorStr, "%s%s", prefix, temp); + free (temp); + break; + + case IceMajorOpcodeDuplicate: + + prefix = (char *)"The major opcode was already used : "; + errorStr = (char *) malloc (strlen (prefix) + 16); + sprintf (errorStr, "%s%d", prefix, (int) *pData); + break; + + case IceUnknownProtocol: + + prefix = (char *)"Unknown Protocol : "; + EXTRACT_STRING (pData, swap, temp); + errorStr = (char *) malloc ( + strlen (prefix) + strlen (temp) + 1); + sprintf (errorStr, "%s%s", prefix, temp); + free (temp); + break; + + default: + invokeHandler = 1; + } + + errorReply->type = ICE_PROTOCOL_ERROR; + errorReply->error_message = errorStr; + } + + if (errorReturned == True) + { + /* + * If we tried to authenticate, tell the authentication + * procedure to clean up. + */ + + IcePoAuthProc authProc; + + if (iceConn->connect_to_you && + iceConn->connect_to_you->auth_active) + { + authProc = _IcePoAuthProcs[(int) + (iceConn->connect_to_you->my_auth_index)]; + + (*authProc) (iceConn, &iceConn->connect_to_you->my_auth_state, + True /* clean up */, False /* swap */, + 0, NULL, NULL, NULL, NULL); + } + else if (iceConn->protosetup_to_you && + iceConn->protosetup_to_you->auth_active) + { + _IcePoProtocol *protocol = _IceProtocols[ + iceConn->protosetup_to_you->my_opcode - 1].orig_client; + + authProc = protocol->auth_procs[(int)(iceConn-> + protosetup_to_you->my_auth_index)]; + + (*authProc) (iceConn, + &iceConn->protosetup_to_you->my_auth_state, + True /* clean up */, False /* swap */, + 0, NULL, NULL, NULL, NULL); + } + } + } + + if (invokeHandler) + { + (*_IceErrorHandler) (iceConn, swap, message->offendingMinorOpcode, + message->offendingSequenceNum, message->errorClass, + message->severity, (IcePointer) pData); + } + + IceDisposeCompleteMessage (iceConn, pStart); + + return (errorReturned); +} + + + +static int +ProcessConnectionSetup (iceConn, length, swap) + +IceConn iceConn; +unsigned long length; +Bool swap; + +{ + iceConnectionSetupMsg *message; + int myVersionCount, hisVersionCount; + int myVersionIndex, hisVersionIndex; + int hisMajorVersion, hisMinorVersion; + int myAuthCount, hisAuthCount; + int found, i, j; + const char *myAuthName; + char **hisAuthNames = NULL; + char *pData, *pStart, *pEnd; + char *vendor = NULL; + char *release = NULL; + int myAuthIndex = 0; + int hisAuthIndex = 0; + int accept_setup_now = 0; + char mustAuthenticate; + int authUsableCount; + int authUsableFlags[MAX_ICE_AUTH_NAMES]; + int authIndices[MAX_ICE_AUTH_NAMES]; + + CHECK_AT_LEAST_SIZE (iceConn, ICE_ConnectionSetup, + length, SIZEOF (iceConnectionSetupMsg), IceFatalToConnection); + + IceReadCompleteMessage (iceConn, SIZEOF (iceConnectionSetupMsg), + iceConnectionSetupMsg, message, pStart); + + if (!IceValidIO (iceConn)) + { + IceDisposeCompleteMessage (iceConn, pStart); + return (0); + } + + pData = pStart; + pEnd = pStart + (length << 3); + + SKIP_STRING (pData, swap, pEnd, + BAIL_STRING(iceConn, ICE_ConnectionSetup, + pStart)); /* vendor */ + SKIP_STRING (pData, swap, pEnd, + BAIL_STRING(iceConn, ICE_ConnectionSetup, + pStart)); /* release */ + SKIP_LISTOF_STRING (pData, swap, (int) message->authCount, pEnd, + BAIL_STRING(iceConn, ICE_ConnectionSetup, + pStart)); /* auth names */ + + pData += (message->versionCount * 4); /* versions */ + + CHECK_COMPLETE_SIZE (iceConn, ICE_ConnectionSetup, + length, pData - pStart + SIZEOF (iceConnectionSetupMsg), + pStart, IceFatalToConnection); + + mustAuthenticate = message->mustAuthenticate; + if (mustAuthenticate != 0 && mustAuthenticate != 1) + { + _IceErrorBadValue (iceConn, 0, + ICE_ConnectionSetup, 8, 1, &mustAuthenticate); + iceConn->connection_status = IceConnectRejected; + IceDisposeCompleteMessage (iceConn, pStart); + return (0); + } + + pData = pStart; + + EXTRACT_STRING (pData, swap, vendor); + EXTRACT_STRING (pData, swap, release); + + if ((hisAuthCount = message->authCount) > 0) + { + hisAuthNames = (char **) malloc (hisAuthCount * sizeof (char *)); + EXTRACT_LISTOF_STRING (pData, swap, hisAuthCount, hisAuthNames); + } + + hisVersionCount = message->versionCount; + myVersionCount = _IceVersionCount; + + hisVersionIndex = myVersionIndex = found = 0; + + for (i = 0; i < hisVersionCount && !found; i++) + { + EXTRACT_CARD16 (pData, swap, hisMajorVersion); + EXTRACT_CARD16 (pData, swap, hisMinorVersion); + + for (j = 0; j < myVersionCount && !found; j++) + { + if (_IceVersions[j].major_version == hisMajorVersion && + _IceVersions[j].minor_version == hisMinorVersion) + { + hisVersionIndex = i; + myVersionIndex = j; + found = 1; + } + } + } + + if (!found) + { + _IceErrorNoVersion (iceConn, ICE_ConnectionSetup); + iceConn->connection_status = IceConnectRejected; + + free (vendor); + free (release); + + if (hisAuthCount > 0) + { + for (i = 0; i < hisAuthCount; i++) + free (hisAuthNames[i]); + + free ((char *) hisAuthNames); + } + + IceDisposeCompleteMessage (iceConn, pStart); + return (0); + } + + _IceGetPaValidAuthIndices ("ICE", iceConn->connection_string, + _IceAuthCount, _IceAuthNames, &authUsableCount, authIndices); + + for (i = 0; i < _IceAuthCount; i++) + { + authUsableFlags[i] = 0; + for (j = 0; j < authUsableCount && !authUsableFlags[i]; j++) + authUsableFlags[i] = (authIndices[j] == i); + } + + myAuthCount = _IceAuthCount; + + for (i = found = 0; i < myAuthCount && !found; i++) + { + if (authUsableFlags[i]) + { + myAuthName = _IceAuthNames[i]; + + for (j = 0; j < hisAuthCount && !found; j++) + if (strcmp (myAuthName, hisAuthNames[j]) == 0) + { + myAuthIndex = i; + hisAuthIndex = j; + found = 1; + } + } + } + + if (!found) + { + /* + * None of the authentication methods specified by the + * other client is supported. If the other client requires + * authentication, we must reject the connection now. + * Otherwise, we can invoke the host-based authentication callback + * to see if we can accept this connection. + */ + + if (mustAuthenticate || !iceConn->listen_obj->host_based_auth_proc) + { + _IceErrorNoAuthentication (iceConn, ICE_ConnectionSetup); + iceConn->connection_status = IceConnectRejected; + } + else + { + char *hostname = _IceGetPeerName (iceConn); + + if ((*iceConn->listen_obj->host_based_auth_proc) (hostname)) + { + accept_setup_now = 1; + } + else + { + _IceErrorAuthenticationRejected (iceConn, + ICE_ConnectionSetup, "None of the authentication protocols specified are supported and host-based authentication failed"); + + iceConn->connection_status = IceConnectRejected; + } + + if (hostname) + free (hostname); + } + + if (iceConn->connection_status == IceConnectRejected) + { + free (vendor); + free (release); + } + } + else + { + IcePaAuthStatus status; + int authDataLen; + IcePointer authData = NULL; + IcePointer authState; + char *errorString = NULL; + IcePaAuthProc authProc = _IcePaAuthProcs[myAuthIndex]; + + authState = NULL; + + status = (*authProc) (iceConn, &authState, + swap, 0, NULL, &authDataLen, &authData, &errorString); + + if (status == IcePaAuthContinue) + { + _IceConnectToMeInfo *setupInfo; + + AuthRequired (iceConn, hisAuthIndex, authDataLen, authData); + + iceConn->connect_to_me = setupInfo = (_IceConnectToMeInfo *) + malloc (sizeof (_IceConnectToMeInfo)); + + setupInfo->my_version_index = myVersionIndex; + setupInfo->his_version_index = hisVersionIndex; + setupInfo->his_vendor = vendor; + setupInfo->his_release = release; + setupInfo->my_auth_index = myAuthIndex; + setupInfo->my_auth_state = authState; + setupInfo->must_authenticate = mustAuthenticate; + } + else if (status == IcePaAuthAccepted) + { + accept_setup_now = 1; + } + + if (authData && authDataLen > 0) + free ((char *) authData); + + if (errorString) + free (errorString); + } + + if (accept_setup_now) + { + AcceptConnection (iceConn, hisVersionIndex); + + iceConn->vendor = vendor; + iceConn->release = release; + iceConn->my_ice_version_index = myVersionIndex; + } + + if (hisAuthCount > 0) + { + for (i = 0; i < hisAuthCount; i++) + free (hisAuthNames[i]); + + free ((char *) hisAuthNames); + } + + IceDisposeCompleteMessage (iceConn, pStart); + return (0); +} + + + +static Bool +ProcessAuthRequired (iceConn, length, swap, replyWait) + +IceConn iceConn; +unsigned long length; +Bool swap; +IceReplyWaitInfo *replyWait; + +{ + iceAuthRequiredMsg *message; + int authDataLen; + IcePointer authData; + int replyDataLen; + IcePointer replyData = NULL; + char *errorString = NULL; + IcePoAuthProc authProc; + IcePoAuthStatus status; + IcePointer authState; + int realAuthIndex = 0; + + CHECK_AT_LEAST_SIZE (iceConn, ICE_AuthRequired, + length, SIZEOF (iceAuthRequiredMsg), + iceConn->connect_to_you ? IceFatalToConnection : IceFatalToProtocol); + + IceReadCompleteMessage (iceConn, SIZEOF (iceAuthRequiredMsg), + iceAuthRequiredMsg, message, authData); + + if (!IceValidIO (iceConn)) + { + IceDisposeCompleteMessage (iceConn, authData); + return (0); + } + + if (swap) + { + message->authDataLength = lswaps (message->authDataLength); + } + + CHECK_COMPLETE_SIZE (iceConn, ICE_AuthRequired, length, + message->authDataLength + SIZEOF (iceAuthRequiredMsg), authData, + iceConn->connect_to_you ? IceFatalToConnection : IceFatalToProtocol); + + if (iceConn->connect_to_you) + { + if ((int) message->authIndex >= _IceAuthCount) + { + _IceConnectionError *errorReply = + &(((_IceReply *) (replyWait->reply))->connection_error); + + char *tempstr = (char *)"Received bad authIndex in the AuthRequired message"; + char errIndex = (int) message->authIndex; + + errorString = (char *) malloc (strlen (tempstr) + 1); + strcpy (errorString, tempstr); + + errorReply->type = ICE_CONNECTION_ERROR; + errorReply->error_message = errorString; + + _IceErrorBadValue (iceConn, 0, + ICE_AuthRequired, 2, 1, &errIndex); + + IceDisposeCompleteMessage (iceConn, authData); + return (1); + } + else + { + authProc = _IcePoAuthProcs[message->authIndex]; + + iceConn->connect_to_you->auth_active = 1; + } + } + else if (iceConn->protosetup_to_you) + { + if ((int) message->authIndex >= + iceConn->protosetup_to_you->my_auth_count) + { + _IceProtocolError *errorReply = + &(((_IceReply *) (replyWait->reply))->protocol_error); + + char *tempstr = (char *)"Received bad authIndex in the AuthRequired message"; + char errIndex = (int) message->authIndex; + + errorString = (char *) malloc (strlen (tempstr) + 1); + strcpy (errorString, tempstr); + + errorReply->type = ICE_PROTOCOL_ERROR; + errorReply->error_message = errorString; + + _IceErrorBadValue (iceConn, 0, + ICE_AuthRequired, 2, 1, &errIndex); + + IceDisposeCompleteMessage (iceConn, authData); + return (1); + } + else + { + _IcePoProtocol *myProtocol = _IceProtocols[ + iceConn->protosetup_to_you->my_opcode - 1].orig_client; + + realAuthIndex = iceConn->protosetup_to_you-> + my_auth_indices[message->authIndex]; + + authProc = myProtocol->auth_procs[realAuthIndex]; + + iceConn->protosetup_to_you->auth_active = 1; + } + } + else + { + /* + * Unexpected message + */ + + _IceErrorBadState (iceConn, 0, ICE_AuthRequired, IceCanContinue); + + IceDisposeCompleteMessage (iceConn, authData); + return (0); + } + + authState = NULL; + authDataLen = message->authDataLength; + + status = (*authProc) (iceConn, &authState, False /* don't clean up */, + swap, authDataLen, authData, &replyDataLen, &replyData, &errorString); + + if (status == IcePoAuthHaveReply) + { + AuthReply (iceConn, replyDataLen, replyData); + + replyWait->sequence_of_request = iceConn->send_sequence; + replyWait->minor_opcode_of_request = ICE_AuthReply; + + if (iceConn->connect_to_you) + { + iceConn->connect_to_you->my_auth_state = authState; + iceConn->connect_to_you->my_auth_index = message->authIndex; + } + else if (iceConn->protosetup_to_you) + { + iceConn->protosetup_to_you->my_auth_state = authState; + iceConn->protosetup_to_you->my_auth_index = realAuthIndex; + } + } + else if (status == IcePoAuthRejected || status == IcePoAuthFailed) + { + char *prefix, *returnErrorString; + + if (status == IcePoAuthRejected) + { + _IceErrorAuthenticationRejected (iceConn, + ICE_AuthRequired, errorString); + + prefix = (char *)"Authentication Rejected, reason : "; + } + else + { + _IceErrorAuthenticationFailed (iceConn, + ICE_AuthRequired, errorString); + + prefix = (char *)"Authentication Failed, reason : "; + } + + returnErrorString = (char *) malloc (strlen (prefix) + + strlen (errorString) + 1); + sprintf (returnErrorString, "%s%s", prefix, errorString); + free (errorString); + + if (iceConn->connect_to_you) + { + _IceConnectionError *errorReply = + &(((_IceReply *) (replyWait->reply))->connection_error); + + errorReply->type = ICE_CONNECTION_ERROR; + errorReply->error_message = returnErrorString; + } + else + { + _IceProtocolError *errorReply = + &(((_IceReply *) (replyWait->reply))->protocol_error); + + errorReply->type = ICE_PROTOCOL_ERROR; + errorReply->error_message = returnErrorString; + } + } + + if (replyData && replyDataLen > 0) + free ((char *) replyData); + + IceDisposeCompleteMessage (iceConn, authData); + + return (status != IcePoAuthHaveReply); +} + + + +static int +ProcessAuthReply (iceConn, length, swap) + +IceConn iceConn; +unsigned long length; +Bool swap; + +{ + iceAuthReplyMsg *message; + int replyDataLen; + IcePointer replyData; + int authDataLen; + IcePointer authData = NULL; + char *errorString = NULL; + + CHECK_AT_LEAST_SIZE (iceConn, ICE_AuthReply, + length, SIZEOF (iceAuthReplyMsg), + iceConn->connect_to_me ? IceFatalToConnection : IceFatalToProtocol); + + IceReadCompleteMessage (iceConn, SIZEOF (iceAuthReplyMsg), + iceAuthReplyMsg, message, replyData); + + if (!IceValidIO (iceConn)) + { + IceDisposeCompleteMessage (iceConn, replyData); + return (0); + } + + if (swap) + { + message->authDataLength = lswaps (message->authDataLength); + } + + CHECK_COMPLETE_SIZE (iceConn, ICE_AuthReply, length, + message->authDataLength + SIZEOF (iceAuthReplyMsg), replyData, + iceConn->connect_to_me ? IceFatalToConnection : IceFatalToProtocol); + + replyDataLen = message->authDataLength; + + if (iceConn->connect_to_me) + { + IcePaAuthProc authProc = _IcePaAuthProcs[(int) + (iceConn->connect_to_me->my_auth_index)]; + IcePaAuthStatus status = + (*authProc) (iceConn, &iceConn->connect_to_me->my_auth_state, swap, + replyDataLen, replyData, &authDataLen, &authData, &errorString); + + if (status == IcePaAuthContinue) + { + AuthNextPhase (iceConn, authDataLen, authData); + } + else if (status == IcePaAuthRejected || status == IcePaAuthFailed) + { + /* + * Before we reject, invoke host-based authentication callback + * and give it a chance to accept the connection (only if the + * other client doesn't require authentication). + */ + + if (!iceConn->connect_to_me->must_authenticate && + iceConn->listen_obj->host_based_auth_proc) + { + char *hostname = _IceGetPeerName (iceConn); + + if ((*iceConn->listen_obj->host_based_auth_proc) (hostname)) + { + status = IcePaAuthAccepted; + } + + if (hostname) + free (hostname); + } + + if (status != IcePaAuthAccepted) + { + free (iceConn->connect_to_me->his_vendor); + free (iceConn->connect_to_me->his_release); + free ((char *) iceConn->connect_to_me); + iceConn->connect_to_me = NULL; + + iceConn->connection_status = IceConnectRejected; + + if (status == IcePaAuthRejected) + { + _IceErrorAuthenticationRejected (iceConn, + ICE_AuthReply, errorString); + } + else + { + _IceErrorAuthenticationFailed (iceConn, + ICE_AuthReply, errorString); + } + } + } + + if (status == IcePaAuthAccepted) + { + AcceptConnection (iceConn, + iceConn->connect_to_me->his_version_index); + + iceConn->vendor = iceConn->connect_to_me->his_vendor; + iceConn->release = iceConn->connect_to_me->his_release; + iceConn->my_ice_version_index = + iceConn->connect_to_me->my_version_index; + + free ((char *) iceConn->connect_to_me); + iceConn->connect_to_me = NULL; + } + } + else if (iceConn->protosetup_to_me) + { + _IcePaProtocol *myProtocol = _IceProtocols[iceConn->protosetup_to_me-> + my_opcode - 1].accept_client; + IcePaAuthProc authProc = myProtocol->auth_procs[(int) + (iceConn->protosetup_to_me->my_auth_index)]; + IcePaAuthStatus status = + (*authProc) (iceConn, &iceConn->protosetup_to_me->my_auth_state, + swap, replyDataLen, replyData, + &authDataLen, &authData, &errorString); + int free_setup_info = 1; + + if (status == IcePaAuthContinue) + { + AuthNextPhase (iceConn, authDataLen, authData); + free_setup_info = 0; + } + else if (status == IcePaAuthRejected || status == IcePaAuthFailed) + { + /* + * Before we reject, invoke host-based authentication callback + * and give it a chance to accept the Protocol Setup (only if the + * other client doesn't require authentication). + */ + + if (!iceConn->protosetup_to_me->must_authenticate && + myProtocol->host_based_auth_proc) + { + char *hostname = _IceGetPeerName (iceConn); + + if ((*myProtocol->host_based_auth_proc) (hostname)) + { + status = IcePaAuthAccepted; + } + + if (hostname) + free (hostname); + } + + if (status == IcePaAuthRejected) + { + _IceErrorAuthenticationRejected (iceConn, + ICE_AuthReply, errorString); + } + else + { + _IceErrorAuthenticationFailed (iceConn, + ICE_AuthReply, errorString); + } + } + + if (status == IcePaAuthAccepted) + { + IcePaProcessMsgProc processMsgProc; + IceProtocolSetupProc protocolSetupProc; + IceProtocolActivateProc protocolActivateProc; + _IceProcessMsgInfo *process_msg_info; + IcePointer clientData = NULL; + char *failureReason = NULL; + Status con_status = 1; + + protocolSetupProc = myProtocol->protocol_setup_proc; + protocolActivateProc = myProtocol->protocol_activate_proc; + + if (protocolSetupProc) + { + /* + * Notify the client of the Protocol Setup. + */ + + con_status = (*protocolSetupProc) (iceConn, + myProtocol->version_recs[iceConn->protosetup_to_me-> + my_version_index].major_version, + myProtocol->version_recs[iceConn->protosetup_to_me-> + my_version_index].minor_version, + iceConn->protosetup_to_me->his_vendor, + iceConn->protosetup_to_me->his_release, + &clientData, &failureReason); + + /* + * Set vendor and release pointers to NULL, so it won't + * get freed below. The ProtocolSetupProc should + * free it. + */ + + iceConn->protosetup_to_me->his_vendor = NULL; + iceConn->protosetup_to_me->his_release = NULL; + } + + if (con_status != 0) + { + /* + * Send the Protocol Reply + */ + + AcceptProtocol (iceConn, + iceConn->protosetup_to_me->his_opcode, + iceConn->protosetup_to_me->my_opcode, + iceConn->protosetup_to_me->his_version_index, + myProtocol->vendor, myProtocol->release); + + + /* + * Set info for this protocol. + */ + + processMsgProc = myProtocol->version_recs[ + iceConn->protosetup_to_me-> + my_version_index].process_msg_proc; + + process_msg_info = &iceConn->process_msg_info[ + iceConn->protosetup_to_me-> + his_opcode -iceConn->his_min_opcode]; + + process_msg_info->client_data = clientData; + process_msg_info->accept_flag = 1; + process_msg_info->process_msg_proc. + accept_client = processMsgProc; + + + /* + * Increase the reference count for the number + * of active protocols. + */ + + iceConn->proto_ref_count++; + + + /* + * Notify the client that the protocol is active. The reason + * we have this 2nd callback invoked is because the client + * may wish to immediately generate a message for this + * protocol, but it must wait until we send the Protocol Reply. + */ + + if (protocolActivateProc) + { + (*protocolActivateProc) (iceConn, + process_msg_info->client_data); + } + } + else + { + /* + * An error was encountered. + */ + + _IceErrorSetupFailed (iceConn, ICE_ProtocolSetup, + failureReason); + + if (failureReason) + free (failureReason); + } + } + + + if (free_setup_info) + { + if (iceConn->protosetup_to_me->his_vendor) + free (iceConn->protosetup_to_me->his_vendor); + if (iceConn->protosetup_to_me->his_release) + free (iceConn->protosetup_to_me->his_release); + free ((char *) iceConn->protosetup_to_me); + iceConn->protosetup_to_me = NULL; + } + } + else + { + /* + * Unexpected message + */ + + _IceErrorBadState (iceConn, 0, ICE_AuthReply, IceCanContinue); + } + + if (authData && authDataLen > 0) + free ((char *) authData); + + if (errorString) + free (errorString); + + IceDisposeCompleteMessage (iceConn, replyData); + return (0); +} + + + +static Bool +ProcessAuthNextPhase (iceConn, length, swap, replyWait) + +IceConn iceConn; +unsigned long length; +Bool swap; +IceReplyWaitInfo *replyWait; + +{ + iceAuthNextPhaseMsg *message; + int authDataLen; + IcePointer authData; + int replyDataLen; + IcePointer replyData = NULL; + char *errorString = NULL; + IcePoAuthProc authProc; + IcePoAuthStatus status; + IcePointer *authState; + + CHECK_AT_LEAST_SIZE (iceConn, ICE_AuthNextPhase, + length, SIZEOF (iceAuthNextPhaseMsg), + iceConn->connect_to_you ? IceFatalToConnection : IceFatalToProtocol); + + IceReadCompleteMessage (iceConn, SIZEOF (iceAuthNextPhaseMsg), + iceAuthNextPhaseMsg, message, authData); + + if (!IceValidIO (iceConn)) + { + IceDisposeCompleteMessage (iceConn, authData); + return (0); + } + + if (swap) + { + message->authDataLength = lswaps (message->authDataLength); + } + + CHECK_COMPLETE_SIZE (iceConn, ICE_AuthNextPhase, length, + message->authDataLength + SIZEOF (iceAuthNextPhaseMsg), authData, + iceConn->connect_to_you ? IceFatalToConnection : IceFatalToProtocol); + + if (iceConn->connect_to_you) + { + authProc = _IcePoAuthProcs[(int) + (iceConn->connect_to_you->my_auth_index)]; + + authState = &iceConn->connect_to_you->my_auth_state; + } + else if (iceConn->protosetup_to_you) + { + _IcePoProtocol *myProtocol = + _IceProtocols[iceConn->protosetup_to_you->my_opcode - 1].orig_client; + + authProc = myProtocol->auth_procs[(int) + (iceConn->protosetup_to_you->my_auth_index)]; + + authState = &iceConn->protosetup_to_you->my_auth_state; + } + else + { + /* + * Unexpected message + */ + + _IceErrorBadState (iceConn, 0, ICE_AuthNextPhase, IceCanContinue); + + IceDisposeCompleteMessage (iceConn, authData); + return (0); + } + + authDataLen = message->authDataLength; + + status = (*authProc) (iceConn, authState, False /* don't clean up */, + swap, authDataLen, authData, &replyDataLen, &replyData, &errorString); + + if (status == IcePoAuthHaveReply) + { + AuthReply (iceConn, replyDataLen, replyData); + + replyWait->sequence_of_request = iceConn->send_sequence; + } + else if (status == IcePoAuthRejected || status == IcePoAuthFailed) + { + char *prefix = NULL; + char *returnErrorString; + + if (status == IcePoAuthRejected) + { + _IceErrorAuthenticationRejected (iceConn, + ICE_AuthNextPhase, errorString); + + prefix = (char *)"Authentication Rejected, reason : "; + } + else if (status == IcePoAuthFailed) + { + _IceErrorAuthenticationFailed (iceConn, + ICE_AuthNextPhase, errorString); + + prefix = (char *)"Authentication Failed, reason : "; + } + + returnErrorString = (char *) malloc (strlen (prefix) + + strlen (errorString) + 1); + sprintf (returnErrorString, "%s%s", prefix, errorString); + free (errorString); + + if (iceConn->connect_to_you) + { + _IceConnectionError *errorReply = + &(((_IceReply *) (replyWait->reply))->connection_error); + + errorReply->type = ICE_CONNECTION_ERROR; + errorReply->error_message = returnErrorString; + } + else + { + _IceProtocolError *errorReply = + &(((_IceReply *) (replyWait->reply))->protocol_error); + + errorReply->type = ICE_PROTOCOL_ERROR; + errorReply->error_message = returnErrorString; + } + } + + if (replyData && replyDataLen > 0) + free ((char *) replyData); + + IceDisposeCompleteMessage (iceConn, authData); + + return (status != IcePoAuthHaveReply); +} + + + +static Bool +ProcessConnectionReply (iceConn, length, swap, replyWait) + +IceConn iceConn; +unsigned long length; +Bool swap; +IceReplyWaitInfo *replyWait; + +{ + iceConnectionReplyMsg *message; + char *pData, *pStart, *pEnd; + Bool replyReady; + + CHECK_AT_LEAST_SIZE (iceConn, ICE_ConnectionReply, + length, SIZEOF (iceConnectionReplyMsg), IceFatalToConnection); + + IceReadCompleteMessage (iceConn, SIZEOF (iceConnectionReplyMsg), + iceConnectionReplyMsg, message, pStart); + + if (!IceValidIO (iceConn)) + { + IceDisposeCompleteMessage (iceConn, pStart); + return (0); + } + + pData = pStart; + pEnd = pStart + (length << 3); + + SKIP_STRING (pData, swap, pEnd, + BAIL_STRING (iceConn, ICE_ConnectionReply, + pStart)); /* vendor */ + SKIP_STRING (pData, swap, pEnd, + BAIL_STRING (iceConn, ICE_ConnectionReply, + pStart)); /* release */ + + CHECK_COMPLETE_SIZE (iceConn, ICE_ConnectionReply, + length, pData - pStart + SIZEOF (iceConnectionReplyMsg), + pStart, IceFatalToConnection); + + pData = pStart; + + if (iceConn->connect_to_you) + { + if (iceConn->connect_to_you->auth_active) + { + /* + * Tell the authentication procedure to clean up. + */ + + IcePoAuthProc authProc = _IcePoAuthProcs[(int) + (iceConn->connect_to_you->my_auth_index)]; + + (*authProc) (iceConn, &iceConn->connect_to_you->my_auth_state, + True /* clean up */, False /* swap */, + 0, NULL, NULL, NULL, NULL); + } + + if ((int) message->versionIndex >= _IceVersionCount) + { + _IceConnectionError *errorReply = + &(((_IceReply *) (replyWait->reply))->connection_error); + char errIndex = message->versionIndex; + + _IceErrorBadValue (iceConn, 0, + ICE_ConnectionReply, 2, 1, &errIndex); + + errorReply->type = ICE_CONNECTION_ERROR; + errorReply->error_message = + (char *)"Received bad version index in Connection Reply"; + } + else + { + _IceReply *reply = (_IceReply *) (replyWait->reply); + + reply->type = ICE_CONNECTION_REPLY; + reply->connection_reply.version_index = message->versionIndex; + + EXTRACT_STRING (pData, swap, reply->connection_reply.vendor); + EXTRACT_STRING (pData, swap, reply->connection_reply.release); + } + + replyReady = True; + } + else + { + /* + * Unexpected message + */ + + _IceErrorBadState (iceConn, 0, ICE_ConnectionReply, IceCanContinue); + + replyReady = False; + } + + IceDisposeCompleteMessage (iceConn, pStart); + + return (replyReady); +} + + + +static int +ProcessProtocolSetup (iceConn, length, swap) + +IceConn iceConn; +unsigned long length; +Bool swap; + +{ + iceProtocolSetupMsg *message; + _IcePaProtocol *myProtocol; + int myVersionCount, hisVersionCount; + int myVersionIndex, hisVersionIndex; + int hisMajorVersion, hisMinorVersion; + int myAuthCount, hisAuthCount; + int myOpcode, hisOpcode; + int found, i, j; + char *myAuthName; + char **hisAuthNames = NULL; + char *protocolName; + char *pData, *pStart, *pEnd; + char *vendor = NULL; + char *release = NULL; + int accept_setup_now = 0; + int myAuthIndex = 0; + int hisAuthIndex = 0; + char mustAuthenticate; + int authUsableCount; + int authUsableFlags[MAX_ICE_AUTH_NAMES]; + int authIndices[MAX_ICE_AUTH_NAMES]; + + CHECK_AT_LEAST_SIZE (iceConn, ICE_ProtocolSetup, + length, SIZEOF (iceProtocolSetupMsg), IceFatalToProtocol); + + if (iceConn->want_to_close) + { + /* + * If we sent a WantToClose message, but just got a ProtocolSetup, + * we must cancel our WantToClose. It is the responsiblity of the + * other client to send a WantToClose later on. + */ + + iceConn->want_to_close = 0; + } + + IceReadCompleteMessage (iceConn, SIZEOF (iceProtocolSetupMsg), + iceProtocolSetupMsg, message, pStart); + + if (!IceValidIO (iceConn)) + { + IceDisposeCompleteMessage (iceConn, pStart); + return (0); + } + + pData = pStart; + pEnd = pStart + (length << 3); + + SKIP_STRING (pData, swap, pEnd, + BAIL_STRING(iceConn, ICE_ProtocolSetup, + pStart)); /* proto name */ + SKIP_STRING (pData, swap, pEnd, + BAIL_STRING(iceConn, ICE_ProtocolSetup, + pStart)); /* vendor */ + SKIP_STRING (pData, swap, pEnd, + BAIL_STRING(iceConn, ICE_ProtocolSetup, + pStart)); /* release */ + SKIP_LISTOF_STRING (pData, swap, (int) message->authCount, pEnd, + BAIL_STRING(iceConn, ICE_ProtocolSetup, + pStart)); /* auth names */ + pData += (message->versionCount * 4); /* versions */ + + CHECK_COMPLETE_SIZE (iceConn, ICE_ProtocolSetup, + length, pData - pStart + SIZEOF (iceProtocolSetupMsg), + pStart, IceFatalToProtocol); + + mustAuthenticate = message->mustAuthenticate; + + if (mustAuthenticate != 0 && mustAuthenticate != 1) + { + _IceErrorBadValue (iceConn, 0, + ICE_ProtocolSetup, 4, 1, &mustAuthenticate); + IceDisposeCompleteMessage (iceConn, pStart); + return (0); + } + + pData = pStart; + + if (iceConn->process_msg_info && + (int) message->protocolOpcode >= iceConn->his_min_opcode && + (int) message->protocolOpcode <= iceConn->his_max_opcode && + iceConn->process_msg_info[ + message->protocolOpcode - iceConn->his_min_opcode].in_use) + { + _IceErrorMajorOpcodeDuplicate (iceConn, message->protocolOpcode); + IceDisposeCompleteMessage (iceConn, pStart); + return (0); + } + + EXTRACT_STRING (pData, swap, protocolName); + + if (iceConn->process_msg_info) + { + for (i = 0; + i <= (iceConn->his_max_opcode - iceConn->his_min_opcode); i++) + { + if (iceConn->process_msg_info[i].in_use && strcmp (protocolName, + iceConn->process_msg_info[i].protocol->protocol_name) == 0) + { + _IceErrorProtocolDuplicate (iceConn, protocolName); + free (protocolName); + IceDisposeCompleteMessage (iceConn, pStart); + return (0); + } + } + } + + for (i = 0; i < _IceLastMajorOpcode; i++) + if (strcmp (protocolName, _IceProtocols[i].protocol_name) == 0) + break; + + if (i < _IceLastMajorOpcode && + (myProtocol = _IceProtocols[i].accept_client) != NULL) + { + hisOpcode = message->protocolOpcode; + myOpcode = i + 1; + free (protocolName); + } + else + { + _IceErrorUnknownProtocol (iceConn, protocolName); + free (protocolName); + IceDisposeCompleteMessage (iceConn, pStart); + return (0); + } + + EXTRACT_STRING (pData, swap, vendor); + EXTRACT_STRING (pData, swap, release); + + if ((hisAuthCount = message->authCount) > 0) + { + hisAuthNames = (char **) malloc (hisAuthCount * sizeof (char *)); + EXTRACT_LISTOF_STRING (pData, swap, hisAuthCount, hisAuthNames); + } + + hisVersionCount = message->versionCount; + myVersionCount = myProtocol->version_count; + + hisVersionIndex = myVersionIndex = found = 0; + + for (i = 0; i < hisVersionCount && !found; i++) + { + EXTRACT_CARD16 (pData, swap, hisMajorVersion); + EXTRACT_CARD16 (pData, swap, hisMinorVersion); + + for (j = 0; j < myVersionCount && !found; j++) + { + if (myProtocol->version_recs[j].major_version == hisMajorVersion && + myProtocol->version_recs[j].minor_version == hisMinorVersion) + { + hisVersionIndex = i; + myVersionIndex = j; + found = 1; + } + } + } + + if (!found) + { + _IceErrorNoVersion (iceConn, ICE_ProtocolSetup); + + free (vendor); + free (release); + + if (hisAuthCount > 0) + { + for (i = 0; i < hisAuthCount; i++) + free (hisAuthNames[i]); + + free ((char *) hisAuthNames); + } + + IceDisposeCompleteMessage (iceConn, pStart); + return (0); + } + + myAuthCount = myProtocol->auth_count; + + _IceGetPaValidAuthIndices ( + _IceProtocols[myOpcode - 1].protocol_name, + iceConn->connection_string, myAuthCount, (const char **)myProtocol->auth_names, + &authUsableCount, authIndices); + + for (i = 0; i < myAuthCount; i++) + { + authUsableFlags[i] = 0; + for (j = 0; j < authUsableCount && !authUsableFlags[i]; j++) + authUsableFlags[i] = (authIndices[j] == i); + } + + for (i = found = 0; i < myAuthCount && !found; i++) + { + if (authUsableFlags[i]) + { + myAuthName = myProtocol->auth_names[i]; + + for (j = 0; j < hisAuthCount && !found; j++) + if (strcmp (myAuthName, hisAuthNames[j]) == 0) + { + myAuthIndex = i; + hisAuthIndex = j; + found = 1; + } + } + } + + if (!found) + { + /* + * None of the authentication methods specified by the + * other client is supported. If the other client requires + * authentication, we must reject the Protocol Setup now. + * Otherwise, we can invoke the host-based authentication callback + * to see if we can accept this Protocol Setup. + */ + + if (mustAuthenticate || !myProtocol->host_based_auth_proc) + { + _IceErrorNoAuthentication (iceConn, ICE_ProtocolSetup); + } + else + { + char *hostname = _IceGetPeerName (iceConn); + + if ((*myProtocol->host_based_auth_proc) (hostname)) + { + accept_setup_now = 1; + } + else + { + _IceErrorAuthenticationRejected (iceConn, + ICE_ProtocolSetup, "None of the authentication protocols specified are supported and host-based authentication failed"); + } + + if (hostname) + free (hostname); + } + } + else + { + IcePaAuthStatus status; + int authDataLen; + IcePointer authData = NULL; + IcePointer authState; + char *errorString = NULL; + IcePaAuthProc authProc = + myProtocol->auth_procs[myAuthIndex]; + + authState = NULL; + + status = (*authProc) (iceConn, &authState, swap, 0, NULL, + &authDataLen, &authData, &errorString); + + if (status == IcePaAuthContinue) + { + _IceProtoSetupToMeInfo *setupInfo; + + AuthRequired (iceConn, hisAuthIndex, authDataLen, authData); + + iceConn->protosetup_to_me = setupInfo = + (_IceProtoSetupToMeInfo *) malloc ( + sizeof (_IceProtoSetupToMeInfo)); + + setupInfo->his_opcode = hisOpcode; + setupInfo->my_opcode = myOpcode; + setupInfo->my_version_index = myVersionIndex; + setupInfo->his_version_index = hisVersionIndex; + setupInfo->his_vendor = vendor; + setupInfo->his_release = release; + vendor = release = NULL; /* so we don't free it */ + setupInfo->my_auth_index = myAuthIndex; + setupInfo->my_auth_state = authState; + setupInfo->must_authenticate = mustAuthenticate; + } + else if (status == IcePaAuthAccepted) + { + accept_setup_now = 1; + } + + if (authData && authDataLen > 0) + free ((char *) authData); + + if (errorString) + free (errorString); + } + + if (accept_setup_now) + { + IcePaProcessMsgProc processMsgProc; + IceProtocolSetupProc protocolSetupProc; + IceProtocolActivateProc protocolActivateProc; + _IceProcessMsgInfo *process_msg_info; + IcePointer clientData = NULL; + char *failureReason = NULL; + Status status = 1; + + protocolSetupProc = myProtocol->protocol_setup_proc; + protocolActivateProc = myProtocol->protocol_activate_proc; + + if (protocolSetupProc) + { + /* + * Notify the client of the Protocol Setup. + */ + + status = (*protocolSetupProc) (iceConn, + myProtocol->version_recs[myVersionIndex].major_version, + myProtocol->version_recs[myVersionIndex].minor_version, + vendor, release, &clientData, &failureReason); + + vendor = release = NULL; /* so we don't free it */ + } + + if (status != 0) + { + /* + * Send the Protocol Reply + */ + + AcceptProtocol (iceConn, hisOpcode, myOpcode, hisVersionIndex, + myProtocol->vendor, myProtocol->release); + + + /* + * Set info for this protocol. + */ + + processMsgProc = myProtocol->version_recs[ + myVersionIndex].process_msg_proc; + + process_msg_info = &iceConn->process_msg_info[hisOpcode - + iceConn->his_min_opcode]; + + process_msg_info->client_data = clientData; + process_msg_info->accept_flag = 1; + process_msg_info->process_msg_proc.accept_client = processMsgProc; + + + /* + * Increase the reference count for the number of active protocols. + */ + + iceConn->proto_ref_count++; + + + /* + * Notify the client that the protocol is active. The reason + * we have this 2nd callback invoked is because the client + * may wish to immediately generate a message for this + * protocol, but it must wait until we send the Protocol Reply. + */ + + if (protocolActivateProc) + { + (*protocolActivateProc) (iceConn, + process_msg_info->client_data); + } + } + else + { + /* + * An error was encountered. + */ + + _IceErrorSetupFailed (iceConn, ICE_ProtocolSetup, failureReason); + + if (failureReason) + free (failureReason); + } + } + + if (vendor) + free (vendor); + + if (release) + free (release); + + if (hisAuthCount > 0) + { + for (i = 0; i < hisAuthCount; i++) + free (hisAuthNames[i]); + + free ((char *) hisAuthNames); + } + + IceDisposeCompleteMessage (iceConn, pStart); + return (0); +} + + + +static Bool +ProcessProtocolReply (iceConn, length, swap, replyWait) + +IceConn iceConn; +unsigned long length; +Bool swap; +IceReplyWaitInfo *replyWait; + +{ + iceProtocolReplyMsg *message; + char *pData, *pStart, *pEnd; + Bool replyReady; + + CHECK_AT_LEAST_SIZE (iceConn, ICE_ProtocolReply, + length, SIZEOF (iceProtocolReplyMsg), IceFatalToProtocol); + + IceReadCompleteMessage (iceConn, SIZEOF (iceProtocolReplyMsg), + iceProtocolReplyMsg, message, pStart); + + if (!IceValidIO (iceConn)) + { + IceDisposeCompleteMessage (iceConn, pStart); + return (0); + } + + pData = pStart; + pEnd = pStart + (length << 3); + + SKIP_STRING (pData, swap, pEnd, + BAIL_STRING(iceConn, ICE_ProtocolReply, + pStart)); /* vendor */ + SKIP_STRING (pData, swap, pEnd, + BAIL_STRING(iceConn, ICE_ProtocolReply, + pStart)); /* release */ + + CHECK_COMPLETE_SIZE (iceConn, ICE_ProtocolReply, + length, pData - pStart + SIZEOF (iceProtocolReplyMsg), + pStart, IceFatalToProtocol); + + pData = pStart; + + if (iceConn->protosetup_to_you) + { + if (iceConn->protosetup_to_you->auth_active) + { + /* + * Tell the authentication procedure to clean up. + */ + + _IcePoProtocol *myProtocol = _IceProtocols[ + iceConn->protosetup_to_you->my_opcode - 1].orig_client; + + IcePoAuthProc authProc = myProtocol->auth_procs[(int) + (iceConn->protosetup_to_you->my_auth_index)]; + +#ifdef SVR4 + +/* + * authProc is never NULL, but the cc compiler on UNIX System V/386 + * Release 4.2 Version 1 screws up an optimization. Unless there is + * some sort of reference to authProc before the function call, the + * function call will seg fault. + */ + if (authProc) +#endif + (*authProc) (iceConn, + &iceConn->protosetup_to_you->my_auth_state, + True /* clean up */, False /* swap */, + 0, NULL, NULL, NULL, NULL); + } + + if ((int) message->versionIndex >= _IceVersionCount) + { + _IceProtocolError *errorReply = + &(((_IceReply *) (replyWait->reply))->protocol_error); + char errIndex = message->versionIndex; + + _IceErrorBadValue (iceConn, 0, + ICE_ProtocolReply, 2, 1, &errIndex); + + errorReply->type = ICE_PROTOCOL_ERROR; + errorReply->error_message = + (char *)"Received bad version index in Protocol Reply"; + } + else + { + _IceProtocolReply *reply = + &(((_IceReply *) (replyWait->reply))->protocol_reply); + + reply->type = ICE_PROTOCOL_REPLY; + reply->major_opcode = message->protocolOpcode; + reply->version_index = message->versionIndex; + + EXTRACT_STRING (pData, swap, reply->vendor); + EXTRACT_STRING (pData, swap, reply->release); + } + + replyReady = True; + } + else + { + _IceErrorBadState (iceConn, 0, ICE_ProtocolReply, IceCanContinue); + + replyReady = False; + } + + IceDisposeCompleteMessage (iceConn, pStart); + + return (replyReady); +} + + + +static int +ProcessPing (iceConn, length) + +IceConn iceConn; +unsigned long length; + +{ + CHECK_SIZE_MATCH (iceConn, ICE_Ping, + length, SIZEOF (icePingMsg), IceFatalToConnection); + + PingReply (iceConn); + + return (0); +} + + + +static int +ProcessPingReply (iceConn, length) + +IceConn iceConn; +unsigned long length; + +{ + CHECK_SIZE_MATCH (iceConn, ICE_PingReply, + length, SIZEOF (icePingReplyMsg), IceFatalToConnection); + + if (iceConn->ping_waits) + { + _IcePingWait *next = iceConn->ping_waits->next; + + (*iceConn->ping_waits->ping_reply_proc) (iceConn, + iceConn->ping_waits->client_data); + + free ((char *) iceConn->ping_waits); + iceConn->ping_waits = next; + } + else + { + _IceErrorBadState (iceConn, 0, ICE_PingReply, IceCanContinue); + } + + return (0); +} + + + +static int +ProcessWantToClose (iceConn, length, connectionClosedRet) + +IceConn iceConn; +unsigned long length; +Bool *connectionClosedRet; + +{ + *connectionClosedRet = False; + + CHECK_SIZE_MATCH (iceConn, ICE_WantToClose, + length, SIZEOF (iceWantToCloseMsg), IceFatalToConnection); + + if (iceConn->want_to_close || iceConn->open_ref_count == 0) + { + /* + * We just received a WantToClose. Either we also sent a + * WantToClose, so we close the connection, or the iceConn + * is not being used, so we close the connection. This + * second case is possible if we sent a WantToClose because + * the iceConn->open_ref_count reached zero, but then we + * received a NoClose. + */ + + _IceConnectionClosed (iceConn); /* invoke watch procs */ + _IceFreeConnection (iceConn); + *connectionClosedRet = True; + } + else if (iceConn->proto_ref_count > 0) + { + /* + * We haven't shut down all of our protocols yet. We send a NoClose, + * and it's up to us to generate a WantToClose later on. + */ + + IceSimpleMessage (iceConn, 0, ICE_NoClose); + IceFlush (iceConn); + } + else + { + /* + * The reference count on this iceConn is zero. This means that + * there are no active protocols, but the client didn't explicitly + * close the connection yet. If we didn't just send a Protocol Setup, + * we send a NoClose, and it's up to us to generate a WantToClose + * later on. + */ + + if (!iceConn->protosetup_to_you) + { + IceSimpleMessage (iceConn, 0, ICE_NoClose); + IceFlush (iceConn); + } + } + + return (0); +} + + + +static int +ProcessNoClose (iceConn, length) + +IceConn iceConn; +unsigned long length; + +{ + CHECK_SIZE_MATCH (iceConn, ICE_NoClose, + length, SIZEOF (iceNoCloseMsg), IceFatalToConnection); + + if (iceConn->want_to_close) + { + /* + * The other side can't close now. We cancel our WantToClose, + * and we can expect a WantToClose from the other side. + */ + + iceConn->want_to_close = 0; + } + else + { + _IceErrorBadState (iceConn, 0, ICE_NoClose, IceCanContinue); + } + + return (0); +} + + + +void +_IceProcessCoreMessage (iceConn, opcode, length, swap, + replyWait, replyReadyRet, connectionClosedRet) + +IceConn iceConn; +int opcode; +unsigned long length; +Bool swap; +IceReplyWaitInfo *replyWait; +Bool *replyReadyRet; +Bool *connectionClosedRet; + +{ + Bool replyReady = False; + + *connectionClosedRet = False; + + switch (opcode) + { + case ICE_Error: + + replyReady = ProcessError (iceConn, length, swap, replyWait); + break; + + case ICE_ConnectionSetup: + + ProcessConnectionSetup (iceConn, length, swap); + break; + + case ICE_AuthRequired: + + replyReady = ProcessAuthRequired (iceConn, length, swap, replyWait); + break; + + case ICE_AuthReply: + + ProcessAuthReply (iceConn, length, swap); + break; + + case ICE_AuthNextPhase: + + replyReady = ProcessAuthNextPhase (iceConn, length, swap, replyWait); + break; + + case ICE_ConnectionReply: + + replyReady = ProcessConnectionReply (iceConn, length, swap, replyWait); + break; + + case ICE_ProtocolSetup: + + ProcessProtocolSetup (iceConn, length, swap); + break; + + case ICE_ProtocolReply: + + replyReady = ProcessProtocolReply (iceConn, length, swap, replyWait); + break; + + case ICE_Ping: + + ProcessPing (iceConn, length); + break; + + case ICE_PingReply: + + ProcessPingReply (iceConn, length); + break; + + case ICE_WantToClose: + + ProcessWantToClose (iceConn, length, connectionClosedRet); + break; + + case ICE_NoClose: + + ProcessNoClose (iceConn, length); + break; + + default: + + _IceErrorBadMinor (iceConn, 0, opcode, IceCanContinue); + _IceReadSkip (iceConn, length << 3); + break; + } + + if (replyWait) + *replyReadyRet = replyReady; +} + + +#ifdef MINIX +int +MNX_IceMessagesAvailable(iceConn) + +IceConn iceConn; +{ + BytesReadable_t bytes; + + _kde_IceTransSetOption(iceConn->trans_conn, TRANS_NONBLOCKING, 1); + if (_kde_IceTransBytesReadable(iceConn->trans_conn, &bytes) < 0) + bytes= -1; + _kde_IceTransSetOption(iceConn->trans_conn, TRANS_NONBLOCKING, 0); + return (bytes != 0); +} +#endif diff --git a/dcop/KDE-ICE/protosetup.c b/dcop/KDE-ICE/protosetup.c new file mode 100644 index 000000000..f675ccd89 --- /dev/null +++ b/dcop/KDE-ICE/protosetup.c @@ -0,0 +1,287 @@ +/* $Xorg: protosetup.c,v 1.3 2000/08/17 19:44:17 cpqbld Exp $ */ +/****************************************************************************** + + +Copyright 1993, 1998 The Open Group + +All Rights Reserved. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + +Author: Ralph Mor, X Consortium +******************************************************************************/ + +#include "KDE-ICE/ICElib.h" +#include "KDE-ICE/ICElibint.h" +#include "KDE-ICE/globals.h" +#include <string.h> + + +IceProtocolSetupStatus +IceProtocolSetup (iceConn, myOpcode, clientData, mustAuthenticate, + majorVersionRet, minorVersionRet, vendorRet, releaseRet, + errorLength, errorStringRet) + +IceConn iceConn; +int myOpcode; +IcePointer clientData; +Bool mustAuthenticate; +int *majorVersionRet; +int *minorVersionRet; +char **vendorRet; +char **releaseRet; +int errorLength; +char *errorStringRet; + +{ + iceProtocolSetupMsg *pMsg; + char *pData; + _IceProtocol *myProtocol; + int extra; + Bool gotReply, ioErrorOccured; + int accepted, i; + int hisOpcode; + unsigned long setup_sequence; + IceReplyWaitInfo replyWait; + _IceReply reply; + IcePoVersionRec *versionRec = NULL; + int authCount; + int *authIndices; + + if (errorStringRet && errorLength > 0) + *errorStringRet = '\0'; + + *majorVersionRet = 0; + *minorVersionRet = 0; + *vendorRet = NULL; + *releaseRet = NULL; + + if (myOpcode < 1 || myOpcode > _IceLastMajorOpcode) + { + strncpy (errorStringRet, "myOpcode out of range", errorLength); + return (IceProtocolSetupFailure); + } + + myProtocol = &_IceProtocols[myOpcode - 1]; + + if (myProtocol->orig_client == NULL) + { + strncpy (errorStringRet, + "IceRegisterForProtocolSetup was not called", errorLength); + return (IceProtocolSetupFailure); + } + + + /* + * Make sure this protocol hasn't been activated already. + */ + + if (iceConn->process_msg_info) + { + for (i = iceConn->his_min_opcode; i <= iceConn->his_max_opcode; i++) + { + if (iceConn->process_msg_info[ + i - iceConn->his_min_opcode].in_use && + iceConn->process_msg_info[ + i - iceConn->his_min_opcode ].my_opcode == myOpcode) + break; + } + + if (i <= iceConn->his_max_opcode) + { + return (IceProtocolAlreadyActive); + } + } + + /* + * Generate the message. + */ + + if (myProtocol->orig_client->auth_count > 0) + { + authIndices = (int *) malloc ( + myProtocol->orig_client->auth_count * sizeof (int)); + + _IceGetPoValidAuthIndices (myProtocol->protocol_name, + iceConn->connection_string, + myProtocol->orig_client->auth_count, + (const char**)myProtocol->orig_client->auth_names, + &authCount, authIndices); + + } + else + { + authCount = 0; + authIndices = NULL; + } + + extra = STRING_BYTES (myProtocol->protocol_name) + + STRING_BYTES (myProtocol->orig_client->vendor) + + STRING_BYTES (myProtocol->orig_client->release); + + for (i = 0; i < authCount; i++) + { + extra += STRING_BYTES (myProtocol->orig_client->auth_names[ + authIndices[i]]); + } + + extra += (myProtocol->orig_client->version_count * 4); + + IceGetHeaderExtra (iceConn, 0, ICE_ProtocolSetup, + SIZEOF (iceProtocolSetupMsg), WORD64COUNT (extra), + iceProtocolSetupMsg, pMsg, pData); + + setup_sequence = iceConn->send_sequence; + + pMsg->protocolOpcode = myOpcode; + pMsg->versionCount = myProtocol->orig_client->version_count; + pMsg->authCount = authCount; + pMsg->mustAuthenticate = mustAuthenticate; + + STORE_STRING (pData, myProtocol->protocol_name); + STORE_STRING (pData, myProtocol->orig_client->vendor); + STORE_STRING (pData, myProtocol->orig_client->release); + + for (i = 0; i < authCount; i++) + { + STORE_STRING (pData, myProtocol->orig_client->auth_names[ + authIndices[i]]); + } + + for (i = 0; i < myProtocol->orig_client->version_count; i++) + { + STORE_CARD16 (pData, + myProtocol->orig_client->version_recs[i].major_version); + STORE_CARD16 (pData, + myProtocol->orig_client->version_recs[i].minor_version); + } + + IceFlush (iceConn); + + + /* + * Process messages until we get a Protocol Reply. + */ + + replyWait.sequence_of_request = setup_sequence; + replyWait.major_opcode_of_request = 0; + replyWait.minor_opcode_of_request = ICE_ProtocolSetup; + replyWait.reply = (IcePointer) &reply; + + iceConn->protosetup_to_you = (_IceProtoSetupToYouInfo *) malloc ( + sizeof (_IceProtoSetupToYouInfo)); + iceConn->protosetup_to_you->my_opcode = myOpcode; + iceConn->protosetup_to_you->my_auth_count = authCount; + iceConn->protosetup_to_you->auth_active = 0; + iceConn->protosetup_to_you->my_auth_indices = authIndices; + + gotReply = False; + ioErrorOccured = False; + accepted = 0; + + while (!gotReply && !ioErrorOccured) + { + ioErrorOccured = (IceProcessMessages ( + iceConn, &replyWait, &gotReply) == IceProcessMessagesIOError); + + if (ioErrorOccured) + { + strncpy (errorStringRet, + "IO error occurred doing Protocol Setup on connection", + errorLength); + return (IceProtocolSetupIOError); + } + else if (gotReply) + { + if (reply.type == ICE_PROTOCOL_REPLY) + { + if (reply.protocol_reply.version_index >= + myProtocol->orig_client->version_count) + { + strncpy (errorStringRet, + "Got a bad version index in the Protocol Reply", + errorLength); + + free (reply.protocol_reply.vendor); + free (reply.protocol_reply.release); + } + else + { + versionRec = &(myProtocol->orig_client->version_recs[ + reply.protocol_reply.version_index]); + + accepted = 1; + } + } + else /* reply.type == ICE_PROTOCOL_ERROR */ + { + /* Protocol Setup failed */ + + strncpy (errorStringRet, reply.protocol_error.error_message, + errorLength); + + free (reply.protocol_error.error_message); + } + + if (iceConn->protosetup_to_you->my_auth_indices) + free ((char *) iceConn->protosetup_to_you->my_auth_indices); + free ((char *) iceConn->protosetup_to_you); + iceConn->protosetup_to_you = NULL; + } + } + + if (accepted) + { + _IceProcessMsgInfo *process_msg_info; + + *majorVersionRet = versionRec->major_version; + *minorVersionRet = versionRec->minor_version; + *vendorRet = reply.protocol_reply.vendor; + *releaseRet = reply.protocol_reply.release; + + + /* + * Increase the reference count for the number of active protocols. + */ + + iceConn->proto_ref_count++; + + + /* + * We may be using a different major opcode for this protocol + * than the other client. Whenever we get a message, we must + * map to our own major opcode. + */ + + hisOpcode = reply.protocol_reply.major_opcode; + + _IceAddOpcodeMapping (iceConn, hisOpcode, myOpcode); + + process_msg_info = &iceConn->process_msg_info[hisOpcode - + iceConn->his_min_opcode]; + + process_msg_info->client_data = clientData; + process_msg_info->accept_flag = 0; + + process_msg_info->process_msg_proc.orig_client = + versionRec->process_msg_proc; + + return (IceProtocolSetupSuccess); + } + else + { + return (IceProtocolSetupFailure); + } +} diff --git a/dcop/KDE-ICE/register.c b/dcop/KDE-ICE/register.c new file mode 100644 index 000000000..77c686ba0 --- /dev/null +++ b/dcop/KDE-ICE/register.c @@ -0,0 +1,251 @@ +/* $Xorg: register.c,v 1.3 2000/08/17 19:44:18 cpqbld Exp $ */ +/****************************************************************************** + + +Copyright 1993, 1998 The Open Group + +All Rights Reserved. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + +Author: Ralph Mor, X Consortium +******************************************************************************/ + +#include "KDE-ICE/ICElib.h" +#include "KDE-ICE/ICElibint.h" +#include "KDE-ICE/globals.h" +#include <string.h> + +int +IceRegisterForProtocolSetup (protocolName, vendor, release, + versionCount, versionRecs, authCount, authNames, authProcs, IOErrorProc) + +char *protocolName; +char *vendor; +char *release; +int versionCount; +IcePoVersionRec *versionRecs; +int authCount; +char **authNames; +IcePoAuthProc *authProcs; +IceIOErrorProc IOErrorProc; + +{ + _IcePoProtocol *p; + int opcodeRet, i; + + for (i = 1; i <= _IceLastMajorOpcode; i++) + if (strcmp (protocolName, _IceProtocols[i - 1].protocol_name) == 0) + { + if (_IceProtocols[i - 1].orig_client != NULL) + { + /* + * We've already registered this protocol. + */ + + return (i); + } + else + { + break; + } + } + + if (i <= _IceLastMajorOpcode) + { + p = _IceProtocols[i - 1].orig_client = + (_IcePoProtocol *) malloc (sizeof (_IcePoProtocol)); + opcodeRet = i; + } + else if (_IceLastMajorOpcode == 255 || + versionCount < 1 || + strlen (protocolName) == 0) + { + return (-1); + } + else + { + char *name; + + _IceProtocols[_IceLastMajorOpcode].protocol_name = name = + (char *) malloc (strlen (protocolName) + 1); + strcpy (name, protocolName); + + p = _IceProtocols[_IceLastMajorOpcode].orig_client = + (_IcePoProtocol *) malloc (sizeof (_IcePoProtocol)); + + _IceProtocols[_IceLastMajorOpcode].accept_client = NULL; + + opcodeRet = ++_IceLastMajorOpcode; + } + + p->vendor = (char *) malloc (strlen (vendor) + 1); + strcpy (p->vendor, vendor); + + p->release = (char *) malloc (strlen (release) + 1); + strcpy (p->release, release); + + p->version_count = versionCount; + + p->version_recs = (IcePoVersionRec *) malloc ( + versionCount * sizeof (IcePoVersionRec)); + memcpy (p->version_recs, versionRecs, + versionCount * sizeof (IcePoVersionRec)); + + if ((p->auth_count = authCount) > 0) + { + p->auth_names = (char **) malloc ( + authCount * sizeof (char *)); + + p->auth_procs = (IcePoAuthProc *) malloc ( + authCount * sizeof (IcePoAuthProc)); + + for (i = 0; i < authCount; i++) + { + p->auth_names[i] = + (char *) malloc (strlen (authNames[i]) + 1); + strcpy (p->auth_names[i], authNames[i]); + + p->auth_procs[i] = authProcs[i]; + } + } + else + { + p->auth_names = NULL; + p->auth_procs = NULL; + } + + p->io_error_proc = IOErrorProc; + + return (opcodeRet); +} + + + +int +IceRegisterForProtocolReply (protocolName, vendor, release, + versionCount, versionRecs, authCount, authNames, authProcs, + hostBasedAuthProc, protocolSetupProc, protocolActivateProc, + IOErrorProc) + +char *protocolName; +char *vendor; +char *release; +int versionCount; +IcePaVersionRec *versionRecs; +int authCount; +char **authNames; +IcePaAuthProc *authProcs; +IceHostBasedAuthProc hostBasedAuthProc; +IceProtocolSetupProc protocolSetupProc; +IceProtocolActivateProc protocolActivateProc; +IceIOErrorProc IOErrorProc; + +{ + _IcePaProtocol *p; + int opcodeRet, i; + + for (i = 1; i <= _IceLastMajorOpcode; i++) + if (strcmp (protocolName, _IceProtocols[i - 1].protocol_name) == 0) + { + if (_IceProtocols[i - 1].accept_client != NULL) + { + /* + * We've already registered this protocol. + */ + + return (i); + } + else + { + break; + } + } + + + if (i <= _IceLastMajorOpcode) + { + p = _IceProtocols[i - 1].accept_client = + (_IcePaProtocol *) malloc (sizeof (_IcePaProtocol)); + opcodeRet = i; + } + else if (_IceLastMajorOpcode == 255 || + versionCount < 1 || + strlen (protocolName) == 0) + { + return (-1); + } + else + { + char *name; + + _IceProtocols[_IceLastMajorOpcode].protocol_name = name = + (char *) malloc (strlen (protocolName) + 1); + strcpy (name, protocolName); + + _IceProtocols[_IceLastMajorOpcode].orig_client = NULL; + + p = _IceProtocols[_IceLastMajorOpcode].accept_client = + (_IcePaProtocol *) malloc (sizeof (_IcePaProtocol)); + + opcodeRet = ++_IceLastMajorOpcode; + } + + p->vendor = (char *) malloc (strlen (vendor) + 1); + strcpy (p->vendor, vendor); + + p->release = (char *) malloc (strlen (release) + 1); + strcpy (p->release, release); + + p->version_count = versionCount; + + p->version_recs = (IcePaVersionRec *) malloc ( + versionCount * sizeof (IcePaVersionRec)); + memcpy (p->version_recs, versionRecs, + versionCount * sizeof (IcePaVersionRec)); + + p->protocol_setup_proc = protocolSetupProc; + p->protocol_activate_proc = protocolActivateProc; + + if ((p->auth_count = authCount) > 0) + { + p->auth_names = (char **) malloc ( + authCount * sizeof (char *)); + + p->auth_procs = (IcePaAuthProc *) malloc ( + authCount * sizeof (IcePaAuthProc)); + + for (i = 0; i < authCount; i++) + { + p->auth_names[i] = + (char *) malloc (strlen (authNames[i]) + 1); + strcpy (p->auth_names[i], authNames[i]); + + p->auth_procs[i] = authProcs[i]; + } + } + else + { + p->auth_names = NULL; + p->auth_procs = NULL; + } + + p->host_based_auth_proc = hostBasedAuthProc; + + p->io_error_proc = IOErrorProc; + + return (opcodeRet); +} + diff --git a/dcop/KDE-ICE/replywait.c b/dcop/KDE-ICE/replywait.c new file mode 100644 index 000000000..a54ce144d --- /dev/null +++ b/dcop/KDE-ICE/replywait.c @@ -0,0 +1,171 @@ +/* $XConsortium: replywait.c,v 1.4 94/04/17 20:15:39 mor Exp $ */ +/****************************************************************************** + + +Copyright (c) 1993 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from the X Consortium. + +Author: Ralph Mor, X Consortium +******************************************************************************/ + +#include <KDE-ICE/ICElib.h> +#include "KDE-ICE/ICElibint.h" + + +void +_IceAddReplyWait (iceConn, replyWait) + +IceConn iceConn; +IceReplyWaitInfo *replyWait; + +{ + /* + * Add this replyWait to the end of the list (only if the + * replyWait is not already in the list). + */ + + _IceSavedReplyWait *savedReplyWait; + _IceSavedReplyWait *prev, *last; + + prev = NULL; + last = iceConn->saved_reply_waits; + + while (last) + { + if (last->reply_wait == replyWait) + return; + + prev = last; + last = last->next; + } + + savedReplyWait = (_IceSavedReplyWait *) malloc ( + sizeof (_IceSavedReplyWait)); + + savedReplyWait->reply_wait = replyWait; + savedReplyWait->reply_ready = False; + savedReplyWait->next = NULL; + + if (prev == NULL) + iceConn->saved_reply_waits = savedReplyWait; + else + prev->next = savedReplyWait; +} + + + +IceReplyWaitInfo * +_IceSearchReplyWaits (iceConn, majorOpcode) + +IceConn iceConn; +int majorOpcode; + +{ + /* + * Return the first replyWait in the list with the given majorOpcode + */ + _IceSavedReplyWait *savedReplyWait = iceConn->saved_reply_waits; + + + /* first translate the opcode from the other end to our major */ + if (majorOpcode != 0) /* major 0 (ICE) is always the same*/ + { + if ((majorOpcode < iceConn->his_min_opcode) || (majorOpcode > iceConn->his_max_opcode)) + return NULL; + majorOpcode = iceConn->process_msg_info[majorOpcode - iceConn->his_min_opcode].my_opcode; + } + + + while (savedReplyWait) + { + if (!savedReplyWait->reply_ready && + (savedReplyWait->reply_wait->major_opcode_of_request == majorOpcode)) + return savedReplyWait->reply_wait; + + savedReplyWait = savedReplyWait->next; + } + + return NULL; +} + + + +void +_IceSetReplyReady (iceConn, replyWait) + +IceConn iceConn; +IceReplyWaitInfo *replyWait; + +{ + /* + * The replyWait specified has a reply ready. + */ + + _IceSavedReplyWait *savedReplyWait = iceConn->saved_reply_waits; + + while (savedReplyWait && savedReplyWait->reply_wait != replyWait) + savedReplyWait = savedReplyWait->next; + + if (savedReplyWait) + savedReplyWait->reply_ready = True; +} + + + +Bool +_IceCheckReplyReady (iceConn, replyWait) + +IceConn iceConn; +IceReplyWaitInfo *replyWait; + +{ + _IceSavedReplyWait *savedReplyWait = iceConn->saved_reply_waits; + _IceSavedReplyWait *prev = NULL; + Bool found = False; + Bool ready; + + while (savedReplyWait && !found) + { + if (savedReplyWait->reply_wait == replyWait) + found = True; + else + { + prev = savedReplyWait; + savedReplyWait = savedReplyWait->next; + } + } + + ready = found && savedReplyWait->reply_ready; + + if (ready) + { + if (prev == NULL) + iceConn->saved_reply_waits = savedReplyWait->next; + else + prev->next = savedReplyWait->next; + + free ((char *) savedReplyWait); + } + + return (ready); +} diff --git a/dcop/KDE-ICE/setauth.c b/dcop/KDE-ICE/setauth.c new file mode 100644 index 000000000..5c16f656f --- /dev/null +++ b/dcop/KDE-ICE/setauth.c @@ -0,0 +1,116 @@ +/* $Xorg: setauth.c,v 1.3 2000/08/17 19:44:18 cpqbld Exp $ */ +/****************************************************************************** + + +Copyright 1993, 1998 The Open Group + +All Rights Reserved. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + +Author: Ralph Mor, X Consortium +******************************************************************************/ +/* $XFree86: xc/lib/ICE/setauth.c,v 1.3 2001/01/17 19:41:29 dawes Exp $ */ + +#include "KDE-ICE/ICElib.h" +#include "KDE-ICE/ICElibint.h" +#include "KDE-ICE/ICEutil.h" +#include "KDE-ICE/globals.h" +#include <string.h> + + +/* + * IceSetPaAuthData is not a standard part of ICElib, it is specific + * to the sample implementation. + * + * For the client that initiates a Protocol Setup, we look in the + * .ICEauthority file to get authentication data. + * + * For the client accepting the Protocol Setup, we get the data + * from an in-memory database of authentication data (set by the + * application calling IceSetPaAuthData). We have to get the data + * from memory because getting it directly from the .ICEauthority + * file is not secure - someone can just modify the contents of the + * .ICEauthority file behind our back. + */ + +int _IcePaAuthDataEntryCount = 0; +#ifndef __EMX__ +IceAuthDataEntry _IcePaAuthDataEntries[ICE_MAX_AUTH_DATA_ENTRIES]; +#else +IceAuthDataEntry _IcePaAuthDataEntries[ICE_MAX_AUTH_DATA_ENTRIES] = {0}; +#endif + + +void +IceSetPaAuthData (numEntries, entries) + +int numEntries; +IceAuthDataEntry *entries; + +{ + /* + * _IcePaAuthDataEntries should really be a linked list. + * On my list of TO DO stuff. + */ + + int i, j; + + for (i = 0; i < numEntries; i++) + { + for (j = 0; j < _IcePaAuthDataEntryCount; j++) + if (strcmp (entries[i].protocol_name, + _IcePaAuthDataEntries[j].protocol_name) == 0 && + strcmp (entries[i].network_id, + _IcePaAuthDataEntries[j].network_id) == 0 && + strcmp (entries[i].auth_name, + _IcePaAuthDataEntries[j].auth_name) == 0) + break; + + if (j < _IcePaAuthDataEntryCount) + { + free (_IcePaAuthDataEntries[j].protocol_name); + free (_IcePaAuthDataEntries[j].network_id); + free (_IcePaAuthDataEntries[j].auth_name); + free (_IcePaAuthDataEntries[j].auth_data); + } + else + { + _IcePaAuthDataEntryCount++; + } + + _IcePaAuthDataEntries[j].protocol_name = (char *) malloc ( + strlen (entries[i].protocol_name) + 1); + strcpy (_IcePaAuthDataEntries[j].protocol_name, + entries[i].protocol_name); + + _IcePaAuthDataEntries[j].network_id = (char *) malloc ( + strlen (entries[i].network_id) + 1); + strcpy (_IcePaAuthDataEntries[j].network_id, + entries[i].network_id); + + _IcePaAuthDataEntries[j].auth_name = (char *) malloc ( + strlen (entries[i].auth_name) + 1); + strcpy (_IcePaAuthDataEntries[j].auth_name, + entries[i].auth_name); + + _IcePaAuthDataEntries[j].auth_data_length = + entries[i].auth_data_length; + _IcePaAuthDataEntries[j].auth_data = (char *) malloc ( + entries[i].auth_data_length); + memcpy (_IcePaAuthDataEntries[j].auth_data, + entries[i].auth_data, entries[i].auth_data_length); + } +} diff --git a/dcop/KDE-ICE/shutdown.c b/dcop/KDE-ICE/shutdown.c new file mode 100644 index 000000000..740126fa4 --- /dev/null +++ b/dcop/KDE-ICE/shutdown.c @@ -0,0 +1,323 @@ +/* $Xorg: shutdown.c,v 1.3 2000/08/17 19:44:18 cpqbld Exp $ */ +/****************************************************************************** + + +Copyright 1993, 1998 The Open Group + +All Rights Reserved. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + +Author: Ralph Mor, X Consortium +******************************************************************************/ + +#include "KDE-ICE/ICElib.h" +#include "KDE-ICE/ICElibint.h" +#include "KDE-ICE/Xtrans.h" +#include "KDE-ICE/globals.h" + + +Status +IceProtocolShutdown (iceConn, majorOpcode) + +IceConn iceConn; +int majorOpcode; + +{ + if (iceConn->proto_ref_count == 0 || iceConn->process_msg_info == NULL || + majorOpcode < 1 || majorOpcode > _IceLastMajorOpcode) + { + return (0); + } + else + { + /* + * Make sure this majorOpcode is really being used. + */ + + int i; + + for (i = iceConn->his_min_opcode; i <= iceConn->his_max_opcode; i++) + { + if (iceConn->process_msg_info[ + i - iceConn->his_min_opcode].in_use && + iceConn->process_msg_info[ + i - iceConn->his_min_opcode].my_opcode == majorOpcode) + break; + } + + if (i > iceConn->his_max_opcode) + { + return (0); + } + else + { + /* + * OK, we can shut down the protocol. + */ + + iceConn->process_msg_info[ + i - iceConn->his_min_opcode].in_use = False; + iceConn->proto_ref_count--; + + return (1); + } + } +} + + + +void +IceSetShutdownNegotiation (iceConn, negotiate) + +IceConn iceConn; +Bool negotiate; + +{ + iceConn->skip_want_to_close = negotiate ? False : True; +} + + + +Bool +IceCheckShutdownNegotiation (iceConn) + +IceConn iceConn; + +{ + return (iceConn->skip_want_to_close ? False : True); +} + + + +IceCloseStatus +IceCloseConnection (iceConn) + +IceConn iceConn; + +{ + int refCountReachedZero; + IceCloseStatus status; + + /* + * If this connection object was never valid, we can close + * it right now. This happens if IceAcceptConnection was + * called, but after calling IceProcessMessages several times + * the connection was rejected (because of authentication or + * some other reason). + */ + + if (iceConn->listen_obj && + iceConn->connection_status != IceConnectAccepted) + { + _IceConnectionClosed (iceConn); /* invoke watch procs */ + _IceFreeConnection (iceConn); + return (IceClosedNow); + } + + + /*--------------------------------------------------------------- + + ACTIONS: + + A = Invoke Watch Procedures + B = Set free-asap bit + C = Free connection + D = Initialize shutdown negotiation + N = do nothing + + + ACTION TABLE: + + IO free- dispatch protocol shutdown + error asap bit level refcount negotiation ACTION + occurred set reached 0 reached 0 + + 0 0 0 0 0 N + 0 0 0 0 1 N + 0 0 0 1 0 AB + 0 0 0 1 1 N + 0 0 1 0 0 N + 0 0 1 0 1 N + 0 0 1 1 0 AC + 0 0 1 1 1 D + 0 1 0 0 0 N + 0 1 0 0 1 N + 0 1 0 1 0 N + 0 1 0 1 1 N + 0 1 1 0 0 C + 0 1 1 0 1 D + 0 1 1 1 0 C + 0 1 1 1 1 D + 1 0 0 0 0 AB + 1 0 0 0 1 AB + 1 0 0 1 0 AB + 1 0 0 1 1 AB + 1 0 1 0 0 AC + 1 0 1 0 1 AC + 1 0 1 1 0 AC + 1 0 1 1 1 AC + 1 1 0 0 0 N + 1 1 0 0 1 N + 1 1 0 1 0 N + 1 1 0 1 1 N + 1 1 1 0 0 C + 1 1 1 0 1 C + 1 1 1 1 0 C + 1 1 1 1 1 C + + ---------------------------------------------------------------*/ + + if (iceConn->open_ref_count > 0) + iceConn->open_ref_count--; + + refCountReachedZero = iceConn->open_ref_count == 0 && + iceConn->proto_ref_count == 0; + + status = IceConnectionInUse; + + if (!iceConn->free_asap && (!iceConn->io_ok || + (iceConn->io_ok && refCountReachedZero && + iceConn->skip_want_to_close))) + { + /* + * Invoke the watch procedures now. + */ + + _IceConnectionClosed (iceConn); + status = IceClosedNow; /* may be overwritten by IceClosedASAP */ + } + + if (!iceConn->free_asap && iceConn->dispatch_level != 0 && + (!iceConn->io_ok || + (iceConn->io_ok && refCountReachedZero && + iceConn->skip_want_to_close))) + { + /* + * Set flag so we free the connection as soon as possible. + */ + + iceConn->free_asap = True; + status = IceClosedASAP; + } + + if (iceConn->io_ok && iceConn->dispatch_level == 0 && + !iceConn->skip_want_to_close && refCountReachedZero) + { + /* + * Initiate shutdown negotiation. + */ + + IceSimpleMessage (iceConn, 0, ICE_WantToClose); + IceFlush (iceConn); + + iceConn->want_to_close = 1; + + status = IceStartedShutdownNegotiation; + } + else if (iceConn->dispatch_level == 0 && + (!iceConn->io_ok || (iceConn->io_ok && iceConn->skip_want_to_close && + (iceConn->free_asap || (!iceConn->free_asap && refCountReachedZero))))) + { + /* + * Free the connection. + */ + + _IceFreeConnection (iceConn); + + status = IceClosedNow; + } + + return (status); +} + + + +void +_IceFreeConnection (iceConn) + +IceConn iceConn; + +{ + if (iceConn->listen_obj == NULL) + { + /* + * This iceConn was created with IceOpenConnection. + * We keep track of all open IceConn's, so we need + * to remove it from the list. + */ + + int i; + + for (i = 0; i < _IceConnectionCount; i++) + if (_IceConnectionObjs[i] == iceConn) + break; + + if (i < _IceConnectionCount) + { + if (i < _IceConnectionCount - 1) + { + _IceConnectionObjs[i] = + _IceConnectionObjs[_IceConnectionCount - 1]; + _IceConnectionStrings[i] = + _IceConnectionStrings[_IceConnectionCount - 1]; + } + + _IceConnectionCount--; + } + } + + if (iceConn->trans_conn) + _kde_IceTransClose (iceConn->trans_conn); + + if (iceConn->connection_string) + free (iceConn->connection_string); + + if (iceConn->vendor) + free (iceConn->vendor); + + if (iceConn->release) + free (iceConn->release); + + if (iceConn->inbuf) + free (iceConn->inbuf); + + if (iceConn->outbuf) + free (iceConn->outbuf); + + if (iceConn->scratch) + free (iceConn->scratch); + + if (iceConn->process_msg_info) + free ((char *) iceConn->process_msg_info); + + if (iceConn->connect_to_you) + free ((char *) iceConn->connect_to_you); + + if (iceConn->protosetup_to_you) + free ((char *) iceConn->protosetup_to_you); + + if (iceConn->connect_to_me) + free ((char *) iceConn->connect_to_me); + + if (iceConn->protosetup_to_me) + free ((char *) iceConn->protosetup_to_me); + + free ((char *) iceConn); +} + + + + diff --git a/dcop/KDE-ICE/transport.c b/dcop/KDE-ICE/transport.c new file mode 100644 index 000000000..8c862ddfb --- /dev/null +++ b/dcop/KDE-ICE/transport.c @@ -0,0 +1,68 @@ +/* $TOG: transport.c /main/7 1998/02/06 15:54:19 kaleb $ */ +/* + +Copyright 1993, 1994, 1998 The Open Group + +All Rights Reserved. + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall +not be used in advertising or otherwise to promote the sale, use or +other dealings in this Software without prior written authorization +from The Open Group. + +*/ +/* $XFree86: xc/lib/xtrans/transport.c,v 3.4 1998/10/03 09:07:37 dawes Exp $ */ + +/* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA + * + * All Rights Reserved + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name NCR not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. NCR makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * NCR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef X_NOT_STDC_ENV +#include <stdlib.h> +#endif + +#define xalloc(_size) malloc(_size) +#define xcalloc(_num,_size) calloc(_num,_size) +#define xrealloc(_ptr,_size) realloc(_ptr,_size) +#define xfree(_ptr) free(_ptr) + +#include "Xtransint.h" + +#ifdef LOCALCONN +#include "Xtranslcl.c" +#endif +#if defined(TCPCONN) || defined(UNIXCONN) +#include "Xtranssock.c" +#endif +#include "Xtrans.c" +#include "Xtransutil.c" diff --git a/dcop/KDE-ICE/watch.c b/dcop/KDE-ICE/watch.c new file mode 100644 index 000000000..79a2b8910 --- /dev/null +++ b/dcop/KDE-ICE/watch.c @@ -0,0 +1,199 @@ +/* $Xorg: watch.c,v 1.3 2000/08/17 19:44:19 cpqbld Exp $ */ +/****************************************************************************** + + +Copyright 1993, 1998 The Open Group + +All Rights Reserved. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + +Author: Ralph Mor, X Consortium +******************************************************************************/ + +#include "KDE-ICE/ICElib.h" +#include "KDE-ICE/ICElibint.h" +#include "KDE-ICE/globals.h" + +Status +IceAddConnectionWatch (watchProc, clientData) + +IceWatchProc watchProc; +IcePointer clientData; + +{ + /* + * watchProc will be called each time an ICE connection is + * created/destroyed by ICElib. + */ + + _IceWatchProc *ptr = _IceWatchProcs; + _IceWatchProc *newWatchProc; + int i; + + if ((newWatchProc = (_IceWatchProc *) malloc ( + sizeof (_IceWatchProc))) == NULL) + { + return (0); + } + + newWatchProc->watch_proc = watchProc; + newWatchProc->client_data = clientData; + newWatchProc->watched_connections = NULL; + newWatchProc->next = NULL; + + while (ptr && ptr->next) + ptr = ptr->next; + + if (ptr == NULL) + _IceWatchProcs = newWatchProc; + else + ptr->next = newWatchProc; + + + /* + * Invoke the watch proc with any previously opened ICE connections. + */ + + for (i = 0; i < _IceConnectionCount; i++) + { + _IceWatchedConnection *newWatchedConn = (_IceWatchedConnection *) + malloc (sizeof (_IceWatchedConnection)); + + newWatchedConn->iceConn = _IceConnectionObjs[i]; + newWatchedConn->next = NULL; + + newWatchProc->watched_connections = newWatchedConn; + + (*newWatchProc->watch_proc) (_IceConnectionObjs[i], + newWatchProc->client_data, True, &newWatchedConn->watch_data); + } + + return (1); +} + + + +void +IceRemoveConnectionWatch (watchProc, clientData) + +IceWatchProc watchProc; +IcePointer clientData; + +{ + _IceWatchProc *currWatchProc = _IceWatchProcs; + _IceWatchProc *prevWatchProc = NULL; + + while (currWatchProc && (currWatchProc->watch_proc != watchProc || + currWatchProc->client_data != clientData)) + { + prevWatchProc = currWatchProc; + currWatchProc = currWatchProc->next; + } + + if (currWatchProc) + { + _IceWatchProc *nextWatchProc = currWatchProc->next; + _IceWatchedConnection *watchedConn; + + watchedConn = currWatchProc->watched_connections; + while (watchedConn) + { + _IceWatchedConnection *nextWatchedConn = watchedConn->next; + free ((char *) watchedConn); + watchedConn = nextWatchedConn; + } + + if (prevWatchProc == NULL) + _IceWatchProcs = nextWatchProc; + else + prevWatchProc->next = nextWatchProc; + + free ((char *) currWatchProc); + } +} + + + +void +_IceConnectionOpened (iceConn) + +IceConn iceConn; + +{ + _IceWatchProc *watchProc = _IceWatchProcs; + + while (watchProc) + { + _IceWatchedConnection *newWatchedConn = (_IceWatchedConnection *) + malloc (sizeof (_IceWatchedConnection)); + _IceWatchedConnection *watchedConn; + + watchedConn = watchProc->watched_connections; + while (watchedConn && watchedConn->next) + watchedConn = watchedConn->next; + + newWatchedConn->iceConn = iceConn; + newWatchedConn->next = NULL; + + if (watchedConn == NULL) + watchProc->watched_connections = newWatchedConn; + else + watchedConn->next = newWatchedConn; + + (*watchProc->watch_proc) (iceConn, + watchProc->client_data, True, &newWatchedConn->watch_data); + + watchProc = watchProc->next; + } +} + + + +void +_IceConnectionClosed (iceConn) + +IceConn iceConn; + +{ + _IceWatchProc *watchProc = _IceWatchProcs; + + while (watchProc) + { + _IceWatchedConnection *watchedConn = watchProc->watched_connections; + _IceWatchedConnection *prev = NULL; + + while (watchedConn && watchedConn->iceConn != iceConn) + { + prev = watchedConn; + watchedConn = watchedConn->next; + } + + if (watchedConn) + { + (*watchProc->watch_proc) (iceConn, + watchProc->client_data, False, &watchedConn->watch_data); + + if (prev == NULL) + watchProc->watched_connections = watchedConn->next; + else + prev->next = watchedConn->next; + + free ((char *) watchedConn); + } + + watchProc = watchProc->next; + } +} |