Compare commits

...

2 Commits

@ -1,5 +1,9 @@
Version 0.4: Version 0.4:
============= =============
2026-04-17:
- adding function to request a certain headline
- base64decode increase the outputbuffer by 2 bytes for null-temrinated strings
2026-04-16: 2026-04-16:
- base64encode and base64decode implemented - base64encode and base64decode implemented

@ -60,6 +60,8 @@ class WebRequestBuffer {
std::string GetProtocolVersion() { return protocol_version; }; std::string GetProtocolVersion() { return protocol_version; };
int GetRequestCmdObj(std::string *cmd, std::string *obj, JSONParse *jp); int GetRequestCmdObj(std::string *cmd, std::string *obj, JSONParse *jp);
std::string GetCookie(std::string name); std::string GetCookie(std::string name);
std::string GetHeader(std::string name);
std::list<WebHeaderLine> GetHeaders();
}; };

@ -463,7 +463,7 @@ int base64decode(std::string input, char **obuffer, int *olen) {
// calculate and realloc size of buffer // calculate and realloc size of buffer
if (*obuffer == NULL || (1 + ilen*3/4) < *olen) { if (*obuffer == NULL || (1 + ilen*3/4) < *olen) {
*olen = 1 + ilen*3/4; *olen = 2 + ilen*3/4; // increase buffer by two ... null terminated string?
*obuffer = (char*) realloc(*obuffer, *olen); *obuffer = (char*) realloc(*obuffer, *olen);
} }
@ -493,6 +493,7 @@ int base64decode(std::string input, char **obuffer, int *olen) {
(*obuffer)[ocnt++] = c; (*obuffer)[ocnt++] = c;
} }
*olen = ocnt; *olen = ocnt;
(*obuffer)[ocnt] = 0; // nullterminate - just to prevent unseen stuff
return 1; return 1;
}; };

@ -33,6 +33,15 @@ int SimpleWebServer::HandleRequest (WebRequestBuffer *requestbuffer, WebServerCl
std::string request = requestbuffer->GetRequest(); std::string request = requestbuffer->GetRequest();
printf ("SimpleWebServerClient::HandleRequest() Request:%s\n", request.c_str()); printf ("SimpleWebServerClient::HandleRequest() Request:%s\n", request.c_str());
debug ("Recived Headers");
std::list<WebHeaderLine> hl;
std::list<WebHeaderLine>::iterator il;
std::string s;
hl = requestbuffer->GetHeaders();
for (il = hl.begin(); il != hl.end(); il++) {
debug ("'%s' -> '%s' ", il->parameter.c_str(), requestbuffer->GetHeader(il->parameter).c_str());
}
if (request.compare ("/") == 0) request = "/index.html"; if (request.compare ("/") == 0) request = "/index.html";
if (request.find("/big.html") != std::string::npos) { if (request.find("/big.html") != std::string::npos) {
std::string htmlfile = GenerateBigHtmlFile(8*1024*1024); std::string htmlfile = GenerateBigHtmlFile(8*1024*1024);

@ -212,3 +212,23 @@ std::string WebRequestBuffer::GetCookie(std::string name) {
}; };
std::string WebRequestBuffer::GetHeader(std::string name) {
std::list<WebHeaderLine>::iterator il;
std::size_t i;
std::string s;
//
// search for coockie line
for (il = headerlines.begin(); il != headerlines.end(); il++) {
if ((string_to_lower(il->parameter).compare(string_to_lower(name)) == 0) ||
(string_to_lower(il->parameter).compare(string_to_lower(name) + ':') == 0)) {
return il->value;
}
}
return "";
};
std::list<WebHeaderLine> WebRequestBuffer::GetHeaders() {
return headerlines;
};

Loading…
Cancel
Save