"
@@ -1323,8 +1319,7 @@ static void For_ShowAForumPost (struct ForumThread *Thr,unsigned PstNum,long Pst
"");
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,"%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,"\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,"",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,"",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,"",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,"");
/***** 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 ",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 ",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:
......
@@ -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 *****/
| |