diff --git a/Global.cpp b/Global.cpp index 485dd25..2b18df2 100644 --- a/Global.cpp +++ b/Global.cpp @@ -101,7 +101,7 @@ namespace jet { void Global::renderVariableName(coreutils::ZString &variable, coreutils::MString &name, coreutils::MString &modifier, std::map &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; @@ -123,7 +123,7 @@ namespace jet { return sessions[sessionId]; } - coreutils::ZString Global::getSessionVariable(coreutils::MString &splitName) { + coreutils::ZString Global::getSessionVariable(coreutils::MString &splitName) { if(sessions.find(splitName[0]) == sessions.end()) throw coreutils::Exception("requested session is not available in variable."); return sessions[splitName[0]]->getColumnValue(splitName[1]); diff --git a/Tag.cpp b/Tag.cpp index 90ee5d7..37705d6 100644 --- a/Tag.cpp +++ b/Tag.cpp @@ -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; diff --git a/__cookie.cpp b/__cookie.cpp new file mode 100644 index 0000000..0cf32b7 --- /dev/null +++ b/__cookie.cpp @@ -0,0 +1,67 @@ +#include "__cookie.h" +#include "Exception.h" +#include "Operand.h" +#include +#include + +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); */ + diff --git a/__cookie.h b/__cookie.h new file mode 100644 index 0000000..ba2e10f --- /dev/null +++ b/__cookie.h @@ -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 diff --git a/__mysql.cpp b/__mysql.cpp index 4a1c435..4c44db4 100644 --- a/__mysql.cpp +++ b/__mysql.cpp @@ -61,7 +61,7 @@ namespace jet { } coreutils::ZString __mysql::getColumnValue(coreutils::ZString column) { - MYSQL_FIELD *field; + MYSQL_FIELD *field; if(column == "?#") { nbrOfColumns = (int)qFields; return nbrOfColumns; diff --git a/tests/testdb.jet b/tests/testdb.jet index 790257e..a4388c4 100755 --- a/tests/testdb.jet +++ b/tests/testdb.jet @@ -7,8 +7,8 @@ Number of rows: $[1.#] Number of columns: $[1.?#] - -Field $[ix] is $[1.#$[ix]] + +Field $[ix] is $[1.?$[ix]]