Skeleton for JSON queries

pull/193/head
Karai Csaba 9 years ago committed by Thorsten von Eicken
parent 3239a2493f
commit 21fbbf6a8a
  1. 9
      httpd/httpdespfs.c
  2. 13
      web-server/web-server.c
  3. 4
      web-server/web-server.h

@ -13,6 +13,7 @@ Connector to let httpd use the espfs filesystem to serve the files in it.
* ---------------------------------------------------------------------------- * ----------------------------------------------------------------------------
*/ */
#include "httpdespfs.h" #include "httpdespfs.h"
#include "web-server.h"
// The static files marked with FLAG_GZIP are compressed and will be served with GZIP compression. // 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.) // 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]; char acceptEncodingBuffer[64];
int isGzip; 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); //os_printf("cgiEspFsHook conn=%p conn->conn=%p file=%p\n", connData, connData->conn, file);
if (connData->conn==NULL) { if (connData->conn==NULL) {

@ -2,6 +2,7 @@
#include "espfs.h" #include "espfs.h"
#include "config.h" #include "config.h"
#include "cgi.h"
char * webServerPages = NULL; char * webServerPages = NULL;
@ -21,7 +22,7 @@ void ICACHE_FLASH_ATTR webServerBrowseFiles()
espFsIteratorInit(userPageCtx, &it); espFsIteratorInit(userPageCtx, &it);
while( espFsIteratorNext(&it) ) while( espFsIteratorNext(&it) )
{ {
int nlen = strlen(it.name); int nlen = os_strlen(it.name);
if( nlen >= 6 ) if( nlen >= 6 )
{ {
if( os_strcmp( it.name + nlen-5, ".html" ) == 0 ) if( os_strcmp( it.name + nlen-5, ".html" ) == 0 )
@ -50,7 +51,7 @@ void ICACHE_FLASH_ATTR webServerBrowseFiles()
os_strcat(buffer, "\""); os_strcat(buffer, "\"");
} }
} }
if( strlen(buffer) > 600 ) if( os_strlen(buffer) > 600 )
break; break;
} }
} }
@ -58,7 +59,7 @@ void ICACHE_FLASH_ATTR webServerBrowseFiles()
if( webServerPages != NULL ) if( webServerPages != NULL )
os_free( webServerPages ); os_free( webServerPages );
int len = strlen(buffer) + 1; int len = os_strlen(buffer) + 1;
webServerPages = (char *)os_malloc( len ); webServerPages = (char *)os_malloc( len );
os_memcpy( webServerPages, buffer, len ); os_memcpy( webServerPages, buffer, len );
} }
@ -73,3 +74,9 @@ void ICACHE_FLASH_ATTR webServerInit()
webServerBrowseFiles(); 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;
}

@ -3,9 +3,13 @@
#include <esp8266.h> #include <esp8266.h>
#include "httpd.h"
void webServerInit(); void webServerInit();
char * webServerUserPages(); char * webServerUserPages();
int webServerProcessJsonQuery(HttpdConnData *connData);
#endif /* WEB_SERVER_H */ #endif /* WEB_SERVER_H */

Loading…
Cancel
Save