diff --git a/swad_ID.c b/swad_ID.c index 1cd906bf..2cf29d00 100644 --- a/swad_ID.c +++ b/swad_ID.c @@ -118,8 +118,7 @@ void ID_GetListIDsFromUsrCod (struct UsrData *UsrDat) row = mysql_fetch_row (mysql_res); /* Get ID from row[0] */ - strncpy (UsrDat->IDs.List[NumID].ID,row[0],ID_MAX_LENGTH_USR_ID); - UsrDat->IDs.List[NumID].ID[ID_MAX_LENGTH_USR_ID] = '\0'; + Str_Copy (UsrDat->IDs.List[NumID].ID,row[0],ID_MAX_LENGTH_USR_ID); /* Get if ID is confirmed from row[1] */ UsrDat->IDs.List[NumID].Confirmed = (row[1][0] == 'Y'); @@ -195,12 +194,10 @@ unsigned ID_GetListUsrCodsFromUsrID (struct UsrData *UsrDat, Lay_ShowErrorAndExit ("Not enough memory to store list of user's IDs."); /***** Get user's code(s) from database *****/ - strncpy (Query,CheckPassword ? "SELECT DISTINCT(usr_IDs.UsrCod) FROM usr_IDs,usr_data" - " WHERE usr_IDs.UsrID IN (" : - "SELECT DISTINCT(UsrCod) FROM usr_IDs" - " WHERE UsrID IN (",Length); - Query[Length] = '\0'; - + Str_Copy (Query,CheckPassword ? "SELECT DISTINCT(usr_IDs.UsrCod) FROM usr_IDs,usr_data" + " WHERE usr_IDs.UsrID IN (" : + "SELECT DISTINCT(UsrCod) FROM usr_IDs" + " WHERE UsrID IN (",Length); for (NumID = 0; NumID < UsrDat->IDs.Num; NumID++) diff --git a/swad_ID.h b/swad_ID.h index 2eeafc1b..5b068d70 100644 --- a/swad_ID.h +++ b/swad_ID.h @@ -43,7 +43,7 @@ struct ListIDs { bool Confirmed; - char ID[ID_MAX_LENGTH_USR_ID+1]; + char ID[ID_MAX_LENGTH_USR_ID + 1]; }; /*****************************************************************************/ diff --git a/swad_MFU.c b/swad_MFU.c index 927de4b5..802a3dcf 100644 --- a/swad_MFU.c +++ b/swad_MFU.c @@ -45,6 +45,9 @@ /***************************** Private constants *****************************/ /*****************************************************************************/ +#define MFU_MAX_LENGTH_TAB (128 - 1) +#define MFU_MAX_LENGTH_MENU (128 - 1) + /*****************************************************************************/ /****************************** Internal types *******************************/ /*****************************************************************************/ @@ -212,9 +215,9 @@ void MFU_WriteBigMFUActions (struct MFU_ListMFUActions *ListMFUActions) Act_Action_t Action; Act_Action_t SuperAction; const char *Title; - char TabStr[128+1]; - char MenuStr[128+1]; - char TabMenuStr[128+6+128+1]; + char TabStr[MFU_MAX_LENGTH_TAB + 1]; + char MenuStr[MFU_MAX_LENGTH_MENU + 1]; + char TabMenuStr[MFU_MAX_LENGTH_TAB + 6 + MFU_MAX_LENGTH_MENU + 1]; /***** Start frame *****/ Lay_StartRoundFrame (NULL,Txt_My_frequent_actions,NULL,Hlp_STATS_Frequent); @@ -232,10 +235,9 @@ void MFU_WriteBigMFUActions (struct MFU_ListMFUActions *ListMFUActions) { /* Action string */ SuperAction = Act_Actions[Action].SuperAction; - strncpy (TabStr,Txt_TABS_TXT[Act_Actions[SuperAction].Tab],128); - TabStr[128] = '\0'; - strncpy (MenuStr,Title,128); - MenuStr[128] = '\0'; + Str_Copy (TabStr,Txt_TABS_TXT[Act_Actions[SuperAction].Tab], + MFU_MAX_LENGTH_TAB); + Str_Copy (MenuStr,Title,MFU_MAX_LENGTH_MENU); sprintf (TabMenuStr,"%s > %s",TabStr,MenuStr); /* Icon and text */ @@ -271,9 +273,9 @@ void MFU_WriteSmallMFUActions (struct MFU_ListMFUActions *ListMFUActions) Act_Action_t Action; Act_Action_t SuperAction; const char *Title; - char TabStr[128+1]; - char MenuStr[128+1]; - char TabMenuStr[128+6+128+1]; + char TabStr[MFU_MAX_LENGTH_TAB + 1]; + char MenuStr[MFU_MAX_LENGTH_MENU + 1]; + char TabMenuStr[MFU_MAX_LENGTH_TAB + 6 + MFU_MAX_LENGTH_MENU + 1]; /***** Start div and link *****/ fprintf (Gbl.F.Out,"
"); @@ -296,10 +298,9 @@ void MFU_WriteSmallMFUActions (struct MFU_ListMFUActions *ListMFUActions) { /* Action string */ SuperAction = Act_Actions[Action].SuperAction; - strncpy (TabStr,Txt_TABS_TXT[Act_Actions[SuperAction].Tab],128); - TabStr[128] = '\0'; - strncpy (MenuStr,Title,128); - MenuStr[128] = '\0'; + Str_Copy (TabStr,Txt_TABS_TXT[Act_Actions[SuperAction].Tab], + MFU_MAX_LENGTH_TAB); + Str_Copy (MenuStr,Title,MFU_MAX_LENGTH_MENU); sprintf (TabMenuStr,"%s > %s",TabStr,MenuStr); /* Icon and text */ diff --git a/swad_QR.c b/swad_QR.c index 8b769a53..e36c991d 100644 --- a/swad_QR.c +++ b/swad_QR.c @@ -25,8 +25,6 @@ /*********************************** Headers *********************************/ /*****************************************************************************/ -#include // For strncpy... - #include "swad_action.h" #include "swad_global.h" #include "swad_ID.h" diff --git a/swad_RSS.c b/swad_RSS.c index d60554b1..5265f705 100644 --- a/swad_RSS.c +++ b/swad_RSS.c @@ -191,8 +191,7 @@ static void RSS_WriteNotices (FILE *FileRSS,struct Course *Crs) fprintf (FileRSS,"\n"); /* Write title (first characters) of the notice */ - strncpy (Content,row[3],Cns_MAX_BYTES_TEXT); - Content[Cns_MAX_BYTES_TEXT] = '\0'; + Str_Copy (Content,row[3],Cns_MAX_BYTES_TEXT); Str_LimitLengthHTMLStr (Content,40); fprintf (FileRSS,"%s: ",Txt_Notice); Str_FilePrintStrChangingBRToRetAndNBSPToSpace (FileRSS,Content); @@ -203,8 +202,7 @@ static void RSS_WriteNotices (FILE *FileRSS,struct Course *Crs) Cfg_URL_SWAD_CGI,Crs->CrsCod); /* Write full content of the notice */ - strncpy (Content,row[3],Cns_MAX_BYTES_TEXT); - Content[Cns_MAX_BYTES_TEXT] = '\0'; + Str_Copy (Content,row[3],Cns_MAX_BYTES_TEXT); Str_InsertLinks (Content,Cns_MAX_BYTES_TEXT,40); fprintf (FileRSS,"<description><![CDATA[<p><em>%s %s %s:</em></p><p>%s</p>]]></description>\n", UsrDat.FirstName,UsrDat.Surname1,UsrDat.Surname2,Content); @@ -295,9 +293,6 @@ static void RSS_WriteExamAnnouncements (FILE *FileRSS,struct Course *Crs) Cfg_URL_SWAD_CGI,Crs->CrsCod); /* Write full content of the exam announcement */ - //strncpy (Content,row[4],Cns_MAX_BYTES_TEXT); - //Content[Cns_MAX_BYTES_TEXT] = '\0'; - //Str_InsertLinkInURLs (Content,Cns_MAX_BYTES_TEXT,40); fprintf (FileRSS,"<description><![CDATA[<p><em>Fecha examen: %s</em></p>]]></description>\n", row[2]); diff --git a/swad_account.c b/swad_account.c index f3a5319e..3fc09fea 100644 --- a/swad_account.c +++ b/swad_account.c @@ -559,9 +559,8 @@ bool Acc_CreateMyNewAccountAndLogIn (void) Gbl.Usrs.Me.UsrDat.IDs.List = NULL; /***** Set password to the password typed by the user *****/ - strncpy (Gbl.Usrs.Me.UsrDat.Password,NewEncryptedPassword, - Cry_LENGTH_ENCRYPTED_STR_SHA512_BASE64); - Gbl.Usrs.Me.UsrDat.Password[Cry_LENGTH_ENCRYPTED_STR_SHA512_BASE64] = '\0'; + Str_Copy (Gbl.Usrs.Me.UsrDat.Password,NewEncryptedPassword, + Cry_LENGTH_ENCRYPTED_STR_SHA512_BASE64); /***** User does not exist in the platform, so create him/her! *****/ Acc_CreateNewUsr (&Gbl.Usrs.Me.UsrDat, @@ -569,16 +568,14 @@ bool Acc_CreateMyNewAccountAndLogIn (void) /***** Save nickname *****/ Nck_UpdateMyNick (NewNicknameWithoutArroba); - strncpy (Gbl.Usrs.Me.UsrDat.Nickname,NewNicknameWithoutArroba, - Nck_MAX_LENGTH_NICKNAME_WITHOUT_ARROBA); - Gbl.Usrs.Me.UsrDat.Nickname[Nck_MAX_LENGTH_NICKNAME_WITHOUT_ARROBA] = '\0'; + Str_Copy (Gbl.Usrs.Me.UsrDat.Nickname,NewNicknameWithoutArroba, + Nck_MAX_LENGTH_NICKNAME_WITHOUT_ARROBA); /***** Save email *****/ if (Mai_UpdateEmailInDB (&Gbl.Usrs.Me.UsrDat,NewEmail)) { /* Email updated sucessfully */ - strncpy (Gbl.Usrs.Me.UsrDat.Email,NewEmail,Usr_MAX_BYTES_USR_EMAIL); - Gbl.Usrs.Me.UsrDat.Email[Usr_MAX_BYTES_USR_EMAIL] = '\0'; + Str_Copy (Gbl.Usrs.Me.UsrDat.Email,NewEmail,Usr_MAX_BYTES_USR_EMAIL); Gbl.Usrs.Me.UsrDat.EmailConfirmed = false; } @@ -615,8 +612,8 @@ static bool Acc_GetParamsNewAccount (char *NewNicknameWithoutArroba, Par_GetParToText ("NewNick",NewNicknameWithArroba,Nck_MAX_BYTES_NICKNAME_WITH_ARROBA); /* Remove arrobas at the beginning */ - strncpy (NewNicknameWithoutArroba,NewNicknameWithArroba,Nck_MAX_BYTES_NICKNAME_WITH_ARROBA); - NewNicknameWithoutArroba[Nck_MAX_BYTES_NICKNAME_WITH_ARROBA] = '\0'; + Str_Copy (NewNicknameWithoutArroba,NewNicknameWithArroba, + Nck_MAX_BYTES_NICKNAME_WITH_ARROBA); Str_RemoveLeadingArrobas (NewNicknameWithoutArroba); /* Create a new version of the nickname with arroba */ diff --git a/swad_action.c b/swad_action.c index 09ef7682..f6ebd116 100644 --- a/swad_action.c +++ b/swad_action.c @@ -4608,8 +4608,7 @@ char *Act_GetActionTextFromDB (long ActCod,char *Txt) { /***** Get text *****/ row = mysql_fetch_row (mysql_res); - strncpy (Txt,row[0],Act_MAX_LENGTH_ACTION_TXT); - Txt[Act_MAX_LENGTH_ACTION_TXT] = '\0'; + Str_Copy (Txt,row[0],Act_MAX_LENGTH_ACTION_TXT); } else // ActCod-Language not found on database Txt[0] = '\0'; diff --git a/swad_agenda.c b/swad_agenda.c index de24423a..ff217cd0 100644 --- a/swad_agenda.c +++ b/swad_agenda.c @@ -947,12 +947,10 @@ static void Agd_GetDataOfEventByCod (struct AgendaEvent *AgdEvent) Dat_PRESENT)); /* Get the event (row[7]) */ - strncpy (AgdEvent->Event,row[7],Agd_MAX_LENGTH_EVENT); - AgdEvent->Event[Agd_MAX_LENGTH_EVENT] = '\0'; + Str_Copy (AgdEvent->Event,row[7],Agd_MAX_LENGTH_EVENT); /* Get the event (row[8]) */ - strncpy (AgdEvent->Location,row[8],Agd_MAX_LENGTH_LOCATION); - AgdEvent->Location[Agd_MAX_LENGTH_LOCATION] = '\0'; + Str_Copy (AgdEvent->Location,row[8],Agd_MAX_LENGTH_LOCATION); } else { @@ -1009,8 +1007,7 @@ static void Agd_GetEventTxtFromDB (struct AgendaEvent *AgdEvent,char *Txt) { /* Get info text */ row = mysql_fetch_row (mysql_res); - strncpy (Txt,row[0],Cns_MAX_BYTES_TEXT); - Txt[Cns_MAX_BYTES_TEXT] = '\0'; + Str_Copy (Txt,row[0],Cns_MAX_BYTES_TEXT); } else Txt[0] = '\0'; diff --git a/swad_announcement.c b/swad_announcement.c index a6e3fdcf..61edefc6 100644 --- a/swad_announcement.c +++ b/swad_announcement.c @@ -25,8 +25,6 @@ /*********************************** Headers *********************************/ /*****************************************************************************/ -#include <string.h> // For strncpy... - #include "swad_announcement.h" #include "swad_database.h" #include "swad_global.h" @@ -151,12 +149,10 @@ void Ann_ShowAllAnnouncements (void) Lay_ShowErrorAndExit ("Error when reading roles of announcement."); /* Get the content (row[3]) */ - strncpy (Subject,row[3],Cns_MAX_BYTES_SUBJECT); - Content[Cns_MAX_BYTES_SUBJECT] = '\0'; + Str_Copy (Subject,row[3],Cns_MAX_BYTES_SUBJECT); /* Get the content (row[4]) and insert links */ - strncpy (Content,row[4],Cns_MAX_BYTES_TEXT); - Content[Cns_MAX_BYTES_TEXT] = '\0'; + Str_Copy (Content,row[4],Cns_MAX_BYTES_TEXT); Str_InsertLinks (Content,Cns_MAX_BYTES_TEXT,50); /* Show the announcement */ @@ -245,12 +241,10 @@ void Ann_ShowMyAnnouncementsNotMarkedAsSeen (void) Lay_ShowErrorAndExit ("Wrong code of announcement."); /* Get the content (row[1]) */ - strncpy (Subject,row[1],Cns_MAX_BYTES_SUBJECT); - Content[Cns_MAX_BYTES_SUBJECT] = '\0'; + Str_Copy (Subject,row[1],Cns_MAX_BYTES_SUBJECT); /* Get the content (row[2]) and insert links */ - strncpy (Content,row[2],Cns_MAX_BYTES_TEXT); - Content[Cns_MAX_BYTES_TEXT] = '\0'; + Str_Copy (Content,row[2],Cns_MAX_BYTES_TEXT); Str_InsertLinks (Content,Cns_MAX_BYTES_TEXT,50); /* Show the announcement */ diff --git a/swad_assignment.c b/swad_assignment.c index 1e2192ea..2ca78a08 100644 --- a/swad_assignment.c +++ b/swad_assignment.c @@ -452,12 +452,8 @@ static void Asg_WriteAsgAuthor (struct Assignment *Asg) "PHOTO15x20",Pho_ZOOM,false); /***** Write name *****/ - strncpy (FirstName,UsrDat.FirstName,Usr_MAX_BYTES_NAME); - UsrDat.FirstName[Usr_MAX_BYTES_NAME] = '\0'; - - strncpy (Surnames,UsrDat.Surname1,Usr_MAX_BYTES_SURNAMES); - Surnames[Usr_MAX_BYTES_SURNAMES] = '\0'; - + Str_Copy (FirstName,UsrDat.FirstName,Usr_MAX_BYTES_NAME); + Str_Copy (Surnames,UsrDat.Surname1,Usr_MAX_BYTES_SURNAMES); if (UsrDat.Surname2[0]) { strcat (Surnames," "); @@ -780,13 +776,10 @@ static void Asg_GetDataOfAssignment (struct Assignment *Asg,const char *Query) Asg->Open = (row[5][0] == '1'); /* Get the title of the assignment (row[6]) */ - strncpy (Asg->Title,row[6],Asg_MAX_LENGTH_ASSIGNMENT_TITLE); - Asg->Title[Asg_MAX_LENGTH_ASSIGNMENT_TITLE] = '\0'; + Str_Copy (Asg->Title,row[6],Asg_MAX_LENGTH_ASSIGNMENT_TITLE); /* Get the folder for the assignment files (row[7]) */ - strncpy (Asg->Folder,row[7],Asg_MAX_LENGTH_FOLDER); - Asg->Folder[Asg_MAX_LENGTH_FOLDER] = '\0'; - + Str_Copy (Asg->Folder,row[7],Asg_MAX_LENGTH_FOLDER); Asg->SendWork = (Asg->Folder[0] != '\0'); /* Can I do this assignment? */ @@ -855,8 +848,7 @@ static void Asg_GetAssignmentTxtFromDB (long AsgCod,char Txt[Cns_MAX_BYTES_TEXT { /* Get info text */ row = mysql_fetch_row (mysql_res); - strncpy (Txt,row[0],Cns_MAX_BYTES_TEXT); - Txt[Cns_MAX_BYTES_TEXT] = '\0'; + Str_Copy (Txt,row[0],Cns_MAX_BYTES_TEXT); } else Txt[0] = '\0'; @@ -895,8 +887,7 @@ void Asg_GetNotifAssignment (char SummaryStr[Cns_MAX_BYTES_TEXT + 1],char **Cont row = mysql_fetch_row (mysql_res); /***** Get summary *****/ - strncpy (SummaryStr,row[0],Cns_MAX_BYTES_TEXT); - SummaryStr[Cns_MAX_BYTES_TEXT] = '\0'; + Str_Copy (SummaryStr,row[0],Cns_MAX_BYTES_TEXT); if (MaxChars) Str_LimitLengthHTMLStr (SummaryStr,MaxChars); @@ -907,8 +898,7 @@ void Asg_GetNotifAssignment (char SummaryStr[Cns_MAX_BYTES_TEXT + 1],char **Cont if ((*ContentStr = (char *) malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL) Lay_ShowErrorAndExit ("Error allocating memory for notification content."); - strncpy (*ContentStr,row[1],Cns_MAX_BYTES_TEXT); - (*ContentStr)[Cns_MAX_BYTES_TEXT] = '\0'; + Str_Copy (*ContentStr,row[1],Cns_MAX_BYTES_TEXT); } } mysql_free_result (mysql_res); diff --git a/swad_attendance.c b/swad_attendance.c index 3b15dcfc..347b423a 100644 --- a/swad_attendance.c +++ b/swad_attendance.c @@ -492,12 +492,8 @@ static void Att_WriteAttEventAuthor (struct AttendanceEvent *Att) "PHOTO15x20",Pho_ZOOM,false); /***** Write name *****/ - strncpy (FirstName,UsrDat.FirstName,Usr_MAX_BYTES_NAME); - FirstName[Usr_MAX_BYTES_NAME] = '\0'; - - strncpy (Surnames,UsrDat.Surname1,Usr_MAX_BYTES_SURNAMES); - Surnames[Usr_MAX_BYTES_SURNAMES] = '\0'; - + Str_Copy (FirstName,UsrDat.FirstName,Usr_MAX_BYTES_NAME); + Str_Copy (Surnames,UsrDat.Surname1,Usr_MAX_BYTES_SURNAMES); if (UsrDat.Surname2[0]) { strcat (Surnames," "); @@ -789,8 +785,7 @@ bool Att_GetDataOfAttEventByCod (struct AttendanceEvent *Att) Att->CommentTchVisible = (row[7][0] == 'Y'); /* Get the title of the attendance event (row[8]) */ - strncpy (Att->Title,row[8],Att_MAX_LENGTH_ATTENDANCE_EVENT_TITLE); - Att->Title[Att_MAX_LENGTH_ATTENDANCE_EVENT_TITLE] = '\0'; + Str_Copy (Att->Title,row[8],Att_MAX_LENGTH_ATTENDANCE_EVENT_TITLE); } /***** Free structure that stores the query result *****/ @@ -861,8 +856,7 @@ static void Att_GetAttEventTxtFromDB (long AttCod,char Txt[Cns_MAX_BYTES_TEXT + row = mysql_fetch_row (mysql_res); /* Get info text */ - strncpy (Txt,row[0],Cns_MAX_BYTES_TEXT); - Txt[Cns_MAX_BYTES_TEXT] = '\0'; + Str_Copy (Txt,row[0],Cns_MAX_BYTES_TEXT); } else Txt[0] = '\0'; @@ -2518,12 +2512,10 @@ static bool Att_CheckIfUsrIsPresentInAttEventAndGetComments (long AttCod,long Us Present = (row[0][0] == 'Y'); /* Get student's comment (row[1]) */ - strncpy (CommentStd,row[1],Cns_MAX_BYTES_TEXT); - CommentStd[Cns_MAX_BYTES_TEXT] = '\0'; + Str_Copy (CommentStd,row[1],Cns_MAX_BYTES_TEXT); /* Get teacher's comment (row[2]) */ - strncpy (CommentTch,row[2],Cns_MAX_BYTES_TEXT); - CommentTch[Cns_MAX_BYTES_TEXT] = '\0'; + Str_Copy (CommentTch,row[2],Cns_MAX_BYTES_TEXT); } else // User is not present { diff --git a/swad_banner.c b/swad_banner.c index df917aa4..87338f76 100644 --- a/swad_banner.c +++ b/swad_banner.c @@ -204,20 +204,16 @@ static void Ban_GetListBanners (const char *Query) Ban->Hidden = (row[1][0] == 'Y'); /* Get the short name of the banner (row[2]) */ - strncpy (Ban->ShrtName,row[2],Ban_MAX_LENGTH_SHRT_NAME); - Ban->ShrtName[Ban_MAX_LENGTH_SHRT_NAME] = '\0'; + Str_Copy (Ban->ShrtName,row[2],Ban_MAX_LENGTH_SHRT_NAME); /* Get the full name of the banner (row[3]) */ - strncpy (Ban->FullName,row[3],Ban_MAX_LENGTH_FULL_NAME); - Ban->FullName[Ban_MAX_LENGTH_FULL_NAME] = '\0'; + Str_Copy (Ban->FullName,row[3],Ban_MAX_LENGTH_FULL_NAME); /* Get the image of the banner (row[4]) */ - strncpy (Ban->Img,row[4],Ban_MAX_LENGTH_IMAGE); - Ban->Img[Ban_MAX_LENGTH_IMAGE] = '\0'; + Str_Copy (Ban->Img,row[4],Ban_MAX_LENGTH_IMAGE); /* Get the URL of the banner (row[5]) */ - strncpy (Ban->WWW,row[5],Cns_MAX_LENGTH_WWW); - Ban->WWW[Cns_MAX_LENGTH_WWW] = '\0'; + Str_Copy (Ban->WWW,row[5],Cns_MAX_LENGTH_WWW); } } else @@ -261,20 +257,16 @@ void Ban_GetDataOfBannerByCod (struct Banner *Ban) Ban->Hidden = (row[0][0] == 'Y'); /* Get the short name of the banner (row[1]) */ - strncpy (Ban->ShrtName,row[1],Ban_MAX_LENGTH_SHRT_NAME); - Ban->ShrtName[Ban_MAX_LENGTH_SHRT_NAME] = '\0'; + Str_Copy (Ban->ShrtName,row[1],Ban_MAX_LENGTH_SHRT_NAME); /* Get the full name of the banner (row[2]) */ - strncpy (Ban->FullName,row[2],Ban_MAX_LENGTH_FULL_NAME); - Ban->FullName[Ban_MAX_LENGTH_FULL_NAME] = '\0'; + Str_Copy (Ban->FullName,row[2],Ban_MAX_LENGTH_FULL_NAME); /* Get the image of the banner (row[3]) */ - strncpy (Ban->Img,row[3],Ban_MAX_LENGTH_IMAGE); - Ban->Img[Ban_MAX_LENGTH_IMAGE] = '\0'; + Str_Copy (Ban->Img,row[3],Ban_MAX_LENGTH_IMAGE); /* Get the URL of the banner (row[4]) */ - strncpy (Ban->WWW,row[4],Cns_MAX_LENGTH_WWW); - Ban->WWW[Cns_MAX_LENGTH_WWW] = '\0'; + Str_Copy (Ban->WWW,row[4],Cns_MAX_LENGTH_WWW); } /***** Free structure that stores the query result *****/ @@ -624,8 +616,7 @@ static void Ban_RenameBanner (Cns_ShrtOrFullName_t ShrtOrFullName) } /***** Show the form again *****/ - strncpy (CurrentBanName,NewBanName,MaxLength); - CurrentBanName[MaxLength] = '\0'; + Str_Copy (CurrentBanName,NewBanName,MaxLength); Ban_EditBanners (); } @@ -683,8 +674,7 @@ void Ban_ChangeBannerImg (void) Lay_ShowAlert (Lay_WARNING,Txt_You_can_not_leave_the_image_empty); /***** Show the form again *****/ - strncpy (Ban->Img,NewImg,Ban_MAX_LENGTH_IMAGE); - Ban->Img[Ban_MAX_LENGTH_IMAGE] = '\0'; + Str_Copy (Ban->Img,NewImg,Ban_MAX_LENGTH_IMAGE); Ban_EditBanners (); } @@ -728,8 +718,7 @@ void Ban_ChangeBannerWWW (void) Lay_ShowAlert (Lay_WARNING,Txt_You_can_not_leave_the_web_address_empty); /***** Show the form again *****/ - strncpy (Ban->WWW,NewWWW,Cns_MAX_LENGTH_WWW); - Ban->WWW[Cns_MAX_LENGTH_WWW] = '\0'; + Str_Copy (Ban->WWW,NewWWW,Cns_MAX_LENGTH_WWW); Ban_EditBanners (); } diff --git a/swad_centre.c b/swad_centre.c index 90383d31..e98af968 100644 --- a/swad_centre.c +++ b/swad_centre.c @@ -1038,16 +1038,13 @@ void Ctr_GetListCentres (long InsCod) Ctr->RequesterUsrCod = Str_ConvertStrCodToLongCod (row[4]); /* Get the short name of the centre (row[5]) */ - strncpy (Ctr->ShrtName,row[5],Ctr_MAX_LENGTH_CENTRE_SHRT_NAME); - Ctr->ShrtName[Ctr_MAX_LENGTH_CENTRE_SHRT_NAME] = '\0'; + Str_Copy (Ctr->ShrtName,row[5],Ctr_MAX_LENGTH_CENTRE_SHRT_NAME); /* Get the full name of the centre (row[6]) */ - strncpy (Ctr->FullName,row[6],Ctr_MAX_LENGTH_CENTRE_FULL_NAME); - Ctr->FullName[Ctr_MAX_LENGTH_CENTRE_FULL_NAME] = '\0'; + Str_Copy (Ctr->FullName,row[6],Ctr_MAX_LENGTH_CENTRE_FULL_NAME); /* Get the URL of the centre (row[7]) */ - strncpy (Ctr->WWW,row[7],Cns_MAX_LENGTH_WWW); - Ctr->WWW[Cns_MAX_LENGTH_WWW] = '\0'; + Str_Copy (Ctr->WWW,row[7],Cns_MAX_LENGTH_WWW); /* Get number of users who claim to belong to this centre (row[8]) */ if (sscanf (row[8],"%u",&Ctr->NumUsrsWhoClaimToBelongToCtr) != 1) @@ -1136,16 +1133,13 @@ bool Ctr_GetDataOfCentreByCod (struct Centre *Ctr) Ctr->RequesterUsrCod = Str_ConvertStrCodToLongCod (row[3]); /* Get the short name of the centre (row[4]) */ - strncpy (Ctr->ShrtName,row[4],Ctr_MAX_LENGTH_CENTRE_SHRT_NAME); - Ctr->ShrtName[Ctr_MAX_LENGTH_CENTRE_SHRT_NAME] = '\0'; + Str_Copy (Ctr->ShrtName,row[4],Ctr_MAX_LENGTH_CENTRE_SHRT_NAME); /* Get the full name of the centre (row[5]) */ - strncpy (Ctr->FullName,row[5],Ctr_MAX_LENGTH_CENTRE_FULL_NAME); - Ctr->FullName[Ctr_MAX_LENGTH_CENTRE_FULL_NAME] = '\0'; + Str_Copy (Ctr->FullName,row[5],Ctr_MAX_LENGTH_CENTRE_FULL_NAME); /* Get the URL of the centre (row[6]) */ - strncpy (Ctr->WWW,row[6],Cns_MAX_LENGTH_WWW); - Ctr->WWW[Cns_MAX_LENGTH_WWW] = '\0'; + Str_Copy (Ctr->WWW,row[6],Cns_MAX_LENGTH_WWW); /* Get number of users who claim to belong to this centre (row[7]) */ if (sscanf (row[7],"%u",&Ctr->NumUsrsWhoClaimToBelongToCtr) != 1) @@ -1223,8 +1217,7 @@ void Ctr_GetShortNameOfCentreByCod (struct Centre *Ctr) /***** Get the short name of this centre *****/ row = mysql_fetch_row (mysql_res); - strncpy (Ctr->ShrtName,row[0],Ctr_MAX_LENGTH_CENTRE_SHRT_NAME); - Ctr->ShrtName[Ctr_MAX_LENGTH_CENTRE_SHRT_NAME] = '\0'; + Str_Copy (Ctr->ShrtName,row[0],Ctr_MAX_LENGTH_CENTRE_SHRT_NAME); } /***** Free structure that stores the query result *****/ @@ -1263,8 +1256,7 @@ static void Ctr_GetPhotoAttribution (long CtrCod,char **PhotoAttribution) if (((*PhotoAttribution) = (char *) malloc (Length + 1)) == NULL) Lay_ShowErrorAndExit ("Error allocating memory for photo attribution."); - strncpy (*PhotoAttribution,row[0],Length); - (*PhotoAttribution)[Length] = '\0'; + Str_Copy (*PhotoAttribution,row[0],Length); } } @@ -1518,8 +1510,7 @@ static void Ctr_ListCentresForEdition (void) } else { - strncpy (WWW,Ctr->WWW,Ctr_MAX_LENGTH_WWW_ON_SCREEN); - WWW[Ctr_MAX_LENGTH_WWW_ON_SCREEN] = '\0'; + Str_Copy (WWW,Ctr->WWW,Ctr_MAX_LENGTH_WWW_ON_SCREEN); fprintf (Gbl.F.Out,"<a href=\"%s\" target=\"_blank\" class=\"DAT\" title=\"%s\">%s", Ctr->WWW,Ctr->WWW,WWW); if (strlen (Ctr->WWW) > Ctr_MAX_LENGTH_WWW_ON_SCREEN) @@ -1959,8 +1950,7 @@ static void Ctr_RenameCentre (struct Centre *Ctr,Cns_ShrtOrFullName_t ShrtOrFull CurrentCtrName,NewCtrName); /* Change current centre name in order to display it properly */ - strncpy (CurrentCtrName,NewCtrName,MaxLength); - CurrentCtrName[MaxLength] = '\0'; + Str_Copy (CurrentCtrName,NewCtrName,MaxLength); } } else // The same name @@ -2013,8 +2003,7 @@ void Ctr_ChangeCtrWWW (void) /***** Update database changing old WWW by new WWW *****/ Ctr_UpdateCtrWWWDB (Ctr->CtrCod,NewWWW); - strncpy (Ctr->WWW,NewWWW,Cns_MAX_LENGTH_WWW); - Ctr->WWW[Cns_MAX_LENGTH_WWW] = '\0'; + Str_Copy (Ctr->WWW,NewWWW,Cns_MAX_LENGTH_WWW); /***** Write message to show the change made *****/ sprintf (Gbl.Message,Txt_The_new_web_address_is_X,NewWWW); @@ -2045,9 +2034,7 @@ void Ctr_ChangeCtrWWWInConfig (void) { /***** Update database changing old WWW by new WWW *****/ Ctr_UpdateCtrWWWDB (Gbl.CurrentCtr.Ctr.CtrCod,NewWWW); - - strncpy (Gbl.CurrentCtr.Ctr.WWW,NewWWW,Cns_MAX_LENGTH_WWW); - Gbl.CurrentCtr.Ctr.WWW[Cns_MAX_LENGTH_WWW] = '\0'; + Str_Copy (Gbl.CurrentCtr.Ctr.WWW,NewWWW,Cns_MAX_LENGTH_WWW); /***** Write message to show the change made *****/ sprintf (Gbl.Message,Txt_The_new_web_address_is_X,NewWWW); @@ -2252,7 +2239,7 @@ void Ctr_ReceivePhoto (void) char FileNameImgSrc[PATH_MAX+1]; char *PtrExtension; size_t LengthExtension; - char MIMEType[Brw_MAX_BYTES_MIME_TYPE+1]; + char MIMEType[Brw_MAX_BYTES_MIME_TYPE + 1]; char PathImgPriv[PATH_MAX+1]; char FileNameImgTmp[PATH_MAX+1]; // Full name (including path and .jpg) of the destination temporary file char FileNameImg[PATH_MAX+1]; // Full name (including path and .jpg) of the destination file diff --git a/swad_changelog.h b/swad_changelog.h index 320ccad3..82c3d250 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -183,19 +183,20 @@ // TODO: Draw future dates in attendance, surveys, assignments in blue? // TODO: Fix bug in generate a test: after entering a number of questions with empty tags and type of answers, number of questions is not remembered -// TODO: Fix big when editing a test question with images: when "Change image" is selected but no image is uploades, other images (for example in answers) are lost +// TODO: Fix bug when editing a test question with images: when "Change image" is selected but no image is uploades, other images (for example in answers) are lost /*****************************************************************************/ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 16.114.3 (2017-01-15)" +#define Log_PLATFORM_VERSION "SWAD 16.115 (2017-01-15)" #define CSS_FILE "swad16.111.5.css" #define JS_FILE "swad16.114.js" // Number of lines (includes comments but not blank lines) has been got with the following command: // nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*?.h sql/swad*.sql | tail -1 /* + Version 16.115: Jan 15, 2017 Code refactoring related to string copy. (211046 lines) Version 16.114.3: Jan 15, 2017 Fixed bug in chat. (211412 lines) Version 16.114.2: Jan 15, 2017 Fixed bug in file browser. (211412 lines) Version 16.114.1: Jan 15, 2017 Fixed bug in string concatenation. (211411 lines) diff --git a/swad_chat.c b/swad_chat.c index a95d1edc..0461266e 100644 --- a/swad_chat.c +++ b/swad_chat.c @@ -29,7 +29,6 @@ #include <stdbool.h> // For boolean type #include <stdio.h> // For sprintf #include <string.h> -#include <sys/param.h> // For MAX() #include "swad_chat.h" #include "swad_config.h" @@ -416,8 +415,7 @@ void Cht_OpenChatWindow (void) Usr_GetMyCourses (); /***** Build my user's name *****/ - strncpy (UsrName,Gbl.Usrs.Me.UsrDat.Surname1,Usr_MAX_BYTES_NAME); - UsrName[Usr_MAX_BYTES_NAME] = '\0'; + Str_Copy (UsrName,Gbl.Usrs.Me.UsrDat.Surname1,Usr_MAX_BYTES_NAME); if (Gbl.Usrs.Me.UsrDat.Surname2[0]) { Str_Concat (UsrName," ",Usr_MAX_BYTES_NAME); @@ -428,12 +426,8 @@ void Cht_OpenChatWindow (void) /***** Build the lists of available rooms *****/ sprintf (ListRoomCodes,"#%s",RoomCode); - - strncpy (ListRoomShortNames,RoomShortName,sizeof (ListRoomShortNames) - 1); - ListRoomShortNames[sizeof (ListRoomShortNames) - 1] = '\0'; - - strncpy (ListRoomFullNames ,RoomFullName,sizeof (ListRoomFullNames) - 1); - ListRoomFullNames[sizeof (ListRoomFullNames) - 1] = '\0'; + Str_Copy (ListRoomShortNames,RoomShortName,sizeof (ListRoomShortNames) - 1); + Str_Copy (ListRoomFullNames ,RoomFullName,sizeof (ListRoomFullNames) - 1); if (strcmp (RoomCode,"GBL_USR")) { diff --git a/swad_connected.c b/swad_connected.c index dafe0aee..536d4bad 100644 --- a/swad_connected.c +++ b/swad_connected.c @@ -464,49 +464,43 @@ static void Con_ShowConnectedUsrsBelongingToLocation (void) switch (Gbl.Scope.Current) { case Sco_SCOPE_SYS: // Show connected users in the whole platform - strncpy (LocationName,Cfg_PLATFORM_SHORT_NAME, - Deg_MAX_LENGTH_LOCATION_SHORT_NAME_SPEC_CHAR); - LocationName[Deg_MAX_LENGTH_LOCATION_SHORT_NAME_SPEC_CHAR] = '\0'; + Str_Copy (LocationName,Cfg_PLATFORM_SHORT_NAME, + Deg_MAX_LENGTH_LOCATION_SHORT_NAME_SPEC_CHAR); break; case Sco_SCOPE_CTY: // Show connected users in the current country if (Gbl.CurrentCty.Cty.CtyCod <= 0) // There is no country selected return; - strncpy (LocationName,Gbl.CurrentCty.Cty.Name[Gbl.Prefs.Language], - Deg_MAX_LENGTH_LOCATION_SHORT_NAME_SPEC_CHAR); - LocationName[Deg_MAX_LENGTH_LOCATION_SHORT_NAME_SPEC_CHAR] = '\0'; + Str_Copy (LocationName,Gbl.CurrentCty.Cty.Name[Gbl.Prefs.Language], + Deg_MAX_LENGTH_LOCATION_SHORT_NAME_SPEC_CHAR); break; case Sco_SCOPE_INS: // Show connected users in the current institution if (Gbl.CurrentIns.Ins.InsCod <= 0) // There is no institution selected return; - strncpy (LocationName,Gbl.CurrentIns.Ins.ShrtName, - Deg_MAX_LENGTH_LOCATION_SHORT_NAME_SPEC_CHAR); - LocationName[Deg_MAX_LENGTH_LOCATION_SHORT_NAME_SPEC_CHAR] = '\0'; + Str_Copy (LocationName,Gbl.CurrentIns.Ins.ShrtName, + Deg_MAX_LENGTH_LOCATION_SHORT_NAME_SPEC_CHAR); break; case Sco_SCOPE_CTR: // Show connected users in the current centre if (Gbl.CurrentCtr.Ctr.CtrCod <= 0) // There is no centre selected return; - strncpy (LocationName,Gbl.CurrentCtr.Ctr.ShrtName, - Deg_MAX_LENGTH_LOCATION_SHORT_NAME_SPEC_CHAR); - LocationName[Deg_MAX_LENGTH_LOCATION_SHORT_NAME_SPEC_CHAR] = '\0'; + Str_Copy (LocationName,Gbl.CurrentCtr.Ctr.ShrtName, + Deg_MAX_LENGTH_LOCATION_SHORT_NAME_SPEC_CHAR); break; case Sco_SCOPE_DEG: // Show connected users in the current degree if (Gbl.CurrentDeg.Deg.DegCod <= 0) // There is no degree selected return; - strncpy (LocationName,Gbl.CurrentDeg.Deg.ShrtName, - Deg_MAX_LENGTH_LOCATION_SHORT_NAME_SPEC_CHAR); - LocationName[Deg_MAX_LENGTH_LOCATION_SHORT_NAME_SPEC_CHAR] = '\0'; + Str_Copy (LocationName,Gbl.CurrentDeg.Deg.ShrtName, + Deg_MAX_LENGTH_LOCATION_SHORT_NAME_SPEC_CHAR); break; case Sco_SCOPE_CRS: // Show connected users in the current course if (Gbl.CurrentCrs.Crs.CrsCod <= 0) // There is no course selected return; - strncpy (LocationName,Gbl.CurrentCrs.Crs.ShrtName, - Deg_MAX_LENGTH_LOCATION_SHORT_NAME_SPEC_CHAR); - LocationName[Deg_MAX_LENGTH_LOCATION_SHORT_NAME_SPEC_CHAR] = '\0'; + Str_Copy (LocationName,Gbl.CurrentCrs.Crs.ShrtName, + Deg_MAX_LENGTH_LOCATION_SHORT_NAME_SPEC_CHAR); break; default: return; @@ -575,9 +569,8 @@ void Con_ShowConnectedUsrsBelongingToCurrentCrs (void) Act_LinkFormSubmitUnique (Txt_Connected_users,The_ClassConnected[Gbl.Prefs.Theme]); /* Write total number of connected users belonging to the current course */ - strncpy (CourseName,Gbl.CurrentCrs.Crs.ShrtName, - Crs_MAX_LENGTH_COURSE_SHRT_NAME); - CourseName[Crs_MAX_LENGTH_COURSE_SHRT_NAME] = '\0'; + Str_Copy (CourseName,Gbl.CurrentCrs.Crs.ShrtName, + Crs_MAX_LENGTH_COURSE_SHRT_NAME); Str_LimitLengthHTMLStr (CourseName,12); Con_GetNumConnectedUsrsWithARoleBelongingCurrentLocation (Rol_UNKNOWN,&Usrs); fprintf (Gbl.F.Out,"%u %s %s", diff --git a/swad_convert_briefcases.c b/swad_convert_briefcases.c index 7832b6d0..247248fb 100644 --- a/swad_convert_briefcases.c +++ b/swad_convert_briefcases.c @@ -46,9 +46,9 @@ int main (void) unsigned NumUsrs = 0; unsigned i; long UsrCod; - char UsrID[16+1]; - char OldPathUsr[PATH_MAX+1]; - char Command[1024+PATH_MAX*2]; + char UsrID[16 + 1]; + char OldPathUsr[PATH_MAX + 1]; + char Command[1024 + PATH_MAX * 2]; sprintf (Command,"mv %s/%s %s/%s_backup", PATH_SWAD_PRIVATE,FOLDER_USR, @@ -94,8 +94,7 @@ int main (void) if (sscanf (row[0],"%ld",&UsrCod) == 1) // UsrCod if (row[1]) { - strncpy (UsrID,row[1],16); // UsrID - UsrID[16] = '\0'; + Str_Copy (UsrID,row[1],16); // UsrID sprintf (OldPathUsr,"%s/%s_backup/%c/%s", PATH_SWAD_PRIVATE,FOLDER_USR,UsrID[strlen (UsrID)-1],UsrID); diff --git a/swad_convert_photos.c b/swad_convert_photos.c index 43837519..a39e1e78 100644 --- a/swad_convert_photos.c +++ b/swad_convert_photos.c @@ -3,6 +3,8 @@ // Author: Antonio Cañas Vargas // Compile with: gcc -Wall -O1 swad_convert_photos.c -o swad_convert_photos -lmysqlclient -L/usr/lib64/mysql +#include "swad_ID.h" + #include <mysql/mysql.h> #include <limits.h> #include <stdio.h> @@ -47,9 +49,9 @@ int main (void) unsigned NumPhotos = 0; unsigned i; long UsrCod; - char UsrID[16+1]; - char OldPathPhoto[PATH_MAX+1]; - char Command[1024+PATH_MAX*2]; + char UsrID[ID_MAX_LENGTH_USR_ID + 1]; + char OldPathPhoto[PATH_MAX + 1]; + char Command[1024 + PATH_MAX * 2]; sprintf (Command,"mv %s/%s %s/%s_backup", PATH_SWAD_PRIVATE,FOLDER_PHOTO, @@ -95,8 +97,7 @@ int main (void) if (sscanf (row[0],"%ld",&UsrCod) == 1) // UsrCod if (row[1]) { - strncpy (UsrID,row[1],16); // UsrID - UsrID[16] = '\0'; + Str_Copy (UsrID,row[1],ID_MAX_LENGTH_USR_ID); // UsrID sprintf (OldPathPhoto,"%s/%s_backup/%s_original.jpg", PATH_SWAD_PRIVATE,FOLDER_PHOTO,UsrID); if (CheckIfPathExists (OldPathPhoto)) diff --git a/swad_convert_works.c b/swad_convert_works.c index 9e18de20..96acd73d 100644 --- a/swad_convert_works.c +++ b/swad_convert_works.c @@ -3,6 +3,8 @@ // Author: Antonio Cañas Vargas // Compile with: gcc -Wall -O1 swad_convert_works.c -o swad_convert_works -lmysqlclient -L/usr/lib64/mysql +#include "swad_ID.h" + #include <mysql/mysql.h> #include <limits.h> #include <stdio.h> @@ -50,11 +52,11 @@ int main (void) unsigned NumUsr; long CrsCod; long UsrCod; - char UsrID[16+1]; - char OldPathUsrs[PATH_MAX+1]; - char OldPathUsr[PATH_MAX+1]; - char Path02u[PATH_MAX+1]; - char Command[1024+PATH_MAX*2]; + char UsrID[ID_MAX_LENGTH_USR_ID + 1]; + char OldPathUsrs[PATH_MAX + 1]; + char OldPathUsr[PATH_MAX + 1]; + char Path02u[PATH_MAX + 1]; + char Command[1024 + PATH_MAX * 2]; if (mysql_init (&mysql) == NULL) { @@ -124,8 +126,7 @@ int main (void) if (sscanf (row[0],"%ld",&UsrCod) == 1) // UsrCod if (row[1]) { - strncpy (UsrID,row[1],16); // UsrID - UsrID[16] = '\0'; + Str_Copy (UsrID,row[1],ID_MAX_LENGTH_USR_ID); // UsrID sprintf (OldPathUsr,"%s_backup/%s",OldPathUsrs,UsrID); if (CheckIfPathExists (OldPathUsr)) diff --git a/swad_country.c b/swad_country.c index b3a114a7..9acf1c51 100644 --- a/swad_country.c +++ b/swad_country.c @@ -773,8 +773,8 @@ void Cty_DrawCountryMapAndNameWithLink (struct Country *Cty,Act_Action_t Action, Cty_DrawCountryMap (Cty,ClassMap); /***** Write country name and end link *****/ - strncpy (CountryName,Cty->Name[Gbl.Prefs.Language],Cty_MAX_BYTES_COUNTRY_NAME); - CountryName[Cty_MAX_BYTES_COUNTRY_NAME] = '\0'; + Str_Copy (CountryName,Cty->Name[Gbl.Prefs.Language], + Cty_MAX_BYTES_COUNTRY_NAME); Str_LimitLengthHTMLStr (CountryName,30); fprintf (Gbl.F.Out," %s (%s)</a>", CountryName, @@ -1031,8 +1031,7 @@ void Cty_GetListCountries (Cty_GetExtraData_t GetExtraData) Lay_ShowErrorAndExit ("Wrong code of country."); /* Get Alpha-2 country code (row[1]) */ - strncpy (Cty->Alpha2,row[1],2); - Cty->Alpha2[2] = '\0'; + Str_Copy (Cty->Alpha2,row[1],2); switch (GetExtraData) { @@ -1049,9 +1048,8 @@ void Cty_GetListCountries (Cty_GetExtraData_t GetExtraData) Cty->NumUsrs = 0; /* Get the name of the country in current language */ - strncpy (Cty->Name[Gbl.Prefs.Language],row[2], - Cty_MAX_BYTES_COUNTRY_NAME); - Cty->Name[Gbl.Prefs.Language][Cty_MAX_BYTES_COUNTRY_NAME] = '\0'; + Str_Copy (Cty->Name[Gbl.Prefs.Language],row[2], + Cty_MAX_BYTES_COUNTRY_NAME); break; case Cty_GET_EXTRA_DATA: /* Get the name of the country in several languages */ @@ -1059,13 +1057,10 @@ void Cty_GetListCountries (Cty_GetExtraData_t GetExtraData) Lan <= Txt_NUM_LANGUAGES; Lan++) { - strncpy (Cty->Name[Lan],row[1 + Lan], - Cty_MAX_BYTES_COUNTRY_NAME); - Cty->Name[Lan][Cty_MAX_BYTES_COUNTRY_NAME] = '\0'; - - strncpy (Cty->WWW[Lan],row[1 + Txt_NUM_LANGUAGES + Lan], - Cns_MAX_LENGTH_WWW); - Cty->WWW[Lan][Cns_MAX_LENGTH_WWW] = '\0'; + Str_Copy (Cty->Name[Lan],row[1 + Lan], + Cty_MAX_BYTES_COUNTRY_NAME); + Str_Copy (Cty->WWW[Lan],row[1 + Txt_NUM_LANGUAGES + Lan], + Cns_MAX_LENGTH_WWW); } /* Get number of users who claim to belong to this country */ @@ -1230,11 +1225,8 @@ bool Cty_GetDataOfCountryByCod (struct Country *Cty,Cty_GetExtraData_t GetExtraD Lan <= Txt_NUM_LANGUAGES; Lan++) if (Lan == Gbl.Prefs.Language) - { - strncpy (Cty->Name[Lan],Txt_Another_country, - Cty_MAX_BYTES_COUNTRY_NAME); - Cty->Name[Lan][Cty_MAX_BYTES_COUNTRY_NAME] = '\0'; - } + Str_Copy (Cty->Name[Lan],Txt_Another_country, + Cty_MAX_BYTES_COUNTRY_NAME); else Cty->Name[Lan][0] = '\0'; return false; @@ -1298,19 +1290,15 @@ bool Cty_GetDataOfCountryByCod (struct Country *Cty,Cty_GetExtraData_t GetExtraD row = mysql_fetch_row (mysql_res); /* Get Alpha-2 country code (row[0]) */ - strncpy (Cty->Alpha2,row[0],2); - Cty->Alpha2[2] = '\0'; + Str_Copy (Cty->Alpha2,row[0],2); switch (GetExtraData) { case Cty_GET_BASIC_DATA: /* Get name and WWW of the country in current language */ - strncpy (Cty->Name[Gbl.Prefs.Language],row[1], - Cty_MAX_BYTES_COUNTRY_NAME); - Cty->Name[Gbl.Prefs.Language][Cty_MAX_BYTES_COUNTRY_NAME] = '\0'; - - strncpy (Cty->WWW[Gbl.Prefs.Language],row[2],Cns_MAX_LENGTH_WWW); - Cty->WWW[Gbl.Prefs.Language][Cns_MAX_LENGTH_WWW] = '\0'; + Str_Copy (Cty->Name[Gbl.Prefs.Language],row[1], + Cty_MAX_BYTES_COUNTRY_NAME); + Str_Copy (Cty->WWW[Gbl.Prefs.Language],row[2],Cns_MAX_LENGTH_WWW); break; case Cty_GET_EXTRA_DATA: /* Get name and WWW of the country in several languages */ @@ -1318,13 +1306,10 @@ bool Cty_GetDataOfCountryByCod (struct Country *Cty,Cty_GetExtraData_t GetExtraD Lan <= Txt_NUM_LANGUAGES; Lan++) { - strncpy (Cty->Name[Lan],row[Lan], - Cty_MAX_BYTES_COUNTRY_NAME); - Cty->Name[Lan][Cty_MAX_BYTES_COUNTRY_NAME] = '\0'; - - strncpy (Cty->WWW[Lan],row[Txt_NUM_LANGUAGES + Lan], - Cns_MAX_LENGTH_WWW); - Cty->WWW[Lan][Cns_MAX_LENGTH_WWW] = '\0'; + Str_Copy (Cty->Name[Lan],row[Lan], + Cty_MAX_BYTES_COUNTRY_NAME); + Str_Copy (Cty->WWW[Lan],row[Txt_NUM_LANGUAGES + Lan], + Cns_MAX_LENGTH_WWW); } /* Get number of users who claim to belong to this country */ @@ -1375,8 +1360,7 @@ void Cty_GetCountryName (long CtyCod,char CtyName[Cty_MAX_BYTES_COUNTRY_NAME+1]) row = mysql_fetch_row (mysql_res); /* Get the name of the country */ - strncpy (CtyName,row[0],Cty_MAX_BYTES_COUNTRY_NAME); - CtyName[Cty_MAX_BYTES_COUNTRY_NAME] = '\0'; + Str_Copy (CtyName,row[0],Cty_MAX_BYTES_COUNTRY_NAME); } /***** Free structure that stores the query result *****/ @@ -1414,8 +1398,7 @@ static void Cty_GetMapAttribution (long CtyCod,char **MapAttribution) if (((*MapAttribution) = (char *) malloc (Length + 1)) == NULL) Lay_ShowErrorAndExit ("Error allocating memory for map attribution."); - strncpy (*MapAttribution,row[0],Length); - (*MapAttribution)[Length] = '\0'; + Str_Copy (*MapAttribution,row[0],Length); } } @@ -1724,8 +1707,7 @@ void Cty_RenameCountry (void) } /***** Show the form again *****/ - strncpy (Cty->Name[Language],NewCtyName,Cty_MAX_BYTES_COUNTRY_NAME); - Cty->Name[Language][Cty_MAX_BYTES_COUNTRY_NAME] = '\0'; + Str_Copy (Cty->Name[Language],NewCtyName,Cty_MAX_BYTES_COUNTRY_NAME); Cty_EditCountries (); } @@ -1812,8 +1794,7 @@ void Cty_ChangeCtyWWW (void) Lay_ShowAlert (Lay_SUCCESS,Gbl.Message); /***** Show the form again *****/ - strncpy (Cty->WWW[Language],NewWWW,Cns_MAX_LENGTH_WWW); - Cty->WWW[Language][Cns_MAX_LENGTH_WWW] = '\0'; + Str_Copy (Cty->WWW[Language],NewWWW,Cns_MAX_LENGTH_WWW); Cty_EditCountries (); } diff --git a/swad_course.c b/swad_course.c index dec25469..10b1d00c 100644 --- a/swad_course.c +++ b/swad_course.c @@ -643,8 +643,7 @@ static void Crs_WriteListMyCoursesToSelectOne (void) Highlight ? ClassHighlight : ClassNormal,NULL); Log_DrawLogo (Sco_SCOPE_INS,Ins.InsCod,Ins.ShrtName,20,NULL,true); - strncpy (InsFullName,Ins.FullName,Ins_MAX_LENGTH_INSTIT_FULL_NAME); - InsFullName[Ins_MAX_LENGTH_INSTIT_FULL_NAME] = '\0'; + Str_Copy (InsFullName,Ins.FullName,Ins_MAX_LENGTH_INSTIT_FULL_NAME); Str_LimitLengthHTMLStr (InsFullName,Crs_MAX_BYTES_TXT_LINK); fprintf (Gbl.F.Out," %s</a>",InsFullName); Act_FormEnd (); @@ -679,8 +678,7 @@ static void Crs_WriteListMyCoursesToSelectOne (void) Highlight ? ClassHighlight : ClassNormal,NULL); Log_DrawLogo (Sco_SCOPE_CTR,Ctr.CtrCod,Ctr.ShrtName,20,NULL,true); - strncpy (CtrFullName,Ctr.FullName,Ctr_MAX_LENGTH_CENTRE_FULL_NAME); - CtrFullName[Ctr_MAX_LENGTH_CENTRE_FULL_NAME] = '\0'; + Str_Copy (CtrFullName,Ctr.FullName,Ctr_MAX_LENGTH_CENTRE_FULL_NAME); Str_LimitLengthHTMLStr (CtrFullName,Crs_MAX_BYTES_TXT_LINK); fprintf (Gbl.F.Out," %s</a>",CtrFullName); Act_FormEnd (); @@ -715,8 +713,7 @@ static void Crs_WriteListMyCoursesToSelectOne (void) Highlight ? ClassHighlight : ClassNormal,NULL); Log_DrawLogo (Sco_SCOPE_DEG,Deg.DegCod,Deg.ShrtName,20,NULL,true); - strncpy (DegFullName,Deg.FullName,Deg_MAX_LENGTH_DEGREE_FULL_NAME); - DegFullName[Deg_MAX_LENGTH_DEGREE_FULL_NAME] = '\0'; + Str_Copy (DegFullName,Deg.FullName,Deg_MAX_LENGTH_DEGREE_FULL_NAME); Str_LimitLengthHTMLStr (DegFullName,Crs_MAX_BYTES_TXT_LINK); fprintf (Gbl.F.Out," %s</a>",DegFullName); Act_FormEnd (); @@ -756,8 +753,8 @@ static void Crs_WriteListMyCoursesToSelectOne (void) Gbl.Prefs.IconsURL, Crs.ShrtName, Crs.FullName); - strncpy (CrsFullName,Crs.FullName,Crs_MAX_LENGTH_COURSE_FULL_NAME); - CrsFullName[Crs_MAX_LENGTH_COURSE_FULL_NAME] = '\0'; + Str_Copy (CrsFullName,Crs.FullName, + Crs_MAX_LENGTH_COURSE_FULL_NAME); Str_LimitLengthHTMLStr (CrsFullName,Crs_MAX_BYTES_TXT_LINK); fprintf (Gbl.F.Out," %s</a>",CrsFullName); Act_FormEnd (); @@ -2106,8 +2103,7 @@ static void Crs_GetDataOfCourseFromRow (struct Course *Crs,MYSQL_ROW row) Crs->Year = Deg_ConvStrToYear (row[2]); /***** Get institutional course code (row[3]) *****/ - strncpy (Crs->InstitutionalCrsCod,row[3],Crs_LENGTH_INSTITUTIONAL_CRS_COD); - Crs->InstitutionalCrsCod[Crs_LENGTH_INSTITUTIONAL_CRS_COD] = '\0'; + Str_Copy (Crs->InstitutionalCrsCod,row[3],Crs_LENGTH_INSTITUTIONAL_CRS_COD); /***** Get course status (row[4]) *****/ if (sscanf (row[4],"%u",&(Crs->Status)) != 1) @@ -2117,12 +2113,10 @@ static void Crs_GetDataOfCourseFromRow (struct Course *Crs,MYSQL_ROW row) Crs->RequesterUsrCod = Str_ConvertStrCodToLongCod (row[5]); /***** Get the short name of the course (row[6]) *****/ - strncpy (Crs->ShrtName,row[6],Crs_MAX_LENGTH_COURSE_SHRT_NAME); - Crs->ShrtName[Crs_MAX_LENGTH_COURSE_SHRT_NAME] = '\0'; + Str_Copy (Crs->ShrtName,row[6],Crs_MAX_LENGTH_COURSE_SHRT_NAME); /***** Get the full name of the course (row[7]) *****/ - strncpy (Crs->FullName,row[7],Crs_MAX_LENGTH_COURSE_FULL_NAME); - Crs->FullName[Crs_MAX_LENGTH_COURSE_FULL_NAME] = '\0'; + Str_Copy (Crs->FullName,row[7],Crs_MAX_LENGTH_COURSE_FULL_NAME); /***** Get number of teachers *****/ Crs->NumTchs = Usr_GetNumUsrsInCrs (Rol_TEACHER,Crs->CrsCod); @@ -2161,11 +2155,8 @@ static void Crs_GetShortNamesByCod (long CrsCod, /***** Get the short name of this course *****/ row = mysql_fetch_row (mysql_res); - strncpy (CrsShortName,row[0],Crs_MAX_LENGTH_COURSE_SHRT_NAME); - CrsShortName[Crs_MAX_LENGTH_COURSE_SHRT_NAME] = '\0'; - - strncpy (DegShortName,row[1],Deg_MAX_LENGTH_DEGREE_SHRT_NAME); - DegShortName[Deg_MAX_LENGTH_DEGREE_SHRT_NAME] = '\0'; + Str_Copy (CrsShortName,row[0],Crs_MAX_LENGTH_COURSE_SHRT_NAME); + Str_Copy (DegShortName,row[1],Deg_MAX_LENGTH_DEGREE_SHRT_NAME); } /***** Free structure that stores the query result *****/ @@ -2390,9 +2381,8 @@ void Crs_ChangeInsCrsCod (void) else { Gbl.Error = true; - strncpy (Gbl.Message,Txt_You_dont_have_permission_to_edit_this_course, - Lay_MAX_BYTES_ALERT); - Gbl.Message[Lay_MAX_BYTES_ALERT] = '\0'; + Str_Copy (Gbl.Message,Txt_You_dont_have_permission_to_edit_this_course, + Lay_MAX_BYTES_ALERT); } } @@ -2598,9 +2588,8 @@ void Crs_ChangeCrsYear (void) else { Gbl.Error = true; - strncpy (Gbl.Message,Txt_You_dont_have_permission_to_edit_this_course, - Lay_MAX_BYTES_ALERT); - Gbl.Message[Lay_MAX_BYTES_ALERT] = '\0'; + Str_Copy (Gbl.Message,Txt_You_dont_have_permission_to_edit_this_course, + Lay_MAX_BYTES_ALERT); } } @@ -2635,8 +2624,8 @@ void Crs_UpdateInstitutionalCrsCod (struct Course *Crs,const char *NewInstitutio DB_QueryUPDATE (Query,"can not update the institutional code of the current course"); /***** Copy institutional course code *****/ - strncpy (Crs->InstitutionalCrsCod,NewInstitutionalCrsCod,Crs_LENGTH_INSTITUTIONAL_CRS_COD); - Crs->InstitutionalCrsCod[Crs_LENGTH_INSTITUTIONAL_CRS_COD] = '\0'; + Str_Copy (Crs->InstitutionalCrsCod,NewInstitutionalCrsCod, + Crs_LENGTH_INSTITUTIONAL_CRS_COD); } /*****************************************************************************/ @@ -2744,8 +2733,7 @@ static void Crs_RenameCourse (struct Course *Crs,Cns_ShrtOrFullName_t ShrtOrFull CurrentCrsName,NewCrsName); /* Change current course name in order to display it properly */ - strncpy (CurrentCrsName,NewCrsName,MaxLength); - CurrentCrsName[MaxLength] = '\0'; + Str_Copy (CurrentCrsName,NewCrsName,MaxLength); } } else // The same name @@ -2756,9 +2744,8 @@ static void Crs_RenameCourse (struct Course *Crs,Cns_ShrtOrFullName_t ShrtOrFull else { Gbl.Error = true; - strncpy (Gbl.Message,Txt_You_dont_have_permission_to_edit_this_course, - Lay_MAX_BYTES_ALERT); - Gbl.Message[Lay_MAX_BYTES_ALERT] = '\0'; + Str_Copy (Gbl.Message,Txt_You_dont_have_permission_to_edit_this_course, + Lay_MAX_BYTES_ALERT); } } diff --git a/swad_course.h b/swad_course.h index 34aca750..0c4bc812 100644 --- a/swad_course.h +++ b/swad_course.h @@ -76,13 +76,13 @@ typedef enum struct Course { long CrsCod; - char InstitutionalCrsCod[Crs_LENGTH_INSTITUTIONAL_CRS_COD+1]; // Institutional code of the course + char InstitutionalCrsCod[Crs_LENGTH_INSTITUTIONAL_CRS_COD + 1]; // Institutional code of the course long DegCod; unsigned Year; // Year: 0 (optatives), 1, 2, 3... Crs_Status_t Status; // Course status long RequesterUsrCod; // User code of the person who requested the creation of this course - char ShrtName[Crs_MAX_LENGTH_COURSE_SHRT_NAME+1]; // Short name of course - char FullName[Crs_MAX_LENGTH_COURSE_FULL_NAME+1]; // Full name of course + char ShrtName[Crs_MAX_LENGTH_COURSE_SHRT_NAME + 1]; // Short name of course + char FullName[Crs_MAX_LENGTH_COURSE_FULL_NAME + 1]; // Full name of course unsigned NumUsrs; // Number of users (students + teachers) unsigned NumTchs; // Number of teachers unsigned NumStds; // Number of students diff --git a/swad_date.c b/swad_date.c index 0a67a77e..fa53874f 100644 --- a/swad_date.c +++ b/swad_date.c @@ -142,8 +142,7 @@ bool Dat_GetDateFromYYYYMMDD (struct Date *Date,const char *YYYYMMDD) { if (sscanf (YYYYMMDD,"%04u%02u%02u",&(Date->Year),&(Date->Month),&(Date->Day)) == 3) { - strncpy (Date->YYYYMMDD,YYYYMMDD,Dat_LENGTH_YYYYMMDD); - Date->YYYYMMDD[Dat_LENGTH_YYYYMMDD] = '\0'; + Str_Copy (Date->YYYYMMDD,YYYYMMDD,Dat_LENGTH_YYYYMMDD); return true; } else @@ -1264,8 +1263,7 @@ void Dat_AssignDate (struct Date *DateDst,struct Date *DateSrc) DateDst->Month = DateSrc->Month; DateDst->Day = DateSrc->Day; DateDst->Week = DateSrc->Week; - strncpy (DateDst->YYYYMMDD,DateSrc->YYYYMMDD,Dat_LENGTH_YYYYMMDD); - DateDst->YYYYMMDD[Dat_LENGTH_YYYYMMDD] = '\0'; + Str_Copy (DateDst->YYYYMMDD,DateSrc->YYYYMMDD,Dat_LENGTH_YYYYMMDD); } /*****************************************************************************/ diff --git a/swad_degree.c b/swad_degree.c index 2529a719..6d282112 100644 --- a/swad_degree.c +++ b/swad_degree.c @@ -822,8 +822,7 @@ static void Deg_ListDegreesForEdition (void) } else { - strncpy (WWW,Deg->WWW,Deg_MAX_LENGTH_WWW_ON_SCREEN); - WWW[Deg_MAX_LENGTH_WWW_ON_SCREEN] = '\0'; + Str_Copy (WWW,Deg->WWW,Deg_MAX_LENGTH_WWW_ON_SCREEN); fprintf (Gbl.F.Out,"<a href=\"%s\" target=\"_blank\"" " class=\"DAT\" title=\"%s\">%s", Deg->WWW,Deg->WWW,WWW); @@ -1738,16 +1737,13 @@ static void Deg_GetDataOfDegreeFromRow (struct Degree *Deg,MYSQL_ROW row) Deg->RequesterUsrCod = Str_ConvertStrCodToLongCod (row[4]); /***** Get degree short name (row[5]) *****/ - strncpy (Deg->ShrtName,row[5],Deg_MAX_LENGTH_DEGREE_SHRT_NAME); - Deg->ShrtName[Deg_MAX_LENGTH_DEGREE_SHRT_NAME] = '\0'; + Str_Copy (Deg->ShrtName,row[5],Deg_MAX_LENGTH_DEGREE_SHRT_NAME); /***** Get degree full name (row[6]) *****/ - strncpy (Deg->FullName,row[6],Deg_MAX_LENGTH_DEGREE_FULL_NAME); - Deg->FullName[Deg_MAX_LENGTH_DEGREE_FULL_NAME] = '\0'; + Str_Copy (Deg->FullName,row[6],Deg_MAX_LENGTH_DEGREE_FULL_NAME); /***** Get WWW (row[7]) *****/ - strncpy (Deg->WWW,row[7],Cns_MAX_LENGTH_WWW); - Deg->WWW[Cns_MAX_LENGTH_WWW] = '\0'; + Str_Copy (Deg->WWW,row[7],Cns_MAX_LENGTH_WWW); } /*****************************************************************************/ @@ -1772,8 +1768,7 @@ void Deg_GetShortNameOfDegreeByCod (struct Degree *Deg) /***** Get the short name of this degree *****/ row = mysql_fetch_row (mysql_res); - strncpy (Deg->ShrtName,row[0],Deg_MAX_LENGTH_DEGREE_SHRT_NAME); - Deg->ShrtName[Deg_MAX_LENGTH_DEGREE_SHRT_NAME] = '\0'; + Str_Copy (Deg->ShrtName,row[0],Deg_MAX_LENGTH_DEGREE_SHRT_NAME); } /***** Free structure that stores the query result *****/ @@ -2011,8 +2006,7 @@ static void Deg_RenameDegree (struct Degree *Deg,Cns_ShrtOrFullName_t ShrtOrFull CurrentDegName,NewDegName); /* Change current degree name in order to display it properly */ - strncpy (CurrentDegName,NewDegName,MaxLength); - CurrentDegName[MaxLength] = '\0'; + Str_Copy (CurrentDegName,NewDegName,MaxLength); } } else // The same name @@ -2143,8 +2137,7 @@ void Deg_ChangeDegWWW (void) { /***** Update the table changing old WWW by new WWW *****/ Deg_UpdateDegWWWDB (Deg->DegCod,NewWWW); - strncpy (Deg->WWW,NewWWW,Cns_MAX_LENGTH_WWW); - Deg->WWW[Cns_MAX_LENGTH_WWW] = '\0'; + Str_Copy (Deg->WWW,NewWWW,Cns_MAX_LENGTH_WWW); /***** Write message to show the change made *****/ sprintf (Gbl.Message,Txt_The_new_web_address_is_X,NewWWW); @@ -2175,8 +2168,7 @@ void Deg_ChangeDegWWWInConfig (void) { /***** Update the table changing old WWW by new WWW *****/ Deg_UpdateDegWWWDB (Gbl.CurrentDeg.Deg.DegCod,NewWWW); - strncpy (Gbl.CurrentDeg.Deg.WWW,NewWWW,Cns_MAX_LENGTH_WWW); - Gbl.CurrentDeg.Deg.WWW[Cns_MAX_LENGTH_WWW] = '\0'; + Str_Copy (Gbl.CurrentDeg.Deg.WWW,NewWWW,Cns_MAX_LENGTH_WWW); /***** Write message to show the change made *****/ sprintf (Gbl.Message,Txt_The_new_web_address_is_X,NewWWW); diff --git a/swad_degree_type.c b/swad_degree_type.c index 1eba6465..71e173ba 100644 --- a/swad_degree_type.c +++ b/swad_degree_type.c @@ -481,8 +481,8 @@ void DT_GetListDegreeTypes (void) Lay_ShowErrorAndExit ("Wrong code of type of degree."); /* Get degree type name (row[1]) */ - strncpy (Gbl.Degs.DegTypes.Lst[NumRow].DegTypName,row[1],Deg_MAX_LENGTH_DEGREE_TYPE_NAME); - Gbl.Degs.DegTypes.Lst[NumRow].DegTypName[Deg_MAX_LENGTH_DEGREE_TYPE_NAME] = '\0'; + Str_Copy (Gbl.Degs.DegTypes.Lst[NumRow].DegTypName,row[1], + Deg_MAX_LENGTH_DEGREE_TYPE_NAME); /* Number of degrees of this type (row[2]) */ if (sscanf (row[2],"%u",&Gbl.Degs.DegTypes.Lst[NumRow].NumDegs) != 1) @@ -650,8 +650,7 @@ bool DT_GetDataOfDegreeTypeByCod (struct DegreeType *DegTyp) row = mysql_fetch_row (mysql_res); /* Get the name of the degree type (row[0]) */ - strncpy (DegTyp->DegTypName,row[0],Deg_MAX_LENGTH_DEGREE_TYPE_NAME); - DegTyp->DegTypName[Deg_MAX_LENGTH_DEGREE_TYPE_NAME] = '\0'; + Str_Copy (DegTyp->DegTypName,row[0],Deg_MAX_LENGTH_DEGREE_TYPE_NAME); /* Count number of degrees of this type */ DegTyp->NumDegs = DT_CountNumDegsOfType (DegTyp->DegTypCod); @@ -786,8 +785,7 @@ void DT_RenameDegreeType (void) } /***** Show the form again *****/ - strncpy (DegTyp->DegTypName,NewNameDegTyp,Deg_MAX_LENGTH_DEGREE_TYPE_NAME); - DegTyp->DegTypName[Deg_MAX_LENGTH_DEGREE_TYPE_NAME] = '\0'; + Str_Copy (DegTyp->DegTypName,NewNameDegTyp,Deg_MAX_LENGTH_DEGREE_TYPE_NAME); DT_ReqEditDegreeTypes (); } diff --git a/swad_department.c b/swad_department.c index ae4611d0..57a14dd2 100644 --- a/swad_department.c +++ b/swad_department.c @@ -351,16 +351,13 @@ void Dpt_GetListDepartments (long InsCod) Lay_ShowErrorAndExit ("Wrong code of institution."); /* Get the short name of the department (row[2]) */ - strncpy (Dpt->ShrtName,row[2],MAX_LENGTH_DEPARTMENT_SHRT_NAME); - Dpt->ShrtName[MAX_LENGTH_DEPARTMENT_SHRT_NAME] = '\0'; + Str_Copy (Dpt->ShrtName,row[2],MAX_LENGTH_DEPARTMENT_SHRT_NAME); /* Get the full name of the department (row[3]) */ - strncpy (Dpt->FullName,row[3],MAX_LENGTH_DEPARTMENT_FULL_NAME); - Dpt->FullName[MAX_LENGTH_DEPARTMENT_FULL_NAME] = '\0'; + Str_Copy (Dpt->FullName,row[3],MAX_LENGTH_DEPARTMENT_FULL_NAME); /* Get the URL of the department (row[4]) */ - strncpy (Dpt->WWW,row[4],Cns_MAX_LENGTH_WWW); - Dpt->WWW[Cns_MAX_LENGTH_WWW] = '\0'; + Str_Copy (Dpt->WWW,row[4],Cns_MAX_LENGTH_WWW); /* Get number of teachers in this department (row[5]) */ if (sscanf (row[5],"%u",&Dpt->NumTchs) != 1) @@ -394,11 +391,10 @@ void Dpt_GetDataOfDepartmentByCod (struct Department *Dpt) /***** Check if department code is correct *****/ if (Dpt->DptCod == 0) { - strncpy (Dpt->ShrtName,Txt_Another_department,MAX_LENGTH_DEPARTMENT_SHRT_NAME); - Dpt->ShrtName[MAX_LENGTH_DEPARTMENT_SHRT_NAME] = '\0'; - - strncpy (Dpt->FullName,Txt_Another_department,MAX_LENGTH_DEPARTMENT_FULL_NAME); - Dpt->FullName[MAX_LENGTH_DEPARTMENT_FULL_NAME] = '\0'; + Str_Copy (Dpt->ShrtName,Txt_Another_department, + MAX_LENGTH_DEPARTMENT_SHRT_NAME); + Str_Copy (Dpt->FullName,Txt_Another_department, + MAX_LENGTH_DEPARTMENT_FULL_NAME); } else if (Dpt->DptCod > 0) { @@ -430,16 +426,13 @@ void Dpt_GetDataOfDepartmentByCod (struct Department *Dpt) Dpt->InsCod = Str_ConvertStrCodToLongCod (row[0]); /* Get the short name of the department (row[1]) */ - strncpy (Dpt->ShrtName,row[1],MAX_LENGTH_DEPARTMENT_SHRT_NAME); - Dpt->ShrtName[MAX_LENGTH_DEPARTMENT_SHRT_NAME] = '\0'; + Str_Copy (Dpt->ShrtName,row[1],MAX_LENGTH_DEPARTMENT_SHRT_NAME); /* Get the full name of the department (row[2]) */ - strncpy (Dpt->FullName,row[2],MAX_LENGTH_DEPARTMENT_FULL_NAME); - Dpt->FullName[MAX_LENGTH_DEPARTMENT_FULL_NAME] = '\0'; + Str_Copy (Dpt->FullName,row[2],MAX_LENGTH_DEPARTMENT_FULL_NAME); /* Get the URL of the department (row[3]) */ - strncpy (Dpt->WWW,row[3],Cns_MAX_LENGTH_WWW); - Dpt->WWW[Cns_MAX_LENGTH_WWW] = '\0'; + Str_Copy (Dpt->WWW,row[3],Cns_MAX_LENGTH_WWW); /* Get number of teachers in this department (row[4]) */ if (sscanf (row[4],"%u",&Dpt->NumTchs) != 1) @@ -798,8 +791,7 @@ static void Dpt_RenameDepartment (Cns_ShrtOrFullName_t ShrtOrFullName) } /***** Show the form again *****/ - strncpy (CurrentDptName,NewDptName,MaxLength); - CurrentDptName[MaxLength] = '\0'; + Str_Copy (CurrentDptName,NewDptName,MaxLength); Dpt_EditDepartments (); } @@ -860,8 +852,7 @@ void Dpt_ChangeDptWWW (void) } /***** Show the form again *****/ - strncpy (Dpt->WWW,NewWWW,Cns_MAX_LENGTH_WWW); - Dpt->WWW[Cns_MAX_LENGTH_WWW] = '\0'; + Str_Copy (Dpt->WWW,NewWWW,Cns_MAX_LENGTH_WWW); Dpt_EditDepartments (); } diff --git a/swad_enrollment.c b/swad_enrollment.c index e342dd6c..c43626d9 100644 --- a/swad_enrollment.c +++ b/swad_enrollment.c @@ -396,8 +396,8 @@ void Enr_GetNotifEnrollment (char SummaryStr[Cns_MAX_BYTES_TEXT + 1], /* Role (row[0]) */ Role = Rol_ConvertUnsignedStrToRole (row[0]); - strncpy (SummaryStr,Txt_ROLES_SINGUL_Abc[Role][UsrDat.Sex],Cns_MAX_BYTES_TEXT); - SummaryStr[Cns_MAX_BYTES_TEXT] = '\0'; + Str_Copy (SummaryStr,Txt_ROLES_SINGUL_Abc[Role][UsrDat.Sex], + Cns_MAX_BYTES_TEXT); if (MaxChars) Str_LimitLengthHTMLStr (SummaryStr,MaxChars); @@ -1442,10 +1442,8 @@ static void Enr_ReceiveFormUsrsCrs (Rol_Role_t Role) { /***** Find users for this user's ID *****/ ID_ReallocateListIDs (&UsrDat,1); // Only one user's ID - - strncpy (UsrDat.IDs.List[0].ID,UsrDat.UsrIDNickOrEmail,ID_MAX_LENGTH_USR_ID); - UsrDat.IDs.List[0].ID[ID_MAX_LENGTH_USR_ID] = '\0'; - + Str_Copy (UsrDat.IDs.List[0].ID,UsrDat.UsrIDNickOrEmail, + ID_MAX_LENGTH_USR_ID); Str_ConvertToUpperText (UsrDat.IDs.List[0].ID); ID_GetListUsrCodsFromUsrID (&UsrDat,NULL,&ListUsrCods,false); } @@ -1568,10 +1566,8 @@ static void Enr_ReceiveFormUsrsCrs (Rol_Role_t Role) /* Find users for this user's ID */ ID_ReallocateListIDs (&UsrDat,1); // Only one user's ID - - strncpy (UsrDat.IDs.List[0].ID,UsrDat.UsrIDNickOrEmail,ID_MAX_LENGTH_USR_ID); - UsrDat.IDs.List[0].ID[ID_MAX_LENGTH_USR_ID] = '\0'; - + Str_Copy (UsrDat.IDs.List[0].ID,UsrDat.UsrIDNickOrEmail, + ID_MAX_LENGTH_USR_ID); Str_ConvertToUpperText (UsrDat.IDs.List[0].ID); ID_GetListUsrCodsFromUsrID (&UsrDat,NULL,&ListUsrCods,false); } @@ -1973,8 +1969,8 @@ void Enr_GetNotifEnrollmentRequest (char SummaryStr[Cns_MAX_BYTES_TEXT + 1],char /* Role (row[1]) */ DesiredRole = Rol_ConvertUnsignedStrToRole (row[1]); - strncpy (SummaryStr,Txt_ROLES_SINGUL_Abc[DesiredRole][UsrDat.Sex],Cns_MAX_BYTES_TEXT); - SummaryStr[Cns_MAX_BYTES_TEXT] = '\0'; + Str_Copy (SummaryStr,Txt_ROLES_SINGUL_Abc[DesiredRole][UsrDat.Sex], + Cns_MAX_BYTES_TEXT); if (MaxChars) Str_LimitLengthHTMLStr (SummaryStr,MaxChars); diff --git a/swad_exam.c b/swad_exam.c index 0385ba11..2e2c1daa 100644 --- a/swad_exam.c +++ b/swad_exam.c @@ -97,9 +97,9 @@ void Exa_PutFrmEditAExamAnnouncement (void) Exa_AllocMemExamAnnouncement (); /***** Get the code of the exam announcement *****/ - Gbl.ExamAnnouncements.ExaDat.ExaCod = Exa_GetParamsExamAnnouncement (); + Gbl.ExamAnns.ExaDat.ExaCod = Exa_GetParamsExamAnnouncement (); - if (Gbl.ExamAnnouncements.ExaDat.ExaCod > 0) // -1 indicates that this is a new exam announcement + if (Gbl.ExamAnns.ExaDat.ExaCod > 0) // -1 indicates that this is a new exam announcement /***** Read exam announcement from the database *****/ Exa_GetDataExamAnnouncementFromDB (); @@ -123,83 +123,80 @@ static long Exa_GetParamsExamAnnouncement (void) ExaCod = Exa_GetParamExaCod (); /***** Get the name of the course (it is allowed to be different from the official name of the course) *****/ - Par_GetParToText ("CrsName",Gbl.ExamAnnouncements.ExaDat.CrsFullName,Cns_MAX_BYTES_STRING); + Par_GetParToText ("CrsName",Gbl.ExamAnns.ExaDat.CrsFullName,Cns_MAX_BYTES_STRING); // If the parameter is not present or is empty, initialize the string to the full name of the current course - if (!Gbl.ExamAnnouncements.ExaDat.CrsFullName[0]) - { - strncpy (Gbl.ExamAnnouncements.ExaDat.CrsFullName,Gbl.CurrentCrs.Crs.FullName, - Crs_MAX_LENGTH_COURSE_FULL_NAME); - Gbl.ExamAnnouncements.ExaDat.CrsFullName[Crs_MAX_LENGTH_COURSE_FULL_NAME] = '\0'; - } + if (!Gbl.ExamAnns.ExaDat.CrsFullName[0]) + Str_Copy (Gbl.ExamAnns.ExaDat.CrsFullName,Gbl.CurrentCrs.Crs.FullName, + Crs_MAX_LENGTH_COURSE_FULL_NAME); /***** Get the year *****/ Par_GetParToText ("Year",UnsignedStr,10); - if (sscanf (UnsignedStr,"%u",&Gbl.ExamAnnouncements.ExaDat.Year) != 1) - Gbl.ExamAnnouncements.ExaDat.Year = Gbl.CurrentCrs.Crs.Year; - if (Gbl.ExamAnnouncements.ExaDat.Year > Deg_MAX_YEARS_PER_DEGREE) - Gbl.ExamAnnouncements.ExaDat.Year = Gbl.CurrentCrs.Crs.Year; + if (sscanf (UnsignedStr,"%u",&Gbl.ExamAnns.ExaDat.Year) != 1) + Gbl.ExamAnns.ExaDat.Year = Gbl.CurrentCrs.Crs.Year; + if (Gbl.ExamAnns.ExaDat.Year > Deg_MAX_YEARS_PER_DEGREE) + Gbl.ExamAnns.ExaDat.Year = Gbl.CurrentCrs.Crs.Year; /***** Get the type of exam announcement *****/ - Par_GetParToText ("ExamSession",Gbl.ExamAnnouncements.ExaDat.Session,Cns_MAX_BYTES_STRING); + Par_GetParToText ("ExamSession",Gbl.ExamAnns.ExaDat.Session,Cns_MAX_BYTES_STRING); /***** Get the data of the exam *****/ Dat_GetDateFromForm ("ExamDay","ExamMonth","ExamYear", - &Gbl.ExamAnnouncements.ExaDat.ExamDate.Day, - &Gbl.ExamAnnouncements.ExaDat.ExamDate.Month, - &Gbl.ExamAnnouncements.ExaDat.ExamDate.Year); - if (Gbl.ExamAnnouncements.ExaDat.ExamDate.Day == 0 || - Gbl.ExamAnnouncements.ExaDat.ExamDate.Month == 0 || - Gbl.ExamAnnouncements.ExaDat.ExamDate.Year == 0) + &Gbl.ExamAnns.ExaDat.ExamDate.Day, + &Gbl.ExamAnns.ExaDat.ExamDate.Month, + &Gbl.ExamAnns.ExaDat.ExamDate.Year); + if (Gbl.ExamAnns.ExaDat.ExamDate.Day == 0 || + Gbl.ExamAnns.ExaDat.ExamDate.Month == 0 || + Gbl.ExamAnns.ExaDat.ExamDate.Year == 0) { - Gbl.ExamAnnouncements.ExaDat.ExamDate.Day = Gbl.Now.Date.Day; - Gbl.ExamAnnouncements.ExaDat.ExamDate.Month = Gbl.Now.Date.Month; - Gbl.ExamAnnouncements.ExaDat.ExamDate.Year = Gbl.Now.Date.Year; + Gbl.ExamAnns.ExaDat.ExamDate.Day = Gbl.Now.Date.Day; + Gbl.ExamAnns.ExaDat.ExamDate.Month = Gbl.Now.Date.Month; + Gbl.ExamAnns.ExaDat.ExamDate.Year = Gbl.Now.Date.Year; } /***** Get the hour of the exam *****/ Par_GetParToText ("ExamHour",UnsignedStr,10); - if (sscanf (UnsignedStr,"%u",&Gbl.ExamAnnouncements.ExaDat.StartTime.Hour) != 1) - Gbl.ExamAnnouncements.ExaDat.StartTime.Hour = 0; - if (Gbl.ExamAnnouncements.ExaDat.StartTime.Hour > 23) - Gbl.ExamAnnouncements.ExaDat.StartTime.Hour = 0; + if (sscanf (UnsignedStr,"%u",&Gbl.ExamAnns.ExaDat.StartTime.Hour) != 1) + Gbl.ExamAnns.ExaDat.StartTime.Hour = 0; + if (Gbl.ExamAnns.ExaDat.StartTime.Hour > 23) + Gbl.ExamAnns.ExaDat.StartTime.Hour = 0; Par_GetParToText ("ExamMinute",UnsignedStr,10); - if (sscanf (UnsignedStr,"%u",&Gbl.ExamAnnouncements.ExaDat.StartTime.Minute) != 1) - Gbl.ExamAnnouncements.ExaDat.StartTime.Minute = 0; - if (Gbl.ExamAnnouncements.ExaDat.StartTime.Minute > 59) - Gbl.ExamAnnouncements.ExaDat.StartTime.Minute = 0; + if (sscanf (UnsignedStr,"%u",&Gbl.ExamAnns.ExaDat.StartTime.Minute) != 1) + Gbl.ExamAnns.ExaDat.StartTime.Minute = 0; + if (Gbl.ExamAnns.ExaDat.StartTime.Minute > 59) + Gbl.ExamAnns.ExaDat.StartTime.Minute = 0; /***** Get the duration of the exam *****/ Par_GetParToText ("DurationHour",UnsignedStr,10); - if (sscanf (UnsignedStr,"%u",&Gbl.ExamAnnouncements.ExaDat.Duration.Hour) != 1) - Gbl.ExamAnnouncements.ExaDat.Duration.Hour = 0; - if (Gbl.ExamAnnouncements.ExaDat.Duration.Hour > 23) - Gbl.ExamAnnouncements.ExaDat.Duration.Hour = 0; + if (sscanf (UnsignedStr,"%u",&Gbl.ExamAnns.ExaDat.Duration.Hour) != 1) + Gbl.ExamAnns.ExaDat.Duration.Hour = 0; + if (Gbl.ExamAnns.ExaDat.Duration.Hour > 23) + Gbl.ExamAnns.ExaDat.Duration.Hour = 0; Par_GetParToText ("DurationMinute",UnsignedStr,10); - if (sscanf (UnsignedStr,"%u",&Gbl.ExamAnnouncements.ExaDat.Duration.Minute) != 1) - Gbl.ExamAnnouncements.ExaDat.Duration.Minute = 0; - if (Gbl.ExamAnnouncements.ExaDat.Duration.Minute > 59) - Gbl.ExamAnnouncements.ExaDat.Duration.Minute = 0; + if (sscanf (UnsignedStr,"%u",&Gbl.ExamAnns.ExaDat.Duration.Minute) != 1) + Gbl.ExamAnns.ExaDat.Duration.Minute = 0; + if (Gbl.ExamAnns.ExaDat.Duration.Minute > 59) + Gbl.ExamAnns.ExaDat.Duration.Minute = 0; /***** Get the place where the exam will happen *****/ - Par_GetParToHTML ("Place",Gbl.ExamAnnouncements.ExaDat.Place,Cns_MAX_BYTES_TEXT); + Par_GetParToHTML ("Place",Gbl.ExamAnns.ExaDat.Place,Cns_MAX_BYTES_TEXT); /***** Get the modality of exam *****/ - Par_GetParToHTML ("ExamMode",Gbl.ExamAnnouncements.ExaDat.Mode,Cns_MAX_BYTES_TEXT); + Par_GetParToHTML ("ExamMode",Gbl.ExamAnns.ExaDat.Mode,Cns_MAX_BYTES_TEXT); /***** Get the structure of exam *****/ - Par_GetParToHTML ("Structure",Gbl.ExamAnnouncements.ExaDat.Structure,Cns_MAX_BYTES_TEXT); + Par_GetParToHTML ("Structure",Gbl.ExamAnns.ExaDat.Structure,Cns_MAX_BYTES_TEXT); /***** Get the mandatory documentation *****/ - Par_GetParToHTML ("DocRequired",Gbl.ExamAnnouncements.ExaDat.DocRequired,Cns_MAX_BYTES_TEXT); + Par_GetParToHTML ("DocRequired",Gbl.ExamAnns.ExaDat.DocRequired,Cns_MAX_BYTES_TEXT); /***** Get the mandatory material *****/ - Par_GetParToHTML ("MatRequired",Gbl.ExamAnnouncements.ExaDat.MatRequired,Cns_MAX_BYTES_TEXT); + Par_GetParToHTML ("MatRequired",Gbl.ExamAnns.ExaDat.MatRequired,Cns_MAX_BYTES_TEXT); /***** Get the allowed material *****/ - Par_GetParToHTML ("MatAllowed",Gbl.ExamAnnouncements.ExaDat.MatAllowed,Cns_MAX_BYTES_TEXT); + Par_GetParToHTML ("MatAllowed",Gbl.ExamAnns.ExaDat.MatAllowed,Cns_MAX_BYTES_TEXT); /***** Get other information *****/ - Par_GetParToHTML ("OtherInfo",Gbl.ExamAnnouncements.ExaDat.OtherInfo,Cns_MAX_BYTES_TEXT); + Par_GetParToHTML ("OtherInfo",Gbl.ExamAnns.ExaDat.OtherInfo,Cns_MAX_BYTES_TEXT); return ExaCod; } @@ -210,25 +207,25 @@ static long Exa_GetParamsExamAnnouncement (void) static void Exa_AllocMemExamAnnouncement (void) { - if ((Gbl.ExamAnnouncements.ExaDat.Place = malloc (Cns_MAX_BYTES_TEXT+1)) == NULL) + if ((Gbl.ExamAnns.ExaDat.Place = malloc (Cns_MAX_BYTES_TEXT+1)) == NULL) Lay_ShowErrorAndExit ("Not enough memory to store exam announcement."); - if ((Gbl.ExamAnnouncements.ExaDat.Mode = malloc (Cns_MAX_BYTES_TEXT+1)) == NULL) + if ((Gbl.ExamAnns.ExaDat.Mode = malloc (Cns_MAX_BYTES_TEXT+1)) == NULL) Lay_ShowErrorAndExit ("Not enough memory to store exam announcement."); - if ((Gbl.ExamAnnouncements.ExaDat.Structure = malloc (Cns_MAX_BYTES_TEXT+1)) == NULL) + if ((Gbl.ExamAnns.ExaDat.Structure = malloc (Cns_MAX_BYTES_TEXT+1)) == NULL) Lay_ShowErrorAndExit ("Not enough memory to store exam announcement."); - if ((Gbl.ExamAnnouncements.ExaDat.DocRequired = malloc (Cns_MAX_BYTES_TEXT+1)) == NULL) + if ((Gbl.ExamAnns.ExaDat.DocRequired = malloc (Cns_MAX_BYTES_TEXT+1)) == NULL) Lay_ShowErrorAndExit ("Not enough memory to store exam announcement."); - if ((Gbl.ExamAnnouncements.ExaDat.MatRequired = malloc (Cns_MAX_BYTES_TEXT+1)) == NULL) + if ((Gbl.ExamAnns.ExaDat.MatRequired = malloc (Cns_MAX_BYTES_TEXT+1)) == NULL) Lay_ShowErrorAndExit ("Not enough memory to store exam announcement."); - if ((Gbl.ExamAnnouncements.ExaDat.MatAllowed = malloc (Cns_MAX_BYTES_TEXT+1)) == NULL) + if ((Gbl.ExamAnns.ExaDat.MatAllowed = malloc (Cns_MAX_BYTES_TEXT+1)) == NULL) Lay_ShowErrorAndExit ("Not enough memory to store exam announcement."); - if ((Gbl.ExamAnnouncements.ExaDat.OtherInfo = malloc (Cns_MAX_BYTES_TEXT+1)) == NULL) + if ((Gbl.ExamAnns.ExaDat.OtherInfo = malloc (Cns_MAX_BYTES_TEXT+1)) == NULL) Lay_ShowErrorAndExit ("Not enough memory to store exam announcement."); } @@ -238,40 +235,40 @@ static void Exa_AllocMemExamAnnouncement (void) void Exa_FreeMemExamAnnouncement (void) { - if (Gbl.ExamAnnouncements.ExaDat.Place) + if (Gbl.ExamAnns.ExaDat.Place) { - free ((void *) Gbl.ExamAnnouncements.ExaDat.Place); - Gbl.ExamAnnouncements.ExaDat.Place = NULL; + free ((void *) Gbl.ExamAnns.ExaDat.Place); + Gbl.ExamAnns.ExaDat.Place = NULL; } - if (Gbl.ExamAnnouncements.ExaDat.Mode) + if (Gbl.ExamAnns.ExaDat.Mode) { - free ((void *) Gbl.ExamAnnouncements.ExaDat.Mode); - Gbl.ExamAnnouncements.ExaDat.Mode = NULL; + free ((void *) Gbl.ExamAnns.ExaDat.Mode); + Gbl.ExamAnns.ExaDat.Mode = NULL; } - if (Gbl.ExamAnnouncements.ExaDat.Structure) + if (Gbl.ExamAnns.ExaDat.Structure) { - free ((void *) Gbl.ExamAnnouncements.ExaDat.Structure); - Gbl.ExamAnnouncements.ExaDat.Structure = NULL; + free ((void *) Gbl.ExamAnns.ExaDat.Structure); + Gbl.ExamAnns.ExaDat.Structure = NULL; } - if (Gbl.ExamAnnouncements.ExaDat.DocRequired) + if (Gbl.ExamAnns.ExaDat.DocRequired) { - free ((void *) Gbl.ExamAnnouncements.ExaDat.DocRequired); - Gbl.ExamAnnouncements.ExaDat.DocRequired = NULL; + free ((void *) Gbl.ExamAnns.ExaDat.DocRequired); + Gbl.ExamAnns.ExaDat.DocRequired = NULL; } - if (Gbl.ExamAnnouncements.ExaDat.MatRequired) + if (Gbl.ExamAnns.ExaDat.MatRequired) { - free ((void *) Gbl.ExamAnnouncements.ExaDat.MatRequired); - Gbl.ExamAnnouncements.ExaDat.MatRequired = NULL; + free ((void *) Gbl.ExamAnns.ExaDat.MatRequired); + Gbl.ExamAnns.ExaDat.MatRequired = NULL; } - if (Gbl.ExamAnnouncements.ExaDat.MatAllowed) + if (Gbl.ExamAnns.ExaDat.MatAllowed) { - free ((void *) Gbl.ExamAnnouncements.ExaDat.MatAllowed); - Gbl.ExamAnnouncements.ExaDat.MatAllowed = NULL; + free ((void *) Gbl.ExamAnns.ExaDat.MatAllowed); + Gbl.ExamAnns.ExaDat.MatAllowed = NULL; } - if (Gbl.ExamAnnouncements.ExaDat.OtherInfo) + if (Gbl.ExamAnns.ExaDat.OtherInfo) { - free ((void *) Gbl.ExamAnnouncements.ExaDat.OtherInfo); - Gbl.ExamAnnouncements.ExaDat.OtherInfo = NULL; + free ((void *) Gbl.ExamAnns.ExaDat.OtherInfo); + Gbl.ExamAnns.ExaDat.OtherInfo = NULL; } } @@ -287,12 +284,12 @@ void Exa_ReceiveExamAnnouncement1 (void) Exa_AllocMemExamAnnouncement (); /***** Get parameters of the exam announcement *****/ - Gbl.ExamAnnouncements.ExaDat.ExaCod = Exa_GetParamsExamAnnouncement (); - Gbl.ExamAnnouncements.NewExamAnnouncement = (Gbl.ExamAnnouncements.ExaDat.ExaCod < 0); + Gbl.ExamAnns.ExaDat.ExaCod = Exa_GetParamsExamAnnouncement (); + Gbl.ExamAnns.NewExamAnnouncement = (Gbl.ExamAnns.ExaDat.ExaCod < 0); /***** Add the exam announcement to the database and read it again from the database *****/ - if (Gbl.ExamAnnouncements.NewExamAnnouncement) - Gbl.ExamAnnouncements.ExaDat.ExaCod = Exa_AddExamAnnouncementToDB (); + if (Gbl.ExamAnns.NewExamAnnouncement) + Gbl.ExamAnns.ExaDat.ExaCod = Exa_AddExamAnnouncementToDB (); else Exa_ModifyExamAnnouncementInDB (); @@ -309,16 +306,16 @@ void Exa_ReceiveExamAnnouncement2 (void) /***** Show message *****/ Lay_ShowAlert (Lay_SUCCESS, - Gbl.ExamAnnouncements.NewExamAnnouncement ? Txt_Created_new_announcement_of_exam : + Gbl.ExamAnns.NewExamAnnouncement ? Txt_Created_new_announcement_of_exam : Txt_The_announcement_of_exam_has_been_successfully_updated); /***** Notify by email about the new exam announcement *****/ - if ((NumUsrsToBeNotifiedByEMail = Ntf_StoreNotifyEventsToAllUsrs (Ntf_EVENT_EXAM_ANNOUNCEMENT,Gbl.ExamAnnouncements.ExaDat.ExaCod))) - Exa_UpdateNumUsrsNotifiedByEMailAboutExamAnnouncement (Gbl.ExamAnnouncements.ExaDat.ExaCod,NumUsrsToBeNotifiedByEMail); + if ((NumUsrsToBeNotifiedByEMail = Ntf_StoreNotifyEventsToAllUsrs (Ntf_EVENT_EXAM_ANNOUNCEMENT,Gbl.ExamAnns.ExaDat.ExaCod))) + Exa_UpdateNumUsrsNotifiedByEMailAboutExamAnnouncement (Gbl.ExamAnns.ExaDat.ExaCod,NumUsrsToBeNotifiedByEMail); Ntf_ShowAlertNumUsrsToBeNotifiedByEMail (NumUsrsToBeNotifiedByEMail); /***** Create a new social note about the new exam announcement *****/ - Soc_StoreAndPublishSocialNote (Soc_NOTE_EXAM_ANNOUNCEMENT,Gbl.ExamAnnouncements.ExaDat.ExaCod,&SocPub); + Soc_StoreAndPublishSocialNote (Soc_NOTE_EXAM_ANNOUNCEMENT,Gbl.ExamAnns.ExaDat.ExaCod,&SocPub); /***** Update RSS of current course *****/ RSS_UpdateRSSFileForACrs (&Gbl.CurrentCrs.Crs); @@ -352,7 +349,7 @@ void Exa_PrintExamAnnouncement (void) Exa_AllocMemExamAnnouncement (); /***** Get the code of the exam announcement *****/ - if ((Gbl.ExamAnnouncements.ExaDat.ExaCod = Exa_GetParamExaCod ()) <= 0) + if ((Gbl.ExamAnns.ExaDat.ExaCod = Exa_GetParamExaCod ()) <= 0) Lay_ShowErrorAndExit ("Code of exam announcement is missing."); /***** Read exam announcement from the database *****/ @@ -375,7 +372,7 @@ void Exa_ReqRemoveExamAnnouncement (void) extern const char *Txt_Remove; /***** Get the code of the exam announcement *****/ - if ((Gbl.ExamAnnouncements.ExaDat.ExaCod = Exa_GetParamExaCod ()) <= 0) + if ((Gbl.ExamAnns.ExaDat.ExaCod = Exa_GetParamExaCod ()) <= 0) Lay_ShowErrorAndExit ("Code of exam announcement is missing."); /***** Message *****/ @@ -537,7 +534,7 @@ void Exa_GetExaCodToHighlight (void) { /***** Get the exam announcement code of the exam announcement to highlight *****/ - Gbl.ExamAnnouncements.HighlightExaCod = Exa_GetParamExaCod (); + Gbl.ExamAnns.HighlightExaCod = Exa_GetParamExaCod (); } /*****************************************************************************/ @@ -548,7 +545,7 @@ void Exa_GetDateToHighlight (void) { /***** Get the date (in YYYY-MM-DD format) of the exam announcements to highlight *****/ - Par_GetParToText ("Date",Gbl.ExamAnnouncements.HighlightDate,4+1+2+1+2); + Par_GetParToText ("Date",Gbl.ExamAnns.HighlightDate,4+1+2+1+2); } /*****************************************************************************/ @@ -579,14 +576,14 @@ static void Exa_ListExamAnnouncements (Exa_TypeViewExamAnnouncement_t TypeViewEx (unsigned) Exa_VISIBLE_EXAM_ANNOUNCEMENT); /***** Show one highlighted exam announcement *****/ - if (Gbl.ExamAnnouncements.HighlightExaCod > 0) + if (Gbl.ExamAnns.HighlightExaCod > 0) { /***** Get one exam announcement from database *****/ sprintf (Query,"SELECT ExaCod" " FROM exam_announcements" " WHERE ExaCod='%ld'" " AND CrsCod='%ld' AND %s", - Gbl.ExamAnnouncements.HighlightExaCod, + Gbl.ExamAnns.HighlightExaCod, Gbl.CurrentCrs.Crs.CrsCod,SubQueryStatus); NumExaAnns = DB_QuerySELECT (Query,&mysql_res,"can not get exam announcements in this course for listing"); @@ -598,7 +595,7 @@ static void Exa_ListExamAnnouncements (Exa_TypeViewExamAnnouncement_t TypeViewEx /***** Get the code of the exam announcement (row[0]) *****/ row = mysql_fetch_row (mysql_res); - if (sscanf (row[0],"%ld",&Gbl.ExamAnnouncements.ExaDat.ExaCod) != 1) + if (sscanf (row[0],"%ld",&Gbl.ExamAnns.ExaDat.ExaCod) != 1) Lay_ShowErrorAndExit ("Wrong code of exam announcement."); /***** Allocate memory for the exam announcement *****/ @@ -616,7 +613,7 @@ static void Exa_ListExamAnnouncements (Exa_TypeViewExamAnnouncement_t TypeViewEx } /***** Show highlighted exam announcements of a date *****/ - if (Gbl.ExamAnnouncements.HighlightDate[0]) + if (Gbl.ExamAnns.HighlightDate[0]) { /***** Get exam announcements (the most recent first) in current course for a date from database *****/ @@ -626,7 +623,7 @@ static void Exa_ListExamAnnouncements (Exa_TypeViewExamAnnouncement_t TypeViewEx " AND DATE(ExamDate)='%s'" " ORDER BY ExamDate DESC", Gbl.CurrentCrs.Crs.CrsCod,SubQueryStatus, - Gbl.ExamAnnouncements.HighlightDate); + Gbl.ExamAnns.HighlightDate); NumExaAnns = DB_QuerySELECT (Query,&mysql_res,"can not get exam announcements in this course for listing"); /***** List the existing exam announcements *****/ @@ -637,7 +634,7 @@ static void Exa_ListExamAnnouncements (Exa_TypeViewExamAnnouncement_t TypeViewEx /***** Get the code of the exam announcement (row[0]) *****/ row = mysql_fetch_row (mysql_res); - if (sscanf (row[0],"%ld",&Gbl.ExamAnnouncements.ExaDat.ExaCod) != 1) + if (sscanf (row[0],"%ld",&Gbl.ExamAnns.ExaDat.ExaCod) != 1) Lay_ShowErrorAndExit ("Wrong code of exam announcement."); /***** Allocate memory for the exam announcement *****/ @@ -665,8 +662,8 @@ static void Exa_ListExamAnnouncements (Exa_TypeViewExamAnnouncement_t TypeViewEx /***** Start frame *****/ Lay_StartRoundFrame (NULL, - (Gbl.ExamAnnouncements.HighlightExaCod > 0 || - Gbl.ExamAnnouncements.HighlightDate[0]) ? Txt_All_announcements_of_exams : + (Gbl.ExamAnns.HighlightExaCod > 0 || + Gbl.ExamAnns.HighlightDate[0]) ? Txt_All_announcements_of_exams : Txt_Announcements_of_exams, ICanEdit ? Exa_PutIconToCreateNewExamAnnouncement : NULL, @@ -688,7 +685,7 @@ static void Exa_ListExamAnnouncements (Exa_TypeViewExamAnnouncement_t TypeViewEx /***** Get the code of the exam announcement (row[0]) *****/ row = mysql_fetch_row (mysql_res); - if (sscanf (row[0],"%ld",&Gbl.ExamAnnouncements.ExaDat.ExaCod) != 1) + if (sscanf (row[0],"%ld",&Gbl.ExamAnns.ExaDat.ExaCod) != 1) Lay_ShowErrorAndExit ("Wrong code of exam announcement."); /***** Allocate memory for the exam announcement *****/ @@ -765,23 +762,23 @@ static long Exa_AddExamAnnouncementToDB (void) "'%s','%s','%s','%s','%s','%s')", Gbl.CurrentCrs.Crs.CrsCod, (unsigned) Exa_VISIBLE_EXAM_ANNOUNCEMENT, - Gbl.ExamAnnouncements.ExaDat.CrsFullName, - Gbl.ExamAnnouncements.ExaDat.Year, - Gbl.ExamAnnouncements.ExaDat.Session, - Gbl.ExamAnnouncements.ExaDat.ExamDate.Year, - Gbl.ExamAnnouncements.ExaDat.ExamDate.Month, - Gbl.ExamAnnouncements.ExaDat.ExamDate.Day, - Gbl.ExamAnnouncements.ExaDat.StartTime.Hour, - Gbl.ExamAnnouncements.ExaDat.StartTime.Minute, - Gbl.ExamAnnouncements.ExaDat.Duration.Hour, - Gbl.ExamAnnouncements.ExaDat.Duration.Minute, - Gbl.ExamAnnouncements.ExaDat.Place, - Gbl.ExamAnnouncements.ExaDat.Mode, - Gbl.ExamAnnouncements.ExaDat.Structure, - Gbl.ExamAnnouncements.ExaDat.DocRequired, - Gbl.ExamAnnouncements.ExaDat.MatRequired, - Gbl.ExamAnnouncements.ExaDat.MatAllowed, - Gbl.ExamAnnouncements.ExaDat.OtherInfo); + Gbl.ExamAnns.ExaDat.CrsFullName, + Gbl.ExamAnns.ExaDat.Year, + Gbl.ExamAnns.ExaDat.Session, + Gbl.ExamAnns.ExaDat.ExamDate.Year, + Gbl.ExamAnns.ExaDat.ExamDate.Month, + Gbl.ExamAnns.ExaDat.ExamDate.Day, + Gbl.ExamAnns.ExaDat.StartTime.Hour, + Gbl.ExamAnns.ExaDat.StartTime.Minute, + Gbl.ExamAnns.ExaDat.Duration.Hour, + Gbl.ExamAnns.ExaDat.Duration.Minute, + Gbl.ExamAnns.ExaDat.Place, + Gbl.ExamAnns.ExaDat.Mode, + Gbl.ExamAnns.ExaDat.Structure, + Gbl.ExamAnns.ExaDat.DocRequired, + Gbl.ExamAnns.ExaDat.MatRequired, + Gbl.ExamAnns.ExaDat.MatAllowed, + Gbl.ExamAnns.ExaDat.OtherInfo); ExaCod = DB_QueryINSERTandReturnCode (Query,"can not create a new exam announcement"); free ((void *) Query); @@ -806,24 +803,24 @@ static void Exa_ModifyExamAnnouncementInDB (void) "Place='%s',ExamMode='%s',Structure='%s'," "DocRequired='%s',MatRequired='%s',MatAllowed='%s',OtherInfo='%s'" " WHERE ExaCod='%ld'", - Gbl.ExamAnnouncements.ExaDat.CrsFullName, - Gbl.ExamAnnouncements.ExaDat.Year, - Gbl.ExamAnnouncements.ExaDat.Session, - Gbl.ExamAnnouncements.ExaDat.ExamDate.Year, - Gbl.ExamAnnouncements.ExaDat.ExamDate.Month, - Gbl.ExamAnnouncements.ExaDat.ExamDate.Day, - Gbl.ExamAnnouncements.ExaDat.StartTime.Hour, - Gbl.ExamAnnouncements.ExaDat.StartTime.Minute, - Gbl.ExamAnnouncements.ExaDat.Duration.Hour, - Gbl.ExamAnnouncements.ExaDat.Duration.Minute, - Gbl.ExamAnnouncements.ExaDat.Place, - Gbl.ExamAnnouncements.ExaDat.Mode, - Gbl.ExamAnnouncements.ExaDat.Structure, - Gbl.ExamAnnouncements.ExaDat.DocRequired, - Gbl.ExamAnnouncements.ExaDat.MatRequired, - Gbl.ExamAnnouncements.ExaDat.MatAllowed, - Gbl.ExamAnnouncements.ExaDat.OtherInfo, - Gbl.ExamAnnouncements.ExaDat.ExaCod); + Gbl.ExamAnns.ExaDat.CrsFullName, + Gbl.ExamAnns.ExaDat.Year, + Gbl.ExamAnns.ExaDat.Session, + Gbl.ExamAnns.ExaDat.ExamDate.Year, + Gbl.ExamAnns.ExaDat.ExamDate.Month, + Gbl.ExamAnns.ExaDat.ExamDate.Day, + Gbl.ExamAnns.ExaDat.StartTime.Hour, + Gbl.ExamAnns.ExaDat.StartTime.Minute, + Gbl.ExamAnns.ExaDat.Duration.Hour, + Gbl.ExamAnns.ExaDat.Duration.Minute, + Gbl.ExamAnns.ExaDat.Place, + Gbl.ExamAnns.ExaDat.Mode, + Gbl.ExamAnns.ExaDat.Structure, + Gbl.ExamAnns.ExaDat.DocRequired, + Gbl.ExamAnns.ExaDat.MatRequired, + Gbl.ExamAnns.ExaDat.MatAllowed, + Gbl.ExamAnns.ExaDat.OtherInfo, + Gbl.ExamAnns.ExaDat.ExaCod); DB_QueryUPDATE (Query,"can not update an exam announcement"); free ((void *) Query); } @@ -853,12 +850,12 @@ void Exa_CreateListDatesOfExamAnnouncements (void) NumExaAnns = DB_QuerySELECT (Query,&mysql_res,"can not get exam announcements in this course"); /***** The result of the query may be empty *****/ - Gbl.ExamAnnouncements.Lst = NULL; - Gbl.ExamAnnouncements.NumExaAnns = 0; + Gbl.ExamAnns.Lst = NULL; + Gbl.ExamAnns.NumExaAnns = 0; if (NumExaAnns) { /***** Allocate memory for the list *****/ - if ((Gbl.ExamAnnouncements.Lst = (struct Date *) calloc (NumExaAnns,sizeof (struct Date))) == NULL) + if ((Gbl.ExamAnns.Lst = (struct Date *) calloc (NumExaAnns,sizeof (struct Date))) == NULL) Lay_ShowErrorAndExit ("Not enough memory to store dates of exam announcements."); /***** Get the dates of the existing exam announcements *****/ @@ -871,13 +868,13 @@ void Exa_CreateListDatesOfExamAnnouncements (void) /* Read the date of the exam (row[0]) */ if (sscanf (row[0],"%04u-%02u-%02u", - &Gbl.ExamAnnouncements.Lst[Gbl.ExamAnnouncements.NumExaAnns].Year, - &Gbl.ExamAnnouncements.Lst[Gbl.ExamAnnouncements.NumExaAnns].Month, - &Gbl.ExamAnnouncements.Lst[Gbl.ExamAnnouncements.NumExaAnns].Day) != 3) + &Gbl.ExamAnns.Lst[Gbl.ExamAnns.NumExaAnns].Year, + &Gbl.ExamAnns.Lst[Gbl.ExamAnns.NumExaAnns].Month, + &Gbl.ExamAnns.Lst[Gbl.ExamAnns.NumExaAnns].Day) != 3) Lay_ShowErrorAndExit ("Wrong date of exam."); /***** Increment number of elements in list *****/ - Gbl.ExamAnnouncements.NumExaAnns++; + Gbl.ExamAnns.NumExaAnns++; } } @@ -892,11 +889,11 @@ void Exa_CreateListDatesOfExamAnnouncements (void) void Exa_FreeListExamAnnouncements (void) { - if (Gbl.ExamAnnouncements.Lst) + if (Gbl.ExamAnns.Lst) { - free ((void *) Gbl.ExamAnnouncements.Lst); - Gbl.ExamAnnouncements.Lst = NULL; - Gbl.ExamAnnouncements.NumExaAnns = 0; + free ((void *) Gbl.ExamAnns.Lst); + Gbl.ExamAnns.Lst = NULL; + Gbl.ExamAnns.NumExaAnns = 0; } } @@ -920,7 +917,7 @@ static void Exa_GetDataExamAnnouncementFromDB (void) "CallDate,ExamDate,Duration,Place,ExamMode," "Structure,DocRequired,MatRequired,MatAllowed,OtherInfo" " FROM exam_announcements WHERE ExaCod='%ld'", - Gbl.ExamAnnouncements.ExaDat.ExaCod); + Gbl.ExamAnns.ExaDat.ExaCod); NumExaAnns = DB_QuerySELECT (Query,&mysql_res,"can not get data of an exam announcement"); /***** The result of the query must have one row *****/ @@ -931,73 +928,64 @@ static void Exa_GetDataExamAnnouncementFromDB (void) row = mysql_fetch_row (mysql_res); /* Code of the course in which the exam announcement is inserted (row[0]) */ - Gbl.ExamAnnouncements.ExaDat.CrsCod = Str_ConvertStrCodToLongCod (row[0]); + Gbl.ExamAnns.ExaDat.CrsCod = Str_ConvertStrCodToLongCod (row[0]); /* Status of the exam announcement (row[1]) */ if (sscanf (row[1],"%u",&UnsignedNum) != 1) Lay_ShowErrorAndExit ("Wrong status."); if (UnsignedNum >= Exa_NUM_STATUS) Lay_ShowErrorAndExit ("Wrong status."); - Gbl.ExamAnnouncements.ExaDat.Status = (Exa_ExamAnnouncementStatus_t) UnsignedNum; + Gbl.ExamAnns.ExaDat.Status = (Exa_ExamAnnouncementStatus_t) UnsignedNum; /* Name of the course (row[2]) */ - strncpy (Gbl.ExamAnnouncements.ExaDat.CrsFullName,row[2], - Crs_MAX_LENGTH_COURSE_FULL_NAME); - Gbl.ExamAnnouncements.ExaDat.CrsFullName[Crs_MAX_LENGTH_COURSE_FULL_NAME] = '\0'; + Str_Copy (Gbl.ExamAnns.ExaDat.CrsFullName,row[2], + Crs_MAX_LENGTH_COURSE_FULL_NAME); /* Year (row[3]) */ - if (sscanf (row[3],"%u",&Gbl.ExamAnnouncements.ExaDat.Year) != 1) + if (sscanf (row[3],"%u",&Gbl.ExamAnns.ExaDat.Year) != 1) Lay_ShowErrorAndExit ("Wrong year."); /* Exam session (row[4]) */ - strncpy (Gbl.ExamAnnouncements.ExaDat.Session,row[4],Cns_MAX_BYTES_STRING); - Gbl.ExamAnnouncements.ExaDat.Session[Cns_MAX_BYTES_STRING] = '\0'; + Str_Copy (Gbl.ExamAnns.ExaDat.Session,row[4],Cns_MAX_BYTES_STRING); /* Date of exam announcement (row[5]) */ if (sscanf (row[5],"%04u-%02u-%02u %02u:%02u:%02u", - &Gbl.ExamAnnouncements.ExaDat.CallDate.Year, - &Gbl.ExamAnnouncements.ExaDat.CallDate.Month, - &Gbl.ExamAnnouncements.ExaDat.CallDate.Day, + &Gbl.ExamAnns.ExaDat.CallDate.Year, + &Gbl.ExamAnns.ExaDat.CallDate.Month, + &Gbl.ExamAnns.ExaDat.CallDate.Day, &Hour,&Minute,&Second) != 6) Lay_ShowErrorAndExit ("Wrong date of exam announcement."); /* Date of exam (row[6]) */ if (sscanf (row[6],"%04u-%02u-%02u %02u:%02u:%02u", - &Gbl.ExamAnnouncements.ExaDat.ExamDate.Year,&Gbl.ExamAnnouncements.ExaDat.ExamDate.Month,&Gbl.ExamAnnouncements.ExaDat.ExamDate.Day, - &Gbl.ExamAnnouncements.ExaDat.StartTime.Hour,&Gbl.ExamAnnouncements.ExaDat.StartTime.Minute,&Second) != 6) + &Gbl.ExamAnns.ExaDat.ExamDate.Year,&Gbl.ExamAnns.ExaDat.ExamDate.Month,&Gbl.ExamAnns.ExaDat.ExamDate.Day, + &Gbl.ExamAnns.ExaDat.StartTime.Hour,&Gbl.ExamAnns.ExaDat.StartTime.Minute,&Second) != 6) Lay_ShowErrorAndExit ("Wrong date of exam."); /* Approximate duration (row[7]) */ - if (sscanf (row[7],"%02u:%02u:%02u",&Gbl.ExamAnnouncements.ExaDat.Duration.Hour,&Gbl.ExamAnnouncements.ExaDat.Duration.Minute,&Second) != 3) + if (sscanf (row[7],"%02u:%02u:%02u",&Gbl.ExamAnns.ExaDat.Duration.Hour,&Gbl.ExamAnns.ExaDat.Duration.Minute,&Second) != 3) Lay_ShowErrorAndExit ("Wrong duration of exam."); /* Place (row[8]) */ - strncpy (Gbl.ExamAnnouncements.ExaDat.Place,row[8],Cns_MAX_BYTES_TEXT); - Gbl.ExamAnnouncements.ExaDat.Place[Cns_MAX_BYTES_TEXT] = '\0'; + Str_Copy (Gbl.ExamAnns.ExaDat.Place,row[8],Cns_MAX_BYTES_TEXT); /* Exam mode (row[9]) */ - strncpy (Gbl.ExamAnnouncements.ExaDat.Mode,row[9],Cns_MAX_BYTES_TEXT); - Gbl.ExamAnnouncements.ExaDat.Mode[Cns_MAX_BYTES_TEXT] = '\0'; + Str_Copy (Gbl.ExamAnns.ExaDat.Mode,row[9],Cns_MAX_BYTES_TEXT); /* Structure (row[10]) */ - strncpy (Gbl.ExamAnnouncements.ExaDat.Structure,row[10],Cns_MAX_BYTES_TEXT); - Gbl.ExamAnnouncements.ExaDat.Structure[Cns_MAX_BYTES_TEXT] = '\0'; + Str_Copy (Gbl.ExamAnns.ExaDat.Structure,row[10],Cns_MAX_BYTES_TEXT); /* Documentation required (row[11]) */ - strncpy (Gbl.ExamAnnouncements.ExaDat.DocRequired,row[11],Cns_MAX_BYTES_TEXT); - Gbl.ExamAnnouncements.ExaDat.DocRequired[Cns_MAX_BYTES_TEXT] = '\0'; + Str_Copy (Gbl.ExamAnns.ExaDat.DocRequired,row[11],Cns_MAX_BYTES_TEXT); /* Material required (row[12]) */ - strncpy (Gbl.ExamAnnouncements.ExaDat.MatRequired,row[12],Cns_MAX_BYTES_TEXT); - Gbl.ExamAnnouncements.ExaDat.MatRequired[Cns_MAX_BYTES_TEXT] = '\0'; + Str_Copy (Gbl.ExamAnns.ExaDat.MatRequired,row[12],Cns_MAX_BYTES_TEXT); /* Material allowed (row[13]) */ - strncpy (Gbl.ExamAnnouncements.ExaDat.MatAllowed,row[13],Cns_MAX_BYTES_TEXT); - Gbl.ExamAnnouncements.ExaDat.MatAllowed[Cns_MAX_BYTES_TEXT] = '\0'; + Str_Copy (Gbl.ExamAnns.ExaDat.MatAllowed,row[13],Cns_MAX_BYTES_TEXT); /* Other information for students (row[14]) */ - strncpy (Gbl.ExamAnnouncements.ExaDat.OtherInfo,row[14],Cns_MAX_BYTES_TEXT); - Gbl.ExamAnnouncements.ExaDat.OtherInfo[Cns_MAX_BYTES_TEXT] = '\0'; + Str_Copy (Gbl.ExamAnns.ExaDat.OtherInfo,row[14],Cns_MAX_BYTES_TEXT); /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); @@ -1080,7 +1068,7 @@ static void Exa_ShowExamAnnouncement (Exa_TypeViewExamAnnouncement_t TypeViewExa Lay_StartRoundFrame ("625px",NULL, TypeViewExamAnnouncement == Exa_NORMAL_VIEW ? Exa_PutIconsExamAnnouncement : NULL, - TypeViewExamAnnouncement == Exa_FORM_VIEW ? ((Gbl.ExamAnnouncements.ExaDat.ExaCod > 0) ? Hlp_ASSESSMENT_Announcements_edit_announcement : + TypeViewExamAnnouncement == Exa_FORM_VIEW ? ((Gbl.ExamAnns.ExaDat.ExaCod > 0) ? Hlp_ASSESSMENT_Announcements_edit_announcement : Hlp_ASSESSMENT_Announcements_new_announcement) : NULL); @@ -1088,13 +1076,13 @@ static void Exa_ShowExamAnnouncement (Exa_TypeViewExamAnnouncement_t TypeViewExa { /***** Start form *****/ Act_FormStart (ActRcvExaAnn); - if (Gbl.ExamAnnouncements.ExaDat.ExaCod > 0) // Existing announcement of exam + if (Gbl.ExamAnns.ExaDat.ExaCod > 0) // Existing announcement of exam Exa_PutParamExaCodToEdit (); } /***** Start table *****/ fprintf (Gbl.F.Out,"<table class=\"%s CELLS_PAD_2\">", - ClassExaAnnouncement[TypeViewExamAnnouncement][Gbl.ExamAnnouncements.ExaDat.Status]); + ClassExaAnnouncement[TypeViewExamAnnouncement][Gbl.ExamAnns.ExaDat.Status]); /***** Institution logo *****/ fprintf (Gbl.F.Out,"<tr>" @@ -1153,11 +1141,11 @@ static void Exa_ShowExamAnnouncement (Exa_TypeViewExamAnnouncement_t TypeViewExa { fprintf (Gbl.F.Out,"<input type=\"text\" id=\"CrsName\" name=\"CrsName\"" " size=\"30\" maxlength=\"%u\" value=\"%s\" />", - Cns_MAX_LENGTH_STRING,Gbl.ExamAnnouncements.ExaDat.CrsFullName); + Cns_MAX_LENGTH_STRING,Gbl.ExamAnns.ExaDat.CrsFullName); } else fprintf (Gbl.F.Out,"<strong>%s</strong>", - Gbl.ExamAnnouncements.ExaDat.CrsFullName); + Gbl.ExamAnns.ExaDat.CrsFullName); fprintf (Gbl.F.Out,"</td>" "</tr>"); @@ -1178,7 +1166,7 @@ static void Exa_ShowExamAnnouncement (Exa_TypeViewExamAnnouncement_t TypeViewExa Year++) { fprintf (Gbl.F.Out,"<option"); - if (Gbl.ExamAnnouncements.ExaDat.Year == Year) + if (Gbl.ExamAnns.ExaDat.Year == Year) fprintf (Gbl.F.Out," selected=\"selected\""); fprintf (Gbl.F.Out," value=\"%u\">" "%s" @@ -1189,7 +1177,7 @@ static void Exa_ShowExamAnnouncement (Exa_TypeViewExamAnnouncement_t TypeViewExa } else fprintf (Gbl.F.Out,"%s", - Txt_YEAR_OF_DEGREE[Gbl.ExamAnnouncements.ExaDat.Year]); + Txt_YEAR_OF_DEGREE[Gbl.ExamAnns.ExaDat.Year]); fprintf (Gbl.F.Out,"</td>" "</tr>"); @@ -1206,9 +1194,9 @@ static void Exa_ShowExamAnnouncement (Exa_TypeViewExamAnnouncement_t TypeViewExa fprintf (Gbl.F.Out,"<input type=\"text\"" " id=\"ExamSession\" name=\"ExamSession\"" " size=\"30\" maxlength=\"%u\" value=\"%s\" />", - Cns_MAX_LENGTH_STRING,Gbl.ExamAnnouncements.ExaDat.Session); + Cns_MAX_LENGTH_STRING,Gbl.ExamAnns.ExaDat.Session); else - fprintf (Gbl.F.Out,"%s",Gbl.ExamAnnouncements.ExaDat.Session); + fprintf (Gbl.F.Out,"%s",Gbl.ExamAnns.ExaDat.Session); fprintf (Gbl.F.Out,"</td>" "</tr>"); @@ -1222,16 +1210,16 @@ static void Exa_ShowExamAnnouncement (Exa_TypeViewExamAnnouncement_t TypeViewExa if (TypeViewExamAnnouncement == Exa_FORM_VIEW) { fprintf (Gbl.F.Out,"<td class=\"LEFT_BOTTOM\">"); - Dat_WriteFormDate (Gbl.ExamAnnouncements.ExaDat.ExamDate.Year < Gbl.Now.Date.Year ? Gbl.ExamAnnouncements.ExaDat.ExamDate.Year : + Dat_WriteFormDate (Gbl.ExamAnns.ExaDat.ExamDate.Year < Gbl.Now.Date.Year ? Gbl.ExamAnns.ExaDat.ExamDate.Year : Gbl.Now.Date.Year, Gbl.Now.Date.Year + 1,"Exam", - &(Gbl.ExamAnnouncements.ExaDat.ExamDate), + &(Gbl.ExamAnns.ExaDat.ExamDate), false,false); fprintf (Gbl.F.Out,"</td>"); } else { - Dat_ConvDateToDateStr (&Gbl.ExamAnnouncements.ExaDat.ExamDate, + Dat_ConvDateToDateStr (&Gbl.ExamAnns.ExaDat.ExamDate, StrExamDate); fprintf (Gbl.F.Out,"<td class=\"%s LEFT_BOTTOM\">" "%s" @@ -1253,7 +1241,7 @@ static void Exa_ShowExamAnnouncement (Exa_TypeViewExamAnnouncement_t TypeViewExa { fprintf (Gbl.F.Out,"<select name=\"ExamHour\">" "<option value=\"0\""); - if (Gbl.ExamAnnouncements.ExaDat.StartTime.Hour == 0) + if (Gbl.ExamAnns.ExaDat.StartTime.Hour == 0) fprintf (Gbl.F.Out," selected=\"selected\""); fprintf (Gbl.F.Out,">-</option>"); for (Hour = 7; @@ -1261,7 +1249,7 @@ static void Exa_ShowExamAnnouncement (Exa_TypeViewExamAnnouncement_t TypeViewExa Hour++) { fprintf (Gbl.F.Out,"<option value=\"%u\"",Hour); - if (Gbl.ExamAnnouncements.ExaDat.StartTime.Hour == Hour) + if (Gbl.ExamAnns.ExaDat.StartTime.Hour == Hour) fprintf (Gbl.F.Out," selected=\"selected\""); fprintf (Gbl.F.Out,">%02u %s</option>", Hour,Txt_hours_ABBREVIATION); @@ -1273,16 +1261,16 @@ static void Exa_ShowExamAnnouncement (Exa_TypeViewExamAnnouncement_t TypeViewExa Minute++) { fprintf (Gbl.F.Out,"<option value=\"%u\"",Minute); - if (Gbl.ExamAnnouncements.ExaDat.StartTime.Minute == Minute) + if (Gbl.ExamAnns.ExaDat.StartTime.Minute == Minute) fprintf (Gbl.F.Out," selected=\"selected\""); fprintf (Gbl.F.Out,">%02u '</option>",Minute); } fprintf (Gbl.F.Out,"</select>"); } - else if (Gbl.ExamAnnouncements.ExaDat.StartTime.Hour) + else if (Gbl.ExamAnns.ExaDat.StartTime.Hour) fprintf (Gbl.F.Out,"%2u:%02u", - Gbl.ExamAnnouncements.ExaDat.StartTime.Hour, - Gbl.ExamAnnouncements.ExaDat.StartTime.Minute); + Gbl.ExamAnns.ExaDat.StartTime.Hour, + Gbl.ExamAnns.ExaDat.StartTime.Minute); fprintf (Gbl.F.Out,"</td>" "</tr>"); @@ -1303,7 +1291,7 @@ static void Exa_ShowExamAnnouncement (Exa_TypeViewExamAnnouncement_t TypeViewExa Hour++) { fprintf (Gbl.F.Out,"<option value=\"%u\"",Hour); - if (Gbl.ExamAnnouncements.ExaDat.Duration.Hour == Hour) + if (Gbl.ExamAnns.ExaDat.Duration.Hour == Hour) fprintf (Gbl.F.Out," selected=\"selected\""); fprintf (Gbl.F.Out,">%02u %s</option>", Hour,Txt_hours_ABBREVIATION); @@ -1315,38 +1303,38 @@ static void Exa_ShowExamAnnouncement (Exa_TypeViewExamAnnouncement_t TypeViewExa Minute++) { fprintf (Gbl.F.Out,"<option value=\"%u\"",Minute); - if (Gbl.ExamAnnouncements.ExaDat.Duration.Minute == Minute) + if (Gbl.ExamAnns.ExaDat.Duration.Minute == Minute) fprintf (Gbl.F.Out," selected=\"selected\""); fprintf (Gbl.F.Out,">%02u '</option>",Minute); } fprintf (Gbl.F.Out,"</select>"); } - else if (Gbl.ExamAnnouncements.ExaDat.Duration.Hour || - Gbl.ExamAnnouncements.ExaDat.Duration.Minute) + else if (Gbl.ExamAnns.ExaDat.Duration.Hour || + Gbl.ExamAnns.ExaDat.Duration.Minute) { - if (Gbl.ExamAnnouncements.ExaDat.Duration.Hour) + if (Gbl.ExamAnns.ExaDat.Duration.Hour) { - if (Gbl.ExamAnnouncements.ExaDat.Duration.Minute) + if (Gbl.ExamAnns.ExaDat.Duration.Minute) fprintf (Gbl.F.Out,"%u %s %u '", - Gbl.ExamAnnouncements.ExaDat.Duration.Hour, + Gbl.ExamAnns.ExaDat.Duration.Hour, Txt_hours_ABBREVIATION, - Gbl.ExamAnnouncements.ExaDat.Duration.Minute); + Gbl.ExamAnns.ExaDat.Duration.Minute); else { - if (Gbl.ExamAnnouncements.ExaDat.Duration.Hour == 1) + if (Gbl.ExamAnns.ExaDat.Duration.Hour == 1) fprintf (Gbl.F.Out,"1 %s",Txt_hour); else fprintf (Gbl.F.Out,"%u %s", - Gbl.ExamAnnouncements.ExaDat.Duration.Hour,Txt_hours); + Gbl.ExamAnns.ExaDat.Duration.Hour,Txt_hours); } } - else if (Gbl.ExamAnnouncements.ExaDat.Duration.Minute) + else if (Gbl.ExamAnns.ExaDat.Duration.Minute) { - if (Gbl.ExamAnnouncements.ExaDat.Duration.Minute == 1) + if (Gbl.ExamAnns.ExaDat.Duration.Minute == 1) fprintf (Gbl.F.Out,"1 %s",Txt_minute); else fprintf (Gbl.F.Out,"%u %s", - Gbl.ExamAnnouncements.ExaDat.Duration.Minute,Txt_minutes); + Gbl.ExamAnns.ExaDat.Duration.Minute,Txt_minutes); } } fprintf (Gbl.F.Out,"</td>" @@ -1366,13 +1354,13 @@ static void Exa_ShowExamAnnouncement (Exa_TypeViewExamAnnouncement_t TypeViewExa " cols=\"40\" rows=\"4\">" "%s" "</textarea>", - Gbl.ExamAnnouncements.ExaDat.Place); + Gbl.ExamAnns.ExaDat.Place); else { Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, - Gbl.ExamAnnouncements.ExaDat.Place, + Gbl.ExamAnns.ExaDat.Place, Cns_MAX_BYTES_TEXT,false); - fprintf (Gbl.F.Out,"%s",Gbl.ExamAnnouncements.ExaDat.Place); + fprintf (Gbl.F.Out,"%s",Gbl.ExamAnns.ExaDat.Place); } fprintf (Gbl.F.Out,"</td>" "</tr>"); @@ -1391,13 +1379,13 @@ static void Exa_ShowExamAnnouncement (Exa_TypeViewExamAnnouncement_t TypeViewExa " cols=\"40\" rows=\"2\">" "%s" "</textarea>", - Gbl.ExamAnnouncements.ExaDat.Mode); + Gbl.ExamAnns.ExaDat.Mode); else { Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, - Gbl.ExamAnnouncements.ExaDat.Mode, + Gbl.ExamAnns.ExaDat.Mode, Cns_MAX_BYTES_TEXT,false); - fprintf (Gbl.F.Out,"%s",Gbl.ExamAnnouncements.ExaDat.Mode); + fprintf (Gbl.F.Out,"%s",Gbl.ExamAnns.ExaDat.Mode); } fprintf (Gbl.F.Out,"</td>" "</tr>"); @@ -1416,13 +1404,13 @@ static void Exa_ShowExamAnnouncement (Exa_TypeViewExamAnnouncement_t TypeViewExa " cols=\"40\" rows=\"8\">" "%s" "</textarea>", - Gbl.ExamAnnouncements.ExaDat.Structure); + Gbl.ExamAnns.ExaDat.Structure); else { Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, - Gbl.ExamAnnouncements.ExaDat.Structure, + Gbl.ExamAnns.ExaDat.Structure, Cns_MAX_BYTES_TEXT,false); - fprintf (Gbl.F.Out,"%s",Gbl.ExamAnnouncements.ExaDat.Structure); + fprintf (Gbl.F.Out,"%s",Gbl.ExamAnns.ExaDat.Structure); } fprintf (Gbl.F.Out,"</td>" "</tr>"); @@ -1441,13 +1429,13 @@ static void Exa_ShowExamAnnouncement (Exa_TypeViewExamAnnouncement_t TypeViewExa " cols=\"40\" rows=\"2\">" "%s" "</textarea>", - Gbl.ExamAnnouncements.ExaDat.DocRequired); + Gbl.ExamAnns.ExaDat.DocRequired); else { Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, - Gbl.ExamAnnouncements.ExaDat.DocRequired, + Gbl.ExamAnns.ExaDat.DocRequired, Cns_MAX_BYTES_TEXT,false); - fprintf (Gbl.F.Out,"%s",Gbl.ExamAnnouncements.ExaDat.DocRequired); + fprintf (Gbl.F.Out,"%s",Gbl.ExamAnns.ExaDat.DocRequired); } fprintf (Gbl.F.Out,"</td>" "</tr>"); @@ -1466,13 +1454,13 @@ static void Exa_ShowExamAnnouncement (Exa_TypeViewExamAnnouncement_t TypeViewExa " cols=\"40\" rows=\"4\">" "%s" "</textarea>", - Gbl.ExamAnnouncements.ExaDat.MatRequired); + Gbl.ExamAnns.ExaDat.MatRequired); else { Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, - Gbl.ExamAnnouncements.ExaDat.MatRequired, + Gbl.ExamAnns.ExaDat.MatRequired, Cns_MAX_BYTES_TEXT,false); - fprintf (Gbl.F.Out,"%s",Gbl.ExamAnnouncements.ExaDat.MatRequired); + fprintf (Gbl.F.Out,"%s",Gbl.ExamAnns.ExaDat.MatRequired); } fprintf (Gbl.F.Out,"</td>" "</tr>"); @@ -1491,13 +1479,13 @@ static void Exa_ShowExamAnnouncement (Exa_TypeViewExamAnnouncement_t TypeViewExa " cols=\"40\" rows=\"4\">" "%s" "</textarea>", - Gbl.ExamAnnouncements.ExaDat.MatAllowed); + Gbl.ExamAnns.ExaDat.MatAllowed); else { Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, - Gbl.ExamAnnouncements.ExaDat.MatAllowed, + Gbl.ExamAnns.ExaDat.MatAllowed, Cns_MAX_BYTES_TEXT,false); - fprintf (Gbl.F.Out,"%s",Gbl.ExamAnnouncements.ExaDat.MatAllowed); + fprintf (Gbl.F.Out,"%s",Gbl.ExamAnns.ExaDat.MatAllowed); } fprintf (Gbl.F.Out,"</td>" "</tr>"); @@ -1515,13 +1503,13 @@ static void Exa_ShowExamAnnouncement (Exa_TypeViewExamAnnouncement_t TypeViewExa " cols=\"40\" rows=\"5\">" "%s" "</textarea>", - Gbl.ExamAnnouncements.ExaDat.OtherInfo); + Gbl.ExamAnns.ExaDat.OtherInfo); else { Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, - Gbl.ExamAnnouncements.ExaDat.OtherInfo, + Gbl.ExamAnns.ExaDat.OtherInfo, Cns_MAX_BYTES_TEXT,false); - fprintf (Gbl.F.Out,"%s",Gbl.ExamAnnouncements.ExaDat.OtherInfo); + fprintf (Gbl.F.Out,"%s",Gbl.ExamAnns.ExaDat.OtherInfo); } fprintf (Gbl.F.Out,"</td>" "</tr>"); @@ -1531,7 +1519,7 @@ static void Exa_ShowExamAnnouncement (Exa_TypeViewExamAnnouncement_t TypeViewExa /***** End frame *****/ if (TypeViewExamAnnouncement == Exa_FORM_VIEW) - Lay_EndRoundFrameWithButton ((Gbl.ExamAnnouncements.ExaDat.ExaCod > 0) ? Lay_CONFIRM_BUTTON : + Lay_EndRoundFrameWithButton ((Gbl.ExamAnns.ExaDat.ExaCod > 0) ? Lay_CONFIRM_BUTTON : Lay_CREATE_BUTTON, Txt_Publish_announcement_OF_EXAM); else @@ -1563,7 +1551,7 @@ static void Exa_PutIconsExamAnnouncement (void) NULL); /***** Put form to hide/show exam announement *****/ - switch (Gbl.ExamAnnouncements.ExaDat.Status) + switch (Gbl.ExamAnns.ExaDat.Status) { case Exa_VISIBLE_EXAM_ANNOUNCEMENT: Lay_PutContextualLink (ActHidExaAnn,Exa_PutParamExaCodToEdit, @@ -1601,7 +1589,7 @@ static void Exa_PutIconsExamAnnouncement (void) static void Exa_PutParamExaCodToEdit (void) { - Exa_PutHiddenParamExaCod (Gbl.ExamAnnouncements.ExaDat.ExaCod); + Exa_PutHiddenParamExaCod (Gbl.ExamAnns.ExaDat.ExaCod); } void Exa_PutHiddenParamExaCod (long ExaCod) @@ -1638,7 +1626,7 @@ void Exa_GetSummaryAndContentExamAnnouncement (char *SummaryStr,char **ContentSt extern const char *Txt_hours_ABBREVIATION; /***** Initializations *****/ - Gbl.ExamAnnouncements.ExaDat.ExaCod = ExaCod; + Gbl.ExamAnns.ExaDat.ExaCod = ExaCod; SummaryStr[0] = '\0'; // Return nothing on error /***** Allocate memory for the exam announcement *****/ @@ -1654,17 +1642,17 @@ void Exa_GetSummaryAndContentExamAnnouncement (char *SummaryStr,char **ContentSt /***** Summary *****/ /* Name of the course */ if (MaxChars) - Str_LimitLengthHTMLStr (Gbl.ExamAnnouncements.ExaDat.CrsFullName, + Str_LimitLengthHTMLStr (Gbl.ExamAnns.ExaDat.CrsFullName, MaxChars-(2+Cns_MAX_LENGTH_DATE+6)); /* Date of exam */ sprintf (SummaryStr,"%s, %04u-%02u-%02u %2u:%02u", - Gbl.ExamAnnouncements.ExaDat.CrsFullName, - Gbl.ExamAnnouncements.ExaDat.ExamDate.Year, - Gbl.ExamAnnouncements.ExaDat.ExamDate.Month, - Gbl.ExamAnnouncements.ExaDat.ExamDate.Day, - Gbl.ExamAnnouncements.ExaDat.StartTime.Hour, - Gbl.ExamAnnouncements.ExaDat.StartTime.Minute); + Gbl.ExamAnns.ExaDat.CrsFullName, + Gbl.ExamAnns.ExaDat.ExamDate.Year, + Gbl.ExamAnns.ExaDat.ExamDate.Month, + Gbl.ExamAnns.ExaDat.ExamDate.Day, + Gbl.ExamAnns.ExaDat.StartTime.Hour, + Gbl.ExamAnns.ExaDat.StartTime.Minute); /***** Free memory of the exam announcement *****/ Exa_FreeMemExamAnnouncement (); @@ -1703,7 +1691,7 @@ static void Exa_GetNotifContentExamAnnouncement (char **ContentStr) (*ContentStr)[0] = '\0'; // Return nothing on error /***** Get data of course *****/ - Crs.CrsCod = Gbl.ExamAnnouncements.ExaDat.CrsCod; + Crs.CrsCod = Gbl.ExamAnns.ExaDat.CrsCod; Crs_GetDataOfCourseByCod (&Crs); /***** Get data of degree *****/ @@ -1714,7 +1702,7 @@ static void Exa_GetNotifContentExamAnnouncement (char **ContentStr) Ins.InsCod = Deg_GetInsCodOfDegreeByCod (Deg.DegCod); Ins_GetDataOfInstitutionByCod (&Ins,Ins_GET_BASIC_DATA); - Dat_ConvDateToDateStr (&Gbl.ExamAnnouncements.ExaDat.ExamDate,StrExamDate); + Dat_ConvDateToDateStr (&Gbl.ExamAnns.ExaDat.ExamDate,StrExamDate); /***** Institution *****/ sprintf (*ContentStr,"%s: %s<br />" @@ -1734,21 +1722,21 @@ static void Exa_GetNotifContentExamAnnouncement (char **ContentStr) "%s: %s", Txt_Institution,Ins.FullName, Txt_Degree,Deg.FullName, - Txt_EXAM_ANNOUNCEMENT_Course,Gbl.ExamAnnouncements.ExaDat.CrsFullName, - Txt_EXAM_ANNOUNCEMENT_Year_or_semester,Txt_YEAR_OF_DEGREE[Gbl.ExamAnnouncements.ExaDat.Year], - Txt_EXAM_ANNOUNCEMENT_Session,Gbl.ExamAnnouncements.ExaDat.Session, + Txt_EXAM_ANNOUNCEMENT_Course,Gbl.ExamAnns.ExaDat.CrsFullName, + Txt_EXAM_ANNOUNCEMENT_Year_or_semester,Txt_YEAR_OF_DEGREE[Gbl.ExamAnns.ExaDat.Year], + Txt_EXAM_ANNOUNCEMENT_Session,Gbl.ExamAnns.ExaDat.Session, Txt_EXAM_ANNOUNCEMENT_Exam_date,StrExamDate, - Txt_EXAM_ANNOUNCEMENT_Start_time,Gbl.ExamAnnouncements.ExaDat.StartTime.Hour, - Gbl.ExamAnnouncements.ExaDat.StartTime.Minute, + Txt_EXAM_ANNOUNCEMENT_Start_time,Gbl.ExamAnns.ExaDat.StartTime.Hour, + Gbl.ExamAnns.ExaDat.StartTime.Minute, Txt_hours_ABBREVIATION, - Txt_EXAM_ANNOUNCEMENT_Approximate_duration,Gbl.ExamAnnouncements.ExaDat.Duration.Hour, - Gbl.ExamAnnouncements.ExaDat.Duration.Minute, + Txt_EXAM_ANNOUNCEMENT_Approximate_duration,Gbl.ExamAnns.ExaDat.Duration.Hour, + Gbl.ExamAnns.ExaDat.Duration.Minute, Txt_hours_ABBREVIATION, - Txt_EXAM_ANNOUNCEMENT_Place_of_exam,Gbl.ExamAnnouncements.ExaDat.Place, - Txt_EXAM_ANNOUNCEMENT_Mode,Gbl.ExamAnnouncements.ExaDat.Mode, - Txt_EXAM_ANNOUNCEMENT_Structure_of_the_exam,Gbl.ExamAnnouncements.ExaDat.Structure, - Txt_EXAM_ANNOUNCEMENT_Documentation_required,Gbl.ExamAnnouncements.ExaDat.DocRequired, - Txt_EXAM_ANNOUNCEMENT_Material_required,Gbl.ExamAnnouncements.ExaDat.MatRequired, - Txt_EXAM_ANNOUNCEMENT_Material_allowed,Gbl.ExamAnnouncements.ExaDat.MatAllowed, - Txt_EXAM_ANNOUNCEMENT_Other_information,Gbl.ExamAnnouncements.ExaDat.OtherInfo); + Txt_EXAM_ANNOUNCEMENT_Place_of_exam,Gbl.ExamAnns.ExaDat.Place, + Txt_EXAM_ANNOUNCEMENT_Mode,Gbl.ExamAnns.ExaDat.Mode, + Txt_EXAM_ANNOUNCEMENT_Structure_of_the_exam,Gbl.ExamAnns.ExaDat.Structure, + Txt_EXAM_ANNOUNCEMENT_Documentation_required,Gbl.ExamAnns.ExaDat.DocRequired, + Txt_EXAM_ANNOUNCEMENT_Material_required,Gbl.ExamAnns.ExaDat.MatRequired, + Txt_EXAM_ANNOUNCEMENT_Material_allowed,Gbl.ExamAnns.ExaDat.MatAllowed, + Txt_EXAM_ANNOUNCEMENT_Other_information,Gbl.ExamAnns.ExaDat.OtherInfo); } diff --git a/swad_file.c b/swad_file.c index 22b86ac6..80342ac8 100644 --- a/swad_file.c +++ b/swad_file.c @@ -322,8 +322,7 @@ void Fil_CreateUpdateFile (const char *CurrentName,const char *ExtensionOldName, { size_t LengthFileRoot = Str_GetLengthRootFileName (CurrentName); - strncpy (NewName,CurrentName,LengthFileRoot); - NewName[LengthFileRoot] = '\0'; + Str_Copy (NewName,CurrentName,LengthFileRoot); sprintf (OldName,"%s%s",NewName,ExtensionOldName); strcat (NewName,".new"); diff --git a/swad_file_browser.c b/swad_file_browser.c index 084b9397..1fd37a59 100644 --- a/swad_file_browser.c +++ b/swad_file_browser.c @@ -2384,15 +2384,10 @@ static void Brw_GetDataCurrentGrp (void) if (Gbl.CurrentCrs.Grps.GrpCod > 0) { Gbl.CurrentCrs.Grps.GrpTyp.GrpTypCod = GrpDat.GrpTypCod; - - strncpy (Gbl.CurrentCrs.Grps.GrpTyp.GrpTypName,GrpDat.GrpTypName, - Grp_MAX_LENGTH_GROUP_TYPE_NAME); - Gbl.CurrentCrs.Grps.GrpTyp.GrpTypName[Grp_MAX_LENGTH_GROUP_TYPE_NAME] = '\0'; - - strncpy (Gbl.CurrentCrs.Grps.GrpName,GrpDat.GrpName, - Grp_MAX_LENGTH_GROUP_NAME); - Gbl.CurrentCrs.Grps.GrpName[Grp_MAX_LENGTH_GROUP_NAME] = '\0'; - + Str_Copy (Gbl.CurrentCrs.Grps.GrpTyp.GrpTypName,GrpDat.GrpTypName, + Grp_MAX_LENGTH_GROUP_TYPE_NAME); + Str_Copy (Gbl.CurrentCrs.Grps.GrpName,GrpDat.GrpName, + Grp_MAX_LENGTH_GROUP_NAME); Gbl.CurrentCrs.Grps.MaxStudents = GrpDat.MaxStudents; Gbl.CurrentCrs.Grps.Open = GrpDat.Open; Gbl.CurrentCrs.Grps.FileZones = GrpDat.FileZones; @@ -2508,11 +2503,9 @@ static void Brw_GetParamsPathInTreeAndFileName (void) Gbl.FileBrowser.Type == Brw_ADMI_ASSIG_CRS)) { if (Gbl.FileBrowser.Level == 1) - { // We are in this case: assignments/assignment-folder - strncpy (Gbl.FileBrowser.Asg.Folder,Gbl.FileBrowser.FilFolLnkName,Asg_MAX_LENGTH_FOLDER); - Gbl.FileBrowser.Asg.Folder[Asg_MAX_LENGTH_FOLDER] = '\0'; - } + Str_Copy (Gbl.FileBrowser.Asg.Folder,Gbl.FileBrowser.FilFolLnkName, + Asg_MAX_LENGTH_FOLDER); else { // We are in this case: assignments/assignment-folder/rest-of-path @@ -2612,9 +2605,8 @@ static void Brw_SetPathFileBrowser (void) case Brw_ADMI_SHARE_CRS: case Brw_SHOW_MARKS_CRS: case Brw_ADMI_MARKS_CRS: - strncpy (Gbl.FileBrowser.Priv.PathAboveRootFolder, - Gbl.CurrentCrs.PathPriv,PATH_MAX); - Gbl.FileBrowser.Priv.PathAboveRootFolder[PATH_MAX] = '\0'; + Str_Copy (Gbl.FileBrowser.Priv.PathAboveRootFolder, + Gbl.CurrentCrs.PathPriv,PATH_MAX); break; case Brw_SHOW_DOCUM_GRP: case Brw_ADMI_DOCUM_GRP: @@ -2664,9 +2656,8 @@ static void Brw_SetPathFileBrowser (void) } break; case Brw_ADMI_BRIEF_USR: - strncpy (Gbl.FileBrowser.Priv.PathAboveRootFolder, - Gbl.Usrs.Me.PathDir,PATH_MAX); - Gbl.FileBrowser.Priv.PathAboveRootFolder[PATH_MAX] = '\0'; + Str_Copy (Gbl.FileBrowser.Priv.PathAboveRootFolder, + Gbl.Usrs.Me.PathDir,PATH_MAX); break; default: return; @@ -4807,10 +4798,7 @@ void Brw_CreateDirDownloadTmp (void) if (NumDir) sprintf (Gbl.FileBrowser.TmpPubDir,"%s_%u",Gbl.UniqueNameEncrypted,NumDir); else - { - strncpy (Gbl.FileBrowser.TmpPubDir,Gbl.UniqueNameEncrypted,NAME_MAX); - Gbl.FileBrowser.TmpPubDir[NAME_MAX] = '\0'; - } + Str_Copy (Gbl.FileBrowser.TmpPubDir,Gbl.UniqueNameEncrypted,NAME_MAX); sprintf (PathPubDirTmp,"%s/%s",PathFileBrowserTmpPubl,Gbl.FileBrowser.TmpPubDir); if (mkdir (PathPubDirTmp,(mode_t) 0xFFF)) Lay_ShowErrorAndExit ("Can not create a temporary folder for download."); @@ -5219,8 +5207,7 @@ static bool Brw_WriteRowFileBrowser (unsigned Level,Brw_ExpandTree_t ExpandTree, { if (Level == 1) // Main folder of the assignment { - strncpy (Gbl.FileBrowser.Asg.Folder,FileName,Asg_MAX_LENGTH_FOLDER); - Gbl.FileBrowser.Asg.Folder[Asg_MAX_LENGTH_FOLDER] = '\0'; + Str_Copy (Gbl.FileBrowser.Asg.Folder,FileName,Asg_MAX_LENGTH_FOLDER); Asg_GetDataOfAssignmentByFolder (&Gbl.FileBrowser.Asg); // The data of this assignment remains in Gbl.FileBrowser.Asg // for all subsequent rows with Level > 1 (files or folders inside this folder), @@ -5356,11 +5343,8 @@ void Brw_SetFullPathInTree (const char *PathInTreeUntilFileOrFolder,const char * sprintf (Gbl.FileBrowser.Priv.FullPathInTree,"%s/%s", PathInTreeUntilFileOrFolder,FilFolLnkName); else // It's the root folder - { - strncpy (Gbl.FileBrowser.Priv.FullPathInTree, - PathInTreeUntilFileOrFolder,PATH_MAX); - Gbl.FileBrowser.Priv.FullPathInTree[PATH_MAX] = '\0'; - } + Str_Copy (Gbl.FileBrowser.Priv.FullPathInTree, + PathInTreeUntilFileOrFolder,PATH_MAX); } /*****************************************************************************/ @@ -6013,8 +5997,7 @@ static void Brw_LimitLengthFileNameToShow (Brw_FileType_t FileType,const char *F NumCharsToCopy -= 4; // Remove .url if (NumCharsToCopy > NAME_MAX) NumCharsToCopy = NAME_MAX; - strncpy (FileNameToShow,FileName,NumCharsToCopy); - FileNameToShow[NumCharsToCopy] = '\0'; + Str_Copy (FileNameToShow,FileName,NumCharsToCopy); Str_LimitLengthHTMLStr (FileNameToShow,60); } @@ -6724,8 +6707,7 @@ static bool Brw_GetMyClipboard (void) Gbl.FileBrowser.Clipboard.FileType = (Brw_FileType_t) UnsignedNum; /* Get file path (row[4]) */ - strncpy (Gbl.FileBrowser.Clipboard.Path,row[4],PATH_MAX); - Gbl.FileBrowser.Clipboard.Path[PATH_MAX] = '\0'; + Str_Copy (Gbl.FileBrowser.Clipboard.Path,row[4],PATH_MAX); Str_SplitFullPathIntoPathAndFileName (Gbl.FileBrowser.Clipboard.Path, PathUntilFileName, Gbl.FileBrowser.Clipboard.FileName); @@ -6920,8 +6902,7 @@ static void Brw_InsFoldersInPathAndUpdOtherFoldersInExpandedFolders (const char // if (strcmp (Path,Brw_RootFolderInternalNames[Gbl.FileBrowser.Type])) // Don't insert root folder /***** Make a copy to keep Path unchanged *****/ - strncpy (CopyOfPath,Path,PATH_MAX); - CopyOfPath[PATH_MAX] = '\0'; + Str_Copy (CopyOfPath,Path,PATH_MAX); /***** Insert paths in table of expanded folders if they are not yet there *****/ do @@ -7689,10 +7670,7 @@ static bool Brw_PasteTreeIntoFolder (unsigned LevelOrg, if (LevelOrg == 0) // Origin of copy is the root folder, // for example "sha" // ==> do not copy the root folder itself into destination - { - strncpy (PathDstInTreeWithFile,PathDstInTree,PATH_MAX); - PathDstInTreeWithFile[PATH_MAX] = '\0'; - } + Str_Copy (PathDstInTreeWithFile,PathDstInTree,PATH_MAX); else // Origin of copy is a file or folder inside the root folder // for example "sha/folder1/file1" sprintf (PathDstInTreeWithFile,"%s/%s",PathDstInTree,FileNameOrg); @@ -8417,15 +8395,15 @@ static bool Brw_RcvFileInFileBrw (Brw_UploadType_t UploadType) char PathUntilFileName[PATH_MAX+1]; char Path[PATH_MAX+1]; char PathTmp[PATH_MAX+1]; - char PathCompleteInTreeIncludingFile[PATH_MAX+1]; - char MIMEType[Brw_MAX_BYTES_MIME_TYPE+1]; + char PathCompleteInTreeIncludingFile[PATH_MAX + 1]; + char MIMEType[Brw_MAX_BYTES_MIME_TYPE + 1]; bool AdminMarks; bool FileIsValid = true; long FilCod = -1L; // Code of new file in database struct FileMetadata FileMetadata; struct MarksProperties Marks; unsigned NumUsrsToBeNotifiedByEMail; - char FileNameToShow[NAME_MAX+1]; + char FileNameToShow[NAME_MAX + 1]; bool UploadSucessful = false; /***** Get parameters related to file browser *****/ @@ -8573,18 +8551,12 @@ static bool Brw_RcvFileInFileBrw (Brw_UploadType_t UploadType) } } else // Empty filename - { - strncpy (Gbl.Message,Txt_UPLOAD_FILE_You_must_specify_the_file_NO_HTML, - Lay_MAX_BYTES_ALERT); - Gbl.Message[Lay_MAX_BYTES_ALERT] = '\0'; - } + Str_Copy (Gbl.Message,Txt_UPLOAD_FILE_You_must_specify_the_file_NO_HTML, + Lay_MAX_BYTES_ALERT); } else // I do not have permission to create files here - { - strncpy (Gbl.Message,Txt_UPLOAD_FILE_Forbidden_NO_HTML, - Lay_MAX_BYTES_ALERT); - Gbl.Message[Lay_MAX_BYTES_ALERT] = '\0'; - } + Str_Copy (Gbl.Message,Txt_UPLOAD_FILE_Forbidden_NO_HTML, + Lay_MAX_BYTES_ALERT); return UploadSucessful; } @@ -8630,7 +8602,7 @@ void Brw_RecLinkFileBrowser (void) Name given by me: intel-architectures.pdf File in swad: intel-architectures.pdf.url */ - strncpy (URLWithoutEndingSlash,Gbl.FileBrowser.NewFilFolLnkName,PATH_MAX); + Str_Copy (URLWithoutEndingSlash,Gbl.FileBrowser.NewFilFolLnkName,PATH_MAX); else /* Gbl.FileBrowser.NewFilFolLnkName is empty @@ -8639,8 +8611,7 @@ void Brw_RecLinkFileBrowser (void) URL: http://www.intel.es/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-manual-325462.pdf File in swad: 64-ia-32-architectures-software-developer-manual-325462.pdf.url */ - strncpy (URLWithoutEndingSlash,URL,PATH_MAX); - URLWithoutEndingSlash[PATH_MAX] = '\0'; + Str_Copy (URLWithoutEndingSlash,URL,PATH_MAX); /* Remove possible final '/' from URL */ if (URLWithoutEndingSlash[LengthURL - 1] == '/') @@ -9997,8 +9968,7 @@ void Brw_GetFileMetadataByPath (struct FileMetadata *FileMetadata) FileMetadata->FileType = (Brw_FileType_t) UnsignedNum; /* Get path (row[6]) */ - strncpy (FileMetadata->FullPathInTree,row[6],PATH_MAX); - FileMetadata->FullPathInTree[PATH_MAX] = '\0'; + Str_Copy (FileMetadata->FullPathInTree,row[6],PATH_MAX); Str_SplitFullPathIntoPathAndFileName (FileMetadata->FullPathInTree, FileMetadata->PathInTreeUntilFilFolLnk, FileMetadata->FilFolLnkName); @@ -10127,8 +10097,7 @@ void Brw_GetFileMetadataByCod (struct FileMetadata *FileMetadata) FileMetadata->FileType = (Brw_FileType_t) UnsignedNum; /* Get path (row[6]) */ - strncpy (FileMetadata->FullPathInTree,row[6],PATH_MAX); - FileMetadata->FullPathInTree[PATH_MAX] = '\0'; + Str_Copy (FileMetadata->FullPathInTree,row[6],PATH_MAX); Str_SplitFullPathIntoPathAndFileName (FileMetadata->FullPathInTree, FileMetadata->PathInTreeUntilFilFolLnk, FileMetadata->FilFolLnkName); @@ -11189,8 +11158,7 @@ void Brw_GetSummaryAndContentOfFile (char SummaryStr[Cns_MAX_BYTES_TEXT + 1],cha Brw_GetFileMetadataByCod (&FileMetadata); /***** Copy file name into summary string *****/ - strncpy (SummaryStr,FileMetadata.FilFolLnkName,Cns_MAX_BYTES_TEXT); - SummaryStr[Cns_MAX_BYTES_TEXT] = '\0'; + Str_Copy (SummaryStr,FileMetadata.FilFolLnkName,Cns_MAX_BYTES_TEXT); if (MaxChars) Str_LimitLengthHTMLStr (SummaryStr,MaxChars); diff --git a/swad_file_browser.h b/swad_file_browser.h index d6f2924c..0f274da8 100644 --- a/swad_file_browser.h +++ b/swad_file_browser.h @@ -136,7 +136,9 @@ struct FileMetadata #define Brw_MAX_DIR_LEVELS 10 // Maximum number of subdirectory levels in file browsers -#define Brw_MAX_BYTES_MIME_TYPE 256 // Maximum length of "image/jpeg", "text/html", etc. +#define Brw_MAX_BYTES_MIME_TYPE (256 - 1) // Maximum length of "image/jpeg", "text/html", etc. + +#define Brw_MAX_LENGTH_LICENSE (256 - 1) #define Brw_INTERNAL_NAME_ROOT_FOLDER_DOCUMENTS "doc" #define Brw_INTERNAL_NAME_ROOT_FOLDER_SHARED_FILES "sha" diff --git a/swad_forum.c b/swad_forum.c index 090be840..98f04ff6 100644 --- a/swad_forum.c +++ b/swad_forum.c @@ -676,8 +676,7 @@ static void For_GetThrSubject (long ThrCod,char *Subject,size_t MaxSize) /***** Write the subject of the thread *****/ row = mysql_fetch_row (mysql_res); - strncpy (Subject,row[0],MaxSize); - Subject[MaxSize] = '\0'; + Str_Copy (Subject,row[0],MaxSize); Str_LimitLengthHTMLStr (Subject,20); /***** Free structure that stores the query result *****/ @@ -1193,11 +1192,8 @@ static void For_ShowAForumPost (struct ForumThread *Thr,unsigned PstNum,long Pst Subject,OriginalContent,&Image); if (Enabled) - { /* Return this subject as last subject */ - strncpy (LastSubject,Subject,Cns_MAX_BYTES_SUBJECT); - LastSubject[Cns_MAX_BYTES_SUBJECT] = '\0'; - } + Str_Copy (LastSubject,Subject,Cns_MAX_BYTES_SUBJECT); /***** Put an icon with post status *****/ fprintf (Gbl.F.Out,"<tr>" @@ -1323,8 +1319,7 @@ static void For_ShowAForumPost (struct ForumThread *Thr,unsigned PstNum,long Pst "<td class=\"MSG_TXT LEFT_TOP\">"); if (Enabled) { - strncpy (Content,OriginalContent,Cns_MAX_BYTES_LONG_TEXT); - Content[Cns_MAX_BYTES_LONG_TEXT] = '\0'; + Str_Copy (Content,OriginalContent,Cns_MAX_BYTES_LONG_TEXT); Msg_WriteMsgContent (Content,Cns_MAX_BYTES_LONG_TEXT,true,false); /***** Show image *****/ @@ -1375,12 +1370,10 @@ static void For_GetPstData (long PstCod,long *UsrCod,time_t *CreatTimeUTC, *CreatTimeUTC = Dat_GetUNIXTimeFromStr (row[1]); /****** Get subject (row[2]) *****/ - strncpy (Subject,row[2],Cns_MAX_BYTES_SUBJECT); - Subject[Cns_MAX_BYTES_SUBJECT] = '\0'; + Str_Copy (Subject,row[2],Cns_MAX_BYTES_SUBJECT); /****** Get location (row[3]) *****/ - strncpy (Content,row[3],Cns_MAX_BYTES_LONG_TEXT); - Content[Cns_MAX_BYTES_LONG_TEXT] = '\0'; + Str_Copy (Content,row[3],Cns_MAX_BYTES_LONG_TEXT); /****** Get image name (row[4]), title (row[5]) and URL (row[6]) *****/ Img_GetImageNameTitleAndURLFromRow (row[4],row[5],row[6],Image); @@ -1419,9 +1412,7 @@ void For_GetSummaryAndContentForumPst (char SummaryStr[Cns_MAX_BYTES_TEXT + 1], row = mysql_fetch_row (mysql_res); /***** Copy subject *****/ - strncpy (SummaryStr,row[0],Cns_MAX_BYTES_TEXT); - SummaryStr[Cns_MAX_BYTES_TEXT] = '\0'; - + Str_Copy (SummaryStr,row[0],Cns_MAX_BYTES_TEXT); if (MaxChars) Str_LimitLengthHTMLStr (SummaryStr,MaxChars); @@ -1433,8 +1424,7 @@ void For_GetSummaryAndContentForumPst (char SummaryStr[Cns_MAX_BYTES_TEXT + 1], if ((*ContentStr = (char *) malloc (Length + 1)) == NULL) Lay_ShowErrorAndExit ("Error allocating memory for notification content."); - strncpy (*ContentStr,row[1],Length); - (*ContentStr)[Length] = '\0'; + Str_Copy (*ContentStr,row[1],Length); } } mysql_free_result (mysql_res); @@ -2201,8 +2191,7 @@ void For_SetForumName (For_ForumType_t ForumType, switch (ForumType) { case For_FORUM_COURSE_USRS: - strncpy (ForumName,Crs->ShrtName,For_MAX_BYTES_FORUM_NAME); - ForumName[For_MAX_BYTES_FORUM_NAME] = '\0'; + Str_Copy (ForumName,Crs->ShrtName,For_MAX_BYTES_FORUM_NAME); break; case For_FORUM_COURSE_TCHS: sprintf (ForumName,"%s%s",Crs->ShrtName, @@ -2210,8 +2199,7 @@ void For_SetForumName (For_ForumType_t ForumType, Txt_only_teachers_NO_HTML[Language]); break; case For_FORUM_DEGREE_USRS: - strncpy (ForumName,Deg->ShrtName,For_MAX_BYTES_FORUM_NAME); - ForumName[For_MAX_BYTES_FORUM_NAME] = '\0'; + Str_Copy (ForumName,Deg->ShrtName,For_MAX_BYTES_FORUM_NAME); break; case For_FORUM_DEGREE_TCHS: sprintf (ForumName,"%s%s",Deg->ShrtName, @@ -2219,8 +2207,7 @@ void For_SetForumName (For_ForumType_t ForumType, Txt_only_teachers_NO_HTML[Language]); break; case For_FORUM_CENTRE_USRS: - strncpy (ForumName,Ctr->ShrtName,For_MAX_BYTES_FORUM_NAME); - ForumName[For_MAX_BYTES_FORUM_NAME] = '\0'; + Str_Copy (ForumName,Ctr->ShrtName,For_MAX_BYTES_FORUM_NAME); break; case For_FORUM_CENTRE_TCHS: sprintf (ForumName,"%s%s",Ctr->ShrtName, @@ -2228,8 +2215,7 @@ void For_SetForumName (For_ForumType_t ForumType, Txt_only_teachers_NO_HTML[Language]); break; case For_FORUM_INSTIT_USRS: - strncpy (ForumName,Ins->ShrtName,For_MAX_BYTES_FORUM_NAME); - ForumName[For_MAX_BYTES_FORUM_NAME] = '\0'; + Str_Copy (ForumName,Ins->ShrtName,For_MAX_BYTES_FORUM_NAME); break; case For_FORUM_INSTIT_TCHS: sprintf (ForumName,"%s%s",Ins->ShrtName, @@ -2237,10 +2223,9 @@ void For_SetForumName (For_ForumType_t ForumType, Txt_only_teachers_NO_HTML[Language]); break; case For_FORUM_GLOBAL_USRS: - strncpy (ForumName,UseHTMLEntities ? Txt_General : + Str_Copy (ForumName,UseHTMLEntities ? Txt_General : Txt_General_NO_HTML[Language], - For_MAX_BYTES_FORUM_NAME); - ForumName[For_MAX_BYTES_FORUM_NAME] = '\0'; + For_MAX_BYTES_FORUM_NAME); break; case For_FORUM_GLOBAL_TCHS: sprintf (ForumName,"%s%s", @@ -2250,8 +2235,7 @@ void For_SetForumName (For_ForumType_t ForumType, Txt_only_teachers_NO_HTML[Language]); break; case For_FORUM_SWAD_USRS: - strncpy (ForumName,Cfg_PLATFORM_SHORT_NAME,For_MAX_BYTES_FORUM_NAME); - ForumName[For_MAX_BYTES_FORUM_NAME] = '\0'; + Str_Copy (ForumName,Cfg_PLATFORM_SHORT_NAME,For_MAX_BYTES_FORUM_NAME); break; case For_FORUM_SWAD_TCHS: sprintf (ForumName,"%s%s",Cfg_PLATFORM_SHORT_NAME, @@ -3613,8 +3597,7 @@ void For_GetThrData (struct ForumThread *Thr) Thr->WriteTime[For_LAST_MSG ] = Dat_GetUNIXTimeFromStr (row[5]); /***** Get the subject of this thread (row[6]) *****/ - strncpy (Thr->Subject,row[6],Cns_MAX_BYTES_SUBJECT); - Thr->Subject[Cns_MAX_BYTES_SUBJECT] = '\0'; + Str_Copy (Thr->Subject,row[6],Cns_MAX_BYTES_SUBJECT); if (!Thr->Subject[0]) sprintf (Thr->Subject,"[%s]",Txt_no_subject); diff --git a/swad_global.c b/swad_global.c index 06c943d8..4d364d97 100644 --- a/swad_global.c +++ b/swad_global.c @@ -191,10 +191,10 @@ void Gbl_InitializeGlobals (void) Gbl.Usrs.LstUsrs[Role].NumUsrs = 0; } - Gbl.ExamAnnouncements.NumExaAnns = 0; - Gbl.ExamAnnouncements.Lst = NULL; - Gbl.ExamAnnouncements.HighlightExaCod = -1L; - Gbl.ExamAnnouncements.HighlightDate[0] = '\0'; // No exam announcements highlighted + Gbl.ExamAnns.NumExaAnns = 0; + Gbl.ExamAnns.Lst = NULL; + Gbl.ExamAnns.HighlightExaCod = -1L; + Gbl.ExamAnns.HighlightDate[0] = '\0'; // No exam announcements highlighted Gbl.Usrs.Select.All = Gbl.Usrs.Select.Std = diff --git a/swad_global.h b/swad_global.h index 7ac4a05d..30a4a668 100644 --- a/swad_global.h +++ b/swad_global.h @@ -493,7 +493,7 @@ struct Globals char HighlightDate[4+1+2+1+2+1]; // Date with exam announcements to be highlighted (in YYYY-MM-DD format) struct ExamData ExaDat; bool NewExamAnnouncement; - } ExamAnnouncements; + } ExamAnns; struct { unsigned Id; // Each file browser in the page has a unique identifier diff --git a/swad_group.c b/swad_group.c index 6f63a2af..0e756ef2 100644 --- a/swad_group.c +++ b/swad_group.c @@ -2367,7 +2367,8 @@ void Grp_GetListGrpTypesInThisCrs (Grp_WhichGroupTypes_t WhichGroupTypes) Lay_ShowErrorAndExit ("Wrong type of group."); /* Get group type name (row[1]) */ - strncpy (Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumRow].GrpTypName,row[1],Grp_MAX_LENGTH_GROUP_TYPE_NAME); + Str_Copy (Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumRow].GrpTypName,row[1], + Grp_MAX_LENGTH_GROUP_TYPE_NAME); /* Is it mandatory to register in any groups of this type? (row[2]) */ Gbl.CurrentCrs.Grps.GrpTypes.LstGrpTypes[NumRow].MandatoryEnrollment = (row[2][0] == 'Y'); @@ -2497,8 +2498,7 @@ void Grp_GetListGrpTypesAndGrpsInThisCrs (Grp_WhichGroupTypes_t WhichGroupTypes) Lay_ShowErrorAndExit ("Wrong code of group."); /* Get group name (row[1]) */ - strncpy (Grp->GrpName,row[1],Grp_MAX_LENGTH_GROUP_NAME); - Grp->GrpName[Grp_MAX_LENGTH_GROUP_NAME] = '\0'; + Str_Copy (Grp->GrpName,row[1],Grp_MAX_LENGTH_GROUP_NAME); /* Get max number of students of group (row[2]) and number of current students */ Grp->MaxStudents = Grp_ConvertToNumMaxStdsGrp (row[2]); @@ -2626,8 +2626,7 @@ static void Grp_GetDataOfGroupTypeByCod (struct GroupType *GrpTyp) /***** Get some data of group type *****/ row = mysql_fetch_row (mysql_res); - strncpy (GrpTyp->GrpTypName,row[0],Grp_MAX_LENGTH_GROUP_TYPE_NAME); - GrpTyp->GrpTypName[Grp_MAX_LENGTH_GROUP_TYPE_NAME] = '\0'; + Str_Copy (GrpTyp->GrpTypName,row[0],Grp_MAX_LENGTH_GROUP_TYPE_NAME); GrpTyp->MandatoryEnrollment = (row[1][0] == 'Y'); GrpTyp->MultipleEnrollment = (row[2][0] == 'Y'); GrpTyp->MustBeOpened = (row[3][0] == 'Y'); @@ -2713,15 +2712,13 @@ void Grp_GetDataOfGroupByCod (struct GroupData *GrpDat) Lay_ShowErrorAndExit ("Wrong code of course."); /* Get the name of the group type (row[2]) */ - strncpy (GrpDat->GrpTypName,row[2],Grp_MAX_LENGTH_GROUP_TYPE_NAME); - GrpDat->GrpTypName[Grp_MAX_LENGTH_GROUP_TYPE_NAME] = '\0'; + Str_Copy (GrpDat->GrpTypName,row[2],Grp_MAX_LENGTH_GROUP_TYPE_NAME); /* Get whether a student may be in one or multiple groups (row[3]) */ GrpDat->MultipleEnrollment = (row[3][0] == 'Y'); /* Get the name of the group (row[4]) */ - strncpy (GrpDat->GrpName,row[4],Grp_MAX_LENGTH_GROUP_NAME); - GrpDat->GrpName[Grp_MAX_LENGTH_GROUP_NAME] = '\0'; + Str_Copy (GrpDat->GrpName,row[4],Grp_MAX_LENGTH_GROUP_NAME); /* Get maximum number of students (row[5]) */ GrpDat->MaxStudents = Grp_ConvertToNumMaxStdsGrp (row[5]); @@ -4018,9 +4015,8 @@ void Grp_RenameGroupType (void) } /***** Show the form again *****/ - strncpy (Gbl.CurrentCrs.Grps.GrpTyp.GrpTypName,NewNameGrpTyp, - Grp_MAX_LENGTH_GROUP_TYPE_NAME); - Gbl.CurrentCrs.Grps.GrpTyp.GrpTypName[Grp_MAX_LENGTH_GROUP_TYPE_NAME] = '\0'; + Str_Copy (Gbl.CurrentCrs.Grps.GrpTyp.GrpTypName,NewNameGrpTyp, + Grp_MAX_LENGTH_GROUP_TYPE_NAME); Grp_ReqEditGroups (); } @@ -4091,8 +4087,7 @@ void Grp_RenameGroup (void) } /***** Show the form again *****/ - strncpy (Gbl.CurrentCrs.Grps.GrpName,NewNameGrp,Grp_MAX_LENGTH_GROUP_NAME); - Gbl.CurrentCrs.Grps.GrpName[Grp_MAX_LENGTH_GROUP_NAME] = '\0'; + Str_Copy (Gbl.CurrentCrs.Grps.GrpName,NewNameGrp,Grp_MAX_LENGTH_GROUP_NAME); Grp_ReqEditGroups (); } diff --git a/swad_holiday.c b/swad_holiday.c index dcaf8661..df3efc3c 100644 --- a/swad_holiday.c +++ b/swad_holiday.c @@ -312,8 +312,7 @@ void Hld_GetListHolidays (void) Hld->PlcCod = Str_ConvertStrCodToLongCod (row[1]); /* Get the full name of the place (row[2]) */ - strncpy (Hld->PlaceFullName,row[2],Plc_MAX_LENGTH_PLACE_FULL_NAME); - Hld->PlaceFullName[Plc_MAX_LENGTH_PLACE_FULL_NAME] = '\0'; + Str_Copy (Hld->PlaceFullName,row[2],Plc_MAX_LENGTH_PLACE_FULL_NAME); /* Get type (row[3]) */ Hld->HldTyp = Hld_GetTypeOfHoliday (row[3]); @@ -337,8 +336,7 @@ void Hld_GetListHolidays (void) } /* Get the name of the holiday/non school period (row[6]) */ - strncpy (Hld->Name,row[6],Hld_MAX_LENGTH_HOLIDAY_NAME); - Hld->Name[Hld_MAX_LENGTH_HOLIDAY_NAME] = '\0'; + Str_Copy (Hld->Name,row[6],Hld_MAX_LENGTH_HOLIDAY_NAME); } } @@ -404,8 +402,7 @@ static void Hld_GetDataOfHolidayByCod (struct Holiday *Hld) Hld->PlcCod = Str_ConvertStrCodToLongCod (row[0]); /* Get the full name of the place (row[1]) */ - strncpy (Hld->PlaceFullName,row[1],Plc_MAX_LENGTH_PLACE_FULL_NAME); - Hld->PlaceFullName[Plc_MAX_LENGTH_PLACE_FULL_NAME] = '\0'; + Str_Copy (Hld->PlaceFullName,row[1],Plc_MAX_LENGTH_PLACE_FULL_NAME); /* Get type (row[2]) */ Hld->HldTyp = Hld_GetTypeOfHoliday (row[2]); @@ -429,8 +426,7 @@ static void Hld_GetDataOfHolidayByCod (struct Holiday *Hld) } /* Get the name of the holiday/non school period (row[5]) */ - strncpy (Hld->Name,row[5],Hld_MAX_LENGTH_HOLIDAY_NAME); - Hld->Name[Hld_MAX_LENGTH_HOLIDAY_NAME] = '\0'; + Str_Copy (Hld->Name,row[5],Hld_MAX_LENGTH_HOLIDAY_NAME); } /***** Free structure that stores the query result *****/ @@ -698,9 +694,7 @@ void Hld_ChangeHolidayPlace (void) /***** Show the form again *****/ Hld->PlcCod = NewPlace.PlcCod; - strncpy (Hld->PlaceFullName,NewPlace.FullName,Plc_MAX_LENGTH_PLACE_FULL_NAME); - Hld->PlaceFullName[Plc_MAX_LENGTH_PLACE_FULL_NAME] = '\0'; - + Str_Copy (Hld->PlaceFullName,NewPlace.FullName,Plc_MAX_LENGTH_PLACE_FULL_NAME); Hld_EditHolidays (); } @@ -895,9 +889,7 @@ void Hld_RenameHoliday (void) } /***** Show the form again *****/ - strncpy (Hld->Name,NewHldName,Hld_MAX_LENGTH_HOLIDAY_NAME); - Hld->Name[Hld_MAX_LENGTH_HOLIDAY_NAME] = '\0'; - + Str_Copy (Hld->Name,NewHldName,Hld_MAX_LENGTH_HOLIDAY_NAME); Hld_EditHolidays (); } diff --git a/swad_image.c b/swad_image.c index ab4be950..c8d7f00a 100644 --- a/swad_image.c +++ b/swad_image.c @@ -143,8 +143,7 @@ void Img_GetImageNameTitleAndURLFromRow (const char *Name, size_t Length; /***** Copy image name to struct *****/ - strncpy (Image->Name,Name,Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64); - Image->Name[Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64] = '\0'; + Str_Copy (Image->Name,Name,Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64); /***** Set status of image file *****/ Image->Status = Image->Name[0] ? Img_NAME_STORED_IN_DB : @@ -164,8 +163,7 @@ void Img_GetImageNameTitleAndURLFromRow (const char *Name, if ((Image->Title = (char *) malloc (Length+1)) == NULL) Lay_ShowErrorAndExit ("Error allocating memory for image title."); - strncpy (Image->Title,Title,Length); - Image->Title[Length] = '\0'; + Str_Copy (Image->Title,Title,Length); } /***** Copy image URL to struct *****/ @@ -181,8 +179,7 @@ void Img_GetImageNameTitleAndURLFromRow (const char *Name, if ((Image->URL = (char *) malloc (Length+1)) == NULL) Lay_ShowErrorAndExit ("Error allocating memory for image URL."); - strncpy (Image->URL,URL,Length); - Image->URL[Length] = '\0'; + Str_Copy (Image->URL,URL,Length); } } @@ -320,8 +317,7 @@ void Img_GetImageFromForm (int NumImgInForm,struct Image *Image, Img_FreeImageTitle (Image); if ((Image->Title = (char *) malloc (Length + 1)) == NULL) Lay_ShowErrorAndExit ("Error allocating memory for image title."); - strncpy (Image->Title,Title,Length); - Image->Title[Length] = '\0'; + Str_Copy (Image->Title,Title,Length); } /***** By last, get image URL from form *****/ @@ -335,8 +331,7 @@ void Img_GetImageFromForm (int NumImgInForm,struct Image *Image, Img_FreeImageURL (Image); if ((Image->URL = (char *) malloc (Length + 1)) == NULL) Lay_ShowErrorAndExit ("Error allocating memory for image URL."); - strncpy (Image->URL,URL,Length); - Image->URL[Length] = '\0'; + Str_Copy (Image->URL,URL,Length); } } @@ -350,17 +345,10 @@ void Img_SetParamNames (struct ParamUploadImg *ParamUploadImg,int NumImgInForm) { if (NumImgInForm < 0) // One unique image in form ==> no suffix needed { - strncpy (ParamUploadImg->Action,"ImgAct",Img_MAX_LENGTH_PARAM_UPLOAD_IMG); - ParamUploadImg->Action[Img_MAX_LENGTH_PARAM_UPLOAD_IMG] = '\0'; - - strncpy (ParamUploadImg->File ,"ImgFil",Img_MAX_LENGTH_PARAM_UPLOAD_IMG); - ParamUploadImg->File [Img_MAX_LENGTH_PARAM_UPLOAD_IMG] = '\0'; - - strncpy (ParamUploadImg->Title ,"ImgTit",Img_MAX_LENGTH_PARAM_UPLOAD_IMG); - ParamUploadImg->Title [Img_MAX_LENGTH_PARAM_UPLOAD_IMG] = '\0'; - - strncpy (ParamUploadImg->URL ,"ImgURL",Img_MAX_LENGTH_PARAM_UPLOAD_IMG); - ParamUploadImg->URL [Img_MAX_LENGTH_PARAM_UPLOAD_IMG] = '\0'; + Str_Copy (ParamUploadImg->Action,"ImgAct",Img_MAX_LENGTH_PARAM_UPLOAD_IMG); + Str_Copy (ParamUploadImg->File ,"ImgFil",Img_MAX_LENGTH_PARAM_UPLOAD_IMG); + Str_Copy (ParamUploadImg->Title ,"ImgTit",Img_MAX_LENGTH_PARAM_UPLOAD_IMG); + Str_Copy (ParamUploadImg->URL ,"ImgURL",Img_MAX_LENGTH_PARAM_UPLOAD_IMG); } else // Several images in form ==> add suffix { @@ -401,7 +389,7 @@ void Img_GetAndProcessImageFileFromForm (struct Image *Image,const char *ParamFi char FileNameImgSrc[PATH_MAX+1]; char *PtrExtension; size_t LengthExtension; - char MIMEType[Brw_MAX_BYTES_MIME_TYPE+1]; + char MIMEType[Brw_MAX_BYTES_MIME_TYPE + 1]; char PathImgPriv[PATH_MAX+1]; char FileNameImgOrig[PATH_MAX+1]; // Full name of original uploaded file char FileNameImgTmp[PATH_MAX+1]; // Full name of temporary processed file diff --git a/swad_info.c b/swad_info.c index 5323a188..f9114df2 100644 --- a/swad_info.c +++ b/swad_info.c @@ -1715,17 +1715,11 @@ static void Inf_GetInfoTxtFromDB (long CrsCod,Inf_InfoType_t InfoType, /* Get text in HTML format (not rigorous) */ if (InfoTxtHTML) - { - strncpy (InfoTxtHTML,row[0],MaxLength); - InfoTxtHTML[MaxLength] = '\0'; - } + Str_Copy (InfoTxtHTML,row[0],MaxLength); /* Get text in Markdown format */ if (InfoTxtMD) - { - strncpy (InfoTxtMD,row[1],MaxLength); - InfoTxtMD[MaxLength] = '\0'; - } + Str_Copy (InfoTxtMD,row[1],MaxLength); } else { @@ -2150,10 +2144,7 @@ void Inf_RecAndChangePlainTxtInfo (void) /***** Get text with course information from form *****/ Par_GetParameter (Par_PARAM_SINGLE,"Txt",Txt_HTMLFormat, Cns_MAX_BYTES_LONG_TEXT,NULL); - - strncpy (Txt_MarkdownFormat,Txt_HTMLFormat,Cns_MAX_BYTES_LONG_TEXT); - Txt_MarkdownFormat[Cns_MAX_BYTES_LONG_TEXT] = '\0'; - + Str_Copy (Txt_MarkdownFormat,Txt_HTMLFormat,Cns_MAX_BYTES_LONG_TEXT); Str_ChangeFormat (Str_FROM_FORM,Str_TO_HTML, Txt_HTMLFormat,Cns_MAX_BYTES_LONG_TEXT,true); // Store in HTML format (not rigorous) Str_ChangeFormat (Str_FROM_FORM,Str_TO_MARKDOWN, @@ -2188,10 +2179,7 @@ void Inf_RecAndChangeRichTxtInfo (void) /***** Get text with course information from form *****/ Par_GetParameter (Par_PARAM_SINGLE,"Txt",Txt_HTMLFormat, Cns_MAX_BYTES_LONG_TEXT,NULL); - - strncpy (Txt_MarkdownFormat,Txt_HTMLFormat,Cns_MAX_BYTES_LONG_TEXT); - Txt_MarkdownFormat[Cns_MAX_BYTES_LONG_TEXT] = '\0'; - + Str_Copy (Txt_MarkdownFormat,Txt_HTMLFormat,Cns_MAX_BYTES_LONG_TEXT); Str_ChangeFormat (Str_FROM_FORM,Str_TO_HTML, Txt_HTMLFormat,Cns_MAX_BYTES_LONG_TEXT,true); // Store in HTML format (not rigorous) Str_ChangeFormat (Str_FROM_FORM,Str_TO_MARKDOWN, @@ -2286,7 +2274,7 @@ void Inf_ReceivePagInfo (void) char PathRelDirHTML[PATH_MAX+1]; char PathRelFileHTML[PATH_MAX+1]; char PathRelFileZIP[PATH_MAX+1]; - char MIMEType[Brw_MAX_BYTES_MIME_TYPE+1]; + char MIMEType[Brw_MAX_BYTES_MIME_TYPE + 1]; char StrUnzip[100+PATH_MAX*2+1]; bool WrongType = false; bool FileIsOK = false; diff --git a/swad_institution.c b/swad_institution.c index d38bcc8c..d15ebb97 100644 --- a/swad_institution.c +++ b/swad_institution.c @@ -1028,16 +1028,13 @@ void Ins_GetListInstitutions (long CtyCod,Ins_GetExtraData_t GetExtraData) Ins->RequesterUsrCod = Str_ConvertStrCodToLongCod (row[3]); /* Get the short name of the institution (row[4]) */ - strncpy (Ins->ShrtName,row[4],Ins_MAX_LENGTH_INSTIT_SHRT_NAME); - Ins->ShrtName[Ins_MAX_LENGTH_INSTIT_SHRT_NAME] = '\0'; + Str_Copy (Ins->ShrtName,row[4],Ins_MAX_LENGTH_INSTIT_SHRT_NAME); /* Get the full name of the institution (row[5]) */ - strncpy (Ins->FullName,row[5],Ins_MAX_LENGTH_INSTIT_FULL_NAME); - Ins->FullName[Ins_MAX_LENGTH_INSTIT_FULL_NAME] = '\0'; + Str_Copy (Ins->FullName,row[5],Ins_MAX_LENGTH_INSTIT_FULL_NAME); /* Get the URL of the institution (row[6]) */ - strncpy (Ins->WWW,row[6],Cns_MAX_LENGTH_WWW); - Ins->WWW[Cns_MAX_LENGTH_WWW] = '\0'; + Str_Copy (Ins->WWW,row[6],Cns_MAX_LENGTH_WWW); /* Get extra data */ switch (GetExtraData) @@ -1125,16 +1122,13 @@ bool Ins_GetDataOfInstitutionByCod (struct Instit *Ins, Ins->RequesterUsrCod = Str_ConvertStrCodToLongCod (row[2]); /* Get the short name of the institution (row[3]) */ - strncpy (Ins->ShrtName,row[3],Ins_MAX_LENGTH_INSTIT_SHRT_NAME); - Ins->ShrtName[Ins_MAX_LENGTH_INSTIT_SHRT_NAME] = '\0'; + Str_Copy (Ins->ShrtName,row[3],Ins_MAX_LENGTH_INSTIT_SHRT_NAME); /* Get the full name of the institution (row[4]) */ - strncpy (Ins->FullName,row[4],Ins_MAX_LENGTH_INSTIT_FULL_NAME); - Ins->FullName[Ins_MAX_LENGTH_INSTIT_FULL_NAME] = '\0'; + Str_Copy (Ins->FullName,row[4],Ins_MAX_LENGTH_INSTIT_FULL_NAME); /* Get the URL of the institution (row[5]) */ - strncpy (Ins->WWW,row[5],Cns_MAX_LENGTH_WWW); - Ins->WWW[Cns_MAX_LENGTH_WWW] = '\0'; + Str_Copy (Ins->WWW,row[5],Cns_MAX_LENGTH_WWW); /* Get extra data */ if (GetExtraData == Ins_GET_EXTRA_DATA) @@ -1184,8 +1178,7 @@ void Ins_GetShortNameOfInstitutionByCod (struct Instit *Ins) /***** Get the short name of this institution *****/ row = mysql_fetch_row (mysql_res); - strncpy (Ins->ShrtName,row[0],Ins_MAX_LENGTH_INSTIT_SHRT_NAME); - Ins->ShrtName[Ins_MAX_LENGTH_INSTIT_SHRT_NAME] = '\0'; + Str_Copy (Ins->ShrtName,row[0],Ins_MAX_LENGTH_INSTIT_SHRT_NAME); } /***** Free structure that stores the query result *****/ @@ -1394,8 +1387,7 @@ static void Ins_ListInstitutionsForEdition (void) } else { - strncpy (WWW,Ins->WWW,Ins_MAX_LENGTH_WWW_ON_SCREEN); - WWW[Ins_MAX_LENGTH_WWW_ON_SCREEN] = '\0'; + Str_Copy (WWW,Ins->WWW,Ins_MAX_LENGTH_WWW_ON_SCREEN); fprintf (Gbl.F.Out,"<a href=\"%s\" target=\"_blank\" class=\"DAT\" title=\"%s\">%s", Ins->WWW,Ins->WWW,WWW); if (strlen (Ins->WWW) > Ins_MAX_LENGTH_WWW_ON_SCREEN) @@ -1717,8 +1709,7 @@ static void Ins_RenameInstitution (struct Instit *Ins,Cns_ShrtOrFullName_t ShrtO CurrentInsName,NewInsName); /* Change current institution name in order to display it properly */ - strncpy (CurrentInsName,NewInsName,MaxLength); - CurrentInsName[MaxLength] = '\0'; + Str_Copy (CurrentInsName,NewInsName,MaxLength); } } else // The same name @@ -1862,9 +1853,7 @@ void Ins_ChangeInsWWW (void) { /***** Update database changing old WWW by new WWW *****/ Ins_UpdateInsWWWDB (Ins->InsCod,NewWWW); - - strncpy (Ins->WWW,NewWWW,Cns_MAX_LENGTH_WWW); - Ins->WWW[Cns_MAX_LENGTH_WWW] = '\0'; + Str_Copy (Ins->WWW,NewWWW,Cns_MAX_LENGTH_WWW); /***** Write message to show the change made *****/ sprintf (Gbl.Message,Txt_The_new_web_address_is_X,NewWWW); @@ -1895,9 +1884,7 @@ void Ins_ChangeInsWWWInConfig (void) { /***** Update database changing old WWW by new WWW *****/ Ins_UpdateInsWWWDB (Gbl.CurrentIns.Ins.InsCod,NewWWW); - - strncpy (Gbl.CurrentIns.Ins.WWW,NewWWW,Cns_MAX_LENGTH_WWW); - Gbl.CurrentIns.Ins.WWW[Cns_MAX_LENGTH_WWW] = '\0'; + Str_Copy (Gbl.CurrentIns.Ins.WWW,NewWWW,Cns_MAX_LENGTH_WWW); /***** Write message to show the change made *****/ sprintf (Gbl.Message,Txt_The_new_web_address_is_X,NewWWW); diff --git a/swad_layout.c b/swad_layout.c index 2c46a340..e186efe2 100644 --- a/swad_layout.c +++ b/swad_layout.c @@ -556,12 +556,12 @@ static void Lay_WriteScripts (void) fprintf (Gbl.F.Out," var LstExamAnnouncements = [];\n"); for (NumExamAnnouncement = 0; - NumExamAnnouncement < Gbl.ExamAnnouncements.NumExaAnns; + NumExamAnnouncement < Gbl.ExamAnns.NumExaAnns; NumExamAnnouncement++) fprintf (Gbl.F.Out," LstExamAnnouncements.push({ Year: %u, Month: %u, Day: %u });\n", - Gbl.ExamAnnouncements.Lst[NumExamAnnouncement].Year, - Gbl.ExamAnnouncements.Lst[NumExamAnnouncement].Month, - Gbl.ExamAnnouncements.Lst[NumExamAnnouncement].Day); + Gbl.ExamAnns.Lst[NumExamAnnouncement].Year, + Gbl.ExamAnns.Lst[NumExamAnnouncement].Month, + Gbl.ExamAnns.Lst[NumExamAnnouncement].Day); fprintf (Gbl.F.Out,"</script>\n"); diff --git a/swad_link.c b/swad_link.c index 2c3b70b4..461e58b2 100644 --- a/swad_link.c +++ b/swad_link.c @@ -232,16 +232,13 @@ void Lnk_GetListLinks (void) Lay_ShowErrorAndExit ("Wrong code of institutional link."); /* Get the short name of the link (row[1]) */ - strncpy (Lnk->ShrtName,row[1],Lnk_MAX_LENGTH_LINK_SHRT_NAME); - Lnk->ShrtName[Lnk_MAX_LENGTH_LINK_SHRT_NAME] = '\0'; + Str_Copy (Lnk->ShrtName,row[1],Lnk_MAX_LENGTH_LINK_SHRT_NAME); /* Get the full name of the link (row[2]) */ - strncpy (Lnk->FullName,row[2],Lnk_MAX_LENGTH_LINK_FULL_NAME); - Lnk->FullName[Lnk_MAX_LENGTH_LINK_FULL_NAME] = '\0'; + Str_Copy (Lnk->FullName,row[2],Lnk_MAX_LENGTH_LINK_FULL_NAME); /* Get the URL of the link (row[3]) */ - strncpy (Lnk->WWW,row[3],Cns_MAX_LENGTH_WWW); - Lnk->WWW[Cns_MAX_LENGTH_WWW] = '\0'; + Str_Copy (Lnk->WWW,row[3],Cns_MAX_LENGTH_WWW); } } else @@ -280,16 +277,13 @@ void Lnk_GetDataOfLinkByCod (struct Link *Lnk) row = mysql_fetch_row (mysql_res); /* Get the short name of the link (row[0]) */ - strncpy (Lnk->ShrtName,row[0],Lnk_MAX_LENGTH_LINK_SHRT_NAME); - Lnk->ShrtName[Lnk_MAX_LENGTH_LINK_SHRT_NAME] = '\0'; + Str_Copy (Lnk->ShrtName,row[0],Lnk_MAX_LENGTH_LINK_SHRT_NAME); /* Get the full name of the link (row[1]) */ - strncpy (Lnk->FullName,row[1],Lnk_MAX_LENGTH_LINK_FULL_NAME); - Lnk->FullName[Lnk_MAX_LENGTH_LINK_FULL_NAME] = '\0'; + Str_Copy (Lnk->FullName,row[1],Lnk_MAX_LENGTH_LINK_FULL_NAME); /* Get the URL of the link (row[2]) */ - strncpy (Lnk->WWW,row[2],Cns_MAX_LENGTH_WWW); - Lnk->WWW[Cns_MAX_LENGTH_WWW] = '\0'; + Str_Copy (Lnk->WWW,row[2],Cns_MAX_LENGTH_WWW); } /***** Free structure that stores the query result *****/ @@ -551,9 +545,7 @@ static void Lnk_RenameLink (Cns_ShrtOrFullName_t ShrtOrFullName) } /***** Show the form again *****/ - strncpy (CurrentLnkName,NewLnkName,MaxLength); - CurrentLnkName[MaxLength] = '\0'; - + Str_Copy (CurrentLnkName,NewLnkName,MaxLength); Lnk_EditLinks (); } @@ -610,9 +602,7 @@ void Lnk_ChangeLinkWWW (void) Lay_ShowAlert (Lay_WARNING,Txt_You_can_not_leave_the_web_address_empty); /***** Show the form again *****/ - strncpy (Lnk->WWW,NewWWW,Cns_MAX_LENGTH_WWW); - Lnk->WWW[Cns_MAX_LENGTH_WWW] = '\0'; - + Str_Copy (Lnk->WWW,NewWWW,Cns_MAX_LENGTH_WWW); Lnk_EditLinks (); } diff --git a/swad_logo.c b/swad_logo.c index bdb5153e..a6de8b96 100644 --- a/swad_logo.c +++ b/swad_logo.c @@ -320,7 +320,7 @@ void Log_ReceiveLogo (Sco_Scope_t Scope) char Path[PATH_MAX+1]; struct Param *Param; char FileNameLogoSrc[PATH_MAX+1]; - char MIMEType[Brw_MAX_BYTES_MIME_TYPE+1]; + char MIMEType[Brw_MAX_BYTES_MIME_TYPE + 1]; char FileNameLogo[PATH_MAX+1]; // Full name (including path and .png) of the destination file bool WrongType = false; diff --git a/swad_mail.c b/swad_mail.c index 44a7991a..7fefa674 100644 --- a/swad_mail.c +++ b/swad_mail.c @@ -288,12 +288,10 @@ static void Mai_GetListMailDomainsAllowedForNotif (void) Lay_ShowErrorAndExit ("Wrong code of mail domain."); /* Get the mail domain (row[1]) */ - strncpy (Mai->Domain,row[1],Mai_MAX_LENGTH_MAIL_DOMAIN); - Mai->Domain[Mai_MAX_LENGTH_MAIL_DOMAIN] = '\0'; + Str_Copy (Mai->Domain,row[1],Mai_MAX_LENGTH_MAIL_DOMAIN); /* Get the mail domain info (row[2]) */ - strncpy (Mai->Info,row[2],Mai_MAX_LENGTH_MAIL_INFO); - Mai->Info[Mai_MAX_LENGTH_MAIL_INFO] = '\0'; + Str_Copy (Mai->Info,row[2],Mai_MAX_LENGTH_MAIL_INFO); /* Get number of users (row[3]) */ if (sscanf (row[3],"%u",&(Mai->NumUsrs)) != 1) @@ -394,12 +392,10 @@ void Mai_GetDataOfMailDomainByCod (struct Mail *Mai) row = mysql_fetch_row (mysql_res); /* Get the short name of the mail (row[0]) */ - strncpy (Mai->Domain,row[0],Mai_MAX_LENGTH_MAIL_DOMAIN); - Mai->Domain[Mai_MAX_LENGTH_MAIL_DOMAIN] = '\0'; + Str_Copy (Mai->Domain,row[0],Mai_MAX_LENGTH_MAIL_DOMAIN); /* Get the full name of the mail (row[1]) */ - strncpy (Mai->Info,row[1],Mai_MAX_LENGTH_MAIL_INFO); - Mai->Info[Mai_MAX_LENGTH_MAIL_INFO] = '\0'; + Str_Copy (Mai->Info,row[1],Mai_MAX_LENGTH_MAIL_INFO); } /***** Free structure that stores the query result *****/ @@ -653,9 +649,7 @@ static void Mai_RenameMailDomain (Cns_ShrtOrFullName_t ShrtOrFullName) } /***** Show the form again *****/ - strncpy (CurrentMaiName,NewMaiName,MaxLength); - CurrentMaiName[MaxLength] = '\0'; - + Str_Copy (CurrentMaiName,NewMaiName,MaxLength); Mai_EditMailDomains (); } @@ -1036,14 +1030,10 @@ bool Mai_GetEmailFromUsrCod (struct UsrData *UsrDat) } else { - row = mysql_fetch_row (mysql_res); - /* Get email */ - strncpy (UsrDat->Email,row[0],Usr_MAX_BYTES_USR_EMAIL); - UsrDat->Email[Usr_MAX_BYTES_USR_EMAIL] = '\0'; - + row = mysql_fetch_row (mysql_res); + Str_Copy (UsrDat->Email,row[0],Usr_MAX_BYTES_USR_EMAIL); UsrDat->EmailConfirmed = (row[1][0] == 'Y'); - Found = true; } @@ -1690,8 +1680,7 @@ void Mai_ConfirmEmail (void) UsrCod = Str_ConvertStrCodToLongCod (row[0]); /* Get user's email */ - strncpy (Email,row[1],Usr_MAX_BYTES_USR_EMAIL); - Email[Usr_MAX_BYTES_USR_EMAIL] = '\0'; + Str_Copy (Email,row[1],Usr_MAX_BYTES_USR_EMAIL); KeyIsCorrect = true; } diff --git a/swad_mark.c b/swad_mark.c index a632af10..4970e405 100644 --- a/swad_mark.c +++ b/swad_mark.c @@ -323,10 +323,8 @@ bool Mrk_CheckFileOfMarks (const char *Path,struct MarksProperties *Marks) // Only one table is allowed if (Str_FindStrInFile (FileAllMarks,"<table",Str_NO_SKIP_HTML_COMMENTS)) { - strncpy (Gbl.Message,Txt_There_are_more_than_one_table_in_the_file_of_marks, - Lay_MAX_BYTES_ALERT); - Gbl.Message[Lay_MAX_BYTES_ALERT] = '\0'; - + Str_Copy (Gbl.Message,Txt_There_are_more_than_one_table_in_the_file_of_marks, + Lay_MAX_BYTES_ALERT); FileIsCorrect = false; } else @@ -387,10 +385,8 @@ bool Mrk_CheckFileOfMarks (const char *Path,struct MarksProperties *Marks) } else { - strncpy (Gbl.Message,Txt_Table_not_found_in_the_file_of_marks, - Lay_MAX_BYTES_ALERT); - Gbl.Message[Lay_MAX_BYTES_ALERT] = '\0'; - + Str_Copy (Gbl.Message,Txt_Table_not_found_in_the_file_of_marks, + Lay_MAX_BYTES_ALERT); FileIsCorrect = false; } @@ -462,9 +458,8 @@ static bool Mrk_GetUsrMarks (FILE *FileUsrMarks,struct UsrData *UsrDat, /***** Open HTML file with the table of marks *****/ if (!(FileAllMarks = fopen (PathFileAllMarks,"rb"))) { // Can't open the file with the table of marks - strncpy (Gbl.Message,"Can not open file of marks.",Lay_MAX_BYTES_ALERT); // TODO: Need translation! - Gbl.Message[Lay_MAX_BYTES_ALERT] = '\0'; - + Str_Copy (Gbl.Message,"Can not open file of marks.", // TODO: Need translation! + Lay_MAX_BYTES_ALERT); return false; } @@ -784,13 +779,11 @@ void Mrk_GetNotifMyMarks (char SummaryStr[Cns_MAX_BYTES_TEXT + 1], &InsCod,&CtrCod,&DegCod,&CrsCod,&GrpCod); /* Path (row[2]) */ - strncpy (FullPathInTreeFromDBMarksTable,row[2],PATH_MAX); - FullPathInTreeFromDBMarksTable[PATH_MAX] = '\0'; + Str_Copy (FullPathInTreeFromDBMarksTable,row[2],PATH_MAX); Str_SplitFullPathIntoPathAndFileName (FullPathInTreeFromDBMarksTable, PathUntilFileName, FileName); - strncpy (SummaryStr,FileName,NAME_MAX); - SummaryStr[NAME_MAX] = '\0'; + Str_Copy (SummaryStr,FileName,NAME_MAX); if (MaxChars) Str_LimitLengthHTMLStr (SummaryStr,MaxChars); @@ -841,7 +834,7 @@ void Mrk_GetNotifMyMarks (char SummaryStr[Cns_MAX_BYTES_TEXT + 1], if ((*ContentStr = (char *) malloc (Length + 1))) { /* 9 starting chars */ - strncpy (*ContentStr,"<![CDATA[",9); + Str_Copy (*ContentStr,"<![CDATA[",9); /* Content */ Ptr = (*ContentStr) + 9; @@ -855,10 +848,7 @@ void Mrk_GetNotifMyMarks (char SummaryStr[Cns_MAX_BYTES_TEXT + 1], } /* 3 ending chars */ - strncpy (Ptr,"]]>",3); - - /* Ending null char */ - (*ContentStr)[Length] = '\0'; + Str_Copy (Ptr,"]]>",3); } } else @@ -870,10 +860,8 @@ void Mrk_GetNotifMyMarks (char SummaryStr[Cns_MAX_BYTES_TEXT + 1], } else { - strncpy (Gbl.Message,"Can not open file with user's marks!", // TODO: Need translation! - Lay_MAX_BYTES_ALERT); - Gbl.Message[Lay_MAX_BYTES_ALERT] = '\0'; - + Str_Copy (Gbl.Message,"Can not open file with user's marks!", // TODO: Need translation! + Lay_MAX_BYTES_ALERT); if ((*ContentStr = (char *) malloc (9+strlen (Gbl.Message)+3+1))) sprintf (*ContentStr,"<![CDATA[%s]]>",Gbl.Message); } @@ -881,9 +869,8 @@ void Mrk_GetNotifMyMarks (char SummaryStr[Cns_MAX_BYTES_TEXT + 1], } else { - strncpy (Gbl.Message,"User's IDs not found!",Lay_MAX_BYTES_ALERT); // TODO: Need translation! - Gbl.Message[Lay_MAX_BYTES_ALERT] = '\0'; - + Str_Copy (Gbl.Message,"User's IDs not found!", // TODO: Need translation! + Lay_MAX_BYTES_ALERT); if ((*ContentStr = (char *) malloc (9+strlen (Gbl.Message)+3+1))) sprintf (*ContentStr,"<![CDATA[%s]]>",Gbl.Message); } diff --git a/swad_message.c b/swad_message.c index cddc1ecb..f410dce7 100644 --- a/swad_message.c +++ b/swad_message.c @@ -518,12 +518,10 @@ static void Msg_WriteFormSubjectAndContentMsgToUsrs (char *Content) row = mysql_fetch_row (mysql_res); /* Get subject */ - strncpy (Gbl.Msg.Subject,row[0],Cns_MAX_BYTES_SUBJECT); - Gbl.Msg.Subject[Cns_MAX_BYTES_SUBJECT] = '\0'; + Str_Copy (Gbl.Msg.Subject,row[0],Cns_MAX_BYTES_SUBJECT); /* Get content */ - strncpy (Content,row[1],Cns_MAX_BYTES_LONG_TEXT); - Content[Cns_MAX_BYTES_LONG_TEXT] = '\0'; + Str_Copy (Content,row[1],Cns_MAX_BYTES_LONG_TEXT); /* Free structure that stores the query result */ DB_FreeMySQLResult (&mysql_res); @@ -2714,8 +2712,7 @@ void Msg_GetMsgSubject (long MsgCod,char *Subject) { /***** Get subject *****/ row = mysql_fetch_row (mysql_res); - strncpy (Subject,row[0],Cns_MAX_BYTES_SUBJECT); - Subject[Cns_MAX_BYTES_SUBJECT] = '\0'; + Str_Copy (Subject,row[0],Cns_MAX_BYTES_SUBJECT); } else Subject[0] = '\0'; @@ -2749,8 +2746,7 @@ static void Msg_GetMsgContent (long MsgCod,char *Content,struct Image *Image) row = mysql_fetch_row (mysql_res); /****** Get content (row[0]) *****/ - strncpy (Content,row[0],Cns_MAX_BYTES_LONG_TEXT); - Content[Cns_MAX_BYTES_LONG_TEXT] = '\0'; + Str_Copy (Content,row[0],Cns_MAX_BYTES_LONG_TEXT); /****** Get image name (row[1]), title (row[2]) and URL (row[3]) *****/ Img_GetImageNameTitleAndURLFromRow (row[1],row[2],row[3],Image); diff --git a/swad_network.c b/swad_network.c index a0b022c2..ee6d42d1 100644 --- a/swad_network.c +++ b/swad_network.c @@ -225,8 +225,7 @@ void Net_ShowWebsAndSocialNets (const struct UsrData *UsrDat) { /* Get URL */ row = mysql_fetch_row (mysql_res); - strncpy (URL,row[0],Cns_MAX_BYTES_URL); - URL[Cns_MAX_BYTES_URL] = '\0'; + Str_Copy (URL,row[0],Cns_MAX_BYTES_URL); /* Show the web / social network */ Net_ShowAWebOrSocialNet (URL, @@ -316,8 +315,7 @@ void Net_ShowFormMyWebsAndSocialNets (void) row = mysql_fetch_row (mysql_res); /* Get URL */ - strncpy (URL,row[0],Cns_MAX_BYTES_URL); - URL[Cns_MAX_BYTES_URL] = '\0'; + Str_Copy (URL,row[0],Cns_MAX_BYTES_URL); } else URL[0] = '\0'; @@ -553,8 +551,7 @@ void Net_ShowWebAndSocialNetworksStats (void) row = mysql_fetch_row (mysql_res); /* Get web / social network (row[0]) */ - strncpy (WebStr,row[0],sizeof (WebStr) - 1); - WebStr[sizeof (WebStr) - 1] = '\0'; + Str_Copy (WebStr,row[0],sizeof (WebStr) - 1); for (Web = (Net_WebsAndSocialNetworks_t) 0; Web < Net_NUM_WEBS_AND_SOCIAL_NETWORKS; Web++) diff --git a/swad_nickname.c b/swad_nickname.c index 259ad80b..4a72b8ae 100644 --- a/swad_nickname.c +++ b/swad_nickname.c @@ -73,8 +73,8 @@ bool Nck_CheckIfNickWithArrobaIsValid (const char *NicknameWithArroba) return false; /***** Make a copy of nickname *****/ - strncpy (NicknameWithoutArroba,NicknameWithArroba,Nck_MAX_BYTES_NICKNAME_WITH_ARROBA); - NicknameWithoutArroba[Nck_MAX_BYTES_NICKNAME_WITH_ARROBA] = '\0'; + Str_Copy (NicknameWithoutArroba,NicknameWithArroba, + Nck_MAX_BYTES_NICKNAME_WITH_ARROBA); Str_RemoveLeadingArrobas (NicknameWithoutArroba); Length = strlen (NicknameWithoutArroba); @@ -116,8 +116,7 @@ bool Nck_GetNicknameFromUsrCod (long UsrCod,char *Nickname) { /* Get nickname */ row = mysql_fetch_row (mysql_res); - strncpy (Nickname,row[0],Nck_MAX_LENGTH_NICKNAME_WITHOUT_ARROBA); - Nickname[Nck_MAX_LENGTH_NICKNAME_WITHOUT_ARROBA] = '\0'; + Str_Copy (Nickname,row[0],Nck_MAX_LENGTH_NICKNAME_WITHOUT_ARROBA); Found = true; } else @@ -150,8 +149,8 @@ long Nck_GetUsrCodFromNickname (const char *Nickname) if (Nickname[0]) { /***** Make a copy without possible starting arrobas *****/ - strncpy (NicknameWithoutArroba,Nickname,Nck_MAX_BYTES_NICKNAME_WITH_ARROBA); - NicknameWithoutArroba[Nck_MAX_BYTES_NICKNAME_WITH_ARROBA] = '\0'; + Str_Copy (NicknameWithoutArroba,Nickname, + Nck_MAX_BYTES_NICKNAME_WITH_ARROBA); Str_RemoveLeadingArrobas (NicknameWithoutArroba); /***** Get user's code from database *****/ @@ -362,8 +361,8 @@ void Nck_UpdateNick (void) if (Nck_CheckIfNickWithArrobaIsValid (NewNicknameWithArroba)) // If new nickname is valid { /***** Remove arrobas at the beginning *****/ - strncpy (NewNicknameWithoutArroba,NewNicknameWithArroba,Nck_MAX_BYTES_NICKNAME_WITH_ARROBA); - NewNicknameWithoutArroba[Nck_MAX_BYTES_NICKNAME_WITH_ARROBA] = '\0'; + Str_Copy (NewNicknameWithoutArroba,NewNicknameWithArroba, + Nck_MAX_BYTES_NICKNAME_WITH_ARROBA); Str_RemoveLeadingArrobas (NewNicknameWithoutArroba); /***** Check if new nickname exists in database *****/ diff --git a/swad_notice.c b/swad_notice.c index 23370ae5..9a55b395 100644 --- a/swad_notice.c +++ b/swad_notice.c @@ -411,9 +411,9 @@ void Not_ShowNotices (Not_Listing_t TypeNoticesListing) UsrCod = Str_ConvertStrCodToLongCod (row[2]); /* Get the content (row[3]) and insert links */ - strncpy (Content,row[3],Cns_MAX_BYTES_TEXT); + Str_Copy (Content,row[3],Cns_MAX_BYTES_TEXT); Str_InsertLinks (Content,Cns_MAX_BYTES_TEXT, - Not_MaxCharsURLOnScreen[TypeNoticesListing]); + Not_MaxCharsURLOnScreen[TypeNoticesListing]); if (TypeNoticesListing == Not_LIST_BRIEF_NOTICES) Str_LimitLengthHTMLStr (Content,Not_MAX_CHARS_ON_NOTICE); @@ -555,9 +555,9 @@ static void Not_GetDataAndShowNotice (long NotCod) UsrCod = Str_ConvertStrCodToLongCod (row[1]); /* Get the content (row[2]) and insert links*/ - strncpy (Content,row[2],Cns_MAX_BYTES_TEXT); + Str_Copy (Content,row[2],Cns_MAX_BYTES_TEXT); Str_InsertLinks (Content,Cns_MAX_BYTES_TEXT, - Not_MaxCharsURLOnScreen[Not_LIST_FULL_NOTICES]); + Not_MaxCharsURLOnScreen[Not_LIST_FULL_NOTICES]); /* Get status of the notice (row[3]) */ Status = Not_OBSOLETE_NOTICE; diff --git a/swad_notification.c b/swad_notification.c index 972107b2..9df26c52 100644 --- a/swad_notification.c +++ b/swad_notification.c @@ -55,6 +55,8 @@ extern struct Globals Gbl; /****************************** Public constants *****************************/ /*****************************************************************************/ +// strings are limited to Ntf_MAX_LENGTH_NOTIFY_EVENT characters + const char *Ntf_WSNotifyEvents[Ntf_NUM_NOTIFY_EVENTS] = { "unknown", // Ntf_EVENT_UNKNOWN diff --git a/swad_notification.h b/swad_notification.h index e75ffb75..711e4f8c 100644 --- a/swad_notification.h +++ b/swad_notification.h @@ -33,11 +33,15 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ +#define Ntf_MAX_LENGTH_NOTIFY_EVENT 32 + +#define Ntf_MAX_LENGTH_NOTIFY_LOCATION (1024 - 1) + /*****************************************************************************/ /******************************** Public types *******************************/ /*****************************************************************************/ -#define Ntf_NUM_NOTIFY_EVENTS (1+19) +#define Ntf_NUM_NOTIFY_EVENTS (1 + 19) // If the numbers assigned to each event type change, // it is necessary to change old numbers to new ones // in database tables notif, sta_notif and usr_data diff --git a/swad_parameter.c b/swad_parameter.c index 34a54a1e..35292534 100644 --- a/swad_parameter.c +++ b/swad_parameter.c @@ -577,8 +577,8 @@ unsigned Par_GetParameter (tParamType ParamType,const char *ParamName, { case Act_CONT_NORM: if (PtrDst) - strncpy (PtrDst,&Gbl.Params.QueryString[Param->Value.Start], - Param->Value.Length); + Str_Copy (PtrDst,&Gbl.Params.QueryString[Param->Value.Start], + Param->Value.Length); break; case Act_CONT_DATA: if (Param->FileName.Start == 0 && // Copy into destination only if it's not a file diff --git a/swad_photo.c b/swad_photo.c index 947bbd7d..be632e43 100644 --- a/swad_photo.c +++ b/swad_photo.c @@ -562,18 +562,18 @@ static bool Pho_ReceivePhotoAndDetectFaces (bool ItsMe,const struct UsrData *Usr extern const char *Txt_X_faces_have_been_detected_in_front_position_1_Z_; extern const char *Txt_X_faces_have_been_detected_in_front_position_Y_Z_; extern const char *Txt_Faces_detected; - char PathPhotosPriv[PATH_MAX+1]; - char PathPhotosPubl[PATH_MAX+1]; + char PathPhotosPriv[PATH_MAX + 1]; + char PathPhotosPubl[PATH_MAX + 1]; struct Param *Param; - char FileNamePhotoSrc[PATH_MAX+1]; - char FileNamePhotoTmp[PATH_MAX+1]; // Full name (including path and .jpg) of the destination temporary file - char FileNamePhotoMap[PATH_MAX+1]; // Full name (including path) of the temporary file with the original image with faces - char FileNameTxtMap[PATH_MAX+1]; // Full name (including path) of the temporary file with the text neccesary to make the image map - char PathRelPhoto[PATH_MAX+1]; - FILE *FileTxtMap = NULL; // Temporary file with the text neccesary to make the image map. Initialized to avoid warning - char MIMEType[Brw_MAX_BYTES_MIME_TYPE+1]; + char FileNamePhotoSrc[PATH_MAX + 1]; + char FileNamePhotoTmp[PATH_MAX + 1]; // Full name (including path and .jpg) of the destination temporary file + char FileNamePhotoMap[PATH_MAX + 1]; // Full name (including path) of the temporary file with the original image with faces + char FileNameTxtMap[PATH_MAX + 1]; // Full name (including path) of the temporary file with the text neccesary to make the image map + char PathRelPhoto[PATH_MAX + 1]; + FILE *FileTxtMap = NULL; // Temporary file with the text neccesary to make the image map. Initialized to avoid warning + char MIMEType[Brw_MAX_BYTES_MIME_TYPE + 1]; bool WrongType = false; - char Command[256+PATH_MAX]; // Command to call the program of preprocessing of photos + char Command[256 + PATH_MAX]; // Command to call the program of preprocessing of photos int ReturnCode; int NumLastForm = 0; // Initialized to avoid warning char FormId[32]; @@ -585,7 +585,7 @@ static bool Pho_ReceivePhotoAndDetectFaces (bool ItsMe,const struct UsrData *Usr unsigned Y; unsigned Radius; unsigned BackgroundCode; - char StrFileName[NAME_MAX+1]; + char StrFileName[NAME_MAX + 1]; /***** Creates directories if not exist *****/ sprintf (PathPhotosPriv,"%s/%s", @@ -2369,8 +2369,7 @@ static void Pho_ShowDegreeAvgPhotoAndStat (struct Degree *Deg, Pho_ComputePhotoSize (NumStds,NumStdsWithPhoto,&PhotoWidth,&PhotoHeight); /***** Make a copy of the degree short name *****/ - strncpy (CopyOfDegShortName,Deg->ShrtName,Deg_MAX_LENGTH_DEGREE_SHRT_NAME); - CopyOfDegShortName[Deg_MAX_LENGTH_DEGREE_SHRT_NAME] = '\0'; + Str_Copy (CopyOfDegShortName,Deg->ShrtName,Deg_MAX_LENGTH_DEGREE_SHRT_NAME); Str_LimitLengthHTMLStr (CopyOfDegShortName, SeeOrPrint == Pho_DEGREES_SEE ? 10 : 15); diff --git a/swad_place.c b/swad_place.c index 08dd8a47..63597669 100644 --- a/swad_place.c +++ b/swad_place.c @@ -340,17 +340,15 @@ void Plc_GetDataOfPlaceByCod (struct Place *Plc) /***** Check if place code is correct *****/ if (Plc->PlcCod < 0) { - strncpy (Plc->ShrtName,Txt_Place_unspecified,Plc_MAX_LENGTH_PLACE_SHRT_NAME); - Plc->ShrtName[Plc_MAX_LENGTH_PLACE_SHRT_NAME] = '\0'; - strncpy (Plc->FullName,Txt_Place_unspecified,Plc_MAX_LENGTH_PLACE_FULL_NAME); - Plc->FullName[Plc_MAX_LENGTH_PLACE_FULL_NAME] = '\0'; + Str_Copy (Plc->ShrtName,Txt_Place_unspecified, + Plc_MAX_LENGTH_PLACE_SHRT_NAME); + Str_Copy (Plc->FullName,Txt_Place_unspecified, + Plc_MAX_LENGTH_PLACE_FULL_NAME); } else if (Plc->PlcCod == 0) { - strncpy (Plc->ShrtName,Txt_Another_place,Plc_MAX_LENGTH_PLACE_SHRT_NAME); - Plc->ShrtName[Plc_MAX_LENGTH_PLACE_SHRT_NAME] = '\0'; - strncpy (Plc->FullName,Txt_Another_place,Plc_MAX_LENGTH_PLACE_FULL_NAME); - Plc->FullName[Plc_MAX_LENGTH_PLACE_FULL_NAME] = '\0'; + Str_Copy (Plc->ShrtName,Txt_Another_place,Plc_MAX_LENGTH_PLACE_SHRT_NAME); + Str_Copy (Plc->FullName,Txt_Another_place,Plc_MAX_LENGTH_PLACE_FULL_NAME); } else if (Plc->PlcCod > 0) { @@ -379,12 +377,10 @@ void Plc_GetDataOfPlaceByCod (struct Place *Plc) row = mysql_fetch_row (mysql_res); /* Get the short name of the place (row[0]) */ - strncpy (Plc->ShrtName,row[0],Plc_MAX_LENGTH_PLACE_SHRT_NAME); - Plc->ShrtName[Plc_MAX_LENGTH_PLACE_SHRT_NAME] = '\0'; + Str_Copy (Plc->ShrtName,row[0],Plc_MAX_LENGTH_PLACE_SHRT_NAME); /* Get the full name of the place (row[1]) */ - strncpy (Plc->FullName,row[1],Plc_MAX_LENGTH_PLACE_FULL_NAME); - Plc->FullName[Plc_MAX_LENGTH_PLACE_FULL_NAME] = '\0'; + Str_Copy (Plc->FullName,row[1],Plc_MAX_LENGTH_PLACE_FULL_NAME); /* Get number of centres in this place (row[2]) */ if (sscanf (row[2],"%u",&Plc->NumCtrs) != 1) diff --git a/swad_plugin.c b/swad_plugin.c index 56404ef1..5b99b1c0 100644 --- a/swad_plugin.c +++ b/swad_plugin.c @@ -227,28 +227,22 @@ static void Plg_GetListPlugins (void) Lay_ShowErrorAndExit ("Wrong code of plugin."); /* Get the name of the plugin (row[1]) */ - strncpy (Plg->Name,row[1],Plg_MAX_LENGTH_PLUGIN_NAME); - Plg->Name[Plg_MAX_LENGTH_PLUGIN_NAME] = '\0'; + Str_Copy (Plg->Name,row[1],Plg_MAX_LENGTH_PLUGIN_NAME); /* Get the description of the plugin (row[2]) */ - strncpy (Plg->Description,row[2],Plg_MAX_LENGTH_PLUGIN_DESCRIPTION); - Plg->Description[Plg_MAX_LENGTH_PLUGIN_DESCRIPTION] = '\0'; + Str_Copy (Plg->Description,row[2],Plg_MAX_LENGTH_PLUGIN_DESCRIPTION); /* Get the logo of the plugin (row[3]) */ - strncpy (Plg->Logo,row[3],Plg_MAX_LENGTH_PLUGIN_LOGO); - Plg->Logo[Plg_MAX_LENGTH_PLUGIN_LOGO] = '\0'; + Str_Copy (Plg->Logo,row[3],Plg_MAX_LENGTH_PLUGIN_LOGO); /* Get the application key of the plugin (row[4]) */ - strncpy (Plg->AppKey,row[4],Plg_MAX_LENGTH_PLUGIN_APP_KEY); - Plg->AppKey[Plg_MAX_LENGTH_PLUGIN_APP_KEY] = '\0'; + Str_Copy (Plg->AppKey,row[4],Plg_MAX_LENGTH_PLUGIN_APP_KEY); /* Get the URL of the plugin (row[5]) */ - strncpy (Plg->URL,row[5],Cns_MAX_LENGTH_WWW); - Plg->URL[Cns_MAX_LENGTH_WWW] = '\0'; + Str_Copy (Plg->URL,row[5],Cns_MAX_LENGTH_WWW); /* Get the IP of the plugin (row[6]) */ - strncpy (Plg->IP,row[6],Cns_MAX_LENGTH_IP); - Plg->IP[Cns_MAX_LENGTH_IP] = '\0'; + Str_Copy (Plg->IP,row[6],Cns_MAX_LENGTH_IP); } } else @@ -294,28 +288,22 @@ bool Plg_GetDataOfPluginByCod (struct Plugin *Plg) row = mysql_fetch_row (mysql_res); /* Get the name of the plugin (row[0]) */ - strncpy (Plg->Name,row[0],Plg_MAX_LENGTH_PLUGIN_NAME); - Plg->Name[Plg_MAX_LENGTH_PLUGIN_NAME] = '\0'; + Str_Copy (Plg->Name,row[0],Plg_MAX_LENGTH_PLUGIN_NAME); /* Get the description of the plugin (row[1]) */ - strncpy (Plg->Description,row[1],Plg_MAX_LENGTH_PLUGIN_DESCRIPTION); - Plg->Description[Plg_MAX_LENGTH_PLUGIN_DESCRIPTION] = '\0'; + Str_Copy (Plg->Description,row[1],Plg_MAX_LENGTH_PLUGIN_DESCRIPTION); /* Get the logo of the plugin (row[2]) */ - strncpy (Plg->Logo,row[2],Plg_MAX_LENGTH_PLUGIN_LOGO); - Plg->Logo[Plg_MAX_LENGTH_PLUGIN_LOGO] = '\0'; + Str_Copy (Plg->Logo,row[2],Plg_MAX_LENGTH_PLUGIN_LOGO); /* Get the application key of the plugin (row[3]) */ - strncpy (Plg->AppKey,row[3],Plg_MAX_LENGTH_PLUGIN_APP_KEY); - Plg->AppKey[Plg_MAX_LENGTH_PLUGIN_APP_KEY] = '\0'; + Str_Copy (Plg->AppKey,row[3],Plg_MAX_LENGTH_PLUGIN_APP_KEY); /* Get the URL of the plugin (row[4]) */ - strncpy (Plg->URL,row[4],Cns_MAX_LENGTH_WWW); - Plg->URL[Cns_MAX_LENGTH_WWW] = '\0'; + Str_Copy (Plg->URL,row[4],Cns_MAX_LENGTH_WWW); /* Get the IP of the plugin (row[5]) */ - strncpy (Plg->IP,row[5],Cns_MAX_LENGTH_IP); - Plg->IP[Cns_MAX_LENGTH_IP] = '\0'; + Str_Copy (Plg->IP,row[5],Cns_MAX_LENGTH_IP); } else PluginFound = false; diff --git a/swad_record.c b/swad_record.c index e43a7bc9..9817ab90 100644 --- a/swad_record.c +++ b/swad_record.c @@ -232,7 +232,8 @@ void Rec_GetListRecordFieldsInCurrentCrs (void) Lay_ShowErrorAndExit ("Wrong code of field."); /* Name of the field (row[1]) */ - strncpy (Gbl.CurrentCrs.Records.LstFields.Lst[NumRow].Name,row[1],Rec_MAX_LENGTH_NAME_FIELD); + Str_Copy (Gbl.CurrentCrs.Records.LstFields.Lst[NumRow].Name,row[1], + Rec_MAX_LENGTH_NAME_FIELD); /* Number of lines (row[2]) */ Gbl.CurrentCrs.Records.LstFields.Lst[NumRow].NumLines = Rec_ConvertToNumLinesField (row[2]); @@ -2572,20 +2573,17 @@ static void Rec_ShowFullName (struct UsrData *UsrDat) fprintf (Gbl.F.Out,"<td class=\"REC_C2_MID REC_NAME LEFT_TOP\">"); /***** First name *****/ - strncpy (Name,UsrDat->FirstName,Usr_MAX_BYTES_NAME); - Name[Usr_MAX_BYTES_NAME] = '\0'; + Str_Copy (Name,UsrDat->FirstName,Usr_MAX_BYTES_NAME); Str_LimitLengthHTMLStr (Name,20); fprintf (Gbl.F.Out,"%s<br />",Name); /***** Surname 1 *****/ - strncpy (Name,UsrDat->Surname1,Usr_MAX_BYTES_NAME); - Name[Usr_MAX_BYTES_NAME] = '\0'; + Str_Copy (Name,UsrDat->Surname1,Usr_MAX_BYTES_NAME); Str_LimitLengthHTMLStr (Name,20); fprintf (Gbl.F.Out,"%s<br />",Name); /***** Surname 2 *****/ - strncpy (Name,UsrDat->Surname2,Usr_MAX_BYTES_NAME); - Name[Usr_MAX_BYTES_NAME] = '\0'; + Str_Copy (Name,UsrDat->Surname2,Usr_MAX_BYTES_NAME); Str_LimitLengthHTMLStr (Name,20); fprintf (Gbl.F.Out,"%s",Name); diff --git a/swad_session.c b/swad_session.c index 275b1a19..9458adad 100644 --- a/swad_session.c +++ b/swad_session.c @@ -314,8 +314,7 @@ bool Ses_GetSessionData (void) Gbl.Search.WhatToSearch = (Sch_WhatToSearch_t) UnsignedNum; /* Get search string (row[9]) */ - strncpy (Gbl.Search.Str,row[9],Sch_MAX_LENGTH_STRING_TO_FIND); - Gbl.Search.Str[Sch_MAX_LENGTH_STRING_TO_FIND] = '\0'; + Str_Copy (Gbl.Search.Str,row[9],Sch_MAX_LENGTH_STRING_TO_FIND); } Result = true; @@ -428,8 +427,7 @@ unsigned Ses_GetHiddenParFromDB (Act_Action_t Action,const char *ParamName,char { /***** Get the value del parameter *****/ row = mysql_fetch_row (mysql_res); - strncpy (ParamValue,row[0],MaxBytes); - ParamValue[MaxBytes] = '\0'; + Str_Copy (ParamValue,row[0],MaxBytes); ParameterIsTooBig = (strlen (row[0]) > MaxBytes); } diff --git a/swad_social.c b/swad_social.c index e95b7b35..b925c0db 100644 --- a/swad_social.c +++ b/swad_social.c @@ -1483,8 +1483,7 @@ static void Soc_GetAndWriteSocialPost (long PstCod) row = mysql_fetch_row (mysql_res); /****** Get content (row[0]) *****/ - strncpy (Content,row[0],Cns_MAX_BYTES_LONG_TEXT); - Content[Cns_MAX_BYTES_LONG_TEXT] = '\0'; + Str_Copy (Content,row[0],Cns_MAX_BYTES_LONG_TEXT); /****** Get image name (row[1]), title (row[2]) and URL (row[3]) *****/ Img_GetImageNameTitleAndURLFromRow (row[1],row[2],row[3],&Image); @@ -4550,8 +4549,7 @@ static void Soc_GetDataOfSocialCommentFromRow (MYSQL_ROW row,struct SocialCommen SocCom->DateTimeUTC = Dat_GetUNIXTimeFromStr (row[3]); /***** Get content (row[4]) *****/ - strncpy (SocCom->Content,row[4],Cns_MAX_BYTES_LONG_TEXT); - SocCom->Content[Cns_MAX_BYTES_LONG_TEXT] = '\0'; + Str_Copy (SocCom->Content,row[4],Cns_MAX_BYTES_LONG_TEXT); /***** Get number of times this comment has been favourited *****/ SocCom->NumFavs = Soc_GetNumTimesACommHasBeenFav (SocCom); @@ -4689,8 +4687,7 @@ void Soc_GetNotifSocialPublishing (char *SummaryStr,char **ContentStr,long PubCo row = mysql_fetch_row (mysql_res); /****** Get content (row[0]) *****/ - strncpy (Content,row[0],Cns_MAX_BYTES_LONG_TEXT); - Content[Cns_MAX_BYTES_LONG_TEXT] = '\0'; + Str_Copy (Content,row[0],Cns_MAX_BYTES_LONG_TEXT); } /***** Free structure that stores the query result *****/ @@ -4723,8 +4720,7 @@ void Soc_GetNotifSocialPublishing (char *SummaryStr,char **ContentStr,long PubCo row = mysql_fetch_row (mysql_res); /****** Get content (row[0]) *****/ - strncpy (Content,row[0],Cns_MAX_BYTES_LONG_TEXT); - Content[Cns_MAX_BYTES_LONG_TEXT] = '\0'; + Str_Copy (Content,row[0],Cns_MAX_BYTES_LONG_TEXT); } /***** Free structure that stores the query result *****/ @@ -4808,8 +4804,7 @@ static void Str_AnalyzeTxtAndStoreNotifyEventToMentionedUsrs (long PubCod,const if (IsNickname) { /* Copy nickname */ - strncpy (UsrDat.Nickname,Nickname.PtrStart,Nickname.Length); - UsrDat.Nickname[Nickname.Length] = '\0'; + Str_Copy (UsrDat.Nickname,Nickname.PtrStart,Nickname.Length); if ((UsrDat.UsrCod = Nck_GetUsrCodFromNickname (UsrDat.Nickname)) > 0) if (UsrDat.UsrCod != Gbl.Usrs.Me.UsrDat.UsrCod) // It's not me diff --git a/swad_statistic.c b/swad_statistic.c index 09977aba..209768fe 100644 --- a/swad_statistic.c +++ b/swad_statistic.c @@ -255,10 +255,7 @@ The IP address of the remote host making the request. void Sta_GetRemoteAddr (void) { if (getenv ("REMOTE_ADDR")) - { - strncpy (Gbl.IP,getenv ("REMOTE_ADDR"),Cns_MAX_LENGTH_IP); - Gbl.IP[Cns_MAX_LENGTH_IP] = '\0'; - } + Str_Copy (Gbl.IP,getenv ("REMOTE_ADDR"),Cns_MAX_LENGTH_IP); else Gbl.IP[0] = '\0'; } diff --git a/swad_string.c b/swad_string.c index 5dee0759..8897eda1 100644 --- a/swad_string.c +++ b/swad_string.c @@ -244,8 +244,7 @@ void Str_InsertLinks (char *Txt,unsigned long MaxLength,size_t MaxCharsURLOnScre /* Make a copy of this URL */ NumBytesToCopy = (Links[NumLinks].NumActualBytes < MAX_BYTES_LIMITED_URL) ? Links[NumLinks].NumActualBytes : MAX_BYTES_LIMITED_URL; - strncpy (LimitedURL,Links[NumLinks].PtrStart,NumBytesToCopy); - LimitedURL[NumBytesToCopy] = '\0'; + Str_Copy (LimitedURL,Links[NumLinks].PtrStart,NumBytesToCopy); /* Limit the number of characters on screen of the copy, and calculate its length in bytes */ LengthVisibleLink = Str_LimitLengthHTMLStr (LimitedURL,MaxCharsURLOnScreen); @@ -408,8 +407,7 @@ void Str_InsertLinks (char *Txt,unsigned long MaxLength,size_t MaxCharsURLOnScre /* Make a copy of this URL */ NumBytesToCopy = (Links[NumLink].NumActualBytes < MAX_BYTES_LIMITED_URL) ? Links[NumLink].NumActualBytes : MAX_BYTES_LIMITED_URL; - strncpy (LimitedURL,Links[NumLink].PtrStart,NumBytesToCopy); - LimitedURL[NumBytesToCopy] = '\0'; + Str_Copy (LimitedURL,Links[NumLink].PtrStart,NumBytesToCopy); /* Limit the length of the copy */ NumBytesToShow = Str_LimitLengthHTMLStr (LimitedURL,MaxCharsURLOnScreen); @@ -1316,7 +1314,7 @@ void Str_ChangeFormat (Str_ChangeFrom_t ChangeFrom,Str_ChangeTo_t ChangeTo, Lay_ShowErrorAndExit ("Space allocated to string is full."); /* Copy to appropiate place the special character string */ - strncpy (PtrDst,StrSpecialChar,LengthSpecStrDst); + Str_Copy (PtrDst,StrSpecialChar,LengthSpecStrDst); /* Increment pointer to character after ';' */ PtrSrc += LengthSpecStrSrc; @@ -1340,8 +1338,7 @@ void Str_ChangeFormat (Str_ChangeFrom_t ChangeFrom,Str_ChangeTo_t ChangeTo, } /***** Copy destination string with changes to source string *****/ - strncpy (Str,StrDst,LengthStrDst); // Str <-- StrDst - Str[LengthStrDst] = '\0'; + Str_Copy (Str,StrDst,LengthStrDst); // Str <-- StrDst /***** Free memory used for the destination string *****/ free ((void *) StrDst); @@ -2356,24 +2353,14 @@ void Str_SplitFullPathIntoPathAndFileName (const char *FullPath, /***** Get PathWithoutFileName *****/ LengthUntilFileName = (size_t) (PtrFileName - FullPath); // Last slash included if (LengthUntilFileName > 1) - { - if (LengthUntilFileName > PATH_MAX) - { - strncpy (PathWithoutFileName,FullPath,PATH_MAX); - PathWithoutFileName[PATH_MAX] = '\0'; - } - else - { - strncpy (PathWithoutFileName,FullPath,LengthUntilFileName - 1); // Do not copy ending slash - PathWithoutFileName[LengthUntilFileName - 1] = '\0'; - } - } + Str_Copy (PathWithoutFileName,FullPath, + LengthUntilFileName > PATH_MAX ? PATH_MAX : + LengthUntilFileName - 1); // Do not copy ending slash else PathWithoutFileName[0] = '\0'; /***** Get FileName *****/ - strncpy (FileName,PtrFileName,NAME_MAX); - FileName[NAME_MAX] = '\0'; + Str_Copy (FileName,PtrFileName,NAME_MAX); } /*****************************************************************************/ @@ -2712,13 +2699,10 @@ bool Str_ConvertFilFolLnkNameToValid (char *FileName) FileName); } else // FileName is empty - { - strncpy (Gbl.Message, - Gbl.FileBrowser.UploadingWithDropzone ? Txt_UPLOAD_FILE_Invalid_name_NO_HTML : - Txt_UPLOAD_FILE_Invalid_name, - Lay_MAX_BYTES_ALERT); - Gbl.Message[Lay_MAX_BYTES_ALERT] = '\0'; - } + Str_Copy (Gbl.Message, + Gbl.FileBrowser.UploadingWithDropzone ? Txt_UPLOAD_FILE_Invalid_name_NO_HTML : + Txt_UPLOAD_FILE_Invalid_name, + Lay_MAX_BYTES_ALERT); return FileNameIsOK; } @@ -2806,18 +2790,25 @@ void Str_GetMailBox (const char *Email,char *MailBox,size_t MaxLength) { Ptr++; // Skip '@' if (strchr (Ptr,(int) '@') == NULL) // No more '@' found - { - strncpy (MailBox,Ptr,MaxLength); - MailBox[MaxLength] = '\0'; - } + Str_Copy (MailBox,Ptr,MaxLength); } } +/*****************************************************************************/ +/****************************** Safe string copy *****************************/ +/*****************************************************************************/ + +void Str_Copy (char *Dst,const char *Src,size_t MaxLength) + { + strncpy (Dst,Src,MaxLength); + Dst[MaxLength] = '\0'; + } + /*****************************************************************************/ /************************** Safe string concatenation ************************/ /*****************************************************************************/ -void Str_Concat (char *Src,const char *Dst,size_t MaxLength) +void Str_Concat (char *Dst,const char *Src,size_t MaxLength) { - strncat (Src,Dst,MaxLength - strlen (Src)); + strncat (Dst,Src,MaxLength - strlen (Dst)); } diff --git a/swad_string.h b/swad_string.h index 6cc031fc..a518549f 100644 --- a/swad_string.h +++ b/swad_string.h @@ -119,6 +119,7 @@ void Str_ConvertToValidFileName (char *Str); void Str_CreateRandomAlphanumStr (char *Str,size_t Length); void Str_GetMailBox (const char *Email,char *MailBox,size_t MaxLength); -void Str_Concat (char *Src,const char *Dst,size_t MaxLength); +void Str_Copy (char *Dst,const char *Src,size_t MaxLength); +void Str_Concat (char *Dst,const char *Src,size_t MaxLength); #endif diff --git a/swad_survey.c b/swad_survey.c index 81429b77..0858f27f 100644 --- a/swad_survey.c +++ b/swad_survey.c @@ -2644,8 +2644,7 @@ static void Svy_ShowFormEditOneQst (long SvyCod,struct SurveyQuestion *SvyQst,ch SvyQst->AnswerType = Svy_ConvertFromStrAnsTypDBToAnsTyp (row[1]); /* Get the stem of the question from the database (row[2]) */ - strncpy (Txt,row[2],Cns_MAX_BYTES_TEXT); - Txt[Cns_MAX_BYTES_TEXT] = '\0'; + Str_Copy (Txt,row[2],Cns_MAX_BYTES_TEXT); /* Free structure that stores the query result */ DB_FreeMySQLResult (&mysql_res); @@ -2663,8 +2662,7 @@ static void Svy_ShowFormEditOneQst (long SvyCod,struct SurveyQuestion *SvyQst,ch if (!Svy_AllocateTextChoiceAnswer (SvyQst,NumAns)) Lay_ShowErrorAndExit (Gbl.Message); - strncpy (SvyQst->AnsChoice[NumAns].Text,row[2],Svy_MAX_BYTES_ANSWER); - SvyQst->AnsChoice[NumAns].Text[Svy_MAX_BYTES_ANSWER] = '\0'; + Str_Copy (SvyQst->AnsChoice[NumAns].Text,row[2],Svy_MAX_BYTES_ANSWER); } /* Free structure that stores the query result */ DB_FreeMySQLResult (&mysql_res); diff --git a/swad_test.c b/swad_test.c index ed7d679d..9ee33ee3 100644 --- a/swad_test.c +++ b/swad_test.c @@ -53,6 +53,7 @@ /***************************** Public constants ******************************/ /*****************************************************************************/ +// strings are limited to Tst_MAX_LENGTH_FEEDBACK_TYPE characters const char *Tst_FeedbackXML[Tst_NUM_TYPES_FEEDBACK] = { "nothing", @@ -61,6 +62,8 @@ const char *Tst_FeedbackXML[Tst_NUM_TYPES_FEEDBACK] = "eachGoodBad", "fullFeedback", }; + +// strings are limited to Tst_MAX_LENGTH_ANSWER_TYPE characters const char *Tst_StrAnswerTypesXML[Tst_NUM_ANS_TYPES] = { "int", @@ -1022,8 +1025,7 @@ void Tst_WriteQstStem (const char *Stem,const char *ClassStem) StemLength = strlen (Stem) * Str_MAX_LENGTH_SPEC_CHAR_HTML; if ((StemRigorousHTML = malloc (StemLength+1)) == NULL) Lay_ShowErrorAndExit ("Not enough memory to store stem of question."); - strncpy (StemRigorousHTML,Stem,StemLength); - StemRigorousHTML[StemLength] = '\0'; + Str_Copy (StemRigorousHTML,Stem,StemLength); Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, StemRigorousHTML,StemLength,false); @@ -1152,8 +1154,7 @@ void Tst_WriteQstFeedback (const char *Feedback,const char *ClassFeedback) FeedbackLength = strlen (Feedback) * Str_MAX_LENGTH_SPEC_CHAR_HTML; if ((FeedbackRigorousHTML = malloc (FeedbackLength+1)) == NULL) Lay_ShowErrorAndExit ("Not enough memory to store stem of question."); - strncpy (FeedbackRigorousHTML,Feedback,FeedbackLength); - FeedbackRigorousHTML[FeedbackLength] = '\0'; + Str_Copy (FeedbackRigorousHTML,Feedback,FeedbackLength); Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, FeedbackRigorousHTML,FeedbackLength,false); @@ -3050,8 +3051,7 @@ static void Tst_WriteAnswersOfAQstEdit (long QstCod) LengthAnswer = strlen (row[1]) * Str_MAX_LENGTH_SPEC_CHAR_HTML; if ((Answer = malloc (LengthAnswer+1)) == NULL) Lay_ShowErrorAndExit ("Not enough memory to store answer."); - strncpy (Answer,row[1],LengthAnswer); - Answer[LengthAnswer] = '\0'; + Str_Copy (Answer,row[1],LengthAnswer); Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, Answer,LengthAnswer,false); @@ -3064,8 +3064,7 @@ static void Tst_WriteAnswersOfAQstEdit (long QstCod) LengthFeedback = strlen (row[2]) * Str_MAX_LENGTH_SPEC_CHAR_HTML; if ((Feedback = malloc (LengthFeedback+1)) == NULL) Lay_ShowErrorAndExit ("Not enough memory to store feedback."); - strncpy (Feedback,row[2],LengthFeedback); - Feedback[LengthFeedback] = '\0'; + Str_Copy (Feedback,row[2],LengthFeedback); Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, Feedback,LengthFeedback,false); } @@ -3383,10 +3382,11 @@ static void Tst_WriteChoiceAnsViewTest (unsigned NumQst,long QstCod,bool Shuffle Lay_ShowErrorAndExit ("Wrong index of answer when showing a test."); /***** Copy text (row[1]) and convert it, that is in HTML, to rigorous HTML ******/ - strncpy (Gbl.Test.Answer.Options[NumOpt].Text,row[1],Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); - Gbl.Test.Answer.Options[NumOpt].Text[Tst_MAX_BYTES_ANSWER_OR_FEEDBACK] = '\0'; + Str_Copy (Gbl.Test.Answer.Options[NumOpt].Text,row[1], + Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, - Gbl.Test.Answer.Options[NumOpt].Text,Tst_MAX_BYTES_ANSWER_OR_FEEDBACK,false); + Gbl.Test.Answer.Options[NumOpt].Text, + Tst_MAX_BYTES_ANSWER_OR_FEEDBACK,false); /***** Copy image *****/ Img_GetImageNameTitleAndURLFromRow (row[3],row[4],row[5],&Gbl.Test.Answer.Options[NumOpt].Image); @@ -3481,10 +3481,11 @@ static void Tst_WriteChoiceAnsAssessTest (unsigned NumQst,MYSQL_RES *mysql_res, /***** Copy answer text (row[1]) and convert it, that is in HTML, to rigorous HTML ******/ - strncpy (Gbl.Test.Answer.Options[NumOpt].Text,row[1],Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); - Gbl.Test.Answer.Options[NumOpt].Text[Tst_MAX_BYTES_ANSWER_OR_FEEDBACK] = '\0'; + Str_Copy (Gbl.Test.Answer.Options[NumOpt].Text,row[1], + Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, - Gbl.Test.Answer.Options[NumOpt].Text,Tst_MAX_BYTES_ANSWER_OR_FEEDBACK,false); + Gbl.Test.Answer.Options[NumOpt].Text, + Tst_MAX_BYTES_ANSWER_OR_FEEDBACK,false); /***** Copy answer feedback (row[2]) and convert it, that is in HTML, to rigorous HTML ******/ @@ -3492,10 +3493,11 @@ static void Tst_WriteChoiceAnsAssessTest (unsigned NumQst,MYSQL_RES *mysql_res, if (row[2]) if (row[2][0]) { - strncpy (Gbl.Test.Answer.Options[NumOpt].Feedback,row[2],Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); - Gbl.Test.Answer.Options[NumOpt].Feedback[Tst_MAX_BYTES_ANSWER_OR_FEEDBACK] = '\0'; + Str_Copy (Gbl.Test.Answer.Options[NumOpt].Feedback,row[2], + Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, - Gbl.Test.Answer.Options[NumOpt].Feedback,Tst_MAX_BYTES_ANSWER_OR_FEEDBACK,false); + Gbl.Test.Answer.Options[NumOpt].Feedback, + Tst_MAX_BYTES_ANSWER_OR_FEEDBACK,false); } /***** Copy image *****/ @@ -3719,19 +3721,22 @@ static void Tst_WriteTextAnsAssessTest (unsigned NumQst,MYSQL_RES *mysql_res, Lay_ShowErrorAndExit (Gbl.Message); /***** Copy answer text (row[1]) and convert it, that is in HTML, to rigorous HTML ******/ - strncpy (Gbl.Test.Answer.Options[NumOpt].Text,row[1],Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); - Gbl.Test.Answer.Options[NumOpt].Text[Tst_MAX_BYTES_ANSWER_OR_FEEDBACK] = '\0'; - Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML,Gbl.Test.Answer.Options[NumOpt].Text,Tst_MAX_BYTES_ANSWER_OR_FEEDBACK,false); + Str_Copy (Gbl.Test.Answer.Options[NumOpt].Text,row[1], + Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); + Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, + Gbl.Test.Answer.Options[NumOpt].Text, + Tst_MAX_BYTES_ANSWER_OR_FEEDBACK,false); /***** Copy answer feedback (row[2]) and convert it, that is in HTML, to rigorous HTML ******/ if (Gbl.Test.Config.FeedbackType == Tst_FEEDBACK_FULL_FEEDBACK) if (row[2]) if (row[2][0]) { - strncpy (Gbl.Test.Answer.Options[NumOpt].Feedback,row[2],Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); - Gbl.Test.Answer.Options[NumOpt].Feedback[Tst_MAX_BYTES_ANSWER_OR_FEEDBACK] = '\0'; + Str_Copy (Gbl.Test.Answer.Options[NumOpt].Feedback,row[2], + Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, - Gbl.Test.Answer.Options[NumOpt].Feedback,Tst_MAX_BYTES_ANSWER_OR_FEEDBACK,false); + Gbl.Test.Answer.Options[NumOpt].Feedback, + Tst_MAX_BYTES_ANSWER_OR_FEEDBACK,false); } /***** Assign correctness (row[6]) of this answer (this option) *****/ @@ -5061,17 +5066,13 @@ static void Tst_GetQstDataFromDB (char *Stem,char *Feedback) Gbl.Test.Shuffle = (row[1][0] == 'Y'); /* Get the stem of the question from the database (row[2]) */ - strncpy (Stem,row[2],Cns_MAX_BYTES_TEXT); - Stem[Cns_MAX_BYTES_TEXT] = '\0'; + Str_Copy (Stem,row[2],Cns_MAX_BYTES_TEXT); /* Get the feedback of the question from the database (row[3]) */ Feedback[0] = '\0'; if (row[3]) if (row[3][0]) - { - strncpy (Feedback,row[3],Cns_MAX_BYTES_TEXT); - Feedback[Cns_MAX_BYTES_TEXT] = '\0'; - } + Str_Copy (Feedback,row[3],Cns_MAX_BYTES_TEXT); /* Get the image name, title and URL of the question from the database (row[4], row[5], row[6]) */ @@ -5087,8 +5088,7 @@ static void Tst_GetQstDataFromDB (char *Stem,char *Feedback) NumRow++) { row = mysql_fetch_row (mysql_res); - strncpy (Gbl.Test.Tags.Txt[NumRow],row[0],Tst_MAX_BYTES_TAG); - Gbl.Test.Tags.Txt[NumRow][Tst_MAX_BYTES_TAG] = '\0'; + Str_Copy (Gbl.Test.Tags.Txt[NumRow],row[0],Tst_MAX_BYTES_TAG); } /* Free structure that stores the query result */ @@ -5135,16 +5135,14 @@ static void Tst_GetQstDataFromDB (char *Stem,char *Feedback) if (!Tst_AllocateTextChoiceAnswer (NumOpt)) Lay_ShowErrorAndExit (Gbl.Message); - strncpy (Gbl.Test.Answer.Options[NumOpt].Text,row[1],Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); - Gbl.Test.Answer.Options[NumOpt].Text[Tst_MAX_BYTES_ANSWER_OR_FEEDBACK] = '\0'; + Str_Copy (Gbl.Test.Answer.Options[NumOpt].Text,row[1], + Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); // Feedback (row[2]) is initialized to empty string if (row[2]) if (row[2][0]) - { - strncpy (Gbl.Test.Answer.Options[NumOpt].Feedback,row[2],Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); - Gbl.Test.Answer.Options[NumOpt].Feedback[Tst_MAX_BYTES_ANSWER_OR_FEEDBACK] = '\0'; - } + Str_Copy (Gbl.Test.Answer.Options[NumOpt].Feedback,row[2], + Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); /* Copy image */ Img_GetImageNameTitleAndURLFromRow (row[3],row[4],row[5],&Gbl.Test.Answer.Options[NumOpt].Image); @@ -7931,12 +7929,12 @@ static void Tst_GetTestResultQuestionsFromDB (long TstCod) Lay_ShowErrorAndExit ("Wrong code of question."); /* Get indexes for this question (row[1]) */ - strncpy (Gbl.Test.StrIndexesOneQst[NumQst],row[1],Tst_MAX_SIZE_INDEXES_ONE_QST); - Gbl.Test.StrIndexesOneQst[NumQst][Tst_MAX_SIZE_INDEXES_ONE_QST] = '\0'; + Str_Copy (Gbl.Test.StrIndexesOneQst[NumQst],row[1], + Tst_MAX_SIZE_INDEXES_ONE_QST); /* Get answers selected by user for this question (row[2]) */ - strncpy (Gbl.Test.StrAnswersOneQst[NumQst],row[2],Tst_MAX_SIZE_ANSWERS_ONE_QST); - Gbl.Test.StrAnswersOneQst[NumQst][Tst_MAX_SIZE_ANSWERS_ONE_QST] = '\0'; + Str_Copy (Gbl.Test.StrAnswersOneQst[NumQst],row[2], + Tst_MAX_SIZE_ANSWERS_ONE_QST); /* Replace each comma by a separator of multiple parameters */ /* In database commas are used as separators instead of special chars */ diff --git a/swad_test.h b/swad_test.h index 292fe8df..da9fe610 100644 --- a/swad_test.h +++ b/swad_test.h @@ -48,6 +48,10 @@ #define Tst_CONFIG_DEFAULT_DEF_QUESTIONS 20 // Number of questions to be generated by default in a self-assessment test #define Tst_CONFIG_DEFAULT_MAX_QUESTIONS 30 // Maximum number of questions to be generated in a self-assessment test +#define Tst_MAX_LENGTH_FEEDBACK_TYPE 32 +#define Tst_MAX_LENGTH_ANSWER_TYPE 32 + + /*****************************************************************************/ /******************************* Public types ********************************/ /*****************************************************************************/ diff --git a/swad_test_import.c b/swad_test_import.c index d633da2f..3948c653 100644 --- a/swad_test_import.c +++ b/swad_test_import.c @@ -397,11 +397,11 @@ static void TsI_WriteAnswersOfAQstXML (long QstCod) void TsI_ImportQstsFromXML (void) { extern const char *Txt_The_file_is_not_X; - char PathTestPriv[PATH_MAX+1]; + char PathTestPriv[PATH_MAX + 1]; struct Param *Param; - char FileNameXMLSrc[PATH_MAX+1]; - char FileNameXMLTmp[PATH_MAX+1]; // Full name (including path and .xml) of the destination temporary file - char MIMEType[Brw_MAX_BYTES_MIME_TYPE+1]; + char FileNameXMLSrc[PATH_MAX + 1]; + char FileNameXMLTmp[PATH_MAX + 1]; // Full name (including path and .xml) of the destination temporary file + char MIMEType[Brw_MAX_BYTES_MIME_TYPE + 1]; bool WrongType = false; /***** Creates directory if not exists *****/ @@ -570,8 +570,8 @@ static void TsI_ImportQuestionsFromXMLBuffer (const char *XMLBuffer) { if (TagElem->Content) { - strncpy (Gbl.Test.Tags.Txt[Gbl.Test.Tags.Num],TagElem->Content,Tst_MAX_BYTES_TAG); - Gbl.Test.Tags.Txt[Gbl.Test.Tags.Num][Tst_MAX_BYTES_TAG] = '\0'; + Str_Copy (Gbl.Test.Tags.Txt[Gbl.Test.Tags.Num], + TagElem->Content,Tst_MAX_BYTES_TAG); Gbl.Test.Tags.Num++; } } @@ -587,8 +587,7 @@ static void TsI_ImportQuestionsFromXMLBuffer (const char *XMLBuffer) if (StemElem->Content) { /* Convert stem from text to HTML (in database stem is stored in HTML) */ - strncpy (Stem,StemElem->Content,Cns_MAX_BYTES_TEXT); - Stem[Cns_MAX_BYTES_TEXT] = '\0'; + Str_Copy (Stem,StemElem->Content,Cns_MAX_BYTES_TEXT); Str_ChangeFormat (Str_FROM_TEXT,Str_TO_HTML, Stem,Cns_MAX_BYTES_TEXT,true); @@ -607,8 +606,8 @@ static void TsI_ImportQuestionsFromXMLBuffer (const char *XMLBuffer) if (FeedbackElem->Content) { /* Convert feedback from text to HTML (in database feedback is stored in HTML) */ - strncpy (Feedback,FeedbackElem->Content,Cns_MAX_BYTES_TEXT); - Feedback[Cns_MAX_BYTES_TEXT] = '\0'; + Str_Copy (Feedback,FeedbackElem->Content, + Cns_MAX_BYTES_TEXT); Str_ChangeFormat (Str_FROM_TEXT,Str_TO_HTML, Feedback,Cns_MAX_BYTES_TEXT,true); @@ -829,11 +828,8 @@ static void TsI_GetAnswerFromXML (struct XMLElement *AnswerElem) Lay_ShowErrorAndExit (Gbl.Message); if (AnswerElem->Content) - { - strncpy (Gbl.Test.Answer.Options[0].Text,AnswerElem->Content, - Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); - Gbl.Test.Answer.Options[0].Text[Tst_MAX_BYTES_ANSWER_OR_FEEDBACK] = '\0'; - } + Str_Copy (Gbl.Test.Answer.Options[0].Text,AnswerElem->Content, + Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); break; case Tst_ANS_FLOAT: if (!Tst_AllocateTextChoiceAnswer (0)) @@ -847,11 +843,8 @@ static void TsI_GetAnswerFromXML (struct XMLElement *AnswerElem) if (!strcmp (LowerUpperElem->TagName,"lower")) { if (LowerUpperElem->Content) - { - strncpy (Gbl.Test.Answer.Options[0].Text,LowerUpperElem->Content, - Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); - Gbl.Test.Answer.Options[0].Text[Tst_MAX_BYTES_ANSWER_OR_FEEDBACK] = '\0'; - } + Str_Copy (Gbl.Test.Answer.Options[0].Text,LowerUpperElem->Content, + Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); break; // Only first element "lower" } for (LowerUpperElem = AnswerElem->FirstChild; @@ -860,11 +853,8 @@ static void TsI_GetAnswerFromXML (struct XMLElement *AnswerElem) if (!strcmp (LowerUpperElem->TagName,"upper")) { if (LowerUpperElem->Content) - { - strncpy (Gbl.Test.Answer.Options[1].Text,LowerUpperElem->Content, - Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); - Gbl.Test.Answer.Options[1].Text[Tst_MAX_BYTES_ANSWER_OR_FEEDBACK] = '\0'; - } + Str_Copy (Gbl.Test.Answer.Options[1].Text,LowerUpperElem->Content, + Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); break; // Only first element "upper" } break; @@ -904,9 +894,9 @@ static void TsI_GetAnswerFromXML (struct XMLElement *AnswerElem) { if (TextElem->Content) { - strncpy (Gbl.Test.Answer.Options[NumOpt].Text,TextElem->Content, - Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); - Gbl.Test.Answer.Options[NumOpt].Text[Tst_MAX_BYTES_ANSWER_OR_FEEDBACK] = '\0'; + Str_Copy (Gbl.Test.Answer.Options[NumOpt].Text, + TextElem->Content, + Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); /* Convert answer from text to HTML (in database answer text is stored in HTML) */ Str_ChangeFormat (Str_FROM_TEXT,Str_TO_HTML, @@ -922,9 +912,9 @@ static void TsI_GetAnswerFromXML (struct XMLElement *AnswerElem) { if (FeedbackElem->Content) { - strncpy (Gbl.Test.Answer.Options[NumOpt].Feedback,FeedbackElem->Content, - Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); - Gbl.Test.Answer.Options[NumOpt].Feedback[Tst_MAX_BYTES_ANSWER_OR_FEEDBACK] = '\0'; + Str_Copy (Gbl.Test.Answer.Options[NumOpt].Feedback, + FeedbackElem->Content, + Tst_MAX_BYTES_ANSWER_OR_FEEDBACK); /* Convert feedback from text to HTML (in database answer feedback is stored in HTML) */ Str_ChangeFormat (Str_FROM_TEXT,Str_TO_HTML, @@ -1132,8 +1122,8 @@ static void TsI_WriteRowImportedQst (struct XMLElement *StemElem, Str_MAX_LENGTH_SPEC_CHAR_HTML; if ((AnswerText = malloc (AnswerTextLength+1)) == NULL) Lay_ShowErrorAndExit ("Not enough memory to store answer."); - strncpy (AnswerText,Gbl.Test.Answer.Options[NumOpt].Text,AnswerTextLength); - AnswerText[AnswerTextLength] = '\0'; + Str_Copy (AnswerText,Gbl.Test.Answer.Options[NumOpt].Text, + AnswerTextLength); Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, AnswerText,AnswerTextLength,false); @@ -1147,8 +1137,9 @@ static void TsI_WriteRowImportedQst (struct XMLElement *StemElem, Str_MAX_LENGTH_SPEC_CHAR_HTML; if ((AnswerFeedback = malloc (AnswerFeedbackLength+1)) == NULL) Lay_ShowErrorAndExit ("Not enough memory to store feedback."); - strncpy (AnswerFeedback,Gbl.Test.Answer.Options[NumOpt].Feedback,AnswerFeedbackLength); - AnswerFeedback[AnswerFeedbackLength] = '\0'; + Str_Copy (AnswerFeedback, + Gbl.Test.Answer.Options[NumOpt].Feedback, + AnswerFeedbackLength); Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML, AnswerFeedback,AnswerFeedbackLength,false); } diff --git a/swad_text.c b/swad_text.c index 49bc4da6..0fca44c6 100644 --- a/swad_text.c +++ b/swad_text.c @@ -16769,39 +16769,39 @@ const char *Txt_LICENSES[Brw_NUM_LICENSES] = #endif , #if L==1 - "Tots els drets reservats" // All Rights Reserved + "Tots els drets reservats" // All Rights Reserved #elif L==2 - "Alle Rechte vorbehalten" // All Rights Reserved + "Alle Rechte vorbehalten" // All Rights Reserved #elif L==3 "All rights reserved" // All Rights Reserved #elif L==4 "Todos los derechos reservados" // All Rights Reserved #elif L==5 - "Tous droits réservés" // All Rights Reserved + "Tous droits réservés" // All Rights Reserved #elif L==6 "Todos los derechos reservados" // All Rights Reserved // Okoteve traducción #elif L==7 - "Tutti i diritti riservati" // All Rights Reserved + "Tutti i diritti riservati" // All Rights Reserved #elif L==8 - "Wszelkie prawa zastrzeżone" // All Rights Reserved + "Wszelkie prawa zastrzeżone" // All Rights Reserved #elif L==9 "Todos os direitos reservados" // All Rights Reserved #endif , #if L==1 - "CC Reconeixement" // CC Attribution License + "CC Reconeixement" // CC Attribution License #elif L==2 - "CC Namensnennung" // CC Attribution License + "CC Namensnennung" // CC Attribution License #elif L==3 - "CC Attribution" // CC Attribution License + "CC Attribution" // CC Attribution License #elif L==4 - "CC Reconocimiento" // CC Attribution License + "CC Reconocimiento" // CC Attribution License #elif L==5 - "CC Attribution" // CC Attribution License + "CC Attribution" // CC Attribution License #elif L==6 - "CC Reconocimiento" // CC Attribution License // Okoteve traducción + "CC Reconocimiento" // CC Attribution License // Okoteve traducción #elif L==7 - "CC Attribuzione" // CC Attribution License + "CC Attribuzione" // CC Attribution License #elif L==8 "CC Uznanie autorstwa" // CC Attribution License #elif L==9 @@ -16813,15 +16813,15 @@ const char *Txt_LICENSES[Brw_NUM_LICENSES] = #elif L==2 "CC Namensnennung - Weitergabe unter gleichen Bedingungen" // CC Attribution-ShareAlike License #elif L==3 - "CC Attribution - Share Alike" // CC Attribution-ShareAlike License + "CC Attribution - Share Alike" // CC Attribution-ShareAlike License #elif L==4 - "CC Reconocimiento - Compartir bajo la misma licencia" // CC Attribution-ShareAlike License + "CC Reconocimiento - Compartir bajo la misma licencia" // CC Attribution-ShareAlike License #elif L==5 - "CC Attribution - Partage à l'Identique" // CC Attribution-ShareAlike License + "CC Attribution - Partage à l'Identique" // CC Attribution-ShareAlike License #elif L==6 - "CC Reconocimiento - Compartir bajo la misma licencia" // CC Attribution-ShareAlike License // Okoteve traducción + "CC Reconocimiento - Compartir bajo la misma licencia" // CC Attribution-ShareAlike License // Okoteve traducción #elif L==7 - "CC Attribuzione - Condividi allo stesso modo" // CC Attribution-ShareAlike License + "CC Attribuzione - Condividi allo stesso modo" // CC Attribution-ShareAlike License #elif L==8 "CC Uznanie autorstwa - Na tych samych warunkach" // CC Attribution-ShareAlike License #elif L==9 @@ -16831,17 +16831,17 @@ const char *Txt_LICENSES[Brw_NUM_LICENSES] = #if L==1 "CC Reconeixement - Sense obra derivada" // CC Attribution-NoDerivs License #elif L==2 - "CC Namensnennung - Keine Bearbeitung" // CC Attribution-NoDerivs License + "CC Namensnennung - Keine Bearbeitung" // CC Attribution-NoDerivs License #elif L==3 - "CC Attribution - No Derivative Works" // CC Attribution-NoDerivs License + "CC Attribution - No Derivative Works" // CC Attribution-NoDerivs License #elif L==4 "CC Reconocimiento - Sin obras derivadas" // CC Attribution-NoDerivs License #elif L==5 - "CC Attribution - Pas de travaux dérivés" // CC Attribution-NoDerivs License + "CC Attribution - Pas de travaux dérivés" // CC Attribution-NoDerivs License #elif L==6 "CC Reconocimiento - Sin obras derivadas" // CC Attribution-NoDerivs License // Okoteve traducción #elif L==7 - "CC Attribuzione - Non opere derivate" // CC Attribution-NoDerivs License + "CC Attribuzione - Non opere derivate" // CC Attribution-NoDerivs License #elif L==8 "CC Uznanie autorstwa - Bez utworów zależnych" // CC Attribution-NoDerivs License #elif L==9 @@ -16851,7 +16851,7 @@ const char *Txt_LICENSES[Brw_NUM_LICENSES] = #if L==1 "CC Reconeixement - No comercial" // CC Attribution-NonCommercial License #elif L==2 - "CC Namensnennung - Keine kommerzielle Nutzung" // CC Attribution-NonCommercial License + "CC Namensnennung - Keine kommerzielle Nutzung" // CC Attribution-NonCommercial License #elif L==3 "CC Attribution - Noncommercial" // CC Attribution-NonCommercial License #elif L==4 @@ -16869,7 +16869,7 @@ const char *Txt_LICENSES[Brw_NUM_LICENSES] = #endif , #if L==1 - "CC Reconeixement - No comercial - Compartir igual" // CC Attribution-NonCommercial-ShareAlike License + "CC Reconeixement - No comercial - Compartir igual" // CC Attribution-NonCommercial-ShareAlike License #elif L==2 "CC Namensnennung - Keine kommerzielle Nutzung - Weitergabe unter gleichen Bedingungen" // CC Attribution-NonCommercial-ShareAlike License #elif L==3 @@ -16881,7 +16881,7 @@ const char *Txt_LICENSES[Brw_NUM_LICENSES] = #elif L==6 "CC Reconocimiento - No comercial - Compartir bajo la misma licencia" // CC Attribution-NonCommercial-ShareAlike License // Okoteve traducción #elif L==7 - "CC Attribuzione - Non commerciale - Condividi allo stesso modo" // CC Attribution-NonCommercial-ShareAlike License + "CC Attribuzione - Non commerciale - Condividi allo stesso modo" // CC Attribution-NonCommercial-ShareAlike License #elif L==8 "CC Uznanie autorstwa - Użycie niekomercyjne - Na tych samych warunkach" // CC Attribution-NonCommercial-ShareAlike License #elif L==9 @@ -16889,21 +16889,21 @@ const char *Txt_LICENSES[Brw_NUM_LICENSES] = #endif , #if L==1 - "CC Reconeixement - No comercial - Sense obra derivada" // CC Attribution-NonCommercial-NoDerivs License + "CC Reconeixement - No comercial - Sense obra derivada" // CC Attribution-NonCommercial-NoDerivs License #elif L==2 "CC Namensnennung - Keine kommerzielle Nutzung - Keine Bearbeitung" // CC Attribution-NonCommercial-NoDerivs License #elif L==3 - "CC Attribution - Noncommercial - No Derivative Works" // CC Attribution-NonCommercial-NoDerivs License + "CC Attribution - Noncommercial - No Derivative Works" // CC Attribution-NonCommercial-NoDerivs License #elif L==4 "CC Reconocimiento - No comercial - Sin obras derivadas" // CC Attribution-NonCommercial-NoDerivs License #elif L==5 - "CC Attribution - Pas d’Utilisation Commerciale - Pas de travaux dérivés" // CC Attribution-NonCommercial-NoDerivs License + "CC Attribution - Pas d’Utilisation Commerciale - Pas de travaux dérivés" // CC Attribution-NonCommercial-NoDerivs License #elif L==6 "CC Reconocimiento - No comercial - Sin obras derivadas" // CC Attribution-NonCommercial-NoDerivs License // Okoteve traducción #elif L==7 "CC Attribuzione - Non commerciale - Non opere derivate" // CC Attribution-NonCommercial-NoDerivs License #elif L==8 - "CC Uznanie autorstwa - Użycie niekomercyjne - Bez utworów zależnych" // CC Attribution-NonCommercial-NoDerivs License + "CC Uznanie autorstwa - Użycie niekomercyjne - Bez utworów zależnych" // CC Attribution-NonCommercial-NoDerivs License #elif L==9 "CC Atribuição - NãoComercial - Trabalhos Derivados Proíbidos" // CC Attribution-NonCommercial-NoDerivs License #endif diff --git a/swad_user.c b/swad_user.c index 38858f76..0e963d20 100644 --- a/swad_user.c +++ b/swad_user.c @@ -429,8 +429,8 @@ void Usr_GetEncryptedUsrCodFromUsrCod (struct UsrData *UsrDat) // TODO: Remove t /***** Get encrypted user's code *****/ row = mysql_fetch_row (mysql_res); - strncpy (UsrDat->EncryptedUsrCod,row[0],sizeof (UsrDat->EncryptedUsrCod) - 1); - UsrDat->EncryptedUsrCod[sizeof (UsrDat->EncryptedUsrCod) - 1] = '\0'; + Str_Copy (UsrDat->EncryptedUsrCod,row[0], + Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64); /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); @@ -478,12 +478,11 @@ void Usr_GetUsrDataFromUsrCod (struct UsrData *UsrDat) row = mysql_fetch_row (mysql_res); /* Get encrypted user's code */ - strncpy (UsrDat->EncryptedUsrCod,row[0],sizeof (UsrDat->EncryptedUsrCod) - 1); - UsrDat->EncryptedUsrCod[sizeof (UsrDat->EncryptedUsrCod) - 1] = '\0'; + Str_Copy (UsrDat->EncryptedUsrCod,row[0], + Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64); /* Get encrypted password */ - strncpy (UsrDat->Password,row[1],sizeof (UsrDat->Password) - 1); - UsrDat->Password[sizeof (UsrDat->Password) - 1] = '\0'; + Str_Copy (UsrDat->Password,row[1],Cry_LENGTH_ENCRYPTED_STR_SHA512_BASE64); /* Get roles */ UsrDat->RoleInCurrentCrsDB = Rol_GetRoleInCrs (Gbl.CurrentCrs.Crs.CrsCod,UsrDat->UsrCod); @@ -495,12 +494,9 @@ void Usr_GetUsrDataFromUsrCod (struct UsrData *UsrDat) Rol_VISITOR; // User belongs to some courses /* Get name */ - strncpy (UsrDat->Surname1 ,row[2],sizeof (UsrDat->Surname1 ) - 1); - UsrDat->Surname1 [sizeof (UsrDat->Surname1 ) - 1] = '\0'; - strncpy (UsrDat->Surname2 ,row[3],sizeof (UsrDat->Surname2 ) - 1); - UsrDat->Surname2 [sizeof (UsrDat->Surname2 ) - 1] = '\0'; - strncpy (UsrDat->FirstName,row[4],sizeof (UsrDat->FirstName) - 1); - UsrDat->FirstName[sizeof (UsrDat->FirstName) - 1] = '\0'; + Str_Copy (UsrDat->Surname1 ,row[2],Usr_MAX_BYTES_NAME); + Str_Copy (UsrDat->Surname2 ,row[3],Usr_MAX_BYTES_NAME); + Str_Copy (UsrDat->FirstName,row[4],Usr_MAX_BYTES_NAME); /* Get sex */ UsrDat->Sex = Usr_GetSexFromStr (row[5]); @@ -545,8 +541,7 @@ void Usr_GetUsrDataFromUsrCod (struct UsrData *UsrDat) UsrDat->Prefs.FirstDayOfWeek = UnsignedNum; /* Get rest of data */ - strncpy (UsrDat->Photo,row[10],sizeof (UsrDat->Photo) - 1); - UsrDat->Photo[sizeof (UsrDat->Photo) - 1] = '\0'; + Str_Copy (UsrDat->Photo,row[10],Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64); UsrDat->PhotoVisibility = Pri_GetVisibilityFromStr (row[11]); UsrDat->ProfileVisibility = Pri_GetVisibilityFromStr (row[12]); UsrDat->CtyCod = Str_ConvertStrCodToLongCod (row[13]); @@ -555,21 +550,14 @@ void Usr_GetUsrDataFromUsrCod (struct UsrData *UsrDat) UsrDat->Tch.DptCod = Str_ConvertStrCodToLongCod (row[16]); UsrDat->Tch.CtrCod = Str_ConvertStrCodToLongCod (row[17]); - strncpy (UsrDat->Tch.Office ,row[18],sizeof (UsrDat->Tch.Office ) - 1); - UsrDat->Tch.Office [sizeof (UsrDat->Tch.Office ) - 1] = '\0'; - strncpy (UsrDat->Tch.OfficePhone,row[19],sizeof (UsrDat->Tch.OfficePhone) - 1); - UsrDat->Tch.OfficePhone[sizeof (UsrDat->Tch.OfficePhone) - 1] = '\0'; + Str_Copy (UsrDat->Tch.Office ,row[18],Cns_MAX_BYTES_STRING); + Str_Copy (UsrDat->Tch.OfficePhone,row[19],Usr_MAX_BYTES_PHONE); - strncpy (UsrDat->LocalAddress ,row[20],sizeof (UsrDat->LocalAddress ) - 1); - UsrDat->LocalAddress [sizeof (UsrDat->LocalAddress ) - 1] = '\0'; - strncpy (UsrDat->LocalPhone ,row[21],sizeof (UsrDat->LocalPhone ) - 1); - UsrDat->LocalPhone [sizeof (UsrDat->LocalPhone ) - 1] = '\0'; - strncpy (UsrDat->FamilyAddress,row[22],sizeof (UsrDat->FamilyAddress) - 1); - UsrDat->FamilyAddress[sizeof (UsrDat->FamilyAddress) - 1] = '\0'; - strncpy (UsrDat->FamilyPhone ,row[23],sizeof (UsrDat->FamilyPhone ) - 1); - UsrDat->FamilyPhone [sizeof (UsrDat->FamilyPhone ) - 1] = '\0'; - strncpy (UsrDat->OriginPlace ,row[24],sizeof (UsrDat->OriginPlace ) - 1); - UsrDat->OriginPlace [sizeof (UsrDat->OriginPlace ) - 1] = '\0'; + Str_Copy (UsrDat->LocalAddress ,row[20],Cns_MAX_BYTES_STRING); + Str_Copy (UsrDat->LocalPhone ,row[21],Usr_MAX_BYTES_PHONE); + Str_Copy (UsrDat->FamilyAddress,row[22],Cns_MAX_BYTES_STRING); + Str_Copy (UsrDat->FamilyPhone ,row[23],Usr_MAX_BYTES_PHONE); + Str_Copy (UsrDat->OriginPlace ,row[24],Cns_MAX_BYTES_STRING); strcpy (StrBirthday, row[25] ? row[25] : "0000-00-00"); @@ -632,11 +620,8 @@ static void Usr_GetUsrCommentsFromString (char *Str,struct UsrData *UsrDat) { /***** Check that memory for comments is allocated *****/ if (UsrDat->Comments) - { /***** Copy comments from Str to Comments *****/ - strncpy (UsrDat->Comments,Str,Cns_MAX_BYTES_TEXT); - UsrDat->Comments[Cns_MAX_BYTES_TEXT] = '\0'; - } + Str_Copy (UsrDat->Comments,Str,Cns_MAX_BYTES_TEXT); } /*****************************************************************************/ @@ -2230,8 +2215,9 @@ unsigned Usr_GetParamOtherUsrIDNickOrEMailAndGetUsrCods (struct ListUsrCods *Lis /* Allocate space for the list */ ID_ReallocateListIDs (&Gbl.Usrs.Other.UsrDat,1); - strncpy (Gbl.Usrs.Other.UsrDat.IDs.List[0].ID,Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail,ID_MAX_LENGTH_USR_ID); - Gbl.Usrs.Other.UsrDat.IDs.List[0].ID[ID_MAX_LENGTH_USR_ID] = '\0'; + Str_Copy (Gbl.Usrs.Other.UsrDat.IDs.List[0].ID, + Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail, + ID_MAX_LENGTH_USR_ID); Str_ConvertToUpperText (Gbl.Usrs.Other.UsrDat.IDs.List[0].ID); /* Check if user's ID exists in database */ @@ -2532,8 +2518,8 @@ static bool Usr_ChkUsrAndGetUsrDataFromDirectLogin (void) /***** Allocate space for the list *****/ ID_ReallocateListIDs (&Gbl.Usrs.Me.UsrDat,1); - strncpy (Gbl.Usrs.Me.UsrDat.IDs.List[0].ID,Gbl.Usrs.Me.UsrIdLogin,ID_MAX_LENGTH_USR_ID); - Gbl.Usrs.Me.UsrDat.IDs.List[0].ID[ID_MAX_LENGTH_USR_ID] = '\0'; + Str_Copy (Gbl.Usrs.Me.UsrDat.IDs.List[0].ID,Gbl.Usrs.Me.UsrIdLogin, + ID_MAX_LENGTH_USR_ID); Str_ConvertToUpperText (Gbl.Usrs.Me.UsrDat.IDs.List[0].ID); /* Check if user's ID exists in database, and get user's data */ @@ -4681,27 +4667,24 @@ static void Usr_GetListUsrsFromQuery (const char *Query,Rol_Role_t Role,Sco_Scop UsrInList->UsrCod = Str_ConvertStrCodToLongCod (row[0]); /* Get encrypted user's code (row[1]) */ - strncpy (UsrInList->EncryptedUsrCod,row[1],sizeof (UsrInList->EncryptedUsrCod) - 1); - UsrInList->EncryptedUsrCod[sizeof (UsrInList->EncryptedUsrCod) - 1] = '\0'; + Str_Copy (UsrInList->EncryptedUsrCod,row[1], + Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64); /* Get user's surname 1 (row[2]) */ - strncpy (UsrInList->Surname1 ,row[2],sizeof (UsrInList->Surname1 ) - 1); - UsrInList->Surname1 [sizeof (UsrInList->Surname1 ) - 1] = '\0'; + Str_Copy (UsrInList->Surname1 ,row[2],Usr_MAX_BYTES_NAME); /* Get user's surname 2 (row[3]) */ - strncpy (UsrInList->Surname2 ,row[3],sizeof (UsrInList->Surname2 ) - 1); - UsrInList->Surname2 [sizeof (UsrInList->Surname2 ) - 1] = '\0'; + Str_Copy (UsrInList->Surname2 ,row[3],Usr_MAX_BYTES_NAME); /* Get user's first name (row[4]) */ - strncpy (UsrInList->FirstName,row[4],sizeof (UsrInList->FirstName) - 1); - UsrInList->FirstName[sizeof (UsrInList->FirstName) - 1] = '\0'; + Str_Copy (UsrInList->FirstName,row[4],Usr_MAX_BYTES_NAME); /* Get user's sex (row[5]) */ UsrInList->Sex = Usr_GetSexFromStr (row[5]); /* Get user's photo (row[6]) */ - strncpy (UsrInList->Photo,row[6],sizeof (UsrInList->Photo) - 1); - UsrInList->Photo[sizeof (UsrInList->Photo) - 1] = '\0'; + Str_Copy (UsrInList->Photo,row[6], + Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64); /* Get user's photo visibility (row[7]) */ UsrInList->PhotoVisibility = Pri_GetVisibilityFromStr (row[7]); @@ -5085,8 +5068,8 @@ bool Usr_GetListMsgRecipientsWrittenExplicitelyBySender (bool WriteErrorMsgs) /***** Allocate space for the list *****/ ID_ReallocateListIDs (&UsrDat,1); - strncpy (UsrDat.IDs.List[0].ID,UsrIDNickOrEmail,ID_MAX_LENGTH_USR_ID); - UsrDat.IDs.List[0].ID[ID_MAX_LENGTH_USR_ID] = '\0'; + Str_Copy (UsrDat.IDs.List[0].ID,UsrIDNickOrEmail, + ID_MAX_LENGTH_USR_ID); /***** Check if a user exists having this user's ID *****/ if (ID_GetListUsrCodsFromUsrID (&UsrDat,NULL,&ListUsrCods,false)) diff --git a/swad_user.h b/swad_user.h index ad16fdf5..3757a915 100644 --- a/swad_user.h +++ b/swad_user.h @@ -116,15 +116,15 @@ typedef enum struct UsrData { long UsrCod; - char EncryptedUsrCod [Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64+1]; - char UsrIDNickOrEmail[Usr_MAX_BYTES_USR_LOGIN+1]; // String to store the ID, nickname or email + char EncryptedUsrCod [Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64 + 1]; + char UsrIDNickOrEmail[Usr_MAX_BYTES_USR_LOGIN + 1]; // String to store the ID, nickname or email struct { struct ListIDs *List; unsigned Num; } IDs; - char Nickname [Nck_MAX_LENGTH_NICKNAME_WITHOUT_ARROBA+1]; - char Password [Cry_LENGTH_ENCRYPTED_STR_SHA512_BASE64+1]; + char Nickname [Nck_MAX_LENGTH_NICKNAME_WITHOUT_ARROBA + 1]; + char Password [Cry_LENGTH_ENCRYPTED_STR_SHA512_BASE64 + 1]; Rol_Role_t RoleInCurrentCrsDB; int Roles; // Check always if filled/calculated // >=0 ==> filled/calculated @@ -133,7 +133,7 @@ struct UsrData char Surname1 [Usr_MAX_BYTES_NAME + 1]; char Surname2 [Usr_MAX_BYTES_NAME + 1]; char FirstName [Usr_MAX_BYTES_NAME + 1]; - char FullName [(Usr_MAX_BYTES_NAME + 1) * 3]; + char FullName [Usr_MAX_BYTES_FULL_NAME + 1]; Usr_Sex_t Sex; char Email [Usr_MAX_BYTES_USR_EMAIL + 1]; bool EmailConfirmed; diff --git a/swad_web_service.c b/swad_web_service.c index 10c0f5ac..d11548c1 100644 --- a/swad_web_service.c +++ b/swad_web_service.c @@ -192,6 +192,8 @@ Svc_Role_t Svc_RolRole_to_SvcRole[Rol_NUM_ROLES] = Svc_ROLE_UNKNOWN, // Rol_SYS_ADM }; +#define Svc_LENGTH_WS_KEY Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64 + /*****************************************************************************/ /********************************* Data types ********************************/ /*****************************************************************************/ @@ -200,7 +202,6 @@ Svc_Role_t Svc_RolRole_to_SvcRole[Rol_NUM_ROLES] = /***************************** Private prototypes ****************************/ /*****************************************************************************/ -// static int Svc_CheckIfIPIsAllowed (void); static int Svc_GetPlgCodFromAppKey (const char *appKey); static int Svc_CheckIdSession (const char *IdSession); static int Svc_CheckWSKey (char *WSKey); @@ -272,38 +273,6 @@ void Svc_Exit (const char *DetailErrorMessage) exit (ReturnCode); } -/*****************************************************************************/ -/*********** Check if the IP of the requester of a web service ***************/ -/*********** is one of the IP allowed in the plugins ***************/ -/*****************************************************************************/ -/* -static int Svc_CheckIfIPIsAllowed (void) - { - char IP[Cns_MAX_LENGTH_IP+1]; - char Query[256+Cns_MAX_LENGTH_IP]; - - ***** Get IP ***** - if (getenv ("REMOTE_ADDR")) - { - strncpy (IP,getenv ("REMOTE_ADDR"),Cns_MAX_LENGTH_IP); - IP[Cns_MAX_LENGTH_IP] = '\0'; - } - else - IP[0] = '\0'; - - ***** Get number of plugins with a IP address ***** - sprintf (Query,"SELECT COUNT(*) FROM plugins WHERE IP='%s'",IP); - if (!DB_QueryCOUNT (Query,"can not check IP")) - { - sprintf (Gbl.Message,"Sender's IP (%s) is forbidden",IP); - return soap_sender_fault (Gbl.soap, - Gbl.Message, - "The IP of the requester of a web service is not allowed"); - } - - return SOAP_OK; - } -*/ /*****************************************************************************/ /****** Check if the application key of the requester of a web service *******/ /****** is one of the application keys allowed in the plugins *******/ @@ -581,23 +550,16 @@ static bool Svc_GetSomeUsrDataFromUsrCod (struct UsrData *UsrDat,long CrsCod) row = mysql_fetch_row (mysql_res); /* Get user's name */ - strncpy (UsrDat->Surname1 ,row[0],sizeof (UsrDat->Surname1 )-1); - UsrDat->Surname1 [sizeof (UsrDat->Surname1 )-1] = '\0'; - strncpy (UsrDat->Surname2 ,row[1],sizeof (UsrDat->Surname2 )-1); - UsrDat->Surname2 [sizeof (UsrDat->Surname2 )-1] = '\0'; - strncpy (UsrDat->FirstName,row[2],sizeof (UsrDat->FirstName)-1); - UsrDat->FirstName[sizeof (UsrDat->FirstName)-1] = '\0'; + Str_Copy (UsrDat->Surname1 ,row[0],Usr_MAX_BYTES_NAME); + Str_Copy (UsrDat->Surname2 ,row[1],Usr_MAX_BYTES_NAME); + Str_Copy (UsrDat->FirstName,row[2],Usr_MAX_BYTES_NAME); /* Get user's photo */ - strncpy (UsrDat->Photo,row[3],sizeof (UsrDat->Photo)-1); - UsrDat->Photo[sizeof (UsrDat->Photo)-1] = '\0'; + Str_Copy (UsrDat->Photo,row[3],Cry_LENGTH_ENCRYPTED_STR_SHA256_BASE64); /* Get user's brithday */ if (row[4]) - { - strncpy (UsrDat->Birthday.YYYYMMDD,row[4],Dat_LENGTH_YYYYMMDD); - UsrDat->Birthday.YYYYMMDD[Dat_LENGTH_YYYYMMDD] = '\0'; - } + Str_Copy (UsrDat->Birthday.YYYYMMDD,row[4],Dat_LENGTH_YYYYMMDD); else strcpy (UsrDat->Birthday.YYYYMMDD,"00000000"); @@ -685,7 +647,7 @@ int swad__createAccount (struct soap *soap, Gbl.WebService.Function = Svc_createAccount; /***** Allocate space for strings *****/ - createAccountOut->wsKey = (char *) soap_malloc (Gbl.soap,256); + createAccountOut->wsKey = (char *) soap_malloc (Gbl.soap,Svc_LENGTH_WS_KEY + 1); /***** Default values returned on error *****/ createAccountOut->userCode = 0; // Undefined error @@ -753,8 +715,8 @@ static int Svc_CheckParamsNewAccount (char *NewNicknameWithArroba, // Input /***** Step 1/3: Check new nickname *****/ /* Make a copy without possible starting arrobas */ - strncpy (NewNicknameWithoutArroba,NewNicknameWithArroba,Nck_MAX_BYTES_NICKNAME_WITH_ARROBA); - NewNicknameWithoutArroba[Nck_MAX_BYTES_NICKNAME_WITH_ARROBA] = '\0'; + Str_Copy (NewNicknameWithoutArroba,NewNicknameWithArroba, + Nck_MAX_BYTES_NICKNAME_WITH_ARROBA); if (Nck_CheckIfNickWithArrobaIsValid (NewNicknameWithArroba)) // If new nickname is valid { /***** Remove arrobas at the beginning *****/ @@ -798,13 +760,13 @@ int swad__loginByUserPasswordKey (struct soap *soap, char *userID,char *userPassword,char *appKey, // input struct swad__loginByUserPasswordKeyOutput *loginByUserPasswordKeyOut) // output { - char UsrIDNickOrEmail[512]; + char UsrIDNickOrEmail[Usr_MAX_BYTES_USR_LOGIN + 1]; int ReturnCode; char Query[512]; MYSQL_RES *mysql_res; MYSQL_ROW row; unsigned NumRows; - char PhotoURL[PATH_MAX+1]; + char PhotoURL[Cns_MAX_BYTES_URL + 1]; bool UsrFound; /***** Initializations *****/ @@ -812,14 +774,14 @@ int swad__loginByUserPasswordKey (struct soap *soap, Gbl.WebService.Function = Svc_loginByUserPasswordKey; /***** Allocate space for strings *****/ - loginByUserPasswordKeyOut->wsKey = (char *) soap_malloc (Gbl.soap,256); + loginByUserPasswordKeyOut->wsKey = (char *) soap_malloc (Gbl.soap,Svc_LENGTH_WS_KEY + 1); loginByUserPasswordKeyOut->userNickname = (char *) soap_malloc (Gbl.soap,Nck_MAX_LENGTH_NICKNAME_WITHOUT_ARROBA+1); - loginByUserPasswordKeyOut->userID = (char *) soap_malloc (Gbl.soap,256); + loginByUserPasswordKeyOut->userID = (char *) soap_malloc (Gbl.soap,ID_MAX_LENGTH_USR_ID + 1); loginByUserPasswordKeyOut->userFirstname = (char *) soap_malloc (Gbl.soap,Usr_MAX_BYTES_NAME + 1); loginByUserPasswordKeyOut->userSurname1 = (char *) soap_malloc (Gbl.soap,Usr_MAX_BYTES_NAME + 1); loginByUserPasswordKeyOut->userSurname2 = (char *) soap_malloc (Gbl.soap,Usr_MAX_BYTES_NAME + 1); - loginByUserPasswordKeyOut->userPhoto = (char *) soap_malloc (Gbl.soap,PATH_MAX+1); - loginByUserPasswordKeyOut->userBirthday = (char *) soap_malloc (Gbl.soap,8+2+2+1); + loginByUserPasswordKeyOut->userPhoto = (char *) soap_malloc (Gbl.soap,Cns_MAX_BYTES_URL + 1); + loginByUserPasswordKeyOut->userBirthday = (char *) soap_malloc (Gbl.soap,Dat_LENGTH_YYYYMMDD + 1); /***** Default values returned on error *****/ loginByUserPasswordKeyOut->userCode = -1; @@ -838,8 +800,7 @@ int swad__loginByUserPasswordKey (struct soap *soap, return ReturnCode; /***** Check if user's email, @nickname or ID are valid *****/ - strncpy (UsrIDNickOrEmail,userID,255); - UsrIDNickOrEmail[255] = '\0'; + Str_Copy (UsrIDNickOrEmail,userID,Usr_MAX_BYTES_USR_LOGIN); if (Nck_CheckIfNickWithArrobaIsValid (UsrIDNickOrEmail)) // 1: It's a nickname { Str_RemoveLeadingArrobas (UsrIDNickOrEmail); @@ -908,28 +869,26 @@ int swad__loginByUserPasswordKey (struct soap *soap, loginByUserPasswordKeyOut->userCode = (int) Gbl.Usrs.Me.UsrDat.UsrCod; - strncpy (loginByUserPasswordKeyOut->userNickname,Gbl.Usrs.Me.UsrDat.Nickname,Nck_MAX_LENGTH_NICKNAME_WITHOUT_ARROBA); - loginByUserPasswordKeyOut->userNickname[Nck_MAX_LENGTH_NICKNAME_WITHOUT_ARROBA] = '\0'; + Str_Copy (loginByUserPasswordKeyOut->userNickname, + Gbl.Usrs.Me.UsrDat.Nickname, + Nck_MAX_LENGTH_NICKNAME_WITHOUT_ARROBA); if (Gbl.Usrs.Me.UsrDat.IDs.Num) - { - strncpy (loginByUserPasswordKeyOut->userID,Gbl.Usrs.Me.UsrDat.IDs.List[0].ID,255); // TODO: What user's ID? - loginByUserPasswordKeyOut->userID[255] = '\0'; - } + Str_Copy (loginByUserPasswordKeyOut->userID, + Gbl.Usrs.Me.UsrDat.IDs.List[0].ID,ID_MAX_LENGTH_USR_ID); // TODO: What user's ID? - strncpy (loginByUserPasswordKeyOut->userSurname1 ,Gbl.Usrs.Me.UsrDat.Surname1 ,Usr_MAX_BYTES_NAME); - loginByUserPasswordKeyOut->userSurname1 [Usr_MAX_BYTES_NAME] = '\0'; - strncpy (loginByUserPasswordKeyOut->userSurname2 ,Gbl.Usrs.Me.UsrDat.Surname2 ,Usr_MAX_BYTES_NAME); - loginByUserPasswordKeyOut->userSurname2 [Usr_MAX_BYTES_NAME] = '\0'; - strncpy (loginByUserPasswordKeyOut->userFirstname,Gbl.Usrs.Me.UsrDat.FirstName,Usr_MAX_BYTES_NAME); - loginByUserPasswordKeyOut->userFirstname[Usr_MAX_BYTES_NAME] = '\0'; + Str_Copy (loginByUserPasswordKeyOut->userSurname1, + Gbl.Usrs.Me.UsrDat.Surname1,Usr_MAX_BYTES_NAME); + Str_Copy (loginByUserPasswordKeyOut->userSurname2, + Gbl.Usrs.Me.UsrDat.Surname2,Usr_MAX_BYTES_NAME); + Str_Copy (loginByUserPasswordKeyOut->userFirstname, + Gbl.Usrs.Me.UsrDat.FirstName,Usr_MAX_BYTES_NAME); Pho_BuildLinkToPhoto (&Gbl.Usrs.Me.UsrDat,PhotoURL); - strncpy (loginByUserPasswordKeyOut->userPhoto,PhotoURL,PATH_MAX); - loginByUserPasswordKeyOut->userPhoto[PATH_MAX] = '\0'; + Str_Copy (loginByUserPasswordKeyOut->userPhoto,PhotoURL,Cns_MAX_BYTES_URL); - strncpy (loginByUserPasswordKeyOut->userBirthday,Gbl.Usrs.Me.UsrDat.Birthday.YYYYMMDD,Dat_LENGTH_YYYYMMDD); - loginByUserPasswordKeyOut->userBirthday[Dat_LENGTH_YYYYMMDD] = '\0'; + Str_Copy (loginByUserPasswordKeyOut->userBirthday, + Gbl.Usrs.Me.UsrDat.Birthday.YYYYMMDD,Dat_LENGTH_YYYYMMDD); loginByUserPasswordKeyOut->userRole = Svc_RolRole_to_SvcRole[Gbl.Usrs.Me.UsrDat.RoleInCurrentCrsDB]; @@ -966,7 +925,7 @@ int swad__loginBySessionKey (struct soap *soap, MYSQL_RES *mysql_res; MYSQL_ROW row; unsigned NumRows; - char PhotoURL[PATH_MAX+1]; + char PhotoURL[Cns_MAX_BYTES_URL + 1]; bool UsrFound; /***** Initializations *****/ @@ -974,16 +933,16 @@ int swad__loginBySessionKey (struct soap *soap, Gbl.WebService.Function = Svc_loginBySessionKey; /***** Allocate space for strings *****/ - loginBySessionKeyOut->wsKey = (char *) soap_malloc (Gbl.soap,256); + loginBySessionKeyOut->wsKey = (char *) soap_malloc (Gbl.soap,Svc_LENGTH_WS_KEY + 1); loginBySessionKeyOut->userNickname = (char *) soap_malloc (Gbl.soap,Nck_MAX_LENGTH_NICKNAME_WITHOUT_ARROBA + 1); - loginBySessionKeyOut->userID = (char *) soap_malloc (Gbl.soap,256); + loginBySessionKeyOut->userID = (char *) soap_malloc (Gbl.soap,ID_MAX_LENGTH_USR_ID + 1); loginBySessionKeyOut->userFirstname = (char *) soap_malloc (Gbl.soap,Usr_MAX_BYTES_NAME + 1); loginBySessionKeyOut->userSurname1 = (char *) soap_malloc (Gbl.soap,Usr_MAX_BYTES_NAME + 1); loginBySessionKeyOut->userSurname2 = (char *) soap_malloc (Gbl.soap,Usr_MAX_BYTES_NAME + 1); - loginBySessionKeyOut->userPhoto = (char *) soap_malloc (Gbl.soap,PATH_MAX+1); - loginBySessionKeyOut->userBirthday = (char *) soap_malloc (Gbl.soap,8+2+2+1); - loginBySessionKeyOut->degreeName = (char *) soap_malloc (Gbl.soap,256); - loginBySessionKeyOut->courseName = (char *) soap_malloc (Gbl.soap,256); + loginBySessionKeyOut->userPhoto = (char *) soap_malloc (Gbl.soap,Cns_MAX_BYTES_URL + 1); + loginBySessionKeyOut->userBirthday = (char *) soap_malloc (Gbl.soap,Dat_LENGTH_YYYYMMDD + 1); + loginBySessionKeyOut->degreeName = (char *) soap_malloc (Gbl.soap,Deg_MAX_LENGTH_DEGREE_FULL_NAME + 1); + loginBySessionKeyOut->courseName = (char *) soap_malloc (Gbl.soap,Crs_MAX_LENGTH_COURSE_FULL_NAME + 1); /***** Default values returned on error *****/ loginBySessionKeyOut->userCode = -1; @@ -1005,10 +964,6 @@ int swad__loginBySessionKey (struct soap *soap, if ((ReturnCode = Svc_GetPlgCodFromAppKey ((const char *) appKey)) != SOAP_OK) return ReturnCode; - /***** Check IP of the sender *****/ -// if ((ReturnCode = Svc_CheckIfIPIsAllowed ()) != SOAP_OK) -// return ReturnCode; - /***** Check length of session identifier *****/ if (sessionID == NULL) return soap_sender_fault (Gbl.soap, @@ -1031,8 +986,8 @@ int swad__loginBySessionKey (struct soap *soap, Gbl.CurrentCrs.Crs.CrsCod = Str_ConvertStrCodToLongCod (row[2]); Crs_GetDataOfCourseByCod (&Gbl.CurrentCrs.Crs); loginBySessionKeyOut->courseCode = (int) Gbl.CurrentCrs.Crs.CrsCod; - strncpy (loginBySessionKeyOut->courseName,Gbl.CurrentCrs.Crs.FullName,255); - loginBySessionKeyOut->courseName[255] = '\0'; + Str_Copy (loginBySessionKeyOut->courseName,Gbl.CurrentCrs.Crs.FullName, + Crs_MAX_LENGTH_COURSE_FULL_NAME); /***** Get user code (row[0]) *****/ Gbl.Usrs.Me.UsrDat.UsrCod = Str_ConvertStrCodToLongCod (row[0]); @@ -1042,8 +997,8 @@ int swad__loginBySessionKey (struct soap *soap, Gbl.CurrentDeg.Deg.DegCod = Str_ConvertStrCodToLongCod (row[1]); Deg_GetDataOfDegreeByCod (&Gbl.CurrentDeg.Deg); loginBySessionKeyOut->degreeCode = (int) Gbl.CurrentDeg.Deg.DegCod; - strncpy (loginBySessionKeyOut->degreeName,Gbl.CurrentDeg.Deg.FullName,255); - loginBySessionKeyOut->degreeName[255] = '\0'; + Str_Copy (loginBySessionKeyOut->degreeName,Gbl.CurrentDeg.Deg.FullName, + Deg_MAX_LENGTH_DEGREE_FULL_NAME); } else UsrFound = false; @@ -1062,28 +1017,26 @@ int swad__loginBySessionKey (struct soap *soap, loginBySessionKeyOut->userCode = (int) Gbl.Usrs.Me.UsrDat.UsrCod; - strncpy (loginBySessionKeyOut->userNickname,Gbl.Usrs.Me.UsrDat.Nickname,Nck_MAX_LENGTH_NICKNAME_WITHOUT_ARROBA); - loginBySessionKeyOut->userNickname[Nck_MAX_LENGTH_NICKNAME_WITHOUT_ARROBA] = '\0'; + Str_Copy (loginBySessionKeyOut->userNickname,Gbl.Usrs.Me.UsrDat.Nickname, + Nck_MAX_LENGTH_NICKNAME_WITHOUT_ARROBA); if (Gbl.Usrs.Me.UsrDat.IDs.Num) - { - strncpy (loginBySessionKeyOut->userID,Gbl.Usrs.Me.UsrDat.IDs.List[0].ID,255); // TODO: What user's ID? - loginBySessionKeyOut->userID[255] = '\0'; - } + Str_Copy (loginBySessionKeyOut->userID, + Gbl.Usrs.Me.UsrDat.IDs.List[0].ID, // TODO: What user's ID? + ID_MAX_LENGTH_USR_ID); - strncpy (loginBySessionKeyOut->userSurname1 ,Gbl.Usrs.Me.UsrDat.Surname1 ,Usr_MAX_BYTES_NAME); - loginBySessionKeyOut->userSurname1 [Usr_MAX_BYTES_NAME] = '\0'; - strncpy (loginBySessionKeyOut->userSurname2 ,Gbl.Usrs.Me.UsrDat.Surname2 ,Usr_MAX_BYTES_NAME); - loginBySessionKeyOut->userSurname2 [Usr_MAX_BYTES_NAME] = '\0'; - strncpy (loginBySessionKeyOut->userFirstname,Gbl.Usrs.Me.UsrDat.FirstName,Usr_MAX_BYTES_NAME); - loginBySessionKeyOut->userFirstname[Usr_MAX_BYTES_NAME] = '\0'; + Str_Copy (loginBySessionKeyOut->userSurname1, + Gbl.Usrs.Me.UsrDat.Surname1,Usr_MAX_BYTES_NAME); + Str_Copy (loginBySessionKeyOut->userSurname2, + Gbl.Usrs.Me.UsrDat.Surname2,Usr_MAX_BYTES_NAME); + Str_Copy (loginBySessionKeyOut->userFirstname, + Gbl.Usrs.Me.UsrDat.FirstName,Usr_MAX_BYTES_NAME); Pho_BuildLinkToPhoto (&Gbl.Usrs.Me.UsrDat,PhotoURL); - strncpy (loginBySessionKeyOut->userPhoto,PhotoURL,PATH_MAX); - loginBySessionKeyOut->userPhoto[PATH_MAX] = '\0'; + Str_Copy (loginBySessionKeyOut->userPhoto,PhotoURL,Cns_MAX_BYTES_URL); - strncpy (loginBySessionKeyOut->userBirthday,Gbl.Usrs.Me.UsrDat.Birthday.YYYYMMDD,Dat_LENGTH_YYYYMMDD); - loginBySessionKeyOut->userBirthday[Dat_LENGTH_YYYYMMDD] = '\0'; + Str_Copy (loginBySessionKeyOut->userBirthday, + Gbl.Usrs.Me.UsrDat.Birthday.YYYYMMDD,Dat_LENGTH_YYYYMMDD); loginBySessionKeyOut->userRole = Svc_RolRole_to_SvcRole[Gbl.Usrs.Me.UsrDat.RoleInCurrentCrsDB]; @@ -1106,7 +1059,7 @@ int swad__getNewPassword (struct soap *soap, struct swad__getNewPasswordOutput *getNewPasswordOut) // output { int ReturnCode; - char UsrIDNickOrEmail[512]; + char UsrIDNickOrEmail[Usr_MAX_BYTES_USR_LOGIN + 1]; char Query[512]; MYSQL_RES *mysql_res; MYSQL_ROW row; @@ -1125,8 +1078,7 @@ int swad__getNewPassword (struct soap *soap, return ReturnCode; /***** Check if user's email, @nickname or ID are valid *****/ - strncpy (UsrIDNickOrEmail,userID,255); - UsrIDNickOrEmail[255] = '\0'; + Str_Copy (UsrIDNickOrEmail,userID,Usr_MAX_BYTES_USR_LOGIN); if (Nck_CheckIfNickWithArrobaIsValid (UsrIDNickOrEmail)) // 1: It's a nickname { Str_RemoveLeadingArrobas (UsrIDNickOrEmail); @@ -1202,7 +1154,8 @@ int swad__getCourses (struct soap *soap, char Query[512]; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned NumRow,NumRows; + unsigned NumRow; + unsigned NumRows; Rol_Role_t Role; /***** Initializations *****/ @@ -1252,14 +1205,14 @@ int swad__getCourses (struct soap *soap, getCoursesOut->coursesArray.__ptr[NumRow].courseCode = (int) Str_ConvertStrCodToLongCod (row[0]); /* Get course short name (row[1]) */ - getCoursesOut->coursesArray.__ptr[NumRow].courseShortName = (char *) soap_malloc (Gbl.soap,256); - strncpy (getCoursesOut->coursesArray.__ptr[NumRow].courseShortName,row[1],255); - getCoursesOut->coursesArray.__ptr[NumRow].courseShortName[255] = '\0'; + getCoursesOut->coursesArray.__ptr[NumRow].courseShortName = (char *) soap_malloc (Gbl.soap,Crs_MAX_LENGTH_COURSE_SHRT_NAME + 1); + Str_Copy (getCoursesOut->coursesArray.__ptr[NumRow].courseShortName, + row[1],Crs_MAX_LENGTH_COURSE_SHRT_NAME); /* Get course full name (row[2]) */ - getCoursesOut->coursesArray.__ptr[NumRow].courseFullName = (char *) soap_malloc (Gbl.soap,256); - strncpy (getCoursesOut->coursesArray.__ptr[NumRow].courseFullName,row[2],255); - getCoursesOut->coursesArray.__ptr[NumRow].courseFullName[255] = '\0'; + getCoursesOut->coursesArray.__ptr[NumRow].courseFullName = (char *) soap_malloc (Gbl.soap,Crs_MAX_LENGTH_COURSE_FULL_NAME + 1); + Str_Copy (getCoursesOut->coursesArray.__ptr[NumRow].courseFullName, + row[2],Crs_MAX_LENGTH_COURSE_FULL_NAME); /* Get role (row[3]) */ if (sscanf (row[3],"%u",&Role) != 1) // Role in this course @@ -1384,7 +1337,7 @@ int swad__getCourseInfo (struct soap *soap, Result = Inf_WritePageIntoHTMLBuffer (&(getCourseInfo->infoTxt)); break; case Inf_INFO_SRC_URL: // Link to a web page - getCourseInfo->infoTxt = (char *) soap_malloc (Gbl.soap,Cns_MAX_BYTES_URL+1); + getCourseInfo->infoTxt = (char *) soap_malloc (Gbl.soap,Cns_MAX_BYTES_URL + 1); Inf_WriteURLIntoTxtBuffer (getCourseInfo->infoTxt); break; } @@ -1538,8 +1491,7 @@ int swad__findUsers (struct soap *soap, Role = Svc_SvcRole_to_RolRole[userRole]; /***** Query users beloging to course or group from database *****/ - strncpy (Gbl.Search.Str,filter,Sch_MAX_LENGTH_STRING_TO_FIND); - Gbl.Search.Str[Sch_MAX_LENGTH_STRING_TO_FIND] = '\0'; + Str_Copy (Gbl.Search.Str,filter,Sch_MAX_LENGTH_STRING_TO_FIND); if (Gbl.Search.Str[0]) // Search some users { @@ -1643,7 +1595,8 @@ int swad__getGroupTypes (struct soap *soap, char Query[512]; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned NumRow,NumRows; + unsigned NumRow; + unsigned NumRows; long OpenTime; /***** Initializations *****/ @@ -1712,9 +1665,9 @@ int swad__getGroupTypes (struct soap *soap, getGroupTypesOut->groupTypesArray.__ptr[NumRow].groupTypeCode = (int) Str_ConvertStrCodToLongCod (row[0]); /* Get group type name (row[1]) */ - getGroupTypesOut->groupTypesArray.__ptr[NumRow].groupTypeName = (char *) soap_malloc (Gbl.soap,256); - strncpy (getGroupTypesOut->groupTypesArray.__ptr[NumRow].groupTypeName,row[1],255); - getGroupTypesOut->groupTypesArray.__ptr[NumRow].groupTypeName[255] = '\0'; + getGroupTypesOut->groupTypesArray.__ptr[NumRow].groupTypeName = (char *) soap_malloc (Gbl.soap,Grp_MAX_LENGTH_GROUP_TYPE_NAME + 1); + Str_Copy (getGroupTypesOut->groupTypesArray.__ptr[NumRow].groupTypeName, + row[1],Grp_MAX_LENGTH_GROUP_TYPE_NAME); /* Get whether enrollment is mandatory ('Y') or voluntary ('N') (row[2]) */ getGroupTypesOut->groupTypesArray.__ptr[NumRow].mandatory = (row[2][0] == 'Y') ? 1 : @@ -1823,18 +1776,18 @@ int swad__getGroups (struct soap *soap, getGroupsOut->groupsArray.__ptr[NumRow].groupTypeCode = (int) Str_ConvertStrCodToLongCod (row[0]); /* Get group type name (row[1]) */ - getGroupsOut->groupsArray.__ptr[NumRow].groupTypeName = (char *) soap_malloc (Gbl.soap,256); - strncpy (getGroupsOut->groupsArray.__ptr[NumRow].groupTypeName,row[1],255); - getGroupsOut->groupsArray.__ptr[NumRow].groupTypeName[255] = '\0'; + getGroupsOut->groupsArray.__ptr[NumRow].groupTypeName = (char *) soap_malloc (Gbl.soap,Grp_MAX_LENGTH_GROUP_TYPE_NAME + 1); + Str_Copy (getGroupsOut->groupsArray.__ptr[NumRow].groupTypeName, + row[1],Grp_MAX_LENGTH_GROUP_TYPE_NAME); /* Get group code (row[2]) */ GrpCod = Str_ConvertStrCodToLongCod (row[2]); getGroupsOut->groupsArray.__ptr[NumRow].groupCode = (int) GrpCod; /* Get group name (row[3]) */ - getGroupsOut->groupsArray.__ptr[NumRow].groupName = (char *) soap_malloc (Gbl.soap,256); - strncpy (getGroupsOut->groupsArray.__ptr[NumRow].groupName,row[3],255); - getGroupsOut->groupsArray.__ptr[NumRow].groupName[255] = '\0'; + getGroupsOut->groupsArray.__ptr[NumRow].groupName = (char *) soap_malloc (Gbl.soap,Grp_MAX_LENGTH_GROUP_NAME + 1); + Str_Copy (getGroupsOut->groupsArray.__ptr[NumRow].groupName, + row[3],Grp_MAX_LENGTH_GROUP_NAME); /* Get max number of students of group (row[4]) and number of current students */ MaxStudents = Grp_ConvertToNumMaxStdsGrp (row[4]); @@ -1984,18 +1937,18 @@ int swad__sendMyGroups (struct soap *soap, SendMyGroupsOut->groupsArray.__ptr[NumRow].groupTypeCode = (int) Str_ConvertStrCodToLongCod (row[0]); /* Get group type name (row[1]) */ - SendMyGroupsOut->groupsArray.__ptr[NumRow].groupTypeName = (char *) soap_malloc (Gbl.soap,256); - strncpy (SendMyGroupsOut->groupsArray.__ptr[NumRow].groupTypeName,row[1],255); - SendMyGroupsOut->groupsArray.__ptr[NumRow].groupTypeName[255] = '\0'; + SendMyGroupsOut->groupsArray.__ptr[NumRow].groupTypeName = (char *) soap_malloc (Gbl.soap,Grp_MAX_LENGTH_GROUP_TYPE_NAME + 1); + Str_Copy (SendMyGroupsOut->groupsArray.__ptr[NumRow].groupTypeName, + row[1],Grp_MAX_LENGTH_GROUP_TYPE_NAME); /* Get group code (row[2]) */ GrpCod = Str_ConvertStrCodToLongCod (row[2]); SendMyGroupsOut->groupsArray.__ptr[NumRow].groupCode = (int) GrpCod; /* Get group name (row[3]) */ - SendMyGroupsOut->groupsArray.__ptr[NumRow].groupName = (char *) soap_malloc (Gbl.soap,256); - strncpy (SendMyGroupsOut->groupsArray.__ptr[NumRow].groupName,row[3],255); - SendMyGroupsOut->groupsArray.__ptr[NumRow].groupName[255] = '\0'; + SendMyGroupsOut->groupsArray.__ptr[NumRow].groupName = (char *) soap_malloc (Gbl.soap,Grp_MAX_LENGTH_GROUP_NAME + 1); + Str_Copy (SendMyGroupsOut->groupsArray.__ptr[NumRow].groupName, + row[3],Grp_MAX_LENGTH_GROUP_NAME); /* Get max number of students of group (row[4]) and number of current students */ MaxStudents = Grp_ConvertToNumMaxStdsGrp (row[4]); @@ -2031,7 +1984,7 @@ int swad__sendMyGroups (struct soap *soap, static void Svc_CopyUsrData (struct swad__user *Usr,struct UsrData *UsrDat,bool UsrIDIsVisible) { - char PhotoURL[PATH_MAX+1]; + char PhotoURL[Cns_MAX_BYTES_URL + 1]; const char *FirstID; /* Copy user's code */ @@ -2063,7 +2016,7 @@ static void Svc_CopyUsrData (struct swad__user *Usr,struct UsrData *UsrDat,bool /* User's photo URL */ Pho_BuildLinkToPhoto (UsrDat,PhotoURL); - Usr->userPhoto = (char *) soap_malloc (Gbl.soap,strlen (PhotoURL) + 1); + Usr->userPhoto = (char *) soap_malloc (Gbl.soap,Cns_MAX_BYTES_URL + 1); strcpy (Usr->userPhoto,PhotoURL); } @@ -2081,7 +2034,7 @@ int swad__getAttendanceEvents (struct soap *soap, MYSQL_ROW row; int NumAttEvent; long AttCod; - char PhotoURL[PATH_MAX+1]; + char PhotoURL[Cns_MAX_BYTES_URL + 1]; long StartTime; long EndTime; size_t Length; @@ -2357,8 +2310,7 @@ int swad__sendAttendanceEvent (struct soap *soap, return soap_receiver_fault (Gbl.soap, "Request forbidden", "Title of attendance event is empty"); - strncpy (Att.Title,title,Att_MAX_LENGTH_ATTENDANCE_EVENT_TITLE); - Att.Title[Att_MAX_LENGTH_ATTENDANCE_EVENT_TITLE] = '\0'; + Str_Copy (Att.Title,title,Att_MAX_LENGTH_ATTENDANCE_EVENT_TITLE); /* Create a list of groups selected */ Svc_GetLstGrpsSel (groups); @@ -2498,7 +2450,7 @@ int swad__getAttendanceUsers (struct soap *soap, MYSQL_RES *mysql_res; MYSQL_ROW row; unsigned NumRow,NumRows; - char PhotoURL[PATH_MAX+1]; + char PhotoURL[Cns_MAX_BYTES_URL + 1]; size_t Length; /***** Initializations *****/ @@ -2797,7 +2749,7 @@ int swad__getNotifications (struct soap *soap, long NtfCod; Ntf_NotifyEvent_t NotifyEvent; long EventTime; - char PhotoURL[PATH_MAX+1]; + char PhotoURL[Cns_MAX_BYTES_URL + 1]; struct Instit Ins; struct Centre Ctr; struct Degree Deg; @@ -2859,9 +2811,9 @@ int swad__getNotifications (struct soap *soap, /* Get notification event type (row[1]) */ NotifyEvent = Ntf_GetNotifyEventFromDB ((const char *) row[1]); - getNotificationsOut->notificationsArray.__ptr[NumNotif].eventType = (char *) soap_malloc (Gbl.soap,256); - strncpy (getNotificationsOut->notificationsArray.__ptr[NumNotif].eventType,Ntf_WSNotifyEvents[NotifyEvent],255); - getNotificationsOut->notificationsArray.__ptr[NumNotif].eventType[255] = '\0'; + getNotificationsOut->notificationsArray.__ptr[NumNotif].eventType = (char *) soap_malloc (Gbl.soap,Ntf_MAX_LENGTH_NOTIFY_EVENT + 1); + Str_Copy (getNotificationsOut->notificationsArray.__ptr[NumNotif].eventType, + Ntf_WSNotifyEvents[NotifyEvent],Ntf_MAX_LENGTH_NOTIFY_EVENT); /* Get time of the event (row[2]) */ EventTime = 0L; @@ -2878,26 +2830,27 @@ int swad__getNotifications (struct soap *soap, if (Svc_GetSomeUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat,Crs.CrsCod)) // Get some user's data from database { - getNotificationsOut->notificationsArray.__ptr[NumNotif].userNickname = (char *) soap_malloc (Gbl.soap,Nck_MAX_LENGTH_NICKNAME_WITHOUT_ARROBA+1); - strncpy (getNotificationsOut->notificationsArray.__ptr[NumNotif].userNickname,Gbl.Usrs.Other.UsrDat.Nickname,Nck_MAX_LENGTH_NICKNAME_WITHOUT_ARROBA); - getNotificationsOut->notificationsArray.__ptr[NumNotif].userNickname[Nck_MAX_LENGTH_NICKNAME_WITHOUT_ARROBA] = '\0'; + getNotificationsOut->notificationsArray.__ptr[NumNotif].userNickname = (char *) soap_malloc (Gbl.soap,Nck_MAX_LENGTH_NICKNAME_WITHOUT_ARROBA + 1); + Str_Copy (getNotificationsOut->notificationsArray.__ptr[NumNotif].userNickname, + Gbl.Usrs.Other.UsrDat.Nickname, + Nck_MAX_LENGTH_NICKNAME_WITHOUT_ARROBA); getNotificationsOut->notificationsArray.__ptr[NumNotif].userSurname1 = (char *) soap_malloc (Gbl.soap,Usr_MAX_BYTES_NAME + 1); - strncpy (getNotificationsOut->notificationsArray.__ptr[NumNotif].userSurname1 ,Gbl.Usrs.Other.UsrDat.Surname1 ,Usr_MAX_BYTES_NAME); - getNotificationsOut->notificationsArray.__ptr[NumNotif].userSurname1 [Usr_MAX_BYTES_NAME] = '\0'; + Str_Copy (getNotificationsOut->notificationsArray.__ptr[NumNotif].userSurname1, + Gbl.Usrs.Other.UsrDat.Surname1 ,Usr_MAX_BYTES_NAME); getNotificationsOut->notificationsArray.__ptr[NumNotif].userSurname2 = (char *) soap_malloc (Gbl.soap,Usr_MAX_BYTES_NAME + 1); - strncpy (getNotificationsOut->notificationsArray.__ptr[NumNotif].userSurname2 ,Gbl.Usrs.Other.UsrDat.Surname2 ,Usr_MAX_BYTES_NAME); - getNotificationsOut->notificationsArray.__ptr[NumNotif].userSurname2 [Usr_MAX_BYTES_NAME] = '\0'; + Str_Copy (getNotificationsOut->notificationsArray.__ptr[NumNotif].userSurname2, + Gbl.Usrs.Other.UsrDat.Surname2 ,Usr_MAX_BYTES_NAME); getNotificationsOut->notificationsArray.__ptr[NumNotif].userFirstname = (char *) soap_malloc (Gbl.soap,Usr_MAX_BYTES_NAME + 1); - strncpy (getNotificationsOut->notificationsArray.__ptr[NumNotif].userFirstname,Gbl.Usrs.Other.UsrDat.FirstName,Usr_MAX_BYTES_NAME); - getNotificationsOut->notificationsArray.__ptr[NumNotif].userFirstname[Usr_MAX_BYTES_NAME] = '\0'; + Str_Copy (getNotificationsOut->notificationsArray.__ptr[NumNotif].userFirstname, + Gbl.Usrs.Other.UsrDat.FirstName,Usr_MAX_BYTES_NAME); Pho_BuildLinkToPhoto (&Gbl.Usrs.Other.UsrDat,PhotoURL); - getNotificationsOut->notificationsArray.__ptr[NumNotif].userPhoto = (char *) soap_malloc (Gbl.soap,PATH_MAX+1); - strncpy (getNotificationsOut->notificationsArray.__ptr[NumNotif].userPhoto,PhotoURL,PATH_MAX); - getNotificationsOut->notificationsArray.__ptr[NumNotif].userPhoto[PATH_MAX] = '\0'; + getNotificationsOut->notificationsArray.__ptr[NumNotif].userPhoto = (char *) soap_malloc (Gbl.soap,Cns_MAX_BYTES_URL + 1); + Str_Copy (getNotificationsOut->notificationsArray.__ptr[NumNotif].userPhoto, + PhotoURL,Cns_MAX_BYTES_URL); } else { @@ -2925,7 +2878,7 @@ int swad__getNotifications (struct soap *soap, getNotificationsOut->notificationsArray.__ptr[NumNotif].eventCode = (int) Cod; /* Set location */ - getNotificationsOut->notificationsArray.__ptr[NumNotif].location = (char *) soap_malloc (Gbl.soap,1024); + getNotificationsOut->notificationsArray.__ptr[NumNotif].location = (char *) soap_malloc (Gbl.soap,Ntf_MAX_LENGTH_NOTIFY_LOCATION + 1); if (NotifyEvent == Ntf_EVENT_FORUM_POST_COURSE || NotifyEvent == Ntf_EVENT_FORUM_REPLY) @@ -3489,7 +3442,7 @@ int swad__getTestConfig (struct soap *soap, /***** Set default result to empty *****/ getTestConfigOut->numQuestions = getTestConfigOut->minQuestions = getTestConfigOut->defQuestions = getTestConfigOut->maxQuestions = 0; - getTestConfigOut->feedback = (char *) soap_malloc (Gbl.soap,256); + getTestConfigOut->feedback = (char *) soap_malloc (Gbl.soap,Tst_MAX_LENGTH_FEEDBACK_TYPE + 1); getTestConfigOut->feedback[0] = '\0'; /***** Get test configuration *****/ @@ -3500,10 +3453,9 @@ int swad__getTestConfig (struct soap *soap, getTestConfigOut->minQuestions = (int) Gbl.Test.Config.Min; getTestConfigOut->defQuestions = (int) Gbl.Test.Config.Def; getTestConfigOut->maxQuestions = (int) Gbl.Test.Config.Max; - // if (Gbl.Test.Config.FeedbackType == Tst_FEEDBACK_FULL_FEEDBACK) - // Gbl.Test.Config.FeedbackType = Tst_FEEDBACK_EACH_GOOD_BAD; // TODO: remove this when SWADroid uses it - strncpy (getTestConfigOut->feedback,Tst_FeedbackXML[Gbl.Test.Config.FeedbackType],255); - getTestConfigOut->feedback[255] = '\0'; + Str_Copy (getTestConfigOut->feedback, + Tst_FeedbackXML[Gbl.Test.Config.FeedbackType], + Tst_MAX_LENGTH_FEEDBACK_TYPE); /***** Get number of tests *****/ if (Gbl.Test.Config.Pluggable == Tst_PLUGGABLE_YES && @@ -3665,7 +3617,8 @@ static int Svc_GetTstTags (long CrsCod,struct swad__getTestsOutput *getTestsOut) char Query[512]; MYSQL_RES *mysql_res; MYSQL_ROW row; - unsigned NumRow,NumRows; + unsigned NumRow; + unsigned NumRows; /***** Get available tags from database *****/ sprintf (Query,"SELECT TagCod,TagTxt" @@ -3694,9 +3647,9 @@ static int Svc_GetTstTags (long CrsCod,struct swad__getTestsOutput *getTestsOut) getTestsOut->tagsArray.__ptr[NumRow].tagCode = (int) Str_ConvertStrCodToLongCod (row[0]); /* Get tag text (row[1]) */ - getTestsOut->tagsArray.__ptr[NumRow].tagText = (char *) soap_malloc (Gbl.soap,256); - strncpy (getTestsOut->tagsArray.__ptr[NumRow].tagText,row[1],255); - getTestsOut->tagsArray.__ptr[NumRow].tagText[255] = '\0'; + getTestsOut->tagsArray.__ptr[NumRow].tagText = (char *) soap_malloc (Gbl.soap,Tst_MAX_BYTES_TAG + 1); + Str_Copy (getTestsOut->tagsArray.__ptr[NumRow].tagText,row[1], + Tst_MAX_BYTES_TAG); } } @@ -3766,23 +3719,23 @@ static int Svc_GetTstQuestions (long CrsCod,long BeginTime,struct swad__getTests /* Get answer type (row[1]) */ AnswerType = Tst_ConvertFromStrAnsTypDBToAnsTyp (row[1]); - getTestsOut->questionsArray.__ptr[NumRow].answerType = (char *) soap_malloc (Gbl.soap,256); - strncpy (getTestsOut->questionsArray.__ptr[NumRow].answerType,Tst_StrAnswerTypesXML[AnswerType],255); - getTestsOut->questionsArray.__ptr[NumRow].answerType[255] = '\0'; + getTestsOut->questionsArray.__ptr[NumRow].answerType = (char *) soap_malloc (Gbl.soap,Tst_MAX_LENGTH_ANSWER_TYPE + 1); + Str_Copy (getTestsOut->questionsArray.__ptr[NumRow].answerType, + Tst_StrAnswerTypesXML[AnswerType],Tst_MAX_LENGTH_ANSWER_TYPE); /* Get shuffle (row[2]) */ getTestsOut->questionsArray.__ptr[NumRow].shuffle = (row[2][0] == 'Y') ? 1 : 0; /* Get question stem (row[3]) */ - getTestsOut->questionsArray.__ptr[NumRow].stem = (char *) soap_malloc (Gbl.soap,Cns_MAX_BYTES_TEXT+1); - strncpy (getTestsOut->questionsArray.__ptr[NumRow].stem,row[3],Cns_MAX_BYTES_TEXT); - getTestsOut->questionsArray.__ptr[NumRow].stem[Cns_MAX_BYTES_TEXT] = '\0'; + getTestsOut->questionsArray.__ptr[NumRow].stem = (char *) soap_malloc (Gbl.soap,Cns_MAX_BYTES_TEXT + 1); + Str_Copy (getTestsOut->questionsArray.__ptr[NumRow].stem,row[3], + Cns_MAX_BYTES_TEXT); /* Get question feedback (row[4]) */ - getTestsOut->questionsArray.__ptr[NumRow].feedback = (char *) soap_malloc (Gbl.soap,Cns_MAX_BYTES_TEXT+1); - strncpy (getTestsOut->questionsArray.__ptr[NumRow].feedback,row[4],Cns_MAX_BYTES_TEXT); - getTestsOut->questionsArray.__ptr[NumRow].feedback[Cns_MAX_BYTES_TEXT] = '\0'; + getTestsOut->questionsArray.__ptr[NumRow].feedback = (char *) soap_malloc (Gbl.soap,Cns_MAX_BYTES_TEXT + 1); + Str_Copy (getTestsOut->questionsArray.__ptr[NumRow].feedback,row[4], + Cns_MAX_BYTES_TEXT); } } @@ -3860,14 +3813,14 @@ static int Svc_GetTstAnswers (long CrsCod,long BeginTime,struct swad__getTestsOu 0; /* Get answer (row[3]) */ - getTestsOut->answersArray.__ptr[NumRow].answerText = (char *) soap_malloc (Gbl.soap,Cns_MAX_BYTES_TEXT+1); - strncpy (getTestsOut->answersArray.__ptr[NumRow].answerText,row[3],Cns_MAX_BYTES_TEXT); - getTestsOut->answersArray.__ptr[NumRow].answerText[Cns_MAX_BYTES_TEXT] = '\0'; + getTestsOut->answersArray.__ptr[NumRow].answerText = (char *) soap_malloc (Gbl.soap,Cns_MAX_BYTES_TEXT + 1); + Str_Copy (getTestsOut->answersArray.__ptr[NumRow].answerText, + row[3],Cns_MAX_BYTES_TEXT); /* Get feedback (row[4]) */ - getTestsOut->answersArray.__ptr[NumRow].answerFeedback = (char *) soap_malloc (Gbl.soap,Cns_MAX_BYTES_TEXT+1); - strncpy (getTestsOut->answersArray.__ptr[NumRow].answerFeedback,row[4],Cns_MAX_BYTES_TEXT); - getTestsOut->answersArray.__ptr[NumRow].answerFeedback[Cns_MAX_BYTES_TEXT] = '\0'; + getTestsOut->answersArray.__ptr[NumRow].answerFeedback = (char *) soap_malloc (Gbl.soap,Cns_MAX_BYTES_TEXT + 1); + Str_Copy (getTestsOut->answersArray.__ptr[NumRow].answerFeedback, + row[4],Cns_MAX_BYTES_TEXT); } } @@ -4092,35 +4045,26 @@ int swad__getTrivialQuestion (struct soap *soap, /* Get answer type (row[1]) */ AnswerType = Tst_ConvertFromStrAnsTypDBToAnsTyp (row[1]); - getTrivialQuestionOut->question.answerType = (char *) soap_malloc (Gbl.soap,256); - strncpy (getTrivialQuestionOut->question.answerType,Tst_StrAnswerTypesXML[AnswerType],255); - getTrivialQuestionOut->question.answerType[255] = '\0'; + getTrivialQuestionOut->question.answerType = (char *) soap_malloc (Gbl.soap,Tst_MAX_LENGTH_ANSWER_TYPE + 1); + Str_Copy (getTrivialQuestionOut->question.answerType, + Tst_StrAnswerTypesXML[AnswerType],Tst_MAX_LENGTH_ANSWER_TYPE); /* Get shuffle (row[2]) */ getTrivialQuestionOut->question.shuffle = (row[2][0] == 'Y') ? 1 : 0; /* Get question stem (row[3]) */ - getTrivialQuestionOut->question.stem = (char *) soap_malloc (Gbl.soap,Cns_MAX_BYTES_TEXT+1); - strncpy (getTrivialQuestionOut->question.stem,row[3],Cns_MAX_BYTES_TEXT); - getTrivialQuestionOut->question.stem[Cns_MAX_BYTES_TEXT] = '\0'; + getTrivialQuestionOut->question.stem = (char *) soap_malloc (Gbl.soap,Cns_MAX_BYTES_TEXT + 1); + Str_Copy (getTrivialQuestionOut->question.stem,row[3], + Cns_MAX_BYTES_TEXT); /* Get question feedback (row[4]) */ - getTrivialQuestionOut->question.feedback = (char *) soap_malloc (Gbl.soap,Cns_MAX_BYTES_TEXT+1); - strncpy (getTrivialQuestionOut->question.feedback,row[4],Cns_MAX_BYTES_TEXT); - getTrivialQuestionOut->question.feedback[Cns_MAX_BYTES_TEXT] = '\0'; + getTrivialQuestionOut->question.feedback = (char *) soap_malloc (Gbl.soap,Cns_MAX_BYTES_TEXT + 1); + Str_Copy (getTrivialQuestionOut->question.feedback,row[4], + Cns_MAX_BYTES_TEXT); } else // Empty question { -/* - if (Gbl.Usrs.Me.UsrDat.UsrCod == 19543) - { - char QueryDebug[512*1024]; - - sprintf (QueryDebug,"INSERT INTO debug (DebugTime,Txt) VALUES (NOW(),'Ninguna pregunta devuelta')"); - DB_QueryINSERT (QueryDebug,"Error inserting in debug table"); - } -*/ /* Question code (row[0]) */ QstCod = -1L; getTrivialQuestionOut->question.questionCode = -1; @@ -4182,14 +4126,14 @@ int swad__getTrivialQuestion (struct soap *soap, 0; /* Get answer (row[3]) */ - getTrivialQuestionOut->answersArray.__ptr[NumRow].answerText = (char *) soap_malloc (Gbl.soap,Cns_MAX_BYTES_TEXT+1); - strncpy (getTrivialQuestionOut->answersArray.__ptr[NumRow].answerText,row[3],Cns_MAX_BYTES_TEXT); - getTrivialQuestionOut->answersArray.__ptr[NumRow].answerText[Cns_MAX_BYTES_TEXT] = '\0'; + getTrivialQuestionOut->answersArray.__ptr[NumRow].answerText = (char *) soap_malloc (Gbl.soap,Cns_MAX_BYTES_TEXT + 1); + Str_Copy (getTrivialQuestionOut->answersArray.__ptr[NumRow].answerText, + row[3],Cns_MAX_BYTES_TEXT); /* Get feedback (row[4]) */ - getTrivialQuestionOut->answersArray.__ptr[NumRow].answerFeedback = (char *) soap_malloc (Gbl.soap,Cns_MAX_BYTES_TEXT+1); - strncpy (getTrivialQuestionOut->answersArray.__ptr[NumRow].answerFeedback,row[4],Cns_MAX_BYTES_TEXT); - getTrivialQuestionOut->answersArray.__ptr[NumRow].answerFeedback[Cns_MAX_BYTES_TEXT] = '\0'; + getTrivialQuestionOut->answersArray.__ptr[NumRow].answerFeedback = (char *) soap_malloc (Gbl.soap,Cns_MAX_BYTES_TEXT + 1); + Str_Copy (getTrivialQuestionOut->answersArray.__ptr[NumRow].answerFeedback, + row[4],Cns_MAX_BYTES_TEXT); } } @@ -4421,7 +4365,7 @@ static bool Svc_WriteRowFileBrowser (unsigned Level,Brw_FileType_t FileType,cons extern const char *Txt_NEW_LINE; extern const char *Txt_LICENSES[Brw_NUM_LICENSES]; struct FileMetadata FileMetadata; - char PhotoURL[PATH_MAX+1]; + char PhotoURL[Cns_MAX_BYTES_URL + 1]; /***** Is this row hidden or visible? *****/ if (Gbl.FileBrowser.Type == Brw_SHOW_DOCUM_CRS || @@ -4497,19 +4441,19 @@ int swad__getFile (struct soap *soap, extern const char *Txt_LICENSES[Brw_NUM_LICENSES]; int ReturnCode; struct FileMetadata FileMetadata; - char URL[PATH_MAX+1]; - char PhotoURL[PATH_MAX+1]; + char URL[Cns_MAX_BYTES_URL + 1]; + char PhotoURL[Cns_MAX_BYTES_URL + 1]; /***** Initializations *****/ Gbl.soap = soap; Gbl.WebService.Function = Svc_getFile; /***** Allocate space for strings *****/ - getFileOut->fileName = (char *) soap_malloc (Gbl.soap,NAME_MAX+1); - getFileOut->URL = (char *) soap_malloc (Gbl.soap,PATH_MAX+1); - getFileOut->license = (char *) soap_malloc (Gbl.soap,256); - getFileOut->publisherName = (char *) soap_malloc (Gbl.soap,255+1+255+1+255+1); - getFileOut->publisherPhoto = (char *) soap_malloc (Gbl.soap,PATH_MAX+1); + getFileOut->fileName = (char *) soap_malloc (Gbl.soap,NAME_MAX + 1); + getFileOut->URL = (char *) soap_malloc (Gbl.soap,Cns_MAX_BYTES_URL + 1); + getFileOut->license = (char *) soap_malloc (Gbl.soap,Brw_MAX_LENGTH_LICENSE + 1); + getFileOut->publisherName = (char *) soap_malloc (Gbl.soap,Usr_MAX_BYTES_FULL_NAME + 1); + getFileOut->publisherPhoto = (char *) soap_malloc (Gbl.soap,Cns_MAX_BYTES_URL + 1); /***** Default values returned on error *****/ getFileOut->fileName[0] = '\0'; @@ -4615,30 +4559,27 @@ int swad__getFile (struct soap *soap, URL); /***** Copy data into output structure *****/ - strncpy (getFileOut->fileName,FileMetadata.FilFolLnkName,NAME_MAX); - getFileOut->fileName[NAME_MAX] = '\0'; + Str_Copy (getFileOut->fileName,FileMetadata.FilFolLnkName,NAME_MAX); - strncpy (getFileOut->URL,URL,PATH_MAX); - getFileOut->URL[PATH_MAX] = '\0'; + Str_Copy (getFileOut->URL,URL,Cns_MAX_BYTES_URL); getFileOut->size = (int) FileMetadata.Size; getFileOut->time = (int) FileMetadata.Time; - strncpy (getFileOut->license,Txt_LICENSES[FileMetadata.License],255); - getFileOut->license[255] = '\0'; + Str_Copy (getFileOut->license,Txt_LICENSES[FileMetadata.License], + Brw_MAX_LENGTH_LICENSE); if ((Gbl.Usrs.Other.UsrDat.UsrCod = FileMetadata.PublisherUsrCod) > 0) /* Get publisher's data */ if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat)) /* Copy publisher's data into output structure */ { - strncpy (getFileOut->publisherName,Gbl.Usrs.Other.UsrDat.FullName,255+1+255+1+255); - getFileOut->publisherName[255+1+255+1+255] = '\0'; + Str_Copy (getFileOut->publisherName,Gbl.Usrs.Other.UsrDat.FullName, + Usr_MAX_BYTES_FULL_NAME); Pho_BuildLinkToPhoto (&Gbl.Usrs.Other.UsrDat,PhotoURL); - strncpy (getFileOut->publisherPhoto,PhotoURL,PATH_MAX); - getFileOut->publisherPhoto[PATH_MAX] = '\0'; + Str_Copy (getFileOut->publisherPhoto,PhotoURL,Cns_MAX_BYTES_URL); } return SOAP_OK; diff --git a/swad_xml.c b/swad_xml.c index 3a400f37..de0cb554 100644 --- a/swad_xml.c +++ b/swad_xml.c @@ -180,8 +180,7 @@ static void XML_GetElement (struct XMLElement *ParentElem) { if ((ParentElem->Content = malloc (ContentLength+1)) == NULL) Lay_ShowErrorAndExit ("Not enough memory."); - strncpy (ParentElem->Content,StartContent,ContentLength); - ParentElem->Content[ContentLength] = '\0'; + Str_Copy (ParentElem->Content,StartContent,ContentLength); ParentElem->ContentLength = ContentLength; } @@ -217,8 +216,7 @@ static void XML_GetElement (struct XMLElement *ParentElem) ChildElem->TagNameLength = strcspn (Gbl.XMLPtr,">/ \t"); if ((ChildElem->TagName = malloc (ChildElem->TagNameLength+1)) == NULL) Lay_ShowErrorAndExit ("Not enough memory."); - strncpy (ChildElem->TagName,Gbl.XMLPtr,ChildElem->TagNameLength); - ChildElem->TagName[ChildElem->TagNameLength] = '\0'; + Str_Copy (ChildElem->TagName,Gbl.XMLPtr,ChildElem->TagNameLength); Gbl.XMLPtr += ChildElem->TagNameLength; /* @@ -337,8 +335,7 @@ static void XML_GetAttributes (struct XMLElement *Elem) Attribute->AttributeNameLength = strcspn (Gbl.XMLPtr,"="); if ((Attribute->AttributeName = malloc (Attribute->AttributeNameLength+1)) == NULL) Lay_ShowErrorAndExit ("Not enough memory."); - strncpy (Attribute->AttributeName,Gbl.XMLPtr,Attribute->AttributeNameLength); - Attribute->AttributeName[Attribute->AttributeNameLength] = '\0'; + Str_Copy (Attribute->AttributeName,Gbl.XMLPtr,Attribute->AttributeNameLength); Gbl.XMLPtr += Attribute->AttributeNameLength; /* End of attribute name: <parent><child attribute1="value" attribute2="value">...</child>...</parent> @@ -367,8 +364,7 @@ static void XML_GetAttributes (struct XMLElement *Elem) if ((Attribute->Content = malloc (Attribute->ContentLength+1)) == NULL) Lay_ShowErrorAndExit ("Not enough memory."); - strncpy (Attribute->Content,Gbl.XMLPtr,Attribute->ContentLength); - Attribute->Content[Attribute->ContentLength] = '\0'; + Str_Copy (Attribute->Content,Gbl.XMLPtr,Attribute->ContentLength); Gbl.XMLPtr += Attribute->ContentLength; Gbl.XMLPtr++; diff --git a/swad_zip.c b/swad_zip.c index afd11c81..211a28ec 100644 --- a/swad_zip.c +++ b/swad_zip.c @@ -598,12 +598,11 @@ static void ZIP_ShowLinkToDownloadZIP (const char *FileName,const char *URL, extern const char *Txt_Filename; extern const char *Txt_File_size; extern const char *Txt_FILE_uncompressed; - char FileNameShort[NAME_MAX+1]; - char FileSizeStr[Fil_MAX_BYTES_FILE_SIZE_STRING]; + char FileNameShort[NAME_MAX + 1]; + char FileSizeStr[Fil_MAX_BYTES_FILE_SIZE_STRING + 1]; /***** Limit length of the name of the file *****/ - strncpy (FileNameShort,FileName,NAME_MAX); - FileNameShort[NAME_MAX] = '\0'; + Str_Copy (FileNameShort,FileName,NAME_MAX); Str_LimitLengthHTMLStr (FileNameShort,50); /***** Start frame *****/