Exemplo n.º 1
0
char*
ephy_embed_utils_normalize_address (const char *address)
{
	char *effective_address = NULL;
	SoupURI *uri;

	g_return_val_if_fail (address, NULL);

	if (ephy_embed_utils_address_is_existing_absolute_filename (address))
		return g_strconcat ("file://", address, NULL);

	uri = soup_uri_new (address);

	/* FIXME: if we are here we passed through the "should we
	 * auto-search this?" regex in EphyWebView, so we should be a
	 * valid-ish URL. Auto-prepend http:// to anything that is not
	 * one according to soup, because it probably will be
	 * something like "google.com". Special case localhost(:port)
	 * and IP(:port), because SoupURI, correctly, thinks it is a
	 * URI with scheme being localhost/IP and, optionally, path
	 * being the port. Ideally we should check if we have a
	 * handler for the scheme, and since we'll fail for localhost
	 * and IP, we'd fallback to loading it as a domain. */
	if (!uri ||
	    (uri && !g_strcmp0 (uri->scheme, "localhost")) ||
	    (uri && g_hostname_is_ip_address (uri->scheme)))
		effective_address = g_strconcat ("http://", address, NULL);
	else {
		/* Convert about: schemes to ephy-about: in order to
		 * force WebKit to delegate its handling to our
		 * EphyRequestAbout. In general about: schemes are
		 * handled internally by WebKit and mean "empty
		 * document".
		 */
		if (g_str_has_prefix (address, "about:") && !g_str_equal (address, "about:blank")) {
			effective_address = g_strconcat (EPHY_ABOUT_SCHEME, address + strlen ("about"), NULL);
		} else
			effective_address = g_strdup (address);
	}

	if (uri)
		soup_uri_free (uri);

	return effective_address;
}
Exemplo n.º 2
0
void
set_proxy_url() {
    SoupURI *suri;

    if (uzbl.net.proxy_url == NULL || *uzbl.net.proxy_url == ' ') {
        soup_session_remove_feature_by_type(uzbl.net.soup_session,
                (GType) SOUP_SESSION_PROXY_URI);
    }
    else {
        suri = soup_uri_new(uzbl.net.proxy_url);
        g_object_set(G_OBJECT(uzbl.net.soup_session),
                SOUP_SESSION_PROXY_URI,
                suri, NULL);
        soup_uri_free(suri);
    }

    return;
}
Exemplo n.º 3
0
static void
liferea_webkit_set_proxy (const gchar *host, guint port, const gchar *user, const gchar *pwd)
{
	SoupURI *proxy = NULL;

	if (host) {
		proxy = soup_uri_new (NULL);
		soup_uri_set_scheme (proxy, SOUP_URI_SCHEME_HTTP);
		soup_uri_set_host (proxy, host);
		soup_uri_set_port (proxy, port);
		soup_uri_set_user (proxy, user);
		soup_uri_set_password (proxy, pwd);
	}

	g_object_set (webkit_get_default_session (),
		      SOUP_SESSION_PROXY_URI, proxy,
		      NULL);
}
Exemplo n.º 4
0
static guint
get_proxy_uri_sync (SoupProxyURIResolver  *resolver,
		    SoupURI		  *uri,
		    GCancellable	  *cancellable,
		    SoupURI		 **proxy_uri)
{
	SoupProxyResolverDefault *resolver_default = SOUP_PROXY_RESOLVER_DEFAULT (resolver);
	SoupProxyResolverDefaultPrivate *priv = soup_proxy_resolver_default_get_instance_private (resolver_default);
	GError *error = NULL;
	char** proxy_uris = NULL;
	char *uri_string;
	guint status = SOUP_STATUS_OK;

	uri_string = soup_uri_to_string (uri, FALSE);

	proxy_uris = g_proxy_resolver_lookup (priv->gproxy_resolver,
					      uri_string,
					      cancellable,
					      &error);

	g_free (uri_string);

	if (error || proxy_uris == NULL || proxy_uris[0] == NULL) {
		status = SOUP_STATUS_CANT_RESOLVE_PROXY;
		goto cleanup;
	}

	/* We need to handle direct:// specially, otherwise
	 * SoupSession will try to resolve it as the proxy address.
	 */
	if (!g_strcmp0 (proxy_uris[0], "direct://"))
		goto cleanup;

	*proxy_uri = soup_uri_new (proxy_uris[0]);

	if (!*proxy_uri)
		status = SOUP_STATUS_CANT_RESOLVE_PROXY;

cleanup:
	g_strfreev (proxy_uris);
	if (error)
		g_clear_error (&error);
	return status;
}
Exemplo n.º 5
0
/*
 * Called when the description document is loaded.
 */
