Skip to content

Commit

Permalink
resolve conflicts with the master branch
Browse files Browse the repository at this point in the history
  • Loading branch information
wgtdkp committed Oct 22, 2020
1 parent c0d74ae commit 79443b0
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 79 deletions.
22 changes: 13 additions & 9 deletions etc/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,23 @@ FROM ubuntu:bionic

ARG OT_BACKBONE_CI
ARG OTBR_OPTIONS
ARG DNS64
ARG NAT64
ARG REFERENCE_DEVICE
ARG RELEASE

ENV OT_BACKBONE_CI=${OT_BACKBONE_CI}
ENV OT_BACKBONE_CI=${OT_BACKBONE_CI:-0}
ENV OTBR_OPTIONS=${OTBR_OPTIONS}
ENV DEBIAN_FRONTEND noninteractive
ENV PLATFORM ubuntu
ENV REFERENCE_DEVICE=${REFERENCE_DEVICE}
ENV RELEASE 1
ENV NAT64 1
ENV DNS64 1
ENV REFERENCE_DEVICE=${REFERENCE_DEVICE:-0}
ENV RELEASE=${RELEASE:-1}
ENV NAT64=${NAT64:-1}
ENV DNS64=${DNS64:-1}
ENV DOCKER 1

RUN env

COPY . /app
WORKDIR /app

Expand All @@ -51,10 +56,9 @@ ENV OTBR_DOCKER_REQS sudo
ENV OTBR_DOCKER_DEPS git ca-certificates

# Required and installed during build (script/bootstrap), could be removed
ENV OTBR_BUILD_DEPS \
apt-utils \
build-essential \
psmisc
ENV OTBR_BUILD_DEPS apt-utils build-essential psmisc ninja-build cmake wget ca-certificates \
libreadline-dev libncurses-dev libcpputest-dev libdbus-1-dev libavahi-common-dev \
libavahi-client-dev libboost-dev libboost-filesystem-dev libboost-system-dev libjsoncpp-dev

# Required for OpenThread Backbone CI
ENV OTBR_OT_BACKBONE_CI_DEPS curl ca-certificates
Expand Down
5 changes: 1 addition & 4 deletions script/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ install_packages_apt()
sudo apt-get install --no-install-recommends -y libdbus-1-dev

# mDNS
sudo apt-get install --no-install-recommends -y libavahi-common-dev libavahi-client-dev avahi-daemon
sudo apt-get install --no-install-recommends -y libavahi-client3 libavahi-common-dev libavahi-client-dev avahi-daemon

# Boost
sudo apt-get install --no-install-recommends -y libboost-dev libboost-filesystem-dev libboost-system-dev
Expand Down Expand Up @@ -84,9 +84,6 @@ install_packages_apt()
fi
}

# libjsoncpp
sudo apt-get install --no-install-recommends -y libjsoncpp-dev

# nginx
sudo apt-get install --no-install-recommends -y nginx
}
Expand Down
1 change: 1 addition & 0 deletions script/test
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ do_prepare()
if [[ ${OTBR_COVERAGE} == 1 ]]; then
otbr_options+=("-DOTBR_COVERAGE=ON")
fi

if [[ ${OTBR_REST} == "rest-off" ]]; then
otbr_options+=("-DOTBR_REST=OFF")
else
Expand Down
2 changes: 1 addition & 1 deletion src/dbus/server/dbus_agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ otbrError DBusAgent::Init(void)
mThreadObject = std::unique_ptr<DBusThreadObject>(new DBusThreadObject(mConnection.get(), mInterfaceName, mNcp));
error = mThreadObject->Init();
exit:
dbus_error_free(&dbusError);
if (error != OTBR_ERROR_NONE)
{
otbrLog(OTBR_LOG_ERR, "dbus error %s: %s", dbusError.name, dbusError.message);
}
dbus_error_free(&dbusError);
return error;
}

