fixed: dots in url-es (now only one dot is available in the whole name and it cannot be only one dot ".")
added: cmslu can act as an authorizer (fast cgi authorize role)
added: Item::static_auth we can have additional static content on the file system
this content is authorized through cmslu (fastcgi authorizer mode)
changed: some changes in config
changed: the way how the www server is using cmslu
added new virtuals: static static_auth
changed: cmslu returns correct http headers (200, 404, 403)
changed: in cookie parser: we get the last cookie (if the server has more than one cookie with the same name)
git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@540 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
155
core/misc.cpp
155
core/misc.cpp
@@ -9,7 +9,7 @@
|
||||
|
||||
#include "misc.h"
|
||||
#include "log.h"
|
||||
|
||||
#include "data.h"
|
||||
|
||||
|
||||
|
||||
@@ -48,11 +48,30 @@ return false;
|
||||
}
|
||||
|
||||
|
||||
void CorrectUrl(Item & item)
|
||||
void CorrectUrlDots(std::string & url)
|
||||
{
|
||||
size_t i = url.size();
|
||||
bool was_dot = false;
|
||||
|
||||
while( i-- > 0 )
|
||||
{
|
||||
if( url[i] == '.' )
|
||||
{
|
||||
if( was_dot )
|
||||
// only one dot is allowed
|
||||
url[i] = '_';
|
||||
|
||||
was_dot = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CorrectUrlChars(std::string & url)
|
||||
{
|
||||
std::string::iterator i;
|
||||
|
||||
for(i = item.url.begin(); i!=item.url.end() ; ++i)
|
||||
|
||||
for(i = url.begin(); i!=url.end() ; ++i)
|
||||
{
|
||||
if( !CorrectUrlChar(*i) )
|
||||
{
|
||||
@@ -64,51 +83,34 @@ std::string::iterator i;
|
||||
*i = '_';
|
||||
}
|
||||
}
|
||||
|
||||
ToSmall(item.url);
|
||||
|
||||
if( item.url.empty() )
|
||||
item.url = "bez_nazwy"; // !! wrzucic do pliku konfiguracyjnego
|
||||
else
|
||||
if( item.url[0] >= '0' && item.url[0] <= '9' )
|
||||
// url must begin with a letter
|
||||
item.url.insert(item.url.begin(), '_');
|
||||
}
|
||||
|
||||
|
||||
void SetUrlFromSubject(Item & item)
|
||||
void CorrectUrlOnlyAllowedChar(std::string & url)
|
||||
{
|
||||
item.url = item.subject;
|
||||
CorrectUrl(item);
|
||||
CorrectUrlDots(url);
|
||||
CorrectUrlChars(url);
|
||||
ToSmall(url);
|
||||
Trim(url, '_');
|
||||
|
||||
/*
|
||||
std::string::iterator i;
|
||||
|
||||
item.url.clear();
|
||||
|
||||
for(i = item.subject.begin(); i!=item.subject.end() ; ++i)
|
||||
if( url.empty() || url == "." )
|
||||
{
|
||||
int c = ChangeLocalChar(*i);
|
||||
|
||||
if( (c >= 'a' && c <='z') ||
|
||||
(c >= 'A' && c <='Z') ||
|
||||
(c >= '0' && c <='9') ||
|
||||
(c == '(' || c == ')' || c == '.' || c == ',' || c == '_' )
|
||||
)
|
||||
{
|
||||
item.url += c;
|
||||
}
|
||||
else
|
||||
item.url += '_';
|
||||
if( data.item_url_empty.empty() )
|
||||
url = "unnamed";
|
||||
else
|
||||
{
|
||||
url = data.item_url_empty;
|
||||
|
||||
CorrectUrlDots(url);
|
||||
CorrectUrlChars(url);
|
||||
ToSmall(url);
|
||||
// we don't trim here and the string will not be empty
|
||||
}
|
||||
}
|
||||
|
||||
if( item.url.empty() )
|
||||
item.url = "bez_nazwy"; // !! wrzucic do pliku konfiguracyjnego
|
||||
else
|
||||
if( item.url[0] >= '0' && item.url[0] <= '9' )
|
||||
if( url[0] >= '0' && url[0] <= '9' )
|
||||
// url must begin with a letter
|
||||
item.url.insert(item.url.begin(), '_');
|
||||
*/
|
||||
url.insert(url.begin(), '_');
|
||||
}
|
||||
|
||||
|
||||
@@ -392,6 +394,36 @@ std::string::size_type i;
|
||||
}
|
||||
|
||||
|
||||
void Trim(std::string & s, char c)
|
||||
{
|
||||
std::string::size_type i;
|
||||
|
||||
if( s.empty() )
|
||||
return;
|
||||
|
||||
// looking for the 'c' characters at the end
|
||||
for(i=s.size()-1 ; i>0 && s[i]==c ; --i);
|
||||
|
||||
if( i==0 && s[i]==c )
|
||||
{
|
||||
// the whole string has the 'c' characters
|
||||
s.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
// deleting 'c' characters at the end
|
||||
if( i != s.size() - 1 )
|
||||
s.erase(i+1, std::string::npos);
|
||||
|
||||
// looking for the 'c' characters at the beginning
|
||||
for(i=0 ; i<s.size() && s[i]==c ; ++i);
|
||||
|
||||
// deleting the 'c' characters at the beginning
|
||||
if( i != 0 )
|
||||
s.erase(0, i);
|
||||
}
|
||||
|
||||
|
||||
const char * SkipWhite(const char * s)
|
||||
{
|
||||
while( IsWhite(*s) )
|
||||
@@ -401,18 +433,53 @@ return s;
|
||||
}
|
||||
|
||||
|
||||
int ToSmall(int c)
|
||||
{
|
||||
if( c>='A' && c<='Z' )
|
||||
c = c - 'A' + 'a';
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
void ToSmall(std::string & s)
|
||||
{
|
||||
std::string::size_type i;
|
||||
|
||||
for(i=0 ; i<s.size() ; ++i)
|
||||
{
|
||||
if( s[i]>='A' && s[i]<='Z' )
|
||||
s[i] = s[i] - 'A' + 'a';
|
||||
}
|
||||
s[i] = ToSmall(s[i]);
|
||||
}
|
||||
|
||||
|
||||
bool IsSubString(const char * short_str, const char * long_str)
|
||||
{
|
||||
while( *short_str && *long_str && *short_str == *long_str )
|
||||
{
|
||||
++short_str;
|
||||
++long_str;
|
||||
}
|
||||
|
||||
if( *short_str == 0 )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool IsSubStringNoCase(const char * short_str, const char * long_str)
|
||||
{
|
||||
while( *short_str && *long_str && ToSmall(*short_str) == ToSmall(*long_str) )
|
||||
{
|
||||
++short_str;
|
||||
++long_str;
|
||||
}
|
||||
|
||||
if( *short_str == 0 )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool ValidateEmail(const std::string & email)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user