static void
description_loaded (GUPnPControlPoint *control_point,
                    GUPnPXMLDoc       *doc,
                    const char        *udn,
                    const char        *service_type,
                    const char        *description_url)
{
        xmlNode *element;
        SoupURI *url_base;

        /* Save the URL base, if any */
        element = xml_util_get_element ((xmlNode *) doc->doc,
                                        "root",
                                        NULL);
        if (element == NULL) {
                g_warning ("No 'root' element found in description document"
                           " '%s'. Ignoring device '%s'\n",
                           description_url,
                           udn);

                return;
        }

        if (element == NULL)
                return;

        url_base = xml_util_get_child_element_content_uri (element,
                                                           "URLBase",
                                                           NULL);
        if (!url_base)
                url_base = soup_uri_new (description_url);

        /* Iterate matching devices */
        process_device_list (element,
                             control_point,
                             doc,
                             udn,
                             service_type,
                             description_url,
                             url_base);

        /* Cleanup */
        soup_uri_free (url_base);
}
static guint
get_proxy_for_uri (SoupURI *uri, SoupURI **proxy_uri)
{
	char *uristr, **proxies;
	gboolean got_proxy;
	int i;

	*proxy_uri = NULL;

	/* resolver_gnome is locked */

	uristr = soup_uri_to_string (uri, FALSE);
	proxies = px_proxy_factory_get_proxies (libproxy_factory, uristr);
	g_free (uristr);

	if (!proxies)
		return SOUP_STATUS_OK;

	got_proxy = FALSE;
	for (i = 0; proxies[i]; i++) {
		if (!strcmp (proxies[i], "direct://")) {
			got_proxy = TRUE;
			break;
		}
		if (strncmp (proxies[i], "http://", 7) == 0) {
			*proxy_uri = soup_uri_new (proxies[i]);
			got_proxy = TRUE;
			break;
		}
	}
	for (i = 0; proxies[i]; i++)
		free (proxies[i]);
	free (proxies);

	if (got_proxy) {
		if (*proxy_uri && proxy_user) {
			soup_uri_set_user (*proxy_uri, proxy_user);
			soup_uri_set_password (*proxy_uri, proxy_password);
		}

		return SOUP_STATUS_OK;
	} else
		return SOUP_STATUS_CANT_RESOLVE_PROXY;
}
Exemplo n.º 7
0
static void
history_service_host_deleted_cb (EphyHistoryService *service,
                                 const char *deleted_url,
                                 EphyEmbedShell *shell)
{
  EphyEmbedShellPrivate *priv = ephy_embed_shell_get_instance_private (shell);
  GList *l;
  SoupURI *deleted_uri;

  deleted_uri = soup_uri_new (deleted_url);

  for (l = priv->web_extensions; l; l = g_list_next (l)) {
    EphyWebExtensionProxy *web_extension = (EphyWebExtensionProxy *)l->data;

    ephy_web_extension_proxy_history_delete_host (web_extension, soup_uri_get_host (deleted_uri));
  }

  soup_uri_free (deleted_uri);
}
Exemplo n.º 8
0
static void test_testinfo_generate(void) {
    Recipe recipe = {"1","1","1","RHEL-6.0","RedHatEnterpriseLinux6","Server","x86_64",NULL,NULL,NULL};
    Task task = {
        "456",
        &recipe,
        soup_uri_new("http://localhost:8000/recipes/123/tasks/456/"),
        "/distribution/install",
        g_dir_make_tmp("restraint_test_task_XXXXXX", NULL),
        TASK_FETCH_UNPACK,
        { .url = soup_uri_new("git://localhost/repo1?master#restraint/sanity/testinfo_generate") },
        NULL,
        NULL,
        FALSE,
        FALSE,
        NULL,
        FALSE,
        NULL,
        0,
    };
    restraint_task_run(&task);

    // assert it's on disk
    GFile *base = g_file_new_for_path(task.path);
    GFile *file = g_file_get_child(base, "Makefile");
    g_assert(g_file_query_exists (file, NULL) != FALSE);
    g_object_unref(file);
    file = g_file_get_child(base, "PURPOSE");
    g_assert(g_file_query_exists (file, NULL) != FALSE);
    g_object_unref(file);
    file = g_file_get_child(base, "runtest.sh");
    g_assert(g_file_query_exists (file, NULL) != FALSE);
    g_object_unref(file);
    g_object_unref(base);

    // assert this is an rhts_compat task
    g_assert(task.rhts_compat == TRUE);

    soup_uri_free(task.task_uri);
    g_free(task.path);
    g_strfreev(task.entry_point);
    g_list_free_full(task.dependencies, (GDestroyNotify) g_free);
    soup_uri_free(task.fetch.url);
}
Exemplo n.º 9
0
static void
do_message_do_not_use_auth_cache_test (void)
{
	SoupSession *session;
	SoupAuthManager *manager;
	SoupURI *soup_uri;
	char *uri;
	char *uri_with_credentials;

	SOUP_TEST_SKIP_IF_NO_APACHE;

	session = soup_test_session_new (SOUP_TYPE_SESSION, NULL);

	uri = g_strconcat (base_uri, "Digest/realm1/", NULL);

	/* First check that cached credentials are not used */
	do_digest_nonce_test (session, "First", uri, TRUE, TRUE, TRUE);
	do_digest_nonce_test (session, "Second", uri, TRUE, FALSE, FALSE);
	do_digest_nonce_test (session, "Third", uri, FALSE, TRUE, TRUE);

	/* Passing credentials in the URI should always authenticate
	 * no matter whether the cache is used or not
	 */
	soup_uri = soup_uri_new (uri);
	soup_uri_set_user (soup_uri, "user1");
	soup_uri_set_password (soup_uri, "realm1");
	uri_with_credentials = soup_uri_to_string (soup_uri, FALSE);
	soup_uri_free (soup_uri);
	do_digest_nonce_test (session, "Fourth", uri_with_credentials, FALSE, TRUE, FALSE);
	g_free (uri_with_credentials);

	manager = SOUP_AUTH_MANAGER (soup_session_get_feature (session, SOUP_TYPE_AUTH_MANAGER));
	soup_auth_manager_clear_cached_credentials (manager);

	/* Now check that credentials are not stored */
	do_digest_nonce_test (session, "First", uri, FALSE, TRUE, TRUE);
	do_digest_nonce_test (session, "Second", uri, TRUE, TRUE, TRUE);
	do_digest_nonce_test (session, "Third", uri, TRUE, FALSE, FALSE);
	g_free (uri);

	soup_test_session_abort_unref (session);
}
Exemplo n.º 10
0
Arquivo: ns_net.c Projeto: vifino/dwb
/**
 * Parses an uri to a {@link SoupUri} object
 *
 * @name parseUri
 * @memberOf net
 * @function
 *
 * @param {String} uri The uri to parse
 *
 * @returns {@link SoupUri}
 *      A parsed uri or null if the uri isn't valid according to RFC 3986.
 *
 * */
