int oilsAuthResetTimeout( osrfMethodContext* ctx ) { OSRF_METHOD_VERIFY_CONTEXT(ctx); const char* authToken = jsonObjectGetString( jsonObjectGetIndex(ctx->params, 0)); oilsEvent* evt = _oilsAuthResetTimeout(authToken); osrfAppRespondComplete( ctx, oilsEventToJSON(evt) ); oilsEventFree(evt); return 0; }
int oilsAuthSessionRetrieve( osrfMethodContext* ctx ) { OSRF_METHOD_VERIFY_CONTEXT(ctx); bool returnFull = false; const char* authToken = jsonObjectGetString( jsonObjectGetIndex(ctx->params, 0)); if(ctx->params->size > 1) { // caller wants full cached object, with authtime, etc. const char* rt = jsonObjectGetString(jsonObjectGetIndex(ctx->params, 1)); if(rt && strcmp(rt, "0") != 0) returnFull = true; } jsonObject* cacheObj = NULL; oilsEvent* evt = NULL; if( authToken ){ // Reset the timeout to keep the session alive evt = _oilsAuthResetTimeout(authToken, 0); if( evt && strcmp(evt->event, OILS_EVENT_SUCCESS) ) { osrfAppRespondComplete( ctx, oilsEventToJSON( evt )); // can't reset timeout } else { // Retrieve the cached session object osrfLogDebug(OSRF_LOG_MARK, "Retrieving auth session: %s", authToken); char* key = va_list_to_string("%s%s", OILS_AUTH_CACHE_PRFX, authToken ); cacheObj = osrfCacheGetObject( key ); if(cacheObj) { // Return a copy of the cached user object if(returnFull) osrfAppRespondComplete( ctx, cacheObj); else osrfAppRespondComplete( ctx, jsonObjectGetKeyConst( cacheObj, "userobj")); jsonObjectFree(cacheObj); } else { // Auth token is invalid or expired oilsEvent* evt2 = oilsNewEvent(OSRF_LOG_MARK, OILS_EVENT_NO_SESSION); osrfAppRespondComplete( ctx, oilsEventToJSON(evt2) ); /* should be event.. */ oilsEventFree(evt2); } free(key); } } else { // No session evt = oilsNewEvent(OSRF_LOG_MARK, OILS_EVENT_NO_SESSION); osrfAppRespondComplete( ctx, oilsEventToJSON(evt) ); } if(evt) oilsEventFree(evt); return 0; }