crap!<br><br>I'm sorry the commit message is wrong...<br><br>"Audioscrobbler: Remove the old protocol version 1.2" is better.<br><br>I will not remove the protocol introduced in the previous patch. :)<br><br>

<div class="gmail_quote">On Fri, Feb 24, 2012 at 11:08 PM, Samuel Pitoiset <span dir="ltr"><<a href="mailto:samuel.pitoiset@gmail.com">samuel.pitoiset@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

---<br>
 modules/misc/audioscrobbler.c |  418 +----------------------------------------<br>
 1 files changed, 4 insertions(+), 414 deletions(-)<br>
<br>
diff --git a/modules/misc/audioscrobbler.c b/modules/misc/audioscrobbler.c<br>
index 9acd92d..ba9ed53 100644<br>
--- a/modules/misc/audioscrobbler.c<br>
+++ b/modules/misc/audioscrobbler.c<br>
@@ -22,11 +22,10 @@<br>
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.<br>
  *****************************************************************************/<br>
<br>
-/* audioscrobbler protocol version: 1.2<br>
- * <a href="http://www.audioscrobbler.net/development/protocol/" target="_blank">http://www.audioscrobbler.net/development/protocol/</a><br>
+/* audioscrobbler protocol version: 2.0<br>
+ * <a href="http://www.last.fm/api/scrobbling" target="_blank">http://www.last.fm/api/scrobbling</a><br>
  *<br>
  * TODO:    "Now Playing" feature (not mandatory)<br>
- *          Update to new API? <a href="http://www.lastfm.fr/api" target="_blank">http://www.lastfm.fr/api</a><br>
  */<br>
 /*****************************************************************************<br>
  * Preamble<br>
@@ -778,7 +777,7 @@ static char *BuildSignedRequest(intf_thread_t *p_this, vlc_array_t *p_params,<br>
 /*****************************************************************************<br>
  * Handshake : Init audioscrobbler connection<br>
  *****************************************************************************/<br>
-static int NewHandshake(intf_thread_t *p_this)<br>
+static int Handshake(intf_thread_t *p_this)<br>
 {<br>
     char                *psz_username, *psz_password, *psz_auth_token;<br>
     char                *psz_scrobbler_url, *psz_handshake_url;<br>
@@ -986,211 +985,6 @@ proto:<br>
     return VLC_EGENERIC;<br>
 }<br>
