Lines 42-47
static char *sc_submit_url,
Link Here
|
42 |
sc_curl_errbuf[CURL_ERROR_SIZE], |
42 |
sc_curl_errbuf[CURL_ERROR_SIZE], |
43 |
*sc_major_error; |
43 |
*sc_major_error; |
44 |
|
44 |
|
|
|
45 |
char* proxy_server = NULL; |
46 |
|
45 |
static void dump_queue(); |
47 |
static void dump_queue(); |
46 |
|
48 |
|
47 |
/* Error functions */ |
49 |
/* Error functions */ |
Lines 227-232
static void hexify(char *pass, int len)
Link Here
|
227 |
|
229 |
|
228 |
static int sc_handshake(void) |
230 |
static int sc_handshake(void) |
229 |
{ |
231 |
{ |
|
|
232 |
pdebug("Handshaking directly", DEBUG); |
233 |
int status; |
234 |
char buf[4096]; |
235 |
CURL *curl; |
236 |
|
237 |
snprintf(buf, sizeof(buf), "%s/?hs=true&p=%s&c=%s&v=%s&u=%s", |
238 |
SCROBBLER_HS_URL, SCROBBLER_VERSION, |
239 |
SCROBBLER_CLI_ID, VERSION, sc_username); |
240 |
|
241 |
curl = curl_easy_init(); |
242 |
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1); |
243 |
curl_easy_setopt(curl, CURLOPT_URL, buf); |
244 |
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, |
245 |
sc_store_res); |
246 |
memset(sc_curl_errbuf, 0, sizeof(sc_curl_errbuf)); |
247 |
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, sc_curl_errbuf); |
248 |
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); |
249 |
status = curl_easy_perform(curl); |
250 |
curl_easy_cleanup(curl); |
251 |
|
252 |
sc_hs_timeout = time(NULL) + SCROBBLER_HS_WAIT; |
253 |
|
254 |
if (status) { |
255 |
pdebug(sc_curl_errbuf, DEBUG); |
256 |
sc_hs_errors++; |
257 |
sc_free_res(); |
258 |
return -1; |
259 |
} |
260 |
|
261 |
if (sc_parse_hs_res()) { |
262 |
sc_hs_errors++; |
263 |
sc_free_res(); |
264 |
return -1; |
265 |
} |
266 |
|
267 |
if (sc_challenge_hash != NULL) { |
268 |
md5_state_t md5state; |
269 |
unsigned char md5pword[16]; |
270 |
|
271 |
md5_init(&md5state); |
272 |
/*pdebug(fmt_vastr("Pass Hash: %s", sc_password), DEBUG);*/ |
273 |
md5_append(&md5state, (unsigned const char *)sc_password, |
274 |
strlen(sc_password)); |
275 |
/*pdebug(fmt_vastr("Challenge Hash: %s", sc_challenge_hash), DEBUG);*/ |
276 |
md5_append(&md5state, (unsigned const char *)sc_challenge_hash, |
277 |
strlen(sc_challenge_hash)); |
278 |
md5_finish(&md5state, md5pword); |
279 |
hexify(md5pword, sizeof(md5pword)); |
280 |
/*pdebug(fmt_vastr("Response Hash: %s", sc_response_hash), DEBUG);*/ |
281 |
} |
282 |
|
283 |
sc_hs_errors = 0; |
284 |
sc_hs_status = 1; |
285 |
|
286 |
sc_free_res(); |
287 |
|
288 |
pdebug(fmt_vastr("submiturl: %s - interval: %d", |
289 |
sc_submit_url, sc_submit_interval), DEBUG); |
290 |
|
291 |
return 0; |
292 |
} |
293 |
|
294 |
static int sc_handshake_proxy(void) |
295 |
{ |
296 |
pdebug("Handshaking through proxy", DEBUG); |
297 |
if (!proxy_server) |
298 |
{ |
299 |
pdebug("No proxy specified", DEBUG); |
300 |
sc_hs_errors++; |
301 |
sc_free_res(); |
302 |
return -1; |
303 |
} |
304 |
pdebug(proxy_server, DEBUG); |
305 |
|
230 |
int status; |
306 |
int status; |
231 |
char buf[4096]; |
307 |
char buf[4096]; |
232 |
CURL *curl; |
308 |
CURL *curl; |
Lines 240-245
static int sc_handshake(void)
Link Here
|
240 |
curl_easy_setopt(curl, CURLOPT_URL, buf); |
316 |
curl_easy_setopt(curl, CURLOPT_URL, buf); |
241 |
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, |
317 |
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, |
242 |
sc_store_res); |
318 |
sc_store_res); |
|
|
319 |
curl_easy_setopt(curl, CURLOPT_PROXY, proxy_server); |
320 |
|
243 |
memset(sc_curl_errbuf, 0, sizeof(sc_curl_errbuf)); |
321 |
memset(sc_curl_errbuf, 0, sizeof(sc_curl_errbuf)); |
244 |
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, sc_curl_errbuf); |
322 |
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, sc_curl_errbuf); |
245 |
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); |
323 |
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); |
Lines 399-405
static int sc_generateentry(GString *sub
Link Here
|
399 |
i = 0; |
477 |
i = 0; |
400 |
#ifdef ALLOW_MULTIPLE |
478 |
#ifdef ALLOW_MULTIPLE |
401 |
q_peekall(1); |
479 |
q_peekall(1); |
402 |
while ((item = q_peekall(0)) && i < 10) { |
480 |
while ((item = q_peekall(0)) /* && i < 10 */ ) { |
403 |
#else |
481 |
#else |
404 |
item = q_peek(); |
482 |
item = q_peek(); |
405 |
#endif |
483 |
#endif |
Lines 427-432
static int sc_generateentry(GString *sub
Link Here
|
427 |
|
505 |
|
428 |
static int sc_submitentry(gchar *entry) |
506 |
static int sc_submitentry(gchar *entry) |
429 |
{ |
507 |
{ |
|
|
508 |
pdebug("Submitting directly", DEBUG); |
509 |
CURL *curl; |
510 |
/* struct HttpPost *post = NULL , *last = NULL; */ |
511 |
int status; |
512 |
GString *submission; |
513 |
|
514 |
curl = curl_easy_init(); |
515 |
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1); |
516 |
curl_easy_setopt(curl, CURLOPT_URL, sc_submit_url); |
517 |
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, |
518 |
sc_store_res); |
519 |
curl_easy_setopt(curl, CURLOPT_USERAGENT, USER_AGENT); |
520 |
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); |
521 |
/*cfa(&post, &last, "debug", "failed");*/ |
522 |
|
523 |
/*pdebug(fmt_vastr("Username: %s", sc_username), DEBUG);*/ |
524 |
submission = g_string_new("u="); |
525 |
g_string_append(submission,(gchar *)sc_username); |
526 |
|
527 |
/*pdebug(fmt_vastr("Response Hash: %s", sc_response_hash), DEBUG);*/ |
528 |
g_string_append(submission,"&s="); |
529 |
g_string_append(submission,(gchar *)sc_response_hash); |
530 |
|
531 |
g_string_append(submission, entry); |
532 |
|
533 |
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, (char *)submission->str); |
534 |
memset(sc_curl_errbuf, 0, sizeof(sc_curl_errbuf)); |
535 |
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, sc_curl_errbuf); |
536 |
|
537 |
/* |
538 |
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); |
539 |
curl_easy_setopt(curl, CURLOPT_TIMEOUT, SCROBBLER_SB_WAIT); |
540 |
*/ |
541 |
|
542 |
status = curl_easy_perform(curl); |
543 |
|
544 |
curl_easy_cleanup(curl); |
545 |
|
546 |
g_string_free(submission,TRUE); |
547 |
|
548 |
if (status) { |
549 |
pdebug(sc_curl_errbuf, DEBUG); |
550 |
sc_sb_errors++; |
551 |
sc_free_res(); |
552 |
return -1; |
553 |
} |
554 |
|
555 |
if (sc_parse_sb_res()) { |
556 |
sc_sb_errors++; |
557 |
sc_free_res(); |
558 |
pdebug(fmt_vastr("Retrying in %d secs, %d elements in queue", |
559 |
sc_submit_interval, q_len()), DEBUG); |
560 |
return -1; |
561 |
} |
562 |
sc_free_res(); |
563 |
return 0; |
564 |
} |
565 |
|
566 |
static int sc_submitentry_proxy(gchar *entry) |
567 |
{ |
568 |
pdebug("Submitting through proxy", DEBUG); |
569 |
if (!proxy_server) |
570 |
{ |
571 |
pdebug("No proxy specified", DEBUG); |
572 |
sc_sb_errors++; |
573 |
sc_free_res(); |
574 |
return -1; |
575 |
} |
576 |
pdebug(proxy_server, DEBUG); |
577 |
|
430 |
CURL *curl; |
578 |
CURL *curl; |
431 |
/* struct HttpPost *post = NULL , *last = NULL; */ |
579 |
/* struct HttpPost *post = NULL , *last = NULL; */ |
432 |
int status; |
580 |
int status; |
Lines 439-444
static int sc_submitentry(gchar *entry)
Link Here
|
439 |
sc_store_res); |
587 |
sc_store_res); |
440 |
curl_easy_setopt(curl, CURLOPT_USERAGENT, USER_AGENT); |
588 |
curl_easy_setopt(curl, CURLOPT_USERAGENT, USER_AGENT); |
441 |
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); |
589 |
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); |
|
|
590 |
curl_easy_setopt(curl, CURLOPT_PROXY, proxy_server); |
442 |
/*cfa(&post, &last, "debug", "failed");*/ |
591 |
/*cfa(&post, &last, "debug", "failed");*/ |
443 |
|
592 |
|
444 |
/*pdebug(fmt_vastr("Username: %s", sc_username), DEBUG);*/ |
593 |
/*pdebug(fmt_vastr("Username: %s", sc_username), DEBUG);*/ |
Lines 527-532
static void sc_handlequeue(pthread_mutex
Link Here
|
527 |
|
676 |
|
528 |
sc_sb_errors = 0; |
677 |
sc_sb_errors = 0; |
529 |
} |
678 |
} |
|
|
679 |
else |
680 |
{ |
681 |
if(!sc_submitentry_proxy(submitentry->str)) |
682 |
{ |
683 |
pthread_mutex_lock(&mutex); |
684 |
|
685 |
#ifdef ALLOW_MULTIPLE |
686 |
q_free(); |
687 |
#else |
688 |
q_get(); |
689 |
#endif |
690 |
/* |
691 |
* This should make sure that the queue doesn't |
692 |
* get submitted multiple times on a nasty |
693 |
* segfault... |
694 |
*/ |
695 |
dump_queue(); |
696 |
|
697 |
pthread_mutex_unlock(&mutex); |
698 |
|
699 |
sc_sb_errors = 0; |
700 |
} |
701 |
|
702 |
} |
530 |
if(sc_sb_errors) |
703 |
if(sc_sb_errors) |
531 |
{ |
704 |
{ |
532 |
if(sc_sb_errors < 5) |
705 |
if(sc_sb_errors < 5) |
Lines 707-713
static void sc_checkhandshake(void)
Link Here
|
707 |
return; |
880 |
return; |
708 |
if (sc_hs_timeout < time(NULL)) |
881 |
if (sc_hs_timeout < time(NULL)) |
709 |
{ |
882 |
{ |
710 |
sc_handshake(); |
883 |
if (sc_handshake()) |
|
|
884 |
sc_handshake_proxy(); |
885 |
|
711 |
|
886 |
|
712 |
if(sc_hs_errors) |
887 |
if(sc_hs_errors) |
713 |
{ |
888 |
{ |