示例#1
0
文件: scrobsol.c 项目: RJ/playdar
static bool handshake()
{
    scrobsub_finish_auth();
    
    if (!scrobsub_session_key || !scrobsub_username)
        return false; //TODO auth required AGAIN
    
    char* username = escape(scrobsub_username);
    time_t time = now();
    char auth[33];
    get_handshake_auth(auth, time);
    int n = 34+8+8+6+11+3+strlen(username)+13+32+9+32+4+32+1;
#if SCROBSUB_NO_C99
    char* url = (char*)alloca(n); //alloca discouraged on BSD
#else
    char url[n];
#endif
    
    n = snprintf(url, n, "http://post.audioscrobbler.com:80/"
                 "?hs=true"
                 "&p=1.2.1"
                 "&c=" SCROBSUB_CLIENT_ID      // length 3
                 "&v=" SCROBSUB_CLIENT_VERSION // length 8 max
                 "&u=%s"
                 "&t=%d" // length 10 for the next millenia at least :P
                 "&a=%s" // length 32
                 "&api_key=" SCROBSUB_API_KEY // length 32
                 "&sk=%s", // length 32
                 username, time, auth, scrobsub_session_key);
    free(username);

    if (n<0) return false; //TODO error callback

    char responses[256];
    scrobsub_get(responses, url);
    
    char* response = responses;
    if(ok(response)){
        response += 3;
        session_id = handshake_response_strdup(&response);
        np_url = handshake_response_strdup(&response);
        submit_url = handshake_response_strdup(&response);
        return true;
    }else{
        //TODO better
        (scrobsub_callback)(SCROBSUB_ERROR_RESPONSE, response);
        return false;
    }
}
示例#2
0
static void handshake()
{
    const char* session_key = scrobsub_session_key();
    const char* username = scrobsub_username();
    
    if (!session_key || !username)
        return; //TODO auth required
    
    time_t time = now();
    char auth[33];
    get_auth(auth, time);
    int n = 34+8+8+6+11+3+strlen(username)+13+32+9+32+4+32+1;
    char url[n];
    
    n = snprintf(url, n, "http://post.audioscrobbler.com:80/"
                 "?hs=true"
                 "&p=1.2.1"
                 "&c=" SCROBSUB_CLIENT_ID      // length 3
                 "&v=" SCROBSUB_CLIENT_VERSION // length 8 max
                 "&u=%s"
                 "&t=%d" // length 10 for the next millenia at least :P
                 "&a=%s" // length 32
                 "&api_key=" SCROBSUB_API_KEY // length 32
                 "&sk=%s", // length 32
                 username, time, auth, session_key);
    if (n<0) return; //TODO error callback

    char responses[256];
    char* response = responses;
    scrobsub_get(responses, url);

    if(ok(response)){
        response += 3;
        session_id = handshake_response_strdup(&response);
        np_url = handshake_response_strdup(&response);
        submit_url = handshake_response_strdup(&response);
    }else
        //TODO better
        (scrobsub_callback)(SCROBSUB_ERROR_RESPONSE, response);
}