replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / src / OCResource.cpp
index 60306d8..0728df0 100644 (file)
@@ -52,12 +52,13 @@ OCResource::OCResource(std::weak_ptr<IClientWrapper> clientWrapper,
                         const OCDevAddr& devAddr, const std::string& uri,
                         const std::string& serverId, uint8_t property,
                         const std::vector<std::string>& resourceTypes,
-                        const std::vector<std::string>& interfaces)
+                        const std::vector<std::string>& interfaces,
+                        const std::string& deviceName)
  :  m_clientWrapper(clientWrapper), m_uri(uri),
     m_resourceId(serverId, m_uri), m_devAddr(devAddr),
     m_isCollection(false), m_property(property),
     m_resourceTypes(resourceTypes), m_interfaces(interfaces),
-    m_observeHandle(nullptr)
+    m_observeHandle(nullptr), m_deviceName(deviceName)
 {
     m_isCollection = std::find(m_interfaces.begin(), m_interfaces.end(), LINK_INTERFACE)
                         != m_interfaces.end();
@@ -67,8 +68,8 @@ OCResource::OCResource(std::weak_ptr<IClientWrapper> clientWrapper,
         interfaces.empty()||
         m_clientWrapper.expired())
     {
-        throw ResourceInitException(m_uri.empty(), resourceTypes.empty(),
-                interfaces.empty(), m_clientWrapper.expired(), false, false);
+        throw ResourceInitException(m_uri.empty(), false, resourceTypes.empty(),
+                interfaces.empty(), m_clientWrapper.expired(), false, false, false);
     }
 }
 
@@ -77,18 +78,19 @@ OCResource::OCResource(std::weak_ptr<IClientWrapper> clientWrapper,
                         const std::string& serverId,
                         OCConnectivityType connectivityType, uint8_t property,
                         const std::vector<std::string>& resourceTypes,
-                        const std::vector<std::string>& interfaces)
+                        const std::vector<std::string>& interfaces,
+                        const std::string& deviceName)
  :  m_clientWrapper(clientWrapper), m_uri(uri),
     m_resourceId(serverId, m_uri),
     m_isCollection(false), m_property(property),
     m_resourceTypes(resourceTypes), m_interfaces(interfaces),
-    m_observeHandle(nullptr)
+    m_observeHandle(nullptr), m_deviceName(deviceName)
 {
     m_devAddr = OCDevAddr{OC_DEFAULT_ADAPTER, OC_DEFAULT_FLAGS, 0, {0}, 0,
 #if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
-                          {0}
+                          {0},
 #endif
-                        };
+                          {0}};
     m_isCollection = std::find(m_interfaces.begin(), m_interfaces.end(), LINK_INTERFACE)
                         != m_interfaces.end();
 
@@ -97,20 +99,20 @@ OCResource::OCResource(std::weak_ptr<IClientWrapper> clientWrapper,
         interfaces.empty()||
         m_clientWrapper.expired())
     {
-        throw ResourceInitException(m_uri.empty(), resourceTypes.empty(),
-                interfaces.empty(), m_clientWrapper.expired(), false, false);
+        throw ResourceInitException(m_uri.empty(), false, resourceTypes.empty(),
+                interfaces.empty(), m_clientWrapper.expired(), false, false, false);
     }
 
     if (uri.length() == 1 && uri[0] == '/')
     {
-        throw ResourceInitException(m_uri.empty(), resourceTypes.empty(),
-                interfaces.empty(), m_clientWrapper.expired(), false, false);
+        throw ResourceInitException(m_uri.empty(), true, resourceTypes.empty(),
+                interfaces.empty(), m_clientWrapper.expired(), false, false, false);
     }
 
     if (uri[0] != '/')
     {
-        throw ResourceInitException(m_uri.empty(), resourceTypes.empty(),
-                interfaces.empty(), m_clientWrapper.expired(), false, false);
+        throw ResourceInitException(m_uri.empty(), true, resourceTypes.empty(),
+                interfaces.empty(), m_clientWrapper.expired(), false, false, false);
     }
 
     // construct the devAddr from the pieces we have
