migrating getvariable and setvarable to Tag. Needs alot of work.
This commit is contained in:
1 parent
229394310d
commit
2549220914
6 files changed
+145
-114
No files matched your search
+2
-68
@@ -58,73 +58,7 @@ namespace jet {
|
||||
return value.fromCGI();
|
||||
throw coreutils::Exception("modifier not valid.");
|
||||
}
|
||||
|
||||
coreutils::MString Global::getVariable(coreutils::ZString &variable,
|
||||
std::map<coreutils::MString, coreutils::MString> &lvariables,
|
||||
std::map<coreutils::MString, coreutils::MString> &keywords) {
|
||||
if(variable.ifNext("$[")) {
|
||||
coreutils::MString name;
|
||||
coreutils::MString modifier;
|
||||
if(variable.ifNext("!")) {
|
||||
renderVariableName(variable, name, modifier, lvariables, keywords);
|
||||
return variables[name];
|
||||
} else if(variable.ifNext("%")) {
|
||||
renderVariableName(variable, name, modifier, lvariables, keywords);
|
||||
return keywords[name];
|
||||
} else if(variable.ifNext(":")) {
|
||||
renderVariableName(variable, name, modifier, lvariables, keywords);
|
||||
if(name.find(":") == -1) {
|
||||
name << ":0";
|
||||
}
|
||||
return processModifier(cgiVariables[name], modifier);
|
||||
} if(variable.ifNext("@")) {
|
||||
// TODO: should only allow session variables. Allow substitution.
|
||||
} if(variable.ifNext("%")) {
|
||||
renderVariableName(variable, name, modifier, lvariables, keywords);
|
||||
return getenv(name.c_str());
|
||||
} else {
|
||||
renderVariableName(variable, name, modifier, lvariables, keywords);
|
||||
name.split(".");
|
||||
if(name.getList().size() == 1) {
|
||||
if(variables.find(name[0]) == variables.end())
|
||||
throw coreutils::Exception("global variable is not initialized.");
|
||||
return processModifier(variables[name[0]], modifier);
|
||||
}
|
||||
return getSessionVariable(name);
|
||||
}
|
||||
throw coreutils::Exception("expected variable name or type designator.");
|
||||
} if(variable.ifNext("#[")) {
|
||||
coreutils::MString name;
|
||||
coreutils::MString modifier;
|
||||
renderVariableName(variable, name, modifier, lvariables, keywords);
|
||||
if(lvariables.find(name) == lvariables.end())
|
||||
throw coreutils::Exception("local variable is not initialized.");
|
||||
return lvariables[name];
|
||||
}
|
||||
throw coreutils::Exception("Expecting a variable initializer ('$[' or '#[').");
|
||||
}
|
||||
|
||||
void Global::renderVariableName(coreutils::ZString &variable,
|
||||
coreutils::MString &name, coreutils::MString &modifier,
|
||||
std::map<coreutils::MString, coreutils::MString> &lvariables,
|
||||
std::map<coreutils::MString, coreutils::MString> &keywords) {
|
||||
while(!variable.ifNext("]")) {
|
||||
name << variable.getTokenInclude("?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-");
|
||||
if(variable.ifNext(";")) {
|
||||
renderVariableName(variable, modifier, modifier, lvariables, keywords);
|
||||
return;
|
||||
} else if(variable.ifNext(":")) {
|
||||
name << ":";
|
||||
} else if(variable.startsWith("$[") || variable.startsWith("#[")) {
|
||||
name << getVariable(variable, lvariables, keywords);
|
||||
} else if(variable.ifNext("]"))
|
||||
return;
|
||||
else if(!variable.ifNextInclude("?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-"))
|
||||
throw coreutils::Exception("invalid variable name.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
__mysql * Global::getSession(coreutils::MString sessionId) {
|
||||
if(sessions.find(sessionId) == sessions.end())
|
||||
throw coreutils::Exception("requested session is not available.");
|
||||
@@ -198,5 +132,5 @@ namespace jet {
|
||||
throw coreutils::Exception("expecting = after name in received CGI data.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user