2 * Copyright (c) 2017, The OpenThread Authors.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. Neither the name of the copyright holder nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
31 * This file implements the web server of border router
34 #ifndef OTBR_WEB_WEB_SERVICE_WEB_SERVER_
35 #define OTBR_WEB_WEB_SERVICE_WEB_SERVER_
37 #include "openthread-br/config.h"
48 #include <boost/asio/ip/tcp.hpp>
50 #include "web/web-service/wpan_service.hpp"
53 template <class T> class Server;
54 typedef boost::asio::ip::tcp::socket HTTP;
55 } // namespace SimpleWeb
60 typedef SimpleWeb::Server<SimpleWeb::HTTP> HttpServer;
63 * This class implements the http server.
70 * This method is constructor to initialize the WebServer.
76 * This method is destructor to free the WebServer.
82 * This method starts the Web Server.
84 * @param[in] aIfName The pointer to the Thread interface name.
85 * @param[in] aListenAddr The http server listen address, can be nullptr for any address.
86 * @param[in] aPort The port of http server.
89 void StartWebServer(const char *aIfName, const char *aListenAddr, uint16_t aPort);
92 * This method stops the Web Server.
95 void StopWebServer(void);
98 typedef std::string (*HttpRequestCallback)(const std::string &aRequest, void *aUserData);
99 static std::string HandleJoinNetworkRequest(const std::string &aJoinRequest, void *aUserData);
100 static std::string HandleFormNetworkRequest(const std::string &aFormRequest, void *aUserData);
101 static std::string HandleAddPrefixRequest(const std::string &aAddPrefixRequest, void *aUserData);
102 static std::string HandleDeletePrefixRequest(const std::string &aDeletePrefixRequest, void *aUserData);
103 static std::string HandleGetStatusRequest(const std::string &aGetStatusRequest, void *aUserData);
104 static std::string HandleGetAvailableNetworkResponse(const std::string &aGetAvailableNetworkRequest,
106 static std::string HandleCommission(const std::string &aCommissionRequest, void *aUserData);
108 std::string HandleJoinNetworkRequest(const std::string &aJoinRequest);
109 std::string HandleFormNetworkRequest(const std::string &aFormRequest);
110 std::string HandleAddPrefixRequest(const std::string &aAddPrefixRequest);
111 std::string HandleDeletePrefixRequest(const std::string &aDeletePrefixRequest);
112 std::string HandleGetStatusRequest(const std::string &aGetStatusRequest);
113 std::string HandleGetAvailableNetworkResponse(const std::string &aGetAvailableNetworkRequest);
114 std::string HandleCommission(const std::string &aCommissionRequest);
116 void HandleHttpRequest(const char *aUrl, const char *aMethod, HttpRequestCallback aCallback);
117 void ResponseJoinNetwork(void);
118 void ResponseFormNetwork(void);
119 void ResponseAddOnMeshPrefix(void);
120 void ResponseDeleteOnMeshPrefix(void);
121 void ResponseGetStatus(void);
122 void ResponseGetAvailableNetwork(void);
123 void DefaultHttpResponse(void);
124 void ResponseCommission(void);
128 HttpServer * mServer;
129 otbr::Web::WpanService mWpanService;
135 #endif // OTBR_WEB_WEB_SERVICE_WEB_SERVER_