[IOT-1463] Fix for getting and setting host address from secured OCResource object. 37/13637/3
authorHarish Kumara Marappa <h.marappa@samsung.com>
Thu, 20 Oct 2016 09:26:47 +0000 (18:26 +0900)
committerUze Choi <uzchoi@samsung.com>
Wed, 26 Oct 2016 09:39:45 +0000 (09:39 +0000)
OCResource object was returning "coap+tcp" even if it is secured resource.
OCResource::setHost() fails to create OCDevAddr for host containing "coaps+tcp".

Change-Id: I2273d08b40e94f66fe95e339e876c2c316986c71
Signed-off-by: Harish Kumara Marappa <h.marappa@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/13489
Reviewed-by: Habib Virji <habib.virji@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Junghyun Oh <junghyun.oh@samsung.com>
Reviewed-by: Ziran Sun <ziran.sun@samsung.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
(cherry picked from commit ae38269f723939c2e3c8c8a722185067bdb783d1)
Reviewed-on: https://gerrit.iotivity.org/gerrit/13637

resource/src/OCResource.cpp

index ba6df4b..35cadad 100644 (file)
@@ -39,6 +39,7 @@ namespace OC {
 static const char COAP[] = "coap://";
 static const char COAPS[] = "coaps://";
 static const char COAP_TCP[] = "coap+tcp://";
+static const char COAPS_TCP[] = "coaps+tcp://";
 static const char COAP_GATT[] = "coap+gatt://";
 static const char COAP_RFCOMM[] = "coap+rfcomm://";
 
@@ -139,6 +140,11 @@ void OCResource::setHost(const std::string& host)
     {
         prefix_len = sizeof(COAP_TCP) - 1;
     }
+    else if (host.compare(0, sizeof(COAPS_TCP) - 1, COAPS_TCP) == 0)
+    {
+        prefix_len = sizeof(COAPS_TCP) - 1;
+        m_devAddr.flags = static_cast<OCTransportFlags>(m_devAddr.flags | OC_SECURE);
+    }
     else if (host.compare(0, sizeof(COAP_GATT) - 1, COAP_GATT) == 0)
     {
         prefix_len = sizeof(COAP_GATT) - 1;
@@ -502,7 +508,14 @@ std::string OCResource::host() const
 
     if (m_devAddr.adapter & OC_ADAPTER_TCP)
     {
-        ss << COAP_TCP;
+        if (m_devAddr.flags & OC_SECURE)
+        {
+            ss << COAPS_TCP;
+        }
+        else
+        {
+            ss << COAP_TCP;
+        }
     }
     else if (m_devAddr.adapter & OC_ADAPTER_GATT_BTLE)
     {