Version 22.53: Oct 28, 2022 Code refactoring in mail domains.

This commit is contained in:
acanas 2022-10-28 13:21:34 +02:00
parent 063d4d0490
commit 0940ab845e
8 changed files with 79 additions and 54 deletions

View File

@ -605,7 +605,7 @@ TODO: Fix bug: error al enviar un mensaje a dos recipientes, error on duplicate
TODO: Attach pdf files in multimedia. TODO: Attach pdf files in multimedia.
*/ */
#define Log_PLATFORM_VERSION "SWAD 22.52 (2022-10-28)" #define Log_PLATFORM_VERSION "SWAD 22.53 (2022-10-28)"
#define CSS_FILE "swad22.49.4.css" #define CSS_FILE "swad22.49.4.css"
#define JS_FILE "swad22.49.js" #define JS_FILE "swad22.49.js"
/* /*
@ -616,6 +616,7 @@ Que al subir un fichero por defecto est
Al subir cosas para los grupos, en documentos, resltar más los grupos porque no son conscientes... Al subir cosas para los grupos, en documentos, resltar más los grupos porque no son conscientes...
Exportar listas en CSV. Exportar listas en CSV.
Version 22.53: Oct 28, 2022 Code refactoring in mail domains. (333607 lines)
Version 22.52: Oct 28, 2022 Code refactoring in plugins. (333589 lines) Version 22.52: Oct 28, 2022 Code refactoring in plugins. (333589 lines)
Version 22.51: Oct 27, 2022 New module swad_process. (333586 lines) Version 22.51: Oct 27, 2022 New module swad_process. (333586 lines)
Version 22.50.8: Oct 20, 2022 Code refactoring in files. (333498 lines) Version 22.50.8: Oct 20, 2022 Code refactoring in files. (333498 lines)

View File

@ -228,10 +228,6 @@ void Gbl_InitializeGlobals (void)
Gbl.Search.Str[0] = '\0'; Gbl.Search.Str[0] = '\0';
Gbl.Search.LogSearch = false; Gbl.Search.LogSearch = false;
Gbl.Mails.Num = 0;
Gbl.Mails.Lst = NULL;
Gbl.Mails.SelectedOrder = Mai_ORDER_DEFAULT;
Gbl.Links.Num = 0; Gbl.Links.Num = 0;
Gbl.Links.Lst = NULL; Gbl.Links.Lst = NULL;

View File

@ -105,12 +105,6 @@ struct Globals
unsigned Num; // Number of degree types unsigned Num; // Number of degree types
struct DegreeType *Lst; // List of degree types struct DegreeType *Lst; // List of degree types
} DegTypes; } DegTypes;
struct
{
unsigned Num; // Number of mail domains
struct Mail *Lst; // List of mail domains
Mai_DomainsOrder_t SelectedOrder;
} Mails;
struct struct
{ {
unsigned Num; // Number of institutional links unsigned Num; // Number of institutional links

View File

@ -54,6 +54,17 @@
extern struct Globals Gbl; extern struct Globals Gbl;
/*****************************************************************************/
/******************************* Private types *******************************/
/*****************************************************************************/
struct Mai_Mails
{
unsigned Num; // Number of mail domains
struct Mail *Lst; // List of mail domains
Mai_DomainsOrder_t SelectedOrder;
};
/*****************************************************************************/ /*****************************************************************************/
/***************************** Private variables *****************************/ /***************************** Private variables *****************************/
/*****************************************************************************/ /*****************************************************************************/
@ -65,14 +76,15 @@ static struct Mail *Mai_EditingMai = NULL; // Static variable to keep the mail d
/***************************** Private prototypes ****************************/ /***************************** Private prototypes ****************************/
/*****************************************************************************/ /*****************************************************************************/
static void Mai_GetParamMaiOrder (void); static Mai_DomainsOrder_t Mai_GetParamMaiOrder (void);
static void Mai_PutIconToEditMailDomains (__attribute__((unused)) void *Args); static void Mai_PutIconToEditMailDomains (__attribute__((unused)) void *Args);
static void Mai_EditMailDomainsInternal (void); static void Mai_EditMailDomainsInternal (void);
static void Mai_GetListMailDomainsAllowedForNotif (void); static void Mai_GetListMailDomainsAllowedForNotif (struct Mai_Mails *Mails);
static void Mai_GetMailDomain (const char *Email, static void Mai_GetMailDomain (const char *Email,
char MailDomain[Cns_MAX_BYTES_EMAIL_ADDRESS + 1]); char MailDomain[Cns_MAX_BYTES_EMAIL_ADDRESS + 1]);
static void Mai_FreeListMailDomains (struct Mai_Mails *Mails);
static void Mai_ListMailDomainsForEdition (void); static void Mai_ListMailDomainsForEdition (const struct Mai_Mails *Mails);
static void Mai_PutParamMaiCod (void *MaiCod); static void Mai_PutParamMaiCod (void *MaiCod);
static void Mai_RenameMailDomain (Cns_ShrtOrFullName_t ShrtOrFullName); static void Mai_RenameMailDomain (Cns_ShrtOrFullName_t ShrtOrFullName);
@ -94,6 +106,8 @@ static void Mai_NewUsrEmail (struct Usr_Data *UsrDat,bool ItsMe);
static void Mai_InsertMailKey (const char Email[Cns_MAX_BYTES_EMAIL_ADDRESS + 1], static void Mai_InsertMailKey (const char Email[Cns_MAX_BYTES_EMAIL_ADDRESS + 1],
const char MailKey[Mai_LENGTH_EMAIL_CONFIRM_KEY + 1]); const char MailKey[Mai_LENGTH_EMAIL_CONFIRM_KEY + 1]);
static void Mai_InitializeMailDomainList (struct Mai_Mails *Mails);
static void Mai_EditingMailDomainConstructor (void); static void Mai_EditingMailDomainConstructor (void);
static void Mai_EditingMailDomainDestructor (void); static void Mai_EditingMailDomainDestructor (void);
@ -109,12 +123,16 @@ void Mai_SeeMailDomains (void)
extern const char *Txt_EMAIL_DOMAIN_ORDER[3]; extern const char *Txt_EMAIL_DOMAIN_ORDER[3];
Mai_DomainsOrder_t Order; Mai_DomainsOrder_t Order;
unsigned NumMai; unsigned NumMai;
struct Mai_Mails Mails;
/***** Initialize mail domain list *****/
Mai_InitializeMailDomainList (&Mails);
/***** Get parameter with the type of order in the list of mail domains *****/ /***** Get parameter with the type of order in the list of mail domains *****/
Mai_GetParamMaiOrder (); Mails.SelectedOrder = Mai_GetParamMaiOrder ();
/***** Get list of mail domains *****/ /***** Get list of mail domains *****/
Mai_GetListMailDomainsAllowedForNotif (); Mai_GetListMailDomainsAllowedForNotif (&Mails);
/***** Begin box and table *****/ /***** Begin box and table *****/
if (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM) if (Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM)
@ -138,10 +156,10 @@ void Mai_SeeMailDomains (void)
Par_PutHiddenParamUnsigned (NULL,"Order",(unsigned) Order); Par_PutHiddenParamUnsigned (NULL,"Order",(unsigned) Order);
HTM_BUTTON_Submit_Begin (Txt_EMAIL_DOMAIN_HELP_ORDER[Order], HTM_BUTTON_Submit_Begin (Txt_EMAIL_DOMAIN_HELP_ORDER[Order],
"class=\"BT_LINK\""); "class=\"BT_LINK\"");
if (Order == Gbl.Mails.SelectedOrder) if (Order == Mails.SelectedOrder)
HTM_U_Begin (); HTM_U_Begin ();
HTM_Txt (Txt_EMAIL_DOMAIN_ORDER[Order]); HTM_Txt (Txt_EMAIL_DOMAIN_ORDER[Order]);
if (Order == Gbl.Mails.SelectedOrder) if (Order == Mails.SelectedOrder)
HTM_U_End (); HTM_U_End ();
HTM_BUTTON_End (); HTM_BUTTON_End ();
Frm_EndForm (); Frm_EndForm ();
@ -152,22 +170,22 @@ void Mai_SeeMailDomains (void)
/***** Write all mail domains *****/ /***** Write all mail domains *****/
for (NumMai = 0; for (NumMai = 0;
NumMai < Gbl.Mails.Num; NumMai < Mails.Num;
NumMai++) NumMai++)
{ {
/* Write data of this mail domain */ /* Write data of this mail domain */
HTM_TR_Begin (NULL); HTM_TR_Begin (NULL);
HTM_TD_Begin ("class=\"LT DAT_%s\"",The_GetSuffix ()); HTM_TD_Begin ("class=\"LT DAT_%s\"",The_GetSuffix ());
HTM_Txt (Gbl.Mails.Lst[NumMai].Domain); HTM_Txt (Mails.Lst[NumMai].Domain);
HTM_TD_End (); HTM_TD_End ();
HTM_TD_Begin ("class=\"LT DAT_%s\"",The_GetSuffix ()); HTM_TD_Begin ("class=\"LT DAT_%s\"",The_GetSuffix ());
HTM_Txt (Gbl.Mails.Lst[NumMai].Info); HTM_Txt (Mails.Lst[NumMai].Info);
HTM_TD_End (); HTM_TD_End ();
HTM_TD_Begin ("class=\"RT DAT_%s\"",The_GetSuffix ()); HTM_TD_Begin ("class=\"RT DAT_%s\"",The_GetSuffix ());
HTM_Unsigned (Gbl.Mails.Lst[NumMai].NumUsrs); HTM_Unsigned (Mails.Lst[NumMai].NumUsrs);
HTM_TD_End (); HTM_TD_End ();
HTM_TR_End (); HTM_TR_End ();
@ -177,20 +195,20 @@ void Mai_SeeMailDomains (void)
Box_BoxTableEnd (); Box_BoxTableEnd ();
/***** Free list of mail domains *****/ /***** Free list of mail domains *****/
Mai_FreeListMailDomains (); Mai_FreeListMailDomains (&Mails);
} }
/*****************************************************************************/ /*****************************************************************************/
/******* Get parameter with the type or order in list of mail domains ********/ /******* Get parameter with the type or order in list of mail domains ********/
/*****************************************************************************/ /*****************************************************************************/
static void Mai_GetParamMaiOrder (void) static Mai_DomainsOrder_t Mai_GetParamMaiOrder (void)
{ {
Gbl.Mails.SelectedOrder = (Mai_DomainsOrder_t) return (Mai_DomainsOrder_t)
Par_GetParToUnsignedLong ("Order", Par_GetParToUnsignedLong ("Order",
0, 0,
Mai_NUM_ORDERS - 1, Mai_NUM_ORDERS - 1,
(unsigned long) Mai_ORDER_DEFAULT); (unsigned long) Mai_ORDER_DEFAULT);
} }
/*****************************************************************************/ /*****************************************************************************/
@ -221,25 +239,30 @@ void Mai_EditMailDomains (void)
static void Mai_EditMailDomainsInternal (void) static void Mai_EditMailDomainsInternal (void)
{ {
struct Mai_Mails Mails;
/***** Initialize mail domain list *****/
Mai_InitializeMailDomainList (&Mails);
/***** Get list of mail domains *****/ /***** Get list of mail domains *****/
Mai_GetListMailDomainsAllowedForNotif (); Mai_GetListMailDomainsAllowedForNotif (&Mails);
/***** Put a form to create a new mail *****/ /***** Put a form to create a new mail *****/
Mai_PutFormToCreateMailDomain (); Mai_PutFormToCreateMailDomain ();
/***** Forms to edit current mail domains *****/ /***** Forms to edit current mail domains *****/
if (Gbl.Mails.Num) if (Mails.Num)
Mai_ListMailDomainsForEdition (); Mai_ListMailDomainsForEdition (&Mails);
/***** Free list of mail domains *****/ /***** Free list of mail domains *****/
Mai_FreeListMailDomains (); Mai_FreeListMailDomains (&Mails);
} }
/*****************************************************************************/ /*****************************************************************************/
/*************************** List all mail domains ***************************/ /*************************** List all mail domains ***************************/
/*****************************************************************************/ /*****************************************************************************/
static void Mai_GetListMailDomainsAllowedForNotif (void) static void Mai_GetListMailDomainsAllowedForNotif (struct Mai_Mails *Mails)
{ {
MYSQL_RES *mysql_res; MYSQL_RES *mysql_res;
MYSQL_ROW row; MYSQL_ROW row;
@ -256,19 +279,19 @@ static void Mai_GetListMailDomainsAllowedForNotif (void)
Mai_DB_CreateTmpTables (); Mai_DB_CreateTmpTables ();
/***** Get mail domains from database *****/ /***** Get mail domains from database *****/
if ((Gbl.Mails.Num = Mai_DB_GetMailDomains (&mysql_res))) // Mail domains found... if ((Mails->Num = Mai_DB_GetMailDomains (&mysql_res,Mails->SelectedOrder))) // Mail domains found...
{ {
/***** Create list with places *****/ /***** Create list with places *****/
if ((Gbl.Mails.Lst = calloc ((size_t) Gbl.Mails.Num, if ((Mails->Lst = calloc ((size_t) Mails->Num,
sizeof (*Gbl.Mails.Lst))) == NULL) sizeof (struct Mail))) == NULL)
Err_NotEnoughMemoryExit (); Err_NotEnoughMemoryExit ();
/***** Get the mail domains *****/ /***** Get the mail domains *****/
for (NumMai = 0; for (NumMai = 0;
NumMai < Gbl.Mails.Num; NumMai < Mails->Num;
NumMai++) NumMai++)
{ {
Mai = &(Gbl.Mails.Lst[NumMai]); Mai = &(Mails->Lst[NumMai]);
/* Get next mail */ /* Get next mail */
row = mysql_fetch_row (mysql_res); row = mysql_fetch_row (mysql_res);
@ -387,14 +410,14 @@ void Mai_GetDataOfMailDomainByCod (struct Mail *Mai)
/************************** Free list of mail domains ************************/ /************************** Free list of mail domains ************************/
/*****************************************************************************/ /*****************************************************************************/
void Mai_FreeListMailDomains (void) static void Mai_FreeListMailDomains (struct Mai_Mails *Mails)
{ {
if (Gbl.Mails.Lst) if (Mails->Lst)
{ {
/***** Free memory used by the list of mail domains *****/ /***** Free memory used by the list of mail domains *****/
free (Gbl.Mails.Lst); free (Mails->Lst);
Gbl.Mails.Lst = NULL; Mails->Lst = NULL;
Gbl.Mails.Num = 0; Mails->Num = 0;
} }
} }
@ -402,7 +425,7 @@ void Mai_FreeListMailDomains (void)
/************************** List all mail domains ****************************/ /************************** List all mail domains ****************************/
/*****************************************************************************/ /*****************************************************************************/
static void Mai_ListMailDomainsForEdition (void) static void Mai_ListMailDomainsForEdition (const struct Mai_Mails *Mails)
{ {
extern const char *Hlp_START_Domains_edit; extern const char *Hlp_START_Domains_edit;
extern const char *Txt_Email_domains_allowed_for_notifications; extern const char *Txt_Email_domains_allowed_for_notifications;
@ -419,10 +442,10 @@ static void Mai_ListMailDomainsForEdition (void)
/***** Write all mail domains *****/ /***** Write all mail domains *****/
for (NumMai = 0; for (NumMai = 0;
NumMai < Gbl.Mails.Num; NumMai < Mails->Num;
NumMai++) NumMai++)
{ {
Mai = &Gbl.Mails.Lst[NumMai]; Mai = &Mails->Lst[NumMai];
HTM_TR_Begin (NULL); HTM_TR_Begin (NULL);
@ -1660,6 +1683,17 @@ bool Mai_ICanSeeOtherUsrEmail (const struct Usr_Data *UsrDat)
} }
} }
/*****************************************************************************/
/************************* Initialize mail domain list ***********************/
/*****************************************************************************/
static void Mai_InitializeMailDomainList (struct Mai_Mails *Mails)
{
Mails->Num = 0;
Mails->Lst = NULL;
Mails->SelectedOrder = Mai_ORDER_DEFAULT;
}
/*****************************************************************************/ /*****************************************************************************/
/********************** Mail domain constructor/destructor *******************/ /********************** Mail domain constructor/destructor *******************/
/*****************************************************************************/ /*****************************************************************************/

View File

@ -61,7 +61,6 @@ struct Mail
void Mai_SeeMailDomains (void); void Mai_SeeMailDomains (void);
void Mai_EditMailDomains (void); void Mai_EditMailDomains (void);
void Mai_FreeListMailDomains (void);
bool Mai_CheckIfUsrCanReceiveEmailNotif (const struct Usr_Data *UsrDat); bool Mai_CheckIfUsrCanReceiveEmailNotif (const struct Usr_Data *UsrDat);
void Mai_WriteWarningEmailNotifications (void); void Mai_WriteWarningEmailNotifications (void);

View File

@ -352,7 +352,7 @@ void Mai_DB_UpdateMailDomainName (long MaiCod,
/****************************** Get mail domains *****************************/ /****************************** Get mail domains *****************************/
/*****************************************************************************/ /*****************************************************************************/
unsigned Mai_DB_GetMailDomains (MYSQL_RES **mysql_res) unsigned Mai_DB_GetMailDomains (MYSQL_RES **mysql_res,Mai_DomainsOrder_t SelectedOrder)
{ {
static const char *OrderBySubQuery[Mai_NUM_ORDERS] = static const char *OrderBySubQuery[Mai_NUM_ORDERS] =
{ {
@ -386,7 +386,7 @@ unsigned Mai_DB_GetMailDomains (MYSQL_RES **mysql_res)
" (SELECT Domain COLLATE 'latin1_bin'" " (SELECT Domain COLLATE 'latin1_bin'"
" FROM T2))" " FROM T2))"
" ORDER BY %s", // COLLATE necessary to avoid error in comparisons " ORDER BY %s", // COLLATE necessary to avoid error in comparisons
OrderBySubQuery[Gbl.Mails.SelectedOrder]); OrderBySubQuery[SelectedOrder]);
} }

View File

@ -66,7 +66,7 @@ void Mai_DB_CreateMailDomain (const struct Mail *Mai);
void Mai_DB_UpdateMailDomainName (long MaiCod, void Mai_DB_UpdateMailDomainName (long MaiCod,
const char *FieldName,const char *NewMaiName); const char *FieldName,const char *NewMaiName);
unsigned Mai_DB_GetMailDomains (MYSQL_RES **mysql_res); unsigned Mai_DB_GetMailDomains (MYSQL_RES **mysql_res,Mai_DomainsOrder_t SelectedOrder);
unsigned Mai_DB_GetDataOfMailDomainByCod (MYSQL_RES **mysql_res,long MaiCod); unsigned Mai_DB_GetDataOfMailDomainByCod (MYSQL_RES **mysql_res,long MaiCod);
bool Mai_DB_CheckIfMailDomainNameExists (const char *FieldName,const char *Name,long MaiCod); bool Mai_DB_CheckIfMailDomainNameExists (const char *FieldName,const char *Name,long MaiCod);
bool Mai_DB_CheckIfMailDomainIsAllowedForNotif (const char MailDomain[Cns_MAX_BYTES_EMAIL_ADDRESS + 1]); bool Mai_DB_CheckIfMailDomainIsAllowedForNotif (const char MailDomain[Cns_MAX_BYTES_EMAIL_ADDRESS + 1]);

View File

@ -63,15 +63,16 @@ extern struct Globals Gbl;
struct Plg_Plugins struct Plg_Plugins
{ {
unsigned Num; // Number of plugins unsigned Num; // Number of plugins
struct Plg_Plugin *Lst; // List of plugins struct Plg_Plugin *Lst; // List of plugins
}; };
/*****************************************************************************/ /*****************************************************************************/
/************************* Private global variables **************************/ /************************* Private global variables **************************/
/*****************************************************************************/ /*****************************************************************************/
static struct Plg_Plugin *Plg_EditingPlg; // Plugin being edited // Global because it's maintained from a-priori to a-posteriori functions
static struct Plg_Plugin *Plg_EditingPlg; // Plugin being edited.
/*****************************************************************************/ /*****************************************************************************/
/***************************** Private prototypes ****************************/ /***************************** Private prototypes ****************************/