Exemple #1
0
static void
get_content (GrlNetWc *self,
             void *op,
             gchar **content,
             gsize *length)
{
  GrlNetWcPrivate *priv = self->priv;
  struct request_res *rr = op;

  dump_data (soup_request_get_uri (rr->request),
             rr->buffer,
             rr->offset);

  if (priv->previous_data)
    g_free (priv->previous_data);

  priv->previous_data = rr->buffer;

  if (content)
    *content = self->priv->previous_data;
  else {
    g_free (rr->buffer);
    self->priv->previous_data = NULL;
    rr->buffer = NULL;
  }

  if (length)
    *length = rr->offset;
}
static gboolean
soup_request_file_ensure_file (SoupRequestFile  *file,
			       GCancellable     *cancellable,
			       GError          **error)
{
	SoupURI *uri;
	char *decoded_path;

	if (file->priv->gfile)
		return TRUE;

	uri = soup_request_get_uri (SOUP_REQUEST (file));
	decoded_path = soup_uri_decode (uri->path);

#ifdef G_OS_WIN32
	windowsify_file_uri_path (decoded_path);
#endif

	if (uri->scheme == SOUP_URI_SCHEME_RESOURCE) {
		char *uri_str;

		uri_str = g_strdup_printf ("resource://%s", decoded_path);
		file->priv->gfile = g_file_new_for_uri (uri_str);
		g_free (uri_str);
	} else
		file->priv->gfile = g_file_new_for_path (decoded_path);

	g_free (decoded_path);
	return TRUE;
}
Exemple #3
0
GInputStream *
uzbl_scheme_request_send (SoupRequest *request, GCancellable *cancellable, GError **error)
{
    UZBL_UNUSED (cancellable);
    UZBL_UNUSED (error);

    UzblSchemeRequest *uzbl_request = UZBL_SCHEME_REQUEST (request);
    UzblSchemeRequestClass *cls = UZBL_SCHEME_REQUEST_GET_CLASS (uzbl_request);

    SoupURI *uri = soup_request_get_uri (request);
    const char *command = g_hash_table_lookup (cls->handlers, uri->scheme);

    GString *result = g_string_new ("");
    GArray *args = uzbl_commands_args_new ();
    const UzblCommand *cmd = uzbl_commands_parse (command, args);

    if (cmd) {
        uzbl_commands_args_append (args, soup_uri_to_string (uri, TRUE));
        uzbl_commands_run_parsed (cmd, args, result);
    }

    uzbl_commands_args_free (args);

    gchar *end = strchr (result->str, '\n');
    size_t line_len = end ? (size_t)(end - result->str) : result->len;

    uzbl_request->priv->content_length = result->len - line_len - 1;
    uzbl_request->priv->content_type = g_strndup (result->str, line_len);
    GInputStream *stream = g_memory_input_stream_new_from_data (
        g_strdup (end + 1),
        uzbl_request->priv->content_length, g_free);
    g_string_free (result, TRUE);

    return stream;
}
static gboolean
soup_request_file_ensure_file (SoupRequestFile  *file,
			       GCancellable     *cancellable,
			       GError          **error)
{
	SoupURI *uri;

	if (file->priv->gfile)
		return TRUE;

	uri = soup_request_get_uri (SOUP_REQUEST (file));
	if (uri->scheme == SOUP_URI_SCHEME_FILE) {
		gchar *decoded_uri = soup_uri_decode (g_strdup (uri->path));

		if (decoded_uri) {
			file->priv->gfile = g_file_new_for_path (decoded_uri);
			g_free (decoded_uri);
		}

		return TRUE;
	}

	g_set_error (error, SOUP_REQUESTER_ERROR, SOUP_REQUESTER_ERROR_UNSUPPORTED_URI_SCHEME,
		     _("Unsupported URI scheme '%s'"), uri->scheme);
	return FALSE;
}
void WebSoupRequestManager::send(GTask* task)
{
    WebKitSoupRequestGeneric* request = WEBKIT_SOUP_REQUEST_GENERIC(g_task_get_source_object(task));
    SoupRequest* soupRequest = SOUP_REQUEST(request);
    GUniquePtr<char> uriString(soup_uri_to_string(soup_request_get_uri(soupRequest), FALSE));

    uint64_t requestID = generateSoupRequestID();
    m_requestMap.set(requestID, adoptPtr(new WebSoupRequestAsyncData(task, request)));

    uint64_t initiatingPageID = WebCore::ResourceHandle::getSoupRequestInitiatingPageID(soupRequest);
    m_process->parentProcessConnection()->send(Messages::WebPageProxy::DidReceiveURIRequest(String::fromUTF8(uriString.get()), requestID), initiatingPageID);
}
void WebSoupRequestManager::send(GSimpleAsyncResult* result, GCancellable* cancellable)
{
    GRefPtr<WebKitSoupRequestGeneric> request = adoptGRef(WEBKIT_SOUP_REQUEST_GENERIC(g_async_result_get_source_object(G_ASYNC_RESULT(result))));
    SoupRequest* soupRequest = SOUP_REQUEST(request.get());
    GOwnPtr<char> uriString(soup_uri_to_string(soup_request_get_uri(soupRequest), FALSE));

    uint64_t requestID = generateSoupRequestID();
    m_requestMap.set(requestID, adoptPtr(new WebSoupRequestAsyncData(result, request.get(), cancellable)));

    uint64_t initiatingPageID = WebCore::ResourceHandle::getSoupRequestInitiatingPageID(soupRequest);
    m_process->connection()->send(Messages::WebPageProxy::DidReceiveURIRequest(String::fromUTF8(uriString.get()), requestID), initiatingPageID);
}
static GInputStream *
soup_request_data_send (SoupRequest   *request,
			GCancellable  *cancellable,
			GError       **error)
{
	SoupRequestData *data = SOUP_REQUEST_DATA (request);
	SoupURI *uri = soup_request_get_uri (request);
	GInputStream *memstream;
	const char *comma, *start, *end;
	gboolean base64 = FALSE;
	char *uristr;

	uristr = soup_uri_to_string (uri, FALSE);
	start = uristr + 5;
	comma = strchr (start, ',');
	if (comma && comma != start) {
		/* Deal with MIME type / params */
		if (comma >= start + BASE64_INDICATOR_LEN && !g_ascii_strncasecmp (comma - BASE64_INDICATOR_LEN, BASE64_INDICATOR, BASE64_INDICATOR_LEN)) {
			end = comma - BASE64_INDICATOR_LEN;
			base64 = TRUE;
		} else
			end = comma;

		if (end != start)
			data->priv->content_type = soup_uri_decoded_copy (start, end - start, NULL);
	}

	memstream = g_memory_input_stream_new ();

	if (comma)
		start = comma + 1;

	if (*start) {
		int decoded_length = 0;
		guchar *buf = (guchar *) soup_uri_decoded_copy (start, strlen (start),
								&decoded_length);

		if (base64)
			buf = g_base64_decode_inplace ((gchar*) buf, &data->priv->content_length);
		else
			data->priv->content_length = decoded_length;

		g_memory_input_stream_add_data (G_MEMORY_INPUT_STREAM (memstream),
						buf, data->priv->content_length,
						g_free);
	}
	g_free (uristr);

	return memstream;
}
static GInputStream *
soup_request_file_send (SoupRequest          *request,
			GCancellable         *cancellable,
			GError              **error)
{
	SoupRequestFile *file = SOUP_REQUEST_FILE (request);
	GInputStream *stream;
	GError *my_error = NULL;

	if (!soup_request_file_ensure_file (file, cancellable, error))
		return NULL;

	stream = G_INPUT_STREAM (g_file_read (file->priv->gfile,
					      cancellable, &my_error));
	if (stream == NULL) {
		if (g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY)) {
			GFileEnumerator *enumerator;
			g_clear_error (&my_error);
			enumerator = g_file_enumerate_children (file->priv->gfile,
								"*",
								G_FILE_QUERY_INFO_NONE,
								cancellable,
								error);
			if (enumerator) {
				stream = soup_directory_input_stream_new (enumerator,
									  soup_request_get_uri (request));
				g_object_unref (enumerator);
				file->priv->mime_type = g_strdup ("text/html");
			}
		} else
			g_propagate_error (error, my_error);
	} else {
		GFileInfo *info = g_file_query_info (file->priv->gfile,
						     G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
						     G_FILE_ATTRIBUTE_STANDARD_SIZE,
						     0, cancellable, NULL);
		if (info) {
			const char *content_type;
			file->priv->size = g_file_info_get_size (info);
			content_type = g_file_info_get_content_type (info);

			if (content_type)
				file->priv->mime_type = g_content_type_get_mime_type (content_type);
			g_object_unref (info);
		}
	}

	return stream;
}
static String failingURI(SoupRequest* request)
{
    ASSERT(request);
    return failingURI(soup_request_get_uri(request));
}
Exemple #10
0
static String failingURI(SoupRequest* request)
{
    ASSERT(request);
    GOwnPtr<char> uri(soup_uri_to_string(soup_request_get_uri(request), FALSE));
    return uri.get();
}
static GInputStream *
soup_request_data_send (SoupRequest   *request,
			GCancellable  *cancellable,
			GError       **error)
{
	SoupRequestData *data = SOUP_REQUEST_DATA (request);
	SoupURI *uri = soup_request_get_uri (request);
	GInputStream *memstream;
	const char *comma, *start, *end;
	gboolean base64 = FALSE;
	char *uristr;

	uristr = soup_uri_to_string (uri, FALSE);
	start = uristr + 5;
	comma = strchr (start, ',');
	if (comma && comma != start) {
		/* Deal with MIME type / params */
		if (comma > start + BASE64_INDICATOR_LEN && !g_ascii_strncasecmp (comma - BASE64_INDICATOR_LEN, BASE64_INDICATOR, BASE64_INDICATOR_LEN)) {
			end = comma - BASE64_INDICATOR_LEN;
			base64 = TRUE;
		} else
			end = comma;

		if (end != start) {
			char *encoded_content_type = g_strndup (start, end - start);

			if (base64)
				data->priv->content_type = encoded_content_type;
			else {
				data->priv->content_type = soup_uri_decode (encoded_content_type);
				g_free (encoded_content_type);
			}
		}
	}

	memstream = g_memory_input_stream_new ();

	if (comma)
		start = comma + 1;

	if (*start) {
		guchar *buf;

		if (base64) {
			int inlen, state = 0;
			guint save = 0;

			inlen = strlen (start);
			buf = g_malloc0 (inlen * 3 / 4 + 3);
			data->priv->content_length =
				g_base64_decode_step (start, inlen, buf,
						      &state, &save);
			if (state != 0) {
				g_free (buf);
				goto fail;
			}
		} else {
			buf = (guchar *) soup_uri_decode (start);
			data->priv->content_length = strlen ((const char *) buf);
		}

		g_memory_input_stream_add_data (G_MEMORY_INPUT_STREAM (memstream),
						buf, data->priv->content_length,
						g_free);
	}
	g_free (uristr);

	return memstream;

 fail:
	g_free (uristr);
	g_set_error (error, SOUP_REQUESTER_ERROR, SOUP_REQUESTER_ERROR_BAD_URI,
		     _("Unable to decode URI: %s"), start);
	g_object_unref (memstream);
	return NULL;
}
static GInputStream *
ephy_request_about_send (SoupRequest          *request,
                         GCancellable         *cancellable,
                         GError              **error)
{
  EphyRequestAbout *about = EPHY_REQUEST_ABOUT (request);
  SoupURI *uri = soup_request_get_uri (request);
  GString *data_str = g_string_new("<html>");

  if (!about->priv->css_style)
    read_css_style (about);

  if (!g_strcmp0 (uri->path, "plugins")) {
    WebKitWebPluginDatabase* database = webkit_get_web_plugin_database ();
    GSList *plugin_list, *p;

    g_string_append_printf (data_str, "<head><title>%s</title>" \
                            "<style type=\"text/css\">%s</style></head><body>",
                            _("Installed plugins"),
                            about->priv->css_style);

    g_string_append_printf (data_str, "<h1>%s</h1>", _("Installed plugins"));
    plugin_list = webkit_web_plugin_database_get_plugins (database);

    for (p = plugin_list; p; p = p->next) {
      WebKitWebPlugin *plugin = WEBKIT_WEB_PLUGIN (p->data);
      GSList *m, *mime_types;

      g_string_append_printf (data_str, "<h2>%s</h2>%s<br>%s: <b>%s</b>"\
                              "<table id=\"plugin-table\">"             \
                              "  <thead><tr><th>%s</th><th>%s</th><th>%s</th></tr></thead><tbody>",
                              webkit_web_plugin_get_name (plugin),
                              webkit_web_plugin_get_description (plugin),
                              _("Enabled"), webkit_web_plugin_get_enabled (plugin) ? _("Yes") : _("No"),
                              _("MIME type"), _("Description"), _("Suffixes"));

      mime_types = webkit_web_plugin_get_mimetypes (plugin);

      for (m = mime_types; m; m = m->next) {
        WebKitWebPluginMIMEType *mime_type = (WebKitWebPluginMIMEType*) m->data;
        guint i;

        g_string_append_printf (data_str, "<tr><td>%s</td><td>%s</td><td>",
                                mime_type->name, mime_type->description);

        for (i = 0; mime_type->extensions[i] != NULL; i++)
          g_string_append_printf (data_str, "%s%c", mime_type->extensions[i],
                                  mime_type->extensions[i + 1] ? ',' : ' ');

        g_string_append (data_str, "</td></tr>");
      }

      g_string_append (data_str, "</tbody></table>");
    }

    webkit_web_plugin_database_plugins_list_free (plugin_list);
    g_string_append (data_str, "</body>");
  } else if (!g_strcmp0 (uri->path, "memory")) {
    char *memory = ephy_smaps_to_html (EPHY_REQUEST_ABOUT (request)->priv->smaps);

    if (memory) {
      g_string_append_printf (data_str, "<head><title>%s</title>"       \
                              "<style type=\"text/css\">%s</style></head><body>",
                              _("Memory usage"),
                              about->priv->css_style);

      g_string_append_printf (data_str, "<h1>%s</h1>", _("Memory usage"));
      g_string_append (data_str, memory);
      g_free (memory);
    }

  } else if (!g_strcmp0 (uri->path, "epiphany")) {
    g_string_append_printf (data_str, "<head><title>Epiphany</title>" \
                            "<style type=\"text/css\">%s</style></head>" \
                            "<body style=\"background: #3369FF; color: white; font-style: italic;\">",
                            about->priv->css_style);

    g_string_append (data_str, "<div id=\"ephytext\">" \
                     "Il semble que la perfection soit atteinte non quand il n'y a plus rien à" \
                     " ajouter, mais quand il n'y a plus rien à retrancher." \
                     "</div>" \
                     "<div id=\"from\">" \
                     "<!-- Terre des Hommes, III: L'Avion, p. 60 -->" \
                     "Antoine de Saint-Exupéry" \
                     "</div></body>");
  } else if (!g_strcmp0 (uri->path, "applications")) {
    GList *applications, *p;

    g_string_append_printf (data_str, "<head><title>%s</title>"   \
                            "<style type=\"text/css\">%s</style></head>" \
                            "<body class=\"applications-body\"><h1>%s</h1>" \
                            "<p>%s</p>",
                            _("Applications"),
                            about->priv->css_style,
                            _("Applications"),
                            _("List of installed web applications"));


    g_string_append (data_str, "<form><table>");

    applications = ephy_web_application_get_application_list ();
    for (p = applications; p; p = p->next) {
      char *img_data = NULL, *img_data_base64 = NULL;
      gsize data_length;
      EphyWebApplication *app = (EphyWebApplication*)p->data;
      
      if (g_file_get_contents (app->icon_url, &img_data, &data_length, NULL))
        img_data_base64 = g_base64_encode ((guchar*)img_data, data_length);
      g_string_append_printf (data_str, "<tbody><tr><td class=\"icon\"><img width=64 height=64 src=\"data:image/png;base64,%s\">" \
                              " </img></td><td class=\"data\"><div class=\"appname\">%s</div><div class=\"appurl\">%s</div></td><td class=\"input\"><input type=\"submit\" value=\"Delete\" id=\"%s\"></td><td class=\"date\">%s <br /> %s</td></tr>",
                              img_data_base64, app->name, app->url, app->name,
                              /* Note for translators: this refers to the installation date. */
                              _("Installed on:"), app->install_date);
      g_free (img_data_base64);
      g_free (img_data);
    }

    g_string_append (data_str, "</form></table></body>");
    
    ephy_web_application_free_application_list (applications);
  }

  g_string_append (data_str, "</html>");
  about->priv->content_length = data_str->len;
  return g_memory_input_stream_new_from_data (g_string_free (data_str, false), about->priv->content_length, g_free);
}