From 662aca0ef65b706b2ddfd04564f5b62a02f60006 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Sun, 21 Oct 2018 13:02:07 +0200 Subject: [PATCH] Version 18.7.22 --- swad_changelog.h | 3 +- swad_database.c | 11 + swad_database.h | 1 + swad_degree.c | 2 +- swad_file_browser.c | 1028 ++++++++++++++++++++++++------------------- swad_search.c | 610 ++++++++++++------------- 6 files changed, 893 insertions(+), 762 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index b2d310533..2e1a20279 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -355,10 +355,11 @@ En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 18.7.21 (2018-10-21)" +#define Log_PLATFORM_VERSION "SWAD 18.7.22 (2018-10-22)" #define CSS_FILE "swad18.4.css" #define JS_FILE "swad17.17.1.js" /* + Version 18.7.22: Oct 20, 2018 Some sprintf for database queries changed by asprintf. (237286 lines) Version 18.7.21: Oct 20, 2018 Some sprintf for database queries changed by asprintf. (237157 lines) Version 18.7.20: Oct 20, 2018 Some sprintf for database queries changed by asprintf. (237092 lines) Version 18.7.19: Oct 20, 2018 Some sprintf for database queries changed by asprintf. (237089 lines) diff --git a/swad_database.c b/swad_database.c index ca208b7a2..e24a32929 100644 --- a/swad_database.c +++ b/swad_database.c @@ -3268,6 +3268,17 @@ void DB_QueryDELETE (const char *Query,const char *MsgError) /**************** Make other kind of query from database *********************/ /*****************************************************************************/ +void DB_Query_free (const char *Query,const char *MsgError) + { + int Result; + + /***** Query database *****/ + Result = mysql_query (&Gbl.mysql,Query); // Returns 0 on success + free ((void *) Query); + if (Result) + DB_ExitOnMySQLError (MsgError); + } + void DB_Query (const char *Query,const char *MsgError) { /***** Query database *****/ diff --git a/swad_database.h b/swad_database.h index 3c2bdb284..42b7b1ac9 100644 --- a/swad_database.h +++ b/swad_database.h @@ -58,6 +58,7 @@ void DB_QueryUPDATE (const char *Query,const char *MsgError); void DB_QueryDELETE_free (const char *Query,const char *MsgError); void DB_QueryDELETE (const char *Query,const char *MsgError); +void DB_Query_free (const char *Query,const char *MsgError); void DB_Query (const char *Query,const char *MsgError); void DB_FreeMySQLResult (MYSQL_RES **mysql_res); void DB_ExitOnMySQLError (const char *Message); diff --git a/swad_degree.c b/swad_degree.c index e19c547bf..a233fa0af 100644 --- a/swad_degree.c +++ b/swad_degree.c @@ -2615,7 +2615,7 @@ unsigned Deg_ListDegsFound (const char *Query) struct Degree Deg; /***** Query database *****/ - if ((NumDegs = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get degrees"))) + if ((NumDegs = (unsigned) DB_QuerySELECT_free (Query,&mysql_res,"can not get degrees"))) { /***** Start box and table *****/ /* Number of degrees found */ diff --git a/swad_file_browser.c b/swad_file_browser.c index 0b10c3500..7d16bc459 100644 --- a/swad_file_browser.c +++ b/swad_file_browser.c @@ -5339,46 +5339,52 @@ void Brw_RemoveWrkFilesFromDB (long CrsCod,long UsrCod) void Brw_RemoveUsrFilesFromDB (long UsrCod) { - char Query[512]; + char *Query; /***** Remove from database the entries that store the file views *****/ // User is not removed from file_view table, // in order to take into account his/her views - sprintf (Query,"DELETE FROM file_view USING file_view,files" - " WHERE files.ZoneUsrCod=%ld" - " AND files.FilCod=file_view.FilCod", - UsrCod); - DB_QueryDELETE (Query,"can not remove file views to files of a user"); + if (asprintf (&Query,"DELETE FROM file_view USING file_view,files" + " WHERE files.ZoneUsrCod=%ld" + " AND files.FilCod=file_view.FilCod", + UsrCod) < 0) + Lay_NotEnoughMemoryExit (); + DB_QueryDELETE_free (Query,"can not remove file views to files of a user"); /***** Remove from database expanded folders *****/ - sprintf (Query,"DELETE LOW_PRIORITY FROM expanded_folders" - " WHERE UsrCod=%ld", - UsrCod); - DB_QueryDELETE (Query,"can not remove expanded folders for a user"); + if (asprintf (&Query,"DELETE LOW_PRIORITY FROM expanded_folders" + " WHERE UsrCod=%ld", + UsrCod) < 0) + Lay_NotEnoughMemoryExit (); + DB_QueryDELETE_free (Query,"can not remove expanded folders for a user"); /***** Remove from database the entries that store clipboards *****/ - sprintf (Query,"DELETE FROM clipboard" - " WHERE UsrCod=%ld", // User's clipboard - UsrCod); - DB_QueryDELETE (Query,"can not remove user's clipboards"); + if (asprintf (&Query,"DELETE FROM clipboard" + " WHERE UsrCod=%ld", // User's clipboard + UsrCod) < 0) + Lay_NotEnoughMemoryExit (); + DB_QueryDELETE_free (Query,"can not remove user's clipboards"); /***** Remove from database the entries that store the last time users visited file zones *****/ - sprintf (Query,"DELETE FROM file_browser_last" - " WHERE UsrCod=%ld", // User's last visits to all zones - UsrCod); - DB_QueryDELETE (Query,"can not remove user's last visits to file zones"); + if (asprintf (&Query,"DELETE FROM file_browser_last" + " WHERE UsrCod=%ld", // User's last visits to all zones + UsrCod) < 0) + Lay_NotEnoughMemoryExit (); + DB_QueryDELETE_free (Query,"can not remove user's last visits to file zones"); /***** Remove from database the entries that store the sizes of the file zones *****/ - sprintf (Query,"DELETE FROM file_browser_size" - " WHERE ZoneUsrCod=%ld", - UsrCod); - DB_QueryDELETE (Query,"can not remove sizes of user's file zones"); + if (asprintf (&Query,"DELETE FROM file_browser_size" + " WHERE ZoneUsrCod=%ld", + UsrCod) < 0) + Lay_NotEnoughMemoryExit (); + DB_QueryDELETE_free (Query,"can not remove sizes of user's file zones"); /***** Remove from database the entries that store the data files *****/ - sprintf (Query,"DELETE FROM files" - " WHERE ZoneUsrCod=%ld", - UsrCod); - DB_QueryDELETE (Query,"can not remove files in user's file zones"); + if (asprintf (&Query,"DELETE FROM files" + " WHERE ZoneUsrCod=%ld", + UsrCod) < 0) + Lay_NotEnoughMemoryExit (); + DB_QueryDELETE_free (Query,"can not remove files in user's file zones"); } /*****************************************************************************/ @@ -5554,7 +5560,7 @@ void Brw_CreateDirDownloadTmp (void) static void Brw_GetAndUpdateDateLastAccFileBrowser (void) { long Cod; - char Query[256]; + char *Query; MYSQL_RES *mysql_res; MYSQL_ROW row; unsigned long NumRows; @@ -5607,12 +5613,13 @@ static void Brw_GetAndUpdateDateLastAccFileBrowser (void) default: return; } - sprintf (Query,"SELECT UNIX_TIMESTAMP(LastClick) FROM file_browser_last" - " WHERE UsrCod=%ld AND FileBrowser=%u AND Cod=%ld", - Gbl.Usrs.Me.UsrDat.UsrCod, - (unsigned) Brw_FileBrowserForDB_file_browser_last[Gbl.FileBrowser.Type], - Cod); - NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get date-time of last access to a file browser"); + if (asprintf (&Query,"SELECT UNIX_TIMESTAMP(LastClick) FROM file_browser_last" + " WHERE UsrCod=%ld AND FileBrowser=%u AND Cod=%ld", + Gbl.Usrs.Me.UsrDat.UsrCod, + (unsigned) Brw_FileBrowserForDB_file_browser_last[Gbl.FileBrowser.Type], + Cod) < 0) + Lay_NotEnoughMemoryExit (); + NumRows = DB_QuerySELECT_free (Query,&mysql_res,"can not get date-time of last access to a file browser"); if (NumRows == 0) // May be an administrator not belonging to this course Gbl.Usrs.Me.TimeLastAccToThisFileBrowser = LONG_MAX; // Initialize to a big value in order to show files as old @@ -5632,14 +5639,15 @@ static void Brw_GetAndUpdateDateLastAccFileBrowser (void) DB_FreeMySQLResult (&mysql_res); /***** Update date of my last access to file browser in this course *****/ - sprintf (Query,"REPLACE INTO file_browser_last" - " (UsrCod,FileBrowser,Cod,LastClick)" - " VALUES" - " (%ld,%u,%ld,NOW())", - Gbl.Usrs.Me.UsrDat.UsrCod, - (unsigned) Brw_FileBrowserForDB_file_browser_last[Gbl.FileBrowser.Type], - Cod); - DB_QueryREPLACE (Query,"can not update date of last access to a file browser"); + if (asprintf (&Query,"REPLACE INTO file_browser_last" + " (UsrCod,FileBrowser,Cod,LastClick)" + " VALUES" + " (%ld,%u,%ld,NOW())", + Gbl.Usrs.Me.UsrDat.UsrCod, + (unsigned) Brw_FileBrowserForDB_file_browser_last[Gbl.FileBrowser.Type], + Cod) < 0) + Lay_NotEnoughMemoryExit (); + DB_QueryREPLACE_free (Query,"can not update date of last access to a file browser"); } /*****************************************************************************/ @@ -5648,19 +5656,20 @@ static void Brw_GetAndUpdateDateLastAccFileBrowser (void) static long Brw_GetGrpLastAccZone (const char *FieldNameDB) { - char Query[256]; + char *Query; MYSQL_RES *mysql_res; MYSQL_ROW row; unsigned long NumRows; long GrpCod = -1L; /***** Get the group of my last access to a common zone from database *****/ - sprintf (Query,"SELECT %s FROM crs_usr" - " WHERE CrsCod=%ld AND UsrCod=%ld", - FieldNameDB, - Gbl.CurrentCrs.Crs.CrsCod, - Gbl.Usrs.Me.UsrDat.UsrCod); - NumRows = DB_QuerySELECT (Query,&mysql_res,"can not get the group of your last access to a file browser"); + if (asprintf (&Query,"SELECT %s FROM crs_usr" + " WHERE CrsCod=%ld AND UsrCod=%ld", + FieldNameDB, + Gbl.CurrentCrs.Crs.CrsCod, + Gbl.Usrs.Me.UsrDat.UsrCod) < 0) + Lay_NotEnoughMemoryExit (); + NumRows = DB_QuerySELECT_free (Query,&mysql_res,"can not get the group of your last access to a file browser"); if (NumRows == 0) // May be an administrator not belonging to this course GrpCod = -1L; @@ -7746,7 +7755,7 @@ static void Brw_WriteCurrentClipboard (void) static bool Brw_GetMyClipboard (void) { - char Query[256]; + char *Query; MYSQL_RES *mysql_res; MYSQL_ROW row; char PathUntilFileName[PATH_MAX + 1]; @@ -7763,10 +7772,11 @@ static bool Brw_GetMyClipboard (void) Gbl.FileBrowser.Clipboard.Level = 0; /***** Get my current clipboard from database *****/ - sprintf (Query,"SELECT FileBrowser,Cod,WorksUsrCod,FileType,Path" - " FROM clipboard WHERE UsrCod=%ld", - Gbl.Usrs.Me.UsrDat.UsrCod); - NumRows = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get source of copy from clipboard"); + if (asprintf (&Query,"SELECT FileBrowser,Cod,WorksUsrCod,FileType,Path" + " FROM clipboard WHERE UsrCod=%ld", + Gbl.Usrs.Me.UsrDat.UsrCod) < 0) + Lay_NotEnoughMemoryExit (); + NumRows = (unsigned) DB_QuerySELECT_free (Query,&mysql_res,"can not get source of copy from clipboard"); if (NumRows == 1) { @@ -7882,17 +7892,18 @@ static void Brw_AddPathToClipboards (void) { long Cod = Brw_GetCodForClipboard (); long WorksUsrCod = Brw_GetWorksUsrCodForClipboard (); - char Query[512 + PATH_MAX]; + char *Query; /***** Add path to clipboards *****/ - sprintf (Query,"INSERT INTO clipboard" - " (UsrCod,FileBrowser,Cod,WorksUsrCod,FileType,Path)" - " VALUES" - " (%ld,%u,%ld,%ld,%u,'%s')", - Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) Gbl.FileBrowser.Type, - Cod,WorksUsrCod, - (unsigned) Gbl.FileBrowser.FileType,Gbl.FileBrowser.Priv.FullPathInTree); - DB_QueryINSERT (Query,"can not add source of copy to clipboard"); + if (asprintf (&Query,"INSERT INTO clipboard" + " (UsrCod,FileBrowser,Cod,WorksUsrCod,FileType,Path)" + " VALUES" + " (%ld,%u,%ld,%ld,%u,'%s')", + Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) Gbl.FileBrowser.Type, + Cod,WorksUsrCod, + (unsigned) Gbl.FileBrowser.FileType,Gbl.FileBrowser.Priv.FullPathInTree) < 0) + Lay_NotEnoughMemoryExit (); + DB_QueryINSERT_free (Query,"can not add source of copy to clipboard"); } /*****************************************************************************/ @@ -7903,18 +7914,19 @@ static void Brw_UpdatePathInClipboard (void) { long Cod = Brw_GetCodForClipboard (); long WorksUsrCod = Brw_GetWorksUsrCodForClipboard (); - char Query[512 + PATH_MAX]; + char *Query; /***** Update path in my clipboard *****/ - sprintf (Query,"UPDATE clipboard SET FileBrowser=%u," - "Cod=%ld,WorksUsrCod=%ld," - "FileType=%u,Path='%s'" - " WHERE UsrCod=%ld", - (unsigned) Gbl.FileBrowser.Type, - Cod,WorksUsrCod, - (unsigned) Gbl.FileBrowser.FileType,Gbl.FileBrowser.Priv.FullPathInTree, - Gbl.Usrs.Me.UsrDat.UsrCod); - DB_QueryUPDATE (Query,"can not update source of copy in clipboard"); + if (asprintf (&Query,"UPDATE clipboard SET FileBrowser=%u," + "Cod=%ld,WorksUsrCod=%ld," + "FileType=%u,Path='%s'" + " WHERE UsrCod=%ld", + (unsigned) Gbl.FileBrowser.Type, + Cod,WorksUsrCod, + (unsigned) Gbl.FileBrowser.FileType,Gbl.FileBrowser.Priv.FullPathInTree, + Gbl.Usrs.Me.UsrDat.UsrCod) < 0) + Lay_NotEnoughMemoryExit (); + DB_QueryUPDATE_free (Query,"can not update source of copy in clipboard"); } /*****************************************************************************/ @@ -8033,19 +8045,20 @@ static void Brw_InsertFolderInExpandedFolders (const char Path[PATH_MAX + 1]) { long Cod = Brw_GetCodForExpandedFolders (); long WorksUsrCod = Brw_GetWorksUsrCodForExpandedFolders (); - char Query[512 + PATH_MAX]; + char *Query; /***** Update path time in table of expanded folders *****/ // Path must be stored with final '/' - sprintf (Query,"INSERT INTO expanded_folders" - " (UsrCod,FileBrowser,Cod,WorksUsrCod,Path,ClickTime)" - " VALUES" - " (%ld,%u,%ld,%ld,'%s/',NOW())", - Gbl.Usrs.Me.UsrDat.UsrCod, - (unsigned) Brw_FileBrowserForDB_expanded_folders[Gbl.FileBrowser.Type], - Cod,WorksUsrCod, - Path); - DB_QueryINSERT (Query,"can not expand the content of a folder"); + if (asprintf (&Query,"INSERT INTO expanded_folders" + " (UsrCod,FileBrowser,Cod,WorksUsrCod,Path,ClickTime)" + " VALUES" + " (%ld,%u,%ld,%ld,'%s/',NOW())", + Gbl.Usrs.Me.UsrDat.UsrCod, + (unsigned) Brw_FileBrowserForDB_expanded_folders[Gbl.FileBrowser.Type], + Cod,WorksUsrCod, + Path) < 0) + Lay_NotEnoughMemoryExit (); + DB_QueryINSERT_free (Query,"can not expand the content of a folder"); } /*****************************************************************************/ @@ -8056,34 +8069,43 @@ static void Brw_UpdateClickTimeOfThisFileBrowserInExpandedFolders (void) { long Cod = Brw_GetCodForExpandedFolders (); long WorksUsrCod = Brw_GetWorksUsrCodForExpandedFolders (); - char Query[512]; + char *Query; Brw_FileBrowser_t FileBrowserForExpandedFolders = Brw_FileBrowserForDB_expanded_folders[Gbl.FileBrowser.Type]; /***** Update click time in table of expanded folders *****/ if (Cod > 0) { if (WorksUsrCod > 0) - sprintf (Query,"UPDATE expanded_folders SET ClickTime=NOW()" - " WHERE UsrCod=%ld AND FileBrowser=%u" - " AND Cod=%ld AND WorksUsrCod=%ld", - Gbl.Usrs.Me.UsrDat.UsrCod, - (unsigned) FileBrowserForExpandedFolders, - Cod, - WorksUsrCod); + { + if (asprintf (&Query,"UPDATE expanded_folders SET ClickTime=NOW()" + " WHERE UsrCod=%ld AND FileBrowser=%u" + " AND Cod=%ld AND WorksUsrCod=%ld", + Gbl.Usrs.Me.UsrDat.UsrCod, + (unsigned) FileBrowserForExpandedFolders, + Cod, + WorksUsrCod) < 0) + Lay_NotEnoughMemoryExit (); + } else - sprintf (Query,"UPDATE expanded_folders SET ClickTime=NOW()" - " WHERE UsrCod=%ld AND FileBrowser=%u" - " AND Cod=%ld", - Gbl.Usrs.Me.UsrDat.UsrCod, - (unsigned) FileBrowserForExpandedFolders, - Cod); + { + if (asprintf (&Query,"UPDATE expanded_folders SET ClickTime=NOW()" + " WHERE UsrCod=%ld AND FileBrowser=%u" + " AND Cod=%ld", + Gbl.Usrs.Me.UsrDat.UsrCod, + (unsigned) FileBrowserForExpandedFolders, + Cod) < 0) + Lay_NotEnoughMemoryExit (); + } } else // Briefcase - sprintf (Query,"UPDATE expanded_folders SET ClickTime=NOW()" - " WHERE UsrCod=%ld AND FileBrowser=%u", - Gbl.Usrs.Me.UsrDat.UsrCod, - (unsigned) FileBrowserForExpandedFolders); - DB_QueryUPDATE (Query,"can not update expanded folder"); + { + if (asprintf (&Query,"UPDATE expanded_folders SET ClickTime=NOW()" + " WHERE UsrCod=%ld AND FileBrowser=%u", + Gbl.Usrs.Me.UsrDat.UsrCod, + (unsigned) FileBrowserForExpandedFolders) < 0) + Lay_NotEnoughMemoryExit (); + } + DB_QueryUPDATE_free (Query,"can not update expanded folder"); } /*****************************************************************************/ @@ -8094,33 +8116,42 @@ static void Brw_RemoveFolderFromExpandedFolders (const char Path[PATH_MAX + 1]) { long Cod = Brw_GetCodForExpandedFolders (); long WorksUsrCod = Brw_GetWorksUsrCodForExpandedFolders (); - char Query[512 + PATH_MAX]; + char *Query; Brw_FileBrowser_t FileBrowserForExpandedFolders = Brw_FileBrowserForDB_expanded_folders[Gbl.FileBrowser.Type]; /***** Remove expanded folders associated to a file browser *****/ if (Cod > 0) { if (WorksUsrCod > 0) - sprintf (Query,"DELETE FROM expanded_folders" - " WHERE UsrCod=%ld AND FileBrowser=%u" - " AND Cod=%ld AND WorksUsrCod=%ld AND Path='%s/'", - Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) FileBrowserForExpandedFolders, - Cod,WorksUsrCod,Path); + { + if (asprintf (&Query,"DELETE FROM expanded_folders" + " WHERE UsrCod=%ld AND FileBrowser=%u" + " AND Cod=%ld AND WorksUsrCod=%ld AND Path='%s/'", + Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) FileBrowserForExpandedFolders, + Cod,WorksUsrCod,Path) < 0) + Lay_NotEnoughMemoryExit (); + } else - sprintf (Query,"DELETE FROM expanded_folders" - " WHERE UsrCod=%ld AND FileBrowser=%u" - " AND Cod=%ld AND Path='%s/'", - Gbl.Usrs.Me.UsrDat.UsrCod, - (unsigned) FileBrowserForExpandedFolders, - Cod,Path); + { + if (asprintf (&Query,"DELETE FROM expanded_folders" + " WHERE UsrCod=%ld AND FileBrowser=%u" + " AND Cod=%ld AND Path='%s/'", + Gbl.Usrs.Me.UsrDat.UsrCod, + (unsigned) FileBrowserForExpandedFolders, + Cod,Path) < 0) + Lay_NotEnoughMemoryExit (); + } } else // Briefcase - sprintf (Query,"DELETE FROM expanded_folders" - " WHERE UsrCod=%ld AND FileBrowser=%u" - " AND Path='%s/'", - Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) FileBrowserForExpandedFolders, - Path); - DB_QueryDELETE (Query,"can not contract the content of a folder"); + { + if (asprintf (&Query,"DELETE FROM expanded_folders" + " WHERE UsrCod=%ld AND FileBrowser=%u" + " AND Path='%s/'", + Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) FileBrowserForExpandedFolders, + Path) < 0) + Lay_NotEnoughMemoryExit (); + } + DB_QueryDELETE_free (Query,"can not contract the content of a folder"); } /*****************************************************************************/ @@ -8131,33 +8162,42 @@ static void Brw_RemoveAffectedExpandedFolders (const char Path[PATH_MAX + 1]) { long Cod = Brw_GetCodForExpandedFolders (); long WorksUsrCod = Brw_GetWorksUsrCodForExpandedFolders (); - char Query[512 + PATH_MAX]; + char *Query; Brw_FileBrowser_t FileBrowserForExpandedFolders = Brw_FileBrowserForDB_expanded_folders[Gbl.FileBrowser.Type]; /***** Remove expanded folders associated to a file browser from a course or from a user *****/ if (Cod > 0) { if (WorksUsrCod > 0) - sprintf (Query,"DELETE FROM expanded_folders" - " WHERE UsrCod=%ld AND FileBrowser=%u" - " AND Cod=%ld AND WorksUsrCod=%ld AND Path LIKE '%s/%%'", - Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) FileBrowserForExpandedFolders, - Cod,WorksUsrCod,Path); + { + if (asprintf (&Query,"DELETE FROM expanded_folders" + " WHERE UsrCod=%ld AND FileBrowser=%u" + " AND Cod=%ld AND WorksUsrCod=%ld AND Path LIKE '%s/%%'", + Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) FileBrowserForExpandedFolders, + Cod,WorksUsrCod,Path) < 0) + Lay_NotEnoughMemoryExit (); + } else - sprintf (Query,"DELETE FROM expanded_folders" - " WHERE UsrCod=%ld AND FileBrowser=%u" - " AND Cod=%ld AND Path LIKE '%s/%%'", - Gbl.Usrs.Me.UsrDat.UsrCod, - (unsigned) FileBrowserForExpandedFolders, - Cod,Path); + { + if (asprintf (&Query,"DELETE FROM expanded_folders" + " WHERE UsrCod=%ld AND FileBrowser=%u" + " AND Cod=%ld AND Path LIKE '%s/%%'", + Gbl.Usrs.Me.UsrDat.UsrCod, + (unsigned) FileBrowserForExpandedFolders, + Cod,Path) < 0) + Lay_NotEnoughMemoryExit (); + } } else // Briefcase - sprintf (Query,"DELETE FROM expanded_folders" - " WHERE UsrCod=%ld AND FileBrowser=%u" - " AND Path LIKE '%s/%%'", - Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) FileBrowserForExpandedFolders, - Path); - DB_QueryDELETE (Query,"can not remove expanded folders"); + { + if (asprintf (&Query,"DELETE FROM expanded_folders" + " WHERE UsrCod=%ld AND FileBrowser=%u" + " AND Path LIKE '%s/%%'", + Gbl.Usrs.Me.UsrDat.UsrCod,(unsigned) FileBrowserForExpandedFolders, + Path) < 0) + Lay_NotEnoughMemoryExit (); + } + DB_QueryDELETE_free (Query,"can not remove expanded folders"); } /*****************************************************************************/ @@ -8169,7 +8209,7 @@ static void Brw_RenameAffectedExpandedFolders (Brw_FileBrowser_t FileBrowser, const char *OldPath,const char *NewPath) { long Cod = Brw_GetCodForExpandedFolders (); - char Query[512 + PATH_MAX * 2]; + char *Query; Brw_FileBrowser_t FileBrowserForExpandedFolders = Brw_FileBrowserForDB_expanded_folders[FileBrowser]; unsigned StartFinalSubpathNotChanged = strlen (OldPath) + 2; @@ -8179,53 +8219,68 @@ static void Brw_RenameAffectedExpandedFolders (Brw_FileBrowser_t FileBrowser, if (MyUsrCod > 0) { if (WorksUsrCod > 0) - sprintf (Query,"UPDATE expanded_folders SET Path=CONCAT('%s','/',SUBSTRING(Path,%u))" - " WHERE UsrCod=%ld AND FileBrowser=%u" - " AND Cod=%ld AND WorksUsrCod=%ld" - " AND Path LIKE '%s/%%'", - NewPath,StartFinalSubpathNotChanged, - MyUsrCod,(unsigned) FileBrowserForExpandedFolders, - Cod,WorksUsrCod, - OldPath); + { + if (asprintf (&Query,"UPDATE expanded_folders SET Path=CONCAT('%s','/',SUBSTRING(Path,%u))" + " WHERE UsrCod=%ld AND FileBrowser=%u" + " AND Cod=%ld AND WorksUsrCod=%ld" + " AND Path LIKE '%s/%%'", + NewPath,StartFinalSubpathNotChanged, + MyUsrCod,(unsigned) FileBrowserForExpandedFolders, + Cod,WorksUsrCod, + OldPath) < 0) + Lay_NotEnoughMemoryExit (); + } else - sprintf (Query,"UPDATE expanded_folders SET Path=CONCAT('%s','/',SUBSTRING(Path,%u))" - " WHERE UsrCod=%ld AND FileBrowser=%u" - " AND Cod=%ld" - " AND Path LIKE '%s/%%'", - NewPath,StartFinalSubpathNotChanged, - MyUsrCod,(unsigned) FileBrowserForExpandedFolders, - Cod, - OldPath); + { + if (asprintf (&Query,"UPDATE expanded_folders SET Path=CONCAT('%s','/',SUBSTRING(Path,%u))" + " WHERE UsrCod=%ld AND FileBrowser=%u" + " AND Cod=%ld" + " AND Path LIKE '%s/%%'", + NewPath,StartFinalSubpathNotChanged, + MyUsrCod,(unsigned) FileBrowserForExpandedFolders, + Cod, + OldPath) < 0) + Lay_NotEnoughMemoryExit (); + } } else // MyUsrCod <= 0 means expanded folders for any user { if (WorksUsrCod > 0) - sprintf (Query,"UPDATE expanded_folders SET Path=CONCAT('%s','/',SUBSTRING(Path,%u))" - " WHERE FileBrowser=%u AND Cod=%ld" - " AND WorksUsrCod=%ld" - " AND Path LIKE '%s/%%'", - NewPath,StartFinalSubpathNotChanged, - (unsigned) FileBrowserForExpandedFolders,Cod, - WorksUsrCod, - OldPath); + { + if (asprintf (&Query,"UPDATE expanded_folders SET Path=CONCAT('%s','/',SUBSTRING(Path,%u))" + " WHERE FileBrowser=%u AND Cod=%ld" + " AND WorksUsrCod=%ld" + " AND Path LIKE '%s/%%'", + NewPath,StartFinalSubpathNotChanged, + (unsigned) FileBrowserForExpandedFolders,Cod, + WorksUsrCod, + OldPath) < 0) + Lay_NotEnoughMemoryExit (); + } else - sprintf (Query,"UPDATE expanded_folders SET Path=CONCAT('%s','/',SUBSTRING(Path,%u))" - " WHERE FileBrowser=%u AND Cod=%ld" - " AND Path LIKE '%s/%%'", - NewPath,StartFinalSubpathNotChanged, - (unsigned) FileBrowserForExpandedFolders,Cod, - OldPath); + { + if (asprintf (&Query,"UPDATE expanded_folders SET Path=CONCAT('%s','/',SUBSTRING(Path,%u))" + " WHERE FileBrowser=%u AND Cod=%ld" + " AND Path LIKE '%s/%%'", + NewPath,StartFinalSubpathNotChanged, + (unsigned) FileBrowserForExpandedFolders,Cod, + OldPath) < 0) + Lay_NotEnoughMemoryExit (); + } } } else // Briefcase - sprintf (Query,"UPDATE expanded_folders SET Path=CONCAT('%s','/',SUBSTRING(Path,%u))" - " WHERE UsrCod=%ld AND FileBrowser=%u" - " AND Path LIKE '%s/%%'", - NewPath,StartFinalSubpathNotChanged, - MyUsrCod, - (unsigned) FileBrowserForExpandedFolders, - OldPath); - DB_QueryUPDATE (Query,"can not update expanded folders"); + { + if (asprintf (&Query,"UPDATE expanded_folders SET Path=CONCAT('%s','/',SUBSTRING(Path,%u))" + " WHERE UsrCod=%ld AND FileBrowser=%u" + " AND Path LIKE '%s/%%'", + NewPath,StartFinalSubpathNotChanged, + MyUsrCod, + (unsigned) FileBrowserForExpandedFolders, + OldPath) < 0) + Lay_NotEnoughMemoryExit (); + } + DB_QueryUPDATE_free (Query,"can not update expanded folders"); } /*****************************************************************************/ @@ -8236,39 +8291,48 @@ static bool Brw_GetIfExpandedTree (const char Path[PATH_MAX + 1]) { long Cod = Brw_GetCodForExpandedFolders (); long WorksUsrCod = Brw_GetWorksUsrCodForExpandedFolders (); - char Query[512 + PATH_MAX]; + char *Query; Brw_FileBrowser_t FileBrowserForExpandedFolders = Brw_FileBrowserForDB_expanded_folders[Gbl.FileBrowser.Type]; /***** Get if a folder is expanded from database *****/ if (Cod > 0) { if (WorksUsrCod > 0) - sprintf (Query,"SELECT COUNT(*) FROM expanded_folders" - " WHERE UsrCod=%ld AND FileBrowser=%u" - " AND Cod=%ld AND WorksUsrCod=%ld" - " AND Path='%s/'", - Gbl.Usrs.Me.UsrDat.UsrCod, - (unsigned) FileBrowserForExpandedFolders, - Cod,WorksUsrCod, - Path); + { + if (asprintf (&Query,"SELECT COUNT(*) FROM expanded_folders" + " WHERE UsrCod=%ld AND FileBrowser=%u" + " AND Cod=%ld AND WorksUsrCod=%ld" + " AND Path='%s/'", + Gbl.Usrs.Me.UsrDat.UsrCod, + (unsigned) FileBrowserForExpandedFolders, + Cod,WorksUsrCod, + Path) < 0) + Lay_NotEnoughMemoryExit (); + } else - sprintf (Query,"SELECT COUNT(*) FROM expanded_folders" - " WHERE UsrCod=%ld AND FileBrowser=%u" - " AND Cod=%ld" - " AND Path='%s/'", - Gbl.Usrs.Me.UsrDat.UsrCod, - (unsigned) FileBrowserForExpandedFolders, - Cod, - Path); + { + if (asprintf (&Query,"SELECT COUNT(*) FROM expanded_folders" + " WHERE UsrCod=%ld AND FileBrowser=%u" + " AND Cod=%ld" + " AND Path='%s/'", + Gbl.Usrs.Me.UsrDat.UsrCod, + (unsigned) FileBrowserForExpandedFolders, + Cod, + Path) < 0) + Lay_NotEnoughMemoryExit (); + } } else // Briefcase - sprintf (Query,"SELECT COUNT(*) FROM expanded_folders" - " WHERE UsrCod=%ld AND FileBrowser=%u" - " AND Path='%s/'", - Gbl.Usrs.Me.UsrDat.UsrCod, - (unsigned) FileBrowserForExpandedFolders, - Path); - return (DB_QueryCOUNT (Query,"can not get check if a folder is expanded") != 0); + { + if (asprintf (&Query,"SELECT COUNT(*) FROM expanded_folders" + " WHERE UsrCod=%ld AND FileBrowser=%u" + " AND Path='%s/'", + Gbl.Usrs.Me.UsrDat.UsrCod, + (unsigned) FileBrowserForExpandedFolders, + Path) < 0) + Lay_NotEnoughMemoryExit (); + } + return (DB_QueryCOUNT_free (Query,"can not get check if a folder is expanded") != 0); } /*****************************************************************************/ @@ -8329,13 +8393,14 @@ static long Brw_GetWorksUsrCodForExpandedFolders (void) void Brw_RemoveExpiredExpandedFolders (void) { - char Query[256]; + char *Query; /***** Remove all expired clipboards *****/ - sprintf (Query,"DELETE LOW_PRIORITY FROM expanded_folders" - " WHERE ClickTime