Library for httpserver

Dependents:   Internet_Piano_v2

Fork of httpServer_with_Ethernt by IOP

Committer:
wiznetw7500
Date:
Tue Nov 28 08:54:11 2017 +0000
Revision:
5:62b15cc96f1b
Parent:
2:dd293a10a772
Internet Piano

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hjjeon 0:e59cc54df17c 1 /* FsHandler.h */
hjjeon 0:e59cc54df17c 2 /*
hjjeon 0:e59cc54df17c 3 Copyright (c) 2013 Henry Leinen (henry[dot]leinen [at] online [dot] de)
hjjeon 0:e59cc54df17c 4
hjjeon 0:e59cc54df17c 5 Permission is hereby granted, free of charge, to any person obtaining a copy
hjjeon 0:e59cc54df17c 6 of this software and associated documentation files (the "Software"), to deal
hjjeon 0:e59cc54df17c 7 in the Software without restriction, including without limitation the rights
hjjeon 0:e59cc54df17c 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
hjjeon 0:e59cc54df17c 9 copies of the Software, and to permit persons to whom the Software is
hjjeon 0:e59cc54df17c 10 furnished to do so, subject to the following conditions:
hjjeon 0:e59cc54df17c 11
hjjeon 0:e59cc54df17c 12 The above copyright notice and this permission notice shall be included in
hjjeon 0:e59cc54df17c 13 all copies or substantial portions of the Software.
hjjeon 0:e59cc54df17c 14
hjjeon 0:e59cc54df17c 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
hjjeon 0:e59cc54df17c 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
hjjeon 0:e59cc54df17c 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
hjjeon 0:e59cc54df17c 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
hjjeon 0:e59cc54df17c 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
hjjeon 0:e59cc54df17c 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
hjjeon 0:e59cc54df17c 21 THE SOFTWARE.
hjjeon 0:e59cc54df17c 22 */
hjjeon 0:e59cc54df17c 23 #ifndef __FSHANDLER_H__
hjjeon 0:e59cc54df17c 24 #define __FSHANDLER_H__
hjjeon 0:e59cc54df17c 25
hjjeon 0:e59cc54df17c 26 #include "mbed.h"
hjjeon 0:e59cc54df17c 27 #include "HTTPRequestHandler.h"
hjjeon 0:e59cc54df17c 28
hjjeon 0:e59cc54df17c 29 #include <map>
hjjeon 0:e59cc54df17c 30 #include <string>
hjjeon 0:e59cc54df17c 31
hjjeon 0:e59cc54df17c 32 /** class HTTPFsRequestHandler serves requests with file-system objects
hjjeon 0:e59cc54df17c 33 */
hjjeon 0:e59cc54df17c 34 class HTTPFsRequestHandler : public HTTPRequestHandler
hjjeon 0:e59cc54df17c 35 {
hjjeon 0:e59cc54df17c 36 std::string m_rootPath;
hjjeon 0:e59cc54df17c 37 std::string m_localPath;
hjjeon 0:e59cc54df17c 38
hjjeon 0:e59cc54df17c 39 public:
hjjeon 0:e59cc54df17c 40 /** constructor for HTTPFsRequestHandler object and stores the request related data locally.
hjjeon 0:e59cc54df17c 41 * the request handling will be initiated from within the constructor.
hjjeon 0:e59cc54df17c 42 * @param rootPath : The path under which the handler was registered.
hjjeon 0:e59cc54df17c 43 * @param localPath : The path which is relative to the registered file system root.
hjjeon 0:e59cc54df17c 44 * @param Msg : Message request information that comes with the request.
hjjeon 0:e59cc54df17c 45 * @param Tcp : The socket connection for communicating with the client.
hjjeon 0:e59cc54df17c 46 */
hjjeon 0:e59cc54df17c 47 HTTPFsRequestHandler(const char* rootPath, const char* localPath, HTTPConnection::HTTPMessage& Msg, TCPSocketConnection& Tcp);
hjjeon 0:e59cc54df17c 48
hjjeon 0:e59cc54df17c 49 /** Destructor
hjjeon 0:e59cc54df17c 50 */
hjjeon 0:e59cc54df17c 51 virtual ~HTTPFsRequestHandler();
hjjeon 0:e59cc54df17c 52
hjjeon 0:e59cc54df17c 53 /** static creation function for this object.
hjjeon 0:e59cc54df17c 54 */
hjjeon 0:e59cc54df17c 55 static inline HTTPRequestHandler* create(const char* rootPath, const char* localPath, HTTPConnection::HTTPMessage& msg, TCPSocketConnection& tcp) { return new HTTPFsRequestHandler(rootPath, localPath, msg, tcp); }
hjjeon 0:e59cc54df17c 56
hjjeon 0:e59cc54df17c 57 /** Handler function to serve GET requests
hjjeon 0:e59cc54df17c 58 */
hjjeon 0:e59cc54df17c 59 virtual int handleGetRequest();
hjjeon 0:e59cc54df17c 60
hjjeon 0:e59cc54df17c 61 /** Handler function to serve PUT requests
hjjeon 0:e59cc54df17c 62 */
hjjeon 0:e59cc54df17c 63 virtual int handlePutRequest();
hjjeon 0:e59cc54df17c 64
hjjeon 0:e59cc54df17c 65 /** Handler function to serve POST requests
hjjeon 0:e59cc54df17c 66 */
hjjeon 0:e59cc54df17c 67 virtual int handlePostRequest();
hjjeon 0:e59cc54df17c 68
hjjeon 0:e59cc54df17c 69 /** Map to register different file system types and associate them with different root paths
hjjeon 0:e59cc54df17c 70 */
hjjeon 0:e59cc54df17c 71 static std::map<const char*, const char*> m_fsMap;
hjjeon 0:e59cc54df17c 72
hjjeon 0:e59cc54df17c 73 /** static function to register a new file system type with a logical root path
hjjeon 0:e59cc54df17c 74 */
hjjeon 0:e59cc54df17c 75 static void mount(const char* requestPath, const char* localPath) { m_fsMap[requestPath] = localPath; }
hjjeon 0:e59cc54df17c 76
hjjeon 0:e59cc54df17c 77 /** Parse a uri string for uri file name and argument:value pairs
hjjeon 0:e59cc54df17c 78 */
hjjeon 0:e59cc54df17c 79 int parseUriArgs(string uri, map<string, string>& args);
hjjeon 0:e59cc54df17c 80
hjjeon 0:e59cc54df17c 81 uint32_t get_http_param_value(char* param_name);
hjjeon 0:e59cc54df17c 82 };
wiznetw7500 5:62b15cc96f1b 83 #endif // __FSHANDLER_H__