Expand Down
89 changes: 48 additions & 41 deletions src/rest/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,11 @@
#define OT_REST_RESOURCE_PATH_NETWORKS_CURRENT_PREFIX OT_REST_RESOURCE_PATH_NETWORKS_CURRENT "/prefix"

#define OT_REST_HTTP_STATUS_200 "200 OK"
#define OT_REST_HTTP_STATUS_201 "201 Created"
#define OT_REST_HTTP_STATUS_202 "202 Accepted"
#define OT_REST_HTTP_STATUS_204 "204 No Content"
#define OT_REST_HTTP_STATUS_400 "400 Bad Request"
#define OT_REST_HTTP_STATUS_404 "404 Not Found"
#define OT_REST_HTTP_STATUS_405 "405 Method Not Allowed"
#define OT_REST_HTTP_STATUS_408 "408 Request Timeout"
#define OT_REST_HTTP_STATUS_411 "411 Length Required"
#define OT_REST_HTTP_STATUS_415 "415 Unsupported Media Type"
#define OT_REST_HTTP_STATUS_500 "500 Internal Server Error"
#define OT_REST_HTTP_STATUS_501 "501 Not Implemented"
#define OT_REST_HTTP_STATUS_505 "505 HTTP Version Not Supported"

#define OT_REST_405_DESCRIPTION "This method is not allowed"
#define OT_REST_404_DESCRIPTION "Resource is not available, please check the URL"
Expand Down Expand Up @@ -95,6 +88,35 @@ static const uint32_t kResetSleepInterval = 1000000;
// Default timeout (in Seconds) for Joiners
static const uint32_t kDefaultJoinerTimeout = 120;

static std::string GetHttpStatus(HttpStatusCode aErrorCode)
{
std::string httpStatus;

switch (aErrorCode)
{
case HttpStatusCode::kStatusOk:
httpStatus = OT_REST_HTTP_STATUS_200;
break;
case HttpStatusCode::kStatusBadRequest:
httpStatus = OT_REST_HTTP_STATUS_400;
break;
case HttpStatusCode::kStatusResourceNotFound:
httpStatus = OT_REST_HTTP_STATUS_404;
break;
case HttpStatusCode::kStatusMethodNotAllowed:
httpStatus = OT_REST_HTTP_STATUS_405;
break;
case HttpStatusCode::kStatusRequestTimeout:
httpStatus = OT_REST_HTTP_STATUS_408;
break;
case HttpStatusCode::kStatusInternalServerError:
httpStatus = OT_REST_HTTP_STATUS_500;
break;
}

return httpStatus;
}

Resource::Resource(ControllerOpenThread *aNcp)
: mNcp(aNcp)
{
Expand Down Expand Up @@ -122,21 +144,6 @@ Resource::Resource(ControllerOpenThread *aNcp)
mResourceCallbackMap.emplace(OT_REST_RESOURCE_PATH_NETWORKS_CURRENT, &Resource::PutCurrentNetworkCallback);
mResourceCallbackMap.emplace(OT_REST_RESOURCE_PATH_NETWORKS_CURRENT_COMMISSION,
&Resource::CurrentNetworkCommissionCallback);

// HTTP Response code
mResponseCodeMap.emplace(HttpStatusCode::kStatusOk, OT_REST_HTTP_STATUS_200);
mResponseCodeMap.emplace(HttpStatusCode::kStatusCreated, OT_REST_HTTP_STATUS_201);
mResponseCodeMap.emplace(HttpStatusCode::kStatusAccepted, OT_REST_HTTP_STATUS_202);
mResponseCodeMap.emplace(HttpStatusCode::kStatusNoContent, OT_REST_HTTP_STATUS_204);
mResponseCodeMap.emplace(HttpStatusCode::kStatusBadRequest, OT_REST_HTTP_STATUS_400);
mResponseCodeMap.emplace(HttpStatusCode::kStatusResourceNotFound, OT_REST_HTTP_STATUS_404);
mResponseCodeMap.emplace(HttpStatusCode::kStatusMethodNotAllowed, OT_REST_HTTP_STATUS_405);
mResponseCodeMap.emplace(HttpStatusCode::kStatusRequestTimeout, OT_REST_HTTP_STATUS_408);
mResponseCodeMap.emplace(HttpStatusCode::kStatusLengthRequired, OT_REST_HTTP_STATUS_411);
mResponseCodeMap.emplace(HttpStatusCode::kStatusUnsupportedMediaType, OT_REST_HTTP_STATUS_415);
mResponseCodeMap.emplace(HttpStatusCode::kStatusInternalServerError, OT_REST_HTTP_STATUS_500);
mResponseCodeMap.emplace(HttpStatusCode::kStatusNotImplemented, OT_REST_HTTP_STATUS_501);
mResponseCodeMap.emplace(HttpStatusCode::kStatusHttpVersionNotSupported, OT_REST_HTTP_STATUS_505);
}

