Exemple #1
0
static bool wispr_input(const guint8 **data, gsize *length,
						gpointer user_data)
{
	struct connman_wispr_portal_context *wp_context = user_data;
	GString *buf;
	gsize count;

	DBG("");

	buf = g_string_sized_new(100);

	g_string_append(buf, "button=Login&UserName="******"&Password="******"&FNAME=0&OriginatingServer=");
	g_string_append_uri_escaped(buf, wp_context->status_url, NULL, FALSE);

	count = buf->len;

	g_free(wp_context->wispr_formdata);
	wp_context->wispr_formdata = g_string_free(buf, FALSE);

	*data = (guint8 *) wp_context->wispr_formdata;
	*length = count;

	return false;
}
static SoupMessage *
get_soup_message (GDataAccessHandler *access_handler, GDataAccessRule *rule, const gchar *method)
{
	GDataLink *link;
	SoupMessage *message;
	GString *uri_string;
	gchar *uri;
	const gchar *scope_type, *scope_value;

	/* Get the edit URI */
	link = gdata_entry_look_up_link (GDATA_ENTRY (rule), "edit");
	if (link != NULL)
		return soup_message_new (method, link->href);

	/* Try building the URI instead */
	link = gdata_entry_look_up_link (GDATA_ENTRY (access_handler), "http://schemas.google.com/acl/2007#accessControlList");
	g_assert (link != NULL);
	gdata_access_rule_get_scope (rule, &scope_type, &scope_value);

	uri_string = g_string_sized_new (strlen (link->href) + 30);
	g_string_append_printf (uri_string, "%s/", link->href);
	g_string_append_uri_escaped (uri_string, scope_type, NULL, TRUE);
	if (scope_value != NULL) {
		g_string_append (uri_string, "%3A");
		g_string_append_uri_escaped (uri_string, scope_value, NULL, TRUE);
	}

	uri = g_string_free (uri_string, FALSE);
	message = soup_message_new (method, uri);
	g_free (uri);

	return message;
}
Exemple #3
0
static void
about_report_bug(GtkAction * action, gpointer user_data)
{
	GString *string;
	gchar *options;

	string = g_string_new("http://bugzilla.gnome.org/enter_bug.cgi?product=bluefish");
#ifdef WIN32
	string = g_string_append(string, ";op_sys=Windows");
#elif PLATFORM_DARWIN
	string = g_string_append(string, ";op_sys=Mac%20OS");
#endif	/* WIN32 */
	string = g_string_append(string, ";version=");
#ifdef SVN_REVISION
	string = g_string_append_uri_escaped(string, "development (SVN TRUNK)",NULL,FALSE);
#else	/* SVN_REVISION */
	string = g_string_append(string, PACKAGE_VERSION);
#endif	/* SVN_REVISION */
	string = g_string_append(string, ";comment=");
	options = g_strconcat(
#ifdef SVN_REVISION
						  "SVN revision ", SVN_REVISION, "\n",
#endif	/* SVN_REVISION */
						  "Bluefish was configured with: ", CONFIGURE_OPTIONS, "\n", NULL);

	string = g_string_append_uri_escaped(string, options, NULL, FALSE);
	g_free(options);

	bluefish_url_show(string->str);
	g_string_free(string, TRUE);
}
Exemple #4
0
static gboolean wispr_input(const guint8 **data, gsize *length,
						gpointer user_data)
{
	struct wispr_session *wispr = user_data;
	GString *buf;
	gsize count;

	buf = g_string_sized_new(100);

	g_string_append(buf, "button=Login&UserName="******"&Password="******"&FNAME=0&OriginatingServer=");
	g_string_append_uri_escaped(buf, wispr->originurl, NULL, FALSE);

	count = buf->len;

	g_free(wispr->formdata);
	wispr->formdata = g_string_free(buf, FALSE);

	*data = (guint8 *) wispr->formdata;
	*length = count;

	return FALSE;
}
static char *
sign_hmac (OAuthProxy *proxy, RestProxyCall *call, GHashTable *oauth_params)
{
  OAuthProxyPrivate *priv;
  RestProxyCallPrivate *callpriv;
  char *key, *signature, *ep, *eep;
  GString *text;
  GHashTable *all_params;

  priv = PROXY_GET_PRIVATE (proxy);
  callpriv = call->priv;

  text = g_string_new (NULL);
  g_string_append (text, rest_proxy_call_get_method (REST_PROXY_CALL (call)));
  g_string_append_c (text, '&');
  if (priv->oauth_echo) {
    g_string_append_uri_escaped (text, priv->service_url, NULL, FALSE);
  } else if (priv->signature_host != NULL) {
    SoupURI *url = soup_uri_new (callpriv->url);
    gchar *signing_url;

    soup_uri_set_host (url, priv->signature_host);
    signing_url = soup_uri_to_string (url, FALSE);

    g_string_append_uri_escaped (text, signing_url, NULL, FALSE);

    soup_uri_free (url);
    g_free (signing_url);
  } else {
    g_string_append_uri_escaped (text, callpriv->url, NULL, FALSE);
  }
  g_string_append_c (text, '&');

  /* Merge the OAuth parameters with the query parameters */
  all_params = g_hash_table_new (g_str_hash, g_str_equal);
  merge_hashes (all_params, oauth_params);
  if (!priv->oauth_echo)
    merge_params (all_params, callpriv->params);

  ep = encode_params (all_params);
  eep = OAUTH_ENCODE_STRING (ep);
  g_string_append (text, eep);
  g_free (ep);
  g_free (eep);
  g_hash_table_destroy (all_params);

  /* PLAINTEXT signature value is the HMAC-SHA1 key value */
  key = sign_plaintext (priv);

  signature = hmac_sha1 (key, text->str);

  g_free (key);
  g_string_free (text, TRUE);

  return signature;
}
Exemple #6
0
char *
g_vfs_encode_uri (GDecodedUri *decoded, gboolean allow_utf8)
{
    GString *uri;

    uri = g_string_new (NULL);

    g_string_append (uri, decoded->scheme);
    g_string_append (uri, "://");

    if (decoded->host != NULL)
    {
        if (decoded->userinfo)
        {
            /* userinfo    = *( unreserved / pct-encoded / sub-delims / ":" ) */
            g_string_append_uri_escaped (uri, decoded->userinfo,
                                         G_URI_RESERVED_CHARS_ALLOWED_IN_USERINFO, allow_utf8);
            g_string_append_c (uri, '@');
        }

        g_string_append_uri_escaped (uri, decoded->host,
                                     /* Allowed unescaped in hostname / ip address */
                                     G_URI_RESERVED_CHARS_SUBCOMPONENT_DELIMITERS ":[]" ,
                                     allow_utf8);

        if (decoded->port != -1)
        {
            g_string_append_c (uri, ':');
            g_string_append_printf (uri, "%d", decoded->port);
        }
    }

    g_string_append_uri_escaped (uri, decoded->path, G_URI_RESERVED_CHARS_ALLOWED_IN_PATH, allow_utf8);

    if (decoded->query)
    {
        g_string_append_c (uri, '?');
        g_string_append (uri, decoded->query);
    }

    if (decoded->fragment)
    {
        g_string_append_c (uri, '#');
        g_string_append (uri, decoded->fragment);
    }

    return g_string_free (uri, FALSE);
}
Exemple #7
0
static gchar *
build_network_label (const gchar *user,
                     const gchar *server,
                     const gchar *object,
                     guint32  port)
{
    GString *s;
    gchar *name;

    if (server != NULL)
    {
        s = g_string_new (NULL);
        if (user != NULL)
            g_string_append_uri_escaped (s, user, G_URI_RESERVED_CHARS_ALLOWED_IN_USERINFO, TRUE);
        g_string_append (s, "@");
        g_string_append (s, server);
        if (port != 0)
            g_string_append_printf (s, ":%d", port);
        if (object != NULL)
            g_string_append_printf (s, "/%s", object);
        name = g_string_free (s, FALSE);
    }
    else
    {
        name = g_strdup ("network password");
    }
    return name;
}
Exemple #8
0
/**
 * g_dbus_address_escape_value:
 * @string: an unescaped string to be included in a D-Bus address
 *     as the value in a key-value pair
 *
 * Escape @string so it can appear in a D-Bus address as the value
 * part of a key-value pair.
 *
 * For instance, if @string is "/run/bus-for-:0",
 * this function would return "/run/bus-for-%3A0",
 * which could be used in a D-Bus address like
 * "unix:nonce-tcp:host=127.0.0.1,port=42,noncefile=/run/bus-for-%3A0".
 *
 * Returns: (transfer full): a copy of @string with all
 *     non-optionally-escaped bytes escaped
 *
 * Since: 2.36
 */
