Beispiel #1
0
// Catches SIGINT and exits gracefully
static void sigint_handler(evutil_socket_t socket,
                           short what,
                           void *userdata) {
  fprintf(stderr, "signal_handler\n");
  struct state *state = userdata;
  sp_session_logout(state->session);
}
// Catches SIGINT and exits gracefully
static void sigint_handler(evutil_socket_t socket,
                           short what,
                           void *userdata) {
  syslog(LOG_DEBUG, "signal_handler\n");
  struct state *state = userdata;
  sp_session_logout(state->session);
}
Beispiel #3
0
void logout(list<int> int_params, list<string> string_params, sp_session *session, sp_track *track) {
    if (session == NULL)
        exitl("Logged out before session was initialized");
    sp_error error = sp_session_logout(session);
    if (error != SP_ERROR_OK)
        log ("!!!logout error occurred: %s",sp_error_message(error));
}
Beispiel #4
0
void QSpotifySession::logout(bool keepLoginInfo)
{
    qDebug() << "QSpotifySession::logout";
    if (!m_isLoggedIn || m_pending_connectionRequest)
        return;

    stop();
    m_playQueue->clear();

    if (!keepLoginInfo) {
        setOfflineMode(false);
        sp_session_forget_me(m_sp_session);
    }

    m_explicitLogout = true;

    m_pending_connectionRequest = true;
    emit pendingConnectionRequestChanged();
    emit loggingOut();

    if(m_user) {
        m_user->deleteLater();
        m_user = nullptr;
    }
    sp_session_logout(m_sp_session);
}
Beispiel #5
0
static void playlistcontainer_loaded(sp_playlistcontainer *pc, void *userdata) {
  syslog(LOG_DEBUG, "playlistcontainer_loaded\n");
  sp_session *session = userdata;
  struct state *state = sp_session_userdata(session);

  sp_playlistcontainer_remove_callbacks(pc, &playlistcontainer_callbacks, session);

  state->http = evhttp_new(state->event_base);
  evhttp_set_timeout(state->http, 60);
  evhttp_set_gencb(state->http, &handle_request, state);

  // Bind HTTP server
  int bind = evhttp_bind_socket(state->http, state->http_host,
                                state->http_port);

  if (bind == -1) {
    syslog(LOG_WARNING, "Could not bind HTTP server socket to %s:%d",
           state->http_host, state->http_port);
    sp_session_logout(session);
    return;
  }

  syslog(LOG_DEBUG, "HTTP server listening on %s:%d", state->http_host,
         state->http_port);
}
Beispiel #6
0
static PyObject *
Session_logout(Session * self)
{
    Py_BEGIN_ALLOW_THREADS;
    sp_session_logout(self->_session);
    Py_END_ALLOW_THREADS;

    Py_RETURN_NONE;
};
void Spotify::logout()
{
    sp_error err = sp_session_logout(sp);
    if (err != SP_ERROR_OK) {
        qDebug() << "Unable to logout:" << QString::fromLocal8Bit(sp_error_message(err));
    } else {
        qDebug() << "Logout request posted";
    }
}
Beispiel #8
0
static PyObject *
Session_logout(PyObject *self)
{
    Py_BEGIN_ALLOW_THREADS;
    sp_session_logout(Session_SP_SESSION(self));
    Py_END_ALLOW_THREADS;

    Py_RETURN_NONE;
};
Beispiel #9
0
void quit_program(sp_session *session)
{
    printf("Logging out..\n");
    sp_session_logout(session);
    free(username);
    free(password);
    printf("Goodbyte\n");
    exit(2);
}
Beispiel #10
0
/**
 * For the session test, we simply log out as soon as we are logged in.
 */
void session_ready(sp_session *session)
{
	sp_error error = sp_session_logout(session);

	if (SP_ERROR_OK != error) {
		fprintf(stderr, "failed to log out from Spotify: %s\n",
		                sp_error_message(error));
		g_exit_code = 5;
		return;
	}
}
Beispiel #11
0
static PyObject *Session_logout(Session *self) {
    sp_error error;
    Py_BEGIN_ALLOW_THREADS
    error = sp_session_logout(self->_session);
    Py_END_ALLOW_THREADS
    if(error != SP_ERROR_OK) {
        PyErr_SetString(SpotifyError, "Failed to log out");
        return NULL;
    }
    Py_INCREF(Py_None);
    return Py_None;
};
/**
  logout
  if clearPlaylists, also unset all loaded playlists
  otherwise, just remove callbacks and release
  **/
