Example #1
1
static SoupMessage *make_token_request_msg(
	const char *token_uri,
	const char *consumer_key,
	const char *consumer_secret)
{
	struct oauth_request *oa = oa_req_new_with_params(
		consumer_key, consumer_secret, token_uri, "POST", SIG_HMAC_SHA1, NULL);
	if(!oa_sign_request(oa, OA_REQ_REQUEST_TOKEN)) {
		/* FIXME: handle! */
		printf("fail!\n");
		oa_req_free(oa);
		return NULL;
	}

	SoupMessage *msg = soup_message_new("POST", token_uri);
#if 0
	soup_message_headers_append(msg->request_headers,
		"Authorization", oa_auth_header(oa, OA_REQ_REQUEST_TOKEN));
#elif 1
	char *body = oa_request_params_to_post_body(oa, OA_REQ_REQUEST_TOKEN);
	soup_message_set_request(msg, OA_POST_MIME_TYPE,
		SOUP_MEMORY_COPY, body, strlen(body));
#else
	GHashTable *query = oa_request_token_params(oa);
	soup_uri_set_query_from_form(soup_message_get_uri(msg), query);
	g_hash_table_destroy(query);
#endif

	oa_req_free(oa);
	return msg;
}
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;
}
static void test_network_request_create_destroy()
{
    WebKitNetworkRequest* request;
    SoupMessage* message;

    /* Test creation with URI */
    request = WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "uri", "http://debian.org/", NULL));
    g_assert(WEBKIT_IS_NETWORK_REQUEST(request));
    message = webkit_network_request_get_message(request);
    g_assert(!message);
    g_object_unref(request);

    /* Test creation with SoupMessage */
    message = soup_message_new("GET", "http://debian.org/");
    request = WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "message", message, NULL));
    g_assert(WEBKIT_IS_NETWORK_REQUEST(request));
    g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 2);
    g_object_unref(request);
    g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 1);
    g_object_unref(message);

    /* Test creation with both SoupMessage and URI */
    message = soup_message_new("GET", "http://debian.org/");
    request = WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "message", message, "uri", "http://gnome.org/", NULL));
    g_assert(WEBKIT_IS_NETWORK_REQUEST(request));
    g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 2);
    g_assert_cmpstr(webkit_network_request_get_uri(request), ==, "http://gnome.org/");
    g_object_unref(request);
    g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 1);
    g_object_unref(message);
}
Example #4
0
static void
do_tests_for_session (SoupSession *session,
		      char *fast_uri, char *slow_uri)
{
	SoupMessage *msg;

	debug_printf (1, "    fast\n");
	msg = soup_message_new ("GET", fast_uri);
	soup_session_send_message (session, msg);
	if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
		debug_printf (1, "      FAILED: %d %s (expected 200 OK)\n",
			      msg->status_code, msg->reason_phrase);
		errors++;
	}
	g_object_unref (msg);

	debug_printf (1, "    slow\n");
	msg = soup_message_new ("GET", slow_uri);
	soup_session_send_message (session, msg);
	if (msg->status_code != SOUP_STATUS_IO_ERROR) {
		debug_printf (1, "      FAILED: %d %s (expected %d %s)\n",
			      msg->status_code, msg->reason_phrase,
			      SOUP_STATUS_IO_ERROR,
			      soup_status_get_phrase (SOUP_STATUS_IO_ERROR));
		errors++;
	}
	g_object_unref (msg);
}
Example #5
0
static void
do_async_auth_no_password_test (void)
{
	SoupSession *session;
	SoupMessage *msg;
	guint auth_id;
	char *uri;
	int remaining;
	gboolean been_there;

	/* Test that giving no password doesn't cause multiple
	 * authenticate signals the second time.
	 */
	g_test_bug ("583462");

	SOUP_TEST_SKIP_IF_NO_APACHE;

	loop = g_main_loop_new (NULL, TRUE);
	session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
	uri = g_strconcat (base_uri, "Basic/realm1/", NULL);
	remaining = 0;

	/* Send a message that doesn't actually authenticate
	 */
	msg = soup_message_new ("GET", uri);
	g_object_set_data (G_OBJECT (msg), "id", GINT_TO_POINTER (1));
	auth_id = g_signal_connect (session, "authenticate",
				    G_CALLBACK (async_authenticate), NULL);
	g_object_ref (msg);
	remaining++;
	soup_session_queue_message (session, msg, async_finished, &remaining);
	g_main_loop_run (loop);
	g_signal_handler_disconnect (session, auth_id);
	soup_session_unpause_message (session, msg);
	g_main_loop_run (loop);
	g_object_unref(msg);

	/* Now send a second message */
	msg = soup_message_new ("GET", uri);
	g_object_set_data (G_OBJECT (msg), "id", GINT_TO_POINTER (2));
	g_object_ref (msg);
	been_there = FALSE;
	auth_id = g_signal_connect (session, "authenticate",
				    G_CALLBACK (async_authenticate_assert_once_and_stop),
				    &been_there);
	remaining++;
	soup_session_queue_message (session, msg, async_finished, &remaining);
	g_main_loop_run (loop);
	soup_session_unpause_message (session, msg);

	g_main_loop_run (loop);
	g_signal_handler_disconnect (session, auth_id);

	soup_test_session_abort_unref (session);
	g_object_unref (msg);

	g_free (uri);
	g_main_loop_unref (loop);
}
Example #6
0
static void
do_message_has_authorization_header_test (void)
{
	SoupSession *session;
	SoupMessage *msg;
	SoupAuthManager *manager;
	SoupAuth *auth = NULL;
	char *token;
	guint auth_id;
	char *uri;

	g_test_bug ("775882");

	SOUP_TEST_SKIP_IF_NO_APACHE;

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

	msg = soup_message_new ("GET", uri);
	auth_id = g_signal_connect (session, "authenticate",
			  G_CALLBACK (has_authorization_header_authenticate), &auth);
	soup_session_send_message (session, msg);
	soup_test_assert_message_status (msg, SOUP_STATUS_OK);
	soup_test_assert (SOUP_IS_AUTH (auth), "Expected a SoupAuth");
	token = soup_auth_get_authorization (auth, msg);
	g_object_unref (auth);
	g_object_unref (msg);
	g_signal_handler_disconnect (session, auth_id);

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

	msg = soup_message_new ("GET", uri);
	soup_message_headers_replace (msg->request_headers, "Authorization", token);
	auth_id = g_signal_connect (session, "authenticate",
				    G_CALLBACK (has_authorization_header_authenticate_assert),
				    NULL);
	soup_session_send_message (session, msg);
	soup_test_assert_message_status (msg, SOUP_STATUS_OK);
	g_object_unref (msg);

	/* Check that we can also provide our own Authorization header when not using credentials cache. */
	soup_auth_manager_clear_cached_credentials (manager);
	msg = soup_message_new ("GET", uri);
	soup_message_headers_replace (msg->request_headers, "Authorization", token);
	soup_message_set_flags (msg, soup_message_get_flags (msg) | SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE);
	soup_session_send_message (session, msg);
	soup_test_assert_message_status (msg, SOUP_STATUS_OK);
	g_object_unref (msg);
	g_free (token);
	g_signal_handler_disconnect (session, auth_id);

	g_free (uri);
	soup_test_session_abort_unref (session);
}
Example #7
0
static gpointer
test1_thread (gpointer use_thread_context)
{
	SoupSession *session;
	GMainContext *async_context;
	char *uri;
	SoupMessage *msg;
	GMainLoop *loop;

	/* Wait for main thread to be waiting on test1_cond */
	g_mutex_lock (&test1_mutex);
	g_mutex_unlock (&test1_mutex);

	async_context = g_main_context_new ();
	if (use_thread_context) {
		g_main_context_push_thread_default (async_context);
		session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC,
						 SOUP_SESSION_USE_THREAD_CONTEXT, TRUE,
						 NULL);
	} else {
		session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC,
						 SOUP_SESSION_ASYNC_CONTEXT, async_context,
						 NULL);
	}
	g_main_context_unref (async_context);

	uri = g_build_filename (base_uri, "slow", NULL);

	debug_printf (1, "  send_message\n");
	msg = soup_message_new ("GET", uri);
	soup_session_send_message (session, msg);
	soup_test_assert_message_status (msg, SOUP_STATUS_OK);
	g_object_unref (msg);

	debug_printf (1, "  queue_message\n");
	msg = soup_message_new ("GET", uri);
	loop = g_main_loop_new (async_context, FALSE);
	g_object_ref (msg);
	soup_session_queue_message (session, msg, test1_finished, loop);
	g_main_loop_run (loop);
	g_main_loop_unref (loop);
	soup_test_assert_message_status (msg, SOUP_STATUS_OK);
	g_object_unref (msg);

	soup_test_session_abort_unref (session);
	g_free (uri);

	g_cond_signal (&test1_cond);

	if (use_thread_context)
		g_main_context_pop_thread_default (async_context);
	return NULL;
}
Example #8
0
static void
do_digest_nonce_test (SoupSession *session,
		      const char *nth, const char *uri,
		      gboolean expect_401, gboolean expect_signal)
{
	SoupMessage *msg;
	gboolean got_401;

	msg = soup_message_new (SOUP_METHOD_GET, uri);
	if (expect_signal) {
		g_signal_connect (session, "authenticate",
				  G_CALLBACK (digest_nonce_authenticate),
				  NULL);
	}
	soup_message_add_status_code_handler (msg, "got_headers",
					      SOUP_STATUS_UNAUTHORIZED,
					      G_CALLBACK (digest_nonce_unauthorized),
					      &got_401);
	got_401 = FALSE;
	soup_session_send_message (session, msg);
	if (got_401 != expect_401) {
		debug_printf (1, "  %s request %s a 401 Unauthorized!\n", nth,
			      got_401 ? "got" : "did not get");
		errors++;
	}
	if (msg->status_code != SOUP_STATUS_OK) {
		debug_printf (1, "  %s request got status %d %s!\n", nth,
			      msg->status_code, msg->reason_phrase);
		errors++;
	}
	if (errors == 0)
		debug_printf (1, "  %s request succeeded\n", nth);
	g_object_unref (msg);
}
Example #9
0
GdkPixbuf*
utils_download_picture_if_newer(SoupSession* soup, const gchar* url, gint64 timestamp)
{
    SoupMessage* msg;
    guint soup_status;
    const gchar* last_modified;
    GdkPixbuf* ret;

    msg = soup_message_new(SOUP_METHOD_HEAD, url);
    soup_status = soup_session_send_message(soup, msg);

    if (SOUP_STATUS_IS_SUCCESSFUL(soup_status) &&
        (last_modified = soup_message_headers_get_one(msg->response_headers, "Last-Modified")) != NULL &&
        utils_http_full_date_to_timestamp(last_modified) < timestamp)
    {
        g_info("{Utils} No new content at url '%s'", url);
        ret = NULL;
    }
    else
        ret = utils_download_picture(soup, url);

    g_object_unref(msg);

    return ret;
}
Example #10
0
static void
do_one_connection_event_test (SoupSession *session, const char *uri,
			      const char *events)
{
	SoupMessage *msg;

	msg = soup_message_new ("GET", uri);
	g_signal_connect (msg, "network-event",
			  G_CALLBACK (network_event),
			  &events);
	soup_session_send_message (session, msg);
	if (msg->status_code != SOUP_STATUS_OK) {
		debug_printf (1, "      Unexpected response: %d %s\n",
			      msg->status_code, msg->reason_phrase);
		errors++;
	} else {
		while (*events) {
			debug_printf (1, "      Expected %s\n",
				      event_name_from_abbrev (*events));
			events++;
			errors++;
		}
	}
	g_object_unref (msg);
	soup_session_abort (session);
}
Example #11
0
static gboolean
send_files (NstPlugin *plugin,
            GtkWidget *contact_widget,
            GList *file_list)
{
    if (!file_list)
        return TRUE; /* returning false, just hangs the send-to dialog */

    gchar *save_items_req = build_save_items_request (file_list);

    SoupSession *soup_session = soup_session_sync_new ();
    SoupMessage *save_msg =
        soup_message_new ("POST", ZOTERO_CONNECTOR_URI"saveItems");
    soup_message_set_request (save_msg, "application/json", SOUP_MEMORY_TAKE,
            save_items_req, strlen (save_items_req));
    soup_message_headers_append (save_msg->request_headers,
            "X-Zotero-Connector-API-Version", ZOTERO_CONNECTOR_API_VERSION);

    guint status = soup_session_send_message(soup_session, save_msg);
    if (status != SAVE_ITEMS_STATUS_OK)
        g_warning ("nst-zotero: send failed: response to saveItems: %u\n", status);
    /* TODO: returning false just hands the send-to dialog, how to fail? */
    g_object_unref (save_msg);
    g_object_unref (soup_session);
    return TRUE;
}
Example #12
0
void
nm_connectivity_check_async (NMConnectivity      *self,
                             GAsyncReadyCallback  callback,
                             gpointer             user_data)
{
	NMConnectivityPrivate *priv;
#if WITH_CONCHECK
	SoupMessage *msg;
#endif
	GSimpleAsyncResult *simple;

	g_return_if_fail (NM_IS_CONNECTIVITY (self));
	priv = NM_CONNECTIVITY_GET_PRIVATE (self);

	simple = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
	                                    nm_connectivity_check_async);

