changed: upload function
select file type by the extension param: multi fixed: uptime function it showed incorrect uptime time (minuts were badly calculated) git-svn-id: svn://ttmath.org/publicrep/winix/trunk@575 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -72,9 +72,10 @@ long content_id;
|
||||
// the direct url is the same but the prefix is: base_url_static_auth
|
||||
enum StaticAuth
|
||||
{
|
||||
static_none = 0,
|
||||
static_image = 1,
|
||||
static_other = 2
|
||||
static_none = 0,
|
||||
static_image = 1, /* png, gif, jpg - only types available to render by a web browser*/
|
||||
static_document = 2, /* pdf doc xls txt */
|
||||
static_other = 3
|
||||
};
|
||||
|
||||
|
||||
|
@@ -50,6 +50,9 @@ return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// this function checks how many dots there are in the url
|
||||
// if there are more than one (last) dot then the first dots will be changed into '_'
|
||||
void CorrectUrlDots(std::string & url)
|
||||
{
|
||||
size_t i = url.size();
|
||||
@@ -73,7 +76,7 @@ void CorrectUrlChars(std::string & url)
|
||||
{
|
||||
std::string::iterator i;
|
||||
|
||||
for(i = url.begin(); i!=url.end() ; ++i)
|
||||
for(i=url.begin(); i != url.end() ; ++i)
|
||||
{
|
||||
if( !CorrectUrlChar(*i) )
|
||||
{
|
||||
@@ -215,6 +218,9 @@ void HtmlEscapeFormTxt(std::ostringstream & out, const std::string & in)
|
||||
std::string::const_iterator i;
|
||||
int was_enter = 0; // how many enteres there were before
|
||||
|
||||
if( in.empty() )
|
||||
return;
|
||||
|
||||
out << "<p>";
|
||||
|
||||
// skipping first new line characters
|
||||
@@ -485,15 +491,15 @@ return false;
|
||||
}
|
||||
|
||||
|
||||
bool EqualNoCase(const char * short_str, const char * long_str)
|
||||
bool EqualNoCase(const char * str1, const char * str2)
|
||||
{
|
||||
while( *short_str && *long_str && ToSmall(*short_str) == ToSmall(*long_str) )
|
||||
while( *str1 && *str2 && ToSmall(*str1) == ToSmall(*str2) )
|
||||
{
|
||||
++short_str;
|
||||
++long_str;
|
||||
++str1;
|
||||
++str2;
|
||||
}
|
||||
|
||||
if( *short_str == 0 && *long_str == 0 )
|
||||
if( *str1 == 0 && *str2 == 0 )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
@@ -555,3 +561,54 @@ bool IsFile(const std::string & file)
|
||||
{
|
||||
return IsFile(file.c_str());
|
||||
}
|
||||
|
||||
|
||||
// if there is not an extension it returns a pointer to the last '\0' character
|
||||
const char * GetFileExt(const char * name)
|
||||
{
|
||||
size_t i, ilast;
|
||||
|
||||
// looking for the end of the name
|
||||
for(i=0 ; name[i] != 0 ; ++i);
|
||||
|
||||
if( i == 0 )
|
||||
return name; // ops, the name is empty
|
||||
|
||||
// remember the end of the string
|
||||
ilast = i;
|
||||
|
||||
// looking for the last dot
|
||||
for(--i ; i>0 && name[i] != '.' ; --i);
|
||||
|
||||
if( name[i] != '.' )
|
||||
return name + ilast; // ops, there is not a dot
|
||||
|
||||
// the extensions starts from i+1
|
||||
// and can be empty (if the last character is a dot)
|
||||
|
||||
return name + i + 1;
|
||||
}
|
||||
|
||||
|
||||
Item::StaticAuth SelectFileType(const char * file_name)
|
||||
{
|
||||
const char * ext = GetFileExt(file_name);
|
||||
|
||||
// as an image we're using only those types which can be rendered
|
||||
// by a web browser
|
||||
if( EqualNoCase(ext, "jpg") ||
|
||||
EqualNoCase(ext, "gif") ||
|
||||
EqualNoCase(ext, "png") )
|
||||
return Item::static_image;
|
||||
|
||||
if( EqualNoCase(ext, "pdf") ||
|
||||
EqualNoCase(ext, "doc") ||
|
||||
EqualNoCase(ext, "xls") ||
|
||||
EqualNoCase(ext, "txt") ||
|
||||
EqualNoCase(ext, "ods") ||
|
||||
EqualNoCase(ext, "odt") )
|
||||
return Item::static_document;
|
||||
|
||||
return Item::static_other;
|
||||
}
|
||||
|
||||
|
@@ -57,12 +57,14 @@ const char * ToStr(int value);
|
||||
|
||||
bool IsSubString(const char * short_str, const char * long_str);
|
||||
bool IsSubStringNoCase(const char * short_str, const char * long_str);
|
||||
bool EqualNoCase(const char * short_str, const char * long_str);
|
||||
bool EqualNoCase(const char * str1, const char * str2);
|
||||
|
||||
bool ValidateEmail(const std::string & email);
|
||||
|
||||
bool IsFile(const char * file);
|
||||
bool IsFile(const std::string & file);
|
||||
|
||||
const char * GetFileExt(const char * name);
|
||||
Item::StaticAuth SelectFileType(const char * file_name);
|
||||
|
||||
#endif
|
||||
|
@@ -911,6 +911,7 @@ void Request::MakePath(std::string & path)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Request::MakeDirsOnFS()
|
||||
{
|
||||
size_t i;
|
||||
@@ -922,11 +923,13 @@ bool Request::MakeDirsOnFS()
|
||||
path += '/';
|
||||
path += dir_table[i]->url;
|
||||
|
||||
if( mkdir(path.c_str(), 0755) < 0 )
|
||||
if( !IsFile(path.c_str()) )
|
||||
{
|
||||
// oops
|
||||
log << log1 << "Request: can't create the directory on fs: " << path << logend;
|
||||
return false;
|
||||
if( mkdir(path.c_str(), 0755) < 0 )
|
||||
{
|
||||
log << log1 << "Request: can't create the directory on fs: " << path << logend;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user