コード例 #1
0
/* 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;
}
コード例 #2
0
ファイル: xsmfns.c プロジェクト: timmartin/remacs
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);
}
コード例 #3
0
static gboolean
process_ice_messages(IceConn connection)
{
  IceProcessMessagesStatus status;

  status = IceProcessMessages(connection, nullptr, nullptr);

  switch (status) {
  case IceProcessMessagesSuccess:
    return TRUE;

  case IceProcessMessagesIOError: {
      nsNativeAppSupportUnix *native =
        static_cast<nsNativeAppSupportUnix *>(IceGetConnectionContext(connection));
      native->DisconnectFromSM();
    }
    return FALSE;

  case IceProcessMessagesConnectionClosed:
    return FALSE;

  default:
    g_assert_not_reached ();
  }
}
コード例 #4
0
ファイル: kworkspace.cpp プロジェクト: KDE/kde-workspace
void KRequestShutdownHelper::processData()
    {
#if HAVE_X11
    if( conn != NULL )
        IceProcessMessages( SmcGetIceConnection( conn ), 0, 0 );
#endif    
    }
コード例 #5
0
ファイル: session.c プロジェクト: JonahAragon/consortium
/* 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; close our connection to the
       * session manager, this will result in the ICE connection
       * being cleaned up, since it is owned by libSM.
       */
      disconnect ();
      meta_quit (META_EXIT_SUCCESS);

      return FALSE;
    }
  
  return TRUE;
}
コード例 #6
0
ファイル: sm_session.c プロジェクト: raboof/notion
static void sm_process_messages(int UNUSED(fd), void *UNUSED(data))
{
    Bool ret;

    if(IceProcessMessages(ice_sm_conn, NULL, &ret)==IceProcessMessagesIOError){
        mod_sm_close();
    }
}
コード例 #7
0
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);
    }
}
コード例 #8
0
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)
    {
	fprintf (stderr, "IO error occured\n");
	exit (1);
    }
}
コード例 #9
0
ファイル: xsmfns.c プロジェクト: zc00gii/emacs
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;
}
コード例 #10
0
ファイル: session.c プロジェクト: iperry/roxterm
static gboolean ioc_watch_callback(GIOChannel *source,
                                   GIOCondition cond, gpointer handle)
{
    SessionData *sd = handle;
    (void) source;
    (void) cond;

    if (IceProcessMessages(sd->ice_conn, NULL, NULL) ==
            IceProcessMessagesIOError)
    {
        g_warning(_("Error processing ICE (session management) messages"));
        SmcCloseConnection(sd->smc_conn, 0, NULL);
        sd->tag = 0;
        return FALSE;
    }
    return TRUE;
}
コード例 #11
0
ファイル: xtwatch.c プロジェクト: Bluerise/bitrig-xenocara
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);
	}
    }
}
コード例 #12
0
/* 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;
}
コード例 #13
0
ファイル: server.cpp プロジェクト: aarontc/kde-workspace
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 );
    }
}
コード例 #14
0
ファイル: session.c プロジェクト: Limsik/e17
static void
ice_msgs_process(void)
{
   IceProcessMessagesStatus status;

   status = IceProcessMessages(ice_conn, NULL, NULL);
   if (status == IceProcessMessagesIOError)
     {
	/* Less of the hope.... E survives */
	Alert(_("ERROR!\n" "\n"
		"Lost the Session Manager that was there?\n"
		"Here here session manager... come here... want a bone?\n"
		"Oh come now! Stop sulking! Bugger. Oh well. "
		"Will continue without\n" "a session manager.\n" "\n"
		"I'll survive somehow.\n" "\n" "\n" "... I hope.\n"));
	ice_exit();
     }
}
コード例 #15
0
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;
}
コード例 #16
0
ファイル: SmWatch.c プロジェクト: juddy/edcde
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);
	}
    }
}
コード例 #17
0
ファイル: gtksession.c プロジェクト: Draghtnod/pidgin
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);
	}
}
コード例 #18
0
static gboolean
ice_process_messages (GIOChannel  *channel,
                      GIOCondition condition,
                      gpointer     user_data)
{
  IceProcessMessagesStatus status;
  XfsmIceConnData         *icdata = user_data;

  status = IceProcessMessages (icdata->ice_conn, NULL, NULL);

  if (status == IceProcessMessagesIOError)
    {
      xfsm_manager_close_connection_by_ice_conn (icdata->manager,
                                                 icdata->ice_conn);

      /* remove the I/O watch */
      return FALSE;
    }

  /* keep the I/O watch running */
  return TRUE;
}
コード例 #19
0
static gboolean
client_iochannel_watch (GIOChannel    *channel,
                        GIOCondition   condition,
                        GsmXSMPClient *client)
{
        gboolean keep_going;

        g_object_ref (client);
        switch (IceProcessMessages (client->priv->ice_connection, NULL, NULL)) {
        case IceProcessMessagesSuccess:
                keep_going = TRUE;
                break;

        case IceProcessMessagesIOError:
                g_debug ("GsmXSMPClient: IceProcessMessagesIOError on '%s'", client->priv->description);
                gsm_client_set_status (GSM_CLIENT (client), GSM_CLIENT_FAILED);
                /* Emitting "disconnected" will eventually cause
                 * IceCloseConnection() to be called.
                 */
                gsm_client_disconnected (GSM_CLIENT (client));
                keep_going = FALSE;
                break;

        case IceProcessMessagesConnectionClosed:
                g_debug ("GsmXSMPClient: IceProcessMessagesConnectionClosed on '%s'",
                         client->priv->description);
                client->priv->ice_connection = NULL;
                keep_going = FALSE;
                break;

        default:
                g_assert_not_reached ();
        }
        g_object_unref (client);

        return keep_going;
}
コード例 #20
0
ファイル: server.cpp プロジェクト: aarontc/kde-workspace
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 );
}
コード例 #21
0
ファイル: protosetup.c プロジェクト: SvenDowideit/clearlinux
IceProtocolSetupStatus
IceProtocolSetup (
	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 = 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 = 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 occured 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 (iceConn->protosetup_to_you->my_auth_indices);
	    free (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);
    }
}
コード例 #22
0
ファイル: sm_client.c プロジェクト: aosm/X11libs
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);
}
コード例 #23
0
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");
      }
}
コード例 #24
0
ファイル: dcopc.c プロジェクト: Fat-Zer/tdelibs
  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;
}
コード例 #25
0
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);
}