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:
Tomasz Sowa 2010-07-04 20:27:14 +00:00
parent 76e32703ac
commit 50cb88c5ed
17 changed files with 150 additions and 51 deletions

View File

@ -23,7 +23,7 @@ void Content::FunNode()
return;
}
long id = atol( request.param_table[0]->c_str() );
long id = atol( request.param_table[0].name.c_str() );
RedirectTo(id);
}

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;

View File

@ -85,8 +85,14 @@ misc.o: ../core/users.h ../core/user.h ../core/ugcontainer.h ../core/log.h
misc.o: ../core/groups.h ../core/group.h ../core/functions.h
misc.o: ../core/function.h ../core/lastcontainer.h ../core/mounts.h
misc.o: ../core/mount.h ../core/error.h ../core/rebus.h ../core/loadavg.h
misc.o: ../core/misc.h misc.h localefilter.h ../core/locale.h
misc.o: ../confparser/confparser.h
misc.o: ../core/misc.h ../core/request.h ../core/requesttypes.h
misc.o: ../core/session.h ../core/plugindata.h ../core/thread.h
misc.o: ../core/compress.h ../core/acceptencodingparser.h
misc.o: ../core/acceptbaseparser.h ../core/htmlfilter.h
misc.o: ../core/postmultiparser.h ../core/ticket.h templates.h
misc.o: patterncacher.h ../core/item.h misc.h localefilter.h ../core/locale.h
misc.o: ../confparser/confparser.h ckeditorgetparser.h
misc.o: ../core/httpsimpleparser.h ../core/log.h indexpatterns.h
mount.o: templates.h patterncacher.h ../core/item.h misc.h localefilter.h
mount.o: ../core/locale.h ../confparser/confparser.h ckeditorgetparser.h
mount.o: ../core/httpsimpleparser.h ../core/log.h indexpatterns.h

View File

@ -263,14 +263,14 @@ void item_date_modification(Info & i)
void item_date_creation_nice(Info & i)
{
tm * ptm = &request.item.date_creation;
TemplatesMisc::print_date_nice(i, ptm);
print_date_nice(i, ptm);
}
void item_date_modification_nice(Info & i)
{
tm * ptm = &request.item.date_modification;
TemplatesMisc::print_date_nice(i, ptm);
print_date_nice(i, ptm);
}
@ -535,7 +535,7 @@ void item_tab_date_creation_nice(Info & i)
if( item_index < request.item_table.size() )
{
tm * ptm = &request.item_table[item_index].date_creation;
TemplatesMisc::print_date_nice(i, ptm);
print_date_nice(i, ptm);
}
}
@ -546,7 +546,7 @@ void item_tab_date_modification_nice(Info & i)
if( item_index < request.item_table.size() )
{
tm * ptm = &request.item_table[item_index].date_modification;
TemplatesMisc::print_date_nice(i, ptm);
print_date_nice(i, ptm);
}
}

View File

@ -28,10 +28,15 @@ void ls_ckeditor_funnum_browse(Info & i)
ls_ckeditor_reqid = request.id;
ckeditor_getparser.fun_num = 2; // default if there is a problem with parsing info
if( !request.param_table.empty() )
if( !request.get_table.empty() )
{
const char * str = request.param_table[request.param_table.size()-1]->c_str() + 1; // the first char is '?'
ckeditor_getparser.Parse(str);
size_t last = request.get_table.size()-1;
if( !request.get_table[last].empty() )
{
const char * str = request.get_table[last].c_str() + 1; // the first char is '?'
ckeditor_getparser.Parse(str);
}
}
ls_ckeditor_funnum = ckeditor_getparser.fun_num;

View File

@ -10,10 +10,12 @@
#include "../core/data.h"
#include "../core/misc.h"
#include "../core/request.h"
#include "templates.h"
#include "misc.h"
namespace TemplatesMisc
namespace TemplatesFunctions
{
@ -77,6 +79,28 @@ size_t loc, pat;
}
} // namespace TemplatesMisc
int ParseCKeditorFun()
{
ckeditor_getparser.fun_num = 2; // default if there is a problem with parsing info
if( !request.get_table.empty() )
{
size_t last = request.get_table.size()-1;
if( !request.get_table[last].empty() )
{
const char * str = request.get_table[last].c_str() + 1; // the first char is '?'
ckeditor_getparser.Parse(str);
}
}
return ckeditor_getparser.fun_num;
}
} // namespace TemplatesFunctions

View File

