Functional variable retrieval including #[local].
This commit is contained in:
parent
062a023683
commit
f0b3c0e0f6
23
Global.cpp
23
Global.cpp
@ -37,22 +37,22 @@ namespace jet {
|
||||
sessions.erase(sessionId);
|
||||
}
|
||||
|
||||
coreutils::ZString Global::getVariable(coreutils::ZString &variable, std::map<coreutils::ZString, coreutils::MString> &variables) {
|
||||
coreutils::ZString Global::getVariable(coreutils::ZString &variable, std::map<coreutils::ZString, coreutils::MString> &lvariables) {
|
||||
if(variable.ifNext("$[")) {
|
||||
coreutils::MString name;
|
||||
coreutils::MString modifier;
|
||||
if(variable.ifNext("!")) {
|
||||
renderVariableName(variable, name, modifier, variables);
|
||||
renderVariableName(variable, name, modifier, lvariables);
|
||||
return variables[name];
|
||||
} if(variable.ifNext(":")) {
|
||||
// TODO: should only allow CGI variable name. Allow variable substitution.
|
||||
} if(variable.ifNext("@")) {
|
||||
// TODO: should only allow session variables. Allow substitution.
|
||||
} if(variable.ifNext("%")) {
|
||||
renderVariableName(variable, name, modifier, variables);
|
||||
renderVariableName(variable, name, modifier, lvariables);
|
||||
return getenv(name.c_str());
|
||||
} else {
|
||||
renderVariableName(variable, name, modifier, variables);
|
||||
renderVariableName(variable, name, modifier, lvariables);
|
||||
name.split(".");
|
||||
if(name.getList().size() == 1)
|
||||
return variables[name[0]];
|
||||
@ -60,25 +60,26 @@ namespace jet {
|
||||
}
|
||||
throw coreutils::Exception("expected variable name or type designator.");
|
||||
} if(variable.ifNext("#[")) {
|
||||
// TODO: this local variable type has no special naming conventions. We
|
||||
// just need to do nested variable substitution for the entry.
|
||||
|
||||
coreutils::MString name;
|
||||
coreutils::MString modifier;
|
||||
renderVariableName(variable, name, modifier, lvariables);
|
||||
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::ZString, coreutils::MString> &variables) {
|
||||
void Global::renderVariableName(coreutils::ZString &variable, coreutils::MString &name, coreutils::MString &modifier, std::map<coreutils::ZString, coreutils::MString> &lvariables) {
|
||||
while(!variable.ifNext("]")) {
|
||||
name << variable.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-");
|
||||
if(variable.ifNext(";")) {
|
||||
renderVariableName(variable, modifier, modifier, variables);
|
||||
renderVariableName(variable, modifier, modifier, lvariables);
|
||||
return;
|
||||
}
|
||||
else if(variable.startsWith("$[")) {
|
||||
name << getVariable(variable, variables);
|
||||
name << getVariable(variable, lvariables);
|
||||
}
|
||||
else if(variable.startsWith("#[")) {
|
||||
name << getVariable(variable, variables);
|
||||
name << getVariable(variable, lvariables);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
4
Global.h
4
Global.h
@ -18,8 +18,8 @@ namespace jet {
|
||||
bool sessionExists(coreutils::MString sessionId);
|
||||
void addSession(coreutils::MString sessionId, __mysql *mysql);
|
||||
void removeSession(coreutils::MString sessionId);
|
||||
coreutils::ZString getVariable(coreutils::ZString &variable, std::map<coreutils::ZString, coreutils::MString> &variables);
|
||||
void renderVariableName(coreutils::ZString &variable, coreutils::MString &name, coreutils::MString &modifier, std::map<coreutils::ZString, coreutils::MString> &variables);
|
||||
coreutils::ZString getVariable(coreutils::ZString &variable, std::map<coreutils::ZString, coreutils::MString> &lvariables);
|
||||
void renderVariableName(coreutils::ZString &variable, coreutils::MString &name, coreutils::MString &modifier, std::map<coreutils::ZString, coreutils::MString> &lvariables);
|
||||
__mysql * getSession(coreutils::MString sessionId);
|
||||
coreutils::ZString getSessionVariable(coreutils::MString &splitName);
|
||||
void outputHeaders();
|
||||
|
@ -10,7 +10,7 @@
|
||||
$[modified1]
|
||||
---
|
||||
$[nonexistant]
|
||||
$[$HOME]
|
||||
$[%HOME]
|
||||
<comment>
|
||||
<mysql host="barant.com" database="barant" user="barant" password="uversa1960" sessionid="1">
|
||||
<sql sessionid="1">select * from testdata</sql>
|
||||
|
Loading…
x
Reference in New Issue
Block a user