added: parameters consist of a name and a value now

sample: /dir/dir2/function/paramname:paramvalue
removed: TemplatesMisc namespace



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@618 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2010-07-04 20:27:14 +00:00
parent 76e32703ac
commit 50cb88c5ed
17 changed files with 150 additions and 51 deletions

View File

@@ -117,19 +117,49 @@ void FunctionParser::ParseFunction()
}
void FunctionParser::ParseParams(const std::string & par)
{
Param param;
size_t i;
if( par.empty() )
return;
// looking for the first colon ':'
for(i=0 ; i<par.size() && par[i] != ':' ; ++i);
if( i == par.size() )
{
// there is no a colon
param.name = par;
}
else
{
if( i > 0 )
param.name = par.substr(0, i);
if( i < par.size() - 1 )
param.value = par.substr(i+1);
}
request.param_table.push_back(param);
log << log3 << "FP: Param: name=" << param.name << ", value=" << param.value << logend;
}
void FunctionParser::ParseParams()
{
while( true )
for( ; true ; ++get_index )
{
SkipEmptyString("FP: Params: skipped empty string");
if( get_index == get_table_len )
break;
request.param_table.push_back( &request.get_table[get_index] );
log << log3 << "FP: Params: " << request.get_table[get_index] << logend;
++get_index;
ParseParams(request.get_table[get_index]);
}
}

View File

@@ -24,6 +24,7 @@ class FunctionParser
void ParseItem();
bool IsAppFunction();
void ParseFunction();
void ParseParams(const std::string & par);
void ParseParams();
public:

View File

@@ -535,13 +535,15 @@ bool compressing = data.compression && role == responder && redirect_to.empty()
bool Request::IsParam(const char * s)
bool Request::IsParam(const char * param_name)
{
std::vector<std::string*>::iterator i;
ParamTable::iterator i;
for(i=param_table.begin() ; i!=param_table.end() ; ++i)
{
if( **i == s )
// !! make sure that exists std::string::operator==(const char*)
// (optimization)
if( i->name == param_name )
return true;
}
@@ -549,6 +551,21 @@ return false;
}
const std::string & Request::ParamValue(const char * param_name)
{
ParamTable::iterator i;
for(i=param_table.begin() ; i!=param_table.end() ; ++i)
{
if( i->name == param_name )
{
return i->value;
}
}
return str_empty;
}
bool Request::CanChangeUser(const Item & item, long new_user_id)
{

View File

@@ -34,7 +34,7 @@ struct Request
// request id
// is incremented for each request and is never 0
// (from -1 will be incremented twice)
// it's used for some optimalization e.g. in templates
// it's used for some optimalizations e.g. in templates
size_t id;
@@ -89,8 +89,8 @@ struct Request
// null if there is no a function
Function * pfunction;
// !! moze nazwac to poprostu param?
std::vector<std::string*> param_table;
// parameters (name:value)
ParamTable param_table;
Error status;
@@ -131,7 +131,8 @@ struct Request
void Init();
bool IsParam(const char * s);
bool IsParam(const char * param_name);
const std::string & ParamValue(const char * param_name); // returns empty string if there is no such a parameter
void SetCookie(const char * name, const char * value, tm * expires = 0);
void SetCookie(const char * name, long value, tm * expires = 0);
@@ -200,6 +201,8 @@ private:
// it contains '\0'
const char char_empty;
// used in ParamValue(const char * param_name) when there is no such a param
const std::string str_empty;
PostMultiParser post_multi_parser;

View File

@@ -24,12 +24,21 @@ struct PostFile
std::string tmp_filename; // file with content (in /tmp)
};
// parameters from get name:value
struct Param
{
std::string name;
std::string value;
};
// some global types used by Request class
typedef std::vector<std::string> GetTable;
typedef std::map<std::string, std::string> PostTable;
typedef std::map<std::string, PostFile> PostFileTable;
typedef std::map<std::string, std::string> CookieTable;
typedef std::vector<Param> ParamTable;