mirror of https://github.com/acanas/swad-core.git
Version 15.171.1
This commit is contained in:
parent
8242ade95f
commit
684dcdb224
|
@ -138,13 +138,14 @@
|
|||
/****************************** Public constants *****************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
#define Log_PLATFORM_VERSION "SWAD 15.171 (2016-04-01)"
|
||||
#define Log_PLATFORM_VERSION "SWAD 15.171.1 (2016-04-01)"
|
||||
#define CSS_FILE "swad15.165.5.css"
|
||||
#define JS_FILE "swad15.131.3.js"
|
||||
|
||||
// Number of lines (includes comments but not blank lines) has been got with the following command:
|
||||
// nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*.h sql/swad*.sql | tail -1
|
||||
/*
|
||||
Version 15.171.1: Apr 01, 2016 Code refactoring in functions to get a parameter and to receive file. (197271 lines)
|
||||
Version 15.171: Apr 01, 2016 Code refactoring in function to get a parameter. (197259 lines)
|
||||
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)
|
||||
|
|
17
swad_file.c
17
swad_file.c
|
@ -224,9 +224,22 @@ struct Param *Fil_StartReceptionOfFile (char *FileName,char *MIMEType)
|
|||
{
|
||||
struct Param *Param;
|
||||
|
||||
/***** Get parameter *****/
|
||||
Par_GetParameter (Par_PARAM_SINGLE,Fil_NAME_OF_PARAM_FILENAME_ORG,NULL,
|
||||
Fil_MAX_FILE_SIZE,&Param);
|
||||
|
||||
/***** Get filename *****/
|
||||
Par_GetParameter (Par_PARAM_SINGLE,Fil_NAME_OF_PARAM_FILENAME_ORG,FileName,
|
||||
PATH_MAX,&Param);
|
||||
/* Check if filename exists */
|
||||
if (Param->FileName.Start == 0 ||
|
||||
Param->FileName.Length == 0 ||
|
||||
Param->FileName.Length > PATH_MAX)
|
||||
Lay_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) !=
|
||||
Param->FileName.Length)
|
||||
Lay_ShowErrorAndExit ("Error while getting filename.");
|
||||
|
||||
/***** Get MIME type *****/
|
||||
/* Check if MIME type exists */
|
||||
|
|
|
@ -469,7 +469,8 @@ void Par_FreeParams (void)
|
|||
/************************* Get the value of a parameter **********************/
|
||||
/*****************************************************************************/
|
||||
// Return the number of parameters found
|
||||
// If ParamPtr is not null, on return it will point to the first ocurrence in list of parameters
|
||||
// If ParamPtr is not NULL, on return it will point to the first ocurrence in list of parameters
|
||||
// ParamValue can be NULL (if so, no value is copied)
|
||||
|
||||
unsigned Par_GetParameter (tParamType ParamType,const char *ParamName,
|
||||
char *ParamValue,size_t MaxBytes,
|
||||
|
@ -482,11 +483,11 @@ unsigned Par_GetParameter (tParamType ParamType,const char *ParamName,
|
|||
unsigned NumTimes;
|
||||
bool ParamFound = false;
|
||||
unsigned ParamNameLength;
|
||||
struct StartLength Copy;
|
||||
bool FindMoreThanOneOcurrence;
|
||||
|
||||
/***** Default values returned *****/
|
||||
ParamValue[0] = '\0'; // By default, the value of the parameter will be an empty string
|
||||
if (ParamValue)
|
||||
ParamValue[0] = '\0'; // By default, the value of the parameter will be an empty string
|
||||
|
||||
/***** Only some selected parameters can be passed by GET method *****/
|
||||
if (Gbl.Params.GetMethod)
|
||||
|
@ -535,6 +536,10 @@ unsigned Par_GetParameter (tParamType ParamType,const char *ParamName,
|
|||
/***** Get the first ocurrence of this parameter in list *****/
|
||||
if (ParamPtr)
|
||||
*ParamPtr = Param;
|
||||
|
||||
/***** If this parameter is a file ==> do not find more ocurrences ******/
|
||||
if (Param->FileName.Start != 0) // It's a file
|
||||
FindMoreThanOneOcurrence = false;
|
||||
}
|
||||
else // Not the first ocurrence of this parameter
|
||||
{
|
||||
|
@ -549,28 +554,16 @@ unsigned Par_GetParameter (tParamType ParamType,const char *ParamName,
|
|||
}
|
||||
|
||||
/* Copy separator */
|
||||
*PtrDst++ = Par_SEPARATOR_PARAM_MULTIPLE; // Separator in the destination string
|
||||
if (PtrDst)
|
||||
*PtrDst++ = Par_SEPARATOR_PARAM_MULTIPLE; // Separator in the destination string
|
||||
BytesAlreadyCopied++;
|
||||
}
|
||||
|
||||
/***** Copy parameter value *****/
|
||||
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 */
|
||||
if (BytesAlreadyCopied + Copy.Length > MaxBytes)
|
||||
if (BytesAlreadyCopied + Param->Value.Length > MaxBytes)
|
||||
{
|
||||
sprintf (Gbl.Message,"Parameter <strong>%s</strong> too large,"
|
||||
" it exceed the maximum allowed size (%lu bytes).",
|
||||
|
@ -582,25 +575,31 @@ unsigned Par_GetParameter (tParamType ParamType,const char *ParamName,
|
|||
switch (Gbl.ContentReceivedByCGI)
|
||||
{
|
||||
case Act_CONTENT_NORM:
|
||||
strncpy (PtrDst,&Gbl.Params.QueryString[Copy.Start],
|
||||
Copy.Length);
|
||||
if (PtrDst)
|
||||
strncpy (PtrDst,&Gbl.Params.QueryString[Param->Value.Start],
|
||||
Param->Value.Length);
|
||||
break;
|
||||
case Act_CONTENT_DATA:
|
||||
fseek (Gbl.F.Tmp,Copy.Start,SEEK_SET);
|
||||
if (fread ((void *) PtrDst,sizeof (char),Copy.Length,Gbl.F.Tmp) !=
|
||||
Copy.Length)
|
||||
Lay_ShowErrorAndExit ("Error while getting value of parameter.");
|
||||
|
||||
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 ((void *) PtrDst,sizeof (char),Param->Value.Length,Gbl.F.Tmp) !=
|
||||
Param->Value.Length)
|
||||
Lay_ShowErrorAndExit ("Error while getting value of parameter.");
|
||||
}
|
||||
break;
|
||||
}
|
||||
BytesAlreadyCopied += Copy.Length;
|
||||
PtrDst += Copy.Length;
|
||||
BytesAlreadyCopied += Param->Value.Length;
|
||||
if (PtrDst)
|
||||
PtrDst += Param->Value.Length;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*PtrDst = '\0'; // Add the final NULL
|
||||
if (PtrDst)
|
||||
*PtrDst = '\0'; // Add the final NULL
|
||||
|
||||
return NumTimes;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue