PsychichHTTP v2-dev

This commit is contained in:
iranl
2024-12-30 14:37:09 +01:00
parent 2cf5201285
commit 78459c2d08
118 changed files with 5453 additions and 4972 deletions

View File

@@ -1,90 +1,112 @@
/************************************************************
TemplatePrinter Class
A basic templating engine for a stream of text.
This wraps the Arduino Print interface and writes to any
Print interface.
Written by Christopher Andrews (https://github.com/Chris--A)
************************************************************/
/************************************************************
TemplatePrinter Class
A basic templating engine for a stream of text.
This wraps the Arduino Print interface and writes to any
Print interface.
Written by Christopher Andrews (https://github.com/Chris--A)
************************************************************/
#include "TemplatePrinter.h"
void TemplatePrinter::resetParam(bool flush){
if(flush && _inParam){
void TemplatePrinter::resetParam(bool flush)
{
if (flush && _inParam)
{
_stream.write(_delimiter);
if(_paramPos)
if (_paramPos)
_stream.print(_paramBuffer);
}
memset(_paramBuffer, 0, sizeof(_paramBuffer));
_paramPos = 0;
_inParam = false;
}
void TemplatePrinter::flush(){
void TemplatePrinter::flush()
{
resetParam(true);
_stream.flush();
}
size_t TemplatePrinter::write(uint8_t data){
if(data == _delimiter){
size_t TemplatePrinter::write(uint8_t data)
{
if (data == _delimiter)
{
// End of parameter, send to callback
if(_inParam){
if (_inParam)
{
// On false, return the parameter place holder as is: not a parameter
// Bug fix: ignore parameters that are zero length.
if(!_paramPos || !_cb(_stream, _paramBuffer)){
// Bug fix: ignore parameters that are zero length.
if (!_paramPos || !_cb(_stream, _paramBuffer))
{
resetParam(true);
_stream.write(data);
}else{
}
else
{
resetParam(false);
}
// Start collecting parameter
}else{
// Start collecting parameter
}
else
{
_inParam = true;
}
}else{
}
else
{
// Are we collecting
if(_inParam){
if (_inParam)
{
// Is param still valid
if(isalnum(data) || data == '_'){
if (isalnum(data) || data == '_')
{
// Total param len must be 63, 1 for null.
if(_paramPos < sizeof(_paramBuffer) - 1){
if (_paramPos < sizeof(_paramBuffer) - 1)
{
_paramBuffer[_paramPos++] = data;
// Not a valid param
}else{
// Not a valid param
}
else
{
resetParam(true);
}
}else{
}
else
{
resetParam(true);
_stream.write(data);
}
// Just output
}else{
// Just output
}
else
{
_stream.write(data);
}
}
return 1;
}
size_t TemplatePrinter::copyFrom(Stream &stream){
size_t TemplatePrinter::copyFrom(Stream& stream)
{
size_t count = 0;
while(stream.available())
while (stream.available())
count += this->write(stream.read());
return count;
}