diff --git a/Global.cpp b/Global.cpp index be623fd..f1c3c62 100644 --- a/Global.cpp +++ b/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; } diff --git a/Global.h b/Global.h index baa78b5..bad9292 100644 --- a/Global.h +++ b/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 variables; + std::map cgiVariables; std::map sessions; std::map headers; diff --git a/__jet.cpp b/__jet.cpp index 106c27a..0139bcd 100644 --- a/__jet.cpp +++ b/__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); } diff --git a/jet-2.0 b/jet-2.0 index 085a137..6e6b7e6 100755 Binary files a/jet-2.0 and b/jet-2.0 differ diff --git a/testjet.jet b/testjet.jet index 82a82a7..e9b98d0 100755 --- a/testjet.jet +++ b/testjet.jet @@ -1,8 +1,14 @@ #!./jet-2.0 - +
This is a comment and should not show up in the output. + --- + + $[modified1;TOHEX] + + $[modified1;$[tohex]] + --- $[nonexistant] $[$HOME]