Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Report POST output in http-curl

Fix bug with null placement
  • Loading branch information...
commit cce81e028935adcd4f6c296455eb4112af2aae1b 1 parent 4525d51
@mxcl mxcl authored
Showing with 10 additions and 5 deletions.
  1. +10 −5 resolvers/audioscrobbler/http-curl.c
View
15 resolvers/audioscrobbler/http-curl.c
@@ -37,7 +37,7 @@ 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-- <= 0) break;
+ if (++n == 255) break;
*(char*)out++ = *(char*)in++;
}
@@ -46,7 +46,7 @@ static size_t curl_writer(void* in, size_t size, size_t N, void* out)
void scrobsub_get(char response[256], const char* url)
{
- n = 256;
+ n = 0;
CURL* h = curl_easy_init(); //TODO may return NULL
curl_easy_setopt(h, CURLOPT_URL, url);
@@ -55,15 +55,20 @@ void scrobsub_get(char response[256], const char* url)
CURLcode result = curl_easy_perform(h);
curl_easy_cleanup(h);
- response[255-n] = '\0'; // curl_writer won't null terminate
+ response[n] = '\0'; // curl_writer won't null terminate
}
void scrobsub_post(char response[256], const char* url, const char* post_data)
-{
+{
+ n = 0;
+
CURL* h = curl_easy_init(); //TODO may return NULL
curl_easy_setopt(h, CURLOPT_POSTFIELDS, post_data);
curl_easy_setopt(h, CURLOPT_URL, url);
+ curl_easy_setopt(h, CURLOPT_WRITEFUNCTION, curl_writer);
+ curl_easy_setopt(h, CURLOPT_WRITEDATA, response);
curl_easy_perform(h);
curl_easy_cleanup(h);
- strcpy(response, "OK\n"); //TODO
+
+ response[n] = '\0'; // curl_writer won't null terminate
}
Please sign in to comment.
Something went wrong with that request. Please try again.