From edebae34b1329c4ead1db1a236d03c96ea19dd3a Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Wed, 15 Jan 2025 14:51:15 -0800 Subject: [PATCH] allow cookie, header and stream only in cgi mode. --- Global.h | 3 ++- TODO.txt | 2 -- __cookie.cpp | 2 ++ __dump.cpp | 19 +++++++++++-------- __header.cpp | 2 ++ __jet.cpp | 3 ++- __stream.cpp | 2 ++ tests/test1.jet | 1 + tests/testtag.jet | 8 ++++++++ 9 files changed, 30 insertions(+), 12 deletions(-) diff --git a/Global.h b/Global.h index cc70927..b60924f 100644 --- a/Global.h +++ b/Global.h @@ -31,7 +31,8 @@ namespace jet { std::map headers; std::map tags; char **envp; - + bool cgi = false; + }; } diff --git a/TODO.txt b/TODO.txt index 9014ad7..e7907e5 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,9 +1,7 @@ 1) Allow keyword variables to be resolved with a ';resolve' modifier. -2) Only allow stream tag in CGI mode. 3) Create a method to upload a file directly to a file name to bypass buffering on large files. -4) Allow the cookie tag only if CGI mode selected. 5) Call tag is acting wierd. Look at testcall.jet. 6) Create a tag for uploading of URL data to a specific file instead of buffering in an internal variable. Use . See testcgi.jet diff --git a/__cookie.cpp b/__cookie.cpp index 5a6de0e..802f874 100644 --- a/__cookie.cpp +++ b/__cookie.cpp @@ -8,6 +8,8 @@ namespace jet { __cookie::__cookie(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, local) { output = false; + if(!global.cgi) + throw coreutils::Exception("must enable cgi mode on jet tag to use cookie tag."); if(!keywordDefined("name")) throw coreutils::Exception("header tag must have name defined."); if(!keywordDefined("expr") && keywordDefined("value") && hasContainer) diff --git a/__dump.cpp b/__dump.cpp index aa633c0..18c1942 100644 --- a/__dump.cpp +++ b/__dump.cpp @@ -11,21 +11,24 @@ namespace jet { std::ofstream outFile(keywords["file"].str()); - outFile << "*** CGI VARIABLES ***" << std::endl; - - for (auto i = global.cgiVariables.begin(); i != global.cgiVariables.end(); i++) - outFile << i->first << "=[" << i->second << "]" << std::endl; - - outFile << "*** GLOBAL VARIABLES ***" << std::endl; + if(global.cgi) { + outFile << "*** CGI VARIABLES ***" << std::endl; + for (auto i = global.cgiVariables.begin(); i != global.cgiVariables.end(); i++) + outFile << i->first << "=[" << i->second << "]" << std::endl; + } + outFile << "*** GLOBAL VARIABLES ***" << std::endl; for (auto i = global.variables.begin(); i != global.variables.end(); i++) outFile << i->first << "=[" << i->second << "]" << std::endl; - outFile << "*** LOCAL VARIABLES ***" << std::endl; - + outFile << "*** LOCAL VARIABLES ***" << std::endl; for (auto i = local->variables.begin(); i != local->variables.end(); i++) outFile << i->first << "=[" << i->second << "]" << std::endl; + outFile << "*** KEYWORD VALUES ***" << std::endl; + for (auto i = parent->keywords.begin(); i != parent->keywords.end(); i++) + outFile << i->first << "=[" << i->second << "]" << std::endl; + outFile.close(); } diff --git a/__header.cpp b/__header.cpp index c23b9a0..fa0014b 100644 --- a/__header.cpp +++ b/__header.cpp @@ -7,6 +7,8 @@ namespace jet { __header::__header(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, local) { output = false; + if(!global.cgi) + throw coreutils::Exception("must enable cgi mode on jet tag to use header tag."); if(!keywordDefined("name")) throw coreutils::Exception("header tag must have name defined."); if(!keywordDefined("expr") && keywordDefined("value") && hasContainer) diff --git a/__jet.cpp b/__jet.cpp index 12a6195..9b0fca7 100644 --- a/__jet.cpp +++ b/__jet.cpp @@ -6,7 +6,8 @@ namespace jet { __jet::__jet(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, this) { - if(keywordDefined("cgi") && (keywords[resolveKeyword("cgi")] == "true")) { + if(keywordDefined("cgi") && (keywords[resolveKeyword("cgi")] == "true")) { + global.cgi = true; coreutils::ZString requestMethod(getenv("REQUEST_METHOD")); if(requestMethod == "POST") { coreutils::ZString contentLength(getenv("CONTENT_LENGTH")); diff --git a/__stream.cpp b/__stream.cpp index 9263ead..3d525e9 100644 --- a/__stream.cpp +++ b/__stream.cpp @@ -7,6 +7,8 @@ namespace jet { __stream::__stream(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, this) { output = false; + if(!global.cgi) + throw coreutils::Exception("must enable cgi mode on jet tag to use stream tag."); if(!keywordDefined("name")) throw coreutils::Exception("stream tag must have a file name to stream."); global.outputHeaders(); diff --git a/tests/test1.jet b/tests/test1.jet index 13a6d83..ca6f06e 100755 --- a/tests/test1.jet +++ b/tests/test1.jet @@ -1,4 +1,5 @@ #!../jet-2.0 This is output + diff --git a/tests/testtag.jet b/tests/testtag.jet index 631fd36..1ea776e 100755 --- a/tests/testtag.jet +++ b/tests/testtag.jet @@ -1,11 +1,19 @@ #!../jet-2.0 + + + + +
+ zzz + xxx +