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); }
/** * ephy_remove_tracking_from_uri: * @uri_string: a uri * * Sanitize @uri to make sure it does not contain analytics tracking * information. Inspired by the Firefox PureURL add-on: * https://addons.mozilla.org/fr/firefox/addon/pure-url/ * * Returns: the sanitized uri, or %NULL on error or when the URI did * not change. */ char * ephy_remove_tracking_from_uri (const char *uri_string) { SoupURI *uri; GList *items, *new_items, *l; const char *query, *host; gboolean has_garbage = FALSE; char *ret = NULL; uri = soup_uri_new (uri_string); if (!uri) return ret; host = soup_uri_get_host (uri); query = soup_uri_get_query (uri); if (!query) goto bail; items = query_split (query); if (!items) goto bail; new_items = NULL; for (l = items; l != NULL; l = l->next) { QueryItem *item = l->data; if (!is_garbage (item->decoded_name, host)) new_items = g_list_prepend (new_items, item); else has_garbage = TRUE; } if (has_garbage) { char *new_query; new_items = g_list_reverse (new_items); new_query = query_concat (new_items); soup_uri_set_query (uri, new_query); g_free (new_query); ret = soup_uri_to_string (uri, FALSE); } g_list_free_full (items, (GDestroyNotify) query_item_free); g_list_free (new_items); bail: soup_uri_free (uri); return ret; }
void gfbgraph_goa_authorizer_process_message (GFBGraphAuthorizer *iface, SoupMessage *message) { gchar *auth_value; SoupURI *uri; GFBGraphGoaAuthorizerPrivate *priv; priv = GFBGRAPH_GOA_AUTHORIZER_GET_PRIVATE (GFBGRAPH_GOA_AUTHORIZER (iface)); g_mutex_lock (&priv->mutex); uri = soup_message_get_uri (message); auth_value = g_strconcat ("access_token=", priv->access_token, NULL); soup_uri_set_query (uri, auth_value); g_free (auth_value); g_mutex_unlock (&priv->mutex); }
void get_url_mocked (GrlNetWc *self, const char *url, GHashTable *headers, GAsyncResult *result, GCancellable *cancellable) { char *data_file, *full_path; GError *error = NULL; GStatBuf stat_buf; char *new_url; if (ignored_parameters) { SoupURI *uri = soup_uri_new (url); const char *query = soup_uri_get_query (uri); if (query) { char *new_query = g_regex_replace (ignored_parameters, query, -1, 0, "", 0, NULL); soup_uri_set_query (uri, *new_query ? new_query : NULL); new_url = soup_uri_to_string (uri, FALSE); soup_uri_free (uri); g_free (new_query); } else { new_url = g_strdup (url); } } else { new_url = g_strdup (url); } if (!config) { g_simple_async_result_set_error (G_SIMPLE_ASYNC_RESULT (result), GRL_NET_WC_ERROR, GRL_NET_WC_ERROR_NETWORK_ERROR, "%s", _("No mock definition found")); g_free (new_url); g_simple_async_result_complete_in_idle (G_SIMPLE_ASYNC_RESULT (result)); g_object_unref (result); return; } data_file = g_key_file_get_value (config, new_url, "data", &error); if (error) { g_simple_async_result_set_error (G_SIMPLE_ASYNC_RESULT (result), GRL_NET_WC_ERROR, GRL_NET_WC_ERROR_NOT_FOUND, _("Could not find mock content %s"), error->message); g_error_free (error); g_free (new_url); g_simple_async_result_complete_in_idle (G_SIMPLE_ASYNC_RESULT (result)); g_object_unref (result); return; } if (data_file[0] != '/') { full_path = g_build_filename (base_path, data_file, NULL); } else { full_path = g_strdup (data_file); } if (g_stat (full_path, &stat_buf) < 0) { g_simple_async_result_set_error (G_SIMPLE_ASYNC_RESULT (result), GRL_NET_WC_ERROR, GRL_NET_WC_ERROR_NOT_FOUND, _("Could not access mock content: %s"), data_file); g_simple_async_result_complete_in_idle (G_SIMPLE_ASYNC_RESULT (result)); g_object_unref (result); g_free (new_url); g_clear_pointer (&data_file, g_free); g_clear_pointer (&full_path, g_free); return; } g_clear_pointer (&data_file, g_free); g_clear_pointer (&full_path, g_free); g_simple_async_result_set_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (result), new_url, NULL); g_simple_async_result_complete_in_idle (G_SIMPLE_ASYNC_RESULT (result)); g_object_unref (result); }
static void _do_token_query(GSignondOauthPlugin *self, GSignondSessionData *session_data, GHashTable* params, GError** error) { gboolean force_request_body_auth; if (gsignond_dictionary_get_boolean(session_data, "ForceClientAuthViaRequestBody", &force_request_body_auth) && force_request_body_auth) { const gchar* client_id = gsignond_dictionary_get_string(session_data, "ClientId"); const gchar* client_secret = gsignond_dictionary_get_string(session_data, "ClientSecret"); if (client_id != NULL && client_secret != NULL) { g_hash_table_insert(params, "client_id", (gchar*)client_id); g_hash_table_insert(params, "client_secret", (gchar*)client_secret); } } const gchar* host = gsignond_dictionary_get_string(session_data, "TokenHost"); if (host == NULL) { *error = g_error_new(GSIGNOND_ERROR, GSIGNOND_ERROR_MISSING_DATA, "TokenHost not set"); return; } gsignond_oauth_plugin_check_host(host, gsignond_session_data_get_allowed_realms (session_data), error); if (*error != NULL) return; const gchar* token_path = gsignond_dictionary_get_string(session_data, "TokenPath"); if (token_path == NULL) { *error = g_error_new(GSIGNOND_ERROR, GSIGNOND_ERROR_MISSING_DATA, "TokenPath not set"); return; } const gchar* token_query_str = gsignond_dictionary_get_string(session_data, "TokenQuery"); SoupURI* open_url = soup_uri_new(NULL); soup_uri_set_scheme(open_url, SOUP_URI_SCHEME_HTTPS); soup_uri_set_host(open_url, host); soup_uri_set_path(open_url, token_path); guint port; if (gsignond_dictionary_get_uint32(session_data, "TokenPort", &port) != FALSE) soup_uri_set_port(open_url, port); if (token_query_str != NULL) { soup_uri_set_query(open_url, token_query_str); } SoupMessage *msg = soup_message_new_from_uri ("POST", open_url); soup_uri_free(open_url); gchar* formdata = soup_form_encode_hash(params); soup_message_set_request (msg, "application/x-www-form-urlencoded", SOUP_MEMORY_TAKE, formdata, strlen (formdata)); soup_session_queue_message (self->soup_session, msg, _http_token_callback, self); }
static gboolean cal_backend_http_load (ECalBackendHttp *backend, const gchar *uri, gchar **out_certificate_pem, GTlsCertificateFlags *out_certificate_errors, GCancellable *cancellable, GError **error) { ECalBackendHttpPrivate *priv = backend->priv; ETimezoneCache *timezone_cache; SoupMessage *soup_message; SoupSession *soup_session; icalcomponent *icalcomp, *subcomp; icalcomponent_kind kind; const gchar *newuri; SoupURI *uri_parsed; GHashTable *old_cache; GSList *comps_in_cache; ESource *source; guint status_code; gulong cancel_id = 0; struct { SoupSession *soup_session; SoupMessage *soup_message; } cancel_data; timezone_cache = E_TIMEZONE_CACHE (backend); soup_session = backend->priv->soup_session; soup_message = cal_backend_http_new_message (backend, uri); if (soup_message == NULL) { g_set_error ( error, SOUP_HTTP_ERROR, SOUP_STATUS_MALFORMED, _("Malformed URI: %s"), uri); return FALSE; } if (G_IS_CANCELLABLE (cancellable)) { cancel_data.soup_session = soup_session; cancel_data.soup_message = soup_message; cancel_id = g_cancellable_connect ( cancellable, G_CALLBACK (cal_backend_http_cancelled), &cancel_data, (GDestroyNotify) NULL); } source = e_backend_get_source (E_BACKEND (backend)); e_soup_ssl_trust_connect (soup_message, source); e_source_set_connection_status (source, E_SOURCE_CONNECTION_STATUS_CONNECTING); status_code = soup_session_send_message (soup_session, soup_message); if (G_IS_CANCELLABLE (cancellable)) g_cancellable_disconnect (cancellable, cancel_id); if (status_code == SOUP_STATUS_NOT_MODIFIED) { e_source_set_connection_status (source, E_SOURCE_CONNECTION_STATUS_CONNECTED); /* attempts with ETag can result in 304 status code */ g_object_unref (soup_message); priv->opened = TRUE; return TRUE; } /* Handle redirection ourselves */ if (SOUP_STATUS_IS_REDIRECTION (status_code)) { gboolean success; newuri = soup_message_headers_get_list ( soup_message->response_headers, "Location"); d (g_message ("Redirected from %s to %s\n", async_context->uri, newuri)); if (newuri != NULL) { gchar *redirected_uri; if (newuri[0]=='/') { g_warning ("Hey! Relative URI returned! Working around...\n"); uri_parsed = soup_uri_new (uri); soup_uri_set_path (uri_parsed, newuri); soup_uri_set_query (uri_parsed, NULL); /* g_free (newuri); */ newuri = soup_uri_to_string (uri_parsed, FALSE); g_message ("Translated URI: %s\n", newuri); soup_uri_free (uri_parsed); } redirected_uri = webcal_to_http_method (newuri, FALSE); success = cal_backend_http_load ( backend, redirected_uri, out_certificate_pem, out_certificate_errors, cancellable, error); g_free (redirected_uri); } else { g_set_error ( error, SOUP_HTTP_ERROR, SOUP_STATUS_BAD_REQUEST, _("Redirected to Invalid URI")); success = FALSE; } if (success) { e_source_set_connection_status (source, E_SOURCE_CONNECTION_STATUS_CONNECTED); } else { e_source_set_connection_status (source, E_SOURCE_CONNECTION_STATUS_DISCONNECTED); } g_object_unref (soup_message); return success; } /* check status code */ if (!SOUP_STATUS_IS_SUCCESSFUL (status_code)) { /* because evolution knows only G_IO_ERROR_CANCELLED */ if (status_code == SOUP_STATUS_CANCELLED) g_set_error ( error, G_IO_ERROR, G_IO_ERROR_CANCELLED, "%s", soup_message->reason_phrase); else g_set_error ( error, SOUP_HTTP_ERROR, status_code, "%s", soup_message->reason_phrase); if (status_code == SOUP_STATUS_SSL_FAILED) { e_source_set_connection_status (source, E_SOURCE_CONNECTION_STATUS_SSL_FAILED); cal_backend_http_extract_ssl_failed_data (soup_message, out_certificate_pem, out_certificate_errors); } else { e_source_set_connection_status (source, E_SOURCE_CONNECTION_STATUS_DISCONNECTED); } g_object_unref (soup_message); empty_cache (backend); return FALSE; } e_source_set_connection_status (source, E_SOURCE_CONNECTION_STATUS_CONNECTED); if (priv->store) { const gchar *etag; etag = soup_message_headers_get_one ( soup_message->response_headers, "ETag"); if (etag != NULL && *etag == '\0') etag = NULL; e_cal_backend_store_put_key_value (priv->store, "ETag", etag); } /* get the calendar from the response */ icalcomp = icalparser_parse_string (soup_message->response_body->data); if (!icalcomp) { g_set_error ( error, SOUP_HTTP_ERROR, SOUP_STATUS_MALFORMED, _("Bad file format.")); g_object_unref (soup_message); empty_cache (backend); return FALSE; } if (icalcomponent_isa (icalcomp) != ICAL_VCALENDAR_COMPONENT) { g_set_error ( error, SOUP_HTTP_ERROR, SOUP_STATUS_MALFORMED, _("Not a calendar.")); icalcomponent_free (icalcomp); g_object_unref (soup_message); empty_cache (backend); return FALSE; } g_object_unref (soup_message); soup_message = NULL; /* Update cache */ old_cache = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); comps_in_cache = e_cal_backend_store_get_components (priv->store); while (comps_in_cache != NULL) { const gchar *uid; ECalComponent *comp = comps_in_cache->data; e_cal_component_get_uid (comp, &uid); g_hash_table_insert (old_cache, g_strdup (uid), e_cal_component_get_as_string (comp)); comps_in_cache = g_slist_remove (comps_in_cache, comps_in_cache->data); g_object_unref (comp); } kind = e_cal_backend_get_kind (E_CAL_BACKEND (backend)); subcomp = icalcomponent_get_first_component (icalcomp, ICAL_ANY_COMPONENT); e_cal_backend_store_freeze_changes (priv->store); while (subcomp) { ECalComponent *comp; icalcomponent_kind subcomp_kind; icalproperty *prop = NULL; subcomp_kind = icalcomponent_isa (subcomp); prop = icalcomponent_get_first_property (subcomp, ICAL_UID_PROPERTY); if (!prop && subcomp_kind == kind) { gchar *new_uid = e_cal_component_gen_uid (); icalcomponent_set_uid (subcomp, new_uid); g_free (new_uid); } if (subcomp_kind == kind) { comp = e_cal_component_new (); if (e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (subcomp))) { const gchar *uid; gpointer orig_key, orig_value; e_cal_component_get_uid (comp, &uid); if (!put_component_to_store (backend, comp)) { g_hash_table_remove (old_cache, uid); } else if (g_hash_table_lookup_extended (old_cache, uid, &orig_key, &orig_value)) { ECalComponent *orig_comp = e_cal_component_new_from_string (orig_value); e_cal_backend_notify_component_modified (E_CAL_BACKEND (backend), orig_comp, comp); g_hash_table_remove (old_cache, uid); if (orig_comp) g_object_unref (orig_comp); } else { e_cal_backend_notify_component_created (E_CAL_BACKEND (backend), comp); } } g_object_unref (comp); } else if (subcomp_kind == ICAL_VTIMEZONE_COMPONENT) { icaltimezone *zone; zone = icaltimezone_new (); icaltimezone_set_component (zone, icalcomponent_new_clone (subcomp)); e_timezone_cache_add_timezone (timezone_cache, zone); icaltimezone_free (zone, 1); } subcomp = icalcomponent_get_next_component (icalcomp, ICAL_ANY_COMPONENT); } e_cal_backend_store_thaw_changes (priv->store); /* notify the removals */ g_hash_table_foreach_remove (old_cache, (GHRFunc) notify_and_remove_from_cache, backend); g_hash_table_destroy (old_cache); /* free memory */ icalcomponent_free (icalcomp); priv->opened = TRUE; return TRUE; }
static void _process_poll_resp(SoupSession *ss, SoupMessage *msg, gpointer user_data) { GWQSession *wqs; const guint8* data; gsize size; SoupBuffer *sBuf; gchar *tmpCStr; JsonParser *jParser; JsonNode *jn; JsonObject *jo; gint32 tmpInt; SoupURI *su; JsonArray *resJa; wqs = (GWQSession*)user_data; GWQ_DBG("poll responsed, retcode=%d, reason:%s\n", msg->status_code, msg->reason_phrase); if (wqs->st != GWQS_ST_IDLE) { goto ERR_OUT; } if (msg->status_code != 200) { GWQ_ERR_OUT(ERR_OUT, "\n"); } sBuf = soup_message_body_flatten(msg->response_body); if (!sBuf) { GWQ_ERR_OUT(ERR_OUT, "\n"); } soup_buffer_get_data(sBuf, &data, &size); if (!data || size <=0 ) { GWQ_ERR_OUT(ERR_FREE_SBUF, "\n"); } GWQ_DBG("bodySize=%d\nbody:%s\n", size, data); if (!(jParser = json_parser_new())) { GWQ_ERR_OUT(ERR_FREE_SBUF, "\n"); } resJa = NULL; if (!json_parser_load_from_data(jParser, (const gchar*)data, size, NULL)) { GWQ_ERR("\n"); } else if (!(jn = json_parser_get_root(jParser)) || !(jo = json_node_get_object(jn))) { GWQ_ERR("\n"); } else if ((tmpInt = json_object_get_int_member(jo, "retcode"))) { GWQ_ERR("poll retcode=%d\n", tmpInt); } else if (!(jn = json_object_get_member(jo, "result")) || !(resJa = json_node_get_array(jn))) { GWQ_ERR("poll no result found\n"); } if (resJa) { json_array_foreach_element(resJa, _PollResultArrayForeach, wqs); } g_object_unref(jParser); soup_buffer_free(sBuf); tmpCStr = g_strdup_printf("clientid=%s&psessionid=%s&t=%ld", wqs->clientId->str, wqs->psessionid->str, GetNowMillisecond() ); su = soup_message_get_uri(msg); soup_uri_set_query(su, tmpCStr); g_free(tmpCStr); GWQ_ERR("Fix me : why soup_session_requeue_message() fails here!!!!!!!!!!!!!!!!!!!!!\n"); //soup_session_requeue_message(wqs->sps, msg); GWQSessionDoPoll(wqs); return; ERR_FREE_J_PARSER: g_object_unref(jParser); ERR_FREE_SBUF: soup_buffer_free(sBuf); ERR_OUT: soup_session_cancel_message(ss, msg, SOUP_STATUS_CANCELLED); }