Пример #1
0
int __cdecl main(int argc, char **argv)
{
	const char *username = argc > 1 ? argv[1] : NULL;
	const char *blob = argc > 2 ? argv[2] : NULL;
	const char *password = NULL;
	int selftest = argc > 3 ? !strcmp(argv[3], "selftest") : 0;
	char username_buf[256];
	char password_buf[256];
	int r;
	int next_timeout = 0;
	DWORD ev;
	DWORD mode;

	events[0] = CreateEvent(NULL, FALSE, FALSE, NULL);
	events[1] = GetStdHandle(STD_INPUT_HANDLE);

	printf("Using libspotify %s\n", sp_build_id());

	if (username == NULL) {
		printf("Username: (just press enter to login with stored credentials): ");
		fflush(stdout);
		fgets(username_buf, sizeof(username_buf), stdin);
		trim(username_buf);
		if(username_buf[0] == 0) {
			username = NULL;
		} else {
			username = username_buf;
		}
	}

	// If a username was supplied but no blob, prompt for password
	if (username != NULL && blob == NULL) {
		printf("Password: "******"Unable to set console mode err=%d\n", GetLastError());
			exit(1);
		}

		fgets(password_buf, sizeof(password_buf), stdin);
		trim(password_buf);
		password = password_buf;
		printf("\r\n");
	}

	if ((r = spshell_init(username, password, blob, selftest)) != 0)
		exit(r);

	if (!SetConsoleMode(events[1], ENABLE_PROCESSED_INPUT)) {
		printf("Unable to set console mode err=%d\n", GetLastError());
		exit(1);
	}

	while(!is_logged_out) {
		ev = WaitForMultipleObjects(1 + enable_console, events, FALSE, next_timeout > 0 ? next_timeout : INFINITE);
		switch (ev) {
		case WAIT_OBJECT_0 + 0:
		case WAIT_TIMEOUT:
			do {
				sp_session_process_events(g_session, &next_timeout);
			} while (next_timeout == 0);

			if(g_selftest)
				test_process();
			break;

		case WAIT_OBJECT_0 + 1:
			console_input();
			break;
		}
	}
	printf("Logged out\n");
	sp_session_release(g_session);
	printf("Exiting...\n");
	return 0;
}
Пример #2
0
int __cdecl main(int argc, char **argv)
{
	const char *username = argc > 1 ? argv[1] : NULL;
	const char *password = argc > 2 ? argv[2] : NULL;
	char username_buf[256];
	char password_buf[256];
	int r;
	int next_timeout = 0;
	DWORD ev;

	events[0] = CreateEvent(NULL, FALSE, FALSE, NULL);
	events[1] = GetStdHandle(STD_INPUT_HANDLE);

	if (username == NULL) {
		printf("Username: "******"Password: "******"Unable to set console mode err=%d\n", GetLastError());
			exit(1);
		}

		fgets(password_buf, sizeof(password_buf), stdin);
		trim(password_buf);
		password = password_buf;
		printf("\r\n");
	}

	if ((r = spshell_init(username, password)) != 0)
		exit(r);

	if (!SetConsoleMode(events[1], ENABLE_PROCESSED_INPUT)) {
		printf("Unable to set console mode err=%d\n", GetLastError());
		exit(1);
	}

	while(1) {
		ev = WaitForMultipleObjects(1 + enable_console, events, FALSE, next_timeout > 0 ? next_timeout : INFINITE);
		switch (ev) {
		case WAIT_OBJECT_0 + 0:
			do {
				sp_session_process_events(g_session, &next_timeout);
			} while (next_timeout == 0);
			break;

		case WAIT_OBJECT_0 + 1:
			console_input();
			break;
		}
	}
}
Пример #3
0
int main(int argc, char **argv)
{
	const char *username = argc > 1 ? argv[1] : NULL;
	const char *password = argc > 2 ? argv[2] : NULL;
	int selftest = argc > 3 ? !strcmp(argv[3], "selftest") : 0;
	char username_buf[256];
	int r;
	int next_timeout = 0;

	printf("Using libspotify %s\n", sp_build_id());

	if (username == NULL) {
		printf("Username (just press enter to login with stored credentials): ");
		fflush(stdout);
		fgets(username_buf, sizeof(username_buf), stdin);
		trim(username_buf);
		if(username_buf[0] == 0) {
			username = NULL;
		} else {
			username = username_buf;
		}
	}

	if (username != NULL && password == NULL)
		password = getpass("Password: "******"Logged out\n");
	sp_session_release(g_session);
	printf("Exiting...\n");
	return 0;
}
Пример #4
0
int main(int argc, char **argv)
{
	const char *username = argc > 1 ? argv[1] : NULL;
	const char *password = argc > 2 ? argv[2] : NULL;
	char username_buf[256];
	int r;
	int next_timeout = 0;

	if (username == NULL) {
		printf("Username: "******"Password: ");

	pthread_mutex_init(&notify_mutex, NULL);
	pthread_cond_init(&notify_cond, NULL);
	pthread_cond_init(&prompt_cond, NULL);

	if ((r = spshell_init(username, password)) != 0)
		exit(r);

	pthread_mutex_lock(&notify_mutex);

	for (;;) {
		// Release prompt

		if (next_timeout == 0) {
			while(!notify_events && !cmdline)
				pthread_cond_wait(&notify_cond, &notify_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

			ts.tv_sec += next_timeout / 1000;
			ts.tv_nsec += (next_timeout % 1000) * 1000000;

			while(!notify_events && !cmdline) {
				if(pthread_cond_timedwait(&notify_cond, &notify_mutex, &ts))
					break;
			}
		}

		// Process input from prompt
		if(cmdline) {
			char *l = cmdline;
			cmdline = NULL;
		
			pthread_mutex_unlock(&notify_mutex);
			cmd_exec_unparsed(l);
			free(l);
			pthread_mutex_lock(&notify_mutex);
		}

		// Process libspotify events
		notify_events = 0;
		pthread_mutex_unlock(&notify_mutex);

		do {
			sp_session_process_events(g_session, &next_timeout);
		} while (next_timeout == 0);

		pthread_mutex_lock(&notify_mutex);
	}
	return 0;
}