From 02c4a6020db5299a1dc8b55a99cd79c033f7e39f Mon Sep 17 00:00:00 2001 From: acanas Date: Wed, 2 Sep 2020 12:20:21 +0200 Subject: [PATCH] Version19.263.1 --- swad_MAC.c | 35 ++++++++++++------------- swad_MAC.h | 4 +++ swad_changelog.h | 9 ++++--- swad_room.c | 68 ++++++++++++++++++++++++++++++++---------------- swad_room.h | 2 +- 5 files changed, 73 insertions(+), 45 deletions(-) diff --git a/swad_MAC.c b/swad_MAC.c index ee3f51eb9..5237fc0e4 100644 --- a/swad_MAC.c +++ b/swad_MAC.c @@ -31,6 +31,7 @@ #include "swad_database.h" #include "swad_form.h" #include "swad_HTML.h" +#include "swad_MAC.h" #include "swad_parameter.h" /*****************************************************************************/ @@ -41,9 +42,6 @@ /***************************** Private constants *****************************/ /*****************************************************************************/ -#define MAC_NUM_BYTES 6 -#define MAC_LENGTH_MAC_ADDRESS (MAC_NUM_BYTES * 3 - 1) // xx:xx:xx:xx:xx:xx - /*****************************************************************************/ /******************************* Private types *******************************/ /*****************************************************************************/ @@ -52,7 +50,7 @@ struct MAC_Params { long Cod; // Code (i.e. room code) - char MAC[MAC_LENGTH_MAC_ADDRESS + 1]; // MAC address + char MACstr[MAC_LENGTH_MAC_ADDRESS + 1]; // MAC address }; /*****************************************************************************/ @@ -67,8 +65,6 @@ static void MAC_PutParams (void *Args); static void MAC_PutFormToEditMACAddress (Act_Action_t NextAction,const char *Anchor, void (*FuncParams) (void *Args),void *Args); -static void MAC_MACnumToMACstr (unsigned long long MACnum,char MACstr[MAC_LENGTH_MAC_ADDRESS + 1]); - /*****************************************************************************/ /**************** Put hidden parameters to edit a MAC address ****************/ /*****************************************************************************/ @@ -78,7 +74,7 @@ static void MAC_PutParams (void *Args) if (Args) { Par_PutHiddenParamLong (NULL,"Cod",((struct MAC_Params *) Args)->Cod); - Par_PutHiddenParamString (NULL,"MAC",((struct MAC_Params *) Args)->MAC); + Par_PutHiddenParamString (NULL,"MAC",((struct MAC_Params *) Args)->MACstr); } } @@ -92,7 +88,7 @@ static void MAC_PutFormToEditMACAddress (Act_Action_t NextAction,const char *Anc /* Form to enter a new MAC address */ Frm_StartFormAnchor (NextAction,Anchor); FuncParams (Args); - HTM_INPUT_TEXT ("NewMAC",MAC_LENGTH_MAC_ADDRESS,((struct MAC_Params *) Args)->MAC, + HTM_INPUT_TEXT ("NewMAC",MAC_LENGTH_MAC_ADDRESS,((struct MAC_Params *) Args)->MACstr, HTM_SUBMIT_ON_CHANGE, "size=\"8\""); Frm_EndForm (); @@ -157,7 +153,7 @@ void MAC_EditMACAddresses (long Cod,const char *Anchor, if (sscanf (row[0],"%llu",&MACnum) == 1) { Params.Cod = Cod; // Code (i.e. room code) - MAC_MACnumToMACstr (MACnum,Params.MAC); // Current MAC address + MAC_MACnumToMACstr (MACnum,Params.MACstr); // Current MAC address in xx:xx:xx:xx:xx:xx format MAC_PutFormToEditMACAddress (ActChgRooMAC,Anchor, MAC_PutParams,&Params); @@ -168,7 +164,7 @@ void MAC_EditMACAddresses (long Cod,const char *Anchor, /* Form to enter a new MAC address */ Params.Cod = Cod; // Code (i.e. room code) - Params.MAC[0] = '\0'; // Current MAC address + Params.MACstr[0] = '\0'; // Current MAC address in xx:xx:xx:xx:xx:xx format MAC_PutFormToEditMACAddress (ActChgRooMAC,Anchor, MAC_PutParams,&Params); @@ -213,13 +209,16 @@ unsigned long long MAC_GetMACnumFromForm (const char *ParamName) /**** Convert from MAC as a number to string in xx:xx:xx:xx:xx:xx format *****/ /*****************************************************************************/ -static void MAC_MACnumToMACstr (unsigned long long MACnum,char MACstr[MAC_LENGTH_MAC_ADDRESS + 1]) +void MAC_MACnumToMACstr (unsigned long long MACnum,char MACstr[MAC_LENGTH_MAC_ADDRESS + 1]) { - snprintf (MACstr,MAC_LENGTH_MAC_ADDRESS + 1,"%02x:%02x:%02x:%02x:%02x:%02x", - (unsigned char) ((MACnum >> (CHAR_BIT * 5)) & ((1 << CHAR_BIT) - 1)), - (unsigned char) ((MACnum >> (CHAR_BIT * 4)) & ((1 << CHAR_BIT) - 1)), - (unsigned char) ((MACnum >> (CHAR_BIT * 3)) & ((1 << CHAR_BIT) - 1)), - (unsigned char) ((MACnum >> (CHAR_BIT * 2)) & ((1 << CHAR_BIT) - 1)), - (unsigned char) ((MACnum >> (CHAR_BIT * 1)) & ((1 << CHAR_BIT) - 1)), - (unsigned char) ((MACnum >> (CHAR_BIT * 0)) & ((1 << CHAR_BIT) - 1))); + if (MACnum) + snprintf (MACstr,MAC_LENGTH_MAC_ADDRESS + 1,"%02x:%02x:%02x:%02x:%02x:%02x", + (unsigned char) ((MACnum >> (CHAR_BIT * 5)) & ((1 << CHAR_BIT) - 1)), + (unsigned char) ((MACnum >> (CHAR_BIT * 4)) & ((1 << CHAR_BIT) - 1)), + (unsigned char) ((MACnum >> (CHAR_BIT * 3)) & ((1 << CHAR_BIT) - 1)), + (unsigned char) ((MACnum >> (CHAR_BIT * 2)) & ((1 << CHAR_BIT) - 1)), + (unsigned char) ((MACnum >> (CHAR_BIT * 1)) & ((1 << CHAR_BIT) - 1)), + (unsigned char) ((MACnum >> (CHAR_BIT * 0)) & ((1 << CHAR_BIT) - 1))); + else + MACstr[0] = '\0'; } diff --git a/swad_MAC.h b/swad_MAC.h index 0d6d491ab..35df89ee2 100644 --- a/swad_MAC.h +++ b/swad_MAC.h @@ -31,6 +31,9 @@ /************************** Public types and constants ***********************/ /*****************************************************************************/ +#define MAC_NUM_BYTES 6 +#define MAC_LENGTH_MAC_ADDRESS (MAC_NUM_BYTES * 3 - 1) // xx:xx:xx:xx:xx:xx + /*****************************************************************************/ /***************************** Public prototypes *****************************/ /*****************************************************************************/ @@ -40,5 +43,6 @@ void MAC_EditMACAddresses (long Cod,const char *Anchor, unsigned NumMACs,MYSQL_RES **mysql_res); unsigned long long MAC_GetMACnumFromForm (const char *ParamName); +void MAC_MACnumToMACstr (unsigned long long MACnum,char MACstr[MAC_LENGTH_MAC_ADDRESS + 1]); #endif diff --git a/swad_changelog.h b/swad_changelog.h index d2f9cd4c0..492b402a8 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.263 (2020-09-02)" +#define Log_PLATFORM_VERSION "SWAD 19.263.1 (2020-09-02)" #define CSS_FILE "swad19.253.css" #define JS_FILE "swad19.254.js" /* @@ -573,9 +573,10 @@ 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.263 : Sep 02, 2020 New module swad_MAC for MAC addresses. (304364 lines) - 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.263.1: Sep 02, 2020 MAC address in form to create a new room. (304389 lines) + Version 19.263: Sep 02, 2020 New module swad_MAC for MAC addresses. (304364 lines) + 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) Version 19.260.1: Aug 26, 2020 Fixed bugs in API functions related to games and matches. Reported by Sergio Díaz Rueda. (304027 lines) diff --git a/swad_room.c b/swad_room.c index b9dd028d5..2b43dba84 100644 --- a/swad_room.c +++ b/swad_room.c @@ -371,8 +371,8 @@ static unsigned Roo_GetMACAddresses (long RooCod,MYSQL_RES **mysql_res) void Roo_ChangeMAC (void) { - unsigned long long OldMAC; - unsigned long long NewMAC; + unsigned long long OldMACnum; + unsigned long long NewMACnum; /***** Room constructor *****/ Roo_EditingRoomConstructor (); @@ -383,27 +383,27 @@ void Roo_ChangeMAC (void) Lay_ShowErrorAndExit ("Code of room is missing."); /* Get the old MAC address of the room */ - OldMAC = MAC_GetMACnumFromForm ("MAC"); + OldMACnum = MAC_GetMACnumFromForm ("MAC"); /* Get the new MAC address of the room */ - NewMAC = MAC_GetMACnumFromForm ("NewMAC"); + NewMACnum = MAC_GetMACnumFromForm ("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) + if (OldMACnum) DB_QueryDELETE ("can not remove MAC address", "DELETE FROM room_MAC" " WHERE RooCod=%ld AND MAC=%llu", - Roo_EditingRoom->RooCod,OldMAC); - if (NewMAC) + Roo_EditingRoom->RooCod,OldMACnum); + if (NewMACnum) /***** 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->RooCod,NewMACnum); - Roo_EditingRoom->MAC = NewMAC; + Roo_EditingRoom->MACnum = NewMACnum; } /*****************************************************************************/ @@ -1416,6 +1416,7 @@ static void Roo_PutFormToCreateRoom (const struct Bld_Buildings *Buildings) extern const char *Txt_New_room; extern const char *Txt_Create_room; char StrCapacity[Cns_MAX_DECIMAL_DIGITS_UINT + 1]; + char MACstr[MAC_LENGTH_MAC_ADDRESS + 1]; // MAC address in xx:xx:xx:xx:xx:xx format /***** Begin form *****/ Frm_StartForm (ActNewRoo); @@ -1479,6 +1480,14 @@ static void Roo_PutFormToCreateRoom (const struct Bld_Buildings *Buildings) "size=\"3\""); HTM_TD_End (); + /***** MAC address *****/ + HTM_TD_Begin ("class=\"LM\""); + MAC_MACnumToMACstr (Roo_EditingRoom->MACnum,MACstr); + HTM_INPUT_TEXT ("MAC",MAC_LENGTH_MAC_ADDRESS,MACstr, + HTM_DONT_SUBMIT_ON_CHANGE, + "size=\"8\""); + HTM_TD_End (); + HTM_TR_End (); /***** End table, send button and end box *****/ @@ -1554,6 +1563,10 @@ void Roo_ReceiveFormNewRoom (void) Roo_MAX_CAPACITY, Roo_UNLIMITED_CAPACITY); + /* Get MAC address */ + Roo_EditingRoom->MACnum = MAC_GetMACnumFromForm ("MAC"); + + if (Roo_EditingRoom->ShrtName[0] && Roo_EditingRoom->FullName[0]) // If there's a room name { @@ -1590,18 +1603,29 @@ static void Roo_CreateRoom (struct Roo_Room *Room) Room->Type = Roo_NO_TYPE; /***** Create a new room *****/ - DB_QueryINSERT ("can not create room", - "INSERT INTO rooms" - " (CtrCod,BldCod,Floor,Type,ShortName,FullName,Capacity)" - " VALUES" - " (%ld,%ld,%d,'%s','%s','%s',%u)", - Gbl.Hierarchy.Ctr.CtrCod, - Room->BldCod, - Room->Floor, - Roo_TypesDB[Room->Type], - Room->ShrtName, - Room->FullName, - Room->Capacity); + Room->RooCod = + DB_QueryINSERTandReturnCode ("can not create room", + "INSERT INTO rooms" + " (CtrCod,BldCod,Floor,Type,ShortName,FullName,Capacity)" + " VALUES" + " (%ld,%ld,%d,'%s','%s','%s',%u)", + Gbl.Hierarchy.Ctr.CtrCod, + Room->BldCod, + Room->Floor, + Roo_TypesDB[Room->Type], + Room->ShrtName, + Room->FullName, + Room->Capacity); + + /***** Create MAC address *****/ + if (Room->MACnum) + DB_QueryINSERT ("can not create MAC address", + "INSERT INTO room_MAC" + " (RooCod,MAC)" + " VALUES" + " (%ld,%llu)", + Room->RooCod, + Room->MACnum); } /*****************************************************************************/ @@ -1627,7 +1651,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; + Roo_EditingRoom->MACnum = 0ULL; } static void Roo_EditingRoomDestructor (void) diff --git a/swad_room.h b/swad_room.h index 3e3899a70..ae97e9921 100644 --- a/swad_room.h +++ b/swad_room.h @@ -86,7 +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; + unsigned long long MACnum; }; #define Roo_NUM_ORDERS 6