annotate src/scrobbler/scrobbler.c @ 1443:f4d8082668c1

scrobbler: tuple API update
author William Pitcock <nenolod@atheme-project.org>
date Fri, 10 Aug 2007 10:03:10 -0500
parents 93dee80e9365
children db616ccdd40c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
a3ca00f30af5 [svn] - path fixes
nenolod
parents: 401
diff changeset
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
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
78 gchar *
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
79 xmms_urldecode_plain(const gchar * encoded_path)
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
80 {
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
81 const gchar *cur, *ext;
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
82 gchar *path, *tmp;
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
83 gint realchar;
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
84
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
85 if (!encoded_path)
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
86 return NULL;
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
87
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
88 cur = encoded_path;
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
89 if (*cur == '/')
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
90 while (cur[1] == '/')
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
91 cur++;
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
92
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
93 tmp = g_malloc0(strlen(cur) + 1);
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
94
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
95 while ((ext = strchr(cur, '%')) != NULL) {
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
96 strncat(tmp, cur, ext - cur);
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
97 ext++;
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
98 cur = ext + 2;
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
99 if (!sscanf(ext, "%2x", &realchar)) {
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
100 /*
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
101 * Assume it is a literal '%'. Several file
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
102 * managers send unencoded file: urls on on
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
103 * drag and drop.
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
104 */
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
105 realchar = '%';
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
106 cur -= 2;
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
107 }
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
108 tmp[strlen(tmp)] = realchar;
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
109 }
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
110
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
111 path = g_strconcat(tmp, cur, NULL);
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
112 g_free(tmp);
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
113 return path;
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
114 }
93dee80e9365 [svn] - fix scrobble from queue
desowin
parents: 1044
diff changeset
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
1443
f4d8082668c1 scrobbler: tuple API update
William Pitcock <nenolod@atheme-project.org>
parents: 1172
diff changeset
134 item->artist = fmt_escape(tuple_get_string(tuple, "artist"));
f4d8082668c1 scrobbler: tuple API update
William Pitcock <nenolod@atheme-project.org>
parents: 1172
diff changeset
135 item->title = fmt_escape(tuple_get_string(tuple, "title"));
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
136 snprintf(item->utctime, sizeof(item->utctime), "%ld", time(NULL));
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
137 snprintf(item->len, sizeof(item->len), "%d", len);
1443
f4d8082668c1 scrobbler: tuple API update
William Pitcock <nenolod@atheme-project.org>
parents: 1172
diff changeset
138 snprintf(item->track, sizeof(item->track), "%d", tuple_get_int(tuple, "track-number"));
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
139
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
140 #ifdef NOTYET
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
141 if(tuple->mb == NULL)
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
142 #endif
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
143 item->mb = fmt_escape("");
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
144 #ifdef NOTYET
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
145 else
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
146 item->mb = fmt_escape((char*)tuple->mb);
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
147 #endif
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
148
1443
f4d8082668c1 scrobbler: tuple API update
William Pitcock <nenolod@atheme-project.org>
parents: 1172
diff changeset
149 if((album = tuple_get_string(tuple, "album")))
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
150 item->album = fmt_escape("");
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
151 else
1443
f4d8082668c1 scrobbler: tuple API update
William Pitcock <nenolod@atheme-project.org>
parents: 1172
diff changeset
152 item->album = fmt_escape((char*) album);
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
153
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
154 q_nitems++;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
155
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
156 item->next = NULL;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
157
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
158 if(q_queue_last == NULL)
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
159 q_queue = q_queue_last = item;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
160 else
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
161 {
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
162 q_queue_last->next = item;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
163 q_queue_last = item;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
164 }
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 return item;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
167 }
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
168
990
238055a6cb8f [svn] - remove support for hatena music as hatena ceased their musical profile service.
yaz
parents: 786
diff changeset
169 #if 0
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
170 static item_t *q_peek(void)
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
171 {
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
172 if (q_nitems == 0)
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
173 return NULL;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
174 return q_queue;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
175 }
990
238055a6cb8f [svn] - remove support for hatena music as hatena ceased their musical profile service.
yaz
parents: 786
diff changeset
176 #endif
344
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
177
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
178 static item_t *q_peekall(int rewind)
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
179 {
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
180 static item_t *citem = NULL;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
181 item_t *temp_item;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
182
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
183 if (rewind) {
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
184 citem = q_queue;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
185 return NULL;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
186 }
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 temp_item = citem;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
189
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
190 if(citem != NULL)
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
191 citem = citem->next;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
192
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
193 return temp_item;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
194 }
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 static int q_get(void)
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
197 {
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
198 item_t *item;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
199
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
200 if (q_nitems == 0)
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
201 return 0;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
202
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
203 item = q_queue;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
204
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
205 if(item == NULL)
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
206 return 0;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
207
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
208 q_nitems--;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
209 q_queue = q_queue->next;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
210
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
211 q_item_free(item);
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
212
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
213 if (q_nitems == 0)
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
214 {
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
215 q_queue_last = NULL;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
216 return 0;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
217 }
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 return -1;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
220 }
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 static void q_free(void)
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
223 {
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
224 while (q_get());
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
225 }
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 static int q_len(void)
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
228 {
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
229 return q_nitems;
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
230 }
03c1ae10bc8d [svn] - Merge audacious-scrobbler III, new features include:
nenolod
parents: 12
diff changeset
231
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
232 /* Error functions */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
233
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
234 static void sc_throw_error(char *errortxt)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
235 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
236 sc_major_error_present = 1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
237 if(sc_major_error == NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
238 sc_major_error = strdup(errortxt);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
239
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
240 return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
241 }
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 int sc_catch_error(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
244 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
245 return sc_major_error_present;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
246 }
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 char *sc_fetch_error(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
249 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
250 return sc_major_error;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
251 }
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 void sc_clear_error(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
254 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
255 sc_major_error_present = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
256 if(sc_major_error != NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
257 free(sc_major_error);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
258 sc_major_error = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
259
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
260 return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
261 }
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 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
264 size_t nmemb,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
265 void *stream __attribute__((unused)))
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
266 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
267 int len = size * nmemb;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
268
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
269 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
270 memcpy(sc_srv_res + sc_srv_res_size,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
271 ptr, len);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
272 sc_srv_res_size += len;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
273 return len;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
274 }
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 static void sc_free_res(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
277 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
278 if(sc_srv_res != NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
279 free(sc_srv_res);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
280 sc_srv_res = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
281 sc_srv_res_size = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
282 }
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 static int sc_parse_hs_res(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
285 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
286 char *interval;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
287
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
288 if (!sc_srv_res_size) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
289 pdebug("No reply from server", DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
290 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
291 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
292 *(sc_srv_res + sc_srv_res_size) = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
293
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
294 if (!strncmp(sc_srv_res, "OK\n", 3)) {
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
295 gchar *scratch = g_strdup(sc_srv_res);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
296 gchar **split = g_strsplit(scratch, "\n", 5);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
297
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
298 g_free(scratch);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
299
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
300 sc_session_id = g_strdup(split[1]);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
301 sc_np_url = g_strdup(split[2]);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
302 sc_submit_url = g_strdup(split[3]);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
303
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
304 g_strfreev(split);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
305 return 0;
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
306 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
307 if (!strncmp(sc_srv_res, "FAILED ", 7)) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
308 interval = strstr(sc_srv_res, "INTERVAL");
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
309
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
310 /* Throwing a major error, just in case */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
311 /* sc_throw_error(fmt_vastr("%s", sc_srv_res));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
312 sc_hs_errors++; */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
313 pdebug(fmt_vastr("error: %s", sc_srv_res), DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
314
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
315 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
316 }
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 if (!strncmp(sc_srv_res, "UPDATE ", 7)) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
319 interval = strstr(sc_srv_res, "INTERVAL");
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
320 if(!interval)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
321 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
322 pdebug("missing INTERVAL", DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
323 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
324 else
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
325 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
326 *(interval - 1) = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
327 sc_submit_interval = strtol(interval + 8, NULL, 10);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
328 }
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 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
331 *(sc_submit_url - 1) = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
332 sc_submit_url = strdup(sc_submit_url);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
333 sc_challenge_hash = strchr(sc_srv_res, '\n') + 1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
334 *(sc_challenge_hash - 1) = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
335 sc_challenge_hash = strdup(sc_challenge_hash);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
336
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
337 /* Throwing major error. Need to alert client to update. */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
338 sc_throw_error(fmt_vastr("Please update Audacious.\n"
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
339 "Update available at: http://audacious-media-player.org"));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
340 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
341
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 * 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
344 * 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
345 */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
346 sc_giveup = -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
347 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
348 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
349 if (!strncmp(sc_srv_res, "UPTODATE\n", 9)) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
350 sc_bad_users = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
351
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
352 interval = strstr(sc_srv_res, "INTERVAL");
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
353 if (!interval) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
354 pdebug("missing INTERVAL", DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
355 /*
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
356 * 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
357 * think its OK to assume that an UPTODATE response
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
358 * may not have an INTERVAL... We return -1 anyway.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
359 */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
360 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
361 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
362 else
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
363 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
364 *(interval - 1) = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
365 sc_submit_interval = strtol(interval + 8, NULL, 10);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
366 }
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 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
369 *(sc_submit_url - 1) = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
370 sc_submit_url = strdup(sc_submit_url);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
371 sc_challenge_hash = strchr(sc_srv_res, '\n') + 1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
372 *(sc_challenge_hash - 1) = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
373 sc_challenge_hash = strdup(sc_challenge_hash);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
374
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
375 return 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
376 }
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
377 if(!strncmp(sc_srv_res, "BADAUTH", 7)) {
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
378 /* Throwing major error. */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
379 sc_throw_error("Incorrect username/password.\n"
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
380 "Please fix in configuration.");
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
381 pdebug("incorrect username/password", DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
382
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
383 interval = strstr(sc_srv_res, "INTERVAL");
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
384 if(!interval)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
385 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
386 pdebug("missing INTERVAL", DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
387 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
388 else
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
389 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
390 *(interval - 1) = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
391 sc_submit_interval = strtol(interval + 8, NULL, 10);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
392 }
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 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
395 }
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 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
398 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
399 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
400
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
401 static unsigned char *md5_string(char *pass, int len)
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
402 {
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
403 md5_state_t md5state;
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
404 static unsigned char md5pword[16];
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
405
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
406 md5_init(&md5state);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
407 md5_append(&md5state, (unsigned const char *)pass, len);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
408 md5_finish(&md5state, md5pword);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
409
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
410 return md5pword;
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
411 }
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
412
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
413 static void hexify(char *pass, int len)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
414 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
415 char *bp = sc_response_hash;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
416 char hexchars[] = "0123456789abcdef";
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
417 int i;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
418
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
419 memset(sc_response_hash, 0, sizeof(sc_response_hash));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
420
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
421 for(i = 0; i < len; i++) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
422 *(bp++) = hexchars[(pass[i] >> 4) & 0x0f];
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
423 *(bp++) = hexchars[pass[i] & 0x0f];
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
424 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
425 *bp = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
426
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
427 return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
428 }
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 static int sc_handshake(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
431 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
432 int status;
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
433 char buf[65535];
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
434 CURL *curl;
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
435 time_t ts = time(NULL);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
436 char *auth_tmp;
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
437 char *auth;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
438
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
439 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
440 auth = (char *)md5_string(auth_tmp, strlen(auth_tmp));
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
441 g_free(auth_tmp);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
442 hexify(auth, strlen(auth));
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
443 auth_tmp = g_strdup(sc_response_hash);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
444
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
445 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
446 SCROBBLER_HS_URL, SCROBBLER_VERSION,
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
447 SCROBBLER_CLI_ID, SCROBBLER_IMPLEMENTATION, sc_username, time(NULL),
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
448 auth_tmp);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
449 g_free(auth_tmp);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
450
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
451 curl = curl_easy_init();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
452 curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
453 curl_easy_setopt(curl, CURLOPT_URL, buf);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
454 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
455 sc_store_res);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
456 memset(sc_curl_errbuf, 0, sizeof(sc_curl_errbuf));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
457 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, sc_curl_errbuf);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
458 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
459 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
460 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
461 status = curl_easy_perform(curl);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
462 curl_easy_cleanup(curl);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
463
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
464 sc_hs_timeout = time(NULL) + SCROBBLER_HS_WAIT;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
465
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
466 if (status) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
467 pdebug(sc_curl_errbuf, DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
468 sc_hs_errors++;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
469 sc_free_res();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
470 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
471 }
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 if (sc_parse_hs_res()) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
474 sc_hs_errors++;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
475 sc_free_res();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
476 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
477 }
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 if (sc_challenge_hash != NULL) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
480 md5_state_t md5state;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
481 unsigned char md5pword[16];
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
482
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
483 md5_init(&md5state);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
484 /*pdebug(fmt_vastr("Pass Hash: %s", sc_password), DEBUG);*/
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
485 md5_append(&md5state, (unsigned const char *)sc_password,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
486 strlen(sc_password));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
487 /*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
488 md5_append(&md5state, (unsigned const char *)sc_challenge_hash,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
489 strlen(sc_challenge_hash));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
490 md5_finish(&md5state, md5pword);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
491 hexify((char*)md5pword, sizeof(md5pword));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
492 /*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
493 }
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 sc_hs_errors = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
496 sc_hs_status = 1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
497
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
498 sc_free_res();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
499
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
500 pdebug(fmt_vastr("submiturl: %s - interval: %d",
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
501 sc_submit_url, sc_submit_interval), DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
502
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
503 return 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
504 }
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 static int sc_parse_sb_res(void)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
507 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
508 char *ch, *ch2;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
509
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
510 if (!sc_srv_res_size) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
511 pdebug("No response from server", DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
512 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
513 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
514 *(sc_srv_res + sc_srv_res_size) = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
515
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
516 if (!strncmp(sc_srv_res, "OK", 2)) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
517 if ((ch = strstr(sc_srv_res, "INTERVAL"))) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
518 sc_submit_interval = strtol(ch + 8, NULL, 10);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
519 pdebug(fmt_vastr("got new interval: %d",
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
520 sc_submit_interval), DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
521 }
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 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
524
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
525 return 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
526 }
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 if (!strncmp(sc_srv_res, "BADAUTH", 7)) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
529 if ((ch = strstr(sc_srv_res, "INTERVAL"))) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
530 sc_submit_interval = strtol(ch + 8, NULL, 10);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
531 pdebug(fmt_vastr("got new interval: %d",
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
532 sc_submit_interval), DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
533 }
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 pdebug("incorrect username/password", DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
536
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
537 sc_giveup = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
538
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 * We obviously aren't authenticated. The server might have
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
541 * lost our handshake status though, so let's try
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
542 * re-handshaking... This might not be proper.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
543 * (we don't give up)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
544 */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
545 sc_hs_status = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
546
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
547 if(sc_challenge_hash != NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
548 free(sc_challenge_hash);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
549 if(sc_submit_url != NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
550 free(sc_submit_url);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
551
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
552 sc_challenge_hash = sc_submit_url = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
553 sc_bad_users++;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
554
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
555 if(sc_bad_users > 2)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
556 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
557 pdebug("3 BADAUTH returns on submission. Halting "
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
558 "submissions until login fixed.", DEBUG)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
559 sc_throw_error("Incorrect username/password.\n"
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
560 "Please fix in configuration.");
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
561 }
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 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
564 }
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 if (!strncmp(sc_srv_res, "FAILED", 6)) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
567 if ((ch = strstr(sc_srv_res, "INTERVAL"))) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
568 sc_submit_interval = strtol(ch + 8, NULL, 10);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
569 pdebug(fmt_vastr("got new interval: %d",
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
570 sc_submit_interval), DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
571 }
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 /* 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
574 /*sc_throw_error(fmt_vastr("%s", sc_srv_res));*/
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
575
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
576 pdebug(sc_srv_res, DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
577
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
578 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
579 }
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 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
582 ch = strstr(sc_srv_res, "<TITLE>");
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
583 ch2 = strstr(sc_srv_res, "</TITLE>");
786
c23705487009 [svn] - avoid crash when error message doesn't contain <TITLE>.
yaz
parents: 733
diff changeset
584 if (ch != NULL && ch2 != NULL) {
c23705487009 [svn] - avoid crash when error message doesn't contain <TITLE>.
yaz
parents: 733
diff changeset
585 ch += strlen("<TITLE>");
c23705487009 [svn] - avoid crash when error message doesn't contain <TITLE>.
yaz
parents: 733
diff changeset
586 *ch2 = '\0';
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
587
786
c23705487009 [svn] - avoid crash when error message doesn't contain <TITLE>.
yaz
parents: 733
diff changeset
588 pdebug(fmt_vastr("HTTP Error (%d): '%s'",
c23705487009 [svn] - avoid crash when error message doesn't contain <TITLE>.
yaz
parents: 733
diff changeset
589 atoi(ch), ch + 4), DEBUG);
c23705487009 [svn] - avoid crash when error message doesn't contain <TITLE>.
yaz
parents: 733
diff changeset
590 // *ch2 = '<'; // needed? --yaz
c23705487009 [svn] - avoid crash when error message doesn't contain <TITLE>.
yaz
parents: 733
diff changeset
591 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
592
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
593 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
594 }
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 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
597
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
598 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
599 }
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 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
602 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
603 static char buf[SCROBBLER_SB_MAXLEN];
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
604 snprintf(buf, SCROBBLER_SB_MAXLEN, "&%c[%d]=%s", c, n, str);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
605 return buf;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
606 }
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 #define cfa(f, l, n, v) \
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
609 curl_formadd(f, l, CURLFORM_COPYNAME, n, \
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
610 CURLFORM_PTRCONTENTS, v, CURLFORM_END)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
611
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
612 static int sc_generateentry(GString *submission)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
613 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
614 int i;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
615 item_t *item;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
616
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
617 i = 0;
1030
9dae0c13a65f [svn] - enforce audioscrobbler rules on queued tracks
nenolod
parents: 1029
diff changeset
618
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
619 q_peekall(1);
1030
9dae0c13a65f [svn] - enforce audioscrobbler rules on queued tracks
nenolod
parents: 1029
diff changeset
620
9dae0c13a65f [svn] - enforce audioscrobbler rules on queued tracks
nenolod
parents: 1029
diff changeset
621 while ((item = q_peekall(0)) && i < 10)
9dae0c13a65f [svn] - enforce audioscrobbler rules on queued tracks
nenolod
parents: 1029
diff changeset
622 {
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 * don't submit queued tracks which don't yet meet audioscrobbler
9dae0c13a65f [svn] - enforce audioscrobbler rules on queued tracks
nenolod
parents: 1029
diff changeset
625 * requirements...
9dae0c13a65f [svn] - enforce audioscrobbler rules on queued tracks
nenolod
parents: 1029
diff changeset
626 */
9dae0c13a65f [svn] - enforce audioscrobbler rules on queued tracks
nenolod
parents: 1029
diff changeset
627 if ((time(NULL) - atoi(item->utctime)) < (atoi(item->len) / 2) &&
9dae0c13a65f [svn] - enforce audioscrobbler rules on queued tracks
nenolod
parents: 1029
diff changeset
628 (time(NULL) - atoi(item->utctime)) < 240)
9dae0c13a65f [svn] - enforce audioscrobbler rules on queued tracks
nenolod
parents: 1029
diff changeset
629 continue;
9dae0c13a65f [svn] - enforce audioscrobbler rules on queued tracks
nenolod
parents: 1029
diff changeset
630
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
631 if (!item)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
632 return i;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
633
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
634 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
635 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
636 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
637 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
638 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
639 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
640 g_string_append(submission,sc_itemtag('o',i,"P"));
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
641 g_string_append(submission,sc_itemtag('n',i,item->track));
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
642 g_string_append(submission,sc_itemtag('r',i,""));
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
643
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
644 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
645 i, I_ARTIST(item),
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
646 i, I_TITLE(item),
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
647 i, I_LEN(item),
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
648 i, I_TIME(item),
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
649 i, I_MB(item),
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
650 i, I_ALBUM(item)), DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
651 #ifdef ALLOW_MULTIPLE
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
652 i++;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
653 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
654 #endif
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
655
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
656 return i;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
657 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
658
1443
f4d8082668c1 scrobbler: tuple API update
William Pitcock <nenolod@atheme-project.org>
parents: 1172
diff changeset
659 static int sc_submit_np(Tuple *tuple)
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
660 {
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
661 CURL *curl;
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
662 /* struct HttpPost *post = NULL , *last = NULL; */
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
663 int status;
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
664 gchar *entry;
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
665
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
666 curl = curl_easy_init();
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
667 curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
668 curl_easy_setopt(curl, CURLOPT_URL, sc_np_url);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
669 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
670 sc_store_res);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
671 curl_easy_setopt(curl, CURLOPT_USERAGENT, USER_AGENT);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
672 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
673 /*cfa(&post, &last, "debug", "failed");*/
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
674
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
675 entry = g_strdup_printf("s=%s&a=%s&t=%s&b=%s&l=%d&n=%d&m=", sc_session_id,
1443
f4d8082668c1 scrobbler: tuple API update
William Pitcock <nenolod@atheme-project.org>
parents: 1172
diff changeset
676 tuple_get_string(tuple, "artist"),
f4d8082668c1 scrobbler: tuple API update
William Pitcock <nenolod@atheme-project.org>
parents: 1172
diff changeset
677 tuple_get_string(tuple, "title"),
f4d8082668c1 scrobbler: tuple API update
William Pitcock <nenolod@atheme-project.org>
parents: 1172
diff changeset
678 tuple_get_string(tuple, "album") ? tuple_get_string(tuple, "album") : "",
f4d8082668c1 scrobbler: tuple API update
William Pitcock <nenolod@atheme-project.org>
parents: 1172
diff changeset
679 tuple_get_int(tuple, "length") / 1000, tuple_get_int(tuple, "track-number"));
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
680
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
681 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, (char *) entry);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
682 memset(sc_curl_errbuf, 0, sizeof(sc_curl_errbuf));
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
683 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, sc_curl_errbuf);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
684 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
685 curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, SC_CURL_TIMEOUT);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
686 curl_easy_setopt(curl, CURLOPT_TIMEOUT, SCROBBLER_SB_WAIT);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
687
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
688 status = curl_easy_perform(curl);
1032
15e8890cb54d [svn] - fix memory-leak for protocol 1.2 code
nenolod
parents: 1031
diff changeset
689 curl_easy_cleanup(curl);
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
690
1032
15e8890cb54d [svn] - fix memory-leak for protocol 1.2 code
nenolod
parents: 1031
diff changeset
691 g_free(entry);
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
692
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
693 if (status) {
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
694 pdebug(sc_curl_errbuf, DEBUG);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
695 sc_sb_errors++;
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
696 sc_free_res();
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
697 return -1;
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
698 }
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
699
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
700 if (sc_parse_sb_res()) {
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
701 sc_sb_errors++;
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
702 sc_free_res();
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
703 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
704 sc_submit_interval, q_len()), DEBUG);
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
705 return -1;
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
706 }
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
707 sc_free_res();
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
708 return 0;
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
709 }
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
710
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
711 static int sc_submitentry(gchar *entry)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
712 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
713 CURL *curl;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
714 /* struct HttpPost *post = NULL , *last = NULL; */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
715 int status;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
716 GString *submission;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
717
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
718 curl = curl_easy_init();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
719 curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
720 curl_easy_setopt(curl, CURLOPT_URL, sc_submit_url);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
721 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
722 sc_store_res);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
723 curl_easy_setopt(curl, CURLOPT_USERAGENT, USER_AGENT);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
724 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
725 /*cfa(&post, &last, "debug", "failed");*/
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
726
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
727 /*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
728 submission = g_string_new("s=");
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
729 g_string_append(submission, (gchar *)sc_session_id);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
730 g_string_append(submission, entry);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
731
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
732 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, (char *)submission->str);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
733 memset(sc_curl_errbuf, 0, sizeof(sc_curl_errbuf));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
734 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
735 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
736 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
737 curl_easy_setopt(curl, CURLOPT_TIMEOUT, SCROBBLER_SB_WAIT);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
738
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
739 status = curl_easy_perform(curl);
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 curl_easy_cleanup(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 if (status) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
744 pdebug(sc_curl_errbuf, DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
745 sc_sb_errors++;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
746 sc_free_res();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
747 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
748 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
749
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
750 if (sc_parse_sb_res()) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
751 sc_sb_errors++;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
752 sc_free_res();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
753 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
754 sc_submit_interval, q_len()), DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
755 return -1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
756 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
757 sc_free_res();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
758 return 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
759 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
760
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
761 static void sc_handlequeue(GMutex *mutex)
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 GString *submitentry;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
764 int nsubmit;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
765 int wait;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
766
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
767 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
768 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
769 submitentry = g_string_new("");
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 g_mutex_lock(mutex);
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 nsubmit = sc_generateentry(submitentry);
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 g_mutex_unlock(mutex);
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 if (nsubmit > 0)
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 pdebug(fmt_vastr("Number submitting: %d", nsubmit), DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
780 pdebug(fmt_vastr("Submission: %s", submitentry->str), DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
781
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
782 if(!sc_submitentry(submitentry->str))
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 g_mutex_lock(mutex);
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 #ifdef ALLOW_MULTIPLE
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
787 q_free();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
788 #else
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
789 q_get();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
790 #endif
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
791 /*
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
792 * This should make sure that the queue doesn't
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
793 * get submitted multiple times on a nasty
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
794 * segfault...
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
795 */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
796 dump_queue();
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 g_mutex_unlock(mutex);
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 sc_sb_errors = 0;
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 if(sc_sb_errors)
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 < 5)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
805 /* Retry after 1 min */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
806 wait = 60;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
807 else
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
808 wait = /* sc_submit_interval + */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
809 ( ((sc_sb_errors - 5) < 7) ?
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
810 (60 << (sc_sb_errors-5)) :
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
811 7200 );
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
812
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
813 sc_submit_timeout = time(NULL) + wait;
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 pdebug(fmt_vastr("Error while submitting. "
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
816 "Retrying after %d seconds.", wait),
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
817 DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
818 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
819 }
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 g_string_free(submitentry, TRUE);
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 }
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 static void read_cache(void)
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 FILE *fd;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
828 char buf[PATH_MAX], *cache = NULL, *ptr1, *ptr2;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
829 int cachesize, written, i = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
830 item_t *item;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
831
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
832 cachesize = written = 0;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
833
732
a3ca00f30af5 [svn] - path fixes
nenolod
parents: 401
diff changeset
834 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
835
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
836 if (!(fd = fopen(buf, "r")))
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
837 return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
838 pdebug(fmt_vastr("Opening %s", buf), DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
839 while(!feof(fd))
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
840 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
841 cachesize += CACHE_SIZE;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
842 cache = realloc(cache, cachesize + 1);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
843 written += fread(cache + written, 1, CACHE_SIZE, fd);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
844 cache[written] = '\0';
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
845 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
846 fclose(fd);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
847 ptr1 = cache;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
848 while(ptr1 < cache + written - 1)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
849 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
850 char *artist, *title, *len, *time, *album, *mb;
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 pdebug("Pushed:", DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
853 ptr2 = strchr(ptr1, ' ');
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
854 artist = calloc(1, ptr2 - ptr1 + 1);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
855 strncpy(artist, ptr1, ptr2 - ptr1);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
856 ptr1 = ptr2 + 1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
857 ptr2 = strchr(ptr1, ' ');
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
858 title = calloc(1, ptr2 - ptr1 + 1);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
859 strncpy(title, ptr1, ptr2 - ptr1);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
860 ptr1 = ptr2 + 1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
861 ptr2 = strchr(ptr1, ' ');
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
862 len = calloc(1, ptr2 - ptr1 + 1);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
863 strncpy(len, ptr1, ptr2 - ptr1);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
864 ptr1 = ptr2 + 1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
865 ptr2 = strchr(ptr1, ' ');
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
866 time = calloc(1, ptr2 - ptr1 + 1);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
867 strncpy(time, ptr1, ptr2 - ptr1);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
868 ptr1 = ptr2 + 1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
869 ptr2 = strchr(ptr1, ' ');
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
870 album = calloc(1, ptr2 - ptr1 + 1);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
871 strncpy(album, ptr1, ptr2 - ptr1);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
872 ptr1 = ptr2 + 1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
873 ptr2 = strchr(ptr1, '\n');
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
874 if(ptr2 != NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
875 *ptr2 = '\0';
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
876 mb = calloc(1, strlen(ptr1) + 1);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
877 strncpy(mb, ptr1, strlen(ptr1));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
878 if(ptr2 != NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
879 *ptr2 = '\n';
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
880 /* Why is our save printing out CR/LF? */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
881 ptr1 = ptr2 + 1;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
882
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
883 {
1443
f4d8082668c1 scrobbler: tuple API update
William Pitcock <nenolod@atheme-project.org>
parents: 1172
diff changeset
884 Tuple *tuple = tuple_new();
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
885
1443
f4d8082668c1 scrobbler: tuple API update
William Pitcock <nenolod@atheme-project.org>
parents: 1172
diff changeset
886 tuple_associate_string(tuple, "artist", xmms_urldecode_plain(artist));
f4d8082668c1 scrobbler: tuple API update
William Pitcock <nenolod@atheme-project.org>
parents: 1172
diff changeset
887 tuple_associate_string(tuple, "title", xmms_urldecode_plain(title));
f4d8082668c1 scrobbler: tuple API update
William Pitcock <nenolod@atheme-project.org>
parents: 1172
diff changeset
888 tuple_associate_string(tuple, "album", xmms_urldecode_plain(album));
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
889
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
890 item = q_put(tuple, atoi(len));
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
891
1443
f4d8082668c1 scrobbler: tuple API update
William Pitcock <nenolod@atheme-project.org>
parents: 1172
diff changeset
892 mowgli_object_unref(tuple);
1028
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
893 }
b5de3b4129a6 [svn] - fully update to AudioScrobbler 1.2 protocol
nenolod
parents: 1026
diff changeset
894
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
895 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
896 i, I_ARTIST(item),
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
897 i, I_TITLE(item),
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
898 i, I_LEN(item),
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
899 i, I_TIME(item),
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
900 i, I_MB(item),
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
901 i, I_ALBUM(item)), DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
902 free(artist);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
903 free(title);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
904 free(len);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
905 free(time);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
906 free(album);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
907 free(mb);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
908
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
909 i++;
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 pdebug("Done loading cache.", DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
912 free(cache);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
913 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
914
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
915 static void dump_queue(void)
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 FILE *fd;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
918 item_t *item;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
919 char *home, buf[PATH_MAX];
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
920
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
921 /*pdebug("Entering dump_queue();", DEBUG);*/
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 if (!(home = getenv("HOME")))
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 pdebug("No HOME directory found. Cannot dump queue.", DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
926 return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
927 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
928
733
7c04570bf809 [svn] fixed where srobbler dumps files.
kustodian
parents: 732
diff changeset
929 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
930
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
931 if (!(fd = fopen(buf, "w")))
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 pdebug(fmt_vastr("Failure opening %s", buf), DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
934 return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
935 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
936
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
937 pdebug(fmt_vastr("Opening %s", buf), DEBUG);
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 q_peekall(1);
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 while ((item = q_peekall(0))) {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
942 fprintf(fd, "%s %s %s %s %s %s\n",
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
943 I_ARTIST(item),
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
944 I_TITLE(item),
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
945 I_LEN(item),
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
946 I_TIME(item),
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
947 I_ALBUM(item),
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
948 I_MB(item));
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
949 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
950
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
951 fclose(fd);
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
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
954 /* This was made public */
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 void sc_cleaner(void)
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 if(sc_submit_url != NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
959 free(sc_submit_url);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
960 if(sc_username != NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
961 free(sc_username);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
962 if(sc_password != NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
963 free(sc_password);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
964 if(sc_challenge_hash != NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
965 free(sc_challenge_hash);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
966 if(sc_srv_res != NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
967 free(sc_srv_res);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
968 if(sc_major_error != NULL)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
969 free(sc_major_error);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
970 dump_queue();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
971 q_free();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
972 pdebug("scrobbler shutting down", DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
973 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
974
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
975 static void sc_checkhandshake(void)
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 int wait;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
978
348
314b7ac7f771 [svn] - handle no account data gracefully (e.g. you only use one of the
nenolod
parents: 344
diff changeset
979 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
980 return;
314b7ac7f771 [svn] - handle no account data gracefully (e.g. you only use one of the
nenolod
parents: 344
diff changeset
981
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
982 if (sc_hs_status)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
983 return;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
984 if (sc_hs_timeout < time(NULL))
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
985 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
986 sc_handshake();
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 if(sc_hs_errors)
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 < 5)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
991 /* Retry after 60 seconds */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
992 wait = 60;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
993 else
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
994 wait = /* sc_submit_interval + */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
995 ( ((sc_hs_errors - 5) < 7) ?
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
996 (60 << (sc_hs_errors-5)) :
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
997 7200 );
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
998 sc_hs_timeout = time(NULL) + wait;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
999 pdebug(fmt_vastr("Error while handshaking. Retrying "
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1000 "after %d seconds.", wait), DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1001 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1002 }
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 /**** Public *****/
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 /* Called at session startup*/
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 void sc_init(char *uname, char *pwd)
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 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
1012 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
1013 sc_bad_users = sc_sb_errors = 0;
1031
3707a3efcc9c [svn] - protocol 1.2: use interval 1
nenolod
parents: 1030
diff changeset
1014 sc_submit_interval = 1;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1015
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1016 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
1017 sc_challenge_hash = sc_major_error = NULL;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1018 sc_username = strdup(uname);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1019 sc_password = strdup(pwd);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1020 read_cache();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1021 pdebug("scrobbler starting up", DEBUG);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1022 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1023
1443
f4d8082668c1 scrobbler: tuple API update
William Pitcock <nenolod@atheme-project.org>
parents: 1172
diff changeset
1024 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
1025 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1026 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
1027
a33470329dbe [svn] - NP pings apparently do not affect musical profile, so queue tracks for submission
nenolod
parents: 1028
diff changeset
1028 sc_submit_np(tuple);
a33470329dbe [svn] - NP pings apparently do not affect musical profile, so queue tracks for submission
nenolod
parents: 1028
diff changeset
1029 q_put(tuple, len);
a33470329dbe [svn] - NP pings apparently do not affect musical profile, so queue tracks for submission
nenolod
parents: 1028
diff changeset
1030
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1031 /*
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1032 * 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
1033 * segfault...
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1034 */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1035 dump_queue();
1029
a33470329dbe [svn] - NP pings apparently do not affect musical profile, so queue tracks for submission
nenolod
parents: 1028
diff changeset
1036
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1037 g_mutex_unlock(mutex);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1038 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1039
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1040 /* Call periodically from the plugin */
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1041 int sc_idle(GMutex *mutex)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1042 {
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1043 sc_checkhandshake();
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1044 if (sc_hs_status)
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1045 sc_handlequeue(mutex);
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1046
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1047 return sc_giveup;
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
1048 }