@@ -156,8 +158,8 @@ void OCResource::setHost(const std::string& host)
     }
     else
     {
-        throw ResourceInitException(m_uri.empty(), m_resourceTypes.empty(),
-            m_interfaces.empty(), m_clientWrapper.expired(), false, false);
+        throw ResourceInitException(m_uri.empty(), false, m_resourceTypes.empty(),
+            m_interfaces.empty(), m_clientWrapper.expired(), false, false, true);
     }
 
     // remove 'coap://' or 'coaps://' or 'coap+tcp://' or 'coap+gatt://' or 'coap+rfcomm://'
@@ -169,8 +171,8 @@ void OCResource::setHost(const std::string& host)
 
         if (std::string::npos == bracket || 0 == bracket)
         {
-            throw ResourceInitException(m_uri.empty(), m_resourceTypes.empty(),
-                m_interfaces.empty(), m_clientWrapper.expired(), false, false);
+            throw ResourceInitException(m_uri.empty(), false, m_resourceTypes.empty(),
+                m_interfaces.empty(), m_clientWrapper.expired(), false, true, false);
         }
         // extract the ipv6 address
         std::string ip6Addr = host_token.substr(1, bracket - 1);
@@ -186,8 +188,8 @@ void OCResource::setHost(const std::string& host)
         const char *cAddr = ip6AddrToValidityCheck.c_str();
         if (0 == inet_pton(AF_INET6, cAddr, &buf))
         {
-            throw ResourceInitException(m_uri.empty(), m_resourceTypes.empty(),
-                m_interfaces.empty(), m_clientWrapper.expired(), false, false);
+            throw ResourceInitException(m_uri.empty(), false, m_resourceTypes.empty(),
+                m_interfaces.empty(), m_clientWrapper.expired(), true, false, false);
         }
 
         //skip ']' and ':' characters in host string
@@ -196,8 +198,8 @@ void OCResource::setHost(const std::string& host)
 
         if (0 > port || UINT16_MAX < port)
         {
-            throw ResourceInitException(m_uri.empty(), m_resourceTypes.empty(),
-                m_interfaces.empty(), m_clientWrapper.expired(), false, false);
+            throw ResourceInitException(m_uri.empty(), false, m_resourceTypes.empty(),
+                m_interfaces.empty(), m_clientWrapper.expired(), true, false, false);
         }
 
         OCStackResult result = OCDecodeAddressForRFC6874(m_devAddr.addr,
@@ -205,8 +207,8 @@ void OCResource::setHost(const std::string& host)
 
         if (OC_STACK_OK != result)
         {
-            throw ResourceInitException(m_uri.empty(), m_resourceTypes.empty(),
-                m_interfaces.empty(), m_clientWrapper.expired(), false, false);
+            throw ResourceInitException(m_uri.empty(), false, m_resourceTypes.empty(),
+                m_interfaces.empty(), m_clientWrapper.expired(), false, true, false);
         }
 
         m_devAddr.port = static_cast<uint16_t>(port);
@@ -214,8 +216,8 @@ void OCResource::setHost(const std::string& host)
     }
     else if (host_token[0] == ':')
     {
-        throw ResourceInitException(m_uri.empty(), m_resourceTypes.empty(),
-            m_interfaces.empty(), m_clientWrapper.expired(), false, false);
+        throw ResourceInitException(m_uri.empty(), false, m_resourceTypes.empty(),
+            m_interfaces.empty(), m_clientWrapper.expired(), false, false, true);
     }
     else
     {
@@ -227,8 +229,8 @@ void OCResource::setHost(const std::string& host)
             // address validity check
             if (MAC_ADDR_STR_SIZE != macAddr.length())
             {
-                throw ResourceInitException(m_uri.empty(), m_resourceTypes.empty(),
-                    m_interfaces.empty(), m_clientWrapper.expired(), false, false);
+                throw ResourceInitException(m_uri.empty(), false, m_resourceTypes.empty(),
+                    m_interfaces.empty(), m_clientWrapper.expired(), false, true, false);
             }
 
             for (size_t blockCnt = 0; blockCnt < MAC_ADDR_BLOCKS; blockCnt++)
@@ -237,8 +239,8 @@ void OCResource::setHost(const std::string& host)
 
                 if (std::string::npos != block.find_first_not_of("0123456789ABCDEFabcdef"))
                 {
-                    throw ResourceInitException(m_uri.empty(), m_resourceTypes.empty(),
-                        m_interfaces.empty(), m_clientWrapper.expired(), false, false);
+                    throw ResourceInitException(m_uri.empty(), false, m_resourceTypes.empty(),
+                        m_interfaces.empty(), m_clientWrapper.expired(), false, true, false);
                 }
 
                 if (MAC_ADDR_BLOCKS - 1 > blockCnt)
@@ -247,8 +249,8 @@ void OCResource::setHost(const std::string& host)
 
                     if (':' != delimiter)
                     {
-                        throw ResourceInitException(m_uri.empty(), m_resourceTypes.empty(),
-                            m_interfaces.empty(), m_clientWrapper.expired(), false, false);
+                        throw ResourceInitException(m_uri.empty(), false, m_resourceTypes.empty(),
+                            m_interfaces.empty(), m_clientWrapper.expired(), false, true, false);
                     }
                 }
             }
