Ejemplo n.º 1
0
/*
 * get_channel_for_incoming_message:
 * @self: a factory
 * @jid: a contact's JID
 * @create_if_missing: if %TRUE, a new channel will be created if there is no
 *                     existing channel to @jid
 *
 * Retrieves a 1-1 text channel to a particular contact. If no channel is open
 * to @jid, it will be created only if @create_if_missing is %TRUE. If @jid is
 * not of the form 'user@domain' (optionally with a resource), no channel will
 * be opened.
 *
 * Returns: an IM channel to @jid, or %NULL
 */
static GabbleIMChannel *
get_channel_for_incoming_message (
    GabbleImFactory *self,
    const gchar *jid,
    gboolean create_if_missing)
{
  GabbleImFactoryPrivate *priv = self->priv;
  TpBaseConnection *conn = (TpBaseConnection *) priv->conn;
  TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (conn,
      TP_HANDLE_TYPE_CONTACT);
  TpHandle handle;
  GabbleIMChannel *chan;

  g_return_val_if_fail (jid != NULL, NULL);

  handle = tp_handle_ensure (contact_repo, jid, NULL, NULL);
  if (handle == 0)
    return NULL;

  chan = g_hash_table_lookup (priv->channels, GUINT_TO_POINTER (handle));
  if (chan != NULL)
    return chan;
  else if (create_if_missing)
    return new_im_channel (self, handle, NULL);
  else
    return NULL;
}
Ejemplo n.º 2
0
static void
location_pep_node_changed (WockyPepService *pep,
    WockyBareContact *contact,
    WockyStanza *stanza,
    GabbleConnection *conn)
{
  TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
      (TpBaseConnection *) conn, TP_HANDLE_TYPE_CONTACT);
  TpBaseConnection *base = (TpBaseConnection *) conn;
  TpHandle handle;
  const gchar *jid;

  jid = wocky_bare_contact_get_jid (contact);
  handle = tp_handle_ensure (contact_repo, jid, NULL, NULL);
  if (handle == 0)
    {
      DEBUG ("Invalid from: %s", jid);
      return;
    }

  if (handle == base->self_handle)
    /* Ignore echoed pubsub notifications */
    goto out;

  update_location_from_msg (conn, handle, stanza);

