diff --git a/script/_nginx_configure b/script/_nginx_server_install similarity index 98% rename from script/_nginx_configure rename to script/_nginx_server_install index f7605032223..eaf850f4721 100644 --- a/script/_nginx_configure +++ b/script/_nginx_server_install @@ -27,7 +27,7 @@ # POSSIBILITY OF SUCH DAMAGE. # -nginx_configure() +nginx_server_install() { if command -v nginx; then diff --git a/script/bootstrap b/script/bootstrap index 8d82121fb9f..7a75af84c6f 100755 --- a/script/bootstrap +++ b/script/bootstrap @@ -117,7 +117,7 @@ install_packages_rpm() install_packages_brew() { - brew install boost cmake cpputest dbus jsoncpp ninja nginx + brew install cmake cpputest dbus ninja nginx } install_packages_source() diff --git a/script/setup b/script/setup index 5c53c725c2e..9ed68caf16e 100755 --- a/script/setup +++ b/script/setup @@ -41,7 +41,7 @@ . script/_swapfile . script/_sudo_extend . script/_disable_services -. script/_nginx_configure +. script/_nginx_server_install main() { @@ -61,7 +61,7 @@ main() dns64_install network_manager_install dhcpv6_pd_install - nginx_configure + nginx_server_install otbr_install . "$AFTER_HOOK" } diff --git a/src/rest/connection.cpp b/src/rest/connection.cpp index 4648b6ee4df..92af98c07de 100644 --- a/src/rest/connection.cpp +++ b/src/rest/connection.cpp @@ -201,6 +201,7 @@ void Connection::ProcessWaitRead(fd_set &aReadFdSet) // Check second failure situation : received = -1 error(indicates that our system call read raise an error ) // then try to send back a response that there is an internal error. VerifyOrExit(received > 0 || (received == -1 && (err == EAGAIN || err == EWOULDBLOCK)), error = OTBR_ERROR_REST); + exit: if (error != OTBR_ERROR_NONE) diff --git a/src/rest/frontend/index.html b/src/rest/frontend/index.html index a32ec33a705..1ca911d2cbf 100644 --- a/src/rest/frontend/index.html +++ b/src/rest/frontend/index.html @@ -334,7 +334,7 @@

Commission

- + @@ -343,18 +343,18 @@

Commission