gchar *
g_dbus_address_escape_value (const gchar *string)
{
  GString *s;
  gsize i;

  g_return_val_if_fail (string != NULL, NULL);

  /* There will often not be anything needing escaping at all. */
  s = g_string_sized_new (strlen (string));

  /* D-Bus address escaping is mostly the same as URI escaping... */
  g_string_append_uri_escaped (s, string, "\\/", FALSE);

  /* ... but '~' is an unreserved character in URIs, but a
   * non-optionally-escaped character in D-Bus addresses. */
  for (i = 0; i < s->len; i++)
    {
      if (G_UNLIKELY (s->str[i] == '~'))
        {
          s->str[i] = '%';
          g_string_insert (s, i + 1, "7E");
          i += 2;
        }
    }

  return g_string_free (s, FALSE);
}
static void
append_query_headers (GDataService *self, GDataAuthorizationDomain *domain, SoupMessage *message)
{
	GDataFreebaseServicePrivate *priv = GDATA_FREEBASE_SERVICE (self)->priv;
	const gchar *query;
	GString *new_query;
	SoupURI *uri;

	g_assert (message != NULL);

	if (priv->developer_key) {
		uri = soup_message_get_uri (message);
		query = soup_uri_get_query (uri);

		/* Set the key on every request, as per
		 * https://developers.google.com/freebase/v1/parameters
		 */
		if (query) {
			new_query = g_string_new (query);

			g_string_append (new_query, "&key=");
			g_string_append_uri_escaped (new_query, priv->developer_key, NULL, FALSE);

			soup_uri_set_query (uri, new_query->str);
			g_string_free (new_query, TRUE);
		}
	}

	/* Chain up to the parent class */
	GDATA_SERVICE_CLASS (gdata_freebase_service_parent_class)->append_query_headers (self, domain, message);
}
Exemple #10
0
static void
_append (GString *gs, char sep, const char *k, const char *v)
{
	if (k != NULL && v != NULL) {
		g_string_append_printf (gs, "%c%s=", sep, k);
		g_string_append_uri_escaped (gs, v, NULL, TRUE);
	}
}
Exemple #11
0
char *
g_mount_spec_to_string (GMountSpec *spec)
{
  GString *str;
  int i;
  gboolean first;

  if (spec == NULL)
    return g_strdup ("(null)");

  str = g_string_new (g_mount_spec_get_type (spec));
  g_string_append_c (str, ':');

  first = TRUE;
  for (i = 0; i < spec->items->len; i++)
    {
      GMountSpecItem *item = &g_array_index (spec->items, GMountSpecItem, i);

      if (strcmp (item->key, "type") == 0)
	continue;

      if (!first)
	g_string_append_c (str, ',');
      first = FALSE;

      g_string_append_printf (str, "%s=", item->key);
      g_string_append_uri_escaped (str, item->value,
				   "$&'()*+",
				   TRUE);
    }

  if (strcmp (spec->mount_prefix, "/") != 0)
    {
      g_string_append_printf (str, ",prefix=");
      g_string_append_uri_escaped (str, spec->mount_prefix,
				   "$&'()*+",
				   TRUE);
    }

  return g_string_free (str, FALSE);
}
Exemple #12
0
/**
 * g_uri_escape_string:
 * @unescaped: the unescaped input string.
 * @reserved_chars_allowed: a string of reserved characters that are
 *      allowed to be used, or %NULL.
 * @allow_utf8: %TRUE if the result can include UTF-8 characters.
 * 
 * Escapes a string for use in a URI.
 *
 * Normally all characters that are not "unreserved" (i.e. ASCII alphanumerical
 * characters plus dash, dot, underscore and tilde) are escaped.
 * But if you specify characters in @reserved_chars_allowed they are not
 * escaped. This is useful for the "reserved" characters in the URI
 * specification, since those are allowed unescaped in some portions of
 * a URI. 
 * 
 * Returns: an escaped version of @unescaped. The returned string should be 
 * freed when no longer needed.
 *
 * Since: 2.16
 **/
char *
g_uri_escape_string (const char *unescaped,
		     const char  *reserved_chars_allowed,
		     gboolean     allow_utf8)
{
  GString *s;

  g_return_val_if_fail (unescaped != NULL, NULL);

  s = g_string_sized_new (strlen (unescaped) + 10);
  
  g_string_append_uri_escaped (s, unescaped, reserved_chars_allowed, allow_utf8);
  
  return g_string_free (s, FALSE);
}
static gchar *
build_events_uri (GDataCalendarCalendar *calendar)
{
	GString *uri;
	const gchar *calendar_id;

	calendar_id = (calendar != NULL) ? gdata_entry_get_id (GDATA_ENTRY (calendar)) : "default";

	uri = g_string_new (_gdata_service_get_scheme ());
	g_string_append (uri, "://www.googleapis.com/calendar/v3/calendars/");
	g_string_append_uri_escaped (uri, calendar_id, NULL, FALSE);
	g_string_append (uri, "/events");

	return g_string_free (uri, FALSE);
}
Exemple #14
0
GError *
oio_proxy_call_content_link (CURL *h, struct oio_url_s *u, const char *id)
{
	struct http_ctx_s i = { .headers = NULL, .body = _gs_vprintf("{\"id\":\"%s\"}", id) };
	GString *http_url = _curl_content_url (u, "link");
	GError *err = _proxy_call (h, "POST", http_url->str, &i, NULL);
	g_string_free (http_url, TRUE);
	g_string_free (i.body, TRUE);
	return err;
}