void SpotifySession::logout(bool clearPlaylists )
{
    if ( m_loggedIn ) {
        if ( clearPlaylists )
            m_SpotifyPlaylists->unsetAllLoaded();

        sp_playlistcontainer_remove_callbacks( m_container, &SpotifyCallbacks::containerCallbacks, this);
        sp_playlistcontainer_release( m_container );
        sp_session_logout( m_session );
    }

}
Beispiel #13
0
int session_logout(void)
{
	sp_error error;
	int retval = 0;
	if (session_is_logged_in()) {
		error = sp_session_logout(g_session);
		if (error != SP_ERROR_OK) {
			fprintf(stderr, "failed to log out %s\n",
					sp_error_message(error));
			retval = -1;
		}
	}
	return retval;
}
Beispiel #14
0
static void playlistcontainer_loaded(sp_playlistcontainer *pc, void *userdata) {
  syslog(LOG_DEBUG, "playlistcontainer_loaded\n");
  sp_session *session = userdata;
  struct state *state = sp_session_userdata(session);

  sp_playlistcontainer_remove_callbacks(pc, &playlistcontainer_callbacks, session);

  state->http = evhttp_new(state->event_base);
  evhttp_set_timeout(state->http, 60);
  evhttp_set_gencb(state->http, &handle_request, state);

  // TODO(liesen): Make address and port configurable
  if (evhttp_bind_socket(state->http, "0.0.0.0", 1337) == -1) {
    syslog(LOG_WARNING, "Could not bind HTTP server socket");
    sp_session_logout(session);
  }
}
Beispiel #15
0
//--------------------------------------------------------
//	 cleanup the session
//--------------------------------------------------------
void TLSpotify::TSession::Shutdown()
{
	//	logout first
	if ( m_pUser )
	{
		sp_error Error = sp_session_logout( m_pSession );
		if ( Error != SP_ERROR_OK )
			TLDebug_Break("Error logging out");
		m_pUser = NULL;
	}
	
	//	cleanup session
	if ( m_pSession )
	{
		//	there are no multiple sessions in libspotify atm, so we cannot cleanup the session.
		m_pSession = NULL;
	}
	
}
Beispiel #16
0
  bool Session::disConnect() {
  	if (m_isEnabled) {
      Logger::printOut("Logging out");

      PlayerHandler::deInit();
      Logger::printOut("cleaned player");

      //delete m_playlists;
      //m_playlists = NULL;
      Logger::printOut("cleaned playlists");

      //SearchHandler::deInit();
      Logger::printOut("cleaned search");

      //RadioHandler::deInit();
      Logger::printOut("cleaned radios");

      //ArtistStore::deInit();
      Logger::printOut("cleaned artists");

      //AlbumStore::deInit();
      Logger::printOut("cleaned albums");

      //TrackStore::deInit();
      Logger::printOut("cleaned tracks");

      ThumbStore::deInit();
      Logger::printOut("cleaned thumbs");

      //TODO FIX THE LOGOUT... Why is it crashing on logout?
      m_isLoggedOut = false;
      sp_session_logout(m_session);

      Logger::printOut("logged out waiting for callback");
      while (!m_isLoggedOut) {
        processEvents();
      }
      Logger::printOut("logged out");
      sp_session_release(m_session);
      Logger::printOut("cleaned session");
  	}
    return true;
  }
