From 4bdd37a586584b21fbed2249249debea20859368 Mon Sep 17 00:00:00 2001 From: acanas Date: Thu, 23 Mar 2023 14:22:43 +0100 Subject: [PATCH] Version 22.78.9: Mar 22, 2023 Code refactoring in mail domains. --- swad_changelog.h | 3 +- swad_link.c | 10 +++---- swad_mail.c | 69 +++++++++++++++++++++++++------------------- swad_mail_database.c | 7 +++-- 4 files changed, 49 insertions(+), 40 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index c75bbae08..0d124d13c 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -629,10 +629,11 @@ TODO: Emilce Barrera Mesa: Podr TODO: Emilce Barrera Mesa: Mis estudiantes presentan muchas dificultades a la hora de poner la foto porque la plataforma es muy exigente respecto al fondo de la imagen. */ -#define Log_PLATFORM_VERSION "SWAD 22.78.8 (2023-03-23)" +#define Log_PLATFORM_VERSION "SWAD 22.78.9 (2023-03-23)" #define CSS_FILE "swad22.57.1.css" #define JS_FILE "swad22.49.js" /* + Version 22.78.9: Mar 22, 2023 Code refactoring in mail domains. (337657 lines) Version 22.78.8: Mar 22, 2023 Code refactoring in holidays. (337648 lines) Version 22.78.7: Mar 22, 2023 Code refactoring in exam sets. (337671 lines) Version 22.78.6: Mar 22, 2023 Code refactoring in departments. (337691 lines) diff --git a/swad_link.c b/swad_link.c index 22b3c508b..cdedb583d 100644 --- a/swad_link.c +++ b/swad_link.c @@ -79,7 +79,7 @@ static void Lnk_EditLinksInternal (void); static void Lnk_PutIconsEditingLinks (__attribute__((unused)) void *Args); static void Lnk_GetListLinks (struct Lnk_Links *Links); -static void Lnk_GetLinkData (MYSQL_RES *mysql_res,struct Lnk_Link *Lnk); +static void Lnk_GetLinkDataFromRow (MYSQL_RES *mysql_res,struct Lnk_Link *Lnk); static void Lnk_FreeListLinks (struct Lnk_Links *Links); @@ -319,8 +319,7 @@ static void Lnk_GetListLinks (struct Lnk_Links *Links) for (NumLnk = 0; NumLnk < Links->Num; NumLnk++) - /* Get next link */ - Lnk_GetLinkData (mysql_res,&Links->Lst[NumLnk]); + Lnk_GetLinkDataFromRow (mysql_res,&Links->Lst[NumLnk]); } /***** Free structure that stores the query result *****/ @@ -346,7 +345,7 @@ void Lnk_GetLinkDataByCod (struct Lnk_Link *Lnk) { /***** Get data of an institutional link from database *****/ if (Lnk_DB_GetLinkDataByCod (&mysql_res,Lnk->LnkCod)) // Link found... - Lnk_GetLinkData (mysql_res,Lnk); + Lnk_GetLinkDataFromRow (mysql_res,Lnk); /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); @@ -357,7 +356,7 @@ void Lnk_GetLinkDataByCod (struct Lnk_Link *Lnk) /**************************** Get data of link *******************************/ /*****************************************************************************/ -static void Lnk_GetLinkData (MYSQL_RES *mysql_res,struct Lnk_Link *Lnk) +static void Lnk_GetLinkDataFromRow (MYSQL_RES *mysql_res,struct Lnk_Link *Lnk) { MYSQL_ROW row; @@ -369,7 +368,6 @@ static void Lnk_GetLinkData (MYSQL_RES *mysql_res,struct Lnk_Link *Lnk) row[2] FullName row[3] WWW */ - /***** Get plugin code (row[0]) *****/ if ((Lnk->LnkCod = Str_ConvertStrCodToLongCod (row[0])) <= 0) Err_WrongLinkExit (); diff --git a/swad_mail.c b/swad_mail.c index 1775412e1..4e3cf0077 100644 --- a/swad_mail.c +++ b/swad_mail.c @@ -83,6 +83,9 @@ static void Mai_EditMailDomainsInternal (void); static void Mai_GetListMailDomainsAllowedForNotif (struct Mai_Mails *Mails); static void Mai_GetMailDomain (const char *Email, char MailDomain[Cns_MAX_BYTES_EMAIL_ADDRESS + 1]); +static void Mai_GetMailDomainDataFromRow (MYSQL_RES *mysql_res, + struct Mail *Mai, + bool GetNumUsrs); static void Mai_FreeListMailDomains (struct Mai_Mails *Mails); static void Mai_ListMailDomainsForEdition (const struct Mai_Mails *Mails); @@ -266,9 +269,7 @@ static void Mai_EditMailDomainsInternal (void) static void Mai_GetListMailDomainsAllowedForNotif (struct Mai_Mails *Mails) { MYSQL_RES *mysql_res; - MYSQL_ROW row; unsigned NumMai; - struct Mail *Mai; // Query uses temporary tables for speed // Query uses two identical temporary tables... @@ -291,24 +292,8 @@ static void Mai_GetListMailDomainsAllowedForNotif (struct Mai_Mails *Mails) for (NumMai = 0; NumMai < Mails->Num; NumMai++) - { - Mai = &(Mails->Lst[NumMai]); - - /* Get next mail */ - row = mysql_fetch_row (mysql_res); - - /* Get mail code (row[0]) */ - if ((Mai->MaiCod = Str_ConvertStrCodToLongCod (row[0])) <= 0) - Err_WrongMailDomainExit (); - - /* Get the mail domain (row[1]) and the mail domain info (row[2]) */ - Str_Copy (Mai->Domain,row[1],sizeof (Mai->Domain) - 1); - Str_Copy (Mai->Info ,row[2],sizeof (Mai->Info ) - 1); - - /* Get number of users (row[3]) */ - if (sscanf (row[3],"%u",&(Mai->NumUsrs)) != 1) - Mai->NumUsrs = 0; - } + Mai_GetMailDomainDataFromRow (mysql_res,&(Mails->Lst[NumMai]), + true); // Get number of users } /***** Free structure that stores the query result *****/ @@ -385,13 +370,12 @@ void Mai_WriteWarningEmailNotifications (void) } /*****************************************************************************/ -/**************************** Get mail domain data ***************************/ +/******************* Get mail domain data using its code *********************/ /*****************************************************************************/ void Mai_GetMailDomainDataByCod (struct Mail *Mai) { MYSQL_RES *mysql_res; - MYSQL_ROW row; /***** Clear data *****/ Mai->Domain[0] = Mai->Info[0] = '\0'; @@ -401,20 +385,45 @@ void Mai_GetMailDomainDataByCod (struct Mail *Mai) { /***** Get data of a mail domain from database *****/ if (Mai_DB_GetMailDomainDataByCod (&mysql_res,Mai->MaiCod)) // Mail found... - { - /* Get row */ - row = mysql_fetch_row (mysql_res); - - /* Get the short & full name of the mail (row[0], row[1]) */ - Str_Copy (Mai->Domain,row[0],sizeof (Mai->Domain) - 1); - Str_Copy (Mai->Info ,row[1],sizeof (Mai->Info ) - 1); - } + Mai_GetMailDomainDataFromRow (mysql_res,Mai, + false); // Don't get number of users /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); } } +/*****************************************************************************/ +/****************** Get mail domain data from database row *******************/ +/*****************************************************************************/ + +static void Mai_GetMailDomainDataFromRow (MYSQL_RES *mysql_res, + struct Mail *Mai, + bool GetNumUsrs) + { + MYSQL_ROW row; + + /***** Get row *****/ + row = mysql_fetch_row (mysql_res); + + /***** Get mail code (row[0]) *****/ + if ((Mai->MaiCod = Str_ConvertStrCodToLongCod (row[0])) <= 0) + Err_WrongMailDomainExit (); + + /***** Get the mail domain (row[1]) and the mail domain info (row[2]) *****/ + Str_Copy (Mai->Domain,row[1],sizeof (Mai->Domain) - 1); + Str_Copy (Mai->Info ,row[2],sizeof (Mai->Info ) - 1); + + /***** Get number of users (row[3]) *****/ + if (GetNumUsrs) + { + if (sscanf (row[3],"%u",&(Mai->NumUsrs)) != 1) + Mai->NumUsrs = 0; + } + else + Mai->NumUsrs = 0; + } + /*****************************************************************************/ /************************** Free list of mail domains ************************/ /*****************************************************************************/ diff --git a/swad_mail_database.c b/swad_mail_database.c index c99d8e56e..cdbd7213e 100644 --- a/swad_mail_database.c +++ b/swad_mail_database.c @@ -397,9 +397,10 @@ unsigned Mai_DB_GetMailDomains (MYSQL_RES **mysql_res,Mai_DomainsOrder_t Selecte unsigned Mai_DB_GetMailDomainDataByCod (MYSQL_RES **mysql_res,long MaiCod) { return (unsigned) - DB_QuerySELECT (mysql_res,"can not get data of a mail domain", - "SELECT Domain," // row[0] - "Info" // row[1] + DB_QuerySELECT (mysql_res,"can not get mail domain", + "SELECT MaiCod," // row[0] + "Domain," // row[1] + "Info" // row[2] " FROM ntf_mail_domains" " WHERE MaiCod=%ld", MaiCod);