Adaptation of the HttpServer by user yueee_yt. This version has improved handling of the HTTP headers (**NOTE**: There are limitations with this implementation and it is not fully functional. Use it only as a starting point.)

Dependents:   DMSupport DMSupport DMSupport DMSupport

Fork of DM_HttpServer by EmbeddedArtists AB

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers <title>FSHandler.h Source File</title>

FSHandler.h

00001 /*
00002 Permission is hereby granted, free of charge, to any person obtaining a copy
00003 of this software and associated documentation files (the "Software"), to deal
00004 in the Software without restriction, including without limitation the rights
00005 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00006 copies of the Software, and to permit persons to whom the Software is
00007 furnished to do so, subject to the following conditions:
00008  
00009 The above copyright notice and this permission notice shall be included in
00010 all copies or substantial portions of the Software.
00011  
00012 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00013 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00014 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00015 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00016 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00017 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00018 THE SOFTWARE.
00019 */
00020 
00021 #ifndef FS_HANDLER_H
00022 #define FS_HANDLER_H
00023 
00024 #include "../HTTPRequestHandler.h"
00025 #include "mbed.h"
00026 #include "EthernetInterface.h"
00027 #include <map>
00028 using std::map;
00029 
00030 #include <string>
00031 using std::string;
00032 
00033 class FSHandler : public HTTPRequestHandler
00034 {
00035 public:
00036   FSHandler(const char* rootPath, const char* path, TCPSocket* pTCPSocketConnection);
00037   virtual ~FSHandler();
00038   
00039   static void mount(const string& fsPath, const string& rootPath);
00040 
00041 //protected:
00042  static inline HTTPRequestHandler* inst(const char* rootPath, const char* path, TCPSocket* pTCPSocketConnection) { return new FSHandler(rootPath, path, pTCPSocketConnection); } //if we ever could do static virtual functions, this would be one
00043 
00044   virtual void doGet();
00045   virtual void doPost();
00046   virtual void doHead();
00047   
00048   virtual void onReadable(); //Data has been read
00049   virtual void onWriteable(); //Data has been written & buf is free
00050   virtual void onClose(); //Connection is closing
00051   
00052 private:
00053   FILE* m_fp;
00054   bool m_err404;
00055   static map<string,string> m_lFsPath;
00056 };
00057 
00058 #endif