Add camel_session_set/get_socks_proxy()
authorFederico Mena Quintero <federico@novell.com>
Wed, 12 May 2010 20:00:54 +0000 (15:00 -0500)
committerFederico Mena Quintero <federico@novell.com>
Wed, 2 Jun 2010 22:11:29 +0000 (17:11 -0500)
This is the only API that clients should need to call to
set a SOCKS proxy for Camel's TCP connections.

Signed-off-by: Federico Mena Quintero <federico@novell.com>
camel/camel-session.c
camel/camel-session.h

index a091873..df3e98a 100644 (file)
@@ -64,6 +64,9 @@ struct _CamelSessionPrivate {
        GHashTable *thread_msg_op;
        GHashTable *junk_headers;
 
+       char *socks_proxy_host;
+       int socks_proxy_port;
+
        guint check_junk        : 1;
        guint network_available : 1;
        guint online            : 1;
@@ -1101,3 +1104,44 @@ camel_session_unlock (CamelSession *session,
                        g_return_if_reached ();
        }
 }
+
+/**
+ * camel_session_set_socks_proxy:
+ * @session: A #CamelSession
+ * @socks_host: Hostname of the SOCKS proxy, or #NULL for none.
+ * @socks_port: Port number of the SOCKS proxy
+ *
+ * Sets a SOCKS proxy that will be used throughout the @session for TCP connections.
+ */
+void
+camel_session_set_socks_proxy (CamelSession *session, const gchar *socks_host, int socks_port)
+{
+       g_return_if_fail (CAMEL_IS_SESSION (session));
+
+       if (session->priv->socks_proxy_host)
+               g_free (session->priv->socks_proxy_host);
+
+       session->priv->socks_proxy_host = g_strdup (socks_host);
+       session->priv->socks_proxy_port = socks_port;
+}
+
+/**
+ * camel_session_get_socks_proxy:
+ * @session: A #CamelSession
+ * @host_ret: Location to return the SOCKS proxy hostname
+ * @port_ret: Location to return the SOCKS proxy port
+ *
+ * Queries the SOCKS proxy that is configured for a @session.  This will
+ * put #NULL in @hosts_ret if there is no proxy configured.
+ */
+void
+camel_session_get_socks_proxy (CamelSession *session, const char **host_ret, int *port_ret)
+{
+       g_return_if_fail (CAMEL_IS_SESSION (session));
+       g_return_if_fail (host_ret != NULL);
+       g_return_if_fail (port_ret != NULL);
+
+       *host_ret = g_strdup (session->priv->socks_proxy_host);
+       *port_ret = session->priv->socks_proxy_port;
+}
+
index 76c7f60..8ad79e8 100644 (file)
@@ -155,6 +155,14 @@ struct _CamelSessionClass {
 GType          camel_session_get_type          (void);
 void           camel_session_construct         (CamelSession *session,
                                                 const gchar *storage_path);
+
+void            camel_session_set_socks_proxy   (CamelSession *session,
+                                                const gchar *socks_host,
+                                                gint socks_port);
+void            camel_session_get_socks_proxy   (CamelSession *session,
+                                                const char **host_ret,
+                                                int *port_ret);
+
 CamelService * camel_session_get_service       (CamelSession *session,
                                                 const gchar *url_string,
                                                 CamelProviderType type,