From 21fbbf6a8af70fcf9bc659f71ca4d23b85c82c5a Mon Sep 17 00:00:00 2001 From: Karai Csaba Date: Sat, 7 May 2016 17:41:25 +0200 Subject: [PATCH] Skeleton for JSON queries --- httpd/httpdespfs.c | 9 +++++++++ web-server/web-server.c | 13 ++++++++++--- web-server/web-server.h | 4 ++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/httpd/httpdespfs.c b/httpd/httpdespfs.c index 9321aad..ea443d1 100644 --- a/httpd/httpdespfs.c +++ b/httpd/httpdespfs.c @@ -13,6 +13,7 @@ Connector to let httpd use the espfs filesystem to serve the files in it. * ---------------------------------------------------------------------------- */ #include "httpdespfs.h" +#include "web-server.h" // The static files marked with FLAG_GZIP are compressed and will be served with GZIP compression. // If the client does not advertise that he accepts GZIP send following warning message (telnet users for e.g.) @@ -29,6 +30,14 @@ cgiEspFsHook(HttpdConnData *connData) { char acceptEncodingBuffer[64]; int isGzip; + int urlLen = os_strlen(connData->url); + if( urlLen > 5 ) + { + if( os_strcmp( connData->url+urlLen-5, ".json" ) == 0 ) + { + return webServerProcessJsonQuery(connData); + } + } //os_printf("cgiEspFsHook conn=%p conn->conn=%p file=%p\n", connData, connData->conn, file); if (connData->conn==NULL) { diff --git a/web-server/web-server.c b/web-server/web-server.c index 0d83eb5..862436e 100644 --- a/web-server/web-server.c +++ b/web-server/web-server.c @@ -2,6 +2,7 @@ #include "espfs.h" #include "config.h" +#include "cgi.h" char * webServerPages = NULL; @@ -21,7 +22,7 @@ void ICACHE_FLASH_ATTR webServerBrowseFiles() espFsIteratorInit(userPageCtx, &it); while( espFsIteratorNext(&it) ) { - int nlen = strlen(it.name); + int nlen = os_strlen(it.name); if( nlen >= 6 ) { if( os_strcmp( it.name + nlen-5, ".html" ) == 0 ) @@ -50,7 +51,7 @@ void ICACHE_FLASH_ATTR webServerBrowseFiles() os_strcat(buffer, "\""); } } - if( strlen(buffer) > 600 ) + if( os_strlen(buffer) > 600 ) break; } } @@ -58,7 +59,7 @@ void ICACHE_FLASH_ATTR webServerBrowseFiles() if( webServerPages != NULL ) os_free( webServerPages ); - int len = strlen(buffer) + 1; + int len = os_strlen(buffer) + 1; webServerPages = (char *)os_malloc( len ); os_memcpy( webServerPages, buffer, len ); } @@ -73,3 +74,9 @@ void ICACHE_FLASH_ATTR webServerInit() webServerBrowseFiles(); } +int ICACHE_FLASH_ATTR webServerProcessJsonQuery(HttpdConnData *connData) +{ + os_printf("URL: %s\n", connData->url); + errorResponse(connData, 400, "Slip protocol is not enabled!"); + return HTTPD_CGI_DONE; +} diff --git a/web-server/web-server.h b/web-server/web-server.h index 7716b33..2fdd236 100644 --- a/web-server/web-server.h +++ b/web-server/web-server.h @@ -3,9 +3,13 @@ #include +#include "httpd.h" + void webServerInit(); char * webServerUserPages(); +int webServerProcessJsonQuery(HttpdConnData *connData); + #endif /* WEB_SERVER_H */