GError *
oio_proxy_call_content_prepare (CURL *h, struct oio_url_s *u,
		gsize size, gboolean autocreate,
		struct oio_proxy_content_prepare_out_s *out)
{
	gchar *hdrin[] = {
		PROXYD_HEADER_MODE, autocreate ? "autocreate" : NULL,
		NULL
	};
	struct http_ctx_s i = {
		.headers = hdrin,
		.body = _gs_vprintf ("{\"size\":%"G_GSIZE_FORMAT",\"autocreate\":%s}",
			size, autocreate ? "true" : "false")
	};
	struct http_ctx_s o = {
		.headers = g_malloc0(sizeof(void*)),
		.body = out ? out->body : NULL
	};
	GString *http_url = _curl_content_url (u, "prepare");
	GError *err = _proxy_call (h, "POST", http_url->str, &i, &o);
	if (!err && out && o.headers) {
		for (gchar **p=o.headers; *p && *(p+1) ;p+=2) {
			if (!g_ascii_strcasecmp(*p, "ns-chunk-size"))
				oio_str_replace (&out->header_chunk_size, *(p+1));
			else if (!g_ascii_strcasecmp(*p, "content-meta-version"))
				oio_str_replace (&out->header_version, *(p+1));
			else if (!g_ascii_strcasecmp(*p, "content-meta-id"))
				oio_str_replace (&out->header_content, *(p+1));
			else if (!g_ascii_strcasecmp(*p, "content-meta-policy"))
				oio_str_replace (&out->header_stgpol, *(p+1));
			else if (!g_ascii_strcasecmp(*p, "content-meta-mime-type"))
				oio_str_replace (&out->header_mime_type, *(p+1));
			else if (!g_ascii_strcasecmp(*p, "content-meta-chunk-method"))
				oio_str_replace (&out->header_chunk_method, *(p+1));
		}
	}
	g_string_free (http_url, TRUE);
	g_string_free(i.body, TRUE);
	if (o.headers)
		g_strfreev (o.headers);
	return err;
}

