changeset 2904:ff9b4776b938

now scrobbler uses proxy settings; whole scrobbler plugin needs to be re-written using neon
author Andrew O. Shadoura <bugzilla@tut.by>
date Wed, 13 Aug 2008 16:15:29 +0300
parents 9c623f4ac901
children 19c696215a73
files src/scrobbler/gerpok.c src/scrobbler/plugin.c src/scrobbler/plugin.h src/scrobbler/scrobbler.c
diffstat 4 files changed, 45 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/scrobbler/gerpok.c	Wed Aug 13 14:10:14 2008 +0300
+++ b/src/scrobbler/gerpok.c	Wed Aug 13 16:15:29 2008 +0300
@@ -5,9 +5,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdarg.h>
-#include <curl/curl.h>
 #include <stdio.h>
 #include "fmt.h"
+#include "plugin.h"
 #include "scrobbler.h"
 #include "config.h"
 #include <glib.h>
@@ -416,6 +416,7 @@
 			SCROBBLER_CLI_ID, SCROBBLER_IMPLEMENTATION, gerpok_sc_username);
 
 	curl = curl_easy_init();
+        setup_proxy(curl);
 	curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
 	curl_easy_setopt(curl, CURLOPT_URL, buf);
 	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, 
@@ -621,6 +622,7 @@
         GString *submission;
 
 	curl = curl_easy_init();
+        setup_proxy(curl);
 	curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
 	curl_easy_setopt(curl, CURLOPT_URL, gerpok_sc_submit_url);
 	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
--- a/src/scrobbler/plugin.c	Wed Aug 13 14:10:14 2008 +0300
+++ b/src/scrobbler/plugin.c	Wed Aug 13 16:15:29 2008 +0300
@@ -19,6 +19,8 @@
 #include <wchar.h>
 #include <sys/time.h>
 
+#include <curl/curl.h>
+
 #include "plugin.h"
 #include "scrobbler.h"
 #include "gerpok.h"
@@ -338,6 +340,39 @@
 	return NULL;
 }
 
+void setup_proxy(CURL *curl)
+{
+    mcs_handle_t *db;
+    gboolean use_proxy;
+
+    db = aud_cfg_db_open();
+    aud_cfg_db_get_bool(db, NULL, "use_proxy", &use_proxy);
+    if (use_proxy == FALSE)
+    {
+        curl_easy_setopt(curl, CURLOPT_PROXY, "");
+    }
+    else
+    {
+        gchar *proxy_host, *proxy_port;
+        gboolean proxy_use_auth;
+        aud_cfg_db_get_string(db, NULL, "proxy_host", &proxy_host);
+        aud_cfg_db_get_string(db, NULL, "proxy_port", &proxy_port);
+        curl_easy_setopt(curl, CURLOPT_PROXY, proxy_host);
+        curl_easy_setopt(curl, CURLOPT_PROXYPORT, proxy_port);
+        aud_cfg_db_get_bool(db, NULL, "proxy_use_auth", &proxy_use_auth);
+        if (proxy_use_auth != FALSE)
+        {
+            gchar *userpwd, *user, *pass;
+            aud_cfg_db_get_string(db, NULL, "proxy_user", &user);
+            aud_cfg_db_get_string(db, NULL, "proxy_pass", &pass);
+            userpwd = g_strdup_printf("%s:%s", user, pass);
+            curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, userpwd);
+            g_free(userpwd);
+        }
+    }
+    aud_cfg_db_close(db);
+}
+
 GeneralPlugin *scrobbler_gplist[] = { &scrobbler_gp, NULL };
 
 DECLARE_PLUGIN(scrobbler, NULL, NULL, NULL, NULL, NULL, scrobbler_gplist, NULL, NULL);
--- a/src/scrobbler/plugin.h	Wed Aug 13 14:10:14 2008 +0300
+++ b/src/scrobbler/plugin.h	Wed Aug 13 16:15:29 2008 +0300
@@ -1,7 +1,10 @@
 #ifndef PLUGIN_H
 #define PLUGIN_H
 
+#include <curl/curl.h>
+
 void start(void);
 void stop(void);
+void setup_proxy(CURL *curl);
 
 #endif
--- a/src/scrobbler/scrobbler.c	Wed Aug 13 14:10:14 2008 +0300
+++ b/src/scrobbler/scrobbler.c	Wed Aug 13 16:15:29 2008 +0300
@@ -3,9 +3,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdarg.h>
-#include <curl/curl.h>
 #include <stdio.h>
 #include "fmt.h"
+#include "plugin.h"
 #include "scrobbler.h"
 #include "config.h"
 #include "settings.h"
@@ -489,6 +489,7 @@
     g_free(auth_tmp);
 
     curl = curl_easy_init();
+    setup_proxy(curl);
     curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
     curl_easy_setopt(curl, CURLOPT_URL, buf);
     curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, 
@@ -704,6 +705,7 @@
     gchar *entry;
 
     curl = curl_easy_init();
+    setup_proxy(curl);
     curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
     curl_easy_setopt(curl, CURLOPT_URL, sc_np_url);
     curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
@@ -763,6 +765,7 @@
         GString *submission;
 
     curl = curl_easy_init();
+    setup_proxy(curl);
     curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
     curl_easy_setopt(curl, CURLOPT_URL, sc_submit_url);
     curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,