diff --git a/swad_changelog.h b/swad_changelog.h index 9f87c720..8786599c 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -602,13 +602,14 @@ TODO: FIX BUG, URGENT! En las fechas como par TODO: En las encuestas, que los estudiantes no puedan ver los resultados hasta que no finalice el plazo. */ -#define Log_PLATFORM_VERSION "SWAD 21.35 (2021-10-18)" +#define Log_PLATFORM_VERSION "SWAD 21.35.1 (2021-10-18)" #define CSS_FILE "swad20.45.css" #define JS_FILE "swad20.69.1.js" /* TODO: Rename CENTRE to CENTER in help wiki. TODO: Rename ASSESSMENT.Announcements to ASSESSMENT.Calls_for_exams + Version 21.35.1: Oct 18, 2021 Queries moved to module swad_file_database. (320175 lines) Version 21.35: Oct 18, 2021 New module swad_file_database for database queries related to files. (320171 lines) Version 21.34: Oct 15, 2021 New module swad_session_database for database queries related to sessions. (320081 lines) Version 21.33.2: Oct 15, 2021 Fixed bug getting name of degree. (319950 lines) diff --git a/swad_global.c b/swad_global.c index 38201655..568a6676 100644 --- a/swad_global.c +++ b/swad_global.c @@ -51,6 +51,7 @@ #include "swad_project.h" #include "swad_role.h" #include "swad_room.h" +#include "swad_session_database.h" #include "swad_setting.h" #include "swad_statistic.h" #include "swad_theme.h" @@ -357,7 +358,7 @@ void Gbl_Cleanup (void) if (!Gbl.Action.UsesAJAX && !Gbl.WebService.IsWebService && Act_GetBrowserTab (Gbl.Action.Act) == Act_BRW_1ST_TAB) - Ses_RemoveParamFromThisSession (); + Ses_DB_RemoveParam (); Usr_FreeMyCourses (); Usr_FreeMyDegrees (); Usr_FreeMyCenters (); diff --git a/swad_session.c b/swad_session.c index 89f47f66..9c4070c6 100644 --- a/swad_session.c +++ b/swad_session.c @@ -56,8 +56,6 @@ extern struct Globals Gbl; static void Ses_RemoveSessionFromDB (void); -static bool Ses_CheckIfParamIsAlreadyInDB (const char *ParamName); - /*****************************************************************************/ /************************** Get number of open sessions **********************/ /*****************************************************************************/ @@ -119,7 +117,7 @@ void Ses_CloseSession (void) Con_DB_RemoveOldConnected (); /***** Remove unused data associated to expired sessions *****/ - Ses_RemoveParamsFromExpiredSessions (); + Ses_DB_RemoveParamsFromExpiredSessions (); Fil_DB_RemovePublicDirsFromExpiredSessions (); /***** Now, user is not logged in *****/ @@ -222,81 +220,16 @@ void Ses_InsertParamInDB (const char *ParamName,const char *ParamValue) { /***** Before of inserting the first session parameter passed to the next action, delete all the parameters coming from the previous action *****/ - Ses_RemoveParamFromThisSession (); + Ses_DB_RemoveParam (); /***** For a unique session-parameter, don't insert a parameter more than one time *****/ if (ParamName) if (ParamName[0]) - if (!Ses_CheckIfParamIsAlreadyInDB (ParamName)) + if (!Ses_DB_CheckIfParamIsAlreadyStored (ParamName)) { /***** Insert session parameter in the database *****/ Ses_DB_InsertParam (ParamName,ParamValue); Gbl.Session.ParamsInsertedIntoDB = true; } } - -/*****************************************************************************/ -/************ Remove session parameters of a session from database ***********/ -/*****************************************************************************/ - -void Ses_RemoveParamFromThisSession (void) - { - if (Gbl.Session.IsOpen && // There is an open session - !Gbl.Session.ParamsInsertedIntoDB) // No params just inserted - /***** Remove session parameters of this session *****/ - DB_QueryDELETE ("can not remove session parameters of current session", - "DELETE FROM ses_params" - " WHERE SessionId='%s'", - Gbl.Session.Id); - } - -/*****************************************************************************/ -/********* Remove expired hidden parameters (from expired sessions) **********/ -/*****************************************************************************/ - -void Ses_RemoveParamsFromExpiredSessions (void) - { - /***** Remove session parameters from expired sessions *****/ - DB_QueryDELETE ("can not remove session parameters of expired sessions", - "DELETE FROM ses_params" - " WHERE SessionId NOT IN" - " (SELECT SessionId" - " FROM ses_sessions)"); - } - -/*****************************************************************************/ -/************** Check if a session parameter existed in database *************/ -/*****************************************************************************/ -// Return true if the parameter already existed in database - -static bool Ses_CheckIfParamIsAlreadyInDB (const char *ParamName) - { - return (DB_QueryCOUNT ("can not check if a session parameter" - " is already in database", - "SELECT COUNT(*)" - " FROM ses_params" - " WHERE SessionId='%s'" - " AND ParamName='%s'", - Gbl.Session.Id, - ParamName) != 0); - } - -/*****************************************************************************/ -/***************** Get session parameter from the database *******************/ -/*****************************************************************************/ -// StrSize is the size of the parameter value, not including the ending '\0' - -void Ses_GetParamFromDB (const char *ParamName,char *ParamValue,size_t StrSize) - { - ParamValue[0] = '\0'; - if (Gbl.Session.IsOpen) // If the session is open, get parameter from DB - /***** Get a session parameter from database *****/ - DB_QuerySELECTString (ParamValue,StrSize,"can not get a session parameter", - "SELECT ParamValue" // row[0] - " FROM ses_params" - " WHERE SessionId='%s'" - " AND ParamName='%s'", - Gbl.Session.Id, - ParamName); - } diff --git a/swad_session.h b/swad_session.h index eb314b45..d3e03509 100644 --- a/swad_session.h +++ b/swad_session.h @@ -44,9 +44,7 @@ void Ses_CloseSession (void); bool Ses_GetSessionData (void); +//---------------------------- Session parameters ----------------------------- void Ses_InsertParamInDB (const char *ParamName,const char *ParamValue); -void Ses_RemoveParamFromThisSession (void); -void Ses_RemoveParamsFromExpiredSessions (void); -void Ses_GetParamFromDB (const char *ParamName,char *ParamValue,size_t StrSize); #endif diff --git a/swad_session_database.c b/swad_session_database.c index b5e86aa2..684ca266 100644 --- a/swad_session_database.c +++ b/swad_session_database.c @@ -279,3 +279,68 @@ void Ses_DB_InsertParam (const char *ParamName,const char *ParamValue) ParamValue ? ParamValue : ""); } + +/*****************************************************************************/ +/************** Check if a session parameter existed in database *************/ +/*****************************************************************************/ +// Return true if the parameter already existed in database + +bool Ses_DB_CheckIfParamIsAlreadyStored (const char *ParamName) + { + return (DB_QueryCOUNT ("can not check if a session parameter" + " is already in database", + "SELECT COUNT(*)" + " FROM ses_params" + " WHERE SessionId='%s'" + " AND ParamName='%s'", + Gbl.Session.Id, + ParamName) != 0); + } + +/*****************************************************************************/ +/***************** Get session parameter from the database *******************/ +/*****************************************************************************/ +// StrSize is the size of the parameter value, not including the ending '\0' + +void Ses_DB_GetParam (const char *ParamName,char *ParamValue,size_t StrSize) + { + ParamValue[0] = '\0'; + if (Gbl.Session.IsOpen) // If the session is open, get parameter from DB + /***** Get a session parameter from database *****/ + DB_QuerySELECTString (ParamValue,StrSize,"can not get a session parameter", + "SELECT ParamValue" // row[0] + " FROM ses_params" + " WHERE SessionId='%s'" + " AND ParamName='%s'", + Gbl.Session.Id, + ParamName); + } + +/*****************************************************************************/ +/************ Remove session parameters of a session from database ***********/ +/*****************************************************************************/ + +void Ses_DB_RemoveParam (void) + { + if (Gbl.Session.IsOpen && // There is an open session + !Gbl.Session.ParamsInsertedIntoDB) // No params just inserted + /***** Remove session parameters of this session *****/ + DB_QueryDELETE ("can not remove session parameters of current session", + "DELETE FROM ses_params" + " WHERE SessionId='%s'", + Gbl.Session.Id); + } + +/*****************************************************************************/ +/********* Remove expired hidden parameters (from expired sessions) **********/ +/*****************************************************************************/ + +void Ses_DB_RemoveParamsFromExpiredSessions (void) + { + /***** Remove session parameters from expired sessions *****/ + DB_QueryDELETE ("can not remove session parameters of expired sessions", + "DELETE FROM ses_params" + " WHERE SessionId NOT IN" + " (SELECT SessionId" + " FROM ses_sessions)"); + } diff --git a/swad_session_database.h b/swad_session_database.h index e63be9a6..9ad0ff22 100644 --- a/swad_session_database.h +++ b/swad_session_database.h @@ -37,7 +37,7 @@ /*****************************************************************************/ /***************************** Public prototypes *****************************/ /*****************************************************************************/ - +//---------------------------------- Sessions --------------------------------- void Ses_DB_InsertSession (void); void Ses_DB_UpdateSession (void); void Ses_DB_SaveLastSearchIntoSession (void); @@ -53,7 +53,12 @@ void Ses_DB_RemoveUsrSessions (long UsrCod); void Ses_SB_RemoveCurrentSession (void); //---------------------------- Session parameters ----------------------------- - void Ses_DB_InsertParam (const char *ParamName,const char *ParamValue); +bool Ses_DB_CheckIfParamIsAlreadyStored (const char *ParamName); +void Ses_DB_GetParam (const char *ParamName,char *ParamValue,size_t StrSize); + +void Ses_DB_RemoveParam (void); +void Ses_DB_RemoveParamsFromExpiredSessions (void); + #endif diff --git a/swad_user.c b/swad_user.c index 404c89ea..01b4c88d 100644 --- a/swad_user.c +++ b/swad_user.c @@ -5923,7 +5923,7 @@ void Usr_GetListsSelectedEncryptedUsrsCods (struct SelectedUsrs *SelectedUsrs) Usr_AllocateListSelectedEncryptedUsrCods (SelectedUsrs,Rol_UNK); if (Gbl.Session.IsOpen) // If the session is open, get parameter from DB { - Ses_GetParamFromDB (ParamName,SelectedUsrs->List[Rol_UNK], + Ses_DB_GetParam (ParamName,SelectedUsrs->List[Rol_UNK], Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS); Str_ChangeFormat (Str_FROM_FORM,Str_TO_TEXT,SelectedUsrs->List[Rol_UNK], Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS,true);