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) {
|
coreutils::ZString Global::getVariable(coreutils::ZString &variable) {
|
||||||
if(variable.ifNext("$[")) {
|
if(variable.ifNext("$[")) {
|
||||||
coreutils::MString name;
|
coreutils::MString name;
|
||||||
|
coreutils::MString modifier;
|
||||||
if(variable.ifNext("!")) {
|
if(variable.ifNext("!")) {
|
||||||
return variables[renderVariableName(name, variable)];
|
return variables[renderVariableName(variable, name, modifier)];
|
||||||
} 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 environment variables. Allow substitution.
|
// TODO: should only allow environment variables. Allow substitution.
|
||||||
} if(variable.ifNext("$")) {
|
} if(variable.ifNext("$")) {
|
||||||
return getenv(renderVariableName(name, variable).c_str());
|
return getenv(renderVariableName(variable, name, modifier).c_str());
|
||||||
} else {
|
} else {
|
||||||
coreutils::MString splitName = renderVariableName(name, variable);
|
renderVariableName(variable, name, modifier);
|
||||||
splitName.split(".");
|
if(!variable.ifNext("]")) {
|
||||||
if(splitName.getList().size() == 1)
|
std::cout << "unparsed: " << variable.unparsed() << std::endl;
|
||||||
return variables[splitName[0]];
|
throw coreutils::Exception("expecting ] to close variable name.");
|
||||||
return getSessionVariable(splitName);
|
}
|
||||||
|
name.split(".");
|
||||||
|
if(name.getList().size() == 1)
|
||||||
|
return variables[name[0]];
|
||||||
|
return getSessionVariable(name);
|
||||||
}
|
}
|
||||||
throw coreutils::Exception("expected variable name or type designator.");
|
throw coreutils::Exception("expected variable name or type designator.");
|
||||||
} if(variable.ifNext("#[")) {
|
} if(variable.ifNext("#[")) {
|
||||||
@ -64,16 +69,15 @@ namespace jet {
|
|||||||
throw coreutils::Exception("Expecting a variable initializer ('$[' or '#[').");
|
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._-");
|
name << variable.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-");
|
||||||
if(variable.ifNext("]"))
|
if(variable.ifNext("]"));
|
||||||
return name;
|
else if(variable.ifNext(";")) {
|
||||||
if(variable.startsWith("$[")) {
|
modifier = renderVariableName(variable, modifier, modifier);
|
||||||
name << getVariable(variable);
|
}
|
||||||
if(variable.ifNext("]"))
|
else if(variable.startsWith("$[")) {
|
||||||
return name;
|
name << getVariable(variable);
|
||||||
}
|
}
|
||||||
renderVariableName(name, variable);
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
Global.h
3
Global.h
@ -19,12 +19,13 @@ namespace jet {
|
|||||||
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);
|
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);
|
__mysql * getSession(coreutils::MString sessionId);
|
||||||
coreutils::ZString getSessionVariable(coreutils::MString &splitName);
|
coreutils::ZString getSessionVariable(coreutils::MString &splitName);
|
||||||
void outputHeaders();
|
void outputHeaders();
|
||||||
|
|
||||||
std::map<coreutils::MString, coreutils::MString> variables;
|
std::map<coreutils::MString, coreutils::MString> variables;
|
||||||
|
std::map<coreutils::MString, coreutils::MString> cgiVariables;
|
||||||
std::map<coreutils::MString, __mysql *> sessions;
|
std::map<coreutils::MString, __mysql *> sessions;
|
||||||
std::map<coreutils::MString, coreutils::MString> headers;
|
std::map<coreutils::MString, coreutils::MString> headers;
|
||||||
|
|
||||||
|
11
__jet.cpp
11
__jet.cpp
@ -5,6 +5,17 @@
|
|||||||
namespace jet {
|
namespace jet {
|
||||||
|
|
||||||
__jet::__jet(coreutils::ZString &in, coreutils::MString &parent, Global &global) : Tag(in, parent, global) {
|
__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 {
|
try {
|
||||||
processContainer(container);
|
processContainer(container);
|
||||||
|
@ -1,8 +1,14 @@
|
|||||||
#!./jet-2.0
|
#!./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" />
|
<header name="Content-Type" value="text/html" />
|
||||||
<comment>This is a comment and should not show up in the output.</comment>
|
<comment>This is a comment and should not show up in the output.</comment>
|
||||||
<html>
|
<html>
|
||||||
|
---
|
||||||
|
<set name="modified1" value="ABCD" />
|
||||||
|
$[modified1;TOHEX]
|
||||||
|
<set name="tohex" value="TOHEX" />
|
||||||
|
$[modified1;$[tohex]]
|
||||||
|
---
|
||||||
$[nonexistant]
|
$[nonexistant]
|
||||||
$[$HOME]
|
$[$HOME]
|
||||||
<comment>
|
<comment>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user