void Resource::Init(void)
Expand Down Expand Up @@ -190,7 +197,7 @@ void Resource::HandleDiagnosticCallback(const Request &aRequest, Response &aResp
}

body = Json::Diag2JsonString(diagContentSet);
errorCode = mResponseCodeMap.at(HttpStatusCode::kStatusOk);
errorCode = GetHttpStatus(HttpStatusCode::kStatusOk);
aResponse.SetResponsCode(errorCode);
aResponse.SetBody(body);
aResponse.SetComplete();
Expand All @@ -199,7 +206,7 @@ void Resource::HandleDiagnosticCallback(const Request &aRequest, Response &aResp

void Resource::ErrorHandler(Response &aResponse, HttpStatusCode aErrorCode, std::string aErrorDescription) const
{
std::string errorMessage = mResponseCodeMap.at(aErrorCode);
std::string errorMessage = GetHttpStatus(aErrorCode);
std::string body = Json::Error2JsonString(aErrorCode, errorMessage, aErrorDescription);

aResponse.SetResponsCode(errorMessage);
Expand Down Expand Up @@ -248,7 +255,7 @@ void Resource::GetCurrentNetworkPrefix(const Request &aRequest, Response &aRespo
body = Json::PrefixList2JsonString(configList);

aResponse.SetBody(body);
errorCode = mResponseCodeMap.at(HttpStatusCode::kStatusOk);
errorCode = GetHttpStatus(HttpStatusCode::kStatusOk);
aResponse.SetResponsCode(errorCode);
aResponse.SetComplete();
}
Expand Down Expand Up @@ -294,7 +301,7 @@ void Resource::PostCurrentNetworkPrefix(const Request &aRequest, Response &aResp
if (error == PostError::kPostErrorNone)
{
aResponse.SetBody(requestBody);
errorCode = mResponseCodeMap.at(HttpStatusCode::kStatusOk);
errorCode = GetHttpStatus(HttpStatusCode::kStatusOk);
aResponse.SetResponsCode(errorCode);
aResponse.SetComplete();
}
Expand Down Expand Up @@ -340,7 +347,7 @@ void Resource::DeleteCurrentNetworkPrefix(const Request &aRequest, Response &aRe
if (error == PostError::kPostErrorNone)
{
aResponse.SetBody(requestBody);
errorCode = mResponseCodeMap.at(HttpStatusCode::kStatusOk);
errorCode = GetHttpStatus(HttpStatusCode::kStatusOk);
aResponse.SetResponsCode(errorCode);
aResponse.SetComplete();
}
Expand Down Expand Up @@ -404,7 +411,7 @@ void Resource::CurrentNetworkCommissionCallback(const Request &aRequest, Respons
if (error == PostError::kPostErrorNone)
{
aResponse.SetBody(requestBody);
errorCode = mResponseCodeMap.at(HttpStatusCode::kStatusOk);
errorCode = GetHttpStatus(HttpStatusCode::kStatusOk);
aResponse.SetResponsCode(errorCode);
aResponse.SetComplete();
}
Expand Down Expand Up @@ -490,7 +497,7 @@ void Resource::GetCurrentNetwork(Response &aResponse) const

if (error == OTBR_ERROR_NONE)
{
errorCode = mResponseCodeMap.at(HttpStatusCode::kStatusOk);
errorCode = GetHttpStatus(HttpStatusCode::kStatusOk);
aResponse.SetResponsCode(errorCode);
}
else
Expand Down Expand Up @@ -610,7 +617,7 @@ void Resource::PutCurrentNetworkCallback(const Request &aRequest, Response &aRes
if (error == PostError::kPostErrorNone)
{
aResponse.SetBody(requestBody);
errorCode = mResponseCodeMap.at(HttpStatusCode::kStatusOk);
errorCode = GetHttpStatus(HttpStatusCode::kStatusOk);
aResponse.SetResponsCode(errorCode);
aResponse.SetComplete();
}
Expand Down Expand Up @@ -693,7 +700,7 @@ void Resource::GetNodeInfo(Response &aResponse) const
}
else
{
errorCode = mResponseCodeMap.at(HttpStatusCode::kStatusOk);
errorCode = GetHttpStatus(HttpStatusCode::kStatusOk);
aResponse.SetResponsCode(errorCode);
aResponse.SetComplete();
}
Expand Down Expand Up @@ -724,7 +731,7 @@ void Resource::GetDataExtendedAddr(Response &aResponse) const
std::string body = Json::Bytes2HexJsonString(extAddress, OT_EXT_ADDRESS_SIZE);

aResponse.SetBody(body);
errorCode = mResponseCodeMap.at(HttpStatusCode::kStatusOk);
errorCode = GetHttpStatus(HttpStatusCode::kStatusOk);
aResponse.SetResponsCode(errorCode);
}

Expand Down Expand Up @@ -756,7 +763,7 @@ void Resource::GetDataState(Response &aResponse) const
role = otThreadGetDeviceRole(mInstance);
state = Json::Number2JsonString(role);
aResponse.SetBody(state);
errorCode = mResponseCodeMap.at(HttpStatusCode::kStatusOk);
errorCode = GetHttpStatus(HttpStatusCode::kStatusOk);
aResponse.SetResponsCode(errorCode);
}

Expand All @@ -783,7 +790,7 @@ void Resource::GetDataNetworkName(Response &aResponse) const
networkName = Json::String2JsonString(networkName);

aResponse.SetBody(networkName);
errorCode = mResponseCodeMap.at(HttpStatusCode::kStatusOk);
errorCode = GetHttpStatus(HttpStatusCode::kStatusOk);
aResponse.SetResponsCode(errorCode);
}

Expand Down Expand Up @@ -822,7 +829,7 @@ void Resource::GetDataLeaderData(Response &aResponse) const
exit:
if (error == OTBR_ERROR_NONE)
{
errorCode = mResponseCodeMap.at(HttpStatusCode::kStatusOk);
errorCode = GetHttpStatus(HttpStatusCode::kStatusOk);
aResponse.SetResponsCode(errorCode);
}
else
Expand Down Expand Up @@ -865,7 +872,7 @@ void Resource::GetDataNumOfRoute(Response &aResponse) const
body = Json::Number2JsonString(count);

aResponse.SetBody(body);
errorCode = mResponseCodeMap.at(HttpStatusCode::kStatusOk);
errorCode = GetHttpStatus(HttpStatusCode::kStatusOk);
aResponse.SetResponsCode(errorCode);
}

Expand All @@ -892,7 +899,7 @@ void Resource::GetDataRloc16(Response &aResponse) const
body = Json::Number2JsonString(rloc16);

aResponse.SetBody(body);
errorCode = mResponseCodeMap.at(HttpStatusCode::kStatusOk);
errorCode = GetHttpStatus(HttpStatusCode::kStatusOk);
aResponse.SetResponsCode(errorCode);
}