static JSValueRef
net_parse_uri(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
    JSValueRef ret = NIL;
    if (argc > 0)
    {
        char *uri = js_value_to_char(ctx, argv[0], -1, NULL);
        if (uri != NULL)
        {
            SoupURI *suri = soup_uri_new(uri);
            if (suri != NULL)
            {
                ret = suri_to_object(ctx, suri, exc);
                soup_uri_free(suri);
            }
            g_free(uri);
        }
    }
    return ret;
}
Exemplo n.º 11
0
void ResourceRequest::updateSoupMessage(SoupMessage* soupMessage) const
{
    g_object_set(soupMessage, SOUP_MESSAGE_METHOD, httpMethod().utf8().data(), NULL);

    const HTTPHeaderMap& headers = httpHeaderFields();
    SoupMessageHeaders* soupHeaders = soupMessage->request_headers;
    if (!headers.isEmpty()) {
        HTTPHeaderMap::const_iterator end = headers.end();
        for (HTTPHeaderMap::const_iterator it = headers.begin(); it != end; ++it)
            soup_message_headers_append(soupHeaders, it->first.string().utf8().data(), it->second.utf8().data());
    }

    String firstPartyString = firstPartyForCookies().string();
    if (!firstPartyString.isEmpty()) {
        GOwnPtr<SoupURI> firstParty(soup_uri_new(firstPartyString.utf8().data()));
        soup_message_set_first_party(soupMessage, firstParty.get());
    }

    soup_message_set_flags(soupMessage, m_soupFlags);
}
Exemplo n.º 12
0
void deleteCookie(NetworkingContext* context, const KURL& url, const String& name)
{
    SoupCookieJar* jar = context ? cookieJarForContext(context) : soupCookieJar();
    if (!jar)
        return;

    GOwnPtr<GSList> cookies(soup_cookie_jar_all_cookies(jar));
    if (!cookies)
        return;

    CString cookieName = name.utf8();
    GOwnPtr<SoupURI> uri(soup_uri_new(url.string().utf8().data()));
    for (GSList* iter = cookies.get(); iter; iter = g_slist_next(iter)) {
        GOwnPtr<SoupCookie> cookie(static_cast<SoupCookie*>(iter->data));
        if (!soup_cookie_applies_to_uri(cookie.get(), uri.get()))
            continue;
        if (cookieName == cookie->name)
            soup_cookie_jar_delete_cookie(jar, cookie.get());
    }
}
Exemplo n.º 13
0
/* note, this has to be set before username and password */
static void
fwupd_remote_set_metadata_uri (FwupdRemote *self, const gchar *metadata_uri)
{
	FwupdRemotePrivate *priv = GET_PRIVATE (self);
	const gchar *suffix;
	g_autoptr(SoupURI) uri = NULL;

	/* build the URI */
	uri = soup_uri_new (metadata_uri);
	if (uri == NULL)
		return;

	/* save this so we can export the object as a GVariant */
	priv->metadata_uri = g_strdup (metadata_uri);

	/* generate the signature URI too */
	suffix = fwupd_remote_get_suffix_for_keyring_kind (priv->keyring_kind);
	if (suffix != NULL)
		priv->metadata_uri_sig = g_strconcat (metadata_uri, suffix, NULL);
}
Exemplo n.º 14
0
static SoupURI *
get_uri (BuilderSourceFile *self,
         GError **error)
{
  SoupURI *uri;

  if (self->url == NULL)
    {
      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "URL not specified");
      return NULL;
    }

  uri = soup_uri_new (self->url);
  if (uri == NULL)
    {
      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid URL '%s'", self->url);
      return NULL;
    }
  return uri;
}
/**
 * webkit_network_request_set_uri:
 * @request: a #WebKitNetworkRequest
 * @uri: an URI
 *
 * Sets the URI held and used by the given request. When the request
 * has an associated #SoupMessage, its URI will also be set by this
 * call.
 *
 */
