JetCore/__jet.cpp
2025-03-09 14:58:22 -07:00

63 lines
2.2 KiB
C++

#include "__jet.h"
#include "Exception.h"
#include <iostream>
#include <fstream>
#include <openssl/ssl.h>
namespace jet {
__jet::__jet(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, this) {
char *cookies;
if(keywordDefined("cgi") && (resolveKeyword("cgi") == "true")) {
global.cgi = true;
if(keywordDefined("sessiondir")) {
coreutils::ZString cookies = getenv("HTTP_COOKIE");
storeVariable("cookies", cookies, "global");
global.session = true;
// if request_has_cookie then
// pull sessionfile from sessiondir.
// if last activity time is expired then ignore.
// follow sessiontimeoutredirecturl.
// else
// generate new session id.
// create session cookie in response.
unsigned char hashit[64];
unsigned char hash[SHA_DIGEST_LENGTH];
char hashname[64];
sprintf((char *)hashit, "JETSESSION%ld", time(0));
SHA1(hashit, strlen((char *)hashit), hash);
sprintf(hashname, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
hash[0], hash[1], hash[2], hash[3], hash[4], hash[5], hash[6], hash[7], hash[8], hash[9],
hash[10], hash[11], hash[12], hash[13], hash[14], hash[15], hash[16], hash[17], hash[18], hash[19]);
coreutils::ZString sessionCookie(hashname);
global.headers["Set-Cookie"] << "session=" << sessionCookie;
if(keywordDefined("sessiontimeout")) {
time_t timeout = time(0) + keywords["sessiontimeout"].asInteger();
}
// also save last activity time in session file.
}
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") {
coreutils::IMFMultipart postdata(0, contentLength.asInteger());
}
else if(contentType == "application/x-www-form-urlencoded")
global.setupFormURLEncoded(postdata);
}
}
processContainer(container);
}
}