static SoupSession * create_hkp_soup_session (void) { SoupSession *session; #if WITH_DEBUG SoupLogger *logger; const gchar *env; #endif session = soup_session_async_new_with_options (SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_PROXY_RESOLVER_DEFAULT, NULL); #if WITH_DEBUG env = g_getenv ("G_MESSAGES_DEBUG"); if (env && strstr (env, "seahorse")) { logger = soup_logger_new (SOUP_LOGGER_LOG_BODY, -1); soup_session_add_feature (session, SOUP_SESSION_FEATURE (logger)); g_object_unref (logger); } #endif return session; }
static void aur_client_constructed (GObject * object) { AurClient *client = (AurClient *) (object); gint max_con = 1; if (G_OBJECT_CLASS (aur_client_parent_class)->constructed != NULL) G_OBJECT_CLASS (aur_client_parent_class)->constructed (object); client->soup = soup_session_async_new_with_options (SOUP_SESSION_ASYNC_CONTEXT, client->context, NULL); g_assert (client->soup); if (!g_strcmp0 ("1", g_getenv ("AURENA_DEBUG"))) soup_session_add_feature (client->soup, SOUP_SESSION_FEATURE (soup_logger_new (SOUP_LOGGER_LOG_BODY, -1))); /* Set a 20 second timeout on pings from the server */ g_object_set (G_OBJECT (client->soup), "idle-timeout", 20, NULL); /* 5 second timeout before retrying with new connections */ g_object_set (G_OBJECT (client->soup), "timeout", 5, NULL); if (client->flags & AUR_CLIENT_PLAYER) max_con++; if (client->flags & AUR_CLIENT_CONTROLLER) max_con++; g_object_set (client->soup, "max-conns-per-host", max_con, NULL); try_reconnect (client); }
SoupSession * soup_test_session_new (GType type, ...) { va_list args; const char *propname; SoupSession *session; va_start (args, type); propname = va_arg (args, const char *); session = (SoupSession *)g_object_new_valist (type, propname, args); va_end (args); g_object_set (G_OBJECT (session), SOUP_SESSION_SSL_CA_FILE, SRCDIR "/test-cert.pem", SOUP_SESSION_SSL_STRICT, FALSE, NULL); if (http_debug_level && !logger) { SoupLoggerLogLevel level = MIN ((SoupLoggerLogLevel)http_debug_level, SOUP_LOGGER_LOG_BODY); logger = soup_logger_new (level, -1); } if (logger) soup_session_add_feature (session, SOUP_SESSION_FEATURE (logger)); return session; }
void goa_http_client_check (GoaHttpClient *self, const gchar *uri, const gchar *username, const gchar *password, gboolean accept_ssl_errors, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { CheckData *data; CheckAuthData *auth; SoupLogger *logger; g_return_if_fail (GOA_IS_HTTP_CLIENT (self)); g_return_if_fail (uri != NULL && uri[0] != '\0'); g_return_if_fail (username != NULL && username[0] != '\0'); g_return_if_fail (password != NULL && password[0] != '\0'); g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); data = g_slice_new0 (CheckData); data->res = g_simple_async_result_new (G_OBJECT (self), callback, user_data, goa_http_client_check); data->session = soup_session_new_with_options (SOUP_SESSION_SSL_STRICT, FALSE, NULL); logger = soup_logger_new (SOUP_LOGGER_LOG_BODY, -1); soup_logger_set_printer (logger, http_client_log_printer, NULL, NULL); soup_session_add_feature (data->session, SOUP_SESSION_FEATURE (logger)); g_object_unref (logger); data->accept_ssl_errors = accept_ssl_errors; data->msg = soup_message_new (SOUP_METHOD_GET, uri); soup_message_headers_append (data->msg->request_headers, "Connection", "close"); if (cancellable != NULL) { data->cancellable = g_object_ref (cancellable); data->cancellable_id = g_cancellable_connect (data->cancellable, G_CALLBACK (http_client_check_cancelled_cb), data, NULL); g_simple_async_result_set_check_cancellable (data->res, data->cancellable); } auth = g_slice_new0 (CheckAuthData); auth->username = g_strdup (username); auth->password = g_strdup (password); g_signal_connect_data (data->session, "authenticate", G_CALLBACK (http_client_authenticate), auth, http_client_check_auth_data_free, 0); g_signal_connect (data->session, "request-started", G_CALLBACK (http_client_request_started), data); soup_session_queue_message (data->session, data->msg, http_client_check_response_cb, data); }
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); }
static void snra_client_init (SnraClient * client) { client->soup = soup_session_async_new (); client->server_port = 5457; client->paused = TRUE; if (!g_strcmp0 ("1", g_getenv ("AURENA_DEBUG"))) soup_session_add_feature (client->soup, SOUP_SESSION_FEATURE (soup_logger_new (SOUP_LOGGER_LOG_BODY, -1))); }
void cmd_http_debug() { soup_session_remove_feature (uzbl.net.soup_session, SOUP_SESSION_FEATURE(uzbl.net.soup_logger)); /* do we leak if this doesn't get freed? why does it occasionally crash if freed? */ /*g_free(uzbl.net.soup_logger);*/ uzbl.net.soup_logger = soup_logger_new(uzbl.behave.http_debug, -1); soup_session_add_feature(uzbl.net.soup_session, SOUP_SESSION_FEATURE(uzbl.net.soup_logger)); }
void SoupNetworkSession::setupLogger() { #if !LOG_DISABLED if (LogNetwork.state != WTFLogChannelOn || soup_session_get_feature(m_soupSession.get(), SOUP_TYPE_LOGGER)) return; GRefPtr<SoupLogger> logger = adoptGRef(soup_logger_new(SOUP_LOGGER_LOG_BODY, -1)); soup_session_add_feature(m_soupSession.get(), SOUP_SESSION_FEATURE(logger.get())); soup_logger_set_printer(logger.get(), soupLogPrinter, nullptr, nullptr); #endif }
static void seahorse_hkp_operation_init (SeahorseHKPOperation *hop) { SoupURI *uri; gchar *host; #if DEBUG_HKP_ENABLE SoupLogger *logger; #endif if (seahorse_gconf_get_boolean (GCONF_USE_HTTP_PROXY)) { host = seahorse_gconf_get_string (GCONF_HTTP_PROXY_HOST); if (host) { uri = soup_uri_new (NULL); if (!uri) { g_warning ("creation of SoupURI from '%s' failed", host); } else { soup_uri_set_scheme (uri, SOUP_URI_SCHEME_HTTP); soup_uri_set_host (uri, host); g_free (host); soup_uri_set_port (uri, seahorse_gconf_get_integer (GCONF_PROXY_PORT)); if (seahorse_gconf_get_boolean (GCONF_USE_AUTH)) { char *user, *pass; user = seahorse_gconf_get_string (GCONF_AUTH_USER); soup_uri_set_user (uri, user); g_free (user); pass = seahorse_gconf_get_string (GCONF_AUTH_PASS); soup_uri_set_password (uri, pass); g_free (pass); } hop->session = soup_session_async_new_with_options (SOUP_SESSION_PROXY_URI, uri, NULL); soup_uri_free (uri); } } } /* Without a proxy */ if (!hop->session) hop->session = soup_session_async_new (); #if DEBUG_HKP_ENABLE logger = soup_logger_new (SOUP_LOGGER_LOG_BODY, -1); soup_logger_attach (logger, hop->session); g_object_unref (logger); #endif }
bool ResourceHandle::startHttp(String urlString) { if (!session) { session = soup_session_async_new(); soup_session_add_feature(session, SOUP_SESSION_FEATURE(getCookieJar())); const char* soup_debug = g_getenv("WEBKIT_SOUP_LOGGING"); if (soup_debug) { int soup_debug_level = atoi(soup_debug); SoupLogger* logger = soup_logger_new(static_cast<SoupLoggerLogLevel>(soup_debug_level), -1); soup_logger_attach(logger, session); g_object_unref(logger); } } SoupMessage* msg; msg = soup_message_new(request().httpMethod().utf8().data(), urlString.utf8().data()); g_signal_connect(msg, "restarted", G_CALLBACK(restartedCallback), this); g_signal_connect(msg, "got-headers", G_CALLBACK(gotHeadersCallback), this); g_signal_connect(msg, "got-chunk", G_CALLBACK(gotChunkCallback), this); HTTPHeaderMap customHeaders = d->m_request.httpHeaderFields(); if (!customHeaders.isEmpty()) { HTTPHeaderMap::const_iterator end = customHeaders.end(); for (HTTPHeaderMap::const_iterator it = customHeaders.begin(); it != end; ++it) soup_message_headers_append(msg->request_headers, it->first.utf8().data(), it->second.utf8().data()); } FormData* httpBody = d->m_request.httpBody(); if (httpBody && !httpBody->isEmpty()) { // Making a copy of the request body isn't the most efficient way to // serialize it, but by far the most simple. Dealing with individual // FormData elements and shared buffers should be more memory // efficient. // // This possibly isn't handling file uploads/attachments, for which // shared buffers or streaming should definitely be used. Vector<char> body; httpBody->flatten(body); soup_message_set_request(msg, d->m_request.httpContentType().utf8().data(), SOUP_MEMORY_COPY, body.data(), body.size()); } d->m_msg = static_cast<SoupMessage*>(g_object_ref(msg)); soup_session_queue_message(session, d->m_msg, finishedCallback, this); return true; }
void network_init (void) { gchar *useragent; SoupCookieJar *cookies; gchar *filename; SoupLogger *logger; SoupURI *proxy; /* Set an appropriate user agent */ if (g_getenv ("LANG")) { /* e.g. "Liferea/1.6.0 (Linux; de_DE; http://liferea.sf.net/)" */ useragent = g_strdup_printf ("Liferea/%s (%s; %s; %s)", VERSION, OSNAME, g_getenv ("LANG"), HOMEPAGE); } else { /* e.g. "Liferea/1.6.0 (Linux; http://liferea.sf.net/)" */ useragent = g_strdup_printf ("Liferea/%s (%s; %s)", VERSION, OSNAME, HOMEPAGE); } /* Cookies */ filename = common_create_cache_filename ("", "cookies", "txt"); cookies = soup_cookie_jar_text_new (filename, FALSE); g_free (filename); /* Initialize libsoup */ proxy = network_get_proxy_uri (); session = soup_session_async_new_with_options (SOUP_SESSION_USER_AGENT, useragent, SOUP_SESSION_TIMEOUT, 120, SOUP_SESSION_IDLE_TIMEOUT, 30, SOUP_SESSION_PROXY_URI, proxy, SOUP_SESSION_ADD_FEATURE, cookies, NULL); if (proxy) soup_uri_free (proxy); 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); }
static void ensureSessionIsInitialized(SoupSession* session) { if (g_object_get_data(G_OBJECT(session), "webkit-init")) return; SoupCookieJar* jar = reinterpret_cast<SoupCookieJar*>(soup_session_get_feature(session, SOUP_TYPE_COOKIE_JAR)); if (!jar) soup_session_add_feature(session, SOUP_SESSION_FEATURE(defaultCookieJar())); else setDefaultCookieJar(jar); if (!soup_session_get_feature(session, SOUP_TYPE_LOGGER) && LogNetwork.state == WTFLogChannelOn) { SoupLogger* logger = soup_logger_new(static_cast<SoupLoggerLogLevel>(SOUP_LOGGER_LOG_BODY), -1); soup_logger_attach(logger, session); g_object_unref(logger); } g_object_set_data(G_OBJECT(session), "webkit-init", reinterpret_cast<void*>(0xdeadbeef)); }
void _web_service_send_message (WebService *self, SoupMessage *msg, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data, gpointer source_tag, SoupSessionCallback soup_session_cb, gpointer soup_session_cb_data) { if (self->priv->session == NULL) { self->priv->session = soup_session_new (); #ifdef DEBUG_WEB_CONNECTION { SoupLogger *logger; logger = soup_logger_new (SOUP_LOGGER_LOG_BODY, -1); soup_session_add_feature (self->priv->session, SOUP_SESSION_FEATURE (logger)); g_object_unref (logger); } #endif } _g_object_unref (self->priv->cancellable); self->priv->cancellable = _g_object_ref (cancellable); _g_object_unref (self->priv->result); self->priv->result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, source_tag); self->priv->msg = msg; g_object_add_weak_pointer (G_OBJECT (msg), (gpointer *) &self->priv->msg); soup_session_queue_message (self->priv->session, msg, soup_session_cb, soup_session_cb_data); }
/** * grl_net_wc_set_log_level: * @self: a #GrlNetWc instance * @log_level: the libsoup log level to set [0,3] * * Setting the log level the logger feature is added into * the libsoup session. */ void grl_net_wc_set_log_level (GrlNetWc *self, guint log_level) { SoupLogger *logger; g_return_if_fail (log_level <= 3); g_return_if_fail (GRL_IS_NET_WC (self)); if (self->priv->log_level == log_level) return; soup_session_remove_feature_by_type (self->priv->session, SOUP_TYPE_LOGGER); logger = soup_logger_new ((SoupLoggerLogLevel) log_level, -1); soup_session_add_feature (self->priv->session, SOUP_SESSION_FEATURE (logger)); g_object_unref (logger); self->priv->log_level = (SoupLoggerLogLevel) log_level; }
static void e_cal_backend_http_constructed (GObject *object) { ECalBackendHttp *backend; SoupSession *soup_session; /* Chain up to parent's constructed() method. */ G_OBJECT_CLASS (e_cal_backend_http_parent_class)->constructed (object); soup_session = soup_session_sync_new (); g_object_set ( soup_session, SOUP_SESSION_TIMEOUT, 90, SOUP_SESSION_SSL_STRICT, TRUE, SOUP_SESSION_SSL_USE_SYSTEM_CA_FILE, TRUE, SOUP_SESSION_ACCEPT_LANGUAGE_AUTO, TRUE, NULL); backend = E_CAL_BACKEND_HTTP (object); backend->priv->soup_session = soup_session; e_binding_bind_property ( backend, "proxy-resolver", backend->priv->soup_session, "proxy-resolver", G_BINDING_SYNC_CREATE); g_signal_connect ( backend->priv->soup_session, "authenticate", G_CALLBACK (soup_authenticate), backend); if (g_getenv ("WEBCAL_DEBUG") != NULL) { SoupLogger *logger; logger = soup_logger_new ( SOUP_LOGGER_LOG_BODY, 1024 * 1024); soup_session_add_feature ( backend->priv->soup_session, SOUP_SESSION_FEATURE (logger)); g_object_unref (logger); } }
SoupSession * soup_test_session_new (GType type, ...) { va_list args; const char *propname; SoupSession *session; va_start (args, type); propname = va_arg (args, const char *); session = (SoupSession *)g_object_new_valist (type, propname, args); va_end (args); if (http_debug_level && !logger) { SoupLoggerLogLevel level = MIN ((SoupLoggerLogLevel)http_debug_level, SOUP_LOGGER_LOG_BODY); logger = soup_logger_new (level, -1); } if (logger) soup_session_add_feature (session, SOUP_SESSION_FEATURE (logger)); return session; }
static void webdav_debug_setup (SoupSession *session) { const gchar *debug_str; SoupLogger *logger; SoupLoggerLogLevel level; g_return_if_fail (session != NULL); debug_str = g_getenv ("WEBDAV_DEBUG"); if (!debug_str || !*debug_str) return; if (g_ascii_strcasecmp (debug_str, "all") == 0) level = SOUP_LOGGER_LOG_BODY; else if (g_ascii_strcasecmp (debug_str, "headers") == 0) level = SOUP_LOGGER_LOG_HEADERS; else level = SOUP_LOGGER_LOG_MINIMAL; logger = soup_logger_new (level, 100 * 1024 * 1024); soup_session_add_feature (session, SOUP_SESSION_FEATURE (logger)); g_object_unref (logger); }
bool oauth_login( GtkBuilder *builder, char **username_p, char **auth_token_p, char **auth_secret_p, uint64_t *userid_p, GError **err_p) { #if !USE_LOCAL_CGI const char *token_uri = "https://api.twitter.com/oauth/request_token"; const char *access_uri = "https://api.twitter.com/oauth/access_token"; #else const char *token_uri = "https://localhost/cgi-bin/oauth.cgi/request_token"; const char *access_uri = "https://localhost/cgi-bin/oauth.cgi/access_token"; #endif SoupSession *ss = soup_session_async_new(); #if 0 SoupLogger *logger = soup_logger_new(1, -1); soup_session_add_feature(ss, SOUP_SESSION_FEATURE(logger)); g_object_unref(logger); #endif SoupMessage *msg = make_token_request_msg(token_uri, CONSUMER_KEY, CONSUMER_SECRET); if(msg == NULL) { /* FIXME */ abort(); } soup_session_send_message(ss, msg); bool ok; if(msg->status_code != SOUP_STATUS_OK) { fprintf(stderr, "%s: server returned status %d (%s)\n", __func__, msg->status_code, soup_status_get_phrase(msg->status_code)); ok = false; goto end; } /* interpret the response. */ char **rt_output = oa_parse_response(msg->response_body->data, "oauth_token", "oauth_token_secret", NULL); if(rt_output == NULL) { g_set_error(err_p, 0, EINVAL, "can't parse response data"); ok = false; goto end; } /* do out-of-band OAuth */ const char *req_token = rt_output[0], *req_secret = rt_output[1]; #if !USE_LOCAL_CGI GError *err = NULL; if(!launch_authorization_browser(req_token, &err)) { fprintf(stderr, "warning: browser launching failed: %s\n", err->message); g_error_free(err); } #endif char *pin = query_pin(builder); printf("PIN is: `%s'\n", pin); /* get an access token */ g_object_unref(msg); msg = make_access_token_request_msg(access_uri, req_token, req_secret, pin, CONSUMER_KEY, CONSUMER_SECRET); g_free(pin); if(msg == NULL) { fprintf(stderr, "can't sign access request message!\n"); abort(); } soup_session_send_message(ss, msg); if(msg->status_code != SOUP_STATUS_OK) { fprintf(stderr, "%s: server returned status %d (%s)\n", __func__, msg->status_code, soup_status_get_phrase(msg->status_code)); /* FIXME: handle */ abort(); } char **at_output = oa_parse_response(msg->response_body->data, "oauth_token", "oauth_token_secret", "user_id", "screen_name", NULL); if(at_output == NULL) { /* FIXME: response data parsing fail */ abort(); } /* the payoff */ *auth_token_p = g_strdup(at_output[0]); *auth_secret_p = g_strdup(at_output[1]); *userid_p = strtoull(at_output[2], NULL, 10); *username_p = g_strdup(at_output[3]); printf("login successful! username `%s', userid %llu\n", *username_p, (unsigned long long)*userid_p); g_strfreev(at_output); g_strfreev(rt_output); ok = true; end: g_object_unref(msg); g_object_unref(ss); return ok; }
static void settings_init () { GKeyFile* config; gboolean res = FALSE; char *saveptr; gchar** keys = NULL; if (!config_file) { const char* XDG_CONFIG_HOME = getenv ("XDG_CONFIG_HOME"); if (! XDG_CONFIG_HOME || ! strcmp (XDG_CONFIG_HOME, "")) { XDG_CONFIG_HOME = (char*)XDG_CONFIG_HOME_default; } printf("XDG_CONFIG_HOME: %s\n", XDG_CONFIG_HOME); strcpy (config_file_path, XDG_CONFIG_HOME); strcat (config_file_path, "/uzbl/config"); if (file_exists (config_file_path)) { printf ("Config file %s found.\n", config_file_path); config_file = &config_file_path[0]; } else { // Now we check $XDG_CONFIG_DIRS char *XDG_CONFIG_DIRS = getenv ("XDG_CONFIG_DIRS"); if (! XDG_CONFIG_DIRS || ! strcmp (XDG_CONFIG_DIRS, "")) XDG_CONFIG_DIRS = XDG_CONFIG_DIRS_default; printf("XDG_CONFIG_DIRS: %s\n", XDG_CONFIG_DIRS); char buffer[512]; strcpy (buffer, XDG_CONFIG_DIRS); const gchar* dir = (char *) strtok_r (buffer, ":", &saveptr); while (dir && ! file_exists (config_file_path)) { strcpy (config_file_path, dir); strcat (config_file_path, "/uzbl/config_file_pathig"); if (file_exists (config_file_path)) { printf ("Config file %s found.\n", config_file_path); config_file = &config_file_path[0]; } dir = (char * ) strtok_r (NULL, ":", &saveptr); } } } if (config_file) { config = g_key_file_new (); res = g_key_file_load_from_file (config, config_file, G_KEY_FILE_NONE, NULL); if (res) { printf ("Config %s loaded\n", config_file); } else { fprintf (stderr, "Config %s loading failed\n", config_file); } } else { printf ("No configuration.\n"); } if (res) { history_handler = g_key_file_get_value (config, "behavior", "history_handler", NULL); download_handler = g_key_file_get_value (config, "behavior", "download_handler", NULL); always_insert_mode = g_key_file_get_boolean (config, "behavior", "always_insert_mode", NULL); show_status = g_key_file_get_boolean (config, "behavior", "show_status", NULL); modkey = g_key_file_get_value (config, "behavior", "modkey", NULL); status_top = g_key_file_get_boolean (config, "behavior", "status_top", NULL); if (! fifo_dir) fifo_dir = g_key_file_get_value (config, "behavior", "fifo_dir", NULL); if (! socket_dir) socket_dir = g_key_file_get_value (config, "behavior", "socket_dir", NULL); keys = g_key_file_get_keys (config, "bindings", NULL, NULL); } printf ("History handler: %s\n", (history_handler ? history_handler : "disabled")); printf ("Download manager: %s\n", (download_handler ? download_handler : "disabled")); printf ("Fifo directory: %s\n", (fifo_dir ? fifo_dir : "disabled")); printf ("Socket directory: %s\n", (socket_dir ? socket_dir : "disabled")); printf ("Always insert mode: %s\n", (always_insert_mode ? "TRUE" : "FALSE")); printf ("Show status: %s\n", (show_status ? "TRUE" : "FALSE")); printf ("Status top: %s\n", (status_top ? "TRUE" : "FALSE")); printf ("Modkey: %s\n", (modkey ? modkey : "disabled")); if (! modkey) modkey = ""; //POSSIBLE MODKEY VALUES (COMBINATIONS CAN BE USED) gchar* modkeyup = g_utf8_strup (modkey, -1); if (g_strrstr (modkeyup,"SHIFT") != NULL) modmask |= GDK_SHIFT_MASK; //the Shift key. if (g_strrstr (modkeyup,"LOCK") != NULL) modmask |= GDK_LOCK_MASK; //a Lock key (depending on the modifier mapping of the X server this may either be CapsLock or ShiftLock). if (g_strrstr (modkeyup,"CONTROL") != NULL) modmask |= GDK_CONTROL_MASK; //the Control key. if (g_strrstr (modkeyup,"MOD1") != NULL) modmask |= GDK_MOD1_MASK; //the fourth modifier key (it depends on the modifier mapping of the X server which key is interpreted as this modifier, but normally it is the Alt key). if (g_strrstr (modkeyup,"MOD2") != NULL) modmask |= GDK_MOD2_MASK; //the fifth modifier key (it depends on the modifier mapping of the X server which key is interpreted as this modifier). if (g_strrstr (modkeyup,"MOD3") != NULL) modmask |= GDK_MOD3_MASK; //the sixth modifier key (it depends on the modifier mapping of the X server which key is interpreted as this modifier). if (g_strrstr (modkeyup,"MOD4") != NULL) modmask |= GDK_MOD4_MASK; //the seventh modifier key (it depends on the modifier mapping of the X server which key is interpreted as this modifier). if (g_strrstr (modkeyup,"MOD5") != NULL) modmask |= GDK_MOD5_MASK; //the eighth modifier key (it depends on the modifier mapping of the X server which key is interpreted as this modifier). if (g_strrstr (modkeyup,"BUTTON1") != NULL) modmask |= GDK_BUTTON1_MASK; //the first mouse button. if (g_strrstr (modkeyup,"BUTTON2") != NULL) modmask |= GDK_BUTTON2_MASK; //the second mouse button. if (g_strrstr (modkeyup,"BUTTON3") != NULL) modmask |= GDK_BUTTON3_MASK; //the third mouse button. if (g_strrstr (modkeyup,"BUTTON4") != NULL) modmask |= GDK_BUTTON4_MASK; //the fourth mouse button. if (g_strrstr (modkeyup,"BUTTON5") != NULL) modmask |= GDK_BUTTON5_MASK; //the fifth mouse button. if (g_strrstr (modkeyup,"SUPER") != NULL) modmask |= GDK_SUPER_MASK; //the Super modifier. Since 2.10 if (g_strrstr (modkeyup,"HYPER") != NULL) modmask |= GDK_HYPER_MASK; //the Hyper modifier. Since 2.10 if (g_strrstr (modkeyup,"META") != NULL) modmask |= GDK_META_MASK; //the Meta modifier. Since 2.10 */ free (modkeyup); if (keys) { int i; for (i = 0; keys[i]; i++) { gchar *value = g_key_file_get_string (config, "bindings", keys[i], NULL); add_binding(g_strstrip(keys[i]), value); g_free(value); } g_strfreev(keys); } /* networking options */ if (res) { proxy_url = g_key_file_get_value (config, "network", "proxy_server", NULL); http_debug = g_key_file_get_integer (config, "network", "http_debug", NULL); useragent = g_key_file_get_value (config, "network", "user-agent", NULL); max_conns = g_key_file_get_integer (config, "network", "max_conns", NULL); max_conns_host = g_key_file_get_integer (config, "network", "max_conns_per_host", NULL); } if(proxy_url){ g_object_set(G_OBJECT(soup_session), SOUP_SESSION_PROXY_URI, soup_uri_new(proxy_url), NULL); } if(!(http_debug <= 3)){ http_debug = 0; fprintf(stderr, "Wrong http_debug level, ignoring.\n"); } else if (http_debug > 0) { soup_logger = soup_logger_new(http_debug, -1); soup_session_add_feature(soup_session, SOUP_SESSION_FEATURE(soup_logger)); } if(useragent){ char* newagent = malloc(1024); strcpy(newagent, str_replace("%webkit-major%", itos(WEBKIT_MAJOR_VERSION), useragent)); strcpy(newagent, str_replace("%webkit-minor%", itos(WEBKIT_MINOR_VERSION), newagent)); strcpy(newagent, str_replace("%webkit-micro%", itos(WEBKIT_MICRO_VERSION), newagent)); if (uname (&unameinfo) == -1) { printf("Error getting uname info. Not replacing system-related user agent variables.\n"); } else { strcpy(newagent, str_replace("%sysname%", unameinfo.sysname, newagent)); strcpy(newagent, str_replace("%nodename%", unameinfo.nodename, newagent)); strcpy(newagent, str_replace("%kernrel%", unameinfo.release, newagent)); strcpy(newagent, str_replace("%kernver%", unameinfo.version, newagent)); strcpy(newagent, str_replace("%arch-system%", unameinfo.machine, newagent)); #ifdef _GNU_SOURCE strcpy(newagent, str_replace("%domainname%", unameinfo.domainname, newagent)); #endif } strcpy(newagent, str_replace("%arch-uzbl%", ARCH, newagent)); strcpy(newagent, str_replace("%commit%", COMMIT, newagent)); useragent = malloc(1024); strcpy(useragent, newagent); g_object_set(G_OBJECT(soup_session), SOUP_SESSION_USER_AGENT, useragent, NULL); } if(max_conns >= 1){ g_object_set(G_OBJECT(soup_session), SOUP_SESSION_MAX_CONNS, max_conns, NULL); } if(max_conns_host >= 1){ g_object_set(G_OBJECT(soup_session), SOUP_SESSION_MAX_CONNS_PER_HOST, max_conns_host, NULL); } printf("Proxy configured: %s\n", proxy_url ? proxy_url : "none"); printf("HTTP logging level: %d\n", http_debug); printf("User-agent: %s\n", useragent? useragent : "default"); printf("Maximum connections: %d\n", max_conns ? max_conns : 0); printf("Maximum connections per host: %d\n", max_conns_host ? max_conns_host: 0); //Cookies cookie_text_file = g_key_file_get_value (config, "behavior", "cookie_text_file", NULL); if (cookie_text_file) { printf("Cookie text file location: %s\n", cookie_text_file); soup_cookie = soup_cookie_jar_text_new (cookie_text_file, FALSE); soup_session_add_feature(soup_session, SOUP_SESSION_FEATURE(soup_cookie)); } }
int main (int argc, char **argv) { GOptionContext *opts; const char *url; SoupURI *proxy_uri, *parsed; GError *error = NULL; SoupLogger *logger = NULL; opts = g_option_context_new (NULL); g_option_context_add_main_entries (opts, entries, NULL); if (!g_option_context_parse (opts, &argc, &argv, &error)) { g_printerr ("Could not parse arguments: %s\n", error->message); g_printerr ("%s", g_option_context_get_help (opts, TRUE, NULL)); exit (1); } if (argc != 2) { g_printerr ("%s", g_option_context_get_help (opts, TRUE, NULL)); exit (1); } g_option_context_free (opts); url = argv[1]; parsed = soup_uri_new (url); if (!parsed) { g_printerr ("Could not parse '%s' as a URL\n", url); exit (1); } soup_uri_free (parsed); session = g_object_new (SOUP_TYPE_SESSION, SOUP_SESSION_SSL_CA_FILE, ca_file, SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_CONTENT_DECODER, SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_COOKIE_JAR, SOUP_SESSION_USER_AGENT, "get ", SOUP_SESSION_ACCEPT_LANGUAGE_AUTO, TRUE, NULL); if (ntlm) soup_session_add_feature_by_type (session, SOUP_TYPE_AUTH_NTLM); if (debug) { logger = soup_logger_new (SOUP_LOGGER_LOG_BODY, -1); soup_session_add_feature (session, SOUP_SESSION_FEATURE (logger)); g_object_unref (logger); } if (proxy) { proxy_uri = soup_uri_new (proxy); if (!proxy_uri) { g_printerr ("Could not parse '%s' as URI\n", proxy); exit (1); } g_object_set (G_OBJECT (session), SOUP_SESSION_PROXY_URI, proxy_uri, NULL); soup_uri_free (proxy_uri); } if (!synchronous) loop = g_main_loop_new (NULL, TRUE); get_url (url); if (!synchronous) g_main_loop_unref (loop); return 0; }
static void g_vfs_backend_http_class_init (GVfsBackendHttpClass *klass) { const char *debug; SoupSessionFeature *cookie_jar; GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GVfsBackendClass *backend_class; gobject_class->finalize = g_vfs_backend_http_finalize; backend_class = G_VFS_BACKEND_CLASS (klass); backend_class->try_mount = try_mount; backend_class->try_open_for_read = try_open_for_read; backend_class->try_read = try_read; backend_class->try_seek_on_read = try_seek_on_read; backend_class->try_close_read = try_close_read; backend_class->try_query_info = try_query_info; backend_class->try_query_info_on_read = try_query_info_on_read; backend_class->try_query_fs_info = try_query_fs_info; /* Initialize the SoupSession, common to all backend instances */ the_session = soup_session_new_with_options ("user-agent", "gvfs/" VERSION, NULL); g_object_set (the_session, "ssl-strict", FALSE, NULL); /* Cookie handling - stored temporarlly in memory, mostly useful for * authentication in WebDAV. */ cookie_jar = g_object_new (SOUP_TYPE_COOKIE_JAR, NULL); soup_session_add_feature (the_session, cookie_jar); g_object_unref (cookie_jar); /* Send Accept-Language header (see bug 166795) */ g_object_set (the_session, "accept-language-auto", TRUE, NULL); /* Prevent connection timeouts during long operations like COPY. */ g_object_set (the_session, "timeout", 0, NULL); /* Logging */ debug = g_getenv ("GVFS_HTTP_DEBUG"); if (debug) { SoupLogger *logger; SoupLoggerLogLevel level; if (g_ascii_strcasecmp (debug, "all") == 0 || g_ascii_strcasecmp (debug, "body") == 0) level = SOUP_LOGGER_LOG_BODY; else if (g_ascii_strcasecmp (debug, "header") == 0) level = SOUP_LOGGER_LOG_HEADERS; else level = SOUP_LOGGER_LOG_MINIMAL; logger = soup_logger_new (level, DEBUG_MAX_BODY_SIZE); soup_session_add_feature (the_session, SOUP_SESSION_FEATURE (logger)); g_object_unref (logger); } }
static void g_vfs_backend_http_init (GVfsBackendHttp *backend) { const char *debug; SoupSessionFeature *proxy_resolver; SoupSessionFeature *cookie_jar; SoupSessionFeature *content_decoder; g_vfs_backend_set_user_visible (G_VFS_BACKEND (backend), FALSE); backend->session = soup_session_sync_new_with_options ("user-agent", "gvfs/" VERSION, NULL); backend->session_async = soup_session_async_new_with_options ("user-agent", "gvfs/" VERSION, NULL); /* SoupRequester seems to depend on use-thread-context */ g_object_set (G_OBJECT (backend->session_async), "use-thread-context", TRUE, NULL); /* Proxy handling */ proxy_resolver = g_object_new (SOUP_TYPE_PROXY_RESOLVER_GNOME, NULL); soup_session_add_feature (backend->session, proxy_resolver); soup_session_add_feature (backend->session_async, proxy_resolver); g_object_unref (proxy_resolver); /* Cookie handling - stored temporarlly in memory, mostly useful for * authentication in WebDAV. */ cookie_jar = g_object_new (SOUP_TYPE_COOKIE_JAR, NULL); soup_session_add_feature (backend->session, cookie_jar); soup_session_add_feature (backend->session_async, cookie_jar); g_object_unref (cookie_jar); /* Send Accept-Language header (see bug 166795) */ g_object_set (backend->session, "accept-language-auto", TRUE, NULL); g_object_set (backend->session_async, "accept-language-auto", TRUE, NULL); /* Handle decompression automatically */ content_decoder = g_object_new (SOUP_TYPE_CONTENT_DECODER, NULL); soup_session_add_feature (backend->session, content_decoder); soup_session_add_feature (backend->session_async, content_decoder); g_object_unref (content_decoder); /* Request API */ soup_session_add_feature_by_type (backend->session, SOUP_TYPE_REQUESTER); soup_session_add_feature_by_type (backend->session_async, SOUP_TYPE_REQUESTER); /* Logging */ debug = g_getenv ("GVFS_HTTP_DEBUG"); if (debug) { SoupLogger *logger; SoupLoggerLogLevel level; if (g_ascii_strcasecmp (debug, "all") || g_ascii_strcasecmp (debug, "body")) level = SOUP_LOGGER_LOG_BODY; else if (g_ascii_strcasecmp (debug, "header")) level = SOUP_LOGGER_LOG_HEADERS; else level = SOUP_LOGGER_LOG_MINIMAL; logger = soup_logger_new (level, DEBUG_MAX_BODY_SIZE); soup_session_add_feature (backend->session, SOUP_SESSION_FEATURE (logger)); soup_session_add_feature (backend->session_async, SOUP_SESSION_FEATURE (logger)); g_object_unref (logger); } }