GError *
oio_proxy_call_content_create (CURL *h, struct oio_url_s *u,
		struct oio_proxy_content_create_in_s *in, GString *out)
{
	GString *http_url = _curl_content_url (u, "create");
	if (in->content) {
		g_string_append (http_url, "&id=");
		g_string_append_uri_escaped (http_url, in->content, NULL, TRUE);
	}
	gchar *hdrin[] = {
		g_strdup(PROXYD_HEADER_PREFIX "content-meta-id"),
		g_strdup_printf("%s", in->content),
		g_strdup(PROXYD_HEADER_PREFIX "content-meta-version"),
		g_strdup_printf("%"G_GINT64_FORMAT, in->version),
		g_strdup(PROXYD_HEADER_PREFIX "content-meta-length"),
		g_strdup_printf("%"G_GSIZE_FORMAT, in->size),
		g_strdup(PROXYD_HEADER_PREFIX "content-meta-hash"),
		g_strdup_printf("%s", in->hash),
		g_strdup(PROXYD_HEADER_PREFIX "content-meta-policy"),
		g_strdup_printf("%s", "NONE"),
		NULL
	};
	struct http_ctx_s i = { .headers = hdrin, .body = in ? in->chunks : NULL };
	struct http_ctx_s o = { .headers = NULL, .body = out };
	GError *err = _proxy_call (h, "POST", http_url->str, &i, &o);
	_ptrv_free_content (i.headers);
	g_string_free (http_url, TRUE);
	return err;
}

GError *
oio_proxy_call_content_list (CURL *h, struct oio_url_s *u, GString *out,
		const char *prefix, const char *marker, const char *end,
		guint max, char delim)
{
	GString *http_url = _curl_container_url (u, "list");
	if (prefix) _append (http_url, '&', "prefix", prefix);
	if (marker) _append (http_url, '&', "marker", marker);
	if (end) _append (http_url, '&', "end", end);
	if (max) g_string_append_printf (http_url, "&max=%u", max);
	if (delim) g_string_append_printf (http_url, "&delimiter=%c", delim);

	struct http_ctx_s o = { .headers = NULL, .body = out };
	GError *err = _proxy_call (h, "GET", http_url->str, NULL, &o);
	g_strfreev (o.headers);

	g_string_free(http_url, TRUE);
	return err;
}

