- if( p_sys->b_handshaked == VLC_FALSE )
- {
- if ( time( NULL ) >=
- ( p_sys->time_last_interval + p_sys->i_interval ) )
- {
- msg_Dbg( p_this, "Handshaking with last.fm ..." );
- i_handshake = Handshake( p_this );
-
- if( i_handshake == VLC_ENOMEM )
- {
- msg_Err( p_this, "Out of memory" );
- return;
- }
-
- else if( i_handshake == VLC_ENOVAR )
- /* username not set */
- {
- msg_Dbg( p_this, "Set an username then restart vlc" );
- vlc_mutex_unlock ( &p_sys->lock );
- return;
- }
-
- else if( i_handshake == 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 );
- }
-
- else
- {
- vlc_mutex_lock ( &p_sys->lock );
- p_sys->i_interval = DEFAULT_INTERVAL;
- time( &p_sys->time_last_interval );
- vlc_mutex_unlock ( &p_sys->lock );
- }
- }
- }
-
- else
- {
- if ( ( p_sys->p_first_queue->i_songs_nb > 0 ) &&
- ( time( NULL ) >=
- ( p_sys->time_last_interval + p_sys->i_interval ) ) )
- {
- msg_Dbg( p_this, "Going to submit some data..." );
- vlc_mutex_lock ( &p_sys->lock );
- psz_submit_string = malloc( 2048 * sizeof( char ) );
-
- if (!psz_submit_string)
- {
- msg_Err( p_this, "Out of memory" );
- vlc_mutex_unlock ( &p_sys->lock );
- return;
- }
-
- for (i_song = 0; i_song < p_sys->p_first_queue->i_songs_nb ;
- i_song++ )
- {
- snprintf( psz_submit_string, 2048, POST_DATA,
- p_sys->psz_username, p_sys->psz_response_md5,
- 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,
- 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
- );
- }
-
- p_sys->i_post_socket = net_ConnectTCP( p_this,
- p_sys->psz_submit_host, p_sys->i_submit_port);
-
- i_netprintf = net_Printf(
- VLC_OBJECT(p_this), p_sys->i_post_socket, NULL,
- POST_REQUEST, p_sys->psz_submit_file,
- strlen( psz_submit_string), p_sys->psz_submit_file,
- VERSION, psz_submit_string
- );
-
- if ( i_netprintf == -1 )
- {
- /* If connection fails, we assume we must handshake again */
- p_sys->i_interval = DEFAULT_INTERVAL;
- time( &p_sys->time_last_interval );
- p_sys->b_handshaked = VLC_FALSE;
- vlc_mutex_unlock ( &p_sys->lock );
- return;
- }
-
- p_buffer = ( uint8_t* ) calloc( 1, 1024 );
- if ( !p_buffer )
- {
- msg_Err( p_this, "Out of memory" );
- vlc_mutex_unlock ( &p_sys->lock );
- return;
- }
-
- net_Read( p_this, p_sys->i_post_socket, NULL,
- p_buffer, 1024, VLC_FALSE );
- net_Close( p_sys->i_post_socket );
-
- p_buffer_pos = strstr( ( char * ) p_buffer, "INTERVAL" );
-
- if ( p_buffer_pos )
- {
- p_sys->i_interval = atoi( p_buffer_pos +
- strlen( "INTERVAL " ) );
- time( &p_sys->time_last_interval );
- }
-
- p_buffer_pos = strstr( ( char * ) p_buffer, "FAILED" );
-
- if ( p_buffer_pos )
- {
- msg_Err( p_this, p_buffer_pos );
- vlc_mutex_unlock ( &p_sys->lock );
- return;
- }