/* Thread: filescanner */ int lastfm_login(char *path) { struct keyval *kv; char *username; char *password; int ret; DPRINTF(E_DBG, L_LASTFM, "Got LastFM login request\n"); // Delete any existing session key if (lastfm_session_key) free(lastfm_session_key); lastfm_session_key = NULL; db_admin_delete("lastfm_sk"); // Read the credentials file ret = credentials_read(path, &username, &password); if (ret < 0) return -1; // Enable LastFM now that we got a login attempt lastfm_disabled = 0; kv = keyval_alloc(); if (!kv) { free(username); free(password); return -1; } ret = ( (keyval_add(kv, "api_key", lastfm_api_key) == 0) && (keyval_add(kv, "username", username) == 0) && (keyval_add(kv, "password", password) == 0) ); free(username); free(password); // Send the login request ret = request_post("auth.getMobileSession", kv, 1); keyval_clear(kv); free(kv); return ret; }
/* Thread: filescanner */ void lastfm_login(char *path) { struct lastfm_command *cmd; struct keyval *kv; char *username; char *password; int ret; DPRINTF(E_DBG, L_LASTFM, "Got LastFM login request\n"); // Delete any existing session key if (g_session_key) free(g_session_key); g_session_key = NULL; db_admin_delete("lastfm_sk"); // Read the credentials file ret = credentials_read(path, &username, &password); if (ret < 0) return; // Enable LastFM now that we got a login attempt g_disabled = 0; kv = keyval_alloc(); if (!kv) { free(username); free(password); return; } ret = ( (keyval_add(kv, "api_key", g_api_key) == 0) && (keyval_add(kv, "username", username) == 0) && (keyval_add(kv, "password", password) == 0) ); free(username); free(password); if (!ret) { keyval_clear(kv); return; } // Spawn thread ret = lastfm_init(); if (ret < 0) { g_disabled = 1; return; } g_initialized = 1; // Send login command to the thread cmd = (struct lastfm_command *)malloc(sizeof(struct lastfm_command)); if (!cmd) { DPRINTF(E_LOG, L_LASTFM, "Could not allocate lastfm_command\n"); return; } memset(cmd, 0, sizeof(struct lastfm_command)); cmd->nonblock = 1; cmd->func = login; cmd->arg.kv = kv; nonblock_command(cmd); return; }