virtual OCStackResult GetResourceRepresentation(
const OCDevAddr& devAddr,
+ bool useHostString,
const std::string& uri,
const QueryParamsMap& queryParams,
const HeaderOptions& headerOptions,
virtual OCStackResult PutResourceRepresentation(
const OCDevAddr& devAddr,
+ bool useHostString,
const std::string& uri,
const OCRepresentation& rep, const QueryParamsMap& queryParams,
const HeaderOptions& headerOptions,
virtual OCStackResult PostResourceRepresentation(
const OCDevAddr& devAddr,
+ bool useHostString,
const std::string& uri,
const OCRepresentation& rep, const QueryParamsMap& queryParams,
const HeaderOptions& headerOptions,
virtual OCStackResult DeleteResource(
const OCDevAddr& devAddr,
+ bool useHostString,
const std::string& uri,
const HeaderOptions& headerOptions,
DeleteCallback& callback, QualityOfService QoS) = 0;
virtual OCStackResult ObserveResource(
ObserveType observeType, OCDoHandle* handle,
const OCDevAddr& devAddr,
+ bool useHostString,
const std::string& uri,
const QueryParamsMap& queryParams,
const HeaderOptions& headerOptions, ObserveCallback& callback,
FindDeviceCallback& callback, QualityOfService QoS);
virtual OCStackResult GetResourceRepresentation(
- const OCDevAddr& devAddr,
+ const OCDevAddr& devAddr, bool useHostString,
const std::string& uri,
const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
GetCallback& callback, QualityOfService QoS);
virtual OCStackResult PutResourceRepresentation(
- const OCDevAddr& devAddr,
+ const OCDevAddr& devAddr, bool useHostString,
const std::string& uri,
const OCRepresentation& attributes, const QueryParamsMap& queryParams,
const HeaderOptions& headerOptions, PutCallback& callback, QualityOfService QoS);
virtual OCStackResult PostResourceRepresentation(
- const OCDevAddr& devAddr,
+ const OCDevAddr& devAddr, bool useHostString,
const std::string& uri,
const OCRepresentation& attributes, const QueryParamsMap& queryParams,
const HeaderOptions& headerOptions, PostCallback& callback, QualityOfService QoS);
virtual OCStackResult DeleteResource(
- const OCDevAddr& devAddr,
+ const OCDevAddr& devAddr, bool useHostString,
const std::string& uri,
const HeaderOptions& headerOptions,
DeleteCallback& callback, QualityOfService QoS);
virtual OCStackResult ObserveResource(
ObserveType observeType, OCDoHandle* handle,
- const OCDevAddr& devAddr,
+ const OCDevAddr& devAddr, bool useHostString,
const std::string& uri,
const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
ObserveCallback& callback, QualityOfService QoS);
std::string m_uri;
OCResourceIdentifier m_resourceId;
OCDevAddr m_devAddr;
+ bool m_useHostString;
bool m_isObservable;
bool m_isCollection;
std::vector<std::string> m_resourceTypes;
{return OC_STACK_NOTIMPL;}
virtual OCStackResult GetResourceRepresentation(
- const OCDevAddr& devAddr,
+ const OCDevAddr& devAddr, bool useHostString,
const std::string& uri,
const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
GetCallback& callback, QualityOfService QoS)
{return OC_STACK_NOTIMPL;}
virtual OCStackResult PutResourceRepresentation(
- const OCDevAddr& devAddr,
+ const OCDevAddr& devAddr, bool useHostString,
const std::string& uri,
const OCRepresentation& attributes, const QueryParamsMap& queryParams,
const HeaderOptions& headerOptions, PutCallback& callback,
{return OC_STACK_NOTIMPL;}
virtual OCStackResult PostResourceRepresentation(
- const OCDevAddr& devAddr,
+ const OCDevAddr& devAddr, bool useHostString,
const std::string& uri,
const OCRepresentation& attributes, const QueryParamsMap& queryParams,
const HeaderOptions& headerOptions, PostCallback& callback, QualityOfService QoS)
{return OC_STACK_NOTIMPL;}
virtual OCStackResult DeleteResource(
- const OCDevAddr& devAddr,
+ const OCDevAddr& devAddr, bool useHostString,
const std::string& uri,
const HeaderOptions& headerOptions,
DeleteCallback& callback, QualityOfService QoS)
virtual OCStackResult ObserveResource(
ObserveType observeType, OCDoHandle* handle,
- const OCDevAddr& devAddr,
+ const OCDevAddr& devAddr, bool useHostString,
const std::string& uri,
const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
ObserveCallback& callback, QualityOfService QoS)
return OC_STACK_DELETE_TRANSACTION;
}
+ OCStackResult InvokeDoResource(OCDoHandle *handle,
+ OCMethod method,
+ const char *requestUri,
+ const OCDevAddr *destination,
+ const char *request,
+ OCConnectivityType connectivityType,
+ OCQualityOfService qos,
+ OCCallbackData *cbData,
+ OCHeaderOption *options,
+ uint8_t numOptions,
+ bool useHostString)
+ {
+ if (useHostString)
+ {
+ ostringstream host;
+ host << destination << requestUri;
+ connectivityType = (OCConnectivityType)
+ ((destination->adapter << CT_ADAPTER_SHIFT)
+ | (destination->flags & CT_MASK_FLAGS));
+ return OCDoResource(handle,
+ method,
+ host.str().c_str(),
+ nullptr,
+ request,
+ connectivityType,
+ qos,
+ cbData,
+ options,
+ numOptions);
+ }
+ else
+ {
+ return OCDoResource(handle,
+ method,
+ requestUri,
+ destination,
+ request,
+ connectivityType,
+ qos,
+ cbData,
+ options,
+ numOptions);
+ }
+ }
+
OCStackResult InProcClientWrapper::GetResourceRepresentation(
- const OCDevAddr& devAddr,
+ const OCDevAddr& devAddr, bool useHostString,
const std::string& resourceUri,
const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
GetCallback& callback, QualityOfService QoS)
}
OCStackResult InProcClientWrapper::PostResourceRepresentation(
- const OCDevAddr& devAddr,
+ const OCDevAddr& devAddr, bool useHostString,
const std::string& uri,
const OCRepresentation& rep,
const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
}
OCStackResult InProcClientWrapper::PutResourceRepresentation(
- const OCDevAddr& devAddr,
+ const OCDevAddr& devAddr, bool useHostString,
const std::string& uri,
const OCRepresentation& rep,
const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
}
OCStackResult InProcClientWrapper::DeleteResource(
- const OCDevAddr& devAddr,
+ const OCDevAddr& devAddr, bool useHostString,
const std::string& uri,
const HeaderOptions& headerOptions, DeleteCallback& callback, QualityOfService QoS)
{
}
OCStackResult InProcClientWrapper::ObserveResource(ObserveType observeType, OCDoHandle* handle,
- const OCDevAddr& devAddr,
+ const OCDevAddr& devAddr, bool useHostString,
const std::string& uri,
const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
ObserveCallback& callback, QualityOfService QoS)
#include "OCUtilities.h"
#include <boost/lexical_cast.hpp>
+#include <sstream>
namespace OC {
const std::vector<std::string>& resourceTypes,
const std::vector<std::string>& interfaces)
: m_clientWrapper(clientWrapper), m_uri(uri),
- m_resourceId(serverId, m_uri), m_devAddr(devAddr),
+ m_resourceId(serverId, m_uri), m_devAddr(devAddr), m_useHostString(false),
m_isObservable(observable), m_isCollection(false),
m_resourceTypes(resourceTypes), m_interfaces(interfaces),
m_observeHandle(nullptr)
: m_clientWrapper(clientWrapper), m_uri(uri),
m_resourceId(serverId, m_uri),
m_devAddr{ OC_DEFAULT_ADAPTER },
+ m_useHostString(true),
m_isObservable(observable), m_isCollection(false),
m_resourceTypes(resourceTypes), m_interfaces(interfaces),
m_observeHandle(nullptr)
{
return checked_guard(m_clientWrapper.lock(),
&IClientWrapper::GetResourceRepresentation,
- m_devAddr, m_uri,
+ m_devAddr, m_useHostString, m_uri,
queryParametersMap, m_headerOptions,
attributeHandler, QoS);
}
QualityOfService QoS)
{
return checked_guard(m_clientWrapper.lock(), &IClientWrapper::PutResourceRepresentation,
- m_devAddr, m_uri, rep, queryParametersMap,
+ m_devAddr, m_useHostString, m_uri, rep, queryParametersMap,
m_headerOptions, attributeHandler, QoS);
}
QualityOfService QoS)
{
return checked_guard(m_clientWrapper.lock(), &IClientWrapper::PostResourceRepresentation,
- m_devAddr, m_uri, rep, queryParametersMap,
+ m_devAddr, m_useHostString, m_uri, rep, queryParametersMap,
m_headerOptions, attributeHandler, QoS);
}
OCStackResult OCResource::deleteResource(DeleteCallback deleteHandler, QualityOfService QoS)
{
return checked_guard(m_clientWrapper.lock(), &IClientWrapper::DeleteResource,
- m_devAddr, m_uri, m_headerOptions, deleteHandler, QoS);
+ m_devAddr, m_useHostString, m_uri, m_headerOptions, deleteHandler, QoS);
}
OCStackResult OCResource::deleteResource(DeleteCallback deleteHandler)
return checked_guard(m_clientWrapper.lock(), &IClientWrapper::ObserveResource,
observeType, &m_observeHandle, m_devAddr,
- m_uri, queryParametersMap, m_headerOptions,
+ m_useHostString, m_uri, queryParametersMap, m_headerOptions,
observeHandler, QoS);
}
std::string OCResource::host() const
{
- return std::string(m_devAddr.addr);
+ if (m_useHostString)
+ {
+ return std::string(m_devAddr.addr);
+ }
+
+ std::ostringstream ss;
+ if (m_devAddr.flags & OC_SECURE)
+ {
+ ss << "coaps://";
+ }
+ else
+ {
+ ss << "coap://";
+ }
+ if (m_devAddr.flags & OC_IP_USE_V6)
+ {
+ ss << '[' << m_devAddr.addr << ']';
+ }
+ else
+ {
+ ss << m_devAddr.addr;
+ }
+ if (m_devAddr.port)
+ {
+ ss << ':' << m_devAddr.port;
+ }
+ return ss.str();
}
std::string OCResource::uri() const