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