Functional variable retrieval including #[local].

This commit is contained in:
Brad Arant 2024-10-17 15:57:35 -07:00
parent 062a023683
commit f0b3c0e0f6
4 changed files with 15 additions and 14 deletions

View File

@ -37,22 +37,22 @@ namespace jet {
sessions.erase(sessionId); 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("$[")) { if(variable.ifNext("$[")) {
coreutils::MString name; coreutils::MString name;
coreutils::MString modifier; coreutils::MString modifier;
if(variable.ifNext("!")) { if(variable.ifNext("!")) {
renderVariableName(variable, name, modifier, variables); renderVariableName(variable, name, modifier, lvariables);
return variables[name]; return variables[name];
} if(variable.ifNext(":")) { } if(variable.ifNext(":")) {
// TODO: should only allow CGI variable name. Allow variable substitution. // TODO: should only allow CGI variable name. Allow variable substitution.
} if(variable.ifNext("@")) { } if(variable.ifNext("@")) {
// TODO: should only allow session variables. Allow substitution. // TODO: should only allow session variables. Allow substitution.
} if(variable.ifNext("%")) { } if(variable.ifNext("%")) {
renderVariableName(variable, name, modifier, variables); renderVariableName(variable, name, modifier, lvariables);
return getenv(name.c_str()); return getenv(name.c_str());
} else { } else {
renderVariableName(variable, name, modifier, variables); renderVariableName(variable, name, modifier, lvariables);
name.split("."); name.split(".");
if(name.getList().size() == 1) if(name.getList().size() == 1)
return variables[name[0]]; return variables[name[0]];
@ -60,25 +60,26 @@ namespace jet {
} }
throw coreutils::Exception("expected variable name or type designator."); throw coreutils::Exception("expected variable name or type designator.");
} if(variable.ifNext("#[")) { } if(variable.ifNext("#[")) {
// TODO: this local variable type has no special naming conventions. We coreutils::MString name;
// just need to do nested variable substitution for the entry. coreutils::MString modifier;
renderVariableName(variable, name, modifier, lvariables);
return lvariables[name];
} }
throw coreutils::Exception("Expecting a variable initializer ('$[' or '#[')."); 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("]")) { while(!variable.ifNext("]")) {
name << variable.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-"); name << variable.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-");
if(variable.ifNext(";")) { if(variable.ifNext(";")) {
renderVariableName(variable, modifier, modifier, variables); renderVariableName(variable, modifier, modifier, lvariables);
return; return;
} }
else if(variable.startsWith("$[")) { else if(variable.startsWith("$[")) {
name << getVariable(variable, variables); name << getVariable(variable, lvariables);
} }
else if(variable.startsWith("#[")) { else if(variable.startsWith("#[")) {
name << getVariable(variable, variables); name << getVariable(variable, lvariables);
} }
} }
return; return;

View File

@ -18,8 +18,8 @@ namespace jet {
bool sessionExists(coreutils::MString sessionId); bool sessionExists(coreutils::MString sessionId);
void addSession(coreutils::MString sessionId, __mysql *mysql); void addSession(coreutils::MString sessionId, __mysql *mysql);
void removeSession(coreutils::MString sessionId); void removeSession(coreutils::MString sessionId);
coreutils::ZString getVariable(coreutils::ZString &variable, 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> &variables); void renderVariableName(coreutils::ZString &variable, coreutils::MString &name, coreutils::MString &modifier, std::map<coreutils::ZString, coreutils::MString> &lvariables);
__mysql * getSession(coreutils::MString sessionId); __mysql * getSession(coreutils::MString sessionId);
coreutils::ZString getSessionVariable(coreutils::MString &splitName); coreutils::ZString getSessionVariable(coreutils::MString &splitName);
void outputHeaders(); void outputHeaders();

BIN
jet-2.0

Binary file not shown.

View File

@ -10,7 +10,7 @@
$[modified1] $[modified1]
--- ---
$[nonexistant] $[nonexistant]
$[$HOME] $[%HOME]
<comment> <comment>
<mysql host="barant.com" database="barant" user="barant" password="uversa1960" sessionid="1"> <mysql host="barant.com" database="barant" user="barant" password="uversa1960" sessionid="1">
<sql sessionid="1">select * from testdata</sql> <sql sessionid="1">select * from testdata</sql>