changeset 2361:c831816c0b87

Add support for proxy_use_auth.
author William Pitcock <nenolod@atheme.org>
date Mon, 04 Feb 2008 22:55:38 -0600
parents ead24454f4b7
children 5eb15f6cf71e
files src/neon/neon.c
diffstat 1 files changed, 44 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/neon/neon.c	Tue Feb 05 07:37:00 2008 +0300
+++ b/src/neon/neon.c	Mon Feb 04 22:55:38 2008 -0600
@@ -480,6 +480,41 @@
  * -----
  */
 
+static int neon_proxy_auth_cb(void *userdata, const char *realm, int attempt, char *username, char *password) {
+
+    ConfigDb *db;
+    gchar *value = NULL;
+
+    _ENTER;
+
+    if ((db = aud_cfg_db_open()) == NULL) {
+        _DEBUG("<%p> configdb failed to open!", userdata);
+        _LEAVE -1;
+    }
+
+    aud_cfg_db_get_string(db, NULL, "proxy_user", &value);
+    if (!value) {
+        _DEBUG("<%p> proxy_auth requested but no proxy_user", userdata);
+        _LEAVE -1;
+    }
+    g_strlcpy(username, value, NE_ABUFSIZ);
+    value = NULL;
+
+    aud_cfg_db_get_string(db, NULL, "proxy_pass", &value);
+    if (!value) {
+        _DEBUG("<%p> proxy_auth requested but no proxy_pass", userdata);
+        _LEAVE -1;
+    }
+    g_strlcpy(password, value, NE_ABUFSIZ);
+    value = NULL;
+
+    _LEAVE attempt;
+}
+
+/*
+ * -----
+ */
+
 static int open_request(struct neon_handle* handle, unsigned long startbyte) {
 
     int ret;
@@ -574,7 +609,7 @@
     gchar* proxy_port_s;
     gchar* endptr;
     unsigned int proxy_port = 0;
-    gboolean use_proxy;
+    gboolean use_proxy, use_proxy_auth;
 
     _ENTER;
 
@@ -583,6 +618,10 @@
         use_proxy = FALSE;
     }
 
+    if (FALSE == aud_cfg_db_get_bool(db, NULL, "use_proxy_auth", &use_proxy_auth)) {
+        use_proxy_auth = FALSE;
+    }
+
     if (use_proxy) {
         if (FALSE == aud_cfg_db_get_string(db, NULL, "proxy_host", &proxy_host)) {
             _ERROR("<%p> Could not read proxy host, disabling proxy use", handle);
@@ -633,6 +672,10 @@
         if (use_proxy) {
             _DEBUG("<%p> Using proxy: %s:%d", handle, proxy_host, proxy_port);
             ne_session_proxy(handle->session, proxy_host, proxy_port);
+
+            if (use_proxy_auth) {
+                ne_set_proxy_auth(handle->session, neon_proxy_auth_cb, handle);
+            }
         }
 
         _DEBUG("<%p> Creating request", handle);