@@ -262,8 +264,8 @@ void OCResource::setHost(const std::string& host)
 
             if (colon == std::string::npos || colon == 0)
             {
-                throw ResourceInitException(m_uri.empty(), m_resourceTypes.empty(),
-                    m_interfaces.empty(), m_clientWrapper.expired(), false, false);
+                throw ResourceInitException(m_uri.empty(), false, m_resourceTypes.empty(),
+                    m_interfaces.empty(), m_clientWrapper.expired(), false, true, false);
             }
 
             // extract the ipv4 address
@@ -274,8 +276,8 @@ void OCResource::setHost(const std::string& host)
             const char *cAddr = ip4Addr.c_str();
             if (0 == inet_pton(AF_INET, cAddr, &buf))
             {
-                throw ResourceInitException(m_uri.empty(), m_resourceTypes.empty(),
-                    m_interfaces.empty(), m_clientWrapper.expired(), false, false);
+                throw ResourceInitException(m_uri.empty(), false, m_resourceTypes.empty(),
+                    m_interfaces.empty(), m_clientWrapper.expired(), true, false, false);
             }
 
             //skip ':' characters in host string
@@ -284,8 +286,8 @@ void OCResource::setHost(const std::string& host)
 
             if (0 > port || UINT16_MAX < port)
             {
-                throw ResourceInitException(m_uri.empty(), m_resourceTypes.empty(),
-                    m_interfaces.empty(), m_clientWrapper.expired(), false, false);
+                throw ResourceInitException(m_uri.empty(), false, m_resourceTypes.empty(),
+                    m_interfaces.empty(), m_clientWrapper.expired(), true, false, false);
             }
 
             ip4Addr.copy(m_devAddr.addr, sizeof(m_devAddr.addr));
@@ -554,8 +556,8 @@ std::string OCResource::host() const
                                                          m_devAddr.addr);
         if (OC_STACK_OK != result)
         {
-            throw ResourceInitException(m_uri.empty(), m_resourceTypes.empty(),
-                m_interfaces.empty(), m_clientWrapper.expired(), false, false);
+            throw ResourceInitException(m_uri.empty(), false, m_resourceTypes.empty(),
+                m_interfaces.empty(), m_clientWrapper.expired(), false, true, false);
         }
         ss << '[' << addressEncoded << ']';
     }
@@ -613,6 +615,16 @@ std::string OCResource::sid() const
     return this->uniqueIdentifier().m_representation;
 }
 
+std::string OCResource::deviceName() const
+{
+    return m_deviceName;
+}
+
+OCDevAddr OCResource::getDevAddr() const
+{
+    return m_devAddr;
+}
+
 #ifdef WITH_MQ
 OCStackResult OCResource::discoveryMQTopics(const QueryParamsMap& queryParametersMap,
                                             MQTopicCallback attributeHandler,