mirror of https://github.com/acanas/swad-core.git
Version 22.50.7: Oct 20, 2022 Code refactoring in files.
This commit is contained in:
parent
611668070c
commit
96ecc72a50
59
swad_API.c
59
swad_API.c
|
@ -292,9 +292,11 @@ static int API_GetTstQuestionTags (struct soap *soap,
|
|||
static void API_GetListGrpsInMatchFromDB (struct soap *soap,
|
||||
long MchCod,char **ListGroups);
|
||||
|
||||
static void API_ListDir (unsigned Level,const char *Path,const char *PathInTree);
|
||||
static bool API_WriteRowFileBrowser (unsigned Level,Brw_FileType_t FileType,const char *FileName);
|
||||
static void API_IndentXMLLine (unsigned Level);
|
||||
static void API_ListDir (FILE *XML,unsigned Level,const char *Path,const char *PathInTree);
|
||||
static bool API_WriteRowFileBrowser (FILE *XML,unsigned Level,
|
||||
Brw_FileType_t FileType,
|
||||
const char *FileName);
|
||||
static void API_IndentXMLLine (FILE *XML,unsigned Level);
|
||||
|
||||
static void API_GetDataOfLocation (struct soap *soap,
|
||||
struct swad__location *location,
|
||||
|
@ -4598,6 +4600,7 @@ int swad__getDirectoryTree (struct soap *soap,
|
|||
extern const char *Brw_RootFolderInternalNames[Brw_NUM_TYPES_FILE_BROWSER];
|
||||
int ReturnCode;
|
||||
char XMLFileName[PATH_MAX + 1];
|
||||
FILE *XML;
|
||||
unsigned long FileSize;
|
||||
unsigned long NumBytesRead;
|
||||
|
||||
|
@ -4708,30 +4711,32 @@ int swad__getDirectoryTree (struct soap *soap,
|
|||
Cfg_PATH_OUT_PRIVATE,Cry_GetUniqueNameEncrypted ());
|
||||
|
||||
/* Open file for writing and reading */
|
||||
if ((Gbl.F.XML = fopen (XMLFileName,"w+t")) == NULL)
|
||||
if ((XML = fopen (XMLFileName,"w+t")) == NULL)
|
||||
return soap_receiver_fault (soap,
|
||||
"Can not get tree",
|
||||
"Can not create temporary XML file");
|
||||
|
||||
/* Get directory tree into XML file */
|
||||
XML_WriteStartFile (Gbl.F.XML,"tree",false);
|
||||
XML_WriteStartFile (XML,"tree",false);
|
||||
if (!Brw_CheckIfFileOrFolderIsSetAsHiddenInDB (Brw_IS_FOLDER,
|
||||
Gbl.FileBrowser.FilFolLnk.Full)) // If root folder is visible
|
||||
API_ListDir (1,Gbl.FileBrowser.Priv.PathRootFolder,Brw_RootFolderInternalNames[Gbl.FileBrowser.Type]);
|
||||
XML_WriteEndFile (Gbl.F.XML,"tree");
|
||||
API_ListDir (XML,1,
|
||||
Gbl.FileBrowser.Priv.PathRootFolder,
|
||||
Brw_RootFolderInternalNames[Gbl.FileBrowser.Type]);
|
||||
XML_WriteEndFile (XML,"tree");
|
||||
|
||||
/* Compute file size */
|
||||
// fseek (Gbl.F.XML,0L,SEEK_END);
|
||||
FileSize = (unsigned long) ftell (Gbl.F.XML);
|
||||
fseek (Gbl.F.XML,0L,SEEK_SET);
|
||||
// fseek (XML,0L,SEEK_END);
|
||||
FileSize = (unsigned long) ftell (XML);
|
||||
fseek (XML,0L,SEEK_SET);
|
||||
|
||||
/* Copy XML content from file to memory */
|
||||
getDirectoryTreeOut->tree = soap_malloc (soap,FileSize + 1);
|
||||
NumBytesRead = fread (getDirectoryTreeOut->tree,1,FileSize,Gbl.F.XML);
|
||||
NumBytesRead = fread (getDirectoryTreeOut->tree,1,FileSize,XML);
|
||||
getDirectoryTreeOut->tree[NumBytesRead] = '\0';
|
||||
|
||||
/* Close and remove XML file */
|
||||
Fil_CloseXMLFile ();
|
||||
fclose (XML);
|
||||
unlink (XMLFileName);
|
||||
|
||||
return SOAP_OK;
|
||||
|
@ -4741,7 +4746,8 @@ int swad__getDirectoryTree (struct soap *soap,
|
|||
/************************ List a directory recursively ***********************/
|
||||
/*****************************************************************************/
|
||||
|
||||
static void API_ListDir (unsigned Level,const char *Path,const char *PathInTree)
|
||||
static void API_ListDir (FILE *XML,unsigned Level,
|
||||
const char *Path,const char *PathInTree)
|
||||
{
|
||||
extern const char *Txt_NEW_LINE;
|
||||
struct dirent **FileList;
|
||||
|
@ -4780,18 +4786,21 @@ static void API_ListDir (unsigned Level,const char *Path,const char *PathInTree)
|
|||
if (S_ISDIR (FileStatus.st_mode)) // It's a directory
|
||||
{
|
||||
/***** Write a row for the subdirectory *****/
|
||||
if (API_WriteRowFileBrowser (Level,Brw_IS_FOLDER,FileList[NumFile]->d_name))
|
||||
if (API_WriteRowFileBrowser (XML,Level,
|
||||
Brw_IS_FOLDER,
|
||||
FileList[NumFile]->d_name))
|
||||
{
|
||||
/* List subtree starting at this this directory */
|
||||
API_ListDir (Level + 1,PathFileRel,PathFileInExplTree);
|
||||
API_ListDir (XML,Level + 1,
|
||||
PathFileRel,PathFileInExplTree);
|
||||
|
||||
/* Indent and end dir */
|
||||
API_IndentXMLLine (Level);
|
||||
fprintf (Gbl.F.XML,"</dir>%s",Txt_NEW_LINE);
|
||||
API_IndentXMLLine (XML,Level);
|
||||
fprintf (XML,"</dir>%s",Txt_NEW_LINE);
|
||||
}
|
||||
}
|
||||
else if (S_ISREG (FileStatus.st_mode)) // It's a regular file
|
||||
API_WriteRowFileBrowser (Level,
|
||||
API_WriteRowFileBrowser (XML,Level,
|
||||
Str_FileIs (FileList[NumFile]->d_name,"url") ? Brw_IS_LINK :
|
||||
Brw_IS_FILE,
|
||||
FileList[NumFile]->d_name);
|
||||
|
@ -4811,7 +4820,9 @@ static void API_ListDir (unsigned Level,const char *Path,const char *PathInTree)
|
|||
// If it is not the first row, it is shown or not depending on whether it is hidden or not
|
||||
// If the row is visible, return true. If it is hidden, return false
|
||||
|
||||
static bool API_WriteRowFileBrowser (unsigned Level,Brw_FileType_t FileType,const char *FileName)
|
||||
static bool API_WriteRowFileBrowser (FILE *XML,unsigned Level,
|
||||
Brw_FileType_t FileType,
|
||||
const char *FileName)
|
||||
{
|
||||
extern const char *Txt_NEW_LINE;
|
||||
extern const char *Txt_LICENSES[Brw_NUM_LICENSES];
|
||||
|
@ -4827,11 +4838,11 @@ static bool API_WriteRowFileBrowser (unsigned Level,Brw_FileType_t FileType,cons
|
|||
|
||||
/***** XML row *****/
|
||||
/* Indent */
|
||||
API_IndentXMLLine (Level);
|
||||
API_IndentXMLLine (XML,Level);
|
||||
|
||||
/* Write file or folder data */
|
||||
if (FileType == Brw_IS_FOLDER)
|
||||
fprintf (Gbl.F.XML,"<dir name=\"%s\">%s",
|
||||
fprintf (XML,"<dir name=\"%s\">%s",
|
||||
FileName,Txt_NEW_LINE);
|
||||
else // File or link
|
||||
{
|
||||
|
@ -4850,7 +4861,7 @@ static bool API_WriteRowFileBrowser (unsigned Level,Brw_FileType_t FileType,cons
|
|||
Usr_DONT_GET_ROLE_IN_CURRENT_CRS);
|
||||
Pho_BuildLinkToPhoto (&Gbl.Usrs.Me.UsrDat,PhotoURL);
|
||||
|
||||
fprintf (Gbl.F.XML,"<file name=\"%s\">"
|
||||
fprintf (XML,"<file name=\"%s\">"
|
||||
"<code>%ld</code>"
|
||||
"<size>%lu</size>"
|
||||
"<time>%lu</time>"
|
||||
|
@ -4875,12 +4886,12 @@ static bool API_WriteRowFileBrowser (unsigned Level,Brw_FileType_t FileType,cons
|
|||
/******************************* Indent XML line *****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
static void API_IndentXMLLine (unsigned Level)
|
||||
static void API_IndentXMLLine (FILE *XML,unsigned Level)
|
||||
{
|
||||
for ( ;
|
||||
Level;
|
||||
Level--)
|
||||
fprintf (Gbl.F.XML,"\t");
|
||||
fprintf (XML,"\t");
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -6664,7 +6664,7 @@ static bool Brw_PasteTreeIntoFolder (unsigned LevelOrg,
|
|||
{
|
||||
/* Check extension of the file */
|
||||
if (Str_FileIsHTML (FileNameOrg))
|
||||
Mrk_CheckFileOfMarks (PathOrg,&Marks); // Gbl.Alert.Txt contains feedback text
|
||||
Mrk_CheckFileOfMarks (PathOrg,&Marks);
|
||||
else
|
||||
{
|
||||
Ale_ShowAlert (Ale_WARNING,Txt_The_copy_has_stopped_when_trying_to_paste_the_file_X_because_you_can_not_paste_a_file_here_of_a_type_other_than_HTML,
|
||||
|
@ -7362,7 +7362,7 @@ static bool Brw_RcvFileInFileBrw (Brw_UploadType_t UploadType)
|
|||
/***** Check if creating a new file is allowed *****/
|
||||
if (Brw_CheckIfICanCreateIntoFolder (Gbl.FileBrowser.Level))
|
||||
{
|
||||
/***** First, we save in disk the file from stdin (really from Gbl.F.Tmp) *****/
|
||||
/***** First, we save in disk the file received *****/
|
||||
Param = Fil_StartReceptionOfFile (Fil_NAME_OF_PARAM_FILENAME_ORG,
|
||||
SrcFileName,MIMEType);
|
||||
|
||||
|
@ -7374,7 +7374,7 @@ static bool Brw_RcvFileInFileBrw (Brw_UploadType_t UploadType)
|
|||
if (Gbl.FileBrowser.NewFilFolLnkName[0])
|
||||
{
|
||||
/***** Check if uploading this kind of file is allowed *****/
|
||||
if (Brw_CheckIfUploadIsAllowed (MIMEType)) // Gbl.Alert.Txt contains feedback text
|
||||
if (Brw_CheckIfUploadIsAllowed (MIMEType))
|
||||
{
|
||||
if (Str_ConvertFilFolLnkNameToValid (Gbl.FileBrowser.NewFilFolLnkName))
|
||||
{
|
||||
|
@ -7398,12 +7398,12 @@ static bool Brw_RcvFileInFileBrw (Brw_UploadType_t UploadType)
|
|||
{
|
||||
/* End receiving the file */
|
||||
snprintf (PathTmp,sizeof (PathTmp),"%s.tmp",Path);
|
||||
FileIsValid = Fil_EndReceptionOfFile (PathTmp,Param); // Gbl.Alert.Txt contains feedback text
|
||||
FileIsValid = Fil_EndReceptionOfFile (PathTmp,Param);
|
||||
|
||||
/* Check if the content of the file of marks is valid */
|
||||
if (FileIsValid)
|
||||
if (AdminMarks)
|
||||
if (!Mrk_CheckFileOfMarks (PathTmp,&Marks)) // Gbl.Alert.Txt contains feedback text
|
||||
if (!Mrk_CheckFileOfMarks (PathTmp,&Marks))
|
||||
FileIsValid = false;
|
||||
|
||||
if (FileIsValid)
|
||||
|
@ -7575,7 +7575,7 @@ void Brw_RecLinkFileBrowser (void)
|
|||
FileName);
|
||||
|
||||
/* Convert the last name in URL to a valid filename */
|
||||
if (Str_ConvertFilFolLnkNameToValid (FileName)) // Gbl.Alert.Txt contains feedback text
|
||||
if (Str_ConvertFilFolLnkNameToValid (FileName))
|
||||
{
|
||||
/* The name of the file with the link will be the FileName.url */
|
||||
snprintf (Path,sizeof (Path),"%s/%s",
|
||||
|
|
|
@ -920,7 +920,7 @@ void CtrCfg_ReceivePhoto (void)
|
|||
|
||||
/* End the reception of image in a temporary file */
|
||||
snprintf (PathFileImgTmp,sizeof (PathFileImgTmp),"%s/%s.%s",
|
||||
Cfg_PATH_MEDIA_TMP_PRIVATE,Gbl.UniqueNameEncrypted,PtrExtension);
|
||||
Cfg_PATH_MEDIA_TMP_PRIVATE,Cry_GetUniqueNameEncrypted (),PtrExtension);
|
||||
if (!Fil_EndReceptionOfFile (PathFileImgTmp,Param))
|
||||
{
|
||||
Ale_ShowAlert (Ale_WARNING,"Error copying file.");
|
||||
|
|
|
@ -605,7 +605,7 @@ TODO: Fix bug: error al enviar un mensaje a dos recipientes, error on duplicate
|
|||
|
||||
TODO: Attach pdf files in multimedia.
|
||||
*/
|
||||
#define Log_PLATFORM_VERSION "SWAD 22.50.6 (2022-10-21)"
|
||||
#define Log_PLATFORM_VERSION "SWAD 22.50.7 (2022-10-21)"
|
||||
#define CSS_FILE "swad22.49.4.css"
|
||||
#define JS_FILE "swad22.49.js"
|
||||
/*
|
||||
|
@ -616,6 +616,7 @@ Que al subir un fichero por defecto est
|
|||
Al subir cosas para los grupos, en documentos, resltar más los grupos porque no son conscientes...
|
||||
Exportar listas en CSV.
|
||||
|
||||
Version 22.50.7: Oct 20, 2022 Code refactoring in files. (333496 lines)
|
||||
Version 22.50.6: Oct 20, 2022 Code refactoring in syllabus. (333492 lines)
|
||||
Version 22.50.5: Oct 20, 2022 Code refactoring in configuration. (333447 lines)
|
||||
Version 22.50.4: Oct 20, 2022 Code refactoring in email sending. (333438 lines)
|
||||
|
|
|
@ -130,7 +130,7 @@ void Cry_EncryptSHA512Base64 (const char *PlainText,
|
|||
/*** Create a unique name encrypted, different each time function is called **/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Cry_CreateUniqueNameEncrypted (char UniqueNameEncrypted[Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64 + 1])
|
||||
void Cry_CreateUniqueNameEncrypted (char *UniqueNameEncrypted)
|
||||
{
|
||||
static unsigned NumCall = 0; // When this function is called several times in the same execution of the program, each time a new name is created
|
||||
char UniqueNamePlain[Cns_MAX_BYTES_IP +
|
||||
|
@ -147,7 +147,7 @@ void Cry_CreateUniqueNameEncrypted (char UniqueNameEncrypted[Cry_BYTES_ENCRYPTED
|
|||
Cry_EncryptSHA256Base64 (UniqueNamePlain,UniqueNameEncrypted); // Make difficult to guess a unique name
|
||||
}
|
||||
|
||||
const char *Cry_GetUniqueNameEncrypted (void)
|
||||
char *Cry_GetUniqueNameEncrypted (void)
|
||||
{
|
||||
return Cry_UniqueNameEncrypted;
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ void Cry_EncryptSHA256Base64 (const char *PlainText,
|
|||
void Cry_EncryptSHA512Base64 (const char *PlainText,
|
||||
char EncryptedText[Cry_LENGTH_ENCRYPTED_STR_SHA512_BASE64 + 1]);
|
||||
|
||||
void Cry_CreateUniqueNameEncrypted (char UniqueNameEncrypted[Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64 + 1]);
|
||||
const char *Cry_GetUniqueNameEncrypted (void);
|
||||
void Cry_CreateUniqueNameEncrypted (char *UniqueNameEncrypted);
|
||||
char *Cry_GetUniqueNameEncrypted (void);
|
||||
|
||||
#endif
|
||||
|
|
53
swad_file.c
53
swad_file.c
|
@ -63,6 +63,21 @@ static struct
|
|||
char FileName[PATH_MAX + 1];
|
||||
} Fil_HTMLOutput;
|
||||
|
||||
/*****************************************************************************/
|
||||
/************************* Private global variables **************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
static FILE *Fil_QueryFile = NULL; // Temporary file to save stdin
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************************** Get query file ********************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
FILE *Fil_GetQueryFile (void)
|
||||
{
|
||||
return Fil_QueryFile;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/******** Create HTML output file for the web page sent by this CGI **********/
|
||||
/*****************************************************************************/
|
||||
|
@ -74,7 +89,7 @@ void Fil_CreateFileForHTMLOutput (void)
|
|||
|
||||
/***** Create a unique name for the file *****/
|
||||
snprintf (Fil_HTMLOutput.FileName,sizeof (Fil_HTMLOutput.FileName),
|
||||
"%s/%s.html",Cfg_PATH_OUT_PRIVATE,Gbl.UniqueNameEncrypted);
|
||||
"%s/%s.html",Cfg_PATH_OUT_PRIVATE,Cry_GetUniqueNameEncrypted ());
|
||||
|
||||
/***** Open file for writing and reading *****/
|
||||
if ((Gbl.F.Out = fopen (Fil_HTMLOutput.FileName,"w+t")) == NULL)
|
||||
|
@ -101,7 +116,6 @@ void Fil_CloseAndRemoveFileForHTMLOutput (void)
|
|||
/*****************************************************************************/
|
||||
/********** Open temporary file and write on it reading from stdin ***********/
|
||||
/*****************************************************************************/
|
||||
// On error, Gbl.Alert.Txt will contain feedback
|
||||
|
||||
bool Fil_ReadStdinIntoTmpFile (void)
|
||||
{
|
||||
|
@ -111,7 +125,7 @@ bool Fil_ReadStdinIntoTmpFile (void)
|
|||
bool FileIsTooBig = false;
|
||||
bool TimeExceeded = false;
|
||||
|
||||
if ((Gbl.F.Tmp = tmpfile ()) == NULL)
|
||||
if ((Fil_QueryFile = tmpfile ()) == NULL)
|
||||
{
|
||||
Fil_EndOfReadingStdin ();
|
||||
Err_ShowErrorAndExit ("Can not create temporary file.");
|
||||
|
@ -124,7 +138,7 @@ bool Fil_ReadStdinIntoTmpFile (void)
|
|||
if (!(TmpFileSize % (64ULL * 1024ULL))) // Check timeout from time to time
|
||||
if (time (NULL) - Dat_GetStartExecutionTimeUTC () >= Cfg_TIME_TO_ABORT_FILE_UPLOAD)
|
||||
TimeExceeded = true;
|
||||
fputc (fgetc (stdin),Gbl.F.Tmp);
|
||||
fputc (fgetc (stdin),Fil_QueryFile);
|
||||
}
|
||||
else
|
||||
FileIsTooBig = true;
|
||||
|
@ -152,7 +166,7 @@ bool Fil_ReadStdinIntoTmpFile (void)
|
|||
|
||||
return false;
|
||||
}
|
||||
rewind (Gbl.F.Tmp);
|
||||
rewind (Fil_QueryFile);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -213,6 +227,7 @@ struct Param *Fil_StartReceptionOfFile (const char *ParamFile,
|
|||
char *FileName,char *MIMEType)
|
||||
{
|
||||
struct Param *Param;
|
||||
FILE *QueryFile = Fil_GetQueryFile ();
|
||||
|
||||
/***** Set default values *****/
|
||||
FileName[0] = 0;
|
||||
|
@ -232,8 +247,8 @@ struct Param *Fil_StartReceptionOfFile (const char *ParamFile,
|
|||
Err_ShowErrorAndExit ("Error while getting filename.");
|
||||
|
||||
/* Copy filename */
|
||||
fseek (Gbl.F.Tmp,Param->FileName.Start,SEEK_SET);
|
||||
if (fread (FileName,sizeof (char),Param->FileName.Length,Gbl.F.Tmp) !=
|
||||
fseek (QueryFile,Param->FileName.Start,SEEK_SET);
|
||||
if (fread (FileName,sizeof (char),Param->FileName.Length,QueryFile) !=
|
||||
Param->FileName.Length)
|
||||
Err_ShowErrorAndExit ("Error while getting filename.");
|
||||
FileName[Param->FileName.Length] = '\0';
|
||||
|
@ -246,8 +261,8 @@ struct Param *Fil_StartReceptionOfFile (const char *ParamFile,
|
|||
Err_ShowErrorAndExit ("Error while getting content type.");
|
||||
|
||||
/* Copy MIME type */
|
||||
fseek (Gbl.F.Tmp,Param->ContentType.Start,SEEK_SET);
|
||||
if (fread (MIMEType,sizeof (char),Param->ContentType.Length,Gbl.F.Tmp) !=
|
||||
fseek (QueryFile,Param->ContentType.Start,SEEK_SET);
|
||||
if (fread (MIMEType,sizeof (char),Param->ContentType.Length,QueryFile) !=
|
||||
Param->ContentType.Length)
|
||||
Err_ShowErrorAndExit ("Error while getting content type.");
|
||||
MIMEType[Param->ContentType.Length] = '\0';
|
||||
|
@ -265,6 +280,7 @@ bool Fil_EndReceptionOfFile (char *FileNameDataTmp,struct Param *Param)
|
|||
unsigned char Bytes[NUM_BYTES_PER_CHUNK];
|
||||
size_t RemainingBytesToCopy;
|
||||
size_t BytesToCopy;
|
||||
FILE *QueryFile = Fil_GetQueryFile ();
|
||||
|
||||
/***** Open destination file *****/
|
||||
if ((FileDataTmp = fopen (FileNameDataTmp,"wb")) == NULL)
|
||||
|
@ -274,16 +290,16 @@ bool Fil_EndReceptionOfFile (char *FileNameDataTmp,struct Param *Param)
|
|||
/* Go to start of source */
|
||||
if (Param->Value.Start == 0)
|
||||
Err_ShowErrorAndExit ("Error while copying file.");
|
||||
fseek (Gbl.F.Tmp,Param->Value.Start,SEEK_SET);
|
||||
fseek (QueryFile,Param->Value.Start,SEEK_SET);
|
||||
|
||||
/* Copy part of Gbl.F.Tmp to FileDataTmp */
|
||||
/* Copy part of query file to FileDataTmp */
|
||||
for (RemainingBytesToCopy = Param->Value.Length;
|
||||
RemainingBytesToCopy != 0;
|
||||
RemainingBytesToCopy -= BytesToCopy)
|
||||
{
|
||||
BytesToCopy = (RemainingBytesToCopy >= NUM_BYTES_PER_CHUNK) ? NUM_BYTES_PER_CHUNK :
|
||||
RemainingBytesToCopy;
|
||||
if (fread (Bytes,1,BytesToCopy,Gbl.F.Tmp) != BytesToCopy)
|
||||
if (fread (Bytes,1,BytesToCopy,QueryFile) != BytesToCopy)
|
||||
{
|
||||
fclose (FileDataTmp);
|
||||
return false;
|
||||
|
@ -558,19 +574,6 @@ void Fil_FastCopyOfOpenFiles (FILE *FileSrc,FILE *FileTgt)
|
|||
fwrite (Bytes,sizeof (Bytes[0]),NumBytesRead,FileTgt);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**************************** Close XML file *********************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
void Fil_CloseXMLFile (void)
|
||||
{
|
||||
if (Gbl.F.XML)
|
||||
{
|
||||
fclose (Gbl.F.XML);
|
||||
Gbl.F.XML = NULL; // To indicate that it is not open
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/***************************** Close report file *****************************/
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -48,8 +48,6 @@
|
|||
struct Fil_Files
|
||||
{
|
||||
FILE *Out; // File with the HTML output of this CGI
|
||||
FILE *Tmp; // Temporary file to save stdin
|
||||
FILE *XML; // XML file for syllabus, for directory tree
|
||||
FILE *Rep; // Temporary file to save report
|
||||
};
|
||||
|
||||
|
@ -59,6 +57,7 @@ struct Fil_Files
|
|||
/***************************** Public prototypes *****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
FILE *Fil_GetQueryFile (void);
|
||||
void Fil_CreateFileForHTMLOutput (void);
|
||||
void Fil_CloseAndRemoveFileForHTMLOutput (void);
|
||||
bool Fil_ReadStdinIntoTmpFile (void);
|
||||
|
@ -85,7 +84,6 @@ void Fil_RemoveOldTmpFiles (const char *Path,time_t TimeToRemove,
|
|||
void Fil_FastCopyOfFiles (const char *PathSrc,const char *PathTgt);
|
||||
void Fil_FastCopyOfOpenFiles (FILE *FileSrc,FILE *FileTgt);
|
||||
|
||||
void Fil_CloseXMLFile (void);
|
||||
void Fil_CloseReportFile (void);
|
||||
|
||||
void Fil_WriteFileSizeBrief (double SizeInBytes,
|
||||
|
|
|
@ -255,10 +255,10 @@ void Frm_SetUniqueId (char UniqueId[Frm_MAX_BYTES_ID + 1])
|
|||
/***** Create Id. The id must be unique,
|
||||
the page content may be updated via AJAX.
|
||||
So, Id uses:
|
||||
- a name for this execution (Gbl.UniqueNameEncrypted)
|
||||
- a number for each element in this execution (CountForThisExecution) *****/
|
||||
- a name for this execution
|
||||
- a number for each element in this execution *****/
|
||||
snprintf (UniqueId,Frm_MAX_BYTES_ID + 1,"id_%s_%u",
|
||||
Gbl.UniqueNameEncrypted,
|
||||
Cry_GetUniqueNameEncrypted (),
|
||||
++CountForThisExecution);
|
||||
}
|
||||
|
||||
|
|
|
@ -88,15 +88,13 @@ void Gbl_InitializeGlobals (void)
|
|||
Gbl.PID = getpid ();
|
||||
Sta_GetRemoteAddr ();
|
||||
|
||||
Cry_CreateUniqueNameEncrypted (Gbl.UniqueNameEncrypted);
|
||||
Cry_CreateUniqueNameEncrypted (Cry_GetUniqueNameEncrypted ());
|
||||
|
||||
srand ((unsigned int) Dat_GetStartExecutionTimeUTC ()); // Initialize seed for rand()
|
||||
|
||||
Gbl.WebService.IsWebService = false;
|
||||
|
||||
Gbl.F.Out = stdout;
|
||||
Gbl.F.Tmp = NULL;
|
||||
Gbl.F.XML = NULL;
|
||||
Gbl.F.Rep = NULL; // Report
|
||||
|
||||
Gbl.Prefs.Language = Txt_Current_CGI_SWAD_Language;
|
||||
|
@ -338,9 +336,6 @@ void Gbl_Cleanup (void)
|
|||
Usr_FreeListOtherRecipients ();
|
||||
Usr_FreeListsSelectedEncryptedUsrsCods (&Gbl.Usrs.Selected);
|
||||
Syl_FreeListItemsSyllabus ();
|
||||
if (Gbl.F.Tmp)
|
||||
fclose (Gbl.F.Tmp);
|
||||
Fil_CloseXMLFile ();
|
||||
Fil_CloseReportFile ();
|
||||
Par_FreeParams ();
|
||||
Ale_ResetAllAlerts ();
|
||||
|
|
|
@ -1528,6 +1528,7 @@ static bool Inf_CheckAndShowRichTxt (void)
|
|||
char TxtMD[Cns_MAX_BYTES_LONG_TEXT + 1];
|
||||
char PathFileMD[PATH_MAX + 1];
|
||||
char PathFileHTML[PATH_MAX + 1];
|
||||
const char *UniqueNameEncrypted;
|
||||
FILE *FileMD; // Temporary Markdown file
|
||||
FILE *FileHTML; // Temporary HTML file
|
||||
char MathJaxURL[PATH_MAX + 1];
|
||||
|
@ -1573,10 +1574,11 @@ static bool Inf_CheckAndShowRichTxt (void)
|
|||
/***** Store text into a temporary .md file in HTML output directory *****/
|
||||
// TODO: change to another directory?
|
||||
/* Create a unique name for the .md file */
|
||||
UniqueNameEncrypted = Cry_GetUniqueNameEncrypted ();
|
||||
snprintf (PathFileMD,sizeof (PathFileMD),"%s/%s.md",
|
||||
Cfg_PATH_OUT_PRIVATE,Gbl.UniqueNameEncrypted);
|
||||
Cfg_PATH_OUT_PRIVATE,UniqueNameEncrypted);
|
||||
snprintf (PathFileHTML,sizeof (PathFileHTML),"%s/%s.md.html", // Do not use only .html because that is the output temporary file
|
||||
Cfg_PATH_OUT_PRIVATE,Gbl.UniqueNameEncrypted);
|
||||
Cfg_PATH_OUT_PRIVATE,UniqueNameEncrypted);
|
||||
|
||||
/* Open Markdown file for writing */
|
||||
if ((FileMD = fopen (PathFileMD,"wb")) == NULL)
|
||||
|
@ -1931,7 +1933,7 @@ void Inf_ReceivePagInfo (void)
|
|||
/***** Set info type *****/
|
||||
Inf_AsignInfoType (&Gbl.Crs.Info,&Syllabus);
|
||||
|
||||
/***** First of all, store in disk the file from stdin (really from Gbl.F.Tmp) *****/
|
||||
/***** First of all, store in disk the file received *****/
|
||||
Param = Fil_StartReceptionOfFile (Fil_NAME_OF_PARAM_FILENAME_ORG,
|
||||
SourceFileName,MIMEType);
|
||||
|
||||
|
|
|
@ -357,7 +357,7 @@ void Lgo_ReceiveLogo (HieLvl_Level_t Scope)
|
|||
(unsigned) Cod);
|
||||
Fil_CreateDirIfNotExists (Path);
|
||||
|
||||
/***** Copy in disk the file received from stdin (really from Gbl.F.Tmp) *****/
|
||||
/***** Copy in disk the file received *****/
|
||||
Param = Fil_StartReceptionOfFile (Fil_NAME_OF_PARAM_FILENAME_ORG,
|
||||
FileNameLogoSrc,MIMEType);
|
||||
|
||||
|
|
|
@ -1431,6 +1431,7 @@ bool Mai_SendMailMsgToConfirmEmail (void)
|
|||
extern const char *Txt_There_was_a_problem_sending_an_email_automatically;
|
||||
char FileNameMail[PATH_MAX + 1];
|
||||
FILE *FileMail;
|
||||
const char *UniqueNameEncrypted = Cry_GetUniqueNameEncrypted ();
|
||||
int ReturnCode;
|
||||
|
||||
/***** Create temporary file for mail content *****/
|
||||
|
@ -1441,13 +1442,13 @@ bool Mai_SendMailMsgToConfirmEmail (void)
|
|||
Mai_WriteWelcomeNoteEMail (FileMail,&Gbl.Usrs.Me.UsrDat);
|
||||
|
||||
/* Store encrypted key in database */
|
||||
Mai_InsertMailKey (Gbl.Usrs.Me.UsrDat.Email,Gbl.UniqueNameEncrypted);
|
||||
Mai_InsertMailKey (Gbl.Usrs.Me.UsrDat.Email,UniqueNameEncrypted);
|
||||
|
||||
/* Message body */
|
||||
fprintf (FileMail,
|
||||
Txt_If_you_just_requested_from_X_the_confirmation_of_your_email_Y_NO_HTML,
|
||||
Cfg_URL_SWAD_CGI,Gbl.Usrs.Me.UsrDat.Email,
|
||||
Cfg_URL_SWAD_CGI,Act_GetActCod (ActCnfMai),Gbl.UniqueNameEncrypted,
|
||||
Cfg_URL_SWAD_CGI,Act_GetActCod (ActCnfMai),UniqueNameEncrypted,
|
||||
Cfg_URL_SWAD_CGI);
|
||||
|
||||
/* Footer note */
|
||||
|
@ -1576,7 +1577,7 @@ void Mai_ConfirmEmail (void)
|
|||
void Mai_CreateFileNameMail (char FileNameMail[PATH_MAX + 1],FILE **FileMail)
|
||||
{
|
||||
snprintf (FileNameMail,PATH_MAX + 1,"%s/%s_mail.txt",
|
||||
Cfg_PATH_OUT_PRIVATE,Gbl.UniqueNameEncrypted);
|
||||
Cfg_PATH_OUT_PRIVATE,Cry_GetUniqueNameEncrypted ());
|
||||
if ((*FileMail = fopen (FileNameMail,"wb")) == NULL)
|
||||
Err_ShowErrorAndExit ("Can not open file to send email.");
|
||||
}
|
||||
|
|
|
@ -223,7 +223,6 @@ static void Mrk_ChangeNumRowsHeaderOrFooter (Brw_HeadOrFoot_t HeaderOrFooter)
|
|||
/*****************************************************************************/
|
||||
// Returns true if the format of the HTML file of marks is correct
|
||||
// Returns true if the format of the HTML file of marks is wrong
|
||||
// Gbl.Alert.Txt will contain feedback text
|
||||
|
||||
bool Mrk_CheckFileOfMarks (const char *Path,struct Mrk_Properties *Marks)
|
||||
{
|
||||
|
@ -590,7 +589,7 @@ void Mrk_ShowMyMarks (void)
|
|||
|
||||
/* Create a new temporary file *****/
|
||||
snprintf (FileNameUsrMarks,sizeof (FileNameUsrMarks),"%s/%s.html",
|
||||
Cfg_PATH_MARK_PRIVATE,Gbl.UniqueNameEncrypted);
|
||||
Cfg_PATH_MARK_PRIVATE,Cry_GetUniqueNameEncrypted ());
|
||||
if ((FileUsrMarks = fopen (FileNameUsrMarks,"wb")) == NULL)
|
||||
Err_ShowErrorAndExit ("Can not open file for my marks.");
|
||||
|
||||
|
@ -720,7 +719,7 @@ void Mrk_GetNotifMyMarks (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
|
|||
|
||||
/* Create a new temporary file *****/
|
||||
snprintf (FileNameUsrMarks,sizeof (FileNameUsrMarks),"%s/%s.html",
|
||||
Cfg_PATH_MARK_PRIVATE,Gbl.UniqueNameEncrypted);
|
||||
Cfg_PATH_MARK_PRIVATE,Cry_GetUniqueNameEncrypted ());
|
||||
if ((FileUsrMarks = fopen (FileNameUsrMarks,"wb")))
|
||||
{
|
||||
/***** Get user's marks *****/
|
||||
|
|
|
@ -102,8 +102,8 @@ static void Par_GetBoundary (void);
|
|||
|
||||
static void Par_CreateListOfParamsFromQueryString (void);
|
||||
static void Par_CreateListOfParamsFromTmpFile (void);
|
||||
static int Par_ReadTmpFileUntilQuote (void);
|
||||
static int Par_ReadTmpFileUntilReturn (void);
|
||||
static int Par_ReadTmpFileUntilQuote (FILE *QueryFile);
|
||||
static int Par_ReadTmpFileUntilReturn (FILE *QueryFile);
|
||||
|
||||
static bool Par_CheckIsParamCanBeUsedInGETMethod (const char *ParamName);
|
||||
|
||||
|
@ -350,7 +350,6 @@ static void Par_CreateListOfParamsFromQueryString (void)
|
|||
/*****************************************************************************/
|
||||
/*************** Create list of parameters from temporary file ***************/
|
||||
/*****************************************************************************/
|
||||
// TODO: Rename Gbl.F.Tmp to Gbl.F.In (InFile, QueryFile)?
|
||||
|
||||
#define Par_LENGTH_OF_STR_BEFORE_PARAM 38 // Length of "Content-Disposition: form-data; name=\""
|
||||
#define Par_LENGTH_OF_STR_FILENAME 12 // Length of "; filename=\""
|
||||
|
@ -367,10 +366,11 @@ static void Par_CreateListOfParamsFromTmpFile (void)
|
|||
struct Param *NewParam;
|
||||
int Ch;
|
||||
char StrAux[Par_MAX_BYTES_STR_AUX + 1];
|
||||
FILE *QueryFile = Fil_GetQueryFile ();
|
||||
|
||||
/***** Go over the file
|
||||
getting start positions and lengths of parameters *****/
|
||||
if (Str_ReadFileUntilBoundaryStr (Gbl.F.Tmp,NULL,
|
||||
if (Str_ReadFileUntilBoundaryStr (QueryFile,NULL,
|
||||
Par_Params.Boundary.StrWithoutCRLF,
|
||||
Par_Params.Boundary.LengthWithoutCRLF,
|
||||
Fil_MAX_FILE_SIZE) == 1) // Delimiter string found
|
||||
|
@ -380,10 +380,10 @@ static void Par_CreateListOfParamsFromTmpFile (void)
|
|||
)
|
||||
{
|
||||
/***** Skip \r\n after delimiter string *****/
|
||||
if (fgetc (Gbl.F.Tmp) != 0x0D) break; // '\r'
|
||||
if (fgetc (Gbl.F.Tmp) != 0x0A) break; // '\n'
|
||||
if (fgetc (QueryFile) != 0x0D) break; // '\r'
|
||||
if (fgetc (QueryFile) != 0x0A) break; // '\n'
|
||||
|
||||
Str_GetNextStrFromFileConvertingToLower (Gbl.F.Tmp,StrAux,
|
||||
Str_GetNextStrFromFileConvertingToLower (QueryFile,StrAux,
|
||||
Par_LENGTH_OF_STR_BEFORE_PARAM);
|
||||
if (!strcasecmp (StrAux,StringBeforeParam)) // Start of a parameter
|
||||
{
|
||||
|
@ -401,49 +401,49 @@ static void Par_CreateListOfParamsFromTmpFile (void)
|
|||
Param = NewParam;
|
||||
|
||||
/***** Get parameter name *****/
|
||||
CurPos = (unsigned long) ftell (Gbl.F.Tmp); // At start of parameter name
|
||||
CurPos = (unsigned long) ftell (QueryFile); // At start of parameter name
|
||||
Param->Name.Start = CurPos;
|
||||
Ch = Par_ReadTmpFileUntilQuote ();
|
||||
CurPos = (unsigned long) ftell (Gbl.F.Tmp); // Just after quote
|
||||
Ch = Par_ReadTmpFileUntilQuote (QueryFile);
|
||||
CurPos = (unsigned long) ftell (QueryFile); // Just after quote
|
||||
Param->Name.Length = CurPos - 1 - Param->Name.Start;
|
||||
|
||||
/* Check if last character read after parameter name is a quote */
|
||||
if (Ch != (int) '\"') break; // '\"'
|
||||
|
||||
/* Get next char after parameter name */
|
||||
Ch = fgetc (Gbl.F.Tmp);
|
||||
Ch = fgetc (QueryFile);
|
||||
|
||||
/***** Check if filename is present *****/
|
||||
if (Ch == (int) StringFilename[0])
|
||||
{
|
||||
Str_GetNextStrFromFileConvertingToLower (Gbl.F.Tmp,StrAux,
|
||||
Str_GetNextStrFromFileConvertingToLower (QueryFile,StrAux,
|
||||
Par_LENGTH_OF_STR_FILENAME-1);
|
||||
if (!strcasecmp (StrAux,StringFilename + 1)) // Start of filename
|
||||
{
|
||||
/* Get filename */
|
||||
CurPos = (unsigned long) ftell (Gbl.F.Tmp); // At start of filename
|
||||
CurPos = (unsigned long) ftell (QueryFile); // At start of filename
|
||||
Param->FileName.Start = CurPos;
|
||||
Ch = Par_ReadTmpFileUntilQuote ();
|
||||
CurPos = (unsigned long) ftell (Gbl.F.Tmp); // Just after quote
|
||||
Ch = Par_ReadTmpFileUntilQuote (QueryFile);
|
||||
CurPos = (unsigned long) ftell (QueryFile); // Just after quote
|
||||
Param->FileName.Length = CurPos - 1 - Param->FileName.Start;
|
||||
|
||||
/* Check if last character read after filename is a quote */
|
||||
if (Ch != (int) '\"') break; // '\"'
|
||||
|
||||
/* Skip \r\n */
|
||||
if (fgetc (Gbl.F.Tmp) != 0x0D) break; // '\r'
|
||||
if (fgetc (Gbl.F.Tmp) != 0x0A) break; // '\n'
|
||||
if (fgetc (QueryFile) != 0x0D) break; // '\r'
|
||||
if (fgetc (QueryFile) != 0x0A) break; // '\n'
|
||||
|
||||
/* Check if Content-Type is present */
|
||||
Str_GetNextStrFromFileConvertingToLower (Gbl.F.Tmp,StrAux,
|
||||
Str_GetNextStrFromFileConvertingToLower (QueryFile,StrAux,
|
||||
Par_LENGTH_OF_STR_CONTENT_TYPE);
|
||||
if (!strcasecmp (StrAux,StringContentType)) // Start of Content-Type
|
||||
{
|
||||
/* Get content type */
|
||||
CurPos = (unsigned long) ftell (Gbl.F.Tmp); // At start of content type
|
||||
CurPos = (unsigned long) ftell (QueryFile); // At start of content type
|
||||
Param->ContentType.Start = CurPos;
|
||||
Ch = Par_ReadTmpFileUntilReturn ();
|
||||
CurPos = (unsigned long) ftell (Gbl.F.Tmp); // Just after return
|
||||
Ch = Par_ReadTmpFileUntilReturn (QueryFile);
|
||||
CurPos = (unsigned long) ftell (QueryFile); // Just after return
|
||||
Param->ContentType.Length = CurPos - 1 - Param->ContentType.Start;
|
||||
}
|
||||
}
|
||||
|
@ -454,20 +454,20 @@ static void Par_CreateListOfParamsFromTmpFile (void)
|
|||
if (Ch != 0x0D) break; // '\r'
|
||||
|
||||
/* Skip \n\r\n */
|
||||
if (fgetc (Gbl.F.Tmp) != 0x0A) break; // '\n'
|
||||
if (fgetc (Gbl.F.Tmp) != 0x0D) break; // '\r'
|
||||
if (fgetc (Gbl.F.Tmp) != 0x0A) break; // '\n'
|
||||
if (fgetc (QueryFile) != 0x0A) break; // '\n'
|
||||
if (fgetc (QueryFile) != 0x0D) break; // '\r'
|
||||
if (fgetc (QueryFile) != 0x0A) break; // '\n'
|
||||
|
||||
/***** Get parameter value or file content *****/
|
||||
CurPos = (unsigned long) ftell (Gbl.F.Tmp); // At start of value or file content
|
||||
if (Str_ReadFileUntilBoundaryStr (Gbl.F.Tmp,NULL,
|
||||
CurPos = (unsigned long) ftell (QueryFile); // At start of value or file content
|
||||
if (Str_ReadFileUntilBoundaryStr (QueryFile,NULL,
|
||||
Par_Params.Boundary.StrWithCRLF,
|
||||
Par_Params.Boundary.LengthWithCRLF,
|
||||
Fil_MAX_FILE_SIZE) != 1) break; // Boundary string not found
|
||||
|
||||
// Delimiter string found
|
||||
Param->Value.Start = CurPos;
|
||||
CurPos = (unsigned long) ftell (Gbl.F.Tmp); // Just after delimiter string
|
||||
CurPos = (unsigned long) ftell (QueryFile); // Just after delimiter string
|
||||
Param->Value.Length = CurPos - Par_Params.Boundary.LengthWithCRLF -
|
||||
Param->Value.Start;
|
||||
}
|
||||
|
@ -479,13 +479,13 @@ static void Par_CreateListOfParamsFromTmpFile (void)
|
|||
/*****************************************************************************/
|
||||
// Return last char read
|
||||
|
||||
static int Par_ReadTmpFileUntilQuote (void)
|
||||
static int Par_ReadTmpFileUntilQuote (FILE *QueryFile)
|
||||
{
|
||||
int Ch;
|
||||
|
||||
/***** Read until quote if found *****/
|
||||
do
|
||||
Ch = fgetc (Gbl.F.Tmp);
|
||||
Ch = fgetc (QueryFile);
|
||||
while (Ch != EOF && Ch != (int) '\"');
|
||||
|
||||
return Ch;
|
||||
|
@ -496,13 +496,13 @@ static int Par_ReadTmpFileUntilQuote (void)
|
|||
/*****************************************************************************/
|
||||
// Return last char read
|
||||
|
||||
static int Par_ReadTmpFileUntilReturn (void)
|
||||
static int Par_ReadTmpFileUntilReturn (FILE *QueryFile)
|
||||
{
|
||||
int Ch;
|
||||
|
||||
/***** Read until \r if found *****/
|
||||
do
|
||||
Ch = fgetc (Gbl.F.Tmp);
|
||||
Ch = fgetc (QueryFile);
|
||||
while (Ch != EOF && Ch != 0x0D); // '\r'
|
||||
|
||||
return Ch;
|
||||
|
@ -543,6 +543,7 @@ unsigned Par_GetParameter (Par_ParamType_t ParamType,const char *ParamName,
|
|||
struct Param **ParamPtr) // NULL if not used
|
||||
{
|
||||
extern const char *Par_SEPARATOR_PARAM_MULTIPLE;
|
||||
FILE *QueryFile = Fil_GetQueryFile ();
|
||||
size_t BytesAlreadyCopied = 0;
|
||||
unsigned i;
|
||||
struct Param *Param;
|
||||
|
@ -588,11 +589,11 @@ unsigned Par_GetParameter (Par_ParamType_t ParamType,const char *ParamName,
|
|||
Param->Name.Length);
|
||||
break;
|
||||
case Act_CONT_DATA:
|
||||
fseek (Gbl.F.Tmp,Param->Name.Start,SEEK_SET);
|
||||
fseek (QueryFile,Param->Name.Start,SEEK_SET);
|
||||
for (i = 0, ParamFound = true;
|
||||
i < Param->Name.Length && ParamFound;
|
||||
i++)
|
||||
if (ParamName[i] != (char) fgetc (Gbl.F.Tmp))
|
||||
if (ParamName[i] != (char) fgetc (QueryFile))
|
||||
ParamFound = false;
|
||||
break;
|
||||
}
|
||||
|
@ -654,8 +655,8 @@ unsigned Par_GetParameter (Par_ParamType_t ParamType,const char *ParamName,
|
|||
if (Param->FileName.Start == 0 && // Copy into destination only if it's not a file
|
||||
PtrDst)
|
||||
{
|
||||
fseek (Gbl.F.Tmp,Param->Value.Start,SEEK_SET);
|
||||
if (fread (PtrDst,sizeof (char),Param->Value.Length,Gbl.F.Tmp) !=
|
||||
fseek (QueryFile,Param->Value.Start,SEEK_SET);
|
||||
if (fread (PtrDst,sizeof (char),Param->Value.Length,QueryFile) !=
|
||||
Param->Value.Length)
|
||||
Err_ShowErrorAndExit ("Error while getting value of parameter.");
|
||||
}
|
||||
|
|
16
swad_photo.c
16
swad_photo.c
|
@ -572,6 +572,7 @@ static bool Pho_ReceivePhotoAndDetectFaces (bool ItsMe,const struct Usr_Data *Us
|
|||
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
|
||||
const char *UniqueNameEncrypted = Cry_GetUniqueNameEncrypted ();
|
||||
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];
|
||||
|
@ -620,7 +621,7 @@ static bool Pho_ReceivePhotoAndDetectFaces (bool ItsMe,const struct Usr_Data *Us
|
|||
/* Create temporary directory for photos */
|
||||
Fil_CreateDirIfNotExists (Cfg_PATH_PHOTO_TMP_PUBLIC);
|
||||
|
||||
/***** First of all, copy in disk the file received from stdin (really from Gbl.F.Tmp) *****/
|
||||
/***** First of all, copy in disk the file received *****/
|
||||
Param = Fil_StartReceptionOfFile (Fil_NAME_OF_PARAM_FILENAME_ORG,
|
||||
FileNamePhotoSrc,MIMEType);
|
||||
|
||||
|
@ -640,7 +641,7 @@ static bool Pho_ReceivePhotoAndDetectFaces (bool ItsMe,const struct Usr_Data *Us
|
|||
|
||||
/* End the reception of photo in a temporary file */
|
||||
snprintf (FileNamePhotoTmp,sizeof (FileNamePhotoTmp),"%s/%s.jpg",
|
||||
Cfg_PATH_PHOTO_TMP_PUBLIC,Gbl.UniqueNameEncrypted);
|
||||
Cfg_PATH_PHOTO_TMP_PUBLIC,UniqueNameEncrypted);
|
||||
if (!Fil_EndReceptionOfFile (FileNamePhotoTmp,Param))
|
||||
{
|
||||
Ale_ShowAlert (Ale_ERROR,"Error copying file.");
|
||||
|
@ -669,7 +670,7 @@ static bool Pho_ReceivePhotoAndDetectFaces (bool ItsMe,const struct Usr_Data *Us
|
|||
case 0: // Faces detected
|
||||
/***** Open text file with text for image map *****/
|
||||
snprintf (FileNameTxtMap,sizeof (FileNameTxtMap),"%s/%s_map.txt",
|
||||
Cfg_PATH_PHOTO_TMP_PUBLIC,Gbl.UniqueNameEncrypted);
|
||||
Cfg_PATH_PHOTO_TMP_PUBLIC,UniqueNameEncrypted);
|
||||
if ((FileTxtMap = fopen (FileNameTxtMap,"rb")) == NULL)
|
||||
Err_ShowErrorAndExit ("Can not read text file with coordinates of detected faces.");
|
||||
|
||||
|
@ -765,9 +766,9 @@ static bool Pho_ReceivePhotoAndDetectFaces (bool ItsMe,const struct Usr_Data *Us
|
|||
|
||||
/***** Show map photo *****/
|
||||
snprintf (FileNamePhotoMap,sizeof (FileNamePhotoMap),"%s/%s_map.jpg",
|
||||
Cfg_PATH_PHOTO_TMP_PUBLIC,Gbl.UniqueNameEncrypted);
|
||||
Cfg_PATH_PHOTO_TMP_PUBLIC,UniqueNameEncrypted);
|
||||
HTM_DIV_Begin ("class=\"TIT CM\"");
|
||||
if (asprintf (&Icon,"%s_map.jpg",Gbl.UniqueNameEncrypted) < 0)
|
||||
if (asprintf (&Icon,"%s_map.jpg",UniqueNameEncrypted) < 0)
|
||||
Err_NotEnoughMemoryExit ();
|
||||
HTM_IMG (Cfg_URL_PHOTO_TMP_PUBLIC,Icon,Txt_Faces_detected,"usemap=\"#faces_map\"");
|
||||
free (Icon);
|
||||
|
@ -1350,9 +1351,10 @@ bool Pho_RemovePhoto (struct Usr_Data *UsrDat)
|
|||
void Pho_UpdatePhotoName (struct Usr_Data *UsrDat)
|
||||
{
|
||||
char PathPublPhoto[PATH_MAX + 1];
|
||||
const char *UniqueNameEncrypted = Cry_GetUniqueNameEncrypted ();
|
||||
|
||||
/***** Update photo name in database *****/
|
||||
Pho_DB_UpdatePhotoName (UsrDat->UsrCod,Gbl.UniqueNameEncrypted);
|
||||
Pho_DB_UpdatePhotoName (UsrDat->UsrCod,UniqueNameEncrypted);
|
||||
|
||||
/***** Remove the old symbolic link to photo *****/
|
||||
snprintf (PathPublPhoto,sizeof (PathPublPhoto),"%s/%s.jpg",
|
||||
|
@ -1360,7 +1362,7 @@ void Pho_UpdatePhotoName (struct Usr_Data *UsrDat)
|
|||
unlink (PathPublPhoto); // Remove public link
|
||||
|
||||
/***** Update photo name in user's data *****/
|
||||
Str_Copy (UsrDat->Photo,Gbl.UniqueNameEncrypted,sizeof (UsrDat->Photo) - 1);
|
||||
Str_Copy (UsrDat->Photo,UniqueNameEncrypted,sizeof (UsrDat->Photo) - 1);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
@ -382,7 +382,7 @@ void QstImp_ImpQstsFromXML (void)
|
|||
/***** Creates directory if not exists *****/
|
||||
Fil_CreateDirIfNotExists (Cfg_PATH_TEST_PRIVATE);
|
||||
|
||||
/***** First of all, copy in disk the file received from stdin (really from Gbl.F.Tmp) *****/
|
||||
/***** First of all, copy in disk the file received *****/
|
||||
Param = Fil_StartReceptionOfFile (Fil_NAME_OF_PARAM_FILENAME_ORG,
|
||||
FileNameXMLSrc,MIMEType);
|
||||
|
||||
|
@ -401,7 +401,7 @@ void QstImp_ImpQstsFromXML (void)
|
|||
{
|
||||
/* End the reception of XML in a temporary file */
|
||||
snprintf (FileNameXMLTmp,sizeof (FileNameXMLTmp),"%s/%s.xml",
|
||||
Cfg_PATH_TEST_PRIVATE,Gbl.UniqueNameEncrypted);
|
||||
Cfg_PATH_TEST_PRIVATE,Cry_GetUniqueNameEncrypted ());
|
||||
if (Fil_EndReceptionOfFile (FileNameXMLTmp,Param))
|
||||
/***** Get questions from XML file and store them in database *****/
|
||||
QstImp_ReadQuestionsFromXMLFileAndStoreInDB (FileNameXMLTmp);
|
||||
|
|
|
@ -173,7 +173,7 @@ static void Rep_CreateMyUsageReport (struct Rep_Report *Report)
|
|||
|
||||
/***** Store report entry into database *****/
|
||||
Rep_DB_CreateNewReport (Gbl.Usrs.Me.UsrDat.UsrCod,Report,
|
||||
Gbl.UniqueNameEncrypted);
|
||||
Cry_GetUniqueNameEncrypted ());
|
||||
|
||||
/***** Begin file *****/
|
||||
Lay_BeginHTMLFile (Gbl.F.Rep,Report->FilenameReport);
|
||||
|
@ -344,6 +344,7 @@ static void Rep_CreateNewReportFile (struct Rep_Report *Report)
|
|||
char PathUniqueDirL[PATH_MAX + 1];
|
||||
char PathUniqueDirR[PATH_MAX + 1 + Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64 + 1];
|
||||
char PathFileReport[PATH_MAX + 1 + Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64 + 1 + NAME_MAX + 1];
|
||||
const char *UniqueNameEncrypted = Cry_GetUniqueNameEncrypted ();
|
||||
char Permalink[128 +
|
||||
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64 +
|
||||
NAME_MAX];
|
||||
|
@ -355,14 +356,14 @@ static void Rep_CreateNewReportFile (struct Rep_Report *Report)
|
|||
/* 1. Create a directory using the leftmost 2 chars of a unique name */
|
||||
snprintf (PathUniqueDirL,sizeof (PathUniqueDirL),"%s/%c%c",
|
||||
Cfg_PATH_REP_PUBLIC,
|
||||
Gbl.UniqueNameEncrypted[0],
|
||||
Gbl.UniqueNameEncrypted[1]);
|
||||
UniqueNameEncrypted[0],
|
||||
UniqueNameEncrypted[1]);
|
||||
Fil_CreateDirIfNotExists (PathUniqueDirL);
|
||||
|
||||
/* 2. Create a directory using the rightmost 41 chars of a unique name */
|
||||
snprintf (PathUniqueDirR,sizeof (PathUniqueDirR),"%s/%s",
|
||||
PathUniqueDirL,
|
||||
&Gbl.UniqueNameEncrypted[2]);
|
||||
&UniqueNameEncrypted[2]);
|
||||
if (mkdir (PathUniqueDirR,(mode_t) 0xFFF))
|
||||
Err_ShowErrorAndExit ("Can not create directory for report.");
|
||||
|
||||
|
@ -378,9 +379,9 @@ static void Rep_CreateNewReportFile (struct Rep_Report *Report)
|
|||
/***** Permalink *****/
|
||||
snprintf (Permalink,sizeof (Permalink),"%s/%c%c/%s/%s",
|
||||
Cfg_URL_REP_PUBLIC,
|
||||
Gbl.UniqueNameEncrypted[0],
|
||||
Gbl.UniqueNameEncrypted[1],
|
||||
&Gbl.UniqueNameEncrypted[2],
|
||||
UniqueNameEncrypted[0],
|
||||
UniqueNameEncrypted[1],
|
||||
&UniqueNameEncrypted[2],
|
||||
Report->FilenameReport);
|
||||
Str_Copy (Report->Permalink,Permalink,sizeof (Report->Permalink) - 1);
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ void Ses_GetNumSessions (void)
|
|||
void Ses_CreateSession (void)
|
||||
{
|
||||
/***** Create a unique name for the session *****/
|
||||
Str_Copy (Gbl.Session.Id,Gbl.UniqueNameEncrypted,sizeof (Gbl.Session.Id) - 1);
|
||||
Str_Copy (Gbl.Session.Id,Cry_GetUniqueNameEncrypted (),sizeof (Gbl.Session.Id) - 1);
|
||||
|
||||
/***** Check that session is not open *****/
|
||||
if (Ses_DB_CheckIfSessionExists (Gbl.Session.Id))
|
||||
|
|
|
@ -670,7 +670,7 @@ static void TmlCom_WriteButtons (const struct Tml_Timeline *Timeline,
|
|||
|
||||
/***** Foot column 1: fav zone *****/
|
||||
HTM_DIV_Begin ("id=\"fav_com_%s_%u\" class=\"Tml_FAV_COM Tml_FAV_WIDTH\"",
|
||||
Gbl.UniqueNameEncrypted,NumDiv);
|
||||
Cry_GetUniqueNameEncrypted (),NumDiv);
|
||||
TmlUsr_PutIconFavSha (TmlUsr_FAV_UNF_COMM,
|
||||
Com->PubCod,Com->UsrCod,Com->NumFavs,
|
||||
TmlUsr_SHOW_FEW_USRS);
|
||||
|
|
|
@ -818,6 +818,7 @@ static void TmlNot_WriteFavShaRem (const struct Tml_Timeline *Timeline,
|
|||
const struct Usr_Data *UsrDat) // Author
|
||||
{
|
||||
static unsigned NumDiv = 0; // Used to create unique div id for fav and shared
|
||||
const char *UniqueNameEncrypted = Cry_GetUniqueNameEncrypted ();
|
||||
|
||||
NumDiv++;
|
||||
|
||||
|
@ -827,7 +828,7 @@ static void TmlNot_WriteFavShaRem (const struct Tml_Timeline *Timeline,
|
|||
/***** Foot column 1: fav zone *****/
|
||||
HTM_DIV_Begin ("id=\"fav_not_%s_%u\""
|
||||
" class=\"Tml_FAV_NOT Tml_FAV_NOT_WIDTH\"",
|
||||
Gbl.UniqueNameEncrypted,NumDiv);
|
||||
UniqueNameEncrypted,NumDiv);
|
||||
TmlUsr_PutIconFavSha (TmlUsr_FAV_UNF_NOTE,
|
||||
Not->NotCod,Not->UsrCod,Not->NumFavs,
|
||||
TmlUsr_SHOW_FEW_USRS);
|
||||
|
@ -836,7 +837,7 @@ static void TmlNot_WriteFavShaRem (const struct Tml_Timeline *Timeline,
|
|||
/***** Foot column 2: share zone *****/
|
||||
HTM_DIV_Begin ("id=\"sha_not_%s_%u\""
|
||||
" class=\"Tml_SHA_NOT Tml_SHA_NOT_WIDTH\"",
|
||||
Gbl.UniqueNameEncrypted,NumDiv);
|
||||
UniqueNameEncrypted,NumDiv);
|
||||
TmlUsr_PutIconFavSha (TmlUsr_SHA_UNS_NOTE,
|
||||
Not->NotCod,Not->UsrCod,Not->NumShared,
|
||||
TmlUsr_SHOW_FEW_USRS);
|
||||
|
|
|
@ -2947,15 +2947,6 @@ void Usr_CopyBasicUsrDataFromList (struct Usr_Data *UsrDat,
|
|||
|
||||
static void Usr_AllocateUsrsList (Rol_Role_t Role)
|
||||
{
|
||||
/*
|
||||
if (Gbl.Usrs.Me.Roles.LoggedRole == Rol_SYS_ADM)
|
||||
{
|
||||
snprintf (Gbl.Alert.Txt,sizeof (Gbl.Alert.Txt),
|
||||
"Memory used by list = %lu",
|
||||
(long) sizeof (struct UsrInList) * NumUsrs);
|
||||
Lay_ShowAlert (Lay_INFO,Gbl.Alert.Txt);
|
||||
}
|
||||
*/
|
||||
if (Gbl.Usrs.LstUsrs[Role].NumUsrs)
|
||||
if ((Gbl.Usrs.LstUsrs[Role].Lst = calloc (Gbl.Usrs.LstUsrs[Role].NumUsrs,
|
||||
sizeof (*Gbl.Usrs.LstUsrs[Role].Lst))) == NULL)
|
||||
|
|
|
@ -225,7 +225,7 @@ static void ZIP_CreateTmpDirForCompression (void)
|
|||
Fil_CreateDirIfNotExists (Cfg_PATH_ZIP_PRIVATE);
|
||||
|
||||
/***** Create a new temporary directory *****/
|
||||
Str_Copy (Gbl.FileBrowser.ZIP.TmpDir,Gbl.UniqueNameEncrypted,
|
||||
Str_Copy (Gbl.FileBrowser.ZIP.TmpDir,Cry_GetUniqueNameEncrypted (),
|
||||
sizeof (Gbl.FileBrowser.ZIP.TmpDir) - 1);
|
||||
snprintf (PathDirTmp,sizeof (PathDirTmp),"%s/%s",
|
||||
Cfg_PATH_ZIP_PRIVATE,Gbl.FileBrowser.ZIP.TmpDir);
|
||||
|
|
Loading…
Reference in New Issue