void webkit_network_request_set_uri(WebKitNetworkRequest* request, const gchar* uri)
{
    g_return_if_fail(WEBKIT_IS_NETWORK_REQUEST(request));
    g_return_if_fail(uri);

    WebKitNetworkRequestPrivate* priv = request->priv;

    if (priv->uri)
        g_free(priv->uri);
    priv->uri = g_strdup(uri);

    if (!priv->message)
        return;

    SoupURI* soupURI = soup_uri_new(uri);
    g_return_if_fail(soupURI);

    soup_message_set_uri(priv->message, soupURI);
    soup_uri_free(soupURI);
}
Exemplo n.º 16
0
int
main (int argc, char **argv)
{
	test_init (argc, argv, NULL);

	server = soup_test_server_new (TRUE);
	soup_server_add_handler (server, NULL, server_callback, NULL, NULL);
	base_uri = soup_uri_new ("http://127.0.0.1/");
	soup_uri_set_port (base_uri, soup_server_get_port (server));

	do_coding_test ();
	do_coding_req_test ();
	do_coding_empty_test ();

	soup_uri_free (base_uri);
	soup_test_server_quit_unref (server);

	test_cleanup ();
	return errors != 0;
}
Exemplo n.º 17
0
/**
 * webkit_network_response_set_uri:
 * @response: a #WebKitNetworkResponse
 * @uri: an URI
 *
 * Sets the URI held and used by the given response. When the response
 * has an associated #SoupMessage, its URI will also be set by this
 * call.
 *
 * Since: 1.1.14
 */
