Rob Dobson / RdWebServer

Dependents:   RdBlindsServer SpideyWallWeb RdGasUseMonitor

Revision:
15:0865fa4b046a
Parent:
14:4b83670854f0
Child:
17:080f2bed8b36
--- a/RdWebServer.h	Tue May 05 15:05:44 2015 +0000
+++ b/RdWebServer.h	Tue May 05 20:27:33 2015 +0000
@@ -1,5 +1,5 @@
 /* RdWebServer.h
-   Rob Dobson 2013
+   Rob Dobson 2013-2015
    Inspired by Jasper Schuurmans multi-threaded web server for Netduino http://www.schuurmans.cc/multi-threaded-web-server-for-netduino-plus
 */
 #ifndef RD_WEB_SERVER
@@ -52,9 +52,12 @@
 
 //#define SUPPORT_LOCAL_FILESYSTEM 1
 //#define SUPPORT_FOLDER_VIEW 1
+//#define SUPPORT_LOCAL_FILE_CACHE 1
 
 extern RawSerial pc;
 
+#ifdef SUPPORT_LOCAL_FILE_CACHE
+
 class RdFileCacheEntry
 {
     public:
@@ -78,6 +81,8 @@
         int _nFileLen;
 };
 
+#endif
+
 typedef char* (*CmdCallbackType)(int method, char*cmdStr, char* argStr);
 
 class RdWebServerCmdDef
@@ -86,23 +91,27 @@
         static const int CMD_LOCALFILE = 1;
         static const int CMD_CALLBACK = 2;
         static const int CMD_SDORUSBFILE = 3;
-        RdWebServerCmdDef(char* pStr, int cmdType, CmdCallbackType callback, char* substFileName, bool bCacheIfPossible)
+        RdWebServerCmdDef(char* pStr, int cmdType, CmdCallbackType callback, char* subst8dot3FileName = NULL, bool bCacheIfPossible = false)
         {
             _pCmdStr = pStr;
             _cmdType = cmdType;
             _callback = callback;
-            _substFileName[0] = '\0';
-            if (substFileName != NULL)
+#ifdef SUPPORT_LOCAL_FILE_CACHE
+            _subst8dot3FileName[0] = '\0';
+            if (subst8dot3FileName != NULL)
             {
-                strncpy(_substFileName, substFileName, RdFileCacheEntry::CACHE_MAX_FNAME_LEN);
-                _substFileName[RdFileCacheEntry::CACHE_MAX_FNAME_LEN-1] = '\0';
+                strncpy(_subst8dot3FileName, subst8dot3FileName, RdFileCacheEntry::CACHE_MAX_FNAME_LEN);
+                _subst8dot3FileName[RdFileCacheEntry::CACHE_MAX_FNAME_LEN-1] = '\0';
             }
+#endif
             _bCacheIfPossible = bCacheIfPossible;
         };
         char* _pCmdStr;
         int _cmdType;
         CmdCallbackType _callback;
-        char _substFileName[RdFileCacheEntry::CACHE_MAX_FNAME_LEN];
+#ifdef SUPPORT_LOCAL_FILE_CACHE
+        char _subst8dot3FileName[RdFileCacheEntry::CACHE_MAX_FNAME_LEN];
+#endif
         bool _bCacheIfPossible;
 };
 
@@ -120,20 +129,17 @@
         
         bool init(int port, DigitalOut* pStatusLed, char* pBaseWebFolder);
         void run();
-        bool isListening()
-        {
-            return _serverIsListening;
-        };
-        
         void addCommand(char* pCmdStr, int cmdType, CmdCallbackType callback = NULL, char* substFileName = NULL, bool cacheIfPossible = false);
         
     private :
         int _port;
         DigitalOut* _pStatusLed;
-        TCPSocketServer _socketSrv;
-        bool _serverIsListening;
+        TCPSocketServer _serverSocket;
+        bool _initOk;
         std::vector<RdWebServerCmdDef*> _commands;
+#ifdef SUPPORT_LOCAL_FILE_CACHE
         std::vector<RdFileCacheEntry*> _cachedFiles;
+#endif
         bool extractCmdArgs(char* buf, char* pCmdStr, int maxCmdStrLen, char* pArgStr, int maxArgStrLen);
         char* _pBaseWebFolder;
         char _httpHeader[HTTPD_MAX_HDR_LENGTH+1];
@@ -142,7 +148,9 @@
         void handleLocalFileRequest(char* cmdStr, char* argStr, TCPSocketConnection &client, char* httpHeader, bool bCacheIfPossible);
         bool handleSDFileRequest(char* cmdStr, char* argStr, TCPSocketConnection &client, char* httpHeader);
         void handleCGIRequest(char* pUriStr, char* pQueryStr);
+#ifdef SUPPORT_LOCAL_FILE_CACHE
         void sendFromCache(RdFileCacheEntry* pCacheEntry, TCPSocketConnection &client, char* httpHeader);
+#endif
         bool handleReceivedHttp(TCPSocketConnection &client);
 
 };