From 623799d144f1883cf636d555828ce2cf0387f978 Mon Sep 17 00:00:00 2001 From: acanas Date: Tue, 1 Sep 2020 21:41:34 +0200 Subject: [PATCH] Version19.262 --- swad_action.c | 2 + swad_action.h | 41 +++++---- swad_changelog.h | 3 +- swad_room.c | 234 +++++++++++++++++++++++++++++++++++++++-------- swad_room.h | 2 + 5 files changed, 223 insertions(+), 59 deletions(-) diff --git a/swad_action.c b/swad_action.c index 9f4df8caf..078539051 100644 --- a/swad_action.c +++ b/swad_action.c @@ -374,6 +374,7 @@ const struct Act_Actions Act_Actions[Act_NUM_ACTIONS] = [ActRenRooSho ] = {1748,-1,TabUnk,ActSeeRoo , 0, 0, 0,0x3C6, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,Roo_RenameRoomShort ,Roo_ContEditAfterChgRoom ,NULL}, [ActRenRooFul ] = {1749,-1,TabUnk,ActSeeRoo , 0, 0, 0,0x3C6, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,Roo_RenameRoomFull ,Roo_ContEditAfterChgRoom ,NULL}, [ActChgRooMaxUsr ] = {1750,-1,TabUnk,ActSeeRoo , 0, 0, 0,0x3C6, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,Roo_ChangeCapacity ,Roo_ContEditAfterChgRoom ,NULL}, + [ActChgRooMAC ] = {1911,-1,TabUnk,ActSeeRoo , 0, 0, 0,0x3C6, 0, 0, 0,Act_CONT_NORM,Act_BRW_1ST_TAB,Roo_ChangeMAC ,Roo_ContEditAfterChgRoom ,NULL}, // TabDeg ****************************************************************** // Actions in menu: @@ -3722,6 +3723,7 @@ Act_Action_t Act_FromActCodToAction[1 + Act_MAX_ACTION_COD] = // Do not reuse un ActEndExaPrn, // #1908 ActValSetQst, // #1909 ActInvSetQst, // #1910 + ActChgRooMAC, // #1911 }; /*****************************************************************************/ diff --git a/swad_action.h b/swad_action.h index ee0aa70a6..1cebc9b23 100644 --- a/swad_action.h +++ b/swad_action.h @@ -64,7 +64,7 @@ typedef enum typedef signed int Act_Action_t; // Must be a signed type, because -1 is used to indicate obsolete action -#define Act_MAX_ACTION_COD 1910 +#define Act_MAX_ACTION_COD 1911 #define Act_MAX_OPTIONS_IN_MENU_PER_TAB 13 @@ -345,33 +345,34 @@ typedef signed int Act_Action_t; // Must be a signed type, because -1 is used to #define ActRenRooSho (ActRenHld + 46) #define ActRenRooFul (ActRenHld + 47) #define ActChgRooMaxUsr (ActRenHld + 48) +#define ActChgRooMAC (ActRenHld + 49) /*****************************************************************************/ /********************************* Degree tab ********************************/ /*****************************************************************************/ // Actions in menu -#define ActSeeDegInf (ActChgRooMaxUsr + 1) -#define ActSeeCrs (ActChgRooMaxUsr + 2) +#define ActSeeDegInf (ActChgRooMAC + 1) +#define ActSeeCrs (ActChgRooMAC + 2) // Secondary actions -#define ActPrnDegInf (ActChgRooMaxUsr + 3) -#define ActChgDegCtrCfg (ActChgRooMaxUsr + 4) -#define ActRenDegShoCfg (ActChgRooMaxUsr + 5) -#define ActRenDegFulCfg (ActChgRooMaxUsr + 6) -#define ActChgDegWWWCfg (ActChgRooMaxUsr + 7) -#define ActReqDegLog (ActChgRooMaxUsr + 8) -#define ActRecDegLog (ActChgRooMaxUsr + 9) -#define ActRemDegLog (ActChgRooMaxUsr + 10) +#define ActPrnDegInf (ActChgRooMAC + 3) +#define ActChgDegCtrCfg (ActChgRooMAC + 4) +#define ActRenDegShoCfg (ActChgRooMAC + 5) +#define ActRenDegFulCfg (ActChgRooMAC + 6) +#define ActChgDegWWWCfg (ActChgRooMAC + 7) +#define ActReqDegLog (ActChgRooMAC + 8) +#define ActRecDegLog (ActChgRooMAC + 9) +#define ActRemDegLog (ActChgRooMAC + 10) -#define ActEdiCrs (ActChgRooMaxUsr + 11) -#define ActReqCrs (ActChgRooMaxUsr + 12) -#define ActNewCrs (ActChgRooMaxUsr + 13) -#define ActRemCrs (ActChgRooMaxUsr + 14) -#define ActChgInsCrsCod (ActChgRooMaxUsr + 15) -#define ActChgCrsYea (ActChgRooMaxUsr + 16) -#define ActRenCrsSho (ActChgRooMaxUsr + 17) -#define ActRenCrsFul (ActChgRooMaxUsr + 18) -#define ActChgCrsSta (ActChgRooMaxUsr + 19) +#define ActEdiCrs (ActChgRooMAC + 11) +#define ActReqCrs (ActChgRooMAC + 12) +#define ActNewCrs (ActChgRooMAC + 13) +#define ActRemCrs (ActChgRooMAC + 14) +#define ActChgInsCrsCod (ActChgRooMAC + 15) +#define ActChgCrsYea (ActChgRooMAC + 16) +#define ActRenCrsSho (ActChgRooMAC + 17) +#define ActRenCrsFul (ActChgRooMAC + 18) +#define ActChgCrsSta (ActChgRooMAC + 19) /*****************************************************************************/ /******************************** Course tab *********************************/ diff --git a/swad_changelog.h b/swad_changelog.h index 626f26f16..77a240aa3 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -555,7 +555,7 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - * En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 19.261 (2020-09-01)" +#define Log_PLATFORM_VERSION "SWAD 19.262 (2020-09-01)" #define CSS_FILE "swad19.253.css" #define JS_FILE "swad19.254.js" /* @@ -573,6 +573,7 @@ TODO: Que al generar un examen s TODO: Create module swad_test_result "sudo apt install webp" en Ubuntu, y "yum install libwebp libwebp-tools" en CentOS, para decodificar imágenes Web/ug reportado por Javier Fernández Baldomero. + Version 19.262 : Sep 01, 2020 Edition of MAC addresses in listing of rooms. (304239 lines) Version 19.261 : Sep 01, 2020 MAC addresses are printed in listing of rooms. (304103 lines) Version 19.260.3: Aug 30, 2020 Fixed bug in API function answerMatchQuestion. Reported by Sergio Díaz Rueda. (304010 lines) Version 19.260.2: Aug 28, 2020 Fixed bugs in API functions related to games and matches. Reported by Sergio Díaz Rueda. (304010 lines) diff --git a/swad_room.c b/swad_room.c index f6748571f..8d191c393 100644 --- a/swad_room.c +++ b/swad_room.c @@ -119,7 +119,11 @@ static struct Roo_Room *Roo_EditingRoom = NULL; // Static variable to keep the r /***************************** Private prototypes ****************************/ /*****************************************************************************/ -static void Roo_GetAndWriteMACAddresses (long RooCod); +static void Roo_GetAndListMACAddresses (long RooCod); +static void Roo_GetAndEditMACAddresses (long RooCod,const char *Anchor); +static unsigned Roo_GetMACAddresses (long RooCod,MYSQL_RES **mysql_res); +static void Roo_MACnumToMACstr (unsigned long long MACnum,char MACstr[17 + 1]); +unsigned long long Roo_GetMACnum (const char *ParamName); static Roo_Order_t Roo_GetParamRoomOrder (void); static bool Roo_CheckIfICanCreateRooms (void); @@ -250,32 +254,32 @@ void Roo_SeeRooms (void) HTM_TR_Begin (NULL); /* Building short name */ - HTM_TD_Begin ("class=\"DAT LM %s\"",Gbl.ColorRows[RowEvenOdd]); + HTM_TD_Begin ("class=\"DAT LT %s\"",Gbl.ColorRows[RowEvenOdd]); HTM_Txt (Rooms.Lst[NumRoom].BldShrtName); HTM_TD_End (); /* Floor */ - HTM_TD_Begin ("class=\"DAT RM %s\"",Gbl.ColorRows[RowEvenOdd]); + HTM_TD_Begin ("class=\"DAT RT %s\"",Gbl.ColorRows[RowEvenOdd]); HTM_Int (Rooms.Lst[NumRoom].Floor); HTM_TD_End (); /* Type */ - HTM_TD_Begin ("class=\"DAT LM %s\"",Gbl.ColorRows[RowEvenOdd]); + HTM_TD_Begin ("class=\"DAT LT %s\"",Gbl.ColorRows[RowEvenOdd]); Ico_PutIconOn (Roo_TypesIcons[Rooms.Lst[NumRoom].Type],Txt_ROOM_TYPES[Rooms.Lst[NumRoom].Type]); HTM_TD_End (); /* Short name */ - HTM_TD_Begin ("class=\"DAT LM %s\"",Gbl.ColorRows[RowEvenOdd]); + HTM_TD_Begin ("class=\"DAT LT %s\"",Gbl.ColorRows[RowEvenOdd]); HTM_Txt (Rooms.Lst[NumRoom].ShrtName); HTM_TD_End (); /* Full name */ - HTM_TD_Begin ("class=\"DAT LM %s\"",Gbl.ColorRows[RowEvenOdd]); + HTM_TD_Begin ("class=\"DAT LT %s\"",Gbl.ColorRows[RowEvenOdd]); HTM_Txt (Rooms.Lst[NumRoom].FullName); HTM_TD_End (); /* Capacity */ - HTM_TD_Begin ("class=\"DAT RM %s\"",Gbl.ColorRows[RowEvenOdd]); + HTM_TD_Begin ("class=\"DAT RT %s\"",Gbl.ColorRows[RowEvenOdd]); Roo_WriteCapacity (StrCapacity,Rooms.Lst[NumRoom].Capacity); HTM_Txt (StrCapacity); HTM_TD_End (); @@ -286,8 +290,8 @@ void Roo_SeeRooms (void) case Rol_CTR_ADM: case Rol_INS_ADM: case Rol_SYS_ADM: - HTM_TD_Begin ("class=\"DAT RM %s\"",Gbl.ColorRows[RowEvenOdd]); - Roo_GetAndWriteMACAddresses (Rooms.Lst[NumRoom].RooCod); + HTM_TD_Begin ("class=\"DAT LT %s\"",Gbl.ColorRows[RowEvenOdd]); + Roo_GetAndListMACAddresses (Rooms.Lst[NumRoom].RooCod); HTM_TD_End (); break; default: @@ -316,55 +320,201 @@ void Roo_SeeRooms (void) } /*****************************************************************************/ -/************* Write list of MAC addresses associated to a room **************/ +/************ Get and list the MAC addresses associated to a room ************/ /*****************************************************************************/ -static void Roo_GetAndWriteMACAddresses (long RooCod) +static void Roo_GetAndListMACAddresses (long RooCod) { MYSQL_RES *mysql_res; MYSQL_ROW row; unsigned NumMACs; unsigned NumMAC; unsigned long long MACnum; + char MACstr[17 + 1]; /***** Get MAC addresses from database *****/ - NumMACs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get MAC addresses", - "SELECT MAC" // row[0] - " FROM room_MAC" - " WHERE RooCod=%ld" - " ORDER BY MAC", - RooCod); + NumMACs = Roo_GetMACAddresses (RooCod,&mysql_res); - /***** Write the MACs *****/ + /***** Write the MAC addresses *****/ for (NumMAC = 0; NumMAC < NumMACs; NumMAC++) { - /* Get next MAC */ + /* Get next MAC address */ row = mysql_fetch_row (mysql_res); /* Write break line */ if (NumMAC) HTM_BR (); - /* Get MAC (row[0]) */ + /* Write MAC address (row[0]) */ if (sscanf (row[0],"%llu",&MACnum) == 1) - /* Write MAC */ - HTM_TxtF ("%02x:%02x:%02x:%02x:%02x:%02x", - (unsigned char) ((MACnum >> 40) & 0xff), - (unsigned char) ((MACnum >> 32) & 0xff), - (unsigned char) ((MACnum >> 24) & 0xff), - (unsigned char) ((MACnum >> 16) & 0xff), - (unsigned char) ((MACnum >> 8) & 0xff), - (unsigned char) ((MACnum ) & 0xff)); - else - HTM_Txt ("?"); + { + Roo_MACnumToMACstr (MACnum,MACstr); + HTM_Txt (MACstr); + } } /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); } +/*****************************************************************************/ +/****** Get and list for edition the MAC addresses associated to a room ******/ +/*****************************************************************************/ + +static void Roo_GetAndEditMACAddresses (long RooCod,const char *Anchor) + { + MYSQL_RES *mysql_res; + MYSQL_ROW row; + unsigned NumMACs; + unsigned NumMAC; + unsigned long long MACnum; + char MACstr[17 + 1]; + + /***** Get MAC addresses from database *****/ + NumMACs = Roo_GetMACAddresses (RooCod,&mysql_res); + + /***** Write the MAC addresses *****/ + for (NumMAC = 0; + NumMAC < NumMACs; + NumMAC++) + { + /* Get next MAC address */ + row = mysql_fetch_row (mysql_res); + + /* Write MAC address (row[0]) */ + if (sscanf (row[0],"%llu",&MACnum) == 1) + { + Frm_StartFormAnchor (ActChgRooMAC,Anchor); + Roo_PutParamRooCod (RooCod); + Roo_MACnumToMACstr (MACnum,MACstr); + Par_PutHiddenParamString (NULL,"OldMAC",MACstr); + HTM_INPUT_TEXT ("NewMAC",17,MACstr, + HTM_SUBMIT_ON_CHANGE, + "size=\"8\""); + Frm_EndForm (); + + /* Write break line */ + HTM_BR (); + } + } + + /* New MAC address */ + Frm_StartFormAnchor (ActChgRooMAC,Anchor); + Roo_PutParamRooCod (RooCod); + HTM_INPUT_TEXT ("NewMAC",17,"", + HTM_SUBMIT_ON_CHANGE, + "size=\"8\""); + Frm_EndForm (); + + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); + } + +/*****************************************************************************/ +/***************** Get the MAC addresses associated to a room ****************/ +/*****************************************************************************/ + +static unsigned Roo_GetMACAddresses (long RooCod,MYSQL_RES **mysql_res) + { + /***** Get MAC addresses from database *****/ + return (unsigned) DB_QuerySELECT (mysql_res,"can not get MAC addresses", + "SELECT MAC" // row[0] + " FROM room_MAC" + " WHERE RooCod=%ld" + " ORDER BY MAC", + RooCod); + } + +/*****************************************************************************/ +/****** Get and list for edition the MAC addresses associated to a room ******/ +/*****************************************************************************/ + +static void Roo_MACnumToMACstr (unsigned long long MACnum,char MACstr[17 + 1]) + { + snprintf (MACstr,17 + 1,"%02x:%02x:%02x:%02x:%02x:%02x", + (unsigned char) ((MACnum >> 40) & 0xff), + (unsigned char) ((MACnum >> 32) & 0xff), + (unsigned char) ((MACnum >> 24) & 0xff), + (unsigned char) ((MACnum >> 16) & 0xff), + (unsigned char) ((MACnum >> 8) & 0xff), + (unsigned char) ((MACnum ) & 0xff)); + } + +/*****************************************************************************/ +/**************************** Change MAC of a room ***************************/ +/*****************************************************************************/ + +void Roo_ChangeMAC (void) + { + unsigned long long OldMAC; + unsigned long long NewMAC; + + /***** Room constructor *****/ + Roo_EditingRoomConstructor (); + + /***** Get parameters from form *****/ + /* Get room code */ + if ((Roo_EditingRoom->RooCod = Roo_GetParamRooCod ()) == -1L) + Lay_ShowErrorAndExit ("Code of room is missing."); + + /* Get the old MAC address of the room */ + OldMAC = Roo_GetMACnum ("OldMAC"); + + /* Get the new MAC address of the room */ + NewMAC = Roo_GetMACnum ("NewMAC"); + + /***** Get data of the room from database *****/ + Roo_GetDataOfRoomByCod (Roo_EditingRoom); + + /***** Check if the new MAC is different from the old MAC *****/ + if (OldMAC) + DB_QueryDELETE ("can not remove MAC address", + "DELETE FROM room_MAC" + " WHERE RooCod=%ld AND MAC=%llu", + Roo_EditingRoom->RooCod,OldMAC); + if (NewMAC) + /***** Update the table of rooms-MACs changing the old MAC for the new one *****/ + DB_QueryREPLACE ("can not change MAC address", + "REPLACE INTO room_MAC (RooCod,MAC) VALUES (%ld,%llu)", + Roo_EditingRoom->RooCod,NewMAC); + + Roo_EditingRoom->MAC = NewMAC; + } + +/*****************************************************************************/ +/****************** Get MAC address as a number from a form ******************/ +/*****************************************************************************/ + +unsigned long long Roo_GetMACnum (const char *ParamName) + { + char MACstr[17 * Str_MAX_BYTES_PER_CHAR + 1]; + unsigned long long MAC[6 + 1]; + unsigned long long MACnum; + + /***** Get parameter *****/ + Par_GetParToText (ParamName,MACstr,17 * Str_MAX_BYTES_PER_CHAR); + + if (MACstr[0]) // Not empty + { + /***** Try to scan it in xx:xx:xx:xx:xx:xx format (where x are hexadecimal digits) *****/ + if (sscanf (MACstr,"%02llx:%02llx:%02llx:%02llx:%02llx:%02llx",&MAC[0],&MAC[1],&MAC[2],&MAC[3],&MAC[4],&MAC[5]) == 6) + return (MAC[0] << 40) + + (MAC[1] << 32) + + (MAC[2] << 24) + + (MAC[3] << 16) + + (MAC[4] << 8) + + MAC[5]; + + /***** Try to scan it in xxxxxxxxxxxx format (where x are hexadecimal digits) ******/ + if (sscanf (MACstr,"%llx",&MACnum) == 1) + return MACnum; + } + + return 0; + } + /*****************************************************************************/ /*********** Get parameter with the type or order in list of rooms ***********/ /*****************************************************************************/ @@ -755,7 +905,7 @@ static void Roo_ListRoomsForEdition (const struct Bld_Buildings *Buildings, HTM_TR_Begin (NULL); /* Put icon to remove room */ - HTM_TD_Begin ("class=\"BM\""); + HTM_TD_Begin ("class=\"BT\""); Frm_StartForm (ActRemRoo); Roo_PutParamRooCod (Room->RooCod); Ico_PutIconRemove (); @@ -763,14 +913,14 @@ static void Roo_ListRoomsForEdition (const struct Bld_Buildings *Buildings, HTM_TD_End (); /* Room code */ - HTM_TD_Begin ("class=\"DAT RM\""); + HTM_TD_Begin ("class=\"DAT RT\""); HTM_ARTICLE_Begin (Anchor); HTM_Long (Room->RooCod); HTM_ARTICLE_End (); HTM_TD_End (); /* Building */ - HTM_TD_Begin ("class=\"CM\""); + HTM_TD_Begin ("class=\"CT\""); Frm_StartFormAnchor (ActChgRooBld,Anchor); Roo_PutParamRooCod (Room->RooCod); Roo_PutSelectorBuilding (Room->BldCod,Buildings, @@ -779,7 +929,7 @@ static void Roo_ListRoomsForEdition (const struct Bld_Buildings *Buildings, HTM_TD_End (); /* Floor */ - HTM_TD_Begin ("class=\"LM\""); + HTM_TD_Begin ("class=\"LT\""); Frm_StartFormAnchor (ActChgRooFlo,Anchor); Roo_PutParamRooCod (Room->RooCod); HTM_INPUT_LONG ("Floor",(long) INT_MIN,(long) INT_MAX,(long) Room->Floor, @@ -789,7 +939,7 @@ static void Roo_ListRoomsForEdition (const struct Bld_Buildings *Buildings, HTM_TD_End (); /* Room type */ - HTM_TD_Begin ("class=\"CM\""); + HTM_TD_Begin ("class=\"CT\""); Frm_StartFormAnchor (ActChgRooTyp,Anchor); Roo_PutParamRooCod (Room->RooCod); Roo_PutSelectorType (Room->Type, @@ -798,7 +948,7 @@ static void Roo_ListRoomsForEdition (const struct Bld_Buildings *Buildings, HTM_TD_End (); /* Room short name */ - HTM_TD_Begin ("class=\"LM\""); + HTM_TD_Begin ("class=\"LT\""); Frm_StartFormAnchor (ActRenRooSho,Anchor); Roo_PutParamRooCod (Room->RooCod); HTM_INPUT_TEXT ("ShortName",Roo_MAX_CHARS_SHRT_NAME,Room->ShrtName, @@ -808,7 +958,7 @@ static void Roo_ListRoomsForEdition (const struct Bld_Buildings *Buildings, HTM_TD_End (); /* Room full name */ - HTM_TD_Begin ("class=\"LM\""); + HTM_TD_Begin ("class=\"LT\""); Frm_StartFormAnchor (ActRenRooFul,Anchor); Roo_PutParamRooCod (Room->RooCod); HTM_INPUT_TEXT ("FullName",Roo_MAX_CHARS_FULL_NAME,Room->FullName, @@ -818,7 +968,7 @@ static void Roo_ListRoomsForEdition (const struct Bld_Buildings *Buildings, HTM_TD_End (); /* Seating capacity */ - HTM_TD_Begin ("class=\"LM\""); + HTM_TD_Begin ("class=\"LT\""); Frm_StartFormAnchor (ActChgRooMaxUsr,Anchor); Roo_PutParamRooCod (Room->RooCod); Roo_WriteCapacity (StrCapacity,Room->Capacity); @@ -828,6 +978,11 @@ static void Roo_ListRoomsForEdition (const struct Bld_Buildings *Buildings, Frm_EndForm (); HTM_TD_End (); + /* MAC addresses */ + HTM_TD_Begin ("class=\"LT\""); + Roo_GetAndEditMACAddresses (Room->RooCod,Anchor); + HTM_TD_End (); + HTM_TR_End (); } @@ -1455,6 +1610,7 @@ static void Roo_PutHeadRooms (void) extern const char *Txt_Short_name; extern const char *Txt_Full_name; extern const char *Txt_Capacity_OF_A_ROOM; + extern const char *Txt_MAC_address; HTM_TR_Begin (NULL); @@ -1466,6 +1622,7 @@ static void Roo_PutHeadRooms (void) HTM_TH (1,1,"LM",Txt_Short_name); HTM_TH (1,1,"LM",Txt_Full_name); HTM_TH (1,1,"LM",Txt_Capacity_OF_A_ROOM); + HTM_TH (1,1,"LM",Txt_MAC_address); HTM_TR_End (); } @@ -1579,6 +1736,7 @@ static void Roo_EditingRoomConstructor (void) Roo_EditingRoom->ShrtName[0] = '\0'; Roo_EditingRoom->FullName[0] = '\0'; Roo_EditingRoom->Capacity = Roo_UNLIMITED_CAPACITY; + Roo_EditingRoom->MAC = 0ULL; } static void Roo_EditingRoomDestructor (void) diff --git a/swad_room.h b/swad_room.h index 14cbb8f2c..3e3899a70 100644 --- a/swad_room.h +++ b/swad_room.h @@ -86,6 +86,7 @@ struct Roo_Room char FullName[Roo_MAX_BYTES_FULL_NAME + 1]; // Room full name unsigned Capacity; // Room seating capacity // (maximum people who fit in the room) + unsigned long long MAC; }; #define Roo_NUM_ORDERS 6 @@ -121,6 +122,7 @@ struct Roo_Rooms void Roo_ResetRooms (struct Roo_Rooms *Rooms); void Roo_SeeRooms (void); +void Roo_ChangeMAC (void); void Roo_EditRooms (void); void Roo_PutIconToViewRooms (void); void Roo_GetListRooms (struct Roo_Rooms *Rooms,