Print dyn vars user handler added

This commit is contained in:
Bogdan Pilyugin 2022-08-18 10:33:27 +02:00
parent 540da33248
commit 7038b80d4f
3 changed files with 34 additions and 13 deletions

View File

@ -43,6 +43,9 @@
#include "esp_eth.h" #include "esp_eth.h"
#include "mbedtls/base64.h" #include "mbedtls/base64.h"
#define MAX_DYNVAR_LENGTH 64
#define MAX_INCFILE_LENGTH 1024
typedef enum typedef enum
{ {
HTTP_IO_DONE = 0u, // Finished with procedure HTTP_IO_DONE = 0u, // Finished with procedure
@ -51,6 +54,15 @@ typedef enum
HTTP_IO_REDIRECT HTTP_IO_REDIRECT
} HTTP_IO_RESULT; } HTTP_IO_RESULT;
typedef struct
{
const char tag[16];
const int taglen;
void (*HandlerRoutine)(char *VarData, void *arg);
} dyn_var_handler_t;
void regHTTPPrintCustom(int (*print_handler));
esp_err_t start_file_server(void); esp_err_t start_file_server(void);
HTTP_IO_RESULT HTTPPostApp(httpd_req_t *req, const char *filename, char *PostData); HTTP_IO_RESULT HTTPPostApp(httpd_req_t *req, const char *filename, char *PostData);
int HTTPPrint(httpd_req_t *req, char* buf, char* var); int HTTPPrint(httpd_req_t *req, char* buf, char* var);

View File

@ -141,6 +141,8 @@ static HTTP_IO_RESULT AfterPostHandler(httpd_req_t *req, const char *filename, c
if (!memcmp(filename, pg_mm, sizeof(pg_mm))) if (!memcmp(filename, pg_mm, sizeof(pg_mm)))
return HTTPPostMemJson(req, PostData); return HTTPPostMemJson(req, PostData);
return HTTP_IO_DONE; return HTTP_IO_DONE;
} }

View File

@ -23,18 +23,12 @@
#include "HTTPServer.h" #include "HTTPServer.h"
#define MAX_DYNVAR_LENGTH 64
#define MAX_INCFILE_LENGTH 1024
// uint32_t UpTime;
static const char *TAG = "HTTPServerPrint"; static const char *TAG = "HTTPServerPrint";
typedef struct
{
const char tag[16];
const int taglen;
void (*HandlerRoutine)(char *VarData, void *arg);
} dyn_var_handler_t;
typedef enum typedef enum
{ {
@ -43,6 +37,14 @@ typedef enum
GW GW
} IP_PRINT_TYPE; } IP_PRINT_TYPE;
//Pointer to extend user implemented print handler
static int (*HTTPPrintCust)(httpd_req_t *req, char *buf, char *var);
void regHTTPPrintCustom(int (*print_handler))
{
HTTPPrintCust = print_handler;
}
static void PrintInterfaceState(char *VarData, void *arg, esp_netif_t *netif) static void PrintInterfaceState(char *VarData, void *arg, esp_netif_t *netif)
{ {
if (netif != NULL && esp_netif_is_netif_up(netif)) if (netif != NULL && esp_netif_is_netif_up(netif))
@ -465,7 +467,7 @@ dyn_var_handler_t HANDLERS_ARRAY[] = {
{ "dns3", sizeof("dns3") - 1, &HTTPPrint_dns3 }, { "dns3", sizeof("dns3") - 1, &HTTPPrint_dns3 },
{ "macadr", sizeof("macadr") - 1, &HTTPPrint_macadr }, { "macadr", sizeof("macadr") - 1, &HTTPPrint_macadr },
{ "apmacadr", sizeof("apmacadr") - 1, &HTTPPrint_apmacadr }, { "apmacadr", sizeof("apmacadr") - 1, &HTTPPrint_apmacadr },
#endif #endif
#if CONFIG_WEBGUIAPP_ETHERNET_ENABLE #if CONFIG_WEBGUIAPP_ETHERNET_ENABLE
/*ETHERNET network*/ /*ETHERNET network*/
@ -479,7 +481,7 @@ dyn_var_handler_t HANDLERS_ARRAY[] = {
{ "bkedns", sizeof("bkedns") - 1, &HTTPPrint_bkedns }, { "bkedns", sizeof("bkedns") - 1, &HTTPPrint_bkedns },
{ "fledns", sizeof("fledns") - 1, &HTTPPrint_fledns }, { "fledns", sizeof("fledns") - 1, &HTTPPrint_fledns },
{ "emacadr", sizeof("emacadr") - 1, &HTTPPrint_emacadr }, { "emacadr", sizeof("emacadr") - 1, &HTTPPrint_emacadr },
#endif #endif
#if CONFIG_WEBGUIAPP_GPRS_ENABLE #if CONFIG_WEBGUIAPP_GPRS_ENABLE
/*GSM modem*/ /*GSM modem*/
@ -496,7 +498,7 @@ dyn_var_handler_t HANDLERS_ARRAY[] = {
{ "bkgsmdns", sizeof("bkgsmdns") - 1, &HTTPPrint_bkgsmdns }, { "bkgsmdns", sizeof("bkgsmdns") - 1, &HTTPPrint_bkgsmdns },
{ "flgsmdns", sizeof("flgsmdns") - 1, &HTTPPrint_flgsmdns }, { "flgsmdns", sizeof("flgsmdns") - 1, &HTTPPrint_flgsmdns },
{ "gsmmac", sizeof("gsmmac") - 1, &HTTPPrint_gsmmac }, { "gsmmac", sizeof("gsmmac") - 1, &HTTPPrint_gsmmac },
#endif #endif
#if CONFIG_WEBGUIAPP_MQTT_ENABLE #if CONFIG_WEBGUIAPP_MQTT_ENABLE
/*MQTT*/ /*MQTT*/
@ -574,7 +576,12 @@ int HTTPPrint(httpd_req_t *req, char *buf, char *var)
} }
} }
if (!fnd) if (!fnd)
{
if (HTTPPrintCust != NULL)
HTTPPrintCust(req, buf, var);
else
HTTPPrint_DEF(VarData, NULL); HTTPPrint_DEF(VarData, NULL);
}
int dLen = strlen(VarData); int dLen = strlen(VarData);
memcpy(buf, VarData, dLen); memcpy(buf, VarData, dLen);
return dLen; return dLen;