void webkit_network_response_set_uri(WebKitNetworkResponse* response, const gchar* uri)
{
    g_return_if_fail(WEBKIT_IS_NETWORK_RESPONSE(response));
    g_return_if_fail(uri);

    WebKitNetworkResponsePrivate* priv = response->priv;

    if (priv->uri)
        g_free(priv->uri);
    priv->uri = g_strdup(uri);

    if (!priv->message)
        return;

    SoupURI* soupURI = soup_uri_new(uri);
    g_return_if_fail(soupURI);

    soup_message_set_uri(priv->message, soupURI);
    soup_uri_free(soupURI);
}
Exemplo n.º 18
0
// Called each time the message is going to be sent again except the first time.
// It's used mostly to let webkit know about redirects.
static void restartedCallback(SoupMessage* msg, gpointer data)
{
    ResourceHandle* handle = static_cast<ResourceHandle*>(data);
    if (!handle)
        return;
    ResourceHandleInternal* d = handle->getInternal();
    if (d->m_cancelled)
        return;

    char* uri = soup_uri_to_string(soup_message_get_uri(msg), false);
    String location = String(uri);
    g_free(uri);
    KURL newURL = KURL(handle->request().url(), location);

    ResourceRequest request = handle->request();
    ResourceResponse response;
    request.setURL(newURL);
    request.setHTTPMethod(msg->method);
    fillResponseFromMessage(msg, &response);

    // Should not set Referer after a redirect from a secure resource to non-secure one.
    if (!request.url().protocolIs("https") && protocolIs(request.httpReferrer(), "https")) {
        request.clearHTTPReferrer();
        soup_message_headers_remove(msg->request_headers, "Referer");
    }

    if (d->client())
        d->client()->willSendRequest(handle, request, response);

    if (d->m_cancelled)
        return;

#ifdef HAVE_LIBSOUP_2_29_90
    // Update the first party in case the base URL changed with the redirect
    String firstPartyString = request.firstPartyForCookies().string();
    if (!firstPartyString.isEmpty()) {
        GOwnPtr<SoupURI> firstParty(soup_uri_new(firstPartyString.utf8().data()));
        soup_message_set_first_party(d->m_msg, firstParty.get());
    }
#endif
}
Exemplo n.º 19
0
static gboolean validate_destination (NstPlugin *plugin, GtkWidget *contact_widget, char **error)
{
	// Validate ticket number the user has entered
	if (gtk_entry_get_text_length (GTK_ENTRY(ticket_field)) <= 0)
	{
		*error = g_strdup("No ticket number specified");
		return FALSE;
	}

	// Validate the URI the user has entered
	SoupURI *soup_uri = soup_uri_new(gtk_entry_get_text(GTK_ENTRY(url_field)));
	if (!soup_uri)
	{
		*error = g_strdup("URI is invalid");
		return FALSE;
	}
	gchar *uri = soup_uri_to_string (soup_uri, FALSE);
	soup_uri_free(soup_uri);

	// Try an XMLRPC request to see if the URI exists, we can authenticate, the ticket exists, etc
	// We don't really care about the result, as long as it succeeds
	GValue result;
	gchar *err = send_xmlrpc(uri, "ticket.get", &result,
			G_TYPE_INT, strtol(gtk_entry_get_text(GTK_ENTRY(ticket_field)), NULL, 10),
			G_TYPE_INVALID);

	if (err)
	{
		g_free (uri);
		*error = err;
		return FALSE;
	}

	// Save to gconf as last used uri
	GConfClient* client = gconf_client_get_default ();
	gconf_client_set_string (client, LAST_TRAC_URI, uri, NULL);
	g_object_unref (client);

	g_free (uri);
	return TRUE;
}
Exemplo n.º 20
0
void
request_starting_cb(WebKitWebView *web_view, WebKitWebFrame *frame, WebKitWebResource *resource,
        WebKitNetworkRequest *request, WebKitNetworkResponse *response, gpointer user_data) {
    (void) web_view;
    (void) frame;
    (void) resource;
    (void) response;
    (void) user_data;

    const gchar *uri = webkit_network_request_get_uri (request);
    SoupMessage *message = webkit_network_request_get_message (request);

    if (message) {
        SoupURI *soup_uri = soup_uri_new (uri);
        soup_message_set_first_party (message, soup_uri);
    }

    if (uzbl.state.verbose)
        printf("Request starting -> %s\n", uri);
    send_event (REQUEST_STARTING, NULL, TYPE_STR, uri, NULL);

    if (uzbl.behave.request_handler) {
        GString *result = g_string_new ("");
        GArray *a = g_array_new (TRUE, FALSE, sizeof(gchar*));
        const CommandInfo *c = parse_command_parts(uzbl.behave.request_handler, a);

        if(c) {
            g_array_append_val(a, uri);
            run_parsed_command(c, a, result);
        }
        g_array_free(a, TRUE);

        if(result->len > 0) {
            char *p = strchr(result->str, '\n' );
            if ( p != NULL ) *p = '\0';
            webkit_network_request_set_uri(request, result->str);
        }

        g_string_free(result, TRUE);
    }
}
Exemplo n.º 21
0
void LayoutTestController::queueLoad(JSStringRef url, JSStringRef target)
{
    gchar* relativeURL = JSStringCopyUTF8CString(url);
    SoupURI* baseURI = soup_uri_new(webkit_web_frame_get_uri(mainFrame));

    SoupURI* absoluteURI = soup_uri_new_with_base(baseURI, relativeURL);
    soup_uri_free(baseURI);
    g_free(relativeURL);

    gchar* absoluteCString;
    if (absoluteURI) {
        absoluteCString = soup_uri_to_string(absoluteURI, FALSE);
        soup_uri_free(absoluteURI);
    } else
        absoluteCString = JSStringCopyUTF8CString(url);

    JSRetainPtr<JSStringRef> absoluteURL(Adopt, JSStringCreateWithUTF8CString(absoluteCString));
    g_free(absoluteCString);

    WorkQueue::shared()->queue(new LoadItem(absoluteURL.get(), target));
}
Exemplo n.º 22
0
gboolean
download_file_and_signature (const gchar *url,
                             GBytes **contents,
                             GBytes **signature,
                             GError **error)
{
  g_autoptr(SoupURI) uri = soup_uri_new (url);
  g_autoptr(SoupURI) sig_uri = NULL;

  if (uri == NULL)
    {
      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                   "Invalid URL %s", url);
      return FALSE;
    }

  sig_uri = get_uri_to_sig (uri);
  *contents = download_file (uri);
  *signature = download_file (sig_uri);
  return TRUE;
}
Exemplo n.º 23
0
static void test_fetch_git_negative(void) {
    // test-data/git-remote/repo2 has uploadarch=false in .git/config
    ExpectHttpServer *expect_http = expect_http_start();
    ExpectHttpRequest request = { "POST", "/recipes/123/tasks/456/status",
            "status=Aborted&message=Error+from+remote+git+daemon%3A+"
            "access+denied+or+repository+not+exported%3A+%2Frepo2",
            204 };
    expect_http_add_request(expect_http, &request);

    Recipe recipe = {"1","1","1","RHEL-6.0","RedHatEnterpriseLinux6","Server","x86_64",NULL,NULL,NULL};
    Task task = {
        "456",
        &recipe,
        soup_uri_new("http://localhost:8000/recipes/123/tasks/456/"),
        "/distribution/install",
        g_dir_make_tmp("restraint_test_task_XXXXXX", NULL),
        TASK_FETCH_UNPACK,
        { .url = soup_uri_new("git://localhost/repo2?master#restraint/sanity/fetch_git") },
        NULL,
        NULL,
        FALSE,
        FALSE,
        NULL,
        FALSE,
        NULL,
        0,
    };
    restraint_task_run(&task);

    expect_http_finish(expect_http);
    GFile *base = g_file_new_for_path(task.path);
    GFile *file = g_file_get_child(base, "Makefile");
    g_assert(g_file_query_exists (file, NULL) == FALSE);
    g_object_unref(file);
    g_object_unref(base);

    soup_uri_free(task.task_uri);
    g_free(task.path);
    soup_uri_free(task.fetch.url);
}
Exemplo n.º 24
0
static void
get_url_now (GrlNetWc *self,
             const char *url,
             GHashTable *headers,
             GAsyncResult *result,
             GCancellable *cancellable)
{
  GrlNetWcPrivate *priv = self->priv;
  struct request_res *rr = g_slice_new0 (struct request_res);

  g_simple_async_result_set_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (result),
                                             rr,
                                             NULL);

