Fucked up variable handling trying to improve things with a modifier.
This commit is contained in:
parent
d561a65f9d
commit
4972799e7a
34
Global.cpp
34
Global.cpp
@ -40,20 +40,25 @@ namespace jet {
|
||||
coreutils::ZString Global::getVariable(coreutils::ZString &variable) {
|
||||
if(variable.ifNext("$[")) {
|
||||
coreutils::MString name;
|
||||
coreutils::MString modifier;
|
||||
if(variable.ifNext("!")) {
|
||||
return variables[renderVariableName(name, variable)];
|
||||
return variables[renderVariableName(variable, name, modifier)];
|
||||
} if(variable.ifNext(":")) {
|
||||
// TODO: should only allow CGI variable name. Allow variable substitution.
|
||||
} if(variable.ifNext("@")) {
|
||||
// TODO: should only allow environment variables. Allow substitution.
|
||||
} if(variable.ifNext("$")) {
|
||||
return getenv(renderVariableName(name, variable).c_str());
|
||||
return getenv(renderVariableName(variable, name, modifier).c_str());
|
||||
} else {
|
||||
coreutils::MString splitName = renderVariableName(name, variable);
|
||||
splitName.split(".");
|
||||
if(splitName.getList().size() == 1)
|
||||
return variables[splitName[0]];
|
||||
return getSessionVariable(splitName);
|
||||
renderVariableName(variable, name, modifier);
|
||||
if(!variable.ifNext("]")) {
|
||||
std::cout << "unparsed: " << variable.unparsed() << std::endl;
|
||||
throw coreutils::Exception("expecting ] to close variable name.");
|
||||
}
|
||||
name.split(".");
|
||||
if(name.getList().size() == 1)
|
||||
return variables[name[0]];
|
||||
return getSessionVariable(name);
|
||||
}
|
||||
throw coreutils::Exception("expected variable name or type designator.");
|
||||
} if(variable.ifNext("#[")) {
|
||||
@ -64,16 +69,15 @@ namespace jet {
|
||||
throw coreutils::Exception("Expecting a variable initializer ('$[' or '#[').");
|
||||
}
|
||||
|
||||
coreutils::MString Global::renderVariableName(coreutils::MString &name, coreutils::ZString &variable) {
|
||||
coreutils::MString Global::renderVariableName(coreutils::ZString &variable, coreutils::MString &name, coreutils::MString &modifier) {
|
||||
name << variable.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-");
|
||||
if(variable.ifNext("]"))
|
||||
return name;
|
||||
if(variable.startsWith("$[")) {
|
||||
if(variable.ifNext("]"));
|
||||
else if(variable.ifNext(";")) {
|
||||
modifier = renderVariableName(variable, modifier, modifier);
|
||||
}
|
||||
else if(variable.startsWith("$[")) {
|
||||
name << getVariable(variable);
|
||||
if(variable.ifNext("]"))
|
||||
return name;
|
||||
}
|
||||
renderVariableName(name, variable);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
|
3
Global.h
3
Global.h
@ -19,12 +19,13 @@ namespace jet {
|
||||
void addSession(coreutils::MString sessionId, __mysql *mysql);
|
||||
void removeSession(coreutils::MString sessionId);
|
||||
coreutils::ZString getVariable(coreutils::ZString &variable);
|
||||
coreutils::MString renderVariableName(coreutils::MString &name, coreutils::ZString &variable);
|
||||
coreutils::MString renderVariableName(coreutils::ZString &variable, coreutils::MString &name, coreutils::MString &modifier);
|
||||
__mysql * getSession(coreutils::MString sessionId);
|
||||
coreutils::ZString getSessionVariable(coreutils::MString &splitName);
|
||||
void outputHeaders();
|
||||
|
||||
std::map<coreutils::MString, coreutils::MString> variables;
|
||||
std::map<coreutils::MString, coreutils::MString> cgiVariables;
|
||||
std::map<coreutils::MString, __mysql *> sessions;
|
||||
std::map<coreutils::MString, coreutils::MString> headers;
|
||||
|
||||
|
13
__jet.cpp
13
__jet.cpp
@ -5,7 +5,18 @@
|
||||
namespace jet {
|
||||
|
||||
__jet::__jet(coreutils::ZString &in, coreutils::MString &parent, Global &global) : Tag(in, parent, global) {
|
||||
|
||||
if(variables["cgi"] == "true") {
|
||||
coreutils::ZString requestMethod(getenv("REQUEST_METHOD"));
|
||||
if(requestMethod == "POST") {
|
||||
coreutils::ZString contentLength(getenv("CONTENT_LENGTH"));
|
||||
coreutils::ZString contentType(getenv("CONTENT_TYPE"));
|
||||
if(contentType == "multipart/form-data")
|
||||
std::cout << "output multipart variables to global" << std::endl;
|
||||
else if(contentType == "application/x-www-form-urlencoded")
|
||||
std::cout << "output urlencoded variables to global" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
processContainer(container);
|
||||
}
|
||||
|
@ -1,8 +1,14 @@
|
||||
#!./jet-2.0
|
||||
<jet name1="localname" filterblanklines="true" trimlines="true">
|
||||
<jet cgi="true" name1="localname" filterblanklines="true" trimlines="true">
|
||||
<header name="Content-Type" value="text/html" />
|
||||
<comment>This is a comment and should not show up in the output.</comment>
|
||||
<html>
|
||||
---
|
||||
<set name="modified1" value="ABCD" />
|
||||
$[modified1;TOHEX]
|
||||
<set name="tohex" value="TOHEX" />
|
||||
$[modified1;$[tohex]]
|
||||
---
|
||||
$[nonexistant]
|
||||
$[$HOME]
|
||||
<comment>
|
||||
|
Loading…
x
Reference in New Issue
Block a user