Permalink
Browse files

Added proxy support.

Based on a patch by Auke Schrijnen.
  • Loading branch information...
1 parent e00f560 commit ab058922eb739f9ce8193e06f3195f06d858cf7c Tilman Sauerbeck committed Dec 17, 2008
Showing with 23 additions and 2 deletions.
  1. +23 −2 src/xmms2-scrobbler.c
View
@@ -46,7 +46,8 @@ static uint32_t seconds_played;
static time_t started_playing, last_unpause;
static int hard_failure_count;
-static char user[64], hashed_password[33];
+static char user[64], hashed_password[33], proxy_host[128];
+static int proxy_port;
static char session_id[256], np_url[256], subm_url[256];
static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
@@ -194,6 +195,18 @@ handle_submission_reponse (void *ptr, size_t size, size_t nmemb,
return total;
}
+static void
+set_proxy (CURL *curl)
+{
+ if (!*proxy_host)
+ return;
+
+ curl_easy_setopt (curl, CURLOPT_PROXY, proxy_host);
+
+ if (proxy_port)
+ curl_easy_setopt (curl, CURLOPT_PROXYPORT, (long) proxy_port);
+}
+
/* perform the handshake and return true on success, false otherwise. */
static bool
do_handshake (void)
@@ -225,6 +238,8 @@ do_handshake (void)
curl = curl_easy_init ();
+ set_proxy (curl);
+
curl_easy_setopt (curl, CURLOPT_URL, post_data);
curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION,
handle_handshake_reponse);
@@ -293,6 +308,8 @@ curl_thread (void *arg)
curl = curl_easy_init ();
+ set_proxy (curl);
+
curl_easy_setopt (curl, CURLOPT_POST, 1);
curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION,
handle_submission_reponse);
@@ -546,7 +563,11 @@ handle_config_line (const char *line, void *user_data)
} else if (!strncmp (line, "password: ", 10)) {
/* we only ever need the hashed password :) */
md5 (&line[10], hashed_password);
- }
+ } else if (!strncmp (line, "proxy: ", 7)) {
+ strncpy (proxy_host, &line[7], sizeof (proxy_host));
+ proxy_host[sizeof (proxy_host) - 1] = 0;
+ } else if (!strncmp (line, "proxy_port: ", 12))
+ proxy_port = atoi (&line[12]);
}
static bool

0 comments on commit ab05892

Please sign in to comment.