GError *
oio_proxy_call_reference_show (CURL *h, struct oio_url_s *u,
		const char *t, GString *out)
{
	GString *http_url = _curl_reference_url (u, "show");
	if (t) _append(http_url, '&', "type", t);

	struct http_ctx_s o = { .headers = NULL, .body = out };
	GError *err = _proxy_call (h, "GET", http_url->str, NULL, &o);
	g_strfreev (o.headers);

	g_string_free(http_url, TRUE);
	return err;
}
Exemple #15
0
static void
send_http_request (CockpitHttpStream *self)
{
  CockpitChannel *channel = COCKPIT_CHANNEL (self);
  JsonObject *options;
  gboolean had_host;
  gboolean had_encoding;
  const gchar *method;
  const gchar *path;
  GString *string = NULL;
  JsonNode *node;
  JsonObject *headers;
  const gchar *header;
  const gchar *value;
  GList *request = NULL;
  GList *names = NULL;
  GBytes *bytes;
  GList *l;
  gsize total;

  options = cockpit_channel_get_options (channel);

  /*
   * The checks we do here for token validity are just enough to be able
   * to format an HTTP response, without leaking across lines etc.
   */

  if (!cockpit_json_get_string (options, "path", NULL, &path))
    {
      cockpit_channel_fail (channel, "protocol-error",
                            "%s: bad \"path\" field in HTTP stream request", self->name);
      goto out;
    }
  else if (path == NULL)
    {
      cockpit_channel_fail (channel, "protocol-error",
                            "%s: missing \"path\" field in HTTP stream request", self->name);
      goto out;
    }
  else if (!cockpit_web_response_is_simple_token (path))
    {
      cockpit_channel_fail (channel, "protocol-error",
                            "%s: invalid \"path\" field in HTTP stream request", self->name);
      goto out;
    }

  if (!cockpit_json_get_string (options, "method", NULL, &method))
    {
      cockpit_channel_fail (channel, "protocol-error",
                            "%s: bad \"method\" field in HTTP stream request", self->name);
      goto out;
    }
  else if (method == NULL)
    {
      cockpit_channel_fail (channel, "protocol-error",
                            "%s: missing \"method\" field in HTTP stream request", self->name);
      goto out;
    }
  else if (!cockpit_web_response_is_simple_token (method))
    {
      cockpit_channel_fail (channel, "protocol-error",
                            "%s: invalid \"method\" field in HTTP stream request", self->name);
      goto out;
    }

  g_debug ("%s: sending %s request", self->name, method);

  string = g_string_sized_new (128);
  g_string_printf (string, "%s %s HTTP/1.1\r\n", method, path);

  had_encoding = had_host = FALSE;

  node = json_object_get_member (options, "headers");
  if (node)
    {
      if (!JSON_NODE_HOLDS_OBJECT (node))
        {
          cockpit_channel_fail (channel, "protocol-error",
                                "%s: invalid \"headers\" field in HTTP stream request", self->name);
          goto out;
        }

      headers = json_node_get_object (node);
      names = json_object_get_members (headers);
      for (l = names; l != NULL; l = g_list_next (l))
        {
          header = l->data;
          if (!cockpit_web_response_is_simple_token (header))
            {
              cockpit_channel_fail (channel, "protocol-error",
                                    "%s: invalid header in HTTP stream request: %s", self->name, header);
              goto out;
            }
          node = json_object_get_member (headers, header);
          if (!node || !JSON_NODE_HOLDS_VALUE (node) || json_node_get_value_type (node) != G_TYPE_STRING)
            {
              cockpit_channel_fail (channel, "protocol-error",
                                    "%s: invalid header value in HTTP stream request: %s", self->name, header);
              goto out;
            }
          value = json_node_get_string (node);
          if (disallowed_header (header, value, self->binary))
            {
              cockpit_channel_fail (channel, "protocol-error",
                                    "%s: disallowed header in HTTP stream request: %s", self->name, header);
              goto out;
            }
          if (!cockpit_web_response_is_header_value (value))
            {
              cockpit_channel_fail (channel, "protocol-error",
                                    "%s: invalid header value in HTTP stream request: %s", self->name, header);
              goto out;
            }

          g_string_append_printf (string, "%s: %s\r\n", (gchar *)l->data, value);
          g_debug ("%s: sending header: %s %s", self->name, (gchar *)l->data, value);

          if (g_ascii_strcasecmp (l->data, "Host") == 0)
            had_host = TRUE;
          if (g_ascii_strcasecmp (l->data, "Accept-Encoding") == 0)
            had_encoding = TRUE;
        }
    }

  if (!had_host)
    {
      g_string_append (string, "Host: ");
      g_string_append_uri_escaped (string, self->client->connectable->name, "[]!%$&()*+,-.:;=\\_~", FALSE);
      g_string_append (string, "\r\n");
    }
  if (!had_encoding)
    g_string_append (string, "Accept-Encoding: identity\r\n");

  if (!self->binary)
    g_string_append (string, "Accept-Charset: UTF-8\r\n");

  request = g_list_reverse (self->request);
  self->request = NULL;

  /* Calculate how much data we have to send */
  total = 0;
  for (l = request; l != NULL; l = g_list_next (l))
    total += g_bytes_get_size (l->data);

  if (request || g_ascii_strcasecmp (method, "POST") == 0)
    g_string_append_printf (string, "Content-Length: %" G_GSIZE_FORMAT "\r\n", total);
  g_string_append (string, "\r\n");

  bytes = g_string_free_to_bytes (string);
  string = NULL;

  cockpit_stream_write (self->stream, bytes);
  g_bytes_unref (bytes);

  /* Now send all the data */
  for (l = request; l != NULL; l = g_list_next (l))
    cockpit_stream_write (self->stream, l->data);

out:
  g_list_free (names);
  g_list_free_full (request, (GDestroyNotify)g_bytes_unref);
  if (string)
    g_string_free (string, TRUE);
}
Exemple #16
0
static OlLrcCandidate *
ol_lrc_fetch_xiami_search(const OlMusicInfo *info, int *size, const char* charset)
{
  ol_assert_ret (info != NULL, NULL);
  ol_debugf ("  title: %s\n"
             "  artist: %s\n"
             "  album: %s\n",
             info->title,
             info->artist,
             info->album);
  OlLrcCandidate *ret = NULL;
  static OlLrcCandidate candidate_list[TRY_MATCH_MAX];
  OlLrcCandidate candidate;
  int result;
  int count = 0;
  if (info->title == NULL && info->artist == NULL)
    return NULL;

  GString *url = g_string_new (PREFIX_SEARCH_URL);
  if (ol_music_info_get_title (info) != NULL)
    g_string_append_uri_escaped (url,
                                 ol_music_info_get_title (info),
                                 NULL,
                                 FALSE);
  if (ol_music_info_get_artist (info) != NULL)
  {
    g_string_append_c (url, '+');
    g_string_append_uri_escaped (url,
                                 ol_music_info_get_artist (info),
                                 NULL,
                                 FALSE);
  }

  char *search_url = g_string_free (url, FALSE);
  ol_debugf ("Search url: %s\n", search_url);

  struct memo content;
  content.mem_base = NULL;
  content.mem_len = 0;

  if((result = fetch_into_memory(search_url,
                                 NULL, /* refer */
                                 NULL, /* user-agent */
                                 NULL, /* postdata */
                                 0,    /* postdata len */
                                 &content)) >= 0)
  {
    char *current = (char*)content.mem_base;
    char *p;
    while ((p = strstr (current, TITLE_PATTERN)) != NULL)
    {
      current = p + strlen (TITLE_PATTERN);
      if (!isdigit(*current))
        continue;
      p = strchr (current, '\"');
      if (p == NULL)
        break;
      *p = '\0';
      ol_debugf ("url id: %s\n", current);
      char *id = g_strdup (current);
      current = p + 1;
      char *title = _get_title_attr (current, &current);
      if (title == NULL)
        break;
      ol_lrc_candidate_set_title (&candidate, title);
      ol_debugf ("title: %s\n", title);
      g_free (title);
      p = strstr (current, ARTIST_PATTERN);
      if (p != NULL)
      {
        char *artist = _get_title_attr (p, &current);
        if (artist != NULL)
        {
          ol_lrc_candidate_set_artist (&candidate, artist);
          ol_debugf ("artist: %s\n", artist);
          g_free (artist);
        }
      }

      if (ol_lrc_fetch_calc_rank (info, &candidate) >= LRC_RANK_THRESHOLD)
      {
        char *url = _get_lyric_url (id);
        ol_debugf ("lyric url: %s\n", url);
        if (url != NULL)
        {
          ol_lrc_candidate_set_url (&candidate, url);
          count = ol_lrc_fetch_add_candidate (info,
                                              candidate_list,
                                              count,
                                              TRY_MATCH_MAX,
                                              &candidate);
          g_free (url);
        }
      }
      g_free (id);
    }
    free(content.mem_base);
    if (count > 0)
      ret = candidate_list;
  }
  *size = count;
  g_free (search_url);
  return ret;
}
Exemple #17
0
void
oauth_service_add_signature (OAuthService *self,
			     const char   *method,
			     const char   *url,
			     GHashTable   *parameters)
{
	GTimeVal  t;
	GString  *param_string;
	GList    *keys;
	GList    *scan;
	GString  *base_string;
	GString  *signature_key;

	/* Add the OAuth specific parameters */

	g_get_current_time (&t);

	g_free (self->priv->timestamp);
	self->priv->timestamp = oauth_create_timestamp (&t);
	g_hash_table_insert (parameters, "oauth_timestamp", self->priv->timestamp);

	g_free (self->priv->nonce);
	self->priv->nonce = oauth_create_nonce (&t);
	g_hash_table_insert (parameters, "oauth_nonce", self->priv->nonce);
	g_hash_table_insert (parameters, "oauth_version", OAUTH_VERSION);
	g_hash_table_insert (parameters, "oauth_signature_method", OAUTH_SIGNATURE_METHOD);
	g_hash_table_insert (parameters, "oauth_consumer_key", (gpointer) self->priv->consumer->consumer_key);
	if (self->priv->token != NULL)
		g_hash_table_insert (parameters, "oauth_token", self->priv->token);

	/* Create the parameter string */

	param_string = g_string_new ("");
	keys = g_hash_table_get_keys (parameters);
	keys = g_list_sort (keys, (GCompareFunc) strcmp);
	for (scan = keys; scan; scan = scan->next) {
		char *key = scan->data;
		char *value = g_hash_table_lookup (parameters, key);

		g_string_append_uri_escaped (param_string, key, NULL, FALSE);
		g_string_append (param_string, "=");
		g_string_append_uri_escaped (param_string, value, NULL, FALSE);
		if (scan->next != NULL)
			g_string_append (param_string, "&");
	}

	/* Create the Base String */

	base_string = g_string_new ("");
	g_string_append_uri_escaped (base_string, method, NULL, FALSE);
	g_string_append (base_string, "&");
	g_string_append_uri_escaped (base_string, url, NULL, FALSE);
	g_string_append (base_string, "&");
	g_string_append_uri_escaped (base_string, param_string->str, NULL, FALSE);

	/* Calculate the signature value */

	signature_key = g_string_new ("");
	g_string_append_uri_escaped (signature_key, self->priv->consumer->consumer_secret, NULL, FALSE);
	g_string_append (signature_key, "&");
	if (self->priv->token_secret != NULL)
		g_string_append_uri_escaped (signature_key, self->priv->token_secret, NULL, FALSE);
	g_free (self->priv->signature);
	self->priv->signature = g_compute_signature_for_string (G_CHECKSUM_SHA1,
								G_SIGNATURE_ENC_BASE64,
							        signature_key->str,
							        signature_key->len,
							        base_string->str,
							        base_string->len);
	g_hash_table_insert (parameters, "oauth_signature", self->priv->signature);

	g_string_free (signature_key, TRUE);
	g_string_free (base_string, TRUE);
	g_list_free (keys);
	g_string_free (param_string, TRUE);
}