out:
  tp_handle_unref (contact_repo, handle);
}
Ejemplo n.º 3
0
static RingTextChannel *
get_text_channel(RingTextManager *self,
  char const *address,
  gboolean class0,
  gboolean self_invoked)
{
  TpHandleRepoIface *repo;
  RingTextChannel *channel = NULL;
  TpHandle handle, initiator;
  GError *error = NULL;

  g_return_val_if_fail (address != NULL, NULL);

  repo = tp_base_connection_get_handles(
    (TpBaseConnection *)self->priv->connection, TP_HANDLE_TYPE_CONTACT);

  error = NULL;
  handle = tp_handle_ensure(repo, address,
           ring_network_normalization_context(), &error);
  if (handle == 0) {
    DEBUG("tp_handle_ensure: %s: %s (%d@%s)", address, GERROR_MSG_CODE(error));
    g_clear_error(&error);
    /* Xyzzy */
    return NULL;
  }

  initiator = self_invoked ? self->priv->connection->parent.self_handle : handle;

  channel = ring_text_manager_request(self, NULL, initiator, handle, 0, class0);

  if (channel == NULL)
    tp_handle_unref(repo, handle);

  return channel;
}
Ejemplo n.º 4
0
gchar *
tp_tests_simple_connection_ensure_text_chan (TpTestsSimpleConnection *self,
    const gchar *target_id,
    GHashTable **props)
{
  TpTestsTextChannelNull *chan;
  gchar *chan_path;
  TpHandleRepoIface *contact_repo;
  TpHandle handle;
  static guint count = 0;
  TpBaseConnection *base_conn = (TpBaseConnection *) self;

  /* Get contact handle */
  contact_repo = tp_base_connection_get_handles (base_conn,
      TP_HANDLE_TYPE_CONTACT);
  g_assert (contact_repo != NULL);

  handle = tp_handle_ensure (contact_repo, target_id, NULL, NULL);

  chan = g_hash_table_lookup (self->priv->channels, GUINT_TO_POINTER (handle));
  if (chan != NULL)
    {
      /* Channel already exist, reuse it */
      g_object_get (chan, "object-path", &chan_path, NULL);
    }
  else
    {
      chan_path = g_strdup_printf ("%s/Channel%u", base_conn->object_path,
          count++);

       chan = TP_TESTS_TEXT_CHANNEL_NULL (
          tp_tests_object_new_static_class (
            TP_TESTS_TYPE_TEXT_CHANNEL_NULL,
            "connection", self,
            "object-path", chan_path,
            "handle", handle,
            NULL));

      g_hash_table_insert (self->priv->channels, GUINT_TO_POINTER (handle),
          chan);
    }

  tp_handle_unref (contact_repo, handle);

  if (props != NULL)
    *props = tp_tests_text_channel_get_props (chan);

  return chan_path;
}
Ejemplo n.º 5
0
void
tp_tests_simple_connection_set_identifier (TpTestsSimpleConnection *self,
                                  const gchar *identifier)
{
  TpBaseConnection *conn = (TpBaseConnection *) self;
  TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (conn,
      TP_HANDLE_TYPE_CONTACT);
  TpHandle handle = tp_handle_ensure (contact_repo, identifier, NULL, NULL);

  /* if this fails then the identifier was bad - caller error */
  g_return_if_fail (handle != 0);

  tp_base_connection_set_self_handle (conn, handle);
  tp_handle_unref (contact_repo, handle);
}
Ejemplo n.º 6
0
TpHandle
gabble_ensure_handle_from_uri (TpHandleRepoIface *repo,
    const gchar *uri,
    GError **error)
{
  TpHandle handle;

  gchar *jid = gabble_uri_to_jid (uri, error);

  if (jid == NULL)
    return 0;

  handle = tp_handle_ensure (repo, jid, NULL, error);

  g_free (jid);

  return handle;
}
Ejemplo n.º 7
0
TpHandle
gabble_ensure_handle_from_vcard_address (TpHandleRepoIface *repo,
    const gchar *vcard_field,
    const gchar *vcard_address,
    GError **error)
{
  gchar *normalized_jid;
  TpHandle handle;

  normalized_jid = gabble_vcard_address_to_jid (vcard_field, vcard_address, error);
  if (normalized_jid == NULL)
    return 0;

  handle = tp_handle_ensure (repo, normalized_jid, NULL, error);

  g_free (normalized_jid);

  return handle;
}
Ejemplo n.º 8
0
static gboolean
pretend_connected (gpointer data)
{
  TpTestsSimpleConnection *self = TP_TESTS_SIMPLE_CONNECTION (data);
  TpBaseConnection *conn = (TpBaseConnection *) self;
  TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (conn,
      TP_HANDLE_TYPE_CONTACT);

  conn->self_handle = tp_handle_ensure (contact_repo, self->priv->account,
      NULL, NULL);

  if (conn->status == TP_CONNECTION_STATUS_CONNECTING)
    {
      tp_base_connection_change_status (conn, TP_CONNECTION_STATUS_CONNECTED,
          TP_CONNECTION_STATUS_REASON_REQUESTED);
    }

  self->priv->connect_source = 0;
  return FALSE;
}
Ejemplo n.º 9
0
static gboolean
simulate_incoming_call_cb (gpointer p)
{
  ExampleCallManager *self = p;
  TpHandleRepoIface *contact_repo;
  TpHandle caller;

  /* do nothing if we've been disconnected while waiting for the contact to
   * call us */
  if (self->priv->available_id == 0)
    return FALSE;

  /* We're called by someone whose ID on the IM service is "caller" */
  contact_repo = tp_base_connection_get_handles (self->priv->conn,
      TP_HANDLE_TYPE_CONTACT);
  caller = tp_handle_ensure (contact_repo, "caller", NULL, NULL);

  new_channel (self, caller, caller, NULL, TRUE, FALSE);

  return FALSE;
}
Ejemplo n.º 10
0
static gboolean
start_connecting (TpBaseConnection *conn,
                  GError **error)
{
  ExampleContactListConnection *self = EXAMPLE_CONTACT_LIST_CONNECTION (conn);
  TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (conn,
      TP_HANDLE_TYPE_CONTACT);

  /* In a real connection manager we'd ask the underlying implementation to
   * start connecting, then go to state CONNECTED when finished, but here
   * we can do it immediately. */

  conn->self_handle = tp_handle_ensure (contact_repo, self->priv->account,
      NULL, error);

  if (conn->self_handle == 0)
    return FALSE;

  tp_base_connection_change_status (conn, TP_CONNECTION_STATUS_CONNECTED,
      TP_CONNECTION_STATUS_REASON_REQUESTED);

  return TRUE;
}
Ejemplo n.º 11
0
static void
on_modem_call_incoming(ModemCallService *call_service,
  ModemCall *modem_call,
  char const *originator,
  RingMediaManager *self)
{
  RingMediaManagerPrivate *priv = self->priv;
  TpHandleRepoIface *repo;
  RingCallChannel *channel;
  TpHandle handle;
  GError *error = NULL;

  if (!ring_media_manager_is_connected (self))
    return;

  channel = modem_call_get_handler(modem_call);
  if (channel) {
    modem_call_set_handler(modem_call, NULL);
    ring_critical("Call instance %s already associated with channel.",
      modem_call_get_name(modem_call));
    ring_critical("Closing old channel %s.", RING_MEDIA_CHANNEL(channel)->nick);
    ring_media_channel_close(RING_MEDIA_CHANNEL(channel));
  }

  repo = tp_base_connection_get_handles(
    (TpBaseConnection *)(self->priv->connection), TP_HANDLE_TYPE_CONTACT);
  error = NULL;
  handle = tp_handle_ensure(repo, originator,
           ring_network_normalization_context(), &error);

  if (handle == 0) {
    DEBUG("tp_handle_ensure:" GERROR_MSG_FMT, GERROR_MSG_CODE(error));
    if (error) g_error_free(error);
    /* Xyzzy - modem_call_request_release() ?? */
    return;
  }

  /* Incoming call - pass call and handle ownership to new media channel */
  char *object_path = ring_media_manager_new_object_path(self, "incoming");

  channel = (RingCallChannel *)
    g_object_new(RING_TYPE_CALL_CHANNEL,
      "connection", priv->connection,
      "tones", priv->tones,
      "object-path", object_path,
      "initiator-handle", handle,
      "handle-type", TP_HANDLE_TYPE_CONTACT,
      "handle", handle,
      "peer", handle,
      "requested", FALSE,
      "initial-audio", TRUE,
      "anon-modes", priv->anon_modes,
      "call-instance", modem_call,
      "terminating", TRUE,
      NULL);

  g_free(object_path);

  ring_media_manager_emit_new_channel(self, NULL, channel, NULL);
  ring_media_channel_set_state(RING_MEDIA_CHANNEL(channel),
    MODEM_CALL_STATE_INCOMING, 0, 0);
}
Ejemplo n.º 12
0
static void
on_modem_call_created(ModemCallService *call_service,
  ModemCall *modem_call,
  char const *destination,
  RingMediaManager *self)
{
  RingMediaManagerPrivate *priv = self->priv;
  TpHandleRepoIface *repo;
  RingCallChannel *channel;
  TpHandle handle;
  char const *sos;
  GError *error = NULL;

  if (!ring_media_manager_is_connected (self))
    return;

  channel = modem_call_get_handler(modem_call);
  if (channel)
    return; /* Call created by ring, nothing to do */

  /* This is a call created outside ring, create a channel for it */
  DEBUG("Freshly created call instance %s not associated with channel.",
    modem_call_get_name(modem_call));

  repo = tp_base_connection_get_handles(
    (TpBaseConnection *)(self->priv->connection), TP_HANDLE_TYPE_CONTACT);
  error = NULL;
  handle = tp_handle_ensure(repo, destination,
           ring_network_normalization_context(), &error);

  if (handle == 0) {
    ring_warning("tp_handle_ensure:" GERROR_MSG_FMT, GERROR_MSG_CODE(error));
    if (error) g_error_free(error);
    /* Xyzzy - modem_call_request_release() ?? */
    return;
  }

  sos = modem_call_get_emergency_service(priv->call_service, destination);

  char *object_path = ring_media_manager_new_object_path(self, "created");

  channel = (RingCallChannel *)
    g_object_new(RING_TYPE_CALL_CHANNEL,
      "connection", priv->connection,
      "tones", priv->tones,
      "object-path", object_path,
      "initiator-handle", tp_base_connection_get_self_handle(
        TP_BASE_CONNECTION(priv->connection)),
      "handle-type", TP_HANDLE_TYPE_CONTACT,
      "handle", handle,
      "peer", handle,
      "requested", TRUE,
      "initial-remote", handle,
      "initial-audio", TRUE,
      "anon-modes", priv->anon_modes,
      "call-instance", modem_call,
      "originating", TRUE,
      sos ? "initial-emergency-service" : NULL, sos,
      NULL);

  g_free(object_path);

  ring_media_manager_emit_new_channel(self, NULL, channel, NULL);
  ring_media_channel_set_state(RING_MEDIA_CHANNEL(channel),
    MODEM_CALL_STATE_DIALING, 0, 0);
}
static gboolean _parse_atom(IdleParser *parser, GValueArray *arr, char atom, const gchar *token, TpHandleSet *contact_reffed, TpHandleSet *room_reffed) {
	IdleParserPrivate *priv = IDLE_PARSER_GET_PRIVATE(parser);
	TpHandle handle;
	GValue val = {0};
	TpHandleRepoIface *contact_repo = tp_base_connection_get_handles(TP_BASE_CONNECTION(priv->conn), TP_HANDLE_TYPE_CONTACT);
	TpHandleRepoIface *room_repo = tp_base_connection_get_handles(TP_BASE_CONNECTION(priv->conn), TP_HANDLE_TYPE_ROOM);

	if (token[0] == ':')
		token++;

	IDLE_DEBUG("parsing atom \"%s\" as %c", token, atom);

	switch (atom) {
		case 'I':
			IDLE_DEBUG("ignored token");
			return TRUE;
			break;

		case 'c':
		case 'r':
		case 'C': {
			gchar *id, *bang = NULL;
			gchar modechar = '\0';

			if (idle_muc_channel_is_modechar(token[0])) {
				modechar = token[0];
				token++;
			}

			id = g_strdup(token);

			if (atom != 'r') {
				bang = strchr(id, '!');
				if (bang)
					*bang = '\0';
			}

			if (atom == 'r') {
				if ((handle = tp_handle_ensure(room_repo, id, NULL, NULL))) {
					tp_handle_set_add(room_reffed, handle);
				}
			} else {
				if ((handle = tp_handle_ensure(contact_repo, id, NULL, NULL))) {
					tp_handle_set_add(contact_reffed, handle);

					idle_connection_canon_nick_receive(priv->conn, handle, id);
				}
			}

			g_free(id);

			if (!handle)
				return FALSE;

			g_value_init(&val, G_TYPE_UINT);
			g_value_set_uint(&val, handle);
			g_value_array_append(arr, &val);
			g_value_unset(&val);

			IDLE_DEBUG("set handle %u", handle);

			if (atom == 'C') {
				g_value_init(&val, G_TYPE_CHAR);
				g_value_set_schar(&val, modechar);
				g_value_array_append(arr, &val);
				g_value_unset(&val);

				IDLE_DEBUG("set modechar %c", modechar);
			}

			return TRUE;
		}
		break;

		case 'd': {
			guint dval;

			if (sscanf(token, "%d", &dval)) {
				g_value_init(&val, G_TYPE_UINT);
				g_value_set_uint(&val, dval);
				g_value_array_append(arr, &val);
				g_value_unset(&val);

				IDLE_DEBUG("set int %d", dval);

				return TRUE;
			} else {
				return FALSE;
			}
		}
		break;

		case 's':
			g_value_init(&val, G_TYPE_STRING);
			g_value_set_string(&val, token);
			g_value_array_append(arr, &val);
			g_value_unset(&val);
			IDLE_DEBUG("set string \"%s\"", token);

			return TRUE;
			break;

		default:
			IDLE_DEBUG("unknown atom %c", atom);
			return FALSE;
			break;
	}
}