std::string resourceInterface = DEFAULT_INTERFACE; // resource interface.
// OCResourceProperty is defined ocstack.h
- uint8_t resourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE;
+ uint8_t resourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE;
EntityHandler cb = std::bind(&LightResource::entityHandler, this,PH::_1, PH::_2);
std::string resourceInterface = DEFAULT_INTERFACE; // resource interface.
// OCResourceProperty is defined ocstack.h
- uint8_t resourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE;
+ uint8_t resourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE;
EntityHandler cb = std::bind(&LightResource::entityHandler, this,PH::_1, PH::_2);
{
class InProcClientWrapper : public IClientWrapper
{
+
public:
+ enum OCSecureType
+ {
+ IPV4Secure,
+ IPV4
+ };
+
InProcClientWrapper(OC::OCPlatform_impl& owner, std::weak_ptr<std::recursive_mutex> csdkLock,
PlatformConfig cfg);
virtual ~InProcClientWrapper();
// Note: this should never be called by anyone but the handler for the listen command.
// It is public becuase that needs to be a non-instance callback
virtual std::shared_ptr<OCResource> parseOCResource(IClientWrapper::Ptr clientWrapper,
- const std::string& host, const boost::property_tree::ptree resourceNode);
+ OCDevAddr& addr, const boost::property_tree::ptree resourceNode);
OCStackResult GetDefaultQos(QualityOfService& QoS);
private:
+ std::string convertOCAddrToString(OCDevAddr& addr,
+ OCSecureType type, const std::string &portStr = std::string());
void listeningFunc();
std::string assembleSetResourceUri(std::string uri, const QueryParamsMap& queryParams);
std::string assembleSetResourcePayload(const OCRepresentation& attributes);
{
// if the config type is server, we ought to never get called. If the config type
// is both, we count on the server to run the thread and do the initialize
+
if(m_cfg.mode == ModeType::Client)
{
OCStackResult result = OCInit(m_cfg.ipAddress.c_str(), m_cfg.port, OC_CLIENT);
}
}
-
-
- std::string convertOCAddrToString(OCDevAddr& addr)
+ std::string InProcClientWrapper::convertOCAddrToString(OCDevAddr& addr,
+ OCSecureType type, const std::string &portStr)
{
// TODO: we currently assume this is a IPV4 address, need to figure out the actual value
if(OCDevAddrToIPv4Addr(&addr, &a, &b, &c, &d) ==0 && OCDevAddrToPort(&addr, &port)==0)
{
ostringstream os;
- os << "coap://"<<(int)a<<'.'<<(int)b<<'.'<<(int)c<<'.'<<(int)d<<':'<<(int)port;
+ if(type == OCSecureType::IPV4)
+ {
+ os << "coap://" << static_cast<int>(a) << '.' <<
+ static_cast<int>(b) << '.' << static_cast<int>(c) <<
+ '.' << static_cast<int>(d) << ':' <<static_cast<int>(port);
+ }
+ else if(type == OCSecureType::IPV4Secure)
+ {
+ os << "coaps://" << static_cast<int>(a) <<'.' <<
+ static_cast<int>(b) <<'.' << static_cast<int>(c) <<
+ '.' << static_cast<int>(d) << ':' << portStr;
+ }
return os.str();
}
else
std::shared_ptr<OCResource> InProcClientWrapper::parseOCResource(
- IClientWrapper::Ptr clientWrapper, const std::string& host,
+ IClientWrapper::Ptr clientWrapper, OCDevAddr& addr,
const boost::property_tree::ptree resourceNode)
{
std::string uri = resourceNode.get<std::string>(OC::Key::URIKEY, "");
{
rTs.push_back(itr.second.data());
}
+ bool secure = properties.get<int>(OC::Key::SECUREKEY,0) == 1;
boost::property_tree::ptree iF =
properties.get_child(OC::Key::INTERFACESKEY, boost::property_tree::ptree());
ifaces.push_back(itr.second.data());
}
+ std::string host;
+ if(secure)
+ {
+ string port = properties.get<string>(OC::Key::PORTKEY,"");
+ host= convertOCAddrToString(addr, OCSecureType::IPV4Secure, port);
+ }
+ else
+ {
+ host= convertOCAddrToString(addr, OCSecureType::IPV4);
+ }
+
return std::shared_ptr<OCResource>(
new OCResource(clientWrapper, host, uri, obs, rTs, ifaces));
}
{
try
{
- std::string host = convertOCAddrToString(*clientResponse->addr);
std::shared_ptr<OCResource> resource =
- context->clientWrapper->parseOCResource(context->clientWrapper, host,
+ context->clientWrapper->parseOCResource(context->clientWrapper,
+ *clientResponse->addr,
payloadItr.second);
// Note: the call to detach allows the underlying thread to continue until