Ejemplo n.º 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;
}
Ejemplo n.º 2
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);
    }
}
Ejemplo n.º 3
0
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 );
}
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);
        }
}
Ejemplo n.º 5
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)
    {
	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);
	}
    }
}
Ejemplo n.º 6
0
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 );
    }
}
Ejemplo n.º 7
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;
}
Ejemplo n.º 8
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;
}
Ejemplo n.º 9
0
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);
	}
    }
}
Ejemplo n.º 10
0
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);
	}
}
Ejemplo n.º 11
0
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 );
}
Ejemplo n.º 12
0
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);
}
Ejemplo n.º 13
0
Archivo: xsm.c Proyecto: aosm/X11
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);
	}
    }
}
Ejemplo n.º 14
0
  Bool
dcop_connect()
{
  size_t      bytesRead     = 0;
  IcePointer  context       = 0;
  FILE *      f             = 0L;
  char      * newline       = 0L;
  char      * homeDir       = 0L;
  char      * display       = 0L;
  char      * dcopServer    = 0L;
  char        errBuf[BUFFER_SIZE];
  char        fileName[BUFFER_SIZE];
  char        hostName[BUFFER_SIZE];
  char        displayName[BUFFER_SIZE];
  char      * i;

  homeDir = getenv("HOME");

  if (NULL == homeDir)
    return False;

  display = getenv("DISPLAY");
  
  if (NULL == display)
    display = "NODISPLAY";

  strncpy(displayName, display, sizeof(displayName));
  displayName[sizeof(displayName) - 1] = 0;

  if((i = strrchr(displayName, '.')) > strrchr(displayName, ':') && i)
      *i = '\0';

  while((i = strchr(displayName, ':')) != NULL)
     *i = '_';

  dcopServer = getenv("DCOPSERVER");

  if (NULL == dcopServer) {

    if (-1 == chdir(homeDir)) {
      fprintf(stderr, "Cannot cd ~\n");
      return False;
    }

    hostName[0] = '\0';
    if (getenv("XAUTHLOCALHOSTNAME"))
            strlcpy(hostName, getenv("XAUTHLOCALHOSTNAME"),sizeof(hostName)-1);
    else if (gethostname(hostName, sizeof(hostName)))
	    strcpy(hostName, "localhost");
    else
	    hostName[sizeof(hostName)-1] = '\0';

    snprintf(fileName, sizeof(fileName), ".DCOPserver_%s_%s", hostName, displayName);
    f = fopen(fileName, "r");

    if (NULL == f) {
      fprintf(stderr, "Cannot open ~/%s\n", fileName);
      return False;
    }

    dcopServer = (char *)malloc(BUFFER_SIZE);

    bytesRead = fread((void *)dcopServer, sizeof(char), BUFFER_SIZE, f);
    dcopServer[BUFFER_SIZE - 1] = 0;

    if (0 == bytesRead)
      return False;

    newline = strchr(dcopServer, '\n');

    if (NULL == newline) {
      fprintf(stderr, "dcop server file format invalid\n");
      return False;
    }

    *newline = '\0';
  }

  dcop_ice_conn =
    IceOpenConnection(
      dcopServer,
      context,
      False,
      dcop_major_opcode,
      sizeof(errBuf),
      errBuf
    );

  if (NULL != dcopServer)
    free(dcopServer);

  if (0 == dcop_ice_conn) {
    fprintf(stderr, "dcop_ice_conn is 0 :(\n");
    return False;
  }

  IceSetShutdownNegotiation(dcop_ice_conn, False);

  return True;
}