@ -19,7 +19,7 @@
namespace TemplatesMisc
namespace TemplatesFunctions
{
// table: [language][file]
typedef std::vector<std::vector<Ezc::Pattern> > Patterns;
@ -36,7 +36,7 @@ void ClearPatterns(Patterns & patterns, size_t len);
} // namespace TemplatesMisc
} // namespace TemplatesFunctions
#endif

View File

@ -20,13 +20,13 @@
namespace TemplatesFunctions
{
IndexPatterns index_patterns;
TemplatesMisc::Patterns patterns;
Ezc::Functions functions;
PatternCacher pattern_cacher;
Locale locale;
LocaleFilter locale_filter;
CKEditorGetParser ckeditor_getparser;
IndexPatterns index_patterns;
Patterns patterns;
Ezc::Functions functions;
PatternCacher pattern_cacher;
Locale locale;
LocaleFilter locale_filter;
CKEditorGetParser ckeditor_getparser;
const std::string empty; // used by GenerateRunRaw()
@ -485,7 +485,7 @@ void Templates::ReadFile(TemplatesFunctions::Pat pat, const char * file)
{
using namespace TemplatesFunctions;
TemplatesMisc::Read(patterns, static_cast<size_t>(pat), locale, locale_filter, file);
Read(patterns, static_cast<size_t>(pat), locale, locale_filter, file);
}
@ -588,7 +588,7 @@ void Templates::ClearPatterns()
{
using namespace TemplatesFunctions;
TemplatesMisc::ClearPatterns(patterns, pat_last);
TemplatesFunctions::ClearPatterns(patterns, pat_last);
}

View File

@ -69,11 +69,11 @@ namespace TemplatesFunctions
};
extern IndexPatterns index_patterns;
extern TemplatesMisc::Patterns patterns;
extern PatternCacher pattern_cacher;
extern Locale locale;
extern Ezc::Functions functions;
extern IndexPatterns index_patterns;
extern Patterns patterns;
extern PatternCacher pattern_cacher;
extern Locale locale;
extern Ezc::Functions functions;
extern CKEditorGetParser ckeditor_getparser;

View File

@ -140,7 +140,7 @@ void thread_tab_last_item_date_modification_nice(Info & i)
{
if( thread_tab_index < request.thread_tab.size() )
if( request.thread_tab[thread_tab_index].last_item.id != -1 )
TemplatesMisc::print_date_nice(i, &request.thread_tab[thread_tab_index].last_item.date_modification);
print_date_nice(i, &request.thread_tab[thread_tab_index].last_item.date_modification);
}

View File

@ -27,10 +27,15 @@ void upload_ckeditor_funnum(Info & i)
upload_ckeditor_reqid = request.id;
ckeditor_getparser.fun_num = 2; // default if there is a problem with parsing info
if( !request.param_table.empty() )
if( !request.get_table.empty() )
{
const char * str = request.param_table[request.param_table.size()-1]->c_str() + 1; // the first char is '?'
ckeditor_getparser.Parse(str);
size_t last = request.get_table.size()-1;
if( !request.get_table[last].empty() )
{
const char * str = request.get_table[last].c_str() + 1; // the first char is '?'
ckeditor_getparser.Parse(str);
}
}
upload_fun_num = ckeditor_getparser.fun_num;

View File

@ -19,7 +19,7 @@
namespace TemplatesNotifyFunctions
{
TemplatesMisc::Patterns patterns;
Patterns patterns;
Ezc::Functions functions;
Locale locale;
LocaleFilter locale_filter;
@ -63,7 +63,7 @@ void TemplatesNotify::ClearPatterns()
using namespace TemplatesNotifyFunctions;
TemplatesMisc::ClearPatterns(patterns, pat_last);
TemplatesFunctions::ClearPatterns(patterns, pat_last);
}
@ -73,7 +73,6 @@ using namespace TemplatesNotifyFunctions;
void TemplatesNotify::Read()
{
using namespace TemplatesNotifyFunctions;
using namespace TemplatesMisc;
Locale::Lang lang = Locale::StrToLang(data.locale_str);
@ -84,7 +83,7 @@ using namespace TemplatesMisc;
ClearPatterns();
locale.Read(data.locale_dir, data.locale_dir_default);
TemplatesMisc::Read(patterns, pat_email_notify, locale, locale_filter, "notify_email.txt", true);
TemplatesFunctions::Read(patterns, pat_email_notify, locale, locale_filter, "notify_email.txt", true);
notify_msg = 0;
}

View File

@ -43,7 +43,7 @@ namespace TemplatesNotifyFunctions
typedef std::vector<std::vector<Ezc::Pattern> > Patterns;
extern TemplatesMisc::Patterns patterns;
extern Patterns patterns;
extern NotifyMsg * notify_msg;
void notify_item_added(Info & i);