static int scrobbler_send_handshake ( char *  key,
char **  url 
) [static]

Send a handshake to the AudioScrobbler server. Also catch whether the configured password is correct.

Definition at line 352 of file scrobbler.c.

00353 {
00354         char *hsurl;
00355         char hskey[33];
00356         time_t hstime;
00357         CURL *con;
00358         GString *response;
00359         char *lines[4];
00360         int ret;
00361 
00362         con = curl_easy_init();
00363         if (con == NULL)
00364                 return (-1);
00365         
00366         /* Generate the connection URL, including the password key */
00367         hstime = time(NULL);
00368         scrobbler_hash(hstime, hskey);
00369         hskey[32] = '\0';
00370         hsurl = g_strdup_printf(SCROBBLER_URL,
00371             config_getopt("scrobbler.hostname"),
00372             config_getopt("scrobbler.username"),
00373             (unsigned int)hstime, hskey);
00374         curl_easy_setopt(con, CURLOPT_URL, hsurl);
00375         curl_easy_setopt(con, CURLOPT_USERAGENT, APP_NAME "/" APP_VERSION);
00376 
00377         /* Callback function */
00378         response = g_string_sized_new(128);
00379         curl_easy_setopt(con, CURLOPT_WRITEFUNCTION, scrobbler_curl_concat);
00380         curl_easy_setopt(con, CURLOPT_WRITEDATA, response);
00381 
00382         /* Here we go */
00383         ret = curl_easy_perform(con);
00384         curl_easy_cleanup(con);
00385         g_free(hsurl);
00386 
00387         /* Connection error */
00388         if (ret != 0)
00389                 goto done;
00390 
00391         ret = -1;
00392         scrobbler_split_lines(response->str, lines, 4);
00393 
00394         /* First line must be "OK" */
00395         if (lines[0] == NULL || strcmp(lines[0], "OK") != 0) {
00396                 if (lines[0] != NULL && strcmp(lines[0], "BADAUTH") == 0)
00397                         ret = 0;
00398                 goto done;
00399         }
00400         /* Make sure the checksum is there */
00401         if (lines[1] == NULL || strlen(lines[1]) != 32)
00402                 goto done;
00403         memcpy(key, lines[1], 32);
00404 
00405         /* Copy the submission URL */
00406         if (lines[3] == NULL)
00407                 goto done;
00408         g_free(*url);
00409         *url = g_strdup(lines[3]);
00410 
00411         ret = 0;
00412 done:
00413         g_string_free(response, TRUE);
00414         return (ret);
00415 }

Here is the call graph for this function:

Here is the caller graph for this function:

 All Data Structures Files Functions Variables Defines
Generated on Mon Mar 15 04:45:47 2010 for herrie by  doxygen 1.6.3