- /* verify if there is data to submit
- * and if waiting interval is elapsed */
- if ( ( p_sys->p_first_queue->i_songs_nb > 0 ) &&
- ( time( NULL ) >= p_sys->time_next_exchange ) )
- {
- /* handshake if needed */
- if( p_sys->b_handshaked == VLC_FALSE )
- {
- msg_Dbg( p_this, "Handshaking with last.fm ..." );
-
- switch( Handshake( p_this ) )
- {
- case VLC_ENOMEM:
- MEM_ERROR
- break;
-
- case VLC_ENOVAR:
- /* username not set */
- vlc_mutex_unlock ( &p_sys->lock );
- intf_UserFatal( p_this, VLC_FALSE,
- _("Last.fm username not set"),
- _("Please set an username or disable "
- "audioscrobbler plugin, and then restart VLC.\n"
- "Visit https://www.last.fm/join/ to get an account")
- );
- free( psz_submit );
- free( psz_submit_song );
- free( p_buffer );
- return;
- break;
-
- case VLC_SUCCESS:
- msg_Dbg( p_this, "Handshake successfull :)" );
- vlc_mutex_lock ( &p_sys->lock );
- p_sys->b_handshaked = VLC_TRUE;
- vlc_mutex_unlock ( &p_sys->lock );
- break;
-
- case VLC_EGENERIC:
- default:
- /* protocol error : we'll try later */
- vlc_mutex_lock ( &p_sys->lock );
- time( &p_sys->time_next_exchange );
- p_sys->time_next_exchange += DEFAULT_INTERVAL;
- vlc_mutex_unlock ( &p_sys->lock );
- break;
- }
- }
-
- msg_Dbg( p_this, "Going to submit some data..." );
- vlc_mutex_lock ( &p_sys->lock );
-
- snprintf( psz_submit, HTTPPOST_MAXLEN, "u=%s&s=%s",
- p_sys->psz_username, p_sys->psz_response_md5 );
-
- /* forge the HTTP POST request */
- for (i_song = 0 ; i_song < p_sys->p_first_queue->i_songs_nb ;
- i_song++ )
- {
- snprintf( psz_submit_song, HTTPPOST_MAXLEN -1, POST_DATA,
- i_song, p_sys->p_first_queue->p_queue[i_song]->psz_a,
- i_song, p_sys->p_first_queue->p_queue[i_song]->psz_t,
- i_song, p_sys->p_first_queue->p_queue[i_song]->psz_b,
- i_song, p_sys->p_first_queue->p_queue[i_song]->psz_m,
- i_song, p_sys->p_first_queue->p_queue[i_song]->i_l,
- i_song, p_sys->p_first_queue->p_queue[i_song]->psz_i
- );
- strncat( psz_submit, psz_submit_song, HTTPPOST_MAXLEN - 1 );
- }
-
- i_post_socket = net_ConnectTCP( p_this,
- p_sys->psz_submit_host, p_sys->i_submit_port);
-
- if ( i_post_socket == -1 )
- {
- /* If connection fails, we assume we must handshake again */
- time( &p_sys->time_next_exchange );
- p_sys->time_next_exchange += DEFAULT_INTERVAL;
- p_sys->b_handshaked = VLC_FALSE;
- vlc_mutex_unlock( &p_sys->lock );
- continue;
- }
-
- /* we transmit the data */
- i_net_ret = net_Printf(
- VLC_OBJECT(p_this), i_post_socket, NULL,
- POST_REQUEST, p_sys->psz_submit_file,
- strlen( psz_submit ), p_sys->psz_submit_file,
- VERSION, psz_submit
- );
-
- if ( i_net_ret == -1 )
- {
- /* If connection fails, we assume we must handshake again */
- time( &p_sys->time_next_exchange );
- p_sys->time_next_exchange += DEFAULT_INTERVAL;
- p_sys->b_handshaked = VLC_FALSE;
- vlc_mutex_unlock( &p_sys->lock );
- continue;
- }
-
- memset( p_buffer, '\0', 1024 );
-
- i_net_ret = net_Read( p_this, i_post_socket, NULL,
- p_buffer, 1024, VLC_FALSE );
- if ( i_net_ret <= 0 )
- {
- /* if we get no answer, something went wrong : try again */
- vlc_mutex_unlock( &p_sys->lock );
- continue;
- }
-
- net_Close( i_post_socket );
-
- /* record interval */
- p_buffer_pos = strstr( ( char * ) p_buffer, "INTERVAL" );
- if ( p_buffer_pos )
- {
- time( &p_sys->time_next_exchange );
- p_sys->time_next_exchange += atoi( p_buffer_pos +
- strlen( "INTERVAL " ) );
- }