-
+
-
+
-
+
diff --git a/src/rest/frontend/res/js/app.js b/src/rest/frontend/res/js/app.js index a3e352c8004..3875af069cf 100644 --- a/src/rest/frontend/res/js/app.js +++ b/src/rest/frontend/res/js/app.js @@ -122,24 +122,24 @@ $scope.isLoading = false; $scope.showScanAlert = function(ev,response) { - var text; + var alertMessage; if (response.status == 200) { - text = 'No available thread network now' + alertMessage = 'No available thread network now' } else { if ('ErrorDescription' in response.data) { - text = response.data.ErrorDescription; + alertMessage = response.data.ErrorDescription; } else if ('ErorMessage' in response.data) { - text= response.data.ErorMessage; + alertMessage= response.data.ErorMessage; } else { - text = 'Undefined response'; + alertMessage = 'Undefined response'; } } @@ -148,31 +148,31 @@ .parent(angular.element(document.querySelector('#popupContainer'))) .clickOutsideToClose(true) .title('Information') - .textContent(text) + .textContent(alertMessage) .ariaLabel('Alert Dialog Demo') .ok('Okay') ); }; $scope.showStatusAlert = function(ev,response) { - var text; + var alertMessage; if ('ErrorDescription' in response.data) { - text = response.data.ErrorDescription; + alertMessage = response.data.ErrorDescription; } else if ('ErrorMessage' in response.data) { - text= response.data.ErrorMessage ; + alertMessage= response.data.ErrorMessage ; } else { - text = 'Undefined response'; + alertMessage = 'Undefined response'; } $mdDialog.show( $mdDialog.alert() .parent(angular.element(document.querySelector('#popupContainer'))) .clickOutsideToClose(true) .title('Information') - .textContent(text) + .textContent(alertMessage) .ariaLabel('Alert Dialog Demo') .ok('Okay') ); @@ -180,7 +180,7 @@ $scope.showPanels = function(index) { $scope.headerTitle = $scope.menu[index].title; - for (var i = 0; i <= 6; i++) { + for (var i = 0; i < 7; i++) { $scope.menu[i].show = false; } $scope.menu[index].show = true; @@ -275,24 +275,24 @@ $scope.showAlert = function(ev, response) { - var text; + var alertMessage; if (response.status == 200) { - text = 'Successful' + alertMessage = 'Successful' } else { if ('ErrorDescription' in response.data) { - text = response.data.ErrorDescription; + alertMessage = response.data.ErrorDescription; } else if ('ErorMessage' in response.data) { - text= response.data.ErorMessage; + alertMessage= response.data.ErorMessage; } else { - text = 'Failed bacause of Undefined response'; + alertMessage = 'Failed bacause of Undefined response'; } } @@ -301,7 +301,7 @@ .parent(angular.element(document.querySelector('#popupContainer'))) .clickOutsideToClose(true) .title('Information') - .textContent('Join operation is ' + text) + .textContent('Join operation is ' + alertMessage) .ariaLabel('Alert Dialog Demo') .ok('Okay') .targetEvent(ev) @@ -411,24 +411,24 @@ }; $scope.showAlert = function(ev, operation, response) { - var text; + var alertMessage; if (response.status == 200) { - text = 'Successful'; + alertMessage = 'Successful'; } else { if ('ErrorDescription' in response.data) { - text = response.data.ErrorDescription; + alertMessage = response.data.ErrorDescription; } else if ('ErorMessage' in response.data) { - text= response.data.ErorMessage; + alertMessage= response.data.ErorMessage; } else { - text = 'Failed bacause of Undefined response'; + alertMessage = 'Failed bacause of Undefined response'; } } @@ -437,7 +437,7 @@ .parent(angular.element(document.querySelector('#popupContainer'))) .clickOutsideToClose(true) .title('Information') - .textContent(operation + ' operation is ' + text) + .textContent(operation + ' operation is ' + alertMessage) .ariaLabel('Alert Dialog Demo') .ok('Okay') .targetEvent(ev) @@ -524,16 +524,14 @@ httpRequest.then(function successCallback(response) { $scope.showAlert(event, 'Commission', response); - ev.target.disabled = false; + }, function errorCallback(response){ $scope.showAlert(event, 'Commission', response); }); }; - - // Basic information line $scope.basicInfo = { 'NetworkName' : 'Unknown', @@ -546,11 +544,8 @@ $scope.nodeDetailInfo = 'Unknown'; // For response of Diagnostic $scope.networksDiagInfo = ''; - - // 0 : not call topology - // 1 : is loading - // 2 : topology is ready - $scope.graphState = 0; + $scope.topologyIsReady = false; + $scope.topologyIsLoading = false; $scope.detailList = { 'ExtAddress': { 'title': false, 'content': true }, @@ -599,7 +594,7 @@ $scope.detailList[key]['content'] = !$scope.detailList[key]['content'] } - $scope.intToHexString = function(num , len){ + $scope.intToHexString = function(num, len){ var value; value = num.toString(16); @@ -610,24 +605,24 @@ } $scope.showTopologyAlert = function(ev,response) { - var text; + var alertMessage; if (response.status == 200) { - text = 'Empty diagnostic information returned, please check and try again later' + alertMessage = 'Empty diagnostic information returned, please check and try again later' } else { if ('ErrorDescription' in response.data) { - text = response.data.ErrorDescription; + alertMessage = response.data.ErrorDescription; } else if ('ErorMessage' in response.data) { - text= response.data.ErorMessage; + alertMessage= response.data.ErorMessage; } else { - text = 'Undefined response'; + alertMessage = 'Undefined response'; } } @@ -636,7 +631,7 @@ .parent(angular.element(document.querySelector('#popupContainer'))) .clickOutsideToClose(true) .title('Information') - .textContent(text) + .textContent(alertMessage) .ariaLabel('Alert Dialog Demo') .ok('Okay') ); @@ -645,7 +640,8 @@ $scope.showTopology = function(event) { // Is loading - $scope.graphState = 1; + $scope.topologyIsLoading = true; + $scope.topologyIsReady = false; $scope.graphInfo = { 'nodes': [], 'links': [] @@ -655,18 +651,21 @@ { $scope.topology(response); // Loads successfully - $scope.graphState = 2; + $scope.topologyIsLoading = false; + $scope.topologyIsReady = true; } else{ // Not show anything - $scope.graphState = 0; + $scope.topologyIsReady = false; + $scope.topologyIsLoading = false; $scope.showTopologyAlert(event,response); } }, function errorCallback(response){ $scope.showTopologyAlert(event,response); // Not show anything - $scope.graphState = 0; + $scope.topologyIsReady = false; + $scope.topologyIsLoading = false; } @@ -700,7 +699,7 @@ rloc = parseInt(diagOfNode['Rloc16'],16).toString(16); nodeMap[rloc] = count; - if ( diagOfNode['RouteId'] == diagOfNode['LeaderData']['LeaderRouterId']) { + if (diagOfNode['RouteId'] == diagOfNode['LeaderData']['LeaderRouterId']) { diagOfNode['Role'] = 'Leader'; } else { @@ -722,7 +721,7 @@ src = 0; // Construct links - for (var diagOfNode of $scope.networksDiagInfo) { + for (diagOfNode of $scope.networksDiagInfo) { if ('ChildTable' in diagOfNode) { // Link bewtwen routers for (linkNode of diagOfNode['Route']['RouteData']) { @@ -733,8 +732,6 @@ $scope.graphInfo.links.push({ 'source': src, 'target': dist, - 'weight': 1, - 'type': 0, 'linkInfo': { 'inQuality': linkNode['LinkQualityIn'], 'outQuality': linkNode['LinkQualityOut'] @@ -760,8 +757,6 @@ $scope.graphInfo.links.push({ 'source': src, 'target': count, - 'weight': 1, - 'type': 1, 'linkInfo': { 'Timeout': childInfo['Timeout'], 'Mode': childInfo['Mode'] @@ -1028,7 +1023,7 @@ .style('stroke', '#f39191') .style('stroke-width', '1px'); $scope.$apply(function() { - $scope.nodeDetailInfo = item ; + $scope.nodeDetailInfo = item; $scope.updateDetailLabel(); }); }); diff --git a/src/rest/json.cpp b/src/rest/json.cpp index 12ed74c41ff..0c080842fc9 100644 --- a/src/rest/json.cpp +++ b/src/rest/json.cpp @@ -627,7 +627,7 @@ std::string Error2JsonString(HttpStatusCode aErrorCode, std::string aErrorMessag return ret; } -bool JsonString2NetworkConfiguration(std::string aString, NetworkConfiguration &aNetwork) +bool JsonString2NetworkConfiguration(std::string &aString, NetworkConfiguration &aNetwork) { cJSON *value; cJSON *jsonOut; @@ -672,6 +672,8 @@ bool JsonString2NetworkConfiguration(std::string aString, NetworkConfiguration & exit: + cJSON_Delete(jsonOut); + return ret; } @@ -693,6 +695,8 @@ bool JsonString2String(std::string aString, std::string aKey, std::string &aValu ret = false; } + cJSON_Delete(jsonOut); + return ret; } bool JsonString2Bool(std::string aString, std::string aKey, bool &aValue) @@ -715,6 +719,8 @@ bool JsonString2Bool(std::string aString, std::string aKey, bool &aValue) exit: + cJSON_Delete(jsonOut); + return ret; } @@ -736,6 +742,8 @@ bool JsonString2Int(std::string aString, std::string aKey, int32_t &aValue) ret = false; } + cJSON_Delete(jsonOut); + return ret; } diff --git a/src/rest/json.hpp b/src/rest/json.hpp index b13acdfe616..b80ef6ff7b2 100644 --- a/src/rest/json.hpp +++ b/src/rest/json.hpp @@ -104,7 +104,7 @@ std::string Node2JsonString(const NodeInfo &aNode); /** * This method formats a vector including serveral Diagnostic object to a Json array and serialize it to a string. * - * @param[in] aDiagSet A vector including serveral Diagnostic object. + * @param[in] aDiagSet A vector including serveral Diagnostic object. * * @returns A string serlialized by a Json array. * @@ -124,7 +124,7 @@ std::string IpAddr2JsonString(const otIp6Address &aAddress); /** * This method formats extracts prefixes from a list of config object and format them as Json Array. * - * @param[in] aConfig an array of config object. + * @param[in] aConfig An array of config object. * * @returns A string serlialized by a Json Array. * @@ -224,7 +224,7 @@ std::string Network2JsonString(const otOperationalDataset &aDataset); /** * This method formats an error code and an error message to a Json object and serialize it to a string. * - * @param[in] aErrorCode Error code such as '404'. + * @param[in] aErrorCode An enum HttpStatusCode such as '404'. * @param[in] aErrorMessage Error message such as '404 Not Found'. * @param[in] aDescription Detailed error information. * @@ -236,20 +236,20 @@ std::string Error2JsonString(HttpStatusCode aErrorCode, std::string aErrorMessag /** * This method decodes a json object to a NetworkConfiguration object . * - * @param[in] aString a string contains Json object. + * @param[in] aString A string contains Json object. * @param[out] aNetwork A reference to a NetworkConfiguration instance that could be set within this method. * * @returns A bool value that indicates whether the string could be decoded to the NetworkConfiguration object * */ -bool JsonString2NetworkConfiguration(std::string aString, NetworkConfiguration &aNetwork); +bool JsonString2NetworkConfiguration(std::string &aString, NetworkConfiguration &aNetwork); /** * This method decodes a json object to a NetworkConfiguration object . * - * @param[in] aString a string contains Json object. + * @param[in] aString A string contains Json object. * @param[in] aKey The key that may exist in the Json object. - * @param[inout] aValue the string that is the value of the key in this Json object. + * @param[inout] aValue The string that is the value of the key in this Json object. * * @returns A bool value that indicates whether the key exist in this Json object. * @@ -259,9 +259,9 @@ bool JsonString2String(std::string aString, std::string aKey, std::string &aValu /** * This method decodes a json object to a bool value . * - * @param[in] aString a string contains Json object. + * @param[in] aString A string contains Json object. * @param[in] aKey The key that may exist in the Json object. - * @param[inout] aValue the bool value that is the value of the key in this Json object. + * @param[inout] aValue The bool value that is the value of the key in this Json object. * * @returns A bool value that indicates whether the key exist in this Json object. * @@ -271,11 +271,11 @@ bool JsonString2Bool(std::string aString, std::string aKey, bool &aValue); /** * This method decodes a json object to a bool value . * - * @param[in] aString a string contains Json object. + * @param[in] aString A string contains Json object. * @param[in] aKey The key that may exist in the Json object. - * @param[inout] aValue the integer value that is the value of the key in this Json object. + * @param[inout] aValue The integer value that is the value of the key in this Json object. * - * @returns An bool value that indicates whether the key exist in this Json object. + * @returns A bool value that indicates whether the key exist in this Json object. * */ bool JsonString2Int(std::string aString, std::string aKey, int32_t &aValue); diff --git a/src/rest/request.hpp b/src/rest/request.hpp index 110539b683f..e95efef2dbf 100644 --- a/src/rest/request.hpp +++ b/src/rest/request.hpp @@ -105,7 +105,7 @@ class Request /** * This method returns the HTTP method of this request. * - * @returns A enum class representing HTTP method. + * @returns An enum class representing HTTP method. */ HttpMethod GetMethod() const; diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index 829b11e4eb3..8e8aaf77a23 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -27,7 +27,7 @@ # add_subdirectory(openthread) -if(OTBR_WEB) +if(OTBR_REST) add_subdirectory(cJSON) add_subdirectory(http-parser) endif()