#ifdef LIBSOUP_REQUESTER_DEPRECATED
  SoupURI *uri = soup_uri_new (url);
  rr->request = soup_session_request_uri (priv->session, uri, NULL);
  soup_uri_free (uri);
#else
  rr->request = soup_requester_request (priv->requester, url, NULL);
#endif

  if (headers != NULL) {
    SoupMessage *message;
    GHashTableIter iter;
    const char *key, *value;

    message = soup_request_http_get_message (SOUP_REQUEST_HTTP (rr->request));

    if (message) {
      g_hash_table_iter_init (&iter, headers);
      while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *)&value)) {
        soup_message_headers_append (message->request_headers, key, value);
      }
      g_object_unref (message);
    }
  }

  soup_request_send_async (rr->request, cancellable, reply_cb, result);
}
Exemplo n.º 25
0
void
setup(void) {
	SoupSession *s;
	char *proxy;
	char *new_proxy;
	SoupURI *puri;

	/* clean up any zombies immediately */
	sigchld(0);
	gtk_init(NULL, NULL);
	if (!g_thread_supported())
		g_thread_init(NULL);

	dpy = GDK_DISPLAY();
	session = webkit_get_default_session();
	uriprop = XInternAtom(dpy, "_SURF_URI", False);
	findprop = XInternAtom(dpy, "_SURF_FIND", False);

	/* create dirs and files */
	cookiefile = buildpath(cookiefile);
	dldir = buildpath(dldir);
	scriptfile = buildpath(scriptfile);
	stylefile = buildpath(stylefile);

	/* cookie persistance */
	s = webkit_get_default_session();
	cookies = soup_cookie_jar_new();
	soup_session_add_feature(s, SOUP_SESSION_FEATURE(cookies));
	g_signal_connect(cookies, "changed", G_CALLBACK(changecookie), NULL);
	if((proxy = getenv("http_proxy")) && strcmp(proxy, "")) {
		new_proxy = g_strrstr(proxy, "http://") ? g_strdup(proxy) :
			    g_strdup_printf("http://%s", proxy);

		puri = soup_uri_new(new_proxy);
		g_object_set(G_OBJECT(s), "proxy-uri", puri, NULL);
		soup_uri_free(puri);
		g_free(new_proxy);
	}
	reloadcookies();
}
Exemplo n.º 26
0
static void
create_cookie_jar_for_domain (const char *address, const char *directory)
{
  GSList *cookies, *p;
  SoupCookieJar *current_jar, *new_jar;
  char *domain, *filename;
  SoupURI *uri;

  /* Create the new cookie jar */
  filename = g_build_filename (directory, "cookies.sqlite", NULL);
  new_jar = (SoupCookieJar*)soup_cookie_jar_sqlite_new (filename, FALSE);
  g_free (filename);

  /* The app domain for the current view */
  uri = soup_uri_new (address);
  domain = uri->host;

  /* The current cookies */
  current_jar = get_current_cookie_jar ();
  if (!current_jar) {
    soup_uri_free (uri);
    return;
  }

  cookies = soup_cookie_jar_all_cookies (current_jar);

  for (p = cookies; p; p = p->next) {
    SoupCookie *cookie = (SoupCookie*)p->data;

    if (soup_cookie_domain_matches (cookie, domain))
      soup_cookie_jar_add_cookie (new_jar, cookie);
    else
      soup_cookie_free (cookie);
  }

  soup_uri_free (uri);
  g_slist_free (cookies);
  g_object_unref (current_jar);
  g_object_unref (new_jar);
}
void deleteCookie(const NetworkStorageSession& session, const KURL& url, const String& name)
{
    SoupCookieJar* jar = cookieJarForSession(session);
    if (!jar)
        return;

    GOwnPtr<SoupURI> uri(soup_uri_new(url.string().utf8().data()));
    GOwnPtr<GSList> cookies(soup_cookie_jar_get_cookie_list(jar, uri.get(), TRUE));
    if (!cookies)
        return;

    CString cookieName = name.utf8();
    bool wasDeleted = false;
    for (GSList* iter = cookies.get(); iter; iter = g_slist_next(iter)) {
        SoupCookie* cookie = static_cast<SoupCookie*>(iter->data);
        if (!wasDeleted && cookieName == cookie->name) {
            soup_cookie_jar_delete_cookie(jar, cookie);
            wasDeleted = true;
        }
        soup_cookie_free(cookie);
    }
}
bool getRawCookies(const NetworkStorageSession& session, const KURL& /*firstParty*/, const KURL& url, Vector<Cookie>& rawCookies)
{
    rawCookies.clear();
    SoupCookieJar* jar = cookieJarForSession(session);
    if (!jar)
        return false;

    GOwnPtr<SoupURI> uri(soup_uri_new(url.string().utf8().data()));
    GOwnPtr<GSList> cookies(soup_cookie_jar_get_cookie_list(jar, uri.get(), TRUE));
    if (!cookies)
        return false;

    for (GSList* iter = cookies.get(); iter; iter = g_slist_next(iter)) {
        SoupCookie* cookie = static_cast<SoupCookie*>(iter->data);
        rawCookies.append(Cookie(String::fromUTF8(cookie->name), String::fromUTF8(cookie->value), String::fromUTF8(cookie->domain),
            String::fromUTF8(cookie->path), cookie->expires ? static_cast<double>(soup_date_to_time_t(cookie->expires)) * 1000 : 0,
            cookie->http_only, cookie->secure, !cookie->expires));
        soup_cookie_free(cookie);
    }

    return true;
}
Exemplo n.º 29
0
gboolean
ephy_web_application_is_uri_allowed (const char *uri)
{
  EphyWebApplication *webapp = ephy_web_application_for_profile_directory (ephy_profile_dir ());
  SoupURI *request_uri;
  char **urls;
  guint i;
  gboolean matched = FALSE;

  if (g_str_has_prefix (uri, "blob:") || g_str_has_prefix (uri, "data:"))
    return TRUE;

  if (urls_have_same_origin (uri, webapp->url))
    return TRUE;

  if (g_strcmp0 (uri, "about:blank") == 0)
    return TRUE;

  request_uri = soup_uri_new (uri);
  if (!request_uri)
    return FALSE;

  urls = g_settings_get_strv (EPHY_SETTINGS_WEB_APP, EPHY_PREFS_WEB_APP_ADDITIONAL_URLS);
  for (i = 0; urls[i] && !matched; i++) {
    if (!strstr (urls[i], "://")) {
      char *url = g_strdup_printf ("%s://%s", request_uri->scheme, urls[i]);

      matched = g_str_has_prefix (uri, url);
      g_free (url);
    } else {
      matched = g_str_has_prefix (uri, urls[i]);
    }
  }
  g_strfreev (urls);

  soup_uri_free (request_uri);

  return matched;
}
Exemplo n.º 30
0
int
main (int argc, char **argv)
{
    SoupServer *server;

    test_init (argc, argv, NULL);

    buffer = g_malloc (READ_BUFFER_SIZE);

    server = soup_test_server_new (FALSE);
    soup_server_add_handler (server, NULL, server_callback, NULL, NULL);
    base_uri = soup_uri_new ("http://127.0.0.1");
    soup_uri_set_port (base_uri, soup_server_get_port (server));
    base_uri_string = soup_uri_to_string (base_uri, FALSE);

    /* FIXME: I had to raise the number of connections allowed here, otherwise I
     * was hitting the limit, which indicates some connections are not dying.
     */
    session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC,
                                     "use-thread-context", TRUE,
                                     "max-conns", 20,
                                     "max-conns-per-host", 20,
                                     NULL);
    soup_session_add_feature_by_type (session, SOUP_TYPE_CONTENT_SNIFFER);

    test_multipart (1, 1, NO_MULTIPART);
    test_multipart (1, 1, SYNC_MULTIPART);
    test_multipart (1, 1, ASYNC_MULTIPART);
    test_multipart (1, 1, ASYNC_MULTIPART_SMALL_READS);

    soup_uri_free (base_uri);
    g_free (base_uri_string);
    g_free (buffer);

    soup_test_session_abort_unref (session);
    soup_test_server_quit_unref (server);
    test_cleanup ();
    return errors != 0;
}