예제 #1
0
void
gabble_jingle_content_produce_node (GabbleJingleContent *c,
    WockyNode *parent,
    gboolean include_description,
    gboolean include_transport,
    WockyNode **trans_node_out)
{
  GabbleJingleContentPrivate *priv = c->priv;
  WockyNode *content_node, *trans_node;
  JingleDialect dialect = gabble_jingle_session_get_dialect (c->session);
  void (*produce_desc)(GabbleJingleContent *, WockyNode *) =
    GABBLE_JINGLE_CONTENT_GET_CLASS (c)->produce_description;

  if ((dialect == JINGLE_DIALECT_GTALK3) ||
      (dialect == JINGLE_DIALECT_GTALK4))
    {
      content_node = parent;
    }
  else
    {
      content_node = wocky_node_add_child_with_content (parent, "content", NULL);
      wocky_node_set_attributes (content_node,
          "name", priv->name,
          "senders", produce_senders (priv->senders),
          NULL);

      if (gabble_jingle_content_creator_is_initiator (c))
        wocky_node_set_attribute (content_node, "creator", "initiator");
      else
        wocky_node_set_attribute (content_node, "creator", "responder");
    }

  if (include_description)
    produce_desc (c, content_node);

  if (include_transport)
    {
      if (dialect == JINGLE_DIALECT_GTALK3)
        {
          /* GTalk 03 doesn't use a transport, but assumes gtalk-p2p */
          trans_node = parent;
        }
      else
        {
          trans_node = wocky_node_add_child_with_content (content_node, "transport", NULL);
          trans_node->ns = g_quark_from_string (priv->transport_ns);
        }

      if (trans_node_out != NULL)
        *trans_node_out = trans_node;
    }
}
예제 #2
0
guint
gabble_jingle_content_create_share_channel (GabbleJingleContent *self,
    const gchar *name)
{
  GabbleJingleContentPrivate *priv = self->priv;
  WockyNode *sess_node, *channel_node;
  WockyStanza *msg = NULL;

  /* Send the info action before creating the channel, in case candidates need
     to be sent on the signal emit. It doesn't matter if the channel already
     exists anyways... */
  msg = gabble_jingle_session_new_message (self->session,
      JINGLE_ACTION_INFO, &sess_node);

  DEBUG ("Sending 'info' message to peer : channel %s", name);
  channel_node = wocky_node_add_child_with_content (sess_node, "channel", NULL);
  channel_node->ns = g_quark_from_string (priv->content_ns);
  wocky_node_set_attribute (channel_node, "name", name);

  gabble_jingle_session_send (self->session, msg);

  return new_share_channel (self, name);
}
static void
transmit_candidates (GabbleJingleTransportGoogle *transport,
    const gchar *name,
    GList *candidates)
{
  GabbleJingleTransportGooglePrivate *priv = transport->priv;
  GList *li;
  WockyStanza *msg;
  WockyNode *trans_node, *sess_node;

  if (candidates == NULL)
    return;

  msg = gabble_jingle_session_new_message (priv->content->session,
    JINGLE_ACTION_TRANSPORT_INFO, &sess_node);

  gabble_jingle_content_produce_node (priv->content, sess_node, FALSE, TRUE,
      &trans_node);

  for (li = candidates; li; li = li->next)
    {
      JingleCandidate *c = (JingleCandidate *) li->data;
      gchar port_str[16], pref_str[16], comp_str[16], *type_str, *proto_str;
      WockyNode *cnode;

      sprintf (port_str, "%d", c->port);
      sprintf (pref_str, "%lf", c->preference / 65536.0);
      sprintf (comp_str, "%d", c->component);

      switch (c->type) {
        case JINGLE_CANDIDATE_TYPE_LOCAL:
          type_str = "local";
          break;
        case JINGLE_CANDIDATE_TYPE_STUN:
          type_str = "stun";
          break;
        case JINGLE_CANDIDATE_TYPE_RELAY:
          type_str = "relay";
          break;
        default:
          g_assert_not_reached ();
      }

      switch (c->protocol) {
        case JINGLE_TRANSPORT_PROTOCOL_UDP:
          proto_str = "udp";
          break;
        case JINGLE_TRANSPORT_PROTOCOL_TCP:
          if ((c->port == 443) && (c->type == JINGLE_CANDIDATE_TYPE_RELAY))
            proto_str = "ssltcp";
          else
            proto_str = "tcp";
          break;
        default:
          g_assert_not_reached ();
      }

      cnode = wocky_node_add_child_with_content (trans_node, "candidate", NULL);
      wocky_node_set_attributes (cnode,
          "address", c->address,
          "port", port_str,
          "username", c->username,
          "password", c->password != NULL ? c->password : "",
          "preference", pref_str,
          "protocol", proto_str,
          "type", type_str,
          "component", comp_str,
          "network", "0",
          "generation", "0",
          NULL);

      wocky_node_set_attribute (cnode, "name", name);
    }

  wocky_porter_send_iq_async (
      gabble_jingle_session_get_porter (priv->content->session), msg,
      NULL, NULL, NULL);
  g_object_unref (msg);
}
예제 #4
0
static gboolean
add_to_geoloc_node (const gchar *tp_name,
    GValue *value,
    WockyNode *geoloc,
    GError **err)
{
  LocationMapping *mapping;
  gchar *str = NULL;

  /* Map "language" to the xml:lang attribute. */
  if (!tp_strdiff (tp_name, "language"))
    {
      if (G_VALUE_TYPE (value) != G_TYPE_STRING)
        {
          g_set_error (err, TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
              "expecting string for language value, but got %s",
                  G_VALUE_TYPE_NAME (value));
          return FALSE;
        }

      wocky_node_set_attribute (
          geoloc, "xml:lang", g_value_get_string (value));
      return TRUE;
    }

  mapping = g_hash_table_lookup (tp_to_xmpp, tp_name);

  if (mapping == NULL)
    {
      DEBUG ("Unknown location key: %s ; skipping", (const gchar *) tp_name);
      /* We don't raise a D-Bus error if the key is unknown to stay backward
       * compatible if new keys are added in a future version of the spec. */
      return TRUE;
    }

  if (G_VALUE_TYPE (value) != mapping->type)
    {
      g_set_error (err, TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
          "'%s' is supposed to be of type %s but is %s",
          (const char *) tp_name, g_type_name (mapping->type),
          G_VALUE_TYPE_NAME (value));
      return FALSE;
    }

  if (G_VALUE_TYPE (value) == G_TYPE_INT64)
    {
      GTimeVal timeval;

      timeval.tv_sec = CLAMP (g_value_get_int64 (value), 0, G_MAXLONG);
      timeval.tv_usec = 0;
      str = g_time_val_to_iso8601 (&timeval);
    }
  else if (G_VALUE_TYPE (value) == G_TYPE_DOUBLE)
    {
      str = g_strdup_printf ("%.6f", g_value_get_double (value));
    }
  else if (G_VALUE_TYPE (value) == G_TYPE_STRING)
    {
      str = g_value_dup_string (value);
    }
  else
    /* Keys and their type have been checked */
    g_assert_not_reached ();

  wocky_node_add_child_with_content (geoloc, mapping->xmpp_name, str);
  DEBUG ("\t - %s: %s", (gchar *) tp_name, str);
  g_free (str);
  return TRUE;
}
예제 #5
0
static void
produce_description (WockyJingleContent *content, WockyNode *content_node)
{
  GabbleJingleShare *self = GABBLE_JINGLE_SHARE (content);
  GabbleJingleSharePrivate *priv = self->priv;
  GList *i;

  WockyNode *desc_node;
  WockyNode *manifest_node;
  WockyNode *protocol_node;
  WockyNode *http_node;
  WockyNode *url_node;

  DEBUG ("produce description called");

  ensure_manifest (self);

  desc_node = wocky_node_add_child_ns (content_node, "description",
      NS_GOOGLE_SESSION_SHARE);

  manifest_node = wocky_node_add_child (desc_node, "manifest");

  for (i = priv->manifest->entries; i; i = i->next)
    {
      GabbleJingleShareManifestEntry *m = i->data;
      WockyNode *file_node;
      WockyNode *image_node;
      gchar *size_str, *width_str, *height_str;

      if (m->folder)
        file_node = wocky_node_add_child (manifest_node, "folder");
      else
        file_node = wocky_node_add_child (manifest_node, "file");

      if (m->size > 0)
        {
          size_str = g_strdup_printf ("%" G_GUINT64_FORMAT, m->size);
          wocky_node_set_attribute (file_node, "size", size_str);
          g_free (size_str);
        }
      wocky_node_add_child_with_content (file_node, "name", m->name);

      if (m->image &&
          (m->image_width > 0 || m->image_height > 0))
        {
          image_node = wocky_node_add_child (file_node, "image");
          if (m->image_width > 0)
            {
              width_str = g_strdup_printf ("%d", m->image_width);
              wocky_node_set_attribute (image_node, "width", width_str);
              g_free (width_str);
            }

          if (m->image_height > 0)
            {
              height_str = g_strdup_printf ("%d", m->image_height);
              wocky_node_set_attribute (image_node, "height", height_str);
              g_free (height_str);
            }
        }
    }

  protocol_node = wocky_node_add_child (desc_node, "protocol");
  http_node = wocky_node_add_child (protocol_node, "http");
  url_node = wocky_node_add_child_with_content (http_node, "url",
      priv->manifest->source_url);
  wocky_node_set_attribute (url_node, "name", "source-path");
  url_node = wocky_node_add_child_with_content (http_node, "url",
      priv->manifest->preview_url);
  wocky_node_set_attribute (url_node, "name", "preview-path");

}
예제 #6
0
void
gabble_tube_iface_publish_in_node (GabbleTubeIface *tube,
                                   TpBaseConnection *conn,
                                   WockyNode *node)
{
  WockyNode *parameters_node;
  GHashTable *parameters;
  TpTubeType type;
  gchar *service, *id_str;
  guint tube_id;
  TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
    conn, TP_HANDLE_TYPE_CONTACT);
  TpHandle initiator_handle;

  g_object_get (G_OBJECT (tube),
      "type", &type,
      "initiator-handle", &initiator_handle,
      "service", &service,
      "parameters", &parameters,
      "id", &tube_id,
      NULL);

  id_str = g_strdup_printf ("%u", tube_id);

  wocky_node_set_attributes (node,
      "service", service,
      "id", id_str,
      NULL);

  g_free (id_str);

  switch (type)
    {
      case TP_TUBE_TYPE_DBUS:
        {
          gchar *name, *stream_id;

          g_object_get (G_OBJECT (tube),
              "stream-id", &stream_id,
              "dbus-name", &name,
              NULL);

          wocky_node_set_attributes (node,
              "type", "dbus",
              "stream-id", stream_id,
              "initiator", tp_handle_inspect (contact_repo, initiator_handle),
              NULL);

          if (name != NULL)
            wocky_node_set_attribute (node, "dbus-name", name);

          g_free (name);
          g_free (stream_id);
        }
        break;
      case TP_TUBE_TYPE_STREAM:
        {
          wocky_node_set_attribute (node, "type", "stream");
        }
        break;
      default:
        {
          g_return_if_reached ();
        }
    }

  parameters_node = wocky_node_add_child_with_content (node, "parameters",
      NULL);
  lm_message_node_add_children_from_properties (parameters_node, parameters,
      "parameter");

  g_free (service);
  g_hash_table_unref (parameters);
}