Commit bd6a28a7 authored by KIM JungYong's avatar KIM JungYong Committed by Uze Choi

Fix for invalid discovery query in the RE.

When do discovery with specific uri using RE layer,
RE layer trigger to find resource with invalid uri
which is specific uri without wellknown-uri(/oic/res).

But, resource server never response for this discovery request.
Because discovery request only handled by /oic/res,
other discovery request does not a handled by base stack.

In this patch,
1) Request uri is changed to wellknown uri.
2) Related unit test is modified.

Change-Id: I529430834f8c48b0eb5e31b6f58da33fb55c946c
Signed-off-by: default avatarKIM JungYong <jyong2.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/18191Tested-by: default avatarjenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: default avatarUze Choi <uzchoi@samsung.com>
Tested-by: default avatarUze Choi <uzchoi@samsung.com>
parent 2cd2dc1f
......@@ -72,7 +72,8 @@ namespace OIC
void RCSDiscoveryManagerImpl::onResourceFound(
std::shared_ptr< PrimitiveResource > resource, ID discoveryId,
const RCSDiscoveryManager::ResourceDiscoveredCallback& discoverCB)
const RCSDiscoveryManager::ResourceDiscoveredCallback& discoverCB,
const std::string& uri)
{
{
std::lock_guard < std::mutex > lock(m_mutex);
......@@ -83,7 +84,11 @@ namespace OIC
it->second.addKnownResource(resource);
}
discoverCB(std::make_shared < RCSRemoteResourceObject > (resource));
if (uri == OC_RSRVD_WELL_KNOWN_URI || uri == resource->getUri())
{
discoverCB(std::make_shared < RCSRemoteResourceObject > (resource));
}
}
RCSDiscoveryManager::DiscoveryTask::Ptr RCSDiscoveryManagerImpl::startDiscovery(
......@@ -102,7 +107,7 @@ namespace OIC
DiscoveryRequestInfo discoveryInfo(address, relativeUri, resourceTypes,
std::bind(&RCSDiscoveryManagerImpl::onResourceFound, this,
std::placeholders::_1, discoveryId, std::move(cb)));
std::placeholders::_1, discoveryId, std::move(cb), relativeUri));
discoveryInfo.discover();
......@@ -197,7 +202,8 @@ namespace OIC
{
for (const auto& it : m_resourceTypes)
{
discoverResource(m_address, m_relativeUri + "?rt=" + it, m_discoverCb);
discoverResource(m_address, std::string(OC_RSRVD_WELL_KNOWN_URI)
+ "?rt=" + it, m_discoverCb);
}
}
......
......@@ -130,7 +130,8 @@ namespace OIC
* @see PrimitiveResource
*/
void onResourceFound(std::shared_ptr< PrimitiveResource > resource, ID discoveryId,
const RCSDiscoveryManager::ResourceDiscoveredCallback& cb);
const RCSDiscoveryManager::ResourceDiscoveredCallback& cb,
const std::string& uri);
/**
* Discover resource on all requests and posting timer when timer is expired
......
......@@ -43,13 +43,17 @@ constexpr char SECOND_RESOURCETYPE[]{ "resource.type.second" };
#ifdef SECURED
const char * SVR_DB_FILE_NAME = "./oic_svr_db_re_client.dat";
//OCPersistent Storage Handlers
static FILE* client_open(const char * /*path*/, const char *mode)
static FILE* client_open(const char * path, const char *mode)
{
std::string file_name = SVR_DB_FILE_NAME;
if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
{
std::string file_name = SVR_DB_FILE_NAME;
#ifndef LOCAL_RUNNING
file_name = "./service/resource-encapsulation/unittests/oic_svr_db_re_client.dat";
file_name = "./service/resource-encapsulation/unittests/oic_svr_db_re_client.dat";
#endif
return fopen(file_name.c_str(), mode);
return fopen(file_name.c_str(), mode);
}
return fopen(path, mode);
}
#endif
......@@ -89,7 +93,7 @@ private:
TEST(DiscoveryManagerTest, ThrowIfDiscoverWithEmptyCallback)
{
#ifdef SECURED
OCPersistentStorage gps {client_open, fread, fwrite, fclose, unlink };
static OCPersistentStorage gps {client_open, fread, fwrite, fclose, unlink };
OC::PlatformConfig cfg
{ OC::ServiceType::InProc, OC::ModeType::Both, "0.0.0.0", 0,
OC::QualityOfService::LowQos, &gps };
......@@ -112,7 +116,8 @@ TEST(DiscoveryManagerTest, DiscoverInvokesFindResource)
mocks.ExpectCallFuncOverload(static_cast<OCFindResource>(findResource)).Match(
[](const std::string& host, const std::string& resourceURI, OCConnectivityType, FindCallback)
{
return host.empty() && resourceURI == (std::string(RESOURCE_URI) + "?rt=" + RESOURCE_TYPE);
return host.empty() && resourceURI ==
(std::string(OC_RSRVD_WELL_KNOWN_URI) + "?rt=" + RESOURCE_TYPE);
}
).Return(OC_STACK_OK);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment