JetCore/__cookie.cpp
2025-01-02 09:48:31 -08:00

68 lines
2.6 KiB
C++

#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); */