not all cookies where returned by the GetCookie function

master
Steffen Pohle 6 days ago
parent d93e377544
commit 7239983744

3
.gitignore vendored

@ -1,8 +1,11 @@
.vscode
fbconfig.config fbconfig.config
*.oo *.oo
*.o *.o
*.so.* *.so.*
*.so *.so
test-webserver
test-json
test-ssl test-ssl
test-tcpclient test-tcpclient
test-tcpserver test-tcpserver

@ -1,3 +1,7 @@
2026-04-04:
- WebRequestBuffer::GerCookie did not return the correct cookie
- test-webserver: added some basic data in and output.
2026-03-26: 2026-03-26:
- WebRequestBuffer::GetRequestCmdObj complete values where the pointer - WebRequestBuffer::GetRequestCmdObj complete values where the pointer
is set. is set.

@ -1,6 +1,7 @@
#include <unistd.h> #include <unistd.h>
#include <sysexits.h> #include <sysexits.h>
#include <signal.h> #include <signal.h>
#include <math.h>
#include "UDPTCPNetwork.h" #include "UDPTCPNetwork.h"
@ -14,6 +15,7 @@ int running = 1;
static void sig_int(int); static void sig_int(int);
int SetupSignals(); int SetupSignals();
std::string GenerateDataSet(JSONParse *jpdata);
std::string GenerateHtmlFile(); std::string GenerateHtmlFile();
std::string GenerateBigHtmlFile(int size); std::string GenerateBigHtmlFile(int size);
@ -44,6 +46,16 @@ int SimpleWebServer::HandleRequest (WebRequestBuffer *requestbuffer, WebServerCl
if (webclient->SendResponseFileFromMemory(requestbuffer, request, "", if (webclient->SendResponseFileFromMemory(requestbuffer, request, "",
(void*) htmlfile.c_str(), strlen(htmlfile.c_str())) != 1) return 0; (void*) htmlfile.c_str(), strlen(htmlfile.c_str())) != 1) return 0;
} }
else if (request.find("/getdata") != std::string::npos) {
std::string response;
JSONParse data;
requestbuffer->GetRequestCmdObj(NULL, NULL, &data);
response = GenerateDataSet(&data);
if (webclient->SendResponseFileFromMemory(requestbuffer, request, "",
(void*) response.c_str(), strlen(response.c_str())) != 1) return 0;
}
else else
if (webclient->SendResponseFile(requestbuffer, request, "") != 1) return 0; if (webclient->SendResponseFile(requestbuffer, request, "") != 1) return 0;
@ -93,6 +105,7 @@ int SetupSignals() {
return 1; return 1;
}; };
static void sig_int(int sig) { static void sig_int(int sig) {
if (signal (SIGINT, sig_int) == SIG_ERR) errorexit ("could not set up signal SIGINT\n"); if (signal (SIGINT, sig_int) == SIG_ERR) errorexit ("could not set up signal SIGINT\n");
@ -128,3 +141,27 @@ std::string GenerateBigHtmlFile(int size) {
return html; return html;
}; };
std::string GenerateDataSet(JSONParse *jpdata) {
JSONParse jp;
std::string text;
if (! jpdata->GetValueString("oldtext", &text)) text = "no old text";
else {
for (int i = 0; i < text.length(); i++)
text[i] = toupper(text[i]);
}
jp.Clear();
jp.AddObject("sin", 100*sin((double)time(NULL)*M_2_PI/120.0));
jp.AddObject("cos", 100*cos((double)time(NULL)*M_2_PI/120.0));
jp.AddObject("tan", 100*tan((double)time(NULL)*M_2_PI/120.0));
jp.AddObject("time", (int64_t) time(NULL));
jp.AddObject("text", text);
return jp.ToString();
};

@ -193,13 +193,19 @@ std::string WebRequestBuffer::GetRequest() {
std::string WebRequestBuffer::GetCookie(std::string name) { std::string WebRequestBuffer::GetCookie(std::string name) {
std::list<WebHeaderLine>::iterator il; std::list<WebHeaderLine>::iterator il;
std::size_t i; std::size_t i;
std::string s;
//
// search for coockie line
for (il = headerlines.begin(); il != headerlines.end(); il++) { for (il = headerlines.begin(); il != headerlines.end(); il++) {
if (string_to_lower(il->parameter).compare("cookie:") == 0) { if (string_to_lower(il->parameter).compare("cookie:") == 0) {
i = il->value.find('='); //
// search for the correct cookie
i = il->value.find(name + '=');
if (i == std::string::npos) continue; if (i == std::string::npos) continue;
if (il->value.substr(0, i).compare(name) == 0) s = il->value.substr(i, std::string::npos);
return il->value.substr(i+1, std::string::npos); s = s.substr(s.find('=')+1, std::string::npos);
return s.substr (0, s.find(';'));
} }
} }
return ""; return "";

@ -0,0 +1,71 @@
<html>
<head>
<title>TestWebserver</title>
<script src="jquery-3.1.0.min.js"></script>
</head>
<body>
<h1>Testpage</h1>
<p>
This is only a test for more detail see at <a href="https://steffen.gulpe.de/gitea/steffen/libUDPTCPNetwork">https://steffen.gulpe.de/gitea/steffen/libUDPTCPNetwork</a>
<p>
This is a smal test for sending and retrieving data.
<p>
<table>
<thead>
<th>name</th><th>value</th>
</thead>
<tr> <td>Sinus</td><td><input id="valsinus"></td> </tr>
<tr> <td>Cosinus</td><td><input id="valcosinus"></td> </tr>
<tr> <td>Time</td><td><input id="valtime"></td> </tr>
<tr> <td>Text</td><td><input id="valtext"></td> </tr>
</table>
<p>Return to <a href="index.html">INDEX.HTML</a>
</body>
<div id="debug"></div>
<script>
function refreshVariables() {
let debug = document.getElementById("debug");
let inputbox = document.getElementById("valtext");
let timebox = document.getElementById("valtime");
let sinusbox = document.getElementById("valsinus");
let cosinusbox = document.getElementById("valcosinus");
$.ajax({
type: "POST",
url: 'getdata',
data: JSON.stringify({"oldtext": inputbox.value, "sinus": sinusbox.value}),
success: function(response)
{
let variables = JSON.parse(response);
if (variables.text) inputbox.value = variables.text;
if (variables.time) {
let date = new Date(variables.time * 1000);
timebox.value = date.toLocaleDateString() + " " + date.toLocaleTimeString();
}
if (variables.sin) sinusbox.value = variables.sin;
if (variables.cos) cosinusbox.value = variables.cos;
},
error: function(error) {
debug.innerHTML = "ERROR";
}
});
}
function refresh() {
refreshVariables();
}
setInterval(refresh, 2000);
refreshVariables();
</script>
</html>

@ -7,9 +7,11 @@
<p> <p>
This is only a test for more detail see at <a href="https://steffen.gulpe.de/gitea/steffen/libUDPTCPNetwork">https://steffen.gulpe.de/gitea/steffen/libUDPTCPNetwork</a> This is only a test for more detail see at <a href="https://steffen.gulpe.de/gitea/steffen/libUDPTCPNetwork">https://steffen.gulpe.de/gitea/steffen/libUDPTCPNetwork</a>
<p> <p>
<a href="test.html">test.html</a> is a hard coded HTML page. <ul>
<a href="big.html">big.html</a> is a big hard coded HTML page. <li><a href="test.html">test.html</a> is a hard coded HTML page.</li>
<li><a href="big.html">big.html</a> is a big hard coded HTML page.</li>
<li><a href="data.html">data.html</a> sample for data in and ouput.</li>
</ul>
</body> </body>
</html> </html>

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save