static void liferea_htmlview_proxy_changed (NetworkMonitor *nm, gpointer userdata) { LifereaHtmlView *htmlview = LIFEREA_HTMLVIEW (userdata); (RENDERER (htmlview)->setProxy) (network_get_proxy_host (), network_get_proxy_port (), network_get_proxy_username (), network_get_proxy_password ()); }
void network_init (void) { gchar *useragent; SoupCookieJar *cookies; gchar *filename; SoupLogger *logger; /* Set an appropriate user agent */ if (g_getenv ("LANG")) { /* e.g. "Liferea/1.10.0 (Linux; de_DE; https://lzone.de/liferea/) AppleWebKit (KHTML, like Gecko)" */ useragent = g_strdup_printf ("Liferea/%s (%s; %s; %s) AppleWebKit (KHTML, like Gecko)", VERSION, OSNAME, g_getenv ("LANG"), HOMEPAGE); } else { /* e.g. "Liferea/1.10.0 (Linux; https://lzone.de/liferea/) AppleWebKit (KHTML, like Gecko)" */ useragent = g_strdup_printf ("Liferea/%s (%s; %s) AppleWebKit (KHTML, like Gecko)", VERSION, OSNAME, HOMEPAGE); } /* Cookies */ filename = common_create_config_filename ("cookies.txt"); cookies = soup_cookie_jar_text_new (filename, FALSE); g_free (filename); /* Initialize libsoup */ session = soup_session_new_with_options (SOUP_SESSION_USER_AGENT, useragent, SOUP_SESSION_TIMEOUT, 120, SOUP_SESSION_IDLE_TIMEOUT, 30, SOUP_SESSION_ADD_FEATURE, cookies, SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_CONTENT_DECODER, NULL); session2 = soup_session_new_with_options (SOUP_SESSION_USER_AGENT, useragent, SOUP_SESSION_TIMEOUT, 120, SOUP_SESSION_IDLE_TIMEOUT, 30, SOUP_SESSION_ADD_FEATURE, cookies, SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_CONTENT_DECODER, SOUP_SESSION_PROXY_URI, NULL, SOUP_SESSION_PROXY_RESOLVER, NULL, NULL); /* Only 'session' gets proxy, 'session2' is for non-proxy requests */ network_set_soup_session_proxy (session, network_get_proxy_detect_mode(), network_get_proxy_host (), network_get_proxy_port (), network_get_proxy_username (), network_get_proxy_password ()); g_signal_connect (session, "authenticate", G_CALLBACK (network_authenticate), NULL); /* Soup debugging */ if (debug_level & DEBUG_NET) { logger = soup_logger_new (SOUP_LOGGER_LOG_HEADERS, -1); soup_session_add_feature (session, SOUP_SESSION_FEATURE (logger)); } g_free (useragent); }
LifereaHtmlView * liferea_htmlview_new (gboolean forceInternalBrowsing) { LifereaHtmlView *htmlview; htmlview = LIFEREA_HTMLVIEW (g_object_new (LIFEREA_HTMLVIEW_TYPE, NULL)); htmlview->priv->forceInternalBrowsing = forceInternalBrowsing; liferea_htmlview_clear (htmlview); g_signal_connect (network_monitor_get (), "online-status-changed", G_CALLBACK (liferea_htmlview_online_status_changed), htmlview); g_signal_connect (network_monitor_get (), "proxy-changed", G_CALLBACK (liferea_htmlview_proxy_changed), htmlview); if (NULL != network_get_proxy_host ()) { debug0 (DEBUG_NET, "Setting initial HTML widget proxy..."); liferea_htmlview_proxy_changed (network_monitor_get (), htmlview); } return htmlview; }
/* Downloads a feed specified in the request structure, returns the downloaded data or NULL in the request structure. If the the webserver reports a permanent redirection, the feed url will be modified and the old URL 'll be freed. The request structure will also contain the HTTP status and the last modified string. */ void network_process_request (const updateJobPtr const job) { SoupMessage *msg; SoupDate *date; g_assert (NULL != job->request); debug1 (DEBUG_NET, "downloading %s", job->request->source); /* Prepare the SoupMessage */ msg = soup_message_new (job->request->postdata ? SOUP_METHOD_POST : SOUP_METHOD_GET, job->request->source); if (!msg) { g_warning ("The request for %s could not be parsed!", job->request->source); return; } /* Set the postdata for the request */ if (job->request->postdata) { soup_message_set_request (msg, "application/x-www-form-urlencoded", SOUP_MEMORY_STATIC, /* libsoup won't free the postdata */ job->request->postdata, strlen (job->request->postdata)); } /* Set the If-Modified-Since: header */ if (job->request->updateState && job->request->updateState->lastModified) { gchar *datestr; date = soup_date_new_from_time_t (job->request->updateState->lastModified); datestr = soup_date_to_string (date, SOUP_DATE_HTTP); soup_message_headers_append (msg->request_headers, "If-Modified-Since", datestr); g_free (datestr); soup_date_free (date); } /* Set the authentication */ if (!job->request->authValue && job->request->options && job->request->options->username && job->request->options->password) { SoupURI *uri = soup_message_get_uri (msg); soup_uri_set_user (uri, job->request->options->username); soup_uri_set_password (uri, job->request->options->password); } if (job->request->authValue) { soup_message_headers_append (msg->request_headers, "Authorization", job->request->authValue); } /* Add requested cookies */ if (job->request->updateState && job->request->updateState->cookies) { soup_message_headers_append (msg->request_headers, "Cookie", job->request->updateState->cookies); soup_message_disable_feature (msg, SOUP_TYPE_COOKIE_JAR); } /* TODO: Right now we send the msg, and if it requires authentication and * we didn't provide one, the petition fails and when the job is processed * it sees it needs authentication and displays a dialog, and if credentials * are entered, it queues a new job with auth credentials. Instead of that, * we should probably handle authentication directly here, connecting the * msg to a callback in case of 401 (see soup_message_add_status_code_handler()) * displaying the dialog ourselves, and requeing the msg if we get credentials */ /* If the feed has "dont use a proxy" selected, disable the proxy for the msg */ if ((job->request->options && job->request->options->dontUseProxy) || (network_get_proxy_host () == NULL)) soup_message_disable_feature (msg, SOUP_TYPE_PROXY_URI_RESOLVER); soup_session_queue_message (session, msg, network_process_callback, job); }