justin kim / httpServer-orgel

Dependents:   Internet_Orgel

Fork of httpServer by justin kim

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 #include "HTTPConnection.h"
00029 #include "EthernetInterface.h"
00030 
00031 #include <map>
00032 #include <list>
00033 #include <string>
00034 
00035 /** class HTTPFsRequestHandler serves requests with file-system objects
00036 */
00037 class HTTPFsRequestHandler : public HTTPRequestHandler
00038 {
00039         std::string m_rootPath;
00040         std::string m_localPath;
00041 
00042     public:
00043 
00044         /** constructor for HTTPFsRequestHandler object and stores the request related data locally. 
00045         * the request handling will be initiated from within the constructor.
00046         * @param rootPath : The path under which the handler was registered.
00047         * @param localPath : The path which is relative to the registered file system root.
00048         * @param Msg : Message request information that comes with the request.
00049         * @param Tcp : The socket connection for communicating with the client.
00050         */
00051         HTTPFsRequestHandler(const char* rootPath, const char* localPath, HTTPConnection::HTTPMessage& Msg, TCPSocketConnection& Tcp);
00052         
00053         /** Destructor 
00054         */
00055         virtual ~HTTPFsRequestHandler();
00056   
00057         /** static creation function for this object.
00058         */
00059         static inline HTTPRequestHandler* create(const char* rootPath, const char* localPath, HTTPConnection::HTTPMessage& msg, TCPSocketConnection& tcp) { return new HTTPFsRequestHandler(rootPath, localPath, msg, tcp); }
00060               
00061         /** Handler function to serve GET requests
00062         */
00063         virtual int handleGetRequest();
00064         
00065         /** Handler function to serve PUT requests
00066         */
00067         virtual int handlePutRequest();
00068         
00069         /** Handler function to serve POST requests
00070         */
00071         virtual int handlePostRequest();
00072 
00073         /** Map to register different file system types and associate them with different root paths
00074         */
00075         static std::map<const char*, const char*> m_fsMap;
00076         
00077         /** static function to register a new file system type with a logical root path
00078         */
00079         static void mount(const char* requestPath, const char* localPath) { m_fsMap[requestPath] = localPath; }
00080         
00081         //Test
00082         //static std::list<EthernetInterface> m_eth_list;
00083         static std::map<int, EthernetInterface*> m_eth_list;
00084         static void mount_eth(EthernetInterface* eth) { m_eth_list[0] = eth; }
00085         
00086         /** Parse a uri string for uri file name and argument:value pairs
00087         */
00088         int parseUriArgs(string uri, map<string, string>& args);
00089         
00090         uint32_t get_http_param_value(char* param_name);
00091 };
00092 #endif // __FSHANDLER_H__