/** * Check if the host is known and switch the URI scheme to https. */ static void request_queued(SoupSessionFeature *feature, SoupSession *session, SoupMessage *msg) { SoupURI *uri = soup_message_get_uri(msg); /* only look for HSTS headers sent over https RFC 6797 7.2*/ if (uri->scheme == SOUP_URI_SCHEME_HTTPS) { soup_message_add_header_handler( msg, "got-headers", HSTS_HEADER_NAME, G_CALLBACK(process_hsts_header), feature ); } }
/** * Check if the host is known and switch the URI scheme to https. */ static void request_queued(SoupSessionFeature *feature, SoupSession *session, SoupMessage *msg) { SoupURI *uri = soup_message_get_uri(msg); HSTSProvider *provider = HSTS_PROVIDER(feature); /* only look for HSTS headers sent over https RFC 6797 7.2*/ if (uri->scheme == SOUP_URI_SCHEME_HTTPS) { soup_message_add_header_handler( msg, "got-headers", HSTS_HEADER_NAME, G_CALLBACK(process_hsts_header), feature ); } else if (should_secure_host(provider, uri->host)) { /* the ports is set by soup uri if scheme is changed */ soup_uri_set_scheme(uri, SOUP_URI_SCHEME_HTTPS); soup_session_requeue_message(session, msg); } }
static void queue_message (SoupSession *session, SoupMessage *msg, SoupSessionCallback callback, gpointer user_data) { SoupSessionPrivate *priv = SOUP_SESSION_GET_PRIVATE (session); SoupMessageQueueItem *item; item = soup_message_queue_append (priv->queue, msg, callback, user_data); soup_message_set_io_status (msg, SOUP_MESSAGE_IO_STATUS_QUEUED); g_signal_connect_after (msg, "finished", G_CALLBACK (message_finished), item); if (!(soup_message_get_flags (msg) & SOUP_MESSAGE_NO_REDIRECT)) { soup_message_add_header_handler ( msg, "got_body", "Location", G_CALLBACK (redirect_handler), session); } g_signal_emit (session, signals[REQUEST_QUEUED], 0, msg); }
static char * soup_auth_digest_get_authorization (SoupAuth *auth, SoupMessage *msg) { SoupAuthDigestPrivate *priv = SOUP_AUTH_DIGEST_GET_PRIVATE (auth); char response[33], *token; char *url, *algorithm; GString *out; SoupURI *uri; uri = soup_message_get_uri (msg); g_return_val_if_fail (uri != NULL, NULL); url = soup_uri_to_string (uri, TRUE); soup_auth_digest_compute_response (msg->method, url, priv->hex_a1, priv->qop, priv->nonce, priv->cnonce, priv->nc, response); out = g_string_new ("Digest "); soup_header_g_string_append_param_quoted (out, "username", priv->user); g_string_append (out, ", "); soup_header_g_string_append_param_quoted (out, "realm", auth->realm); g_string_append (out, ", "); soup_header_g_string_append_param_quoted (out, "nonce", priv->nonce); g_string_append (out, ", "); soup_header_g_string_append_param_quoted (out, "uri", url); g_string_append (out, ", "); algorithm = soup_auth_digest_get_algorithm (priv->algorithm); g_string_append_printf (out, "algorithm=%s", algorithm); g_free (algorithm); g_string_append (out, ", "); soup_header_g_string_append_param_quoted (out, "response", response); if (priv->opaque) { g_string_append (out, ", "); soup_header_g_string_append_param_quoted (out, "opaque", priv->opaque); } if (priv->qop) { char *qop = soup_auth_digest_get_qop (priv->qop); g_string_append (out, ", "); soup_header_g_string_append_param_quoted (out, "cnonce", priv->cnonce); g_string_append_printf (out, ", nc=%.8x, qop=%s", priv->nc, qop); g_free (qop); } g_free (url); priv->nc++; token = g_string_free (out, FALSE); soup_message_add_header_handler (msg, "got_headers", soup_auth_is_for_proxy (auth) ? "Proxy-Authentication-Info" : "Authentication-Info", G_CALLBACK (authentication_info_cb), auth); return token; }
// same stuff as net_get_* but without accumulating headers // push all donwloads to a customizable length queue gboolean download_unblocking( gchar *url, NetStatusCallback cb, gpointer data, gpointer cb2, gpointer cbdata2, guint track, GError **err) { SoupMessage *msg; CallbackInfo *info = NULL; SoupSession *soup_sess; gchar *agstr; STNET *stnet; soup_sess = soup_session_async_new(); #if LIBSOUP_VERSION > 2024000 if (rss_soup_jar) { soup_session_add_feature(soup_sess, SOUP_SESSION_FEATURE(rss_soup_jar)); } #endif if (cb && data) { info = g_new0(CallbackInfo, 1); info->user_cb = cb; info->user_data = data; info->current = 0; info->total = 0; info->ss = soup_sess; } g_signal_connect (soup_sess, "authenticate", G_CALLBACK (authenticate), (gpointer)url); #if LIBSOUP_VERSION < 2003000 g_signal_connect (soup_sess, "reauthenticate", G_CALLBACK (reauthenticate), (gpointer)url); #endif /* Queue an async HTTP request */ msg = soup_message_new ("GET", url); if (!msg) { g_free(info); g_set_error(err, NET_ERROR, NET_ERROR_GENERIC, "%s", soup_status_get_phrase(2)); //invalid url return FALSE; } if (track) { //we want to be able to abort this session by calling //abort_all_soup g_hash_table_insert(rf->session, soup_sess, msg); g_hash_table_insert(rf->abort_session, soup_sess, msg); g_hash_table_insert(rf->key_session, data, soup_sess); } agstr = g_strdup_printf("Evolution/%s; Evolution-RSS/%s", EVOLUTION_VERSION_STRING, VERSION); #if LIBSOUP_VERSION < 2003000 soup_message_add_header (msg->request_headers, "User-Agent", agstr); #else soup_message_headers_append (msg->request_headers, "User-Agent", agstr); #endif g_free(agstr); if (info) { g_signal_connect(G_OBJECT(msg), "got_chunk", G_CALLBACK(got_chunk_cb), info); //FIXME Find a way to free this maybe weak_ref soup_message_set_flags (msg, SOUP_MESSAGE_NO_REDIRECT); soup_message_add_header_handler (msg, "got_body", "Location", G_CALLBACK (redirect_handler), info); } soup_message_body_set_accumulate (msg->response_body, FALSE); stnet = g_new0(STNET, 1); stnet->ss = soup_sess; stnet->sm = msg; stnet->cb2 = cb2; stnet->cbdata2 = cbdata2; stnet->url = url; stnet->callback = idle_callback; stnet->data = stnet; if (!net_qid) net_qid = g_idle_add((GSourceFunc)net_queue_dispatcher, NULL); stnet->callback(stnet->data); //// g_object_add_weak_pointer (G_OBJECT(msg), (gpointer)info); g_object_weak_ref (G_OBJECT(msg), unblock_free, soup_sess); // g_object_weak_ref (G_OBJECT(soup_sess), unblock_free, soup_sess); // GMainLoop *mainloop = g_main_loop_new (g_main_context_default (), FALSE); // g_timeout_add (10 * 1000, &conn_mainloop_quit, mainloop); return TRUE; }
gboolean net_get_unblocking(gchar *url, NetStatusCallback cb, gpointer data, gpointer cb2, gpointer cbdata2, guint track, GError **err) { SoupMessage *msg; CallbackInfo *info = NULL; SoupSession *soup_sess; gchar *agstr; gchar *mainurl = NULL; gchar **res; STNET *stnet; soup_sess = soup_session_async_new(); #if LIBSOUP_VERSION > 2024000 if (rss_soup_jar) { soup_session_add_feature( soup_sess, SOUP_SESSION_FEATURE(rss_soup_jar)); } #endif if (cb && data) { info = g_new0(CallbackInfo, 1); info->user_cb = cb; info->user_data = data; info->current = 0; info->total = 0; info->ss = soup_sess; } /*try to find upstream url to supply a password*/ if (data) { res = g_strsplit(data, ";COMMENT-", 0); if (res[0] && g_str_has_prefix(res[0], "RSS-")) { mainurl = g_strdup(res[0]+4); g_strfreev(res); } } g_signal_connect (soup_sess, "authenticate", G_CALLBACK (authenticate), (gpointer)mainurl?mainurl:g_strdup(url)); #if LIBSOUP_VERSION < 2003000 g_signal_connect (soup_sess, "reauthenticate", G_CALLBACK (reauthenticate), (gpointer)mainurl?mainurl:g_strdup(url)); #endif /* Queue an async HTTP request */ msg = soup_message_new ("GET", url); if (!msg) { if (info) g_free(info); g_set_error(err, NET_ERROR, NET_ERROR_GENERIC, "%s", soup_status_get_phrase(2)); //invalid url return FALSE; } if (track) { //we want to be able to abort this session by calling //abort_all_soup g_hash_table_insert(rf->session, soup_sess, msg); g_hash_table_insert(rf->abort_session, soup_sess, msg); g_hash_table_insert(rf->key_session, data, soup_sess); } agstr = g_strdup_printf("Evolution/%s; Evolution-RSS/%s", EVOLUTION_VERSION_STRING, VERSION); #if LIBSOUP_VERSION < 2003000 soup_message_add_header (msg->request_headers, "User-Agent", agstr); #else soup_message_headers_append (msg->request_headers, "User-Agent", agstr); #endif g_free(agstr); if (info) { g_signal_connect(G_OBJECT(msg), "got_chunk", G_CALLBACK(got_chunk_cb), info); //FIXME Find a way to free this maybe weak_ref soup_message_set_flags (msg, SOUP_MESSAGE_NO_REDIRECT); soup_message_add_header_handler (msg, "got_body", "Location", G_CALLBACK (redirect_handler), info); } stnet = g_new0(STNET, 1); stnet->ss = soup_sess; stnet->sm = msg; stnet->cb2 = cb2; stnet->cbdata2 = cbdata2; stnet->url = g_strdup(url); stnet->callback = queue_callback; stnet->data = stnet; proxify_session_async(proxy, stnet); //free stnet //// g_object_add_weak_pointer (G_OBJECT(msg), (gpointer)info); g_object_weak_ref (G_OBJECT(msg), unblock_free, soup_sess); // g_object_weak_ref (G_OBJECT(soup_sess), unblock_free, soup_sess); return TRUE; }