Mercurial > audlegacy-plugins
annotate src/scrobbler/gerpok.c @ 2499:4d6045c20cc5
Include cleanups, part #4.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 31 Mar 2008 15:18:05 +0300 |
parents | 166397a7efe1 |
children | bd3a24b39058 |
rev | line source |
---|---|
344
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
1 #include "settings.h" |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
2 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
3 #include <pthread.h> |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
4 #include <limits.h> |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
5 #include <stdlib.h> |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
6 #include <string.h> |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
7 #include <stdarg.h> |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
8 #include <curl/curl.h> |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
9 #include <stdio.h> |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
10 #include "fmt.h" |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
11 #include "md5.h" |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
12 #include "scrobbler.h" |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
13 #include "config.h" |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
14 #include <glib.h> |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
15 |
1982
0ea55fc6f220
scrobbler: vtable fixing
William Pitcock <nenolod@atheme.org>
parents:
1976
diff
changeset
|
16 #include <audacious/plugin.h> |
732 | 17 #include <audacious/util.h> |
344
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
18 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
19 #define SCROBBLER_HS_URL "http://post.gerpok.com" |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
20 #define SCROBBLER_CLI_ID "aud" |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
21 #define SCROBBLER_HS_WAIT 1800 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
22 #define SCROBBLER_SB_WAIT 10 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
23 #define SCROBBLER_VERSION "1.1" |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
24 #define SCROBBLER_IMPLEMENTATION "0.1" /* This is the implementation, not the player version. */ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
25 #define SCROBBLER_SB_MAXLEN 1024 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
26 #define CACHE_SIZE 1024 |
2441
166397a7efe1
Fixes for scrobbler plugin - skipped tracks, inappropriate scrobbling, re-tabs (Bugzilla #200)
CJ Kucera <pez@apocalyptech.com>
parents:
2267
diff
changeset
|
27 #define ALLOW_MULTIPLE |
344
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
28 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
29 /* Scrobblerbackend for xmms plugin, first draft */ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
30 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
31 static int gerpok_sc_hs_status, |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
32 gerpok_sc_hs_timeout, |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
33 gerpok_sc_hs_errors, |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
34 gerpok_sc_sb_errors, |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
35 gerpok_sc_bad_users, |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
36 gerpok_sc_submit_interval, |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
37 gerpok_sc_submit_timeout, |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
38 gerpok_sc_srv_res_size, |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
39 gerpok_sc_giveup, |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
40 gerpok_sc_major_error_present; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
41 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
42 static char *gerpok_sc_submit_url, |
348
314b7ac7f771
[svn] - handle no account data gracefully (e.g. you only use one of the
nenolod
parents:
344
diff
changeset
|
43 *gerpok_sc_username = NULL, |
314b7ac7f771
[svn] - handle no account data gracefully (e.g. you only use one of the
nenolod
parents:
344
diff
changeset
|
44 *gerpok_sc_password = NULL, |
344
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
45 *gerpok_sc_challenge_hash, |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
46 gerpok_sc_response_hash[33], |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
47 *gerpok_sc_srv_res, |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
48 gerpok_sc_curl_errbuf[CURL_ERROR_SIZE], |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
49 *gerpok_sc_major_error; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
50 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
51 static void dump_queue(); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
52 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
53 /**** Queue stuff ****/ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
54 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
55 #define I_ARTIST(i) i->artist |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
56 #define I_TITLE(i) i->title |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
57 #define I_TIME(i) i->utctime |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
58 #define I_LEN(i) i->len |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
59 #define I_MB(i) i->mb |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
60 #define I_ALBUM(i) i->album |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
61 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
62 typedef struct { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
63 char *artist, |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
64 *title, |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
65 *mb, |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
66 *album, |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
67 *utctime, |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
68 len[16]; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
69 int numtries; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
70 void *next; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
71 } item_t; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
72 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
73 static item_t *q_queue = NULL; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
74 static item_t *q_queue_last = NULL; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
75 static int q_nitems; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
76 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
77 static void q_item_free(item_t *item) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
78 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
79 if (item == NULL) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
80 return; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
81 curl_free(item->artist); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
82 curl_free(item->title); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
83 curl_free(item->utctime); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
84 curl_free(item->mb); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
85 curl_free(item->album); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
86 free(item); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
87 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
88 |
1443
f4d8082668c1
scrobbler: tuple API update
William Pitcock <nenolod@atheme-project.org>
parents:
990
diff
changeset
|
89 static void q_put(Tuple *tuple, int len) |
344
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
90 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
91 item_t *item; |
1443
f4d8082668c1
scrobbler: tuple API update
William Pitcock <nenolod@atheme-project.org>
parents:
990
diff
changeset
|
92 const gchar *album; |
344
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
93 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
94 item = malloc(sizeof(item_t)); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
95 |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1687
diff
changeset
|
96 item->artist = fmt_escape(aud_tuple_get_string(tuple, FIELD_ARTIST, NULL)); |
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1687
diff
changeset
|
97 item->title = fmt_escape(aud_tuple_get_string(tuple, FIELD_TITLE, NULL)); |
344
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
98 item->utctime = fmt_escape(fmt_timestr(time(NULL), 1)); |
1687
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1443
diff
changeset
|
99 g_snprintf(item->len, sizeof(item->len), "%d", len); |
344
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
100 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
101 #ifdef NOTYET |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
102 if(tuple->mb == NULL) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
103 #endif |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
104 item->mb = fmt_escape(""); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
105 #ifdef NOTYET |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
106 else |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
107 item->mb = fmt_escape((char*)tuple->mb); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
108 #endif |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
109 |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1687
diff
changeset
|
110 if((album = aud_tuple_get_string(tuple, FIELD_ALBUM, NULL))) |
344
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
111 item->album = fmt_escape(""); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
112 else |
1443
f4d8082668c1
scrobbler: tuple API update
William Pitcock <nenolod@atheme-project.org>
parents:
990
diff
changeset
|
113 item->album = fmt_escape((char*) album); |
344
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
114 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
115 q_nitems++; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
116 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
117 item->next = NULL; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
118 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
119 if(q_queue_last == NULL) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
120 q_queue = q_queue_last = item; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
121 else |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
122 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
123 q_queue_last->next = item; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
124 q_queue_last = item; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
125 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
126 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
127 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
128 static item_t *q_put2(char *artist, char *title, char *len, char *time, |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
129 char *album, char *mb) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
130 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
131 char *temp = NULL; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
132 item_t *item; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
133 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
134 item = calloc(1, sizeof(item_t)); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
135 temp = fmt_unescape(artist); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
136 item->artist = fmt_escape(temp); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
137 curl_free(temp); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
138 temp = fmt_unescape(title); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
139 item->title = fmt_escape(temp); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
140 curl_free(temp); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
141 memcpy(item->len, len, sizeof(len)); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
142 temp = fmt_unescape(time); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
143 item->utctime = fmt_escape(temp); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
144 curl_free(temp); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
145 temp = fmt_unescape(album); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
146 item->album = fmt_escape(temp); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
147 curl_free(temp); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
148 temp = fmt_unescape(mb); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
149 item->mb = fmt_escape(temp); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
150 curl_free(temp); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
151 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
152 q_nitems++; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
153 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
154 item->next = NULL; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
155 if(q_queue_last == NULL) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
156 q_queue = q_queue_last = item; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
157 else |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
158 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
159 q_queue_last->next = item; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
160 q_queue_last = item; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
161 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
162 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
163 return item; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
164 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
165 |
990
238055a6cb8f
[svn] - remove support for hatena music as hatena ceased their musical profile service.
yaz
parents:
786
diff
changeset
|
166 #if 0 |
344
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
167 static item_t *q_peek(void) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
168 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
169 if (q_nitems == 0) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
170 return NULL; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
171 return q_queue; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
172 } |
990
238055a6cb8f
[svn] - remove support for hatena music as hatena ceased their musical profile service.
yaz
parents:
786
diff
changeset
|
173 #endif |
344
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
174 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
175 static item_t *q_peekall(int rewind) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
176 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
177 static item_t *citem = NULL; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
178 item_t *temp_item; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
179 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
180 if (rewind) { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
181 citem = q_queue; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
182 return NULL; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
183 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
184 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
185 temp_item = citem; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
186 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
187 if(citem != NULL) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
188 citem = citem->next; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
189 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
190 return temp_item; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
191 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
192 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
193 static int q_get(void) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
194 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
195 item_t *item; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
196 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
197 if (q_nitems == 0) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
198 return 0; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
199 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
200 item = q_queue; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
201 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
202 if(item == NULL) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
203 return 0; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
204 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
205 q_nitems--; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
206 q_queue = q_queue->next; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
207 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
208 q_item_free(item); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
209 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
210 if (q_nitems == 0) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
211 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
212 q_queue_last = NULL; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
213 return 0; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
214 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
215 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
216 return -1; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
217 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
218 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
219 static void q_free(void) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
220 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
221 while (q_get()); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
222 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
223 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
224 static int q_len(void) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
225 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
226 return q_nitems; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
227 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
228 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
229 /* Error functions */ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
230 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
231 static void gerpok_sc_throw_error(char *errortxt) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
232 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
233 gerpok_sc_major_error_present = 1; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
234 if(gerpok_sc_major_error == NULL) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
235 gerpok_sc_major_error = strdup(errortxt); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
236 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
237 return; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
238 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
239 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
240 int gerpok_sc_catch_error(void) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
241 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
242 return gerpok_sc_major_error_present; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
243 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
244 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
245 char *gerpok_sc_fetch_error(void) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
246 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
247 return gerpok_sc_major_error; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
248 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
249 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
250 void gerpok_sc_clear_error(void) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
251 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
252 gerpok_sc_major_error_present = 0; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
253 if(gerpok_sc_major_error != NULL) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
254 free(gerpok_sc_major_error); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
255 gerpok_sc_major_error = NULL; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
256 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
257 return; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
258 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
259 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
260 static size_t gerpok_sc_store_res(void *ptr, size_t size, |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
261 size_t nmemb, |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
262 void *stream __attribute__((unused))) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
263 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
264 int len = size * nmemb; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
265 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
266 gerpok_sc_srv_res = realloc(gerpok_sc_srv_res, gerpok_sc_srv_res_size + len + 1); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
267 memcpy(gerpok_sc_srv_res + gerpok_sc_srv_res_size, |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
268 ptr, len); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
269 gerpok_sc_srv_res_size += len; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
270 return len; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
271 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
272 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
273 static void gerpok_sc_free_res(void) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
274 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
275 if(gerpok_sc_srv_res != NULL) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
276 free(gerpok_sc_srv_res); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
277 gerpok_sc_srv_res = NULL; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
278 gerpok_sc_srv_res_size = 0; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
279 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
280 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
281 static int gerpok_sc_parse_hs_res(void) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
282 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
283 char *interval; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
284 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
285 if (!gerpok_sc_srv_res_size) { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
286 pdebug("No reply from server", DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
287 return -1; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
288 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
289 *(gerpok_sc_srv_res + gerpok_sc_srv_res_size) = 0; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
290 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
291 if (!strncmp(gerpok_sc_srv_res, "FAILED ", 7)) { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
292 interval = strstr(gerpok_sc_srv_res, "INTERVAL"); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
293 if(!interval) { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
294 pdebug("missing INTERVAL", DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
295 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
296 else |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
297 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
298 *(interval - 1) = 0; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
299 gerpok_sc_submit_interval = strtol(interval + 8, NULL, 10); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
300 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
301 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
302 /* Throwing a major error, just in case */ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
303 /* gerpok_sc_throw_error(fmt_vastr("%s", gerpok_sc_srv_res)); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
304 gerpok_sc_hs_errors++; */ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
305 pdebug(fmt_vastr("error: %s", gerpok_sc_srv_res), DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
306 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
307 return -1; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
308 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
309 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
310 if (!strncmp(gerpok_sc_srv_res, "UPDATE ", 7)) { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
311 interval = strstr(gerpok_sc_srv_res, "INTERVAL"); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
312 if(!interval) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
313 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
314 pdebug("missing INTERVAL", DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
315 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
316 else |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
317 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
318 *(interval - 1) = 0; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
319 gerpok_sc_submit_interval = strtol(interval + 8, NULL, 10); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
320 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
321 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
322 gerpok_sc_submit_url = strchr(strchr(gerpok_sc_srv_res, '\n') + 1, '\n') + 1; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
323 *(gerpok_sc_submit_url - 1) = 0; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
324 gerpok_sc_submit_url = strdup(gerpok_sc_submit_url); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
325 gerpok_sc_challenge_hash = strchr(gerpok_sc_srv_res, '\n') + 1; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
326 *(gerpok_sc_challenge_hash - 1) = 0; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
327 gerpok_sc_challenge_hash = strdup(gerpok_sc_challenge_hash); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
328 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
329 /* Throwing major error. Need to alert client to update. */ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
330 gerpok_sc_throw_error(fmt_vastr("Please update Audacious.\n" |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
331 "Update available at: http://audacious-media-player.org")); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
332 pdebug(fmt_vastr("update client: %s", gerpok_sc_srv_res + 7), DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
333 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
334 /* |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
335 * Russ isn't clear on whether we can submit with a not-updated |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
336 * client. Neither is RJ. I use what we did before. |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
337 */ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
338 gerpok_sc_giveup = -1; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
339 return -1; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
340 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
341 if (!strncmp(gerpok_sc_srv_res, "UPTODATE\n", 9)) { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
342 gerpok_sc_bad_users = 0; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
343 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
344 interval = strstr(gerpok_sc_srv_res, "INTERVAL"); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
345 if (!interval) { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
346 pdebug("missing INTERVAL", DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
347 /* |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
348 * This is probably a bad thing, but Russ seems to |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
349 * think its OK to assume that an UPTODATE response |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
350 * may not have an INTERVAL... We return -1 anyway. |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
351 */ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
352 return -1; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
353 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
354 else |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
355 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
356 *(interval - 1) = 0; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
357 gerpok_sc_submit_interval = strtol(interval + 8, NULL, 10); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
358 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
359 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
360 gerpok_sc_submit_url = strchr(strchr(gerpok_sc_srv_res, '\n') + 1, '\n') + 1; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
361 *(gerpok_sc_submit_url - 1) = 0; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
362 gerpok_sc_submit_url = strdup(gerpok_sc_submit_url); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
363 gerpok_sc_challenge_hash = strchr(gerpok_sc_srv_res, '\n') + 1; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
364 *(gerpok_sc_challenge_hash - 1) = 0; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
365 gerpok_sc_challenge_hash = strdup(gerpok_sc_challenge_hash); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
366 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
367 return 0; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
368 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
369 if(!strncmp(gerpok_sc_srv_res, "BADUSER", 7)) { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
370 /* Throwing major error. */ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
371 gerpok_sc_throw_error("Incorrect username/password.\n" |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
372 "Please fix in configuration."); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
373 pdebug("incorrect username/password", DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
374 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
375 interval = strstr(gerpok_sc_srv_res, "INTERVAL"); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
376 if(!interval) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
377 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
378 pdebug("missing INTERVAL", DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
379 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
380 else |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
381 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
382 *(interval - 1) = 0; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
383 gerpok_sc_submit_interval = strtol(interval + 8, NULL, 10); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
384 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
385 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
386 return -1; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
387 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
388 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
389 pdebug(fmt_vastr("unknown server-reply '%s'", gerpok_sc_srv_res), DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
390 return -1; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
391 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
392 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
393 static void hexify(char *pass, int len) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
394 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
395 char *bp = gerpok_sc_response_hash; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
396 char hexchars[] = "0123456789abcdef"; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
397 int i; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
398 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
399 memset(gerpok_sc_response_hash, 0, sizeof(gerpok_sc_response_hash)); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
400 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
401 for(i = 0; i < len; i++) { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
402 *(bp++) = hexchars[(pass[i] >> 4) & 0x0f]; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
403 *(bp++) = hexchars[pass[i] & 0x0f]; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
404 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
405 *bp = 0; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
406 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
407 return; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
408 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
409 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
410 static int gerpok_sc_handshake(void) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
411 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
412 int status; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
413 char buf[4096]; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
414 CURL *curl; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
415 |
1687
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1443
diff
changeset
|
416 g_snprintf(buf, sizeof(buf), "%s/?hs=true&p=%s&c=%s&v=%s&u=%s", |
344
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
417 SCROBBLER_HS_URL, SCROBBLER_VERSION, |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
418 SCROBBLER_CLI_ID, SCROBBLER_IMPLEMENTATION, gerpok_sc_username); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
419 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
420 curl = curl_easy_init(); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
421 curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
422 curl_easy_setopt(curl, CURLOPT_URL, buf); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
423 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
424 gerpok_sc_store_res); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
425 memset(gerpok_sc_curl_errbuf, 0, sizeof(gerpok_sc_curl_errbuf)); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
426 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, gerpok_sc_curl_errbuf); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
427 curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); |
401
192004e2a1b7
[svn] - add connection timeout option to curl_easy_perform(). hopefully, audacious can quit smoothly even though last.fm server goes down.
yaz
parents:
348
diff
changeset
|
428 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); |
192004e2a1b7
[svn] - add connection timeout option to curl_easy_perform(). hopefully, audacious can quit smoothly even though last.fm server goes down.
yaz
parents:
348
diff
changeset
|
429 curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, SC_CURL_TIMEOUT); |
344
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
430 status = curl_easy_perform(curl); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
431 curl_easy_cleanup(curl); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
432 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
433 gerpok_sc_hs_timeout = time(NULL) + SCROBBLER_HS_WAIT; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
434 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
435 if (status) { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
436 pdebug(gerpok_sc_curl_errbuf, DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
437 gerpok_sc_hs_errors++; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
438 gerpok_sc_free_res(); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
439 return -1; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
440 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
441 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
442 if (gerpok_sc_parse_hs_res()) { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
443 gerpok_sc_hs_errors++; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
444 gerpok_sc_free_res(); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
445 return -1; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
446 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
447 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
448 if (gerpok_sc_challenge_hash != NULL) { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
449 md5_state_t md5state; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
450 unsigned char md5pword[16]; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
451 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
452 md5_init(&md5state); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
453 /*pdebug(fmt_vastr("Pass Hash: %s", gerpok_sc_password), DEBUG);*/ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
454 md5_append(&md5state, (unsigned const char *)gerpok_sc_password, |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
455 strlen(gerpok_sc_password)); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
456 /*pdebug(fmt_vastr("Challenge Hash: %s", gerpok_sc_challenge_hash), DEBUG);*/ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
457 md5_append(&md5state, (unsigned const char *)gerpok_sc_challenge_hash, |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
458 strlen(gerpok_sc_challenge_hash)); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
459 md5_finish(&md5state, md5pword); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
460 hexify((char*)md5pword, sizeof(md5pword)); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
461 /*pdebug(fmt_vastr("Response Hash: %s", gerpok_sc_response_hash), DEBUG);*/ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
462 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
463 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
464 gerpok_sc_hs_errors = 0; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
465 gerpok_sc_hs_status = 1; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
466 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
467 gerpok_sc_free_res(); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
468 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
469 pdebug(fmt_vastr("submiturl: %s - interval: %d", |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
470 gerpok_sc_submit_url, gerpok_sc_submit_interval), DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
471 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
472 return 0; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
473 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
474 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
475 static int gerpok_sc_parse_sb_res(void) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
476 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
477 char *ch, *ch2; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
478 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
479 if (!gerpok_sc_srv_res_size) { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
480 pdebug("No response from server", DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
481 return -1; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
482 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
483 *(gerpok_sc_srv_res + gerpok_sc_srv_res_size) = 0; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
484 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
485 if (!strncmp(gerpok_sc_srv_res, "OK", 2)) { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
486 if ((ch = strstr(gerpok_sc_srv_res, "INTERVAL"))) { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
487 gerpok_sc_submit_interval = strtol(ch + 8, NULL, 10); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
488 pdebug(fmt_vastr("got new interval: %d", |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
489 gerpok_sc_submit_interval), DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
490 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
491 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
492 pdebug(fmt_vastr("submission ok: %s", gerpok_sc_srv_res), DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
493 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
494 return 0; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
495 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
496 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
497 if (!strncmp(gerpok_sc_srv_res, "BADAUTH", 7)) { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
498 if ((ch = strstr(gerpok_sc_srv_res, "INTERVAL"))) { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
499 gerpok_sc_submit_interval = strtol(ch + 8, NULL, 10); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
500 pdebug(fmt_vastr("got new interval: %d", |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
501 gerpok_sc_submit_interval), DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
502 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
503 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
504 pdebug("incorrect username/password", DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
505 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
506 gerpok_sc_giveup = 0; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
507 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
508 /* |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
509 * We obviously aren't authenticated. The server might have |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
510 * lost our handshake status though, so let's try |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
511 * re-handshaking... This might not be proper. |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
512 * (we don't give up) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
513 */ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
514 gerpok_sc_hs_status = 0; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
515 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
516 if(gerpok_sc_challenge_hash != NULL) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
517 free(gerpok_sc_challenge_hash); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
518 if(gerpok_sc_submit_url != NULL) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
519 free(gerpok_sc_submit_url); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
520 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
521 gerpok_sc_challenge_hash = gerpok_sc_submit_url = NULL; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
522 gerpok_sc_bad_users++; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
523 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
524 if(gerpok_sc_bad_users > 2) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
525 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
526 pdebug("3 BADAUTH returns on submission. Halting " |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
527 "submissions until login fixed.", DEBUG) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
528 gerpok_sc_throw_error("Incorrect username/password.\n" |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
529 "Please fix in configuration."); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
530 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
531 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
532 return -1; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
533 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
534 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
535 if (!strncmp(gerpok_sc_srv_res, "FAILED", 6)) { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
536 if ((ch = strstr(gerpok_sc_srv_res, "INTERVAL"))) { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
537 gerpok_sc_submit_interval = strtol(ch + 8, NULL, 10); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
538 pdebug(fmt_vastr("got new interval: %d", |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
539 gerpok_sc_submit_interval), DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
540 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
541 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
542 /* This could be important. (Such as FAILED - Get new plugin) */ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
543 /*gerpok_sc_throw_error(fmt_vastr("%s", gerpok_sc_srv_res));*/ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
544 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
545 pdebug(gerpok_sc_srv_res, DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
546 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
547 return -1; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
548 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
549 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
550 if (!strncmp(gerpok_sc_srv_res, "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">", 50)) { |
786
c23705487009
[svn] - avoid crash when error message doesn't contain <TITLE>.
yaz
parents:
733
diff
changeset
|
551 ch = strstr(gerpok_sc_srv_res, "<TITLE>"); |
344
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
552 ch2 = strstr(gerpok_sc_srv_res, "</TITLE>"); |
786
c23705487009
[svn] - avoid crash when error message doesn't contain <TITLE>.
yaz
parents:
733
diff
changeset
|
553 if (ch != NULL && ch2 != NULL) { |
c23705487009
[svn] - avoid crash when error message doesn't contain <TITLE>.
yaz
parents:
733
diff
changeset
|
554 ch += strlen("<TITLE>"); |
c23705487009
[svn] - avoid crash when error message doesn't contain <TITLE>.
yaz
parents:
733
diff
changeset
|
555 *ch2 = '\0'; |
344
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
556 |
786
c23705487009
[svn] - avoid crash when error message doesn't contain <TITLE>.
yaz
parents:
733
diff
changeset
|
557 pdebug(fmt_vastr("HTTP Error (%d): '%s'", |
c23705487009
[svn] - avoid crash when error message doesn't contain <TITLE>.
yaz
parents:
733
diff
changeset
|
558 atoi(ch), ch + 4), DEBUG); |
c23705487009
[svn] - avoid crash when error message doesn't contain <TITLE>.
yaz
parents:
733
diff
changeset
|
559 // *ch2 = '<'; // needed? --yaz |
c23705487009
[svn] - avoid crash when error message doesn't contain <TITLE>.
yaz
parents:
733
diff
changeset
|
560 } |
344
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
561 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
562 return -1; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
563 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
564 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
565 pdebug(fmt_vastr("unknown server-reply %s", gerpok_sc_srv_res), DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
566 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
567 return -1; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
568 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
569 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
570 static gchar *gerpok_sc_itemtag(char c, int n, char *str) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
571 { |
1687
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1443
diff
changeset
|
572 static char buf[SCROBBLER_SB_MAXLEN]; |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1443
diff
changeset
|
573 g_snprintf(buf, SCROBBLER_SB_MAXLEN, "&%c[%d]=%s", c, n, str); |
d158ce84fda7
Modified for Tuplez/plugin API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1443
diff
changeset
|
574 return buf; |
344
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
575 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
576 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
577 #define cfa(f, l, n, v) \ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
578 curl_formadd(f, l, CURLFORM_COPYNAME, n, \ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
579 CURLFORM_PTRCONTENTS, v, CURLFORM_END) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
580 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
581 static int gerpok_sc_generateentry(GString *submission) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
582 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
583 int i; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
584 item_t *item; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
585 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
586 i = 0; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
587 #ifdef ALLOW_MULTIPLE |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
588 q_peekall(1); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
589 while ((item = q_peekall(0)) && i < 10) { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
590 #else |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
591 item = q_peek(); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
592 #endif |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
593 if (!item) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
594 return i; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
595 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
596 g_string_append(submission,gerpok_sc_itemtag('a',i,I_ARTIST(item))); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
597 g_string_append(submission,gerpok_sc_itemtag('t',i,I_TITLE(item))); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
598 g_string_append(submission,gerpok_sc_itemtag('l',i,I_LEN(item))); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
599 g_string_append(submission,gerpok_sc_itemtag('i',i,I_TIME(item))); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
600 g_string_append(submission,gerpok_sc_itemtag('m',i,I_MB(item))); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
601 g_string_append(submission,gerpok_sc_itemtag('b',i,I_ALBUM(item))); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
602 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
603 pdebug(fmt_vastr("a[%d]=%s t[%d]=%s l[%d]=%s i[%d]=%s m[%d]=%s b[%d]=%s", |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
604 i, I_ARTIST(item), |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
605 i, I_TITLE(item), |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
606 i, I_LEN(item), |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
607 i, I_TIME(item), |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
608 i, I_MB(item), |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
609 i, I_ALBUM(item)), DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
610 #ifdef ALLOW_MULTIPLE |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
611 i++; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
612 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
613 #endif |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
614 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
615 return i; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
616 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
617 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
618 static int gerpok_sc_submitentry(gchar *entry) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
619 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
620 CURL *curl; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
621 /* struct HttpPost *post = NULL , *last = NULL; */ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
622 int status; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
623 GString *submission; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
624 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
625 curl = curl_easy_init(); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
626 curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
627 curl_easy_setopt(curl, CURLOPT_URL, gerpok_sc_submit_url); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
628 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
629 gerpok_sc_store_res); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
630 curl_easy_setopt(curl, CURLOPT_USERAGENT, USER_AGENT); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
631 curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
632 /*cfa(&post, &last, "debug", "failed");*/ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
633 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
634 /*pdebug(fmt_vastr("Username: %s", gerpok_sc_username), DEBUG);*/ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
635 submission = g_string_new("u="); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
636 g_string_append(submission,(gchar *)gerpok_sc_username); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
637 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
638 /*pdebug(fmt_vastr("Response Hash: %s", gerpok_sc_response_hash), DEBUG);*/ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
639 g_string_append(submission,"&s="); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
640 g_string_append(submission,(gchar *)gerpok_sc_response_hash); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
641 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
642 g_string_append(submission, entry); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
643 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
644 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, (char *)submission->str); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
645 memset(gerpok_sc_curl_errbuf, 0, sizeof(gerpok_sc_curl_errbuf)); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
646 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, gerpok_sc_curl_errbuf); |
401
192004e2a1b7
[svn] - add connection timeout option to curl_easy_perform(). hopefully, audacious can quit smoothly even though last.fm server goes down.
yaz
parents:
348
diff
changeset
|
647 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); |
192004e2a1b7
[svn] - add connection timeout option to curl_easy_perform(). hopefully, audacious can quit smoothly even though last.fm server goes down.
yaz
parents:
348
diff
changeset
|
648 curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, SC_CURL_TIMEOUT); |
344
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
649 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
650 /* |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
651 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
652 curl_easy_setopt(curl, CURLOPT_TIMEOUT, SCROBBLER_SB_WAIT); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
653 */ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
654 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
655 status = curl_easy_perform(curl); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
656 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
657 curl_easy_cleanup(curl); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
658 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
659 g_string_free(submission,TRUE); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
660 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
661 if (status) { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
662 pdebug(gerpok_sc_curl_errbuf, DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
663 gerpok_sc_sb_errors++; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
664 gerpok_sc_free_res(); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
665 return -1; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
666 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
667 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
668 if (gerpok_sc_parse_sb_res()) { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
669 gerpok_sc_sb_errors++; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
670 gerpok_sc_free_res(); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
671 pdebug(fmt_vastr("Retrying in %d secs, %d elements in queue", |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
672 gerpok_sc_submit_interval, q_len()), DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
673 return -1; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
674 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
675 gerpok_sc_free_res(); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
676 return 0; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
677 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
678 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
679 static void gerpok_sc_handlequeue(GMutex *mutex) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
680 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
681 GString *submitentry; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
682 int nsubmit; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
683 int wait; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
684 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
685 if(gerpok_sc_submit_timeout < time(NULL) && gerpok_sc_bad_users < 3) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
686 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
687 submitentry = g_string_new(""); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
688 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
689 g_mutex_lock(mutex); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
690 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
691 nsubmit = gerpok_sc_generateentry(submitentry); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
692 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
693 g_mutex_unlock(mutex); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
694 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
695 if (nsubmit > 0) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
696 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
697 pdebug(fmt_vastr("Number submitting: %d", nsubmit), DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
698 pdebug(fmt_vastr("Submission: %s", submitentry->str), DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
699 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
700 if(!gerpok_sc_submitentry(submitentry->str)) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
701 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
702 g_mutex_lock(mutex); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
703 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
704 #ifdef ALLOW_MULTIPLE |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
705 q_free(); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
706 #else |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
707 q_get(); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
708 #endif |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
709 /* |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
710 * This should make sure that the queue doesn't |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
711 * get submitted multiple times on a nasty |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
712 * segfault... |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
713 */ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
714 dump_queue(); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
715 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
716 g_mutex_unlock(mutex); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
717 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
718 gerpok_sc_sb_errors = 0; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
719 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
720 if(gerpok_sc_sb_errors) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
721 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
722 if(gerpok_sc_sb_errors < 5) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
723 /* Retry after 1 min */ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
724 wait = 60; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
725 else |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
726 wait = /* gerpok_sc_submit_interval + */ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
727 ( ((gerpok_sc_sb_errors - 5) < 7) ? |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
728 (60 << (gerpok_sc_sb_errors-5)) : |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
729 7200 ); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
730 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
731 gerpok_sc_submit_timeout = time(NULL) + wait; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
732 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
733 pdebug(fmt_vastr("Error while submitting. " |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
734 "Retrying after %d seconds.", wait), |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
735 DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
736 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
737 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
738 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
739 g_string_free(submitentry, TRUE); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
740 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
741 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
742 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
743 static void read_cache(void) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
744 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
745 FILE *fd; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
746 char buf[PATH_MAX], *cache = NULL, *ptr1, *ptr2; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
747 int cachesize, written, i = 0; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
748 item_t *item; |
2267
2e961ce4bfe8
Fixes memory leaks that are visible during startup in scrobbler plugin (Bugzilla #26)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
1982
diff
changeset
|
749 gchar* config_datadir; |
344
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
750 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
751 cachesize = written = 0; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
752 |
2267
2e961ce4bfe8
Fixes memory leaks that are visible during startup in scrobbler plugin (Bugzilla #26)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
1982
diff
changeset
|
753 config_datadir = audacious_get_localdir(); |
2e961ce4bfe8
Fixes memory leaks that are visible during startup in scrobbler plugin (Bugzilla #26)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
1982
diff
changeset
|
754 g_snprintf(buf, sizeof(buf), "%s/gerpokqueue.txt", config_datadir); |
2e961ce4bfe8
Fixes memory leaks that are visible during startup in scrobbler plugin (Bugzilla #26)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
1982
diff
changeset
|
755 g_free(config_datadir); |
344
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
756 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
757 if (!(fd = fopen(buf, "r"))) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
758 return; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
759 pdebug(fmt_vastr("Opening %s", buf), DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
760 while(!feof(fd)) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
761 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
762 cachesize += CACHE_SIZE; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
763 cache = realloc(cache, cachesize + 1); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
764 written += fread(cache + written, 1, CACHE_SIZE, fd); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
765 cache[written] = '\0'; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
766 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
767 fclose(fd); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
768 ptr1 = cache; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
769 while(ptr1 < cache + written - 1) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
770 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
771 char *artist, *title, *len, *time, *album, *mb; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
772 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
773 pdebug("Pushed:", DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
774 ptr2 = strchr(ptr1, ' '); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
775 artist = calloc(1, ptr2 - ptr1 + 1); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
776 strncpy(artist, ptr1, ptr2 - ptr1); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
777 ptr1 = ptr2 + 1; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
778 ptr2 = strchr(ptr1, ' '); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
779 title = calloc(1, ptr2 - ptr1 + 1); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
780 strncpy(title, ptr1, ptr2 - ptr1); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
781 ptr1 = ptr2 + 1; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
782 ptr2 = strchr(ptr1, ' '); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
783 len = calloc(1, ptr2 - ptr1 + 1); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
784 strncpy(len, ptr1, ptr2 - ptr1); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
785 ptr1 = ptr2 + 1; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
786 ptr2 = strchr(ptr1, ' '); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
787 time = calloc(1, ptr2 - ptr1 + 1); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
788 strncpy(time, ptr1, ptr2 - ptr1); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
789 ptr1 = ptr2 + 1; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
790 ptr2 = strchr(ptr1, ' '); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
791 album = calloc(1, ptr2 - ptr1 + 1); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
792 strncpy(album, ptr1, ptr2 - ptr1); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
793 ptr1 = ptr2 + 1; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
794 ptr2 = strchr(ptr1, '\n'); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
795 if(ptr2 != NULL) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
796 *ptr2 = '\0'; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
797 mb = calloc(1, strlen(ptr1) + 1); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
798 strncpy(mb, ptr1, strlen(ptr1)); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
799 if(ptr2 != NULL) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
800 *ptr2 = '\n'; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
801 /* Why is our save printing out CR/LF? */ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
802 ptr1 = ptr2 + 1; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
803 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
804 item = q_put2(artist, title, len, time, album, mb); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
805 pdebug(fmt_vastr("a[%d]=%s t[%d]=%s l[%d]=%s i[%d]=%s m[%d]=%s b[%d]=%s", |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
806 i, I_ARTIST(item), |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
807 i, I_TITLE(item), |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
808 i, I_LEN(item), |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
809 i, I_TIME(item), |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
810 i, I_MB(item), |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
811 i, I_ALBUM(item)), DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
812 free(artist); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
813 free(title); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
814 free(len); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
815 free(time); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
816 free(album); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
817 free(mb); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
818 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
819 i++; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
820 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
821 pdebug("Done loading cache.", DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
822 free(cache); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
823 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
824 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
825 static void dump_queue(void) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
826 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
827 FILE *fd; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
828 item_t *item; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
829 char *home, buf[PATH_MAX]; |
2267
2e961ce4bfe8
Fixes memory leaks that are visible during startup in scrobbler plugin (Bugzilla #26)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
1982
diff
changeset
|
830 gchar* config_datadir; |
344
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
831 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
832 /*pdebug("Entering dump_queue();", DEBUG);*/ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
833 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
834 if (!(home = getenv("HOME"))) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
835 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
836 pdebug("No HOME directory found. Cannot dump queue.", DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
837 return; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
838 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
839 |
2267
2e961ce4bfe8
Fixes memory leaks that are visible during startup in scrobbler plugin (Bugzilla #26)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
1982
diff
changeset
|
840 config_datadir = audacious_get_localdir(); |
2e961ce4bfe8
Fixes memory leaks that are visible during startup in scrobbler plugin (Bugzilla #26)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
1982
diff
changeset
|
841 g_snprintf(buf, sizeof(buf), "%s/gerpokqueue.txt", config_datadir); |
2e961ce4bfe8
Fixes memory leaks that are visible during startup in scrobbler plugin (Bugzilla #26)
Jussi Judin <jjudin+audacious@iki.fi>
parents:
1982
diff
changeset
|
842 g_free(config_datadir); |
344
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
843 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
844 if (!(fd = fopen(buf, "w"))) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
845 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
846 pdebug(fmt_vastr("Failure opening %s", buf), DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
847 return; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
848 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
849 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
850 pdebug(fmt_vastr("Opening %s", buf), DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
851 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
852 q_peekall(1); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
853 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
854 while ((item = q_peekall(0))) { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
855 fprintf(fd, "%s %s %s %s %s %s\n", |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
856 I_ARTIST(item), |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
857 I_TITLE(item), |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
858 I_LEN(item), |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
859 I_TIME(item), |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
860 I_ALBUM(item), |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
861 I_MB(item)); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
862 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
863 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
864 fclose(fd); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
865 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
866 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
867 /* This was made public */ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
868 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
869 void gerpok_sc_cleaner(void) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
870 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
871 if(gerpok_sc_submit_url != NULL) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
872 free(gerpok_sc_submit_url); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
873 if(gerpok_sc_username != NULL) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
874 free(gerpok_sc_username); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
875 if(gerpok_sc_password != NULL) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
876 free(gerpok_sc_password); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
877 if(gerpok_sc_challenge_hash != NULL) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
878 free(gerpok_sc_challenge_hash); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
879 if(gerpok_sc_srv_res != NULL) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
880 free(gerpok_sc_srv_res); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
881 if(gerpok_sc_major_error != NULL) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
882 free(gerpok_sc_major_error); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
883 dump_queue(); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
884 q_free(); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
885 pdebug("scrobbler shutting down", DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
886 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
887 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
888 static void gerpok_sc_checkhandshake(void) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
889 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
890 int wait; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
891 |
348
314b7ac7f771
[svn] - handle no account data gracefully (e.g. you only use one of the
nenolod
parents:
344
diff
changeset
|
892 if (!gerpok_sc_username || !gerpok_sc_password) |
314b7ac7f771
[svn] - handle no account data gracefully (e.g. you only use one of the
nenolod
parents:
344
diff
changeset
|
893 return; |
314b7ac7f771
[svn] - handle no account data gracefully (e.g. you only use one of the
nenolod
parents:
344
diff
changeset
|
894 |
344
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
895 if (gerpok_sc_hs_status) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
896 return; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
897 if (gerpok_sc_hs_timeout < time(NULL)) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
898 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
899 gerpok_sc_handshake(); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
900 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
901 if(gerpok_sc_hs_errors) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
902 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
903 if(gerpok_sc_hs_errors < 5) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
904 /* Retry after 60 seconds */ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
905 wait = 60; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
906 else |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
907 wait = /* gerpok_sc_submit_interval + */ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
908 ( ((gerpok_sc_hs_errors - 5) < 7) ? |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
909 (60 << (gerpok_sc_hs_errors-5)) : |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
910 7200 ); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
911 gerpok_sc_hs_timeout = time(NULL) + wait; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
912 pdebug(fmt_vastr("Error while handshaking. Retrying " |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
913 "after %d seconds.", wait), DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
914 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
915 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
916 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
917 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
918 /**** Public *****/ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
919 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
920 /* Called at session startup*/ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
921 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
922 void gerpok_sc_init(char *uname, char *pwd) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
923 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
924 gerpok_sc_hs_status = gerpok_sc_hs_timeout = gerpok_sc_hs_errors = gerpok_sc_submit_timeout = |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
925 gerpok_sc_srv_res_size = gerpok_sc_giveup = gerpok_sc_major_error_present = |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
926 gerpok_sc_bad_users = gerpok_sc_sb_errors = 0; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
927 gerpok_sc_submit_interval = 100; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
928 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
929 gerpok_sc_submit_url = gerpok_sc_username = gerpok_sc_password = gerpok_sc_srv_res = |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
930 gerpok_sc_challenge_hash = gerpok_sc_major_error = NULL; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
931 gerpok_sc_username = strdup(uname); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
932 gerpok_sc_password = strdup(pwd); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
933 read_cache(); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
934 pdebug("scrobbler starting up", DEBUG); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
935 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
936 |
1443
f4d8082668c1
scrobbler: tuple API update
William Pitcock <nenolod@atheme-project.org>
parents:
990
diff
changeset
|
937 void gerpok_sc_addentry(GMutex *mutex, Tuple *tuple, int len) |
344
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
938 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
939 g_mutex_lock(mutex); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
940 q_put(tuple, len); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
941 /* |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
942 * This will help make sure the queue will be saved on a nasty |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
943 * segfault... |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
944 */ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
945 dump_queue(); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
946 g_mutex_unlock(mutex); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
947 } |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
948 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
949 /* Call periodically from the plugin */ |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
950 int gerpok_sc_idle(GMutex *mutex) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
951 { |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
952 gerpok_sc_checkhandshake(); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
953 if (gerpok_sc_hs_status) |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
954 gerpok_sc_handlequeue(mutex); |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
955 |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
956 return gerpok_sc_giveup; |
03c1ae10bc8d
[svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents:
diff
changeset
|
957 } |