- __jet.cpp: the cgi keyword check compared against "true" but the
documented/intended value is "yes", so <jet cgi="yes" ...> never
actually turned CGI mode on; fixed. Also replaced the hardcoded
fake multipart boundary ("xxxx") with real extraction from the
Content-Type header's boundary= parameter.
- Global.h: default-initialize cgiData to NULL (a GET request with
cgi="yes" never allocates it, so it was previously left
dangling); Global.cpp now sets the cookie jar's delimiter to ";"
to match RFC 6265, since it defaulted to CGIFormattedData's
&-based form-data delimiter.
- Global.cpp: fix addSession()'s missing throw that let it silently
continue past a duplicate session id.
- Tag.cpp: fix the CGI-variable lookup branch, which failed to
compile (cgiData is a pointer; needed to dereference it before
indexing) and added a null check so a CGI request that never
populated cgiData (bad Content-Type, or the null-safety gap
above) throws a clear error instead of crashing; implemented the
previously-empty session-variable lookup branch; left the
unreachable duplicate environment-variable branch as-is with a
comment, since fixing its sigil is a user-facing template-syntax
decision, not a bug fix.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
60 lines
1.6 KiB
C++
60 lines
1.6 KiB
C++
#include "Global.h"
|
|
#include "Exception.h"
|
|
#include "__mysql.h"
|
|
#include <iostream>
|
|
#include <stdlib.h>
|
|
|
|
namespace jet {
|
|
|
|
Global::Global(char **envp) : envp(envp) {
|
|
cookies.setDelimiter(";");
|
|
}
|
|
|
|
Global::~Global() {
|
|
|
|
}
|
|
|
|
void Global::dump() {
|
|
for (auto i = variables.begin(); i != variables.end(); i++)
|
|
std::cout << i->first << "=[" << i->second << "]" << std::endl;
|
|
}
|
|
|
|
bool Global::sessionExists(coreutils::MString sessionId) {
|
|
return sessions.find(sessionId) != sessions.end();
|
|
}
|
|
|
|
void Global::addSession(coreutils::MString sessionId, __mysql *mysql) {
|
|
if(sessionExists(sessionId))
|
|
throw coreutils::Exception("sessionid already exists.");
|
|
sessions[sessionId] = mysql;
|
|
}
|
|
|
|
void Global::removeSession(coreutils::MString sessionId) {
|
|
sessions.erase(sessionId);
|
|
}
|
|
|
|
__mysql * Global::getSession(coreutils::MString sessionId) {
|
|
if(sessions.find(sessionId) == sessions.end())
|
|
throw coreutils::Exception("requested session is not available.");
|
|
return sessions[sessionId];
|
|
}
|
|
|
|
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]);
|
|
}
|
|
|
|
void Global::outputHeaders() {
|
|
if(headers.size() > 0) {
|
|
for(auto header = headers.begin();
|
|
header != headers.end();
|
|
++header) {
|
|
std::cout << header->first << ": " << header->second << std::endl;
|
|
}
|
|
std::cout << std::endl;
|
|
}
|
|
}
|
|
|
|
}
|