Ejemplo n.º 1
0
gchar *
gabble_jid_to_uri (const gchar *scheme,
    const gchar *jid,
    GError **error)
{
  gchar *normalized_uri = NULL;
  gchar *node = NULL;
  gchar *domain = NULL;
  gchar *resource = NULL;
  gchar *escaped_node = NULL;
  gchar *escaped_domain = NULL;
  gchar *escaped_resource = NULL;
  gchar *escaped_jid = NULL;
  gchar *normalized_scheme = NULL;

  g_return_val_if_fail (scheme != NULL, NULL);

  if (!wocky_decode_jid (jid, &node, &domain, &resource))
    {
      g_set_error (error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
          "'%s' is not a valid JID", jid);
      return NULL;
    }

  /* convert from "foo?" to "foo%3F" */
  if (node)
    escaped_node = g_uri_escape_string (node, NULL, TRUE);

  g_assert (domain != NULL);
  escaped_domain = g_uri_escape_string (domain, NULL, TRUE);

  if (resource)
    escaped_resource = g_uri_escape_string (resource, NULL, TRUE);

  escaped_jid = gabble_encode_jid (escaped_node, escaped_domain, escaped_resource);

  normalized_scheme = g_ascii_strdown (scheme, -1);

  normalized_uri = g_strdup_printf ("%s:%s", normalized_scheme, escaped_jid);

  g_free (node);
  g_free (domain);
  g_free (resource);
  g_free (escaped_node);
  g_free (escaped_domain);
  g_free (escaped_resource);
  g_free (escaped_jid);
  g_free (normalized_scheme);

  return normalized_uri;
}
Ejemplo n.º 2
0
static GabbleJingleSession *
ensure_session (GabbleJingleFactory *self,
    const gchar *sid,
    const gchar *from,
    JingleAction action,
    JingleDialect dialect,
    gboolean *new_session,
    GError **error)
{
  GabbleJingleFactoryPrivate *priv = self->priv;
  gchar *key;
  GabbleJingleSession *sess;

  if (!wocky_decode_jid (from, NULL, NULL, NULL))
    {
      g_prefix_error (error, "Couldn't parse sender '%s': ", from);
      return NULL;
    }

  /* If we can ensure the handle, we can decode the jid */
  key = make_session_map_key (from, sid);
  sess = g_hash_table_lookup (priv->sessions, key);
  g_free (key);

  if (sess == NULL)
    {
      if (action == JINGLE_ACTION_SESSION_INITIATE)
        {
          sess = create_session (self, sid, from, dialect, FALSE);
          *new_session = TRUE;
        }
      else
        {
          g_set_error (error, WOCKY_XMPP_ERROR,
              WOCKY_JINGLE_ERROR_UNKNOWN_SESSION,
              "session %s is unknown", sid);
          return NULL;
        }
    }
  else
    {
      *new_session = FALSE;
    }

  return sess;
}
Ejemplo n.º 3
0
gboolean
gabble_parse_xmpp_uri (const gchar *uri,
    gchar **node,
    gchar **domain,
    gchar **resource,
    GError **error)
{
  gboolean ret = FALSE;
  gchar *scheme;
  const gchar *jid;
  gchar *tmp_node = NULL;
  gchar *tmp_domain = NULL;
  gchar *tmp_resource = NULL;
  gchar *unescaped_node = NULL;
  gchar *unescaped_domain = NULL;
  gchar *unescaped_resource = NULL;
  gchar *unescaped_jid = NULL;
  gchar *normalized_jid = NULL;
  GError *gabble_error = NULL;

  g_return_val_if_fail (uri != NULL, FALSE);
  g_return_val_if_fail (domain != NULL, FALSE);

  scheme = g_uri_parse_scheme (uri);

  if (scheme == NULL)
    {
      g_set_error (error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
          "'%s' is not a valid URI", uri);
      goto OUT;
    }

  jid = uri + strlen (scheme) + 1; /* Strip the scheme */

  if (!wocky_decode_jid (jid, &tmp_node, &tmp_domain, &tmp_resource))
    {
      g_set_error (error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
          "'%s' is not a valid XMPP URI", uri);
      goto OUT;
    }

  /* convert from "foo%3F" to "foo?" */
  if (tmp_node)
    {
      unescaped_node = g_uri_unescape_string (tmp_node, NULL);
      if (unescaped_node == NULL)
        {
          g_set_error (error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
              "'%s' is not a valid XMPP URI", uri);
          goto OUT;
        }
    }

  g_assert (tmp_domain);
  unescaped_domain = g_uri_unescape_string (tmp_domain, NULL);
  if (unescaped_domain == NULL)
    {
      g_set_error (error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
          "'%s' is not a valid XMPP URI", uri);
      goto OUT;
    }

  if (tmp_resource)
    {
      unescaped_resource = g_uri_unescape_string (tmp_resource, NULL);
      if (unescaped_resource == NULL)
        {
          g_set_error (error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
              "'%s' is not a valid XMPP URI", uri);
          goto OUT;
        }
    }

  unescaped_jid = gabble_encode_jid (unescaped_node, unescaped_domain, unescaped_resource);

  normalized_jid = gabble_normalize_contact (NULL, unescaped_jid,
      GUINT_TO_POINTER (GABBLE_JID_GLOBAL), &gabble_error);

  if (gabble_error != NULL)
    {
      g_set_error (error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
          "'%s' is not a valid XMPP URI: %s", uri,
          gabble_error->message);
      g_error_free (gabble_error);
      goto OUT;
    }

  if (!wocky_decode_jid (normalized_jid, node, domain, resource))
    {
      g_set_error (error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
          "'%s' is not a valid XMPP URI", uri);
      goto OUT;
    }

  ret = TRUE;

OUT:
  g_free (scheme);
  g_free (tmp_node);
  g_free (tmp_domain);
  g_free (tmp_resource);
  g_free (unescaped_node);
  g_free (unescaped_domain);
  g_free (unescaped_resource);
  g_free (unescaped_jid);
  g_free (normalized_jid);
  return ret;
}