summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <PromyLOPh@lavabit.com>2010-10-25 12:03:34 +0200
committerLars-Dominik Braun <PromyLOPh@lavabit.com>2010-10-28 13:08:01 +0200
commit3a2e42b0cd164c0d52805b539353c5b12492e284 (patch)
treede73a15369d25d36a729f07ab687c742384e0d93
parent1c44f089383538a113fc46e49a842bb5b3cc66fc (diff)
downloadpianobar-3a2e42b0cd164c0d52805b539353c5b12492e284.tar.gz
pianobar-3a2e42b0cd164c0d52805b539353c5b12492e284.tar.bz2
pianobar-3a2e42b0cd164c0d52805b539353c5b12492e284.zip
Reauthenticate automatically when required
-rw-r--r--src/ui.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/ui.c b/src/ui.c
index fb20f0a..33829c4 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -148,7 +148,33 @@ int BarUiPianoCall (BarApp_t * const app, PianoRequestType_t type,
*pRet = PianoResponse (&app->ph, &req);
if (*pRet != PIANO_RET_CONTINUE_REQUEST) {
- if (*pRet != PIANO_RET_OK) {
+ /* checking for request type avoids infinite loops */
+ if (*pRet == PIANO_RET_AUTH_TOKEN_INVALID &&
+ type != PIANO_REQUEST_LOGIN) {
+ /* reauthenticate */
+ PianoReturn_t authpRet;
+ WaitressReturn_t authwRet;
+ PianoRequestDataLogin_t reqData;
+ reqData.user = app->settings.username;
+ reqData.password = app->settings.password;
+ reqData.step = 0;
+
+ BarUiMsg (MSG_NONE, "Reauthentication required... ");
+ if (!BarUiPianoCall (app, PIANO_REQUEST_LOGIN, &reqData, &authpRet,
+ &authwRet)) {
+ *pRet = authpRet;
+ *wRet = authwRet;
+ if (req.responseData != NULL) {
+ free (req.responseData);
+ }
+ PianoDestroyRequest (&req);
+ return 0;
+ } else {
+ /* try again */
+ *pRet = PIANO_RET_CONTINUE_REQUEST;
+ BarUiMsg (MSG_INFO, "Trying again... ");
+ }
+ } else if (*pRet != PIANO_RET_OK) {
BarUiMsg (MSG_NONE, "Error: %s\n", PianoErrorToStr (*pRet));
PianoDestroyRequest (&req);
if (req.responseData != NULL) {
@@ -160,7 +186,7 @@ int BarUiPianoCall (BarApp_t * const app, PianoRequestType_t type,
}
}
/* we can destroy the request at this point, even when this call needs
- * more than one http request. persistend data (step counter, e.g.) is
+ * more than one http request. persistent data (step counter, e.g.) is
* stored in req.data */
if (req.responseData != NULL) {
free (req.responseData);