static void x_session_check_input (int fd, void *data) { int ret; if (ice_fd == -1) return; /* Reset this so wo can check kind after callbacks have been called by IceProcessMessages. The smc_interact_CB sets the kind to SAVE_SESSION_EVENT, but we don't know beforehand if that callback will be called. */ emacs_event.kind = NO_EVENT; ret = IceProcessMessages (SmcGetIceConnection (smc_conn), 0, 0); if (ret != IceProcessMessagesSuccess) { /* Either IO error or Connection closed. */ if (ret == IceProcessMessagesIOError) IceCloseConnection (SmcGetIceConnection (smc_conn)); ice_connection_closed (); } /* Check if smc_interact_CB was called and we shall generate a SAVE_SESSION_EVENT. */ if (emacs_event.kind != NO_EVENT) kbd_buffer_store_event (&emacs_event); }
/* This is called when data is available on an ICE connection. */ static gboolean process_ice_messages (GIOChannel *channel, GIOCondition condition, gpointer client_data) { IceConn connection = (IceConn) client_data; IceProcessMessagesStatus status; /* This blocks infinitely sometimes. I don't know what * to do about it. Checking "condition" just breaks * session management. */ status = IceProcessMessages (connection, NULL, NULL); if (status == IceProcessMessagesIOError) { #if 0 IcePointer context = IceGetConnectionContext (connection); #endif /* We were disconnected */ IceSetShutdownNegotiation (connection, False); IceCloseConnection (connection); return FALSE; } return TRUE; }
static void ice_io_cb(pa_mainloop_api*a, pa_io_event *e, int fd, pa_io_event_flags_t flags, void *userdata) { IceConn connection = userdata; if (IceProcessMessages(connection, NULL, NULL) == IceProcessMessagesIOError) { IceSetShutdownNegotiation(connection, False); IceCloseConnection(connection); } }
static void NewConnectionXtProc(XtPointer client_data, int *source, XtInputId *id) { IceConn ice_conn; char *connstr; IceAcceptStatus status; if (shutdownInProgress) { /* * Don't accept new connections if we are in the middle * of a shutdown. */ return; } ice_conn = IceAcceptConnection((IceListenObj) client_data, &status); if (! ice_conn) { if (verbose) printf ("IceAcceptConnection failed\n"); } else { IceConnectStatus cstatus; while ((cstatus = IceConnectionStatus (ice_conn))==IceConnectPending) { XtAppProcessEvent (appContext, XtIMAll); } if (cstatus == IceConnectAccepted) { if (verbose) { printf ("ICE Connection opened by client, IceConn fd = %d, ", IceConnectionNumber (ice_conn)); connstr = IceConnectionString (ice_conn); printf ("Accept at networkId %s\n", connstr); free (connstr); printf ("\n"); } } else { if (verbose) { if (cstatus == IceConnectIOError) printf ("IO error opening ICE Connection!\n"); else printf ("ICE Connection rejected!\n"); } IceCloseConnection (ice_conn); } } }
Bool dcop_detach() { int status; IceProtocolShutdown(dcop_ice_conn, dcop_major_opcode); status = IceCloseConnection(dcop_ice_conn); if (status == IceClosedNow) dcop_ice_conn = 0L; else fprintf(stderr, "dcop_detach(): Could not detach\n"); return status == IceClosedNow; }
void KSMCloseConnectionProc ( SmsConn smsConn, SmPointer managerData, int count, char ** reasonMsgs ) { the_server->deleteClient( ( KSMClient* ) managerData ); if ( count ) SmFreeReasons( count, reasonMsgs ); IceConn iceConn = SmsGetIceConnection( smsConn ); SmsCleanUp( smsConn ); IceSetShutdownNegotiation (iceConn, False); IceCloseConnection( iceConn ); }
int x_session_check_input (struct input_event *bufp) { SELECT_TYPE read_fds; EMACS_TIME tmout; int ret; if (ice_fd == -1) return 0; FD_ZERO (&read_fds); FD_SET (ice_fd, &read_fds); tmout.tv_sec = 0; tmout.tv_usec = 0; /* Reset this so wo can check kind after callbacks have been called by IceProcessMessages. The smc_interact_CB sets the kind to SAVE_SESSION_EVENT, but we don't know beforehand if that callback will be called. */ emacs_event.kind = NO_EVENT; ret = select (ice_fd+1, &read_fds, (SELECT_TYPE *)0, (SELECT_TYPE *)0, &tmout); if (ret < 0) { ice_connection_closed (); } else if (ret > 0 && FD_ISSET (ice_fd, &read_fds)) { ret = IceProcessMessages (SmcGetIceConnection (smc_conn), (IceReplyWaitInfo *)0, (Bool *)0); if (ret != IceProcessMessagesSuccess) { /* Either IO error or Connection closed. */ if (ret == IceProcessMessagesIOError) IceCloseConnection (SmcGetIceConnection (smc_conn)); ice_connection_closed (); } } /* Check if smc_interact_CB was called and we shall generate a SAVE_SESSION_EVENT. */ if (emacs_event.kind != NO_EVENT) memcpy (bufp, &emacs_event, sizeof (struct input_event)); return emacs_event.kind != NO_EVENT ? 1 : 0; }
static void gsm_xsmp_client_disconnect (GsmXSMPClient *client) { if (client->priv->watch_id > 0) { g_source_remove (client->priv->watch_id); } if (client->priv->conn != NULL) { SmsCleanUp (client->priv->conn); } if (client->priv->ice_connection != NULL) { IceSetShutdownNegotiation (client->priv->ice_connection, FALSE); IceCloseConnection (client->priv->ice_connection); } }
static void _XtProcessIceMsgProc(XtPointer client_data, int *source, XtInputId *id) { IceConn ice_conn = (IceConn) client_data; IceProcessMessagesStatus status; status = IceProcessMessages (ice_conn, NULL, NULL); if (status == IceProcessMessagesIOError) { List *cl; int found = 0; if (verbose) { printf ("IO error on connection (fd = %d)\n", IceConnectionNumber (ice_conn)); printf ("\n"); } for (cl = ListFirst (RunningList); cl; cl = ListNext (cl)) { ClientRec *client = (ClientRec *) cl->thing; if (client->ice_conn == ice_conn) { CloseDownClient (client); found = 1; break; } } if (!found) { /* * The client must have disconnected before it was added * to the session manager's running list (i.e. before the * NewClientProc callback was invoked). */ IceSetShutdownNegotiation (ice_conn, False); IceCloseConnection (ice_conn); } } }
/* This is called when data is available on an ICE connection. */ static bool iceProcessMessages (IceConn connection) { SM_DEBUG (printf ("ICE connection process messages\n")); IceProcessMessagesStatus status = IceProcessMessages (connection, NULL, NULL); if (status == IceProcessMessagesIOError) { SM_DEBUG (printf ("ICE connection process messages" " - error => shutting down the connection\n")); IceSetShutdownNegotiation (connection, False); IceCloseConnection (connection); } return 1; }
void KSMServer::processData( int /*socket*/ ) { IceConn iceConn = ((KSMConnection*)sender())->iceConn; IceProcessMessagesStatus status = IceProcessMessages( iceConn, 0, 0 ); if ( status == IceProcessMessagesIOError ) { IceSetShutdownNegotiation( iceConn, False ); QList<KSMClient*>::iterator it = clients.begin(); QList<KSMClient*>::iterator const itEnd = clients.end(); while ( ( it != itEnd ) && *it && ( SmsGetIceConnection( ( *it )->connection() ) != iceConn ) ) ++it; if ( ( it != itEnd ) && *it ) { SmsConn smsConn = (*it)->connection(); deleteClient( *it ); SmsCleanUp( smsConn ); } (void) IceCloseConnection( iceConn ); } }
static gboolean ice_connection_accept (GIOChannel *channel, GIOCondition condition, gpointer watch_data) { IceConnectStatus cstatus; IceAcceptStatus astatus; IceListenObj ice_listener = (IceListenObj) watch_data; IceConn ice_conn; ice_conn = IceAcceptConnection (ice_listener, &astatus); if (astatus != IceAcceptSuccess) { g_warning ("Failed to accept ICE connection on listener %p", (gpointer) ice_listener); } else { /* Wait for the connection to leave pending state */ do { IceProcessMessages (ice_conn, NULL, NULL); } while ((cstatus = IceConnectionStatus (ice_conn)) == IceConnectPending); if (cstatus != IceConnectAccepted) { if (cstatus == IceConnectIOError) { g_warning ("I/O error opening ICE connection %p", (gpointer) ice_conn); } else { g_warning ("ICE connection %p rejected", (gpointer) ice_conn); } IceSetShutdownNegotiation (ice_conn, False); IceCloseConnection (ice_conn); } } return TRUE; }
void _XtProcessIceMsgProc ( XtPointer client_data, int *source, XtInputId *id) { IceConn ice_conn = (IceConn) client_data; IceProcessMessagesStatus status; #ifdef DEBUG printf ("_XtProcessIceMsgProc\n"); #endif /* DEBUG */ status = IceProcessMessages (ice_conn, NULL, NULL); if (status == IceProcessMessagesIOError) { ClientRecPtr pClientRec; int found = 0; #ifdef DEBUG printf ("IO error on connection (fd = %d)\n", IceConnectionNumber (ice_conn)); #endif /* DEBUG */ for (pClientRec = connectedList; pClientRec != NULL; pClientRec = pClientRec->next) { if (pClientRec->iceConn == ice_conn) { CloseDownClient (pClientRec); found = 1; break; } } if (!found) { IceSetShutdownNegotiation (ice_conn, False); IceCloseConnection (ice_conn); } } }
static void ice_process_messages(gpointer data, gint fd, PurpleInputCondition condition) { struct ice_connection_info *conninfo = (struct ice_connection_info*) data; IceProcessMessagesStatus status; /* please don't block... please! */ status = IceProcessMessages(conninfo->connection, NULL, NULL); if (status == IceProcessMessagesIOError) { purple_debug(PURPLE_DEBUG_INFO, "Session Management", "ICE IO error, closing connection... "); /* IO error, please disconnect */ IceSetShutdownNegotiation(conninfo->connection, False); IceCloseConnection(conninfo->connection); purple_debug(PURPLE_DEBUG_INFO, NULL, "done.\n"); /* cancel the handler */ purple_input_remove(conninfo->input_id); } }
void KSMServer::newConnection( int /*socket*/ ) { IceAcceptStatus status; IceConn iceConn = IceAcceptConnection( ((KSMListener*)sender())->listenObj, &status); if( iceConn == NULL ) return; IceSetShutdownNegotiation( iceConn, False ); IceConnectStatus cstatus; while ((cstatus = IceConnectionStatus (iceConn))==IceConnectPending) { (void) IceProcessMessages( iceConn, 0, 0 ); } if (cstatus != IceConnectAccepted) { if (cstatus == IceConnectIOError) kDebug( 1218 ) << "IO error opening ICE Connection!"; else kDebug( 1218 ) << "ICE Connection rejected!"; (void )IceCloseConnection (iceConn); return; } // don't leak the fd fcntl( IceConnectionNumber(iceConn), F_SETFD, FD_CLOEXEC ); }
int main(int argc, char *argv[]) { static XtAppContext appContext; IceConn iceConn; IceProtocolSetupStatus setupstat; char *vendor = NULL; char *release = NULL; pmGetProxyAddrMsg *pMsg; char *pData; int i; size_t len; IceReplyWaitInfo replyWait; GetProxyAddrReply reply; int majorVersion, minorVersion; Bool gotReply, ioErrorOccured; char errorString[255]; char *serviceName = NULL, *serverAddress = NULL; char *hostAddress = NULL, *startOptions = NULL; char *managerAddress = NULL; Bool haveAuth = 0; char authName[40]; char authData[128]; char *authDataBinary = NULL; int authLen = 0; for (i = 1; i < argc; i++) { if (argv[i][0] == '-') { switch (argv[i][1]) { case 'a': /* -auth */ haveAuth = 1; continue; case 'm': /* -manager */ if (++i >= argc) goto usage; managerAddress = (char *) XtNewString (argv[i]); continue; case 's': /* -server */ if (++i >= argc) goto usage; serverAddress = (char *) XtNewString (argv[i]); continue; case 'n': /* -name */ if (++i >= argc) goto usage; serviceName = XtNewString (argv[i]); continue; case 'h': /* -host */ if (++i >= argc) goto usage; hostAddress = XtNewString (argv[i]); continue; case 'o': /* -options */ if (++i >= argc) goto usage; startOptions = XtNewString (argv[i]); continue; case 'v': puts(PACKAGE_STRING); exit(0); } } usage: if (i >= argc) fprintf (stderr, "%s: %s requires an argument\n", argv[0], argv[i-1]); else fprintf (stderr, "%s: unrecognized argument '%s'\n", argv[0], argv[i]); usage(); } if (serviceName == NULL) { fprintf (stderr, "%s: -name serviceName must be specified\n", argv[0]); usage(); } if (serverAddress == NULL) { fprintf (stderr, "%s: -server serverAddr must be specified\n", argv[0]); usage(); } if (managerAddress == NULL) { managerAddress = getenv("PROXY_MANAGER"); if (managerAddress == NULL) { fprintf (stderr, "Error: -manager option must be specified when PROXY_MANAGER is not in the environment\n"); exit (1); } } /* * Register support for PROXY_MANAGEMENT. */ if ((PMopcode = IceRegisterForProtocolSetup ( PM_PROTOCOL_NAME, "XC", "1.0", PMversionCount, PMversions, 0, /* authcount */ NULL, /* authnames */ NULL, /* authprocs */ NULL /* IceIOErrorProc */ )) < 0) { fprintf (stderr, "Could not register PROXY_MANAGEMENT protocol with ICE"); exit (1); } appContext = XtCreateApplicationContext (); InitWatchProcs (appContext); if ((iceConn = IceOpenConnection ( managerAddress, NULL, 0, 0, 256, errorString)) == NULL) { fprintf (stderr, "Could not open ICE connection to proxy manager: %s", errorString); exit (1); } setupstat = IceProtocolSetup (iceConn, PMopcode, NULL, False /* mustAuthenticate */, &majorVersion, &minorVersion, &vendor, &release, 256, errorString); if (setupstat != IceProtocolSetupSuccess) { IceCloseConnection (iceConn); fprintf (stderr, "Could not initialize proxy management protocol: %s\n", errorString); exit (1); } /* * If auth data is supplied, read it from stdin. */ if (haveAuth) { fgets (authName, sizeof (authName), stdin); fgets (authData, sizeof (authData), stdin); for (i = 0; i < strlen (authName); i++) if (authName[i] == '\n') { authName[i] = '\0'; break; } for (i = 0; i < strlen (authData); i++) if (authData[i] == '\n') { authData[i] = '\0'; break; } /* * Convert the hex auth data to binary. */ authLen = cvthexkey (authData, &authDataBinary); if (authLen == -1) { fprintf (stderr, "Could not convert hex auth data to binary\n"); exit (1); } } /* * Now send the GetProxyAddr request. */ len = STRING_BYTES (serviceName) + STRING_BYTES (serverAddress) + STRING_BYTES (hostAddress) + STRING_BYTES (startOptions) + (authLen > 0 ? (STRING_BYTES (authName) + authLen) : 0); IceGetHeaderExtra (iceConn, PMopcode, PM_GetProxyAddr, SIZEOF (pmGetProxyAddrMsg), WORD64COUNT (len), pmGetProxyAddrMsg, pMsg, pData); pMsg->authLen = (CARD16) authLen; STORE_STRING (pData, serviceName); STORE_STRING (pData, serverAddress); STORE_STRING (pData, hostAddress); STORE_STRING (pData, startOptions); if (authLen > 0) { STORE_STRING (pData, authName); memcpy (pData, authDataBinary, authLen); } IceFlush (iceConn); replyWait.sequence_of_request = IceLastSentSequenceNumber (iceConn); replyWait.major_opcode_of_request = PMopcode; replyWait.minor_opcode_of_request = PM_GetProxyAddr; replyWait.reply = (IcePointer) &reply; gotReply = False; ioErrorOccured = False; while (!gotReply && !ioErrorOccured) { ioErrorOccured = (IceProcessMessages ( iceConn, &replyWait, &gotReply) == IceProcessMessagesIOError); if (ioErrorOccured) { fprintf (stderr, "IO error occured\n"); exit (1); } else if (gotReply) { if (reply.status == PM_Success) { fprintf (stdout, "%s\n", reply.addr); exit (0); } else { fprintf (stderr, "Error from proxy manager: %s\n", reply.error); exit (1); } } } /*NOTREACHED*/ exit(0); }
SmcConn SmcOpenConnection(char *networkIdsList, SmPointer context, int xsmpMajorRev, int xsmpMinorRev, unsigned long mask, SmcCallbacks *callbacks, char *previousId, char **clientIdRet, int errorLength, char *errorStringRet) { SmcConn smcConn; IceConn iceConn; char *ids; IceProtocolSetupStatus setupstat; int majorVersion; int minorVersion; char *vendor = NULL; char *release = NULL; smRegisterClientMsg *pMsg; char *pData; int extra, len; IceReplyWaitInfo replyWait; _SmcRegisterClientReply reply; Bool gotReply, ioErrorOccured; const char *auth_names[] = {"MIT-MAGIC-COOKIE-1"}; IcePoAuthProc auth_procs[] = {_IcePoMagicCookie1Proc}; int auth_count = 1; IcePoVersionRec versions[] = { {SmProtoMajor, SmProtoMinor, _SmcProcessMessage} }; int version_count = 1; *clientIdRet = NULL; if (errorStringRet && errorLength > 0) *errorStringRet = '\0'; if (!_SmcOpcode) { /* * For now, there is only one version of XSMP, so we don't * have to check {xsmpMajorRev, xsmpMinorRev}. In the future, * we will check against versions and generate the list * of versions the application actually supports. */ if ((_SmcOpcode = IceRegisterForProtocolSetup ("XSMP", SmVendorString, SmReleaseString, version_count, versions, auth_count, auth_names, auth_procs, NULL)) < 0) { if (errorStringRet && errorLength > 0) { strncpy (errorStringRet, "Could not register XSMP protocol with ICE", errorLength); errorStringRet[errorLength - 1] = '\0'; } return (NULL); } } if (networkIdsList == NULL || *networkIdsList == '\0') { if ((ids = (char *) getenv ("SESSION_MANAGER")) == NULL) { if (errorStringRet && errorLength > 0) { strncpy (errorStringRet, "SESSION_MANAGER environment variable not defined", errorLength); errorStringRet[errorLength - 1] = '\0'; } return (NULL); } } else { ids = networkIdsList; } if ((iceConn = IceOpenConnection ( ids, context, 0, _SmcOpcode, errorLength, errorStringRet)) == NULL) { return (NULL); } if ((smcConn = (SmcConn) malloc (sizeof (struct _SmcConn))) == NULL) { if (errorStringRet && errorLength > 0) { strncpy (errorStringRet, "Can't malloc", errorLength); errorStringRet[errorLength - 1] = '\0'; } IceCloseConnection (iceConn); return (NULL); } setupstat = IceProtocolSetup (iceConn, _SmcOpcode, (IcePointer) smcConn, False /* mustAuthenticate */, &majorVersion, &minorVersion, &vendor, &release, errorLength, errorStringRet); if (setupstat == IceProtocolSetupFailure || setupstat == IceProtocolSetupIOError) { IceCloseConnection (iceConn); free ((char *) smcConn); return (NULL); } else if (setupstat == IceProtocolAlreadyActive) { /* * This case should never happen, because when we called * IceOpenConnection, we required that the ICE connection * may not already have XSMP active on it. */ free ((char *) smcConn); if (errorStringRet && errorLength > 0) { strncpy (errorStringRet, "Internal error in IceOpenConnection", errorLength); errorStringRet[errorLength - 1] = '\0'; } return (NULL); } smcConn->iceConn = iceConn; smcConn->proto_major_version = majorVersion; smcConn->proto_minor_version = minorVersion; smcConn->vendor = vendor; smcConn->release = release; smcConn->client_id = NULL; bzero ((char *) &smcConn->callbacks, sizeof (SmcCallbacks)); set_callbacks (smcConn, mask, callbacks); smcConn->interact_waits = NULL; smcConn->phase2_wait = NULL; smcConn->prop_reply_waits = NULL; smcConn->save_yourself_in_progress = False; smcConn->shutdown_in_progress = False; /* * Now register the client */ if (!previousId) previousId = ""; len = strlen (previousId); extra = ARRAY8_BYTES (len); IceGetHeaderExtra (iceConn, _SmcOpcode, SM_RegisterClient, SIZEOF (smRegisterClientMsg), WORD64COUNT (extra), smRegisterClientMsg, pMsg, pData); STORE_ARRAY8 (pData, len, previousId); IceFlush (iceConn); replyWait.sequence_of_request = IceLastSentSequenceNumber (iceConn); replyWait.major_opcode_of_request = _SmcOpcode; replyWait.minor_opcode_of_request = SM_RegisterClient; replyWait.reply = (IcePointer) &reply; gotReply = False; ioErrorOccured = False; while (!gotReply && !ioErrorOccured) { ioErrorOccured = (IceProcessMessages ( iceConn, &replyWait, &gotReply) == IceProcessMessagesIOError); if (ioErrorOccured) { if (errorStringRet && errorLength > 0) { strncpy (errorStringRet, "IO error occured opening connection", errorLength); errorStringRet[errorLength - 1] = '\0'; } free (smcConn->vendor); free (smcConn->release); free ((char *) smcConn); return (NULL); } else if (gotReply) { if (reply.status == 1) { /* * The client successfully registered. */ *clientIdRet = reply.client_id; smcConn->client_id = (char *) malloc ( strlen (*clientIdRet) + 1); strcpy (smcConn->client_id, *clientIdRet); } else { /* * Could not register the client because the previous ID * was bad. So now we register the client with the * previous ID set to NULL. */ extra = ARRAY8_BYTES (0); IceGetHeaderExtra (iceConn, _SmcOpcode, SM_RegisterClient, SIZEOF (smRegisterClientMsg), WORD64COUNT (extra), smRegisterClientMsg, pMsg, pData); STORE_ARRAY8 (pData, 0, ""); IceFlush (iceConn); replyWait.sequence_of_request = IceLastSentSequenceNumber (iceConn); gotReply = False; } } } return (smcConn); }
SmcCloseStatus SmcCloseConnection(SmcConn smcConn, int count, char **reasonMsgs) { IceConn iceConn = smcConn->iceConn; smCloseConnectionMsg *pMsg; char *pData; int extra, i; IceCloseStatus closeStatus; SmcCloseStatus statusRet; extra = 8; for (i = 0; i < count; i++) extra += ARRAY8_BYTES (strlen (reasonMsgs[i])); IceGetHeaderExtra (iceConn, _SmcOpcode, SM_CloseConnection, SIZEOF (smCloseConnectionMsg), WORD64COUNT (extra), smCloseConnectionMsg, pMsg, pData); STORE_CARD32 (pData, count); pData += 4; for (i = 0; i < count; i++) STORE_ARRAY8 (pData, strlen (reasonMsgs[i]), reasonMsgs[i]); IceFlush (iceConn); IceProtocolShutdown (iceConn, _SmcOpcode); IceSetShutdownNegotiation (iceConn, False); closeStatus = IceCloseConnection (iceConn); if (smcConn->vendor) free (smcConn->vendor); if (smcConn->release) free (smcConn->release); if (smcConn->client_id) free (smcConn->client_id); if (smcConn->prop_reply_waits) { _SmcPropReplyWait *ptr = smcConn->prop_reply_waits; _SmcPropReplyWait *next; while (ptr) { next = ptr->next; free ((char *) ptr); ptr = next; } } free ((char *) smcConn); if (closeStatus == IceClosedNow) statusRet = SmcClosedNow; else if (closeStatus == IceClosedASAP) statusRet = SmcClosedASAP; else statusRet = SmcConnectionInUse; return (statusRet); }
static void ProcessNewPMConnection ( int * nfds, fd_set * rinit, struct config * config_info, IceListenObj ** listen_objects, int listen_fd) { IceConn new_ice_conn; IceAcceptStatus accept_status; int temp_sock_fd; IceListenObj * temp_obj; struct timeval time_val; struct timezone time_zone; struct sockaddr_in temp_sockaddr_in; struct sockaddr_in server_sockaddr_in; int retval; int addrlen = sizeof(temp_sockaddr_in); int rule_number; int pm_idx; /* * Only continue if there is room for another PM connection. */ for (pm_idx = 0; pm_idx < config_info->num_pm_conns; pm_idx++) { if (!pm_conn_array[pm_idx]) break; } if (pm_idx >= config_info->num_pm_conns) { (void) fprintf (stderr, "Maximum number of PM connections has been reached (%d)\n", config_info->num_pm_conns); /* * Must accept and then close this connection or the PM will * continue to poll. */ temp_obj = *listen_objects; new_ice_conn = IceAcceptConnection(temp_obj[listen_fd], &accept_status); if (new_ice_conn) IceCloseConnection(new_ice_conn); return; } /* * accept the connection if you can, use pm_listen_array * index to index into ICE listen_object list (this is because the * listen_objects list must correspond to the pm_listen_array) */ temp_obj = *listen_objects; new_ice_conn = IceAcceptConnection(temp_obj[listen_fd], &accept_status); if (!new_ice_conn) { static int been_here; /* * ICE initialization (bug?) makes this happen the * first time readables is hit. */ if (!been_here) been_here++; else (void) fprintf(stderr, "IceAcceptConnection failed (%d)\n", accept_status); return; } /* * extract the fd from this new connection; remember, the fd of * the listen socket is *not* the fd of the actual connection! */ temp_sock_fd = IceConnectionNumber(new_ice_conn); /* * before we get any further, do a config check on the new ICE * connection; start by using getpeername() to get endpoint info */ retval = getpeername(temp_sock_fd, (struct sockaddr*)&temp_sockaddr_in, (void *)&addrlen); if (retval) { IceCloseConnection(new_ice_conn); (void) fprintf(stderr, "getpeername call failed\n"); return; } assert(temp_sockaddr_in.sin_family == AF_INET); /* * Do a configuration check. NOTE: we're not doing anything * with the server_sockaddr_in argument */ if ((doConfigCheck(&temp_sockaddr_in, &server_sockaddr_in, config_info, PMGR, &rule_number)) == FAILURE) { /* * close the PM connection * */ (void) fprintf(stderr, "PM failed config check\n"); IceCloseConnection(new_ice_conn); return; } /* * you've started the connection process; allocate a buffer * for this connection, then continue processing other fd's without * blocking while waiting to read the coming PM data; [NOTE: * we use the fd of the connection socket as index into the * pm_conn_array; this saves us much troublesome linked-list * management!] */ if ((pm_conn_array[pm_idx] = malloc(sizeof(struct pm_conn_buf))) == NULL) { (void) fprintf (stderr, "malloc - PM connection object\n"); return; } /* * save the ICEconn struct for future status checks; also * the fd (although you could extract it from the ICEconn * each time you need it, but that's a pain) */ pm_conn_array[pm_idx]->fd = temp_sock_fd; pm_conn_array[pm_idx]->ice_conn = new_ice_conn; /* * Set the readables select() to listen for a readable on this * fd; remember, we're not interested in pm writables, since * all the negotiation is handled inside this routine; adjust * the nfds (must do that every time we get a new socket to * select() on), and then continue processing current selections */ FD_SET(temp_sock_fd, rinit); *nfds = max(*nfds, temp_sock_fd + 1); /* * this is where we initialize the current time and timeout on this * pm_connection object */ (void) gettimeofday(&time_val, &time_zone); pm_conn_array[pm_idx]->creation_time = time_val.tv_sec; pm_conn_array[pm_idx]->time_to_close = config_info->pm_data_timeout; }
void CloseDownClient(ClientRec *client) { int index_deleted = 0; if (verbose) { printf ("ICE Connection closed, IceConn fd = %d\n", IceConnectionNumber (client->ice_conn)); printf ("\n"); } SmsCleanUp (client->smsConn); IceSetShutdownNegotiation (client->ice_conn, False); IceCloseConnection (client->ice_conn); client->ice_conn = NULL; client->smsConn = NULL; if (!shutdownInProgress && client_info_visible) { for (index_deleted = 0; index_deleted < numClientListNames; index_deleted++) { if (clientListRecs[index_deleted] == client) break; } } ListSearchAndFreeOne (RunningList, (char *) client); if (saveInProgress) { Status delStatus = ListSearchAndFreeOne ( WaitForSaveDoneList, (char *) client); if (delStatus) { ListAddLast (FailedSaveList, (char *) client); client->freeAfterBadSavePopup = True; } ListSearchAndFreeOne (WaitForInteractList, (char *) client); ListSearchAndFreeOne (WaitForPhase2List, (char *) client); if (delStatus && ListCount (WaitForSaveDoneList) == 0) { if (ListCount (FailedSaveList) > 0 && !checkpoint_from_signal) PopupBadSave (); else FinishUpSave (); } else if (ListCount (WaitForInteractList) > 0 && OkToEnterInteractPhase ()) { LetClientInteract (ListFirst (WaitForInteractList)); } else if (!phase2InProgress && ListCount (WaitForPhase2List) > 0 && OkToEnterPhase2 ()) { StartPhase2 (); } } if (client->restartHint == SmRestartImmediately && !shutdownInProgress) { Clone (client, True /* use saved state */); ListAddLast (RestartImmedList, (char *) client); } else if (client->restartHint == SmRestartAnyway) { ListAddLast (RestartAnywayList, (char *) client); } else if (!client->freeAfterBadSavePopup) { FreeClient (client, True /* free props */); } if (shutdownInProgress) { if (ListCount (RunningList) == 0) EndSession (0); } else if (client_info_visible) { UpdateClientList (); if (current_client_selected == index_deleted) { if (current_client_selected == numClientListNames) current_client_selected--; if (current_client_selected >= 0) { XawListHighlight (clientListWidget, current_client_selected); ShowHint (clientListRecs[current_client_selected]); if (client_prop_visible) { DisplayProps (clientListRecs[current_client_selected]); } } } else { if (index_deleted < current_client_selected) current_client_selected--; XawListHighlight (clientListWidget, current_client_selected); } } }
static void ProcessPMInput ( int * nfds, fd_set * rinit, int pm_idx) { IceProcessMessagesStatus process_status; switch (IceConnectionStatus(pm_conn_array[pm_idx]->ice_conn)) { case IceConnectPending: /* * for some reason this connection still isn't ready for * reading, so return and try next readable */ (void) IceProcessMessages(pm_conn_array[pm_idx]->ice_conn, NULL, NULL); break; case IceConnectAccepted: /* * you're ready to read the PM data, allocate and send back * your client listen port, etc., etc.; do this inside * FWPprocessMessages() by calling IceProcessMessages() * [NOTE: The NULL args set it up for non-blocking] */ process_status = IceProcessMessages(pm_conn_array[pm_idx]->ice_conn, NULL, NULL); switch (process_status) { case IceProcessMessagesSuccess: /* * you read the server data, allocated a listen port * for the remote client and wrote it back to the PM, * so you don't need to do anything more until PM * closes the connection (NOTE: Make sure we don't * do this more than once!!) */ break; case IceProcessMessagesIOError: case IceProcessMessagesConnectionClosed: if (process_status == IceProcessMessagesIOError) /* * there was a problem with the connection, close * it explicitly */ IceCloseConnection(pm_conn_array[pm_idx]->ice_conn); else /* * the connection somehow closed itself, so don't call * IceCloseConnection */ ; /* * reset the select() readables mask and nfds, free * the buffer memory on this array element, reset the * pointer to NULL and return */ FD_CLR(pm_conn_array[pm_idx]->fd, rinit); *nfds = max(*nfds, pm_conn_array[pm_idx]->fd + 1); free(pm_conn_array[pm_idx]); pm_conn_array[pm_idx] = NULL; break; default: /* * Should never get here since all of the return * codes from IceProcessMessages have been checked. */ (void) fprintf (stderr, "IceProcessMessages error\n"); } break; case IceConnectRejected: /* * don't know yet what to do in this case, but for now simply * output diagnostic and return to select() processing */ (void) fprintf (stderr, "PM IceConnectRejected\n"); break; case IceConnectIOError: /* * don't know yet what to do in this case, but for now simply * output diagnostic and return to select() processing */ (void) fprintf (stderr, "PM IceConnectIOError\n"); break; default: /* * Should never get here since all of the return * codes from IceConnectionStatus have been checked. */ (void) fprintf (stderr, "IceConnectionStatus error\n"); } }
Bool dcop_call( const char * appId, const char * remApp, const char * remObjId, const char * remFun, const char * data, int dataLength, char ** replyType, char ** replyData, int * replyDataLength ) { IceReplyWaitInfo waitInfo; IceProcessMessagesStatus status; struct dcop_reply_struct replyStruct; char * pos = 0L; char * outputData = 0L; int outputDataLength = 0; int temp = 0; Bool success = False; Bool readyRet = False; struct DCOPMsg * pMsg; fprintf(stderr, "dcop_call() ...\n"); if (0 == dcop_ice_conn) { fprintf(stderr, "Try running dcop_register(), moron\n"); return False; } temp += strlen(appId); temp += strlen(remApp); temp += strlen(remObjId); temp += strlen(remFun); temp += dataLength; temp += 1024; /* Extra space for marshalling overhead */ outputData = (char *)malloc(temp); temp = 0; pos = outputData; pos = dcop_write_string(pos, appId); pos = dcop_write_string(pos, remApp); pos = dcop_write_string(pos, remObjId); pos = dcop_write_string(pos, remFun); pos = dcop_write_int(pos, dataLength); outputDataLength = pos - outputData; IceGetHeader( dcop_ice_conn, dcop_major_opcode, DCOPCall, sizeof(struct DCOPMsg), struct DCOPMsg, pMsg ); pMsg->length += outputDataLength + dataLength; IceSendData(dcop_ice_conn, outputDataLength, outputData); IceSendData(dcop_ice_conn, dataLength, (char *)data); IceFlush(dcop_ice_conn); free(outputData); outputData = NULL; if (IceConnectionStatus(dcop_ice_conn) != IceConnectAccepted) { fprintf(stderr, "dcop_call(): Connection not accepted\n"); return False; } waitInfo.sequence_of_request = IceLastSentSequenceNumber(dcop_ice_conn); waitInfo.major_opcode_of_request = dcop_major_opcode; waitInfo.minor_opcode_of_request = DCOPCall; replyStruct.status = DCOP_REPLY_PENDING; replyStruct.replyId = dcop_reply_id++; replyStruct.replyType = replyType; replyStruct.replyData = replyData; replyStruct.replyDataLength = replyDataLength; waitInfo.reply = (IcePointer)(&replyStruct); readyRet = False; do { fprintf(stderr, "dcop_call(): Doing IceProcessMessages\n"); status = IceProcessMessages(dcop_ice_conn, &waitInfo, &readyRet); if (status == IceProcessMessagesIOError) { fprintf(stderr, "dcop_call(): IceProcessMessagesIOError\n"); IceCloseConnection(dcop_ice_conn); return False; } fprintf(stderr, "dcop_call(): readyRet == %s\n", readyRet ? "True" : "False"); } while (!readyRet); fprintf(stderr, "dcop_call(): Finished\n"); return (replyStruct.status == DCOP_REPLY_OK) ? True : False; }