Commit 29d59876 authored by Neal MIller's avatar Neal MIller Committed by Me No Dev

Webserver library - fix logging (#2355) (#2359)

* Webserver fix logging (#1)

* Change logging to use esp32-hal-log.h

fixes #2355

* adjust log parameter output positions, reduce lines

The DEBUG_ESP method used less lines than I originally set `log_v` to use when displaying the details of the received params ("@" and "=" indexes, and File info on a single line)
parent 8cbc60ed
This diff is collapsed.
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <Arduino.h> #include <Arduino.h>
#include <esp32-hal-log.h>
#include <libb64/cencode.h> #include <libb64/cencode.h>
#include "WiFiServer.h" #include "WiFiServer.h"
#include "WiFiClient.h" #include "WiFiClient.h"
...@@ -30,12 +31,6 @@ ...@@ -30,12 +31,6 @@
#include "detail/RequestHandlersImpl.h" #include "detail/RequestHandlersImpl.h"
#include "mbedtls/md5.h" #include "mbedtls/md5.h"
//#define DEBUG_ESP_HTTP_SERVER
#ifdef DEBUG_ESP_PORT
#define DEBUG_OUTPUT DEBUG_ESP_PORT
#else
#define DEBUG_OUTPUT Serial
#endif
static const char AUTHORIZATION_HEADER[] = "Authorization"; static const char AUTHORIZATION_HEADER[] = "Authorization";
static const char qop_auth[] = "qop=auth"; static const char qop_auth[] = "qop=auth";
...@@ -163,9 +158,7 @@ bool WebServer::authenticate(const char * username, const char * password){ ...@@ -163,9 +158,7 @@ bool WebServer::authenticate(const char * username, const char * password){
delete[] encoded; delete[] encoded;
} else if(authReq.startsWith(F("Digest"))) { } else if(authReq.startsWith(F("Digest"))) {
authReq = authReq.substring(7); authReq = authReq.substring(7);
#ifdef DEBUG_ESP_HTTP_SERVER log_v("%s", authReq.c_str());
DEBUG_OUTPUT.println(authReq);
#endif
String _username = _extractParam(authReq,F("username=\"")); String _username = _extractParam(authReq,F("username=\""));
if(!_username.length() || _username != String(username)) { if(!_username.length() || _username != String(username)) {
authReq = ""; authReq = "";
...@@ -193,9 +186,7 @@ bool WebServer::authenticate(const char * username, const char * password){ ...@@ -193,9 +186,7 @@ bool WebServer::authenticate(const char * username, const char * password){
_cnonce = _extractParam(authReq, F("cnonce=\"")); _cnonce = _extractParam(authReq, F("cnonce=\""));
} }
String _H1 = md5str(String(username) + ':' + _realm + ':' + String(password)); String _H1 = md5str(String(username) + ':' + _realm + ':' + String(password));
#ifdef DEBUG_ESP_HTTP_SERVER log_v("Hash of user:realm:pass=%s", _H1.c_str());
DEBUG_OUTPUT.println("Hash of user:realm:pass=" + _H1);
#endif
String _H2 = ""; String _H2 = "";
if(_currentMethod == HTTP_GET){ if(_currentMethod == HTTP_GET){
_H2 = md5str(String(F("GET:")) + _uri); _H2 = md5str(String(F("GET:")) + _uri);
...@@ -208,18 +199,14 @@ bool WebServer::authenticate(const char * username, const char * password){ ...@@ -208,18 +199,14 @@ bool WebServer::authenticate(const char * username, const char * password){
}else{ }else{
_H2 = md5str(String(F("GET:")) + _uri); _H2 = md5str(String(F("GET:")) + _uri);
} }
#ifdef DEBUG_ESP_HTTP_SERVER log_v("Hash of GET:uri=%s", _H2.c_str());
DEBUG_OUTPUT.println("Hash of GET:uri=" + _H2);
#endif
String _responsecheck = ""; String _responsecheck = "";
if(authReq.indexOf(FPSTR(qop_auth)) != -1) { if(authReq.indexOf(FPSTR(qop_auth)) != -1) {
_responsecheck = md5str(_H1 + ':' + _nonce + ':' + _nc + ':' + _cnonce + F(":auth:") + _H2); _responsecheck = md5str(_H1 + ':' + _nonce + ':' + _nc + ':' + _cnonce + F(":auth:") + _H2);
} else { } else {
_responsecheck = md5str(_H1 + ':' + _nonce + ':' + _H2); _responsecheck = md5str(_H1 + ':' + _nonce + ':' + _H2);
} }
#ifdef DEBUG_ESP_HTTP_SERVER log_v("The Proper response=%s", _responsecheck.c_str());
DEBUG_OUTPUT.println("The Proper response=" +_responsecheck);
#endif
if(_response == _responsecheck){ if(_response == _responsecheck){
authReq = ""; authReq = "";
return true; return true;
...@@ -294,9 +281,7 @@ void WebServer::handleClient() { ...@@ -294,9 +281,7 @@ void WebServer::handleClient() {
return; return;
} }
#ifdef DEBUG_ESP_HTTP_SERVER log_v("New client");
DEBUG_OUTPUT.println("New client");
#endif
_currentClient = client; _currentClient = client;
_currentStatus = HC_WAIT_READ; _currentStatus = HC_WAIT_READ;
...@@ -614,17 +599,13 @@ void WebServer::onNotFound(THandlerFunction fn) { ...@@ -614,17 +599,13 @@ void WebServer::onNotFound(THandlerFunction fn) {
void WebServer::_handleRequest() { void WebServer::_handleRequest() {
bool handled = false; bool handled = false;
if (!_currentHandler){ if (!_currentHandler){
#ifdef DEBUG_ESP_HTTP_SERVER log_e("request handler not found");
DEBUG_OUTPUT.println("request handler not found");
#endif
} }
else { else {
handled = _currentHandler->handle(*this, _currentMethod, _currentUri); handled = _currentHandler->handle(*this, _currentMethod, _currentUri);
#ifdef DEBUG_ESP_HTTP_SERVER
if (!handled) { if (!handled) {
DEBUG_OUTPUT.println("request handler failed to handle request"); log_e("request handler failed to handle request");
} }
#endif
} }
if (!handled && _notFoundHandler) { if (!handled && _notFoundHandler) {
_notFoundHandler(); _notFoundHandler();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment