Skip to content
Browse files

Don't crash if relaying

  • Loading branch information...
1 parent eaffd19 commit 652d8841692cd5fe166b5e6371b4657fd6ed4c77 @mxcl mxcl committed Jul 17, 2009
View
5 resolvers/audioscrobbler/audioscrobbler_plugin.cpp
@@ -74,7 +74,10 @@ static void start(const playdar_request& rq)
static string config(bool auth_required)
{
- if (!auth_required || scrobsub_finish_auth())
+ if (scrobsub_query_relay())
+ return "<p>Playdar is relaying scrobbles to your official Last.fm Audioscrobbler client.</p>";
+
+ if (!auth_required || scrobsub_finish_auth() && scrobsub_username)
return "<p>Playdar is authorized to "
"<a href='http://www.last.fm/help/faq?category=Scrobbling'>scrobble</a> "
"as "+string(scrobsub_username)+". "
View
12 resolvers/audioscrobbler/scrobsub.c
@@ -95,7 +95,12 @@ void scrobsub_init(void(*callback)(int, const char*))
track = (char*)malloc(0);
album = (char*)malloc(0);
mbid = (char*)malloc(0);
-}
+}
+
+bool scrobsub_query_relay()
+{
+ return relay;
+}
static void get_handshake_auth(char out[33], time_t time)
{
@@ -125,10 +130,10 @@ static char* escape(const char* in)
const char hexnumbers[] = "0123456789ABCDEF";
#define toHexHelper(c) hexnumbers[(c) & 0xf]
- int const n = strlen(in);
+ int const n = strlen(in);
int const nn = n*3 + 1;
#if SCROBSUB_NO_C99
- // we only use alloca on Windows as its use is discouraged on BSD
+ // we only use alloca on Windows as its use is discouraged on BSD
char* outs = (char*)alloca(nn);
#else
char outs[nn];
@@ -153,6 +158,7 @@ static char* escape(const char* in)
}
*out = '\0';
+ // we strdup here rather than malloc above to keep memory consumption lower
return strdup(outs);
}
View
4 resolvers/audioscrobbler/scrobsub.h
@@ -47,6 +47,10 @@ extern "C" {
/** Indeed, call this at your earliest convenience! */
void scrobsub_init(void(*callback)(int event, const char* message));
+/** @returns true if scrobsub is relaying scrobbles to the official Last.fm
+ * Audioscrobbler application */
+bool scrobsub_query_relay();
+
/** @see scrobsub_auth. Scrobbling will not function until your application is
* auth'd. However we will be caching scrobbles in memory. */
#define SCROBSUB_AUTH_REQUIRED 0

0 comments on commit 652d884

Please sign in to comment.
Something went wrong with that request. Please try again.