Started the cookie tag. Still needs work.

This commit is contained in:
brad Arant 2025-01-02 09:48:31 -08:00
parent af4f615799
commit 907f449ecc
6 changed files with 96 additions and 6 deletions

View File

@ -101,7 +101,7 @@ namespace jet {
void Global::renderVariableName(coreutils::ZString &variable, coreutils::MString &name, coreutils::MString &modifier, std::map<coreutils::MString, coreutils::MString> &lvariables) {
while(!variable.ifNext("]")) {
name << variable.getTokenInclude("#?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-");
name << variable.getTokenInclude("?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-");
if(variable.ifNext(";")) {
renderVariableName(variable, modifier, modifier, lvariables);
return;
@ -111,7 +111,7 @@ namespace jet {
name << getVariable(variable, lvariables);
} else if(variable.ifNext("]"))
return;
else if(!variable.ifNextInclude("#?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-"))
else if(!variable.ifNextInclude("?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-"))
throw coreutils::Exception("invalid variable name.");
}
return;

View File

@ -19,6 +19,7 @@
#include "__while.h"
#include "__until.h"
#include "__header.h"
#include "__cookie.h"
#include "__whiledir.h"
#include "__tag.h"
#include "__dotag.h"
@ -174,6 +175,9 @@ namespace jet {
} else if(ifTagName(in, "header")) {
__header _header(in, out, global, this, local);
continue;
} else if(ifTagName(in, "cookie")) {
__cookie _cookie(in, out, global, this, local);
continue;
} else if(ifTagName(in, "whiledir")) {
__whiledir _whiledir(in, out, global, this, local);
continue;

67
__cookie.cpp Normal file
View File

@ -0,0 +1,67 @@
#include "__cookie.h"
#include "Exception.h"
#include "Operand.h"
#include <iostream>
#include <ctime>
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(!variableDefined("name"))
throw coreutils::Exception("header tag must have name defined.");
if(!variableDefined("expr") && variableDefined("value") && hasContainer)
throw coreutils::Exception("header tag cannot have both value and a container.");
if(variableDefined("expr") && !variableDefined("value") && hasContainer)
throw coreutils::Exception("header tag cannot have both expr and a container.");
if(variableDefined("expr") && variableDefined("value") && !hasContainer)
throw coreutils::Exception("header tag cannot have both expr and value.");
if(!variableDefined("expr") && !variableDefined("value") && !hasContainer)
throw coreutils::Exception("header tag must have a value, expr or a container.");
resolveKeyword("name");
if(variableDefined("expr")) {
if(variableDefined("eval"))
throw coreutils::Exception("Cannot use eval with expr.");
global.headers[variables["name"]] = Operand(variables["expr"], global, parent->variables).string;
} else if(hasContainer) {
processContainer(container);
if(evaluate) {
global.headers[variables["name"]] = out;
} else {
global.headers[variables["name"]] = container;
}
} else {
resolveKeyword("value");
global.headers[variables["Set-Cookie"]] = variables["value"];
}
}
}
/* write(so, "Set-cookie: ", 12);
write(so, cookie->name, cookie->lname);
write(so, "=", 1);
write(so, cookie->value, cookie->lvalue);
// If cookie has expiration then calculate the unix time for the time value.
if(cookie->ltimeout > 0)
{
timeout_value = atoi(null_terminated(cookie->timeout, cookie->ltimeout));
if(timeout_value > 0)
{
time(&time_value);
time_value += timeout_value;
timeout_struct = localtime(&time_value);
time_length = strftime(cookie_timeout_buffer, sizeof(cookie_timeout_buffer), "%a, %d-%b-%Y %H:%M:%S %Z", timeout_struct); $
write(so, "; Expires=", 10);
write(so, cookie_timeout_buffer, time_length);
}
}
write (so, "\n", 1); */

19
__cookie.h Normal file
View File

@ -0,0 +1,19 @@
#ifndef ____cookie_h__
#define ____cookie_h__
#include "Tag.h"
#include "ZString.h"
#include "MString.h"
namespace jet {
class __cookie : public Tag {
public:
__cookie(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local);
};
}
#endif

View File

@ -7,8 +7,8 @@
</whilerow>
Number of rows: $[1.#]
Number of columns: $[1.?#]
<for name="ix" start="1" end="$[1.?#]" step="1">
Field $[ix] is $[1.#$[ix]]
<for name="ix" start="1" end="$[1.?#]" step="1" scope="global">
Field $[ix] is $[1.?$[ix]]
</for>
</mysql>
</jet>