Single instance HTTP Server using new Ethernet Interface.

Dependents:   EthHTTPServer if201410_section5 _PE2E_12-04_EthernetInterfaceServer MGAS_GR_Peach ... more

Fork of WiFlyHTTPServer by Henry Leinen

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers FsHandler.h Source File

FsHandler.h

00001 /* FsHandler.h */
00002 /*
00003 Copyright (c) 2013 Henry Leinen (henry[dot]leinen [at] online [dot] de)
00004  
00005 Permission is hereby granted, free of charge, to any person obtaining a copy
00006 of this software and associated documentation files (the "Software"), to deal
00007 in the Software without restriction, including without limitation the rights
00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009 copies of the Software, and to permit persons to whom the Software is
00010 furnished to do so, subject to the following conditions:
00011  
00012 The above copyright notice and this permission notice shall be included in
00013 all copies or substantial portions of the Software.
00014  
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00021 THE SOFTWARE.
00022 */
00023 #ifndef __FSHANDLER_H__
00024 #define __FSHANDLER_H__
00025 
00026 #include "mbed.h"
00027 #include "HTTPRequestHandler.h"
00028 
00029 #include <map>
00030 #include <string>
00031 
00032 /** class HTTPFsRequestHandler serves requests with file-system objects
00033 */
00034 class HTTPFsRequestHandler : public HTTPRequestHandler
00035 {
00036         std::string m_rootPath;
00037         std::string m_localPath;
00038 
00039     public:
00040         /** constructor for HTTPFsRequestHandler object and stores the request related data locally. 
00041         * the request handling will be initiated from within the constructor.
00042         * @param rootPath : The path under which the handler was registered.
00043         * @param localPath : The path which is relative to the registered file system root.
00044         * @param Msg : Message request information that comes with the request.
00045         * @param Tcp : The socket connection for communicating with the client.
00046         */
00047         HTTPFsRequestHandler(const char* rootPath, const char* localPath, HTTPConnection::HTTPMessage& Msg, TCPSocketConnection& Tcp);
00048         
00049         /** Destructor 
00050         */
00051         virtual ~HTTPFsRequestHandler();
00052   
00053         /** static creation function for this object.
00054         */
00055         static inline HTTPRequestHandler* create(const char* rootPath, const char* localPath, HTTPConnection::HTTPMessage& msg, TCPSocketConnection& tcp) { return new HTTPFsRequestHandler(rootPath, localPath, msg, tcp); }
00056               
00057         /** Handler function to serve GET requests
00058         */
00059         virtual int handleGetRequest();
00060         
00061         /** Handler function to serve PUT requests
00062         */
00063         virtual int handlePutRequest();
00064         
00065         /** Handler function to serve POST requests
00066         */
00067         virtual int handlePostRequest();
00068 
00069         /** Map to register different file system types and associate them with different root paths
00070         */
00071         static std::map<const char*, const char*> m_fsMap;
00072         
00073         /** static function to register a new file system type with a logical root path
00074         */
00075         static void mount(const char* requestPath, const char* localPath) { m_fsMap[requestPath] = localPath; }
00076         
00077         /** Parse a uri string for uri file name and argument:value pairs
00078         */
00079         int parseUriArgs(string uri, map<string, string>& args);
00080 };
00081 #endif // __FSHANDLER_H__