mirror of
https://github.com/acanas/swad-core.git
synced 2024-06-01 06:15:31 +02:00
Version 15.170
This commit is contained in:
parent
7e0ac827ea
commit
0f315d2f6f
|
@ -2054,6 +2054,7 @@ void Ctr_ReceivePhoto (void)
|
||||||
{
|
{
|
||||||
extern const char *Txt_Wrong_file_type;
|
extern const char *Txt_Wrong_file_type;
|
||||||
char Path[PATH_MAX+1];
|
char Path[PATH_MAX+1];
|
||||||
|
struct Param *Param;
|
||||||
char FileNameImgSrc[PATH_MAX+1];
|
char FileNameImgSrc[PATH_MAX+1];
|
||||||
char *PtrExtension;
|
char *PtrExtension;
|
||||||
size_t LengthExtension;
|
size_t LengthExtension;
|
||||||
|
@ -2066,7 +2067,7 @@ void Ctr_ReceivePhoto (void)
|
||||||
int ReturnCode;
|
int ReturnCode;
|
||||||
|
|
||||||
/***** Copy in disk the file received from stdin (really from Gbl.F.Tmp) *****/
|
/***** Copy in disk the file received from stdin (really from Gbl.F.Tmp) *****/
|
||||||
Fil_StartReceptionOfFile (FileNameImgSrc,MIMEType);
|
Param = Fil_StartReceptionOfFile (FileNameImgSrc,MIMEType);
|
||||||
|
|
||||||
/* Check if the file type is image/ or application/octet-stream */
|
/* Check if the file type is image/ or application/octet-stream */
|
||||||
if (strncmp (MIMEType,"image/",strlen ("image/")))
|
if (strncmp (MIMEType,"image/",strlen ("image/")))
|
||||||
|
@ -2109,9 +2110,9 @@ void Ctr_ReceivePhoto (void)
|
||||||
sprintf (FileNameImgTmp,"%s/%s/%s/%s.%s",
|
sprintf (FileNameImgTmp,"%s/%s/%s/%s.%s",
|
||||||
Cfg_PATH_SWAD_PRIVATE,Cfg_FOLDER_IMG,Cfg_FOLDER_IMG_TMP,
|
Cfg_PATH_SWAD_PRIVATE,Cfg_FOLDER_IMG,Cfg_FOLDER_IMG_TMP,
|
||||||
Gbl.UniqueNameEncrypted,PtrExtension);
|
Gbl.UniqueNameEncrypted,PtrExtension);
|
||||||
if (!Fil_EndReceptionOfFile (FileNameImgTmp))
|
if (!Fil_EndReceptionOfFile (FileNameImgTmp,Param))
|
||||||
{
|
{
|
||||||
Lay_ShowAlert (Lay_WARNING,"Error uploading file.");
|
Lay_ShowAlert (Lay_WARNING,"Error copying file.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -138,13 +138,14 @@
|
||||||
/****************************** Public constants *****************************/
|
/****************************** Public constants *****************************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
#define Log_PLATFORM_VERSION "SWAD 15.169.6 (2016-03-31)"
|
#define Log_PLATFORM_VERSION "SWAD 15.170 (2016-04-01)"
|
||||||
#define CSS_FILE "swad15.165.5.css"
|
#define CSS_FILE "swad15.165.5.css"
|
||||||
#define JS_FILE "swad15.131.3.js"
|
#define JS_FILE "swad15.131.3.js"
|
||||||
|
|
||||||
// Number of lines (includes comments but not blank lines) has been got with the following command:
|
// Number of lines (includes comments but not blank lines) has been got with the following command:
|
||||||
// nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*.h sql/swad*.sql | tail -1
|
// nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*.h sql/swad*.sql | tail -1
|
||||||
/*
|
/*
|
||||||
|
Version 15.170: Apr 01, 2016 Code refactoring in function to receive file. (197310 lines)
|
||||||
Version 15.169.6: Mar 31, 2016 Code refactoring in function to get a parameter. (197313 lines)
|
Version 15.169.6: Mar 31, 2016 Code refactoring in function to get a parameter. (197313 lines)
|
||||||
Version 15.169.5: Mar 31, 2016 Code refactoring in function to get a parameter. (197292 lines)
|
Version 15.169.5: Mar 31, 2016 Code refactoring in function to get a parameter. (197292 lines)
|
||||||
Version 15.169.4: Mar 31, 2016 Code refactoring in list of parameters. (197280 lines)
|
Version 15.169.4: Mar 31, 2016 Code refactoring in list of parameters. (197280 lines)
|
||||||
|
|
112
swad_file.c
112
swad_file.c
|
@ -54,6 +54,8 @@ extern struct Globals Gbl;
|
||||||
/***************************** Private constants *****************************/
|
/***************************** Private constants *****************************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
#define NUM_BYTES_PER_CHUNK 4096
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/******************************* Private types *******************************/
|
/******************************* Private types *******************************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -233,85 +235,75 @@ Content-Type: image/pjpeg
|
||||||
000020 03030304 03030405 08050504 04050A07 ················
|
000020 03030304 03030405 08050504 04050A07 ················
|
||||||
etc, etc.
|
etc, etc.
|
||||||
*/
|
*/
|
||||||
void Fil_StartReceptionOfFile (char *SrcFileName,char *MIMEType)
|
struct Param *Fil_StartReceptionOfFile (char *FileName,char *MIMEType)
|
||||||
{
|
{
|
||||||
char *Ptr;
|
|
||||||
int Ch;
|
|
||||||
int i;
|
|
||||||
/*
|
|
||||||
struct Param *Param;
|
struct Param *Param;
|
||||||
Par_GetParameter (Par_PARAM_SINGLE,Fil_NAME_OF_PARAM_FILENAME_ORG,SrcFileName,
|
|
||||||
PATH_MAX,Param);
|
|
||||||
*/
|
|
||||||
/* At this point, a heading has been read from Gbl.F.Tmp
|
|
||||||
with all the variables passed by form */
|
|
||||||
rewind (Gbl.F.Tmp);
|
|
||||||
if (!Str_FindStrInFile (Gbl.F.Tmp,Fil_NAME_OF_PARAM_FILENAME_ORG,Str_NO_SKIP_HTML_COMMENTS))
|
|
||||||
{
|
|
||||||
sprintf (Gbl.Message,"Error uploading file: parameter <strong>%s</strong> not found.",
|
|
||||||
Fil_NAME_OF_PARAM_FILENAME_ORG);
|
|
||||||
Lay_ShowErrorAndExit (Gbl.Message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Go to the name of the source file */
|
/***** Get filename *****/
|
||||||
if (!Str_FindStrInFile (Gbl.F.Tmp,"filename=\"",Str_NO_SKIP_HTML_COMMENTS))
|
Par_GetParameter (Par_PARAM_SINGLE,Fil_NAME_OF_PARAM_FILENAME_ORG,FileName,
|
||||||
Lay_ShowErrorAndExit ("Error uploading file: parameter "filename" not found.");
|
PATH_MAX,&Param);
|
||||||
|
|
||||||
/* Get the name of the source file */
|
/***** Get MIME type *****/
|
||||||
Ptr = SrcFileName;
|
/* Check if MIME type exists */
|
||||||
while ((Ch = fgetc (Gbl.F.Tmp)) != (int) '\"')
|
if (Param->ContentType.Start == 0 ||
|
||||||
*Ptr++ = Ch;
|
Param->ContentType.Length == 0 ||
|
||||||
*Ptr = '\0';
|
Param->ContentType.Length > Brw_MAX_BYTES_MIME_TYPE)
|
||||||
|
Lay_ShowErrorAndExit ("Error while getting content type.");
|
||||||
|
|
||||||
/* Get and check the type of data */
|
/* Copy MIME type */
|
||||||
if (!Str_FindStrInFile (Gbl.F.Tmp,"Content-Type:",Str_NO_SKIP_HTML_COMMENTS))
|
fseek (Gbl.F.Tmp,Param->ContentType.Start,SEEK_SET);
|
||||||
Lay_ShowErrorAndExit ("Error uploading file: "Content-Type" not found.");
|
if (fread (MIMEType,sizeof (char),Param->ContentType.Length,Gbl.F.Tmp) !=
|
||||||
|
Param->ContentType.Length)
|
||||||
|
Lay_ShowErrorAndExit ("Error while getting content type.");
|
||||||
|
|
||||||
/* Skip spaces and get the type of file */
|
return Param;
|
||||||
while (isspace (Ch = fgetc (Gbl.F.Tmp)));
|
|
||||||
for (i=0, Ptr = MIMEType;
|
|
||||||
!isspace (Ch) && i < Brw_MAX_BYTES_MIME_TYPE;
|
|
||||||
i++)
|
|
||||||
{
|
|
||||||
*Ptr++ = Str_ConvertToLowerLetter ((char) Ch);
|
|
||||||
Ch = fgetc (Gbl.F.Tmp);
|
|
||||||
}
|
|
||||||
*Ptr = '\0';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/****************** End the reception of data of a file **********************/
|
/****************** End the reception of data of a file **********************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
bool Fil_EndReceptionOfFile (char *FileNameDataTmp)
|
bool Fil_EndReceptionOfFile (char *FileNameDataTmp,struct Param *Param)
|
||||||
{
|
{
|
||||||
extern const char *Txt_UPLOAD_FILE_File_too_large_maximum_X_MiB_NO_HTML;
|
extern const char *Txt_UPLOAD_FILE_File_too_large_maximum_X_MiB_NO_HTML;
|
||||||
FILE *FileDataTmp;
|
FILE *FileDataTmp;
|
||||||
int Result; // Result of the reception of the file
|
unsigned char Bytes[NUM_BYTES_PER_CHUNK];
|
||||||
|
size_t RemainingBytesToCopy;
|
||||||
|
size_t BytesToCopy;
|
||||||
|
|
||||||
/***** Open a new file temporary *****/
|
/***** Open destination file *****/
|
||||||
if ((FileDataTmp = fopen (FileNameDataTmp,"wb")) == NULL)
|
if ((FileDataTmp = fopen (FileNameDataTmp,"wb")) == NULL)
|
||||||
Lay_ShowErrorAndExit ("Can not open temporary file.");
|
Lay_ShowErrorAndExit ("Can not open temporary file.");
|
||||||
|
|
||||||
/***** Skip carriage returns, spaces, etc. *****/
|
/***** Copy file *****/
|
||||||
Str_SkipSpacesInFile (Gbl.F.Tmp);
|
/* Go to start of source */
|
||||||
|
if (Param->Value.Start == 0)
|
||||||
|
Lay_ShowErrorAndExit ("Error while copying file.");
|
||||||
|
fseek (Gbl.F.Tmp,Param->Value.Start,SEEK_SET);
|
||||||
|
|
||||||
/* At this point, the data of the file begin */
|
/* Copy part of Gbl.F.Tmp to FileDataTmp */
|
||||||
|
for (RemainingBytesToCopy = Param->Value.Length;
|
||||||
/***** Write the file *****/
|
RemainingBytesToCopy != 0;
|
||||||
Result = Str_ReceiveFileUntilDelimitStr (Gbl.F.Tmp,FileDataTmp,(char *) NULL,
|
RemainingBytesToCopy -= BytesToCopy)
|
||||||
Gbl.Boundary.StrWithCRLF,
|
|
||||||
Fil_MAX_FILE_SIZE);
|
|
||||||
fclose (FileDataTmp);
|
|
||||||
if (Result != 1)
|
|
||||||
/* 0 ==> File too large; -1 ==> Unfinished transmission */
|
|
||||||
{
|
{
|
||||||
unlink (FileNameDataTmp);
|
BytesToCopy = (RemainingBytesToCopy >= NUM_BYTES_PER_CHUNK) ? NUM_BYTES_PER_CHUNK :
|
||||||
sprintf (Gbl.Message,Txt_UPLOAD_FILE_File_too_large_maximum_X_MiB_NO_HTML,
|
RemainingBytesToCopy;
|
||||||
(unsigned long) (Fil_MAX_FILE_SIZE / (1024ULL * 1024ULL)));
|
if (fread ((void *) Bytes,1,BytesToCopy,Gbl.F.Tmp) != BytesToCopy)
|
||||||
return false; // Error
|
{
|
||||||
|
fclose (FileDataTmp);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (fwrite ((void *) Bytes,sizeof (Bytes[0]),BytesToCopy,FileDataTmp) != BytesToCopy)
|
||||||
|
{
|
||||||
|
fclose (FileDataTmp);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true; // Success
|
|
||||||
|
/***** Close destination file *****/
|
||||||
|
fclose (FileDataTmp);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
@ -503,14 +495,12 @@ void Fil_FastCopyOfFiles (const char *PathSrc,const char *PathTgt)
|
||||||
/************************* Fast copy of open files ***************************/
|
/************************* Fast copy of open files ***************************/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
#define NUM_BYTES_PER_COPY 4096
|
|
||||||
|
|
||||||
void Fil_FastCopyOfOpenFiles (FILE *FileSrc,FILE *FileTgt)
|
void Fil_FastCopyOfOpenFiles (FILE *FileSrc,FILE *FileTgt)
|
||||||
{
|
{
|
||||||
unsigned char Bytes[NUM_BYTES_PER_COPY];
|
unsigned char Bytes[NUM_BYTES_PER_CHUNK];
|
||||||
size_t NumBytesRead;
|
size_t NumBytesRead;
|
||||||
|
|
||||||
while ((NumBytesRead = fread ((void *) Bytes,sizeof (Bytes[0]),(size_t) NUM_BYTES_PER_COPY,FileSrc)))
|
while ((NumBytesRead = fread ((void *) Bytes,sizeof (Bytes[0]),(size_t) NUM_BYTES_PER_CHUNK,FileSrc)))
|
||||||
fwrite ((void *) Bytes,sizeof (Bytes[0]),NumBytesRead,FileTgt);
|
fwrite ((void *) Bytes,sizeof (Bytes[0]),NumBytesRead,FileTgt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,8 +59,8 @@ void Fil_CreateFileForHTMLOutput (void);
|
||||||
void Fil_CloseAndRemoveFileForHTMLOutput (void);
|
void Fil_CloseAndRemoveFileForHTMLOutput (void);
|
||||||
bool Fil_ReadStdinIntoTmpFile (void);
|
bool Fil_ReadStdinIntoTmpFile (void);
|
||||||
void Fil_EndOfReadingStdin (void);
|
void Fil_EndOfReadingStdin (void);
|
||||||
void Fil_StartReceptionOfFile (char *SrcFileName,char *MIMEType);
|
struct Param *Fil_StartReceptionOfFile (char *FileName,char *MIMEType);
|
||||||
bool Fil_EndReceptionOfFile (char *FileNameDataTmp);
|
bool Fil_EndReceptionOfFile (char *FileNameDataTmp,struct Param *Param);
|
||||||
void Fil_CreateUpdateFile (const char *CurrentName,const char *ExtensionOldName,char *OldName,char *NewName,FILE **NewFile);
|
void Fil_CreateUpdateFile (const char *CurrentName,const char *ExtensionOldName,char *OldName,char *NewName,FILE **NewFile);
|
||||||
void Fil_CloseUpdateFile (const char *CurrentName,const char *OldName,const char *NewName,FILE *NewFile);
|
void Fil_CloseUpdateFile (const char *CurrentName,const char *OldName,const char *NewName,FILE *NewFile);
|
||||||
bool Fil_RenameFileOrDir (const char *PathOld,const char *PathNew);
|
bool Fil_RenameFileOrDir (const char *PathOld,const char *PathNew);
|
||||||
|
|
|
@ -8380,6 +8380,7 @@ static bool Brw_RcvFileInFileBrw (Brw_UploadType_t UploadType)
|
||||||
extern const char *Txt_The_file_X_has_been_placed_inside_the_folder_Y;
|
extern const char *Txt_The_file_X_has_been_placed_inside_the_folder_Y;
|
||||||
extern const char *Txt_UPLOAD_FILE_You_must_specify_the_file_NO_HTML;
|
extern const char *Txt_UPLOAD_FILE_You_must_specify_the_file_NO_HTML;
|
||||||
extern const char *Txt_UPLOAD_FILE_Forbidden_NO_HTML;
|
extern const char *Txt_UPLOAD_FILE_Forbidden_NO_HTML;
|
||||||
|
struct Param *Param;
|
||||||
char SrcFileName[PATH_MAX+1];
|
char SrcFileName[PATH_MAX+1];
|
||||||
char PathUntilFileName[PATH_MAX+1];
|
char PathUntilFileName[PATH_MAX+1];
|
||||||
char Path[PATH_MAX+1];
|
char Path[PATH_MAX+1];
|
||||||
|
@ -8404,7 +8405,7 @@ static bool Brw_RcvFileInFileBrw (Brw_UploadType_t UploadType)
|
||||||
if (Brw_CheckIfICanCreateIntoFolder (Gbl.FileBrowser.Level))
|
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 from stdin (really from Gbl.F.Tmp) *****/
|
||||||
Fil_StartReceptionOfFile (SrcFileName,MIMEType);
|
Param = Fil_StartReceptionOfFile (SrcFileName,MIMEType);
|
||||||
|
|
||||||
/***** Get filename from path *****/
|
/***** Get filename from path *****/
|
||||||
// Spaces at start or end are allowed
|
// Spaces at start or end are allowed
|
||||||
|
@ -8437,7 +8438,7 @@ static bool Brw_RcvFileInFileBrw (Brw_UploadType_t UploadType)
|
||||||
{
|
{
|
||||||
/* End receiving the file */
|
/* End receiving the file */
|
||||||
sprintf (PathTmp,"%s.tmp",Path);
|
sprintf (PathTmp,"%s.tmp",Path);
|
||||||
FileIsValid = Fil_EndReceptionOfFile (PathTmp); // Gbl.Message contains feedback text
|
FileIsValid = Fil_EndReceptionOfFile (PathTmp,Param); // Gbl.Message contains feedback text
|
||||||
|
|
||||||
/* Check if the content of the file of marks is valid */
|
/* Check if the content of the file of marks is valid */
|
||||||
if (FileIsValid)
|
if (FileIsValid)
|
||||||
|
|
|
@ -2008,6 +2008,7 @@ void Inf_ReceivePagInfo (void)
|
||||||
extern const char *Txt_Found_an_index_htm_file;
|
extern const char *Txt_Found_an_index_htm_file;
|
||||||
extern const char *Txt_No_file_index_html_index_htm_found_within_the_ZIP_file;
|
extern const char *Txt_No_file_index_html_index_htm_found_within_the_ZIP_file;
|
||||||
extern const char *Txt_The_file_type_should_be_HTML_or_ZIP;
|
extern const char *Txt_The_file_type_should_be_HTML_or_ZIP;
|
||||||
|
struct Param *Param;
|
||||||
char SourceFileName[PATH_MAX+1];
|
char SourceFileName[PATH_MAX+1];
|
||||||
char PathRelFileHTML[PATH_MAX+1];
|
char PathRelFileHTML[PATH_MAX+1];
|
||||||
char MIMEType[Brw_MAX_BYTES_MIME_TYPE+1];
|
char MIMEType[Brw_MAX_BYTES_MIME_TYPE+1];
|
||||||
|
@ -2020,7 +2021,7 @@ void Inf_ReceivePagInfo (void)
|
||||||
Gbl.CurrentCrs.Info.Type = Inf_AsignInfoType ();
|
Gbl.CurrentCrs.Info.Type = Inf_AsignInfoType ();
|
||||||
|
|
||||||
/***** First of all, store in disk the file from stdin (really from Gbl.F.Tmp) *****/
|
/***** First of all, store in disk the file from stdin (really from Gbl.F.Tmp) *****/
|
||||||
Fil_StartReceptionOfFile (SourceFileName,MIMEType);
|
Param = Fil_StartReceptionOfFile (SourceFileName,MIMEType);
|
||||||
|
|
||||||
/***** Check that MIME type is HTML or ZIP *****/
|
/***** Check that MIME type is HTML or ZIP *****/
|
||||||
if (strcmp (MIMEType,"text/html"))
|
if (strcmp (MIMEType,"text/html"))
|
||||||
|
@ -2048,7 +2049,7 @@ void Inf_ReceivePagInfo (void)
|
||||||
Brw_RemoveTree (PathWebPage);
|
Brw_RemoveTree (PathWebPage);
|
||||||
Fil_CreateDirIfNotExists (PathWebPage);
|
Fil_CreateDirIfNotExists (PathWebPage);
|
||||||
sprintf (PathRelFileHTML,"%s/index.html",PathWebPage);
|
sprintf (PathRelFileHTML,"%s/index.html",PathWebPage);
|
||||||
if (Fil_EndReceptionOfFile (PathRelFileHTML))
|
if (Fil_EndReceptionOfFile (PathRelFileHTML,Param))
|
||||||
{
|
{
|
||||||
Lay_ShowAlert (Lay_SUCCESS,Txt_The_HTML_file_has_been_received_successfully);
|
Lay_ShowAlert (Lay_SUCCESS,Txt_The_HTML_file_has_been_received_successfully);
|
||||||
FileIsOK = true;
|
FileIsOK = true;
|
||||||
|
@ -2060,7 +2061,7 @@ void Inf_ReceivePagInfo (void)
|
||||||
{
|
{
|
||||||
Brw_RemoveTree (PathWebPage);
|
Brw_RemoveTree (PathWebPage);
|
||||||
Fil_CreateDirIfNotExists (PathWebPage);
|
Fil_CreateDirIfNotExists (PathWebPage);
|
||||||
if (Fil_EndReceptionOfFile (Gbl.CurrentCrs.Info.Links[Gbl.CurrentCrs.Info.Type].PathRelFileZIP))
|
if (Fil_EndReceptionOfFile (Gbl.CurrentCrs.Info.Links[Gbl.CurrentCrs.Info.Type].PathRelFileZIP,Param))
|
||||||
{
|
{
|
||||||
Lay_ShowAlert (Lay_SUCCESS,Txt_The_ZIP_file_has_been_received_successfully);
|
Lay_ShowAlert (Lay_SUCCESS,Txt_The_ZIP_file_has_been_received_successfully);
|
||||||
|
|
||||||
|
|
|
@ -321,6 +321,7 @@ void Log_ReceiveLogo (Sco_Scope_t Scope)
|
||||||
long Cod;
|
long Cod;
|
||||||
const char *Folder;
|
const char *Folder;
|
||||||
char Path[PATH_MAX+1];
|
char Path[PATH_MAX+1];
|
||||||
|
struct Param *Param;
|
||||||
char FileNameLogoSrc[PATH_MAX+1];
|
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
|
char FileNameLogo[PATH_MAX+1]; // Full name (including path and .png) of the destination file
|
||||||
|
@ -365,7 +366,7 @@ void Log_ReceiveLogo (Sco_Scope_t Scope)
|
||||||
Fil_CreateDirIfNotExists (Path);
|
Fil_CreateDirIfNotExists (Path);
|
||||||
|
|
||||||
/***** Copy in disk the file received from stdin (really from Gbl.F.Tmp) *****/
|
/***** Copy in disk the file received from stdin (really from Gbl.F.Tmp) *****/
|
||||||
Fil_StartReceptionOfFile (FileNameLogoSrc,MIMEType);
|
Param = Fil_StartReceptionOfFile (FileNameLogoSrc,MIMEType);
|
||||||
|
|
||||||
/* Check if the file type is image/jpeg or image/pjpeg or application/octet-stream */
|
/* Check if the file type is image/jpeg or image/pjpeg or application/octet-stream */
|
||||||
if (strcmp (MIMEType,"image/png"))
|
if (strcmp (MIMEType,"image/png"))
|
||||||
|
@ -387,8 +388,8 @@ void Log_ReceiveLogo (Sco_Scope_t Scope)
|
||||||
(unsigned) (Cod % 100),
|
(unsigned) (Cod % 100),
|
||||||
(unsigned) Cod,
|
(unsigned) Cod,
|
||||||
(unsigned) Cod);
|
(unsigned) Cod);
|
||||||
if (!Fil_EndReceptionOfFile (FileNameLogo))
|
if (!Fil_EndReceptionOfFile (FileNameLogo,Param))
|
||||||
Lay_ShowAlert (Lay_WARNING,"Error uploading file.");
|
Lay_ShowAlert (Lay_WARNING,"Error copying file.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -192,9 +192,9 @@ List --> |Name.Start | -> |Name.Start |
|
||||||
+------------------+ / +------------------+
|
+------------------+ / +------------------+
|
||||||
|Name.Length | | |Name.Length |
|
|Name.Length | | |Name.Length |
|
||||||
+------------------+ | +------------------+
|
+------------------+ | +------------------+
|
||||||
|Filename.Start | | |Filename.Start |
|
|FileName.Start | | |FileName.Start |
|
||||||
+------------------+ | +------------------+
|
+------------------+ | +------------------+
|
||||||
|Filename.Lenght | | |Filename.Lenght |
|
|FileName.Lenght | | |FileName.Lenght |
|
||||||
+------------------+ . +------------------+
|
+------------------+ . +------------------+
|
||||||
|ContentType.Start | . |ContentType.Start |
|
|ContentType.Start | . |ContentType.Start |
|
||||||
+------------------+ . +------------------+
|
+------------------+ . +------------------+
|
||||||
|
@ -354,10 +354,10 @@ static void Par_CreateListOfParamsFromTmpFile (void)
|
||||||
{
|
{
|
||||||
/* Get filename */
|
/* Get filename */
|
||||||
CurPos = (unsigned long) ftell (Gbl.F.Tmp); // At start of filename
|
CurPos = (unsigned long) ftell (Gbl.F.Tmp); // At start of filename
|
||||||
Param->Filename.Start = CurPos;
|
Param->FileName.Start = CurPos;
|
||||||
Ch = Par_ReadTmpFileUntilQuote ();
|
Ch = Par_ReadTmpFileUntilQuote ();
|
||||||
CurPos = (unsigned long) ftell (Gbl.F.Tmp); // Just after quote
|
CurPos = (unsigned long) ftell (Gbl.F.Tmp); // Just after quote
|
||||||
Param->Filename.Length = CurPos - 1 - Param->Filename.Start;
|
Param->FileName.Length = CurPos - 1 - Param->FileName.Start;
|
||||||
|
|
||||||
/* Check if last character read after filename is a quote */
|
/* Check if last character read after filename is a quote */
|
||||||
if (Ch != (int) '\"') break; // '\"'
|
if (Ch != (int) '\"') break; // '\"'
|
||||||
|
@ -525,7 +525,7 @@ void Par_FreeParams (void)
|
||||||
|
|
||||||
unsigned Par_GetParameter (tParamType ParamType,const char *ParamName,
|
unsigned Par_GetParameter (tParamType ParamType,const char *ParamName,
|
||||||
char *ParamValue,size_t MaxBytes,
|
char *ParamValue,size_t MaxBytes,
|
||||||
struct Param *ParamPtr) // NULL is not used
|
struct Param **ParamPtr) // NULL if not used
|
||||||
{
|
{
|
||||||
size_t BytesAlreadyCopied = 0;
|
size_t BytesAlreadyCopied = 0;
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
@ -534,7 +534,8 @@ unsigned Par_GetParameter (tParamType ParamType,const char *ParamName,
|
||||||
unsigned NumTimes;
|
unsigned NumTimes;
|
||||||
bool ParamFound = false;
|
bool ParamFound = false;
|
||||||
unsigned ParamNameLength;
|
unsigned ParamNameLength;
|
||||||
struct StartLength CopyValueFrom;
|
struct StartLength Copy;
|
||||||
|
bool FindMoreThanOneOcurrence;
|
||||||
|
|
||||||
/***** Default values returned *****/
|
/***** Default values returned *****/
|
||||||
ParamValue[0] = '\0'; // By default, the value of the parameter will be an empty string
|
ParamValue[0] = '\0'; // By default, the value of the parameter will be an empty string
|
||||||
|
@ -547,12 +548,12 @@ unsigned Par_GetParameter (tParamType ParamType,const char *ParamName,
|
||||||
/***** Initializations *****/
|
/***** Initializations *****/
|
||||||
ParamNameLength = strlen (ParamName);
|
ParamNameLength = strlen (ParamName);
|
||||||
PtrDst = ParamValue;
|
PtrDst = ParamValue;
|
||||||
|
FindMoreThanOneOcurrence = (ParamType == Par_PARAM_MULTIPLE);
|
||||||
|
|
||||||
/***** For multiple parameters, loop for any ocurrence of the parameter
|
/***** For multiple parameters, loop for any ocurrence of the parameter
|
||||||
For unique parameter, find only the first ocurrence *****/
|
For unique parameter, find only the first ocurrence *****/
|
||||||
for (Param = Gbl.Params.List, NumTimes = 0;
|
for (Param = Gbl.Params.List, NumTimes = 0;
|
||||||
Param != NULL &&
|
Param != NULL && (FindMoreThanOneOcurrence || NumTimes < 1);
|
||||||
(ParamType == Par_PARAM_MULTIPLE || NumTimes < 1);
|
|
||||||
NumTimes++)
|
NumTimes++)
|
||||||
/***** Find next ocurrence of parameter in list of parameters *****/
|
/***** Find next ocurrence of parameter in list of parameters *****/
|
||||||
for (ParamFound = false;
|
for (ParamFound = false;
|
||||||
|
@ -585,7 +586,7 @@ unsigned Par_GetParameter (tParamType ParamType,const char *ParamName,
|
||||||
{
|
{
|
||||||
/***** Get the first ocurrence of this parameter in list *****/
|
/***** Get the first ocurrence of this parameter in list *****/
|
||||||
if (ParamPtr)
|
if (ParamPtr)
|
||||||
ParamPtr = Param;
|
*ParamPtr = Param;
|
||||||
}
|
}
|
||||||
else // Not the first ocurrence of this parameter
|
else // Not the first ocurrence of this parameter
|
||||||
{
|
{
|
||||||
|
@ -607,8 +608,21 @@ unsigned Par_GetParameter (tParamType ParamType,const char *ParamName,
|
||||||
/***** Copy parameter value *****/
|
/***** Copy parameter value *****/
|
||||||
if (Param->Value.Length)
|
if (Param->Value.Length)
|
||||||
{
|
{
|
||||||
|
if (Param->FileName.Start != 0) // It's a file
|
||||||
|
{
|
||||||
|
/* Copy filename into ParamValue */
|
||||||
|
Copy.Start = Param->FileName.Start;
|
||||||
|
Copy.Length = Param->FileName.Length;
|
||||||
|
}
|
||||||
|
else // It's a normal parameter
|
||||||
|
{
|
||||||
|
/* Copy value into ParamValue */
|
||||||
|
Copy.Start = Param->Value.Start;
|
||||||
|
Copy.Length = Param->Value.Length;
|
||||||
|
}
|
||||||
|
|
||||||
/* Check if there is space to copy the parameter value */
|
/* Check if there is space to copy the parameter value */
|
||||||
if (BytesAlreadyCopied + Param->Value.Length > MaxBytes)
|
if (BytesAlreadyCopied + Copy.Length > MaxBytes)
|
||||||
{
|
{
|
||||||
sprintf (Gbl.Message,"Parameter <strong>%s</strong> too large,"
|
sprintf (Gbl.Message,"Parameter <strong>%s</strong> too large,"
|
||||||
" it exceed the maximum allowed size (%lu bytes).",
|
" it exceed the maximum allowed size (%lu bytes).",
|
||||||
|
@ -620,31 +634,19 @@ unsigned Par_GetParameter (tParamType ParamType,const char *ParamName,
|
||||||
switch (Gbl.ContentReceivedByCGI)
|
switch (Gbl.ContentReceivedByCGI)
|
||||||
{
|
{
|
||||||
case Act_CONTENT_NORM:
|
case Act_CONTENT_NORM:
|
||||||
strncpy (PtrDst,&Gbl.Params.QueryString[Param->Value.Start],
|
strncpy (PtrDst,&Gbl.Params.QueryString[Copy.Start],
|
||||||
Param->Value.Length);
|
Copy.Length);
|
||||||
break;
|
break;
|
||||||
case Act_CONTENT_DATA:
|
case Act_CONTENT_DATA:
|
||||||
if (Param->Filename.Start) // It's a file
|
fseek (Gbl.F.Tmp,Copy.Start,SEEK_SET);
|
||||||
{
|
if (fread ((void *) PtrDst,sizeof (char),Copy.Length,Gbl.F.Tmp) !=
|
||||||
/* Copy filename in ParamValue */
|
Copy.Length)
|
||||||
CopyValueFrom.Start = Param->Filename.Start;
|
|
||||||
CopyValueFrom.Length = Param->Filename.Length;
|
|
||||||
}
|
|
||||||
else // It's a normal parameter
|
|
||||||
{
|
|
||||||
/* Copy value in ParamValue */
|
|
||||||
CopyValueFrom.Start = Param->Value.Start;
|
|
||||||
CopyValueFrom.Length = Param->Value.Length;
|
|
||||||
}
|
|
||||||
fseek (Gbl.F.Tmp,CopyValueFrom.Start,SEEK_SET);
|
|
||||||
if (fread (PtrDst,sizeof (char),CopyValueFrom.Length,Gbl.F.Tmp) !=
|
|
||||||
CopyValueFrom.Length)
|
|
||||||
Lay_ShowErrorAndExit ("Error while getting value of parameter.");
|
Lay_ShowErrorAndExit ("Error while getting value of parameter.");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
BytesAlreadyCopied += Param->Value.Length;
|
BytesAlreadyCopied += Copy.Length;
|
||||||
PtrDst += Param->Value.Length;
|
PtrDst += Copy.Length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,8 +44,8 @@ struct StartLength
|
||||||
struct Param
|
struct Param
|
||||||
{
|
{
|
||||||
struct StartLength Name; // Parameter name
|
struct StartLength Name; // Parameter name
|
||||||
struct StartLength Filename; // optional
|
struct StartLength FileName; // optional, present only when uploading files
|
||||||
struct StartLength ContentType; // optional
|
struct StartLength ContentType; // optional, present only when uploading files
|
||||||
struct StartLength Value; // Parameter value or file content
|
struct StartLength Value; // Parameter value or file content
|
||||||
struct Param *Next;
|
struct Param *Next;
|
||||||
};
|
};
|
||||||
|
@ -67,7 +67,7 @@ void Par_CreateListOfParams (void);
|
||||||
void Par_FreeParams (void);
|
void Par_FreeParams (void);
|
||||||
unsigned Par_GetParameter (tParamType ParamType,const char *ParamName,
|
unsigned Par_GetParameter (tParamType ParamType,const char *ParamName,
|
||||||
char *ParamValue,size_t MaxBytes,
|
char *ParamValue,size_t MaxBytes,
|
||||||
struct Param *ParamPtr);
|
struct Param **ParamPtr);
|
||||||
|
|
||||||
void Par_GetMainParameters (void);
|
void Par_GetMainParameters (void);
|
||||||
|
|
||||||
|
|
|
@ -450,6 +450,7 @@ void Pho_ReceivePhotoAndDetectFaces (bool ItsMe,const struct UsrData *UsrDat)
|
||||||
extern const char *Txt_Faces_detected;
|
extern const char *Txt_Faces_detected;
|
||||||
char PathPhotosPriv[PATH_MAX+1];
|
char PathPhotosPriv[PATH_MAX+1];
|
||||||
char PathPhotosPubl[PATH_MAX+1];
|
char PathPhotosPubl[PATH_MAX+1];
|
||||||
|
struct Param *Param;
|
||||||
char FileNamePhotoSrc[PATH_MAX+1];
|
char FileNamePhotoSrc[PATH_MAX+1];
|
||||||
char FileNamePhotoTmp[PATH_MAX+1]; // Full name (including path and .jpg) of the destination temporary file
|
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 FileNamePhotoMap[PATH_MAX+1]; // Full name (including path) of the temporary file with the original image with faces
|
||||||
|
@ -497,7 +498,7 @@ void Pho_ReceivePhotoAndDetectFaces (bool ItsMe,const struct UsrData *UsrDat)
|
||||||
Fil_RemoveOldTmpFiles (PathPhotosPubl,Cfg_TIME_TO_DELETE_PHOTOS_TMP_FILES,false);
|
Fil_RemoveOldTmpFiles (PathPhotosPubl,Cfg_TIME_TO_DELETE_PHOTOS_TMP_FILES,false);
|
||||||
|
|
||||||
/***** 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 from stdin (really from Gbl.F.Tmp) *****/
|
||||||
Fil_StartReceptionOfFile (FileNamePhotoSrc,MIMEType);
|
Param = Fil_StartReceptionOfFile (FileNamePhotoSrc,MIMEType);
|
||||||
|
|
||||||
/* Check if the file type is image/jpeg or image/pjpeg or application/octet-stream */
|
/* Check if the file type is image/jpeg or image/pjpeg or application/octet-stream */
|
||||||
if (strcmp (MIMEType,"image/jpeg"))
|
if (strcmp (MIMEType,"image/jpeg"))
|
||||||
|
@ -517,9 +518,9 @@ void Pho_ReceivePhotoAndDetectFaces (bool ItsMe,const struct UsrData *UsrDat)
|
||||||
sprintf (FileNamePhotoTmp,"%s/%s/%s/%s.jpg",
|
sprintf (FileNamePhotoTmp,"%s/%s/%s/%s.jpg",
|
||||||
Cfg_PATH_SWAD_PUBLIC,Cfg_FOLDER_PHOTO,
|
Cfg_PATH_SWAD_PUBLIC,Cfg_FOLDER_PHOTO,
|
||||||
Cfg_FOLDER_PHOTO_TMP,Gbl.UniqueNameEncrypted);
|
Cfg_FOLDER_PHOTO_TMP,Gbl.UniqueNameEncrypted);
|
||||||
if (!Fil_EndReceptionOfFile (FileNamePhotoTmp))
|
if (!Fil_EndReceptionOfFile (FileNamePhotoTmp,Param))
|
||||||
{
|
{
|
||||||
Lay_ShowAlert (Lay_WARNING,"Error uploading file.");
|
Lay_ShowAlert (Lay_WARNING,"Error copying file.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -386,6 +386,7 @@ void TsI_ImportQstsFromXML (void)
|
||||||
{
|
{
|
||||||
extern const char *Txt_The_file_is_not_X;
|
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 FileNameXMLSrc[PATH_MAX+1];
|
||||||
char FileNameXMLTmp[PATH_MAX+1]; // Full name (including path and .xml) of the destination temporary file
|
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 MIMEType[Brw_MAX_BYTES_MIME_TYPE+1];
|
||||||
|
@ -399,7 +400,7 @@ void TsI_ImportQstsFromXML (void)
|
||||||
Fil_RemoveOldTmpFiles (PathTestPriv,Cfg_TIME_TO_DELETE_TEST_TMP_FILES,false);
|
Fil_RemoveOldTmpFiles (PathTestPriv,Cfg_TIME_TO_DELETE_TEST_TMP_FILES,false);
|
||||||
|
|
||||||
/***** 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 from stdin (really from Gbl.F.Tmp) *****/
|
||||||
Fil_StartReceptionOfFile (FileNameXMLSrc,MIMEType);
|
Param = Fil_StartReceptionOfFile (FileNameXMLSrc,MIMEType);
|
||||||
|
|
||||||
/* Check if the file type is image/jpeg or image/pjpeg or application/octet-stream */
|
/* Check if the file type is image/jpeg or image/pjpeg or application/octet-stream */
|
||||||
if (strcmp (MIMEType,"text/xml"))
|
if (strcmp (MIMEType,"text/xml"))
|
||||||
|
@ -418,11 +419,11 @@ void TsI_ImportQstsFromXML (void)
|
||||||
{
|
{
|
||||||
/* End the reception of XML in a temporary file */
|
/* End the reception of XML in a temporary file */
|
||||||
sprintf (FileNameXMLTmp,"%s/%s.xml",PathTestPriv,Gbl.UniqueNameEncrypted);
|
sprintf (FileNameXMLTmp,"%s/%s.xml",PathTestPriv,Gbl.UniqueNameEncrypted);
|
||||||
if (Fil_EndReceptionOfFile (FileNameXMLTmp))
|
if (Fil_EndReceptionOfFile (FileNameXMLTmp,Param))
|
||||||
/***** Get questions from XML file and store them in database *****/
|
/***** Get questions from XML file and store them in database *****/
|
||||||
TsI_ReadQuestionsFromXMLFileAndStoreInDB (FileNameXMLTmp);
|
TsI_ReadQuestionsFromXMLFileAndStoreInDB (FileNameXMLTmp);
|
||||||
else
|
else
|
||||||
Lay_ShowAlert (Lay_WARNING,"Error uploading file.");
|
Lay_ShowAlert (Lay_WARNING,"Error copying file.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user