Refactored: use different cgi for JSON

pull/193/head
Karai Csaba 9 years ago committed by Thorsten von Eicken
parent f75c1acf95
commit 979510681b
  1. 1
      esp-link/main.c
  2. 7
      httpd/httpd.c
  3. 9
      httpd/httpdespfs.c
  4. 4
      web-server/web-server.c
  5. 2
      web-server/web-server.h

@ -100,6 +100,7 @@ HttpdBuiltInUrl builtInUrls[] = {
{ "/mqtt", cgiMqtt, NULL }, { "/mqtt", cgiMqtt, NULL },
#endif #endif
{ "/web-server/upload", cgiWebServerUpload, NULL }, { "/web-server/upload", cgiWebServerUpload, NULL },
{ "*.json", cgiJsonHook, NULL }, //Catch-all cgi JSON queries
{ "*", cgiEspFsHook, NULL }, //Catch-all cgi function for the filesystem { "*", cgiEspFsHook, NULL }, //Catch-all cgi function for the filesystem
{ NULL, NULL, NULL } { NULL, NULL, NULL }
}; };

@ -355,11 +355,14 @@ static void ICACHE_FLASH_ATTR httpdProcessRequest(HttpdConnData *conn) {
if (conn->cgi == NULL) { if (conn->cgi == NULL) {
while (builtInUrls[i].url != NULL) { while (builtInUrls[i].url != NULL) {
int match = 0; int match = 0;
int urlLen = os_strlen(builtInUrls[i].url);
//See if there's a literal match //See if there's a literal match
if (os_strcmp(builtInUrls[i].url, conn->url) == 0) match = 1; if (os_strcmp(builtInUrls[i].url, conn->url) == 0) match = 1;
//See if there's a wildcard match //See if there's a wildcard match
if (builtInUrls[i].url[os_strlen(builtInUrls[i].url) - 1] == '*' && if (builtInUrls[i].url[urlLen - 1] == '*' &&
os_strncmp(builtInUrls[i].url, conn->url, os_strlen(builtInUrls[i].url) - 1) == 0) match = 1; os_strncmp(builtInUrls[i].url, conn->url, urlLen - 1) == 0) match = 1;
else if (builtInUrls[i].url[0] == '*' && ( strlen(conn->url) >= urlLen -1 ) &&
os_strncmp(builtInUrls[i].url + 1, conn->url + strlen(conn->url) - urlLen + 1, urlLen - 1) == 0) match = 1;
if (match) { if (match) {
//os_printf("Is url index %d\n", i); //os_printf("Is url index %d\n", i);
conn->cgiData = NULL; conn->cgiData = NULL;

@ -13,7 +13,6 @@ 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.)
@ -30,14 +29,6 @@ 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) {

@ -84,8 +84,10 @@ void ICACHE_FLASH_ATTR webServerInit()
webServerBrowseFiles(); webServerBrowseFiles();
} }
int ICACHE_FLASH_ATTR webServerProcessJsonQuery(HttpdConnData *connData) int ICACHE_FLASH_ATTR cgiJsonHook(HttpdConnData *connData)
{ {
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
if( !flashConfig.slip_enable ) if( !flashConfig.slip_enable )
{ {
errorResponse(connData, 400, "Slip processing is disabled!"); errorResponse(connData, 400, "Slip processing is disabled!");

@ -19,7 +19,7 @@ void webServerInit();
char * webServerUserPages(); char * webServerUserPages();
int webServerProcessJsonQuery(HttpdConnData *connData); int ICACHE_FLASH_ATTR cgiJsonHook(HttpdConnData *connData);
#endif /* WEB_SERVER_H */ #endif /* WEB_SERVER_H */

Loading…
Cancel
Save