Beispiel #17
0
void sess_disconnect()
{
  if (g_session.state == SESS_ONLINE) {
    sess_stop();

     sp_error err = sp_session_logout(g_session.spotify);

     if (err != SP_ERROR_OK)
       panic("sp_session_logout() failed: %s", sp_error_message(err));

    log_append("Disconnecting...");
    g_session.state = SESS_DISCONNECTING;

    // Return to splash screen.
    ui_show(UI_SET_SPLASH);
  }

  // Redraw status info.
  ui_dirty(UI_FOOTER);
  ui_update_post(0);
}
Beispiel #18
0
// ----------------------------------------------------------------------------
//
bool SpotifyEngine::disconnect( void )
{
    m_track_timer.stopThread();

    if ( m_spotify_session ) {
        // Seems to be very important to stop all active tracks before killing Spotify

        clearTrackQueue( );         // Clear any pending tracks
        stopTrack();                // Stop any playing track(s)
        stopThread();               // Stop the spotify dispatcher

        ULONG future = GetCurrentTime() + (2 * 60 * 1000);

        // Logout the user        
        sp_session_logout( m_spotify_session );
        while ( getLoginState() != NOT_LOGGED_IN ) {
            int next_timeout = 0;
            do {
                sp_session_process_events( m_spotify_session, &next_timeout );
            } while (next_timeout == 0);

            if ( GetCurrentTime() > future )
                break;

            Sleep( 100 );
        }
    }

    if ( m_audio_out ) {
        AudioOutputStream::releaseAudioStream ( m_audio_out );
        m_audio_out = NULL;
    }

    removeTrackAnalyzer();

    freeTrackAnalysisCache();

    return true;
}
Beispiel #19
0
PHP_METHOD(Spotify, __destruct)
{
	spotify_object *obj = (spotify_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
	int timeout = 0;

	if (obj->playlistcontainer != NULL) {
		//sp_playlistcontainer_release(obj->playlistcontainer);
	}

    do {
        sp_session_process_events(obj->session, &timeout);
    } while (timeout == 0);

	sp_session_logout(obj->session);

	timeout = 0;
	do {
		sp_session_process_events(obj->session, &timeout);
	} while (!obj->is_logged_out || timeout == 0);

	efree(obj->key_data);
}
Beispiel #20
0
//
// Action handler that logs out the current user from Spotify. No side-effect if the
// user is not logged in.
//
static void logout_from_spotify_action(struct owl_state* state) {
    TRACE("Logging out from Spotify...\n");

    state->state = OWL_STATE_LOGGING_OUT;
    sp_session_logout(state->spotify_state->session);
}
Beispiel #21
0
int cmd_logout(int argc, char **argv)
{
	sp_session_logout(g_session);
	return 0;
}
Beispiel #22
0
Spotify::Error Spotify::Session::logout()
{
    m_error = sp_session_logout( m_session );
    return m_error;
}
Beispiel #23
0
	void Session::Logout()
	{		
		sp_session_logout( m_pSession );
	}
Beispiel #24
0
sp_error session_remote_logout() {
    g_debug("Logging out...");
    if (!g_session)
        g_error("Session is not ready.");
    return sp_session_logout(g_session);
}
Beispiel #25
0
void session_logout() {
    g_debug("Logging out...");
    if (g_session)
        sp_session_logout(g_session);    
}
Beispiel #26
0
JNIEXPORT jboolean JNICALL Java_jahspotify_impl_JahSpotifyImpl_shutdown ( JNIEnv *env, jobject obj)
{
  sp_session_logout(g_sess);
}
Beispiel #27
0
int main(int argc, char** argv)
{
	for (;;) {
		int option_index = 0;
		int c = getopt_long(argc, argv, "hl:u:p:r", NULL, &option_index);
		if (c == -1) {
			break ;
		}
		switch (c) {
		case 'h':
			usage();
			break;
		case 'l':
			playlist_name = strdup(optarg);
			break;
		case 'u':
			user_name = strdup(optarg);
			break;
		case 'p':
			password = strdup(optarg);
			break;
		case 'r':
			reset = true;
			break;
			
		};
	}

	// setup our spotify config
	sp_session_config config;
	memset(&config, 0, sizeof(config));
	config.api_version = SPOTIFY_API_VERSION;
	
	
	config.cache_location = "/tmp/spiffify";
	config.settings_location = "/tmp/spiffify";
	config.application_key = g_appkey;
	config.application_key_size = g_appkey_size;

	/* mkdir(config.cache_location, 0); */
	/* mkdir(config.settings_location, 0); */

	
	config.user_agent = "spiffify";

	sp_session_callbacks callbacks;
	memset(&callbacks, 0, sizeof(callbacks));
	callbacks.logged_in = &logged_in;
	/* callbacks.logged_out = logged_out; */
	callbacks.connection_error = &connection_error; 
	callbacks.notify_main_thread = &notify_main_thread;

	config.callbacks = &callbacks;

	// setup waits
	pthread_mutex_init(&g_mutex, NULL);
	pthread_cond_init(&g_cond, NULL);


	sp_error error = sp_session_create(&config, &session);
	if (SP_ERROR_OK != error) {
		fprintf(stderr, "Could not create session: %s\n", sp_error_message(error));
		abort();
	}

	error = sp_session_login(session, user_name, password, 0, NULL);
	if (SP_ERROR_OK != error) {
		fprintf(stderr, "Could not initiate login: %s\n", sp_error_message(error));
		abort();
	}
	pthread_mutex_lock(&g_mutex);


	int next_timeout=0;
	int load_completed=0;
	int messaged_load_waiting=0;
	for(;;) {
		if (next_timeout == 0) {
            while(!g_notify_do) {
                pthread_cond_wait(&g_cond, &g_mutex);
			}
		}
		else {
            struct timespec ts;

#if _POSIX_TIMERS > 0
            clock_gettime(CLOCK_REALTIME, &ts);
#else
            struct timeval tv;
            gettimeofday(&tv, NULL);
            TIMEVAL_TO_TIMESPEC(&tv, &ts);
#endif

            pthread_cond_timedwait(&g_cond, &g_mutex, &ts);
        }

        g_notify_do = 0;
        pthread_mutex_unlock(&g_mutex);

        do {
            sp_session_process_events(session, &next_timeout);
			if (load_completed == 0 && validate_complete_load()) {
				if (did_spiffify == 0 ) {
					spiffify();
					did_spiffify = 1;
				}
				sp_session_process_events(session, &next_timeout);
				// when the container_loaded event comes back (don't ask) we can be sure that our stuff made it to the server and we can exit there.
				if (can_exit==1) {
					goto done;
				}
			}
			else {
				if (messaged_load_waiting==0) {
					printf("Load not completed.. waiting\n");
					messaged_load_waiting = 1;
				}
			}
        } while (next_timeout == 0);

        pthread_mutex_lock(&g_mutex);
	}

done:
	error = sp_session_logout(session);
	if (SP_ERROR_OK != error) {
		fprintf(stderr, "Could not logout: %s\n", sp_error_message(error));
		exit(1);
	}
	error = sp_session_release(session);
	if (SP_ERROR_OK != error) {
		fprintf(stderr, "Could not destroy session: %s\n", sp_error_message(error));
		exit(1);
	}
};