Expand All @@ -917,7 +924,7 @@ void Resource::GetDataExtendedPanId(Response &aResponse) const
std::string errorCode;

aResponse.SetBody(body);
errorCode = mResponseCodeMap.at(HttpStatusCode::kStatusOk);
errorCode = GetHttpStatus(HttpStatusCode::kStatusOk);
aResponse.SetResponsCode(errorCode);
}

Expand All @@ -944,7 +951,7 @@ void Resource::GetDataRloc(Response &aResponse) const
body = Json::IpAddr2JsonString(rlocAddress);

aResponse.SetBody(body);
errorCode = mResponseCodeMap.at(HttpStatusCode::kStatusOk);
errorCode = GetHttpStatus(HttpStatusCode::kStatusOk);
aResponse.SetResponsCode(errorCode);
}

Expand Down Expand Up @@ -1094,7 +1101,7 @@ void Resource::PostNetworksCallback(const Request &aRequest, Response &aResponse
if (error == PostError::kPostErrorNone)
{
aResponse.SetBody(requestBody);
errorCode = mResponseCodeMap.at(HttpStatusCode::kStatusOk);
errorCode = GetHttpStatus(HttpStatusCode::kStatusOk);
aResponse.SetResponsCode(errorCode);
aResponse.SetComplete();
}
Expand Down Expand Up @@ -1160,7 +1167,7 @@ void Resource::NetworksResponseHandler(Response * aR
}

body = Json::ScanNetworks2JsonString(results);
errorCode = mResponseCodeMap.at(HttpStatusCode::kStatusOk);
errorCode = GetHttpStatus(HttpStatusCode::kStatusOk);
aResponse->SetResponsCode(errorCode);
aResponse->SetBody(body);
aResponse->SetComplete();
Expand Down
3 changes: 0 additions & 3 deletions src/rest/resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,6 @@ class Resource
// Reource Handler Map for those need callback
std::unordered_map<std::string, ResourceCallbackHandler> mResourceCallbackMap;

// Map from Status Code to Status description
std::unordered_map<HttpStatusCode, std::string, HttpStatusCodeHash> mResponseCodeMap;

// Map that maintain Diagnostic information
std::unordered_map<std::string, DiagInfo> mDiagSet;
};
Expand Down
27 changes: 6 additions & 21 deletions src/rest/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,12 @@ enum class HttpMethod : std::uint8_t

enum class HttpStatusCode : std::uint16_t
{
kStatusOk = 200, ///< OK
kStatusCreated = 201, ///< Created
kStatusAccepted = 202, ///< Accepted
kStatusNoContent = 204, ///< No Content
kStatusBadRequest = 400, ///< Bad Request
kStatusResourceNotFound = 404, ///< Resource Not Found
kStatusMethodNotAllowed = 405, ///< Method Not Allowed
kStatusRequestTimeout = 408, ///< Request Timeout
kStatusLengthRequired = 411, ///< Status Length Required
kStatusUnsupportedMediaType = 415, ///< Unsupported Media Type
kStatusInternalServerError = 500, ///< Internal Server Error
kStatusNotImplemented = 501, ///< Not Implemented
kStatusHttpVersionNotSupported = 505, ///< Http Version Not Supported
};

struct HttpStatusCodeHash
{
template <typename HttpStatusCode> std::size_t operator()(HttpStatusCode t) const
{
return static_cast<std::size_t>(t);
}
kStatusOk = 200, ///< OK
kStatusBadRequest = 400, ///< Bad Request
kStatusResourceNotFound = 404, ///< Resource Not Found
kStatusMethodNotAllowed = 405, ///< Method Not Allowed
kStatusRequestTimeout = 408, ///< Request Timeout
kStatusInternalServerError = 500, ///< Internal Server Error
};

enum class PostError : std::uint8_t
Expand Down

0 comments on commit 79443b0

Please sign in to comment.