Permalink
Browse files

Error handling and warning removal

  • Loading branch information...
mxcl committed Jul 17, 2009
1 parent 652d884 commit 662574594ad48685c499bb070259dc1d5aa50869
Showing with 14 additions and 15 deletions.
  1. +11 −11 resolvers/audioscrobbler/auth-libxml2.c
  2. +1 −2 resolvers/audioscrobbler/http-curl.c
  3. +2 −2 resolvers/audioscrobbler/relay.c
@@ -32,25 +32,25 @@ bool scrobsub_persist_credentials();
static char* token = 0;
//TODO localise and get webservice error
-//TODO error handling
+
void scrobsub_auth(char out_url[110])
{
+ out_url = 0;
+
char url[] = "http://ws.audioscrobbler.com/2.0/?method=auth.gettoken&api_key=" SCROBSUB_API_KEY;
char response[256];
scrobsub_get(response, url);
- xmlInitParser(); //TODO can't tell if safe to call more than once, but don't want to call unless auth is done to save initialisations
- xmlDocPtr doc = xmlParseMemory(response, strlen(response)); //TODO can return NULL
+ xmlInitParser();
+ xmlDocPtr doc = xmlParseMemory(response, strlen(response));
xmlXPathContextPtr ctx = xmlXPathNewContext(doc);
xmlXPathObjectPtr obj = xmlXPathEvalExpression("/lfm/token/text()", ctx);
-
- if(!obj) return; // leak, but I don't care, this is an unlikely route
-
- token = strdup(obj->nodesetval->nodeTab[0]->content);
- strcpy(out_url, "http://www.last.fm/api/auth/?api_key=" SCROBSUB_API_KEY "&token=");
- strcat(out_url, token);
-
+ if(obj){
+ token = strdup(obj->nodesetval->nodeTab[0]->content);
+ strcpy(out_url, "http://www.last.fm/api/auth/?api_key=" SCROBSUB_API_KEY "&token=");
+ strcat(out_url, token);
+ }
xmlXPathFreeObject(obj);
xmlXPathFreeContext(ctx);
xmlFreeDoc(doc);
@@ -71,7 +71,7 @@ bool scrobsub_finish_auth()
char response[256];
scrobsub_get(response, url);
- xmlDocPtr doc = xmlParseMemory(response, 256); //TODO can return NULL
+ xmlDocPtr doc = xmlParseMemory(response, 256);
xmlXPathContextPtr ctx = xmlXPathNewContext(doc);
xmlXPathObjectPtr obj_key = xmlXPathEvalExpression("/lfm/session/key/text()", ctx);
xmlXPathObjectPtr obj_name = xmlXPathEvalExpression("/lfm/session/name/text()", ctx);
@@ -37,10 +37,9 @@ static size_t curl_writer(void* in, size_t size, size_t N, void* out)
size_t x;
N *= size;
for(x=0; x<N; ++x){
- if (++n == 255) break;
*(char*)out++ = *(char*)in++;
+ if (++n == 255) break;
}
-
return x;
}
@@ -74,13 +74,13 @@ void scrobsub_relay(int state)
}
}
-static inline uint strcat_escape_quotes(char* dst, char* src)
+static inline void strcat_escape_quotes(char* dst, const char* src)
{
// get to the end of the dst string first
while(*dst)
dst++;
- char* c;
+ char c;
while(c = *src++){
if(c == '\'' || c == '"')
*dst++ = '\\';

0 comments on commit 6625745

Please sign in to comment.