<br>
-/*****************************************************************************<br>
- * Handshake : Init audioscrobbler connection<br>
- *****************************************************************************/<br>
-static int Handshake(intf_thread_t *p_this)<br>
-{<br>
-    char                *psz_username, *psz_password;<br>
-    char                *psz_scrobbler_url;<br>
-    time_t              timestamp;<br>
-    char                psz_timestamp[21];<br>
-<br>
-    struct md5_s        p_struct_md5;<br>
-<br>
-    stream_t            *p_stream;<br>
-    char                *psz_handshake_url;<br>
-    uint8_t             p_buffer[1024];<br>
-    char                *p_buffer_pos;<br>
-<br>
-    int                 i_ret;<br>
-    char                *psz_url;<br>
-<br>
-    intf_thread_t       *p_intf                 = (intf_thread_t*) p_this;<br>
-    intf_sys_t          *p_sys                  = p_this->p_sys;<br>
-<br>
-    psz_username = var_InheritString(p_this, "lastfm-username");<br>
-    if (!psz_username)<br>
-        return VLC_ENOMEM;<br>
-<br>
-    psz_password = var_InheritString(p_this, "lastfm-password");<br>
-    if (!psz_password)<br>
-    {<br>
-        free(psz_username);<br>
-        return VLC_ENOMEM;<br>
-    }<br>
-<br>
-    /* username or password have not been setup */<br>
-    if (!*psz_username || !*psz_password)<br>
-    {<br>
-        free(psz_username);<br>
-        free(psz_password);<br>
-        return VLC_ENOVAR;<br>
-    }<br>
-<br>
-    time(&timestamp);<br>
-<br>
-    /* generates a md5 hash of the password */<br>
-    InitMD5(&p_struct_md5);<br>
-    AddMD5(&p_struct_md5, (uint8_t*) psz_password, strlen(psz_password));<br>
-    EndMD5(&p_struct_md5);<br>
-<br>
-    free(psz_password);<br>
-<br>
-    char *psz_password_md5 = psz_md5_hash(&p_struct_md5);<br>
-    if (!psz_password_md5)<br>
-    {<br>
-        free(psz_username);<br>
-        return VLC_ENOMEM;<br>
-    }<br>
-<br>
-    snprintf(psz_timestamp, sizeof(psz_timestamp), "%"PRIu64,<br>
-              (uint64_t)timestamp);<br>
-<br>
-    /* generates a md5 hash of :<br>
-     * - md5 hash of the password, plus<br>
-     * - timestamp in clear text<br>
-     */<br>
-    InitMD5(&p_struct_md5);<br>
-    AddMD5(&p_struct_md5, (uint8_t*) psz_password_md5, 32);<br>
-    AddMD5(&p_struct_md5, (uint8_t*) psz_timestamp, strlen(psz_timestamp));<br>
-    EndMD5(&p_struct_md5);<br>
-    free(psz_password_md5);<br>
-<br>
-    char *psz_auth_token = psz_md5_hash(&p_struct_md5);<br>
-    if (!psz_auth_token)<br>
-    {<br>
-        free(psz_username);<br>
-        return VLC_ENOMEM;<br>
-    }<br>
-<br>
-    psz_scrobbler_url = var_InheritString(p_this, "scrobbler-url");<br>
-    if (!psz_scrobbler_url)<br>
-    {<br>
-        free(psz_username);<br>
-        return VLC_ENOMEM;<br>
-    }<br>
-<br>
-    i_ret = asprintf(&psz_handshake_url,<br>
-    "http://%s/?hs=true&p=1.2&c="CLIENT_NAME"&v="CLIENT_VERSION"&u=%s&t=%s&a=%s"<br>
-    , psz_scrobbler_url, psz_username, psz_timestamp, psz_auth_token);<br>
-<br>
-    free(psz_scrobbler_url);<br>
-    free(psz_username);<br>
-    if (i_ret == -1)<br>
-        return VLC_ENOMEM;<br>
-<br>
-    /* send the http handshake request */<br>
-    p_stream = stream_UrlNew(p_intf, psz_handshake_url);<br>
-    free(psz_handshake_url);<br>
-<br>
-    if (!p_stream)<br>
-        return VLC_EGENERIC;<br>
-<br>
-    /* read answer */<br>
-    i_ret = stream_Read(p_stream, p_buffer, sizeof(p_buffer) - 1);<br>
-    if (i_ret == 0)<br>
-    {<br>
-        stream_Delete(p_stream);<br>
-        return VLC_EGENERIC;<br>
-    }<br>
-    p_buffer[i_ret] = '\0';<br>
-    stream_Delete(p_stream);<br>
-<br>
-    p_buffer_pos = strstr((char*) p_buffer, "FAILED ");<br>
-    if (p_buffer_pos)<br>
-    {<br>
-        /* handshake request failed, sorry */<br>
-        msg_Err(p_this, "<a href="http://last.fm" target="_blank">last.fm</a> handshake failed: %s", p_buffer_pos + 7);<br>
-        return VLC_EGENERIC;<br>
-    }<br>
-<br>
-    if (strstr((char*) p_buffer, "BADAUTH"))<br>
-    {<br>
-        /* authentication failed, bad username/password combination */<br>
-        dialog_Fatal(p_this,<br>
-            _("<a href="http://last.fm" target="_blank">last.fm</a>: Authentication failed"),<br>
-            "%s", _("<a href="http://last.fm" target="_blank">last.fm</a> username or password is incorrect. "<br>
-              "Please verify your settings and relaunch VLC."));<br>
-        return VLC_AUDIOSCROBBLER_EFATAL;<br>
-    }<br>
-<br>
-    if (strstr((char*) p_buffer, "BANNED"))<br>
-    {<br>
-        /* oops, our version of vlc has been banned by <a href="http://last.fm" target="_blank">last.fm</a> servers */<br>
-        msg_Err(p_intf, "This version of VLC has been banned by <a href="http://last.fm" target="_blank">last.fm</a>. "<br>
-                         "You should upgrade VLC, or disable the <a href="http://last.fm" target="_blank">last.fm</a> plugin.");<br>
-        return VLC_AUDIOSCROBBLER_EFATAL;<br>
-    }<br>
-<br>
-    if (strstr((char*) p_buffer, "BADTIME"))<br>
-    {<br>
-        /* The system clock isn't good */<br>
-        msg_Err(p_intf, "<a href="http://last.fm" target="_blank">last.fm</a> handshake failed because your clock is too "<br>
-                         "much shifted. Please correct it, and relaunch VLC.");<br>
-        return VLC_AUDIOSCROBBLER_EFATAL;<br>
-    }<br>
-<br>
-    p_buffer_pos = strstr((char*) p_buffer, "OK");<br>
-    if (!p_buffer_pos)<br>
-        goto proto;<br>
-<br>
-    p_buffer_pos = strstr(p_buffer_pos, "\n");<br>
-    if (!p_buffer_pos || strlen(p_buffer_pos) < 33)<br>
-        goto proto;<br>
-    p_buffer_pos++; /* we skip the '\n' */<br>
-<br>
-    /* save the session ID */<br>
-    memcpy(p_sys->psz_auth_token, p_buffer_pos, 32);<br>
-    p_sys->psz_auth_token[32] = '\0';<br>
-<br>
-    p_buffer_pos = strstr(p_buffer_pos, "http://");<br>
-    if (!p_buffer_pos || strlen(p_buffer_pos) == 7)<br>
-        goto proto;<br>
-<br>
-    /* We need to read the nowplaying url */<br>
-    p_buffer_pos += 7; /* we skip "http://" */<br>
-#if 0 //NOT USED<br>
-    psz_url = strndup(p_buffer_pos, strcspn(p_buffer_pos, "\n"));<br>
-    if (!psz_url)<br>
-        goto oom;<br>
-<br>
-    switch(ParseURL(psz_url, &p_sys->psz_nowp_host,<br>
-                &p_sys->psz_nowp_file, &p_sys->i_nowp_port))<br>
-    {<br>
-        case VLC_ENOMEM:<br>
-            goto oom;<br>
-        case VLC_EGENERIC:<br>
-            goto proto;<br>
-        case VLC_SUCCESS:<br>
-        default:<br>
-            break;<br>
-    }<br>
-#endif<br>
-    p_buffer_pos = strstr(p_buffer_pos, "http://");<br>
-    if (!p_buffer_pos || strlen(p_buffer_pos) == 7)<br>
-        goto proto;<br>
-<br>
-    /* We need to read the submission url */<br>
-    p_buffer_pos += 7; /* we skip "http://" */<br>
-    psz_url = strndup(p_buffer_pos, strcspn(p_buffer_pos, "\n"));<br>
-    if (!psz_url)<br>
-        goto oom;<br>
-<br>
-    /* parse the submission url */<br>
-    vlc_UrlParse(&p_sys->p_submit_url, psz_url, 0);<br>
-    free(psz_url);<br>
-<br>
-    return VLC_SUCCESS;<br>
-<br>
-oom:<br>
-    return VLC_ENOMEM;<br>
-<br>
-proto:<br>
-    msg_Err(p_intf, "Handshake: can't recognize server protocol");<br>
-    return VLC_EGENERIC;<br>
-}<br>
-<br>
 static void HandleInterval(mtime_t *next, unsigned int *i_interval)<br>
 {<br>
     if (*i_interval == 0)<br>
@@ -1382,7 +1176,7 @@ proto:<br>
 /*****************************************************************************<br>
  * Run : call Handshake() then submit songs<br>
  *****************************************************************************/<br>
-static void NewRun(intf_thread_t *p_this)<br>
+static void Run(intf_thread_t *p_this)<br>
 {<br>
     int                     canc = vlc_savecancel();<br>
     bool                    b_handshaked = false;<br>
@@ -1476,207 +1270,3 @@ static void NewRun(intf_thread_t *p_this)<br>
     vlc_restorecancel(canc);<br>
 }<br>
<br>
-/*****************************************************************************<br>
- * Run : call Handshake() then submit songs<br>
- *****************************************************************************/<br>
-static void Run(intf_thread_t *p_intf)<br>
-{<br>
-    uint8_t                 p_buffer[1024];<br>
-    int                     canc = vlc_savecancel();<br>
-    bool                    b_handshaked = false;<br>
-<br>
-    /* data about audioscrobbler session */<br>
-    mtime_t                 next_exchange;      /**< when can we send data  */<br>
-    unsigned int            i_interval;         /**< waiting interval (secs)*/<br>
-<br>
-    intf_sys_t *p_sys = p_intf->p_sys;<br>
-<br>
-    /* main loop */<br>
-    for (;;)<br>
-    {<br>
-        vlc_restorecancel(canc);<br>
-        vlc_mutex_lock(&p_sys->lock);<br>
-        mutex_cleanup_push(&p_sys->lock);<br>
-<br>
-        do<br>
-            vlc_cond_wait(&p_sys->wait, &p_sys->lock);<br>
-        while (mdate() < next_exchange);<br>
-<br>
-        vlc_cleanup_run();<br>
-        canc = vlc_savecancel();<br>
-<br>
-        /* handshake if needed */<br>
-        if (!b_handshaked)<br>
-        {<br>
-            msg_Dbg(p_intf, "Handshaking with <a href="http://last.fm" target="_blank">last.fm</a> ...");<br>
-<br>
-            switch(Handshake(p_intf))<br>
-            {<br>
-                case VLC_ENOMEM:<br>
-                    return;<br>
-<br>
-                case VLC_ENOVAR:<br>
-                    /* username not set */<br>
-                    dialog_Fatal(p_intf,<br>
-                        _("Last.fm username not set"),<br>
-                        "%s", _("Please set a username or disable the "<br>
-                        "audioscrobbler plugin, and restart VLC.\n"<br>
-                        "Visit <a href="http://www.last.fm/join/" target="_blank">http://www.last.fm/join/</a> to get an account.")<br>
-                   );<br>
-                    return;<br>
-<br>
-                case VLC_SUCCESS:<br>
-                    msg_Dbg(p_intf, "Handshake successfull :)");<br>
-                    b_handshaked = true;<br>
-                    i_interval = 0;<br>
-                    next_exchange = mdate();<br>
-                    break;<br>
-<br>
-                case VLC_AUDIOSCROBBLER_EFATAL:<br>
-                    msg_Warn(p_intf, "Exiting...");<br>
-                    return;<br>
-<br>
-                case VLC_EGENERIC:<br>
-                default:<br>
-                    /* protocol error : we'll try later */<br>
-                    HandleInterval(&next_exchange, &i_interval);<br>
-                    break;<br>
-            }<br>
-            /* if handshake failed let's restart the loop */<br>
-            if (!b_handshaked)<br>
-                continue;<br>
-        }<br>
-<br>
-        msg_Dbg(p_intf, "Going to submit some data...");<br>
-        char *psz_submit;<br>
-        if (asprintf(&psz_submit, "s=%s", p_sys->psz_auth_token) == -1)<br>
-            return;<br>
-<br>
-        /* forge the HTTP POST request */<br>
-        vlc_mutex_lock(&p_sys->lock);<br>
-        audioscrobbler_song_t *p_song;<br>
-        for (int i_song = 0 ; i_song < p_sys->i_songs ; i_song++)<br>
-        {<br>
-            char *psz_submit_song, *psz_submit_tmp;<br>
-            p_song = &p_sys->p_queue[i_song];<br>
-            if (asprintf(&psz_submit_song,<br>
-                    "&a%%5B%d%%5D=%s"<br>
-                    "&t%%5B%d%%5D=%s"<br>
-                    "&i%%5B%d%%5D=%u"<br>
-                    "&o%%5B%d%%5D=P"<br>
-                    "&r%%5B%d%%5D="<br>
-                    "&l%%5B%d%%5D=%d"<br>
-                    "&b%%5B%d%%5D=%s"<br>
-                    "&n%%5B%d%%5D=%s"<br>
-                    "&m%%5B%d%%5D=%s",<br>
-                    i_song, p_song->psz_a,<br>
-                    i_song, p_song->psz_t,<br>
-                    i_song, (unsigned)p_song->date, /* HACK: %ju (uintmax_t) unsupported on Windows */<br>
-                    i_song,<br>
-                    i_song,<br>
-                    i_song, p_song->i_l,<br>
-                    i_song, p_song->psz_b,<br>
-                    i_song, p_song->psz_n,<br>
-                    i_song, p_song->psz_m<br>
-           ) == -1)<br>
-            {   /* Out of memory */<br>
-                vlc_mutex_unlock(&p_sys->lock);<br>
-                return;<br>
-            }<br>
-            psz_submit_tmp = psz_submit;<br>
-            if (asprintf(&psz_submit, "%s%s",<br>
-                    psz_submit_tmp, psz_submit_song) == -1)<br>
-            {   /* Out of memory */<br>
-                free(psz_submit_tmp);<br>
-                free(psz_submit_song);<br>
-                vlc_mutex_unlock(&p_sys->lock);<br>
-                return;<br>
-            }<br>
-            free(psz_submit_song);<br>
-            free(psz_submit_tmp);<br>
-        }<br>
-        vlc_mutex_unlock(&p_sys->lock);<br>
-<br>
-        int i_post_socket = net_ConnectTCP(p_intf, p_sys->p_submit_url.psz_host,<br>
-                                        p_sys->p_submit_url.i_port);<br>
-<br>
-        if (i_post_socket == -1)<br>
-        {<br>
-            /* If connection fails, we assume we must handshake again */<br>
-            HandleInterval(&next_exchange, &i_interval);<br>
-            b_handshaked = false;<br>
-            free(psz_submit);<br>
-            continue;<br>
-        }<br>
-<br>
-        /* we transmit the data */<br>
-        int i_net_ret = net_Printf(p_intf, i_post_socket, NULL,<br>
-            "POST %s HTTP/1.1\n"<br>
-            "Accept-Encoding: identity\n"<br>
-            "Content-length: %zu\n"<br>
-            "Connection: close\n"<br>
-            "Content-type: application/x-www-form-urlencoded\n"<br>
-            "Host: %s\n"<br>
-            "User-agent: VLC media player/"VERSION"\r\n"<br>
-            "\r\n"<br>
-            "%s\r\n"<br>
-            "\r\n",<br>
-            p_sys->p_submit_url.psz_path, strlen(psz_submit),<br>
-            p_sys->p_submit_url.psz_host, psz_submit<br>
-       );<br>
-<br>
-        free(psz_submit);<br>
-        if (i_net_ret == -1)<br>
-        {<br>
-            /* If connection fails, we assume we must handshake again */<br>
-            HandleInterval(&next_exchange, &i_interval);<br>
-            b_handshaked = false;<br>
-            continue;<br>
-        }<br>
-<br>
-        i_net_ret = net_Read(p_intf, i_post_socket, NULL,<br>
-                    p_buffer, sizeof(p_buffer) - 1, false);<br>
-        if (i_net_ret <= 0)<br>
-        {<br>
-            /* if we get no answer, something went wrong : try again */<br>
-            continue;<br>
-        }<br>
-<br>
-        net_Close(i_post_socket);<br>
-        p_buffer[i_net_ret] = '\0';<br>
-<br>
-        char *failed = strstr((char *) p_buffer, "FAILED");<br>
-        if (failed)<br>
-        {<br>
-            msg_Warn(p_intf, "%s", failed);<br>
-            HandleInterval(&next_exchange, &i_interval);<br>
-            continue;<br>
-        }<br>
-<br>
-        if (strstr((char *) p_buffer, "BADSESSION"))<br>
-        {<br>
-            msg_Err(p_intf, "Authentication failed (BADSESSION), are you connected to <a href="http://last.fm" target="_blank">last.fm</a> with another program ?");<br>
-            b_handshaked = false;<br>
-            HandleInterval(&next_exchange, &i_interval);<br>
-            continue;<br>
-        }<br>
-<br>
-        if (strstr((char *) p_buffer, "OK"))<br>
-        {<br>
-            for (int i = 0; i < p_sys->i_songs; i++)<br>
-                DeleteSong(&p_sys->p_queue[i]);<br>
-            p_sys->i_songs = 0;<br>
-            i_interval = 0;<br>
-            next_exchange = mdate();<br>
-            msg_Dbg(p_intf, "Submission successful!");<br>
-        }<br>
-        else<br>
-        {<br>
-            msg_Err(p_intf, "Authentication failed, handshaking again (%s)",<br>
-                             p_buffer);<br>
-            b_handshaked = false;<br>
-            HandleInterval(&next_exchange, &i_interval);<br>
-        }<br>
-    }<br>
-    vlc_restorecancel(canc);<br>
-}<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.9<br>
<br>
</font></span></blockquote></div><br><br clear="all"><br>-- <br><div>Best regards,</div>Samuel Pitoiset.<br><br>