From 3a2e42b0cd164c0d52805b539353c5b12492e284 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Mon, 25 Oct 2010 12:03:34 +0200 Subject: Reauthenticate automatically when required --- src/ui.c | 30 ++++++++++++++++++++++++++++-- 1 file 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); -- cgit v1.2.3