#if WITH_CONCHECK
	if (priv->uri && priv->interval) {
		msg = soup_message_new ("GET", priv->uri);
		soup_message_set_flags (msg, SOUP_MESSAGE_NO_REDIRECT);
		soup_session_queue_message (priv->soup_session,
		                            msg,
		                            nm_connectivity_check_cb,
		                            simple);

		return;
	}
#endif

	g_simple_async_result_set_op_res_gssize (simple, priv->state);
	g_simple_async_result_complete_in_idle (simple);
}
Example #13
0
void
XCAP::CoreImpl::write (boost::shared_ptr<Path> path,
		       const std::string content_type,
		       const std::string content,
		       boost::function1<void,std::string> callback)
{
  SoupSession* session = NULL;
  SoupMessage* message = NULL;
  cb_other_data* data = NULL;

  clear_old_sessions ();

  /* all of this is freed in the result callback */
  session = soup_session_async_new_with_options ("user-agent", "ekiga", NULL);
  message = soup_message_new ("PUT", path->to_uri ().c_str ());
  soup_message_set_request (message, content_type.c_str (),
			    SOUP_MEMORY_COPY,
			    content.c_str (), content.length ());

  data = new cb_other_data;
  data->core = this;
  data->path = path;
  data->callback = callback;

  g_signal_connect (session, "authenticate",
		    G_CALLBACK (authenticate_other_callback), data);

  soup_session_queue_message (session, message,
			      result_other_callback, data);

  pending_sessions.push_back (session);
}
static void
parse_page_version (SoupSession *session,
		    SoupMessage *msg,
		    PlumaWindow *window)
{
	if (msg->status_code == SOUP_STATUS_OK)
	{
		gchar *version;
		SoupMessage *msg2;
		WindowData *data;

		data = g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY);

		version = get_file_page_version (msg->response_body->data,
						 VERSION_PLACE);

		data->url = g_strconcat (PLUMA_URL, version, "/", NULL);
		g_free (version);
		msg2 = soup_message_new ("GET", data->url);

		soup_session_queue_message (session, msg2,
					    (SoupSessionCallback)parse_page_file,
					    window);
	}
	else
	{
		g_object_set_data (G_OBJECT (window),
				   WINDOW_DATA_KEY,
				   NULL);
	}
}
Example #15
0
static void
ws_auth(sr_session_t *s)
{
	struct sr_session_priv *priv = s->priv;
	gchar *auth, *tmp;
	gchar *auth_url;
	SoupMessage *message;

	gchar *params;

	tmp = g_strdup_printf("%s%s", priv->user, priv->hash_pwd);
	auth = g_compute_checksum_for_string(G_CHECKSUM_MD5, tmp, -1);
	g_free(tmp);

	ws_params(s, &params,
			"api_key", priv->api_key,
			"authToken", auth,
			"method", "auth.getMobileSession",
			"username", priv->user,
			NULL);

	auth_url = g_strdup_printf("%s?%s",
			priv->api_url,
			params);
	g_free(params);

	message = soup_message_new("GET", auth_url);
	soup_session_queue_message(priv->soup,
			message,
			ws_auth_cb,
			s);

	g_free(auth_url);
	g_free(auth);
}
Example #16
0
GdkPixbuf*
utils_download_picture(SoupSession* soup, const gchar* url)
{
    SoupMessage* msg;
    GdkPixbuf* ret = NULL;
    GInputStream* input;
    GError* err = NULL;

    msg = soup_message_new("GET", url);
    input = soup_session_send(soup, msg, NULL, &err);

    if (err)
    {
        g_warning("{Utils} Error downloading picture code '%d' message '%s'", err->code, err->message);
        g_error_free(err);
    }
    else
    {
        ret = gdk_pixbuf_new_from_stream(input, NULL, NULL);

        g_input_stream_close(input, NULL, NULL);
    }

    g_object_unref(msg);

    return ret;
}
Example #17
0
static void
do_digest_nonce_test (SoupSession *session,
		      const char *nth, const char *uri, gboolean use_auth_cache,
		      gboolean expect_401, gboolean expect_signal)
{
	SoupMessage *msg;
	gboolean got_401;

	msg = soup_message_new (SOUP_METHOD_GET, uri);
	if (!use_auth_cache) {
		SoupMessageFlags flags = soup_message_get_flags (msg);

		soup_message_set_flags (msg, flags | SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE);
	}
	if (expect_signal) {
		g_signal_connect (session, "authenticate",
				  G_CALLBACK (digest_nonce_authenticate),
				  NULL);
	}
	soup_message_add_status_code_handler (msg, "got_headers",
					      SOUP_STATUS_UNAUTHORIZED,
					      G_CALLBACK (digest_nonce_unauthorized),
					      &got_401);
	got_401 = FALSE;
	soup_session_send_message (session, msg);
	soup_test_assert (got_401 == expect_401,
			  "%s request %s a 401 Unauthorized!\n", nth,
			  got_401 ? "got" : "did not get");
	soup_test_assert_message_status (msg, SOUP_STATUS_OK);

	g_object_unref (msg);
}
static void
impl_activate (PlumaPlugin *plugin,
	       PlumaWindow *window)
{
	SoupMessage *msg;
	WindowData *data;

	pluma_debug (DEBUG_PLUGINS);

	data = g_slice_new (WindowData);
	data->plugin = PLUMA_CHECK_UPDATE_PLUGIN (plugin);
	data->url = NULL;
	data->version = NULL;

	g_object_set_data_full (G_OBJECT (window),
				WINDOW_DATA_KEY,
				data,
				free_window_data);

	msg = soup_message_new ("GET", PLUMA_URL);

	soup_session_queue_message (PLUMA_CHECK_UPDATE_PLUGIN (plugin)->priv->session, msg,
				    (SoupSessionCallback)parse_page_version,
				    window);
}
Example #19
0
static void
do_infinite_auth_test (void)
{
	SoupSession *session;
	SoupMessage *msg;
	char *uri;
	int timeout;

	SOUP_TEST_SKIP_IF_NO_APACHE;

	session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
	g_signal_connect (session, "authenticate",
			  G_CALLBACK (infinite_authenticate), NULL);

	uri = g_strconcat (base_uri, "Basic/realm1/", NULL);
	msg = soup_message_new ("GET", uri);
	g_free (uri);

	timeout = g_timeout_add (500, infinite_cancel, session);
	g_test_expect_message ("libsoup", G_LOG_LEVEL_WARNING,
			       "*stuck in infinite loop*");
	soup_session_send_message (session, msg);
	g_test_assert_expected_messages ();

	soup_test_assert (msg->status_code != SOUP_STATUS_CANCELLED,
			  "Got stuck in loop");
	soup_test_assert_message_status (msg, SOUP_STATUS_UNAUTHORIZED);

	g_source_remove (timeout);
	soup_test_session_abort_unref (session);
	g_object_unref (msg);
}
Example #20
0
void
picasa_web_service_list_albums (PicasaWebService    *self,
			        GCancellable        *cancellable,
			        GAsyncReadyCallback  callback,
			        gpointer             user_data)
{
	OAuthAccount *account;
	SoupMessage  *msg;
	char         *url;

	account = web_service_get_current_account (WEB_SERVICE (self));
	g_return_if_fail (account != NULL);

	gth_task_progress (GTH_TASK (self), _("Getting the album list"), NULL, TRUE, 0.0);

	url = g_strconcat ("https://picasaweb.google.com/data/feed/api/user/", account->id, NULL);
	msg = soup_message_new ("GET", url);
	_picasa_web_service_add_headers (self, msg);
	_web_service_send_message (WEB_SERVICE (self),
				   msg,
				   cancellable,
				   callback,
				   user_data,
				   picasa_web_service_list_albums,
				   list_albums_ready_cb,
				   self);

	g_free (url);
}
Example #21
0
SoupMessage* ResourceRequest::toSoupMessage() const
{
    SoupMessage* soupMessage = soup_message_new(httpMethod().utf8().data(), url().string().utf8().data());
    if (!soupMessage)
        return 0;

    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());
    }

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

    soup_message_set_flags(soupMessage, m_soupFlags);

    // Body data is only handled at ResourceHandleSoup::startHttp for
    // now; this is because this may not be a good place to go
    // openning and mmapping files. We should maybe revisit this.
    return soupMessage;
}
Example #22
0
static SoupMessage* send_msg_to_server (OGDProvider *provider, const gchar *complete_query, GError **error)
{
    guint sendret;
    SoupMessage *msg;

    msg = soup_message_new ("GET", complete_query);
    if (msg == NULL) {
        g_set_error (error, OGD_NETWORK_ERROR_DOMAIN, OGD_NETWORK_ERROR,
                     "Unable to build request to server");
        return NULL;
    }

    sendret = soup_session_send_message (provider->priv->http_session, msg);
    if (sendret != 200) {
        g_set_error (error, OGD_NETWORK_ERROR_DOMAIN, OGD_NETWORK_ERROR,
                     "Unable to send request to server, error %u", sendret);
        g_object_unref (msg);
        return NULL;
    }

    if (check_msg (msg, error) == FALSE)
        return NULL;
    else
        return msg;
}
Example #23
0
static void test_network_request_properties()
{
    WebKitNetworkRequest* request;
    SoupMessage* message;
    gchar* soupURI;

    /* Test URI is set correctly when creating with URI */
    request = webkit_network_request_new("http://debian.org/");
    g_assert(WEBKIT_IS_NETWORK_REQUEST(request));
    g_assert_cmpstr(webkit_network_request_get_uri(request), ==, "http://debian.org/");
    g_object_unref(request);

    /* Test URI is set correctly when creating with Message */
    message = soup_message_new("GET", "http://debian.org/");
    request = WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "message", message, NULL));
    g_assert(WEBKIT_IS_NETWORK_REQUEST(request));
    g_object_unref(message);

    message = webkit_network_request_get_message(request);
    soupURI = soup_uri_to_string(soup_message_get_uri(message), FALSE);
    g_assert_cmpstr(soupURI, ==, "http://debian.org/");
    g_free(soupURI);

    g_assert_cmpstr(webkit_network_request_get_uri(request), ==, "http://debian.org/");
    g_object_unref(request);
}
Example #24
0
gboolean
yahoo_start_open (GWeatherInfo *info)
{
    GWeatherInfoPrivate *priv;
    WeatherLocation *loc;
    gchar *url;
    SoupMessage *message;

    priv = info->priv;
    loc = &priv->location;

    if (!loc->yahoo_id)
	return FALSE;

    /* u=f means that the values are in imperial system (which is what
       weather.c expects). They're converted to user preferences before
       displaying.
    */
    url = g_strdup_printf("https://weather.yahooapis.com/forecastrss?w=%s&u=f", loc->yahoo_id);

    message = soup_message_new ("GET", url);
    _gweather_info_begin_request (info, message);
    soup_session_queue_message (priv->session, message, yahoo_finish, info);

    g_free (url);

    return TRUE;
}
Example #25
0
static void
ws_love(sr_session_t *s)
{
	struct sr_session_priv *priv = s->priv;
	SoupMessage *message;
	gchar *params;
	sr_track_t *t;

	g_mutex_lock(priv->love_queue_mutex);
	t = g_queue_peek_head(priv->love_queue);
	g_mutex_unlock(priv->love_queue_mutex);

	if (!t)
		return;

	ws_params(s, &params,
			"method", "track.love",
			"api_key", priv->api_key,
			"sk", priv->session_key,
			"track", t->title,
			"artist", t->artist,
			NULL);

	message = soup_message_new("POST", priv->api_url);
	soup_message_set_request(message,
			"application/x-www-form-urlencoded",
			SOUP_MEMORY_TAKE,
			params,
			strlen(params));
	soup_session_queue_message(priv->soup,
			message,
			ws_love_cb,
			s);
}
Example #26
0
static void
do_pipelined_auth_test (const char *base_uri)
{
	SoupSession *session;
	SoupMessage *msg;
	gboolean authenticated;
	char *uri;
	int i;

	debug_printf (1, "Testing pipelined auth (bug 271540):\n");
	session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);

	authenticated = FALSE;
	g_signal_connect (session, "authenticate",
			  G_CALLBACK (bug271540_authenticate), &authenticated);

	uri = g_strconcat (base_uri, "Basic/realm1/", NULL);
	for (i = 0; i < 10; i++) {
		msg = soup_message_new (SOUP_METHOD_GET, uri);
		g_object_set_data (G_OBJECT (msg), "#", GINT_TO_POINTER (i + 1));
		g_signal_connect (msg, "wrote_headers",
				  G_CALLBACK (bug271540_sent), &authenticated);

		soup_session_queue_message (session, msg,
					    bug271540_finished, &i);
	}
	g_free (uri);

	loop = g_main_loop_new (NULL, TRUE);
	g_main_loop_run (loop);
	g_main_loop_unref (loop);

	soup_test_session_abort_unref (session);
}
Example #27
0
static gboolean
gs_plugin_odrs_json_post (SoupSession *session,
			  const gchar *uri,
			  const gchar *data,
			  GError **error)
{
	guint status_code;
	g_autoptr(SoupMessage) msg = NULL;

	/* create the GET data */
	g_debug ("odrs sending: %s", data);
	msg = soup_message_new (SOUP_METHOD_POST, uri);
	soup_message_set_request (msg, "application/json; charset=utf-8",
				  SOUP_MEMORY_COPY, data, strlen (data));

	/* set sync request */
	status_code = soup_session_send_message (session, msg);
	if (status_code != SOUP_STATUS_OK) {
		g_warning ("Failed to set rating on odrs: %s",
			   soup_status_get_phrase (status_code));
	}

	/* process returned JSON */
	g_debug ("odrs returned: %s", msg->response_body->data);
	return gs_plugin_odrs_parse_success (msg->response_body->data,
					     msg->response_body->length,
					     error);
}
Example #28
0
void
XCAP::CoreImpl::read (boost::shared_ptr<Path> path,
		      boost::function2<void, bool, std::string> callback)
{
  SoupSession* session = NULL;
  SoupMessage* message = NULL;
  cb_read_data* data = NULL;

  clear_old_sessions ();

  /* all of this is freed in the result callback */
  session = soup_session_async_new_with_options ("user-agent", "ekiga", NULL);
  message = soup_message_new ("GET", path->to_uri ().c_str ());
  data = new cb_read_data;
  data->core = this;
  data->path = path;
  data->callback = callback;

  g_signal_connect (session, "authenticate",
		    G_CALLBACK (authenticate_read_callback), data);

  soup_session_queue_message (session, message,
			      result_read_callback, data);

  pending_sessions.push_back (session);
}
Example #29
0
void
XCAP::CoreImpl::erase (gmref_ptr<Path> path,
		       sigc::slot1<void,std::string> callback)
{
  SoupSession* session = NULL;
  SoupMessage* message = NULL;
  cb_other_data* data = NULL;

  clear_old_sessions ();

  /* all of this is freed in the result callback */
  session = soup_session_async_new_with_options ("user-agent", "ekiga", NULL);
  message = soup_message_new ("DELETE", path->to_uri ().c_str ());
  data = new cb_other_data;
  data->core = this;
  data->path = path;
  data->callback = callback;

  g_signal_connect (session, "authenticate",
		    G_CALLBACK (authenticate_other_callback), data);

  soup_session_queue_message (session, message,
			      result_other_callback, data);

  pending_sessions.push_back (session);
}
Example #30
0
static SoupMessage *make_access_token_request_msg(
	const char *uri,
	const char *req_token,
	const char *req_secret,
	const char *verifier,
	const char *consumer_key,
	const char *consumer_secret)
{
	struct oauth_request *oa = oa_req_new_with_params(consumer_key,
		consumer_secret, uri, "POST", SIG_HMAC_SHA1, NULL);
	oa_set_token(oa, req_token, req_secret);
	oa_set_verifier(oa, verifier);
	if(!oa_sign_request(oa, OA_REQ_ACCESS_TOKEN)) {
		/* FIXME: do something */
		printf("arashgrjhagkhfasfa\n");
		oa_req_free(oa);
		return NULL;
	}

	SoupMessage *msg = soup_message_new("POST", uri);
	char *body = oa_request_params_to_post_body(oa, OA_REQ_ACCESS_TOKEN);
	soup_message_set_request(msg, OA_POST_MIME_TYPE,
		SOUP_MEMORY_COPY, body, strlen(body));

	oa_req_free(oa);
	return msg;
}