Restore host string behavior lost in IPv6 plumbing patch
authorJohn Light <john.j.light@intel.com>
Sat, 20 Jun 2015 22:28:04 +0000 (15:28 -0700)
committerErich Keane <erich.keane@intel.com>
Wed, 1 Jul 2015 16:24:55 +0000 (16:24 +0000)
Change-Id: Ia7120dd3d361e717f2a04782c3b59bdb841bc8bc
Signed-off-by: John Light <john.j.light@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1430
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Erich Keane <erich.keane@intel.com>
resource/include/IClientWrapper.h
resource/include/InProcClientWrapper.h
resource/include/OCResource.h
resource/include/OutOfProcClientWrapper.h
resource/src/InProcClientWrapper.cpp
resource/src/OCResource.cpp

index 272cd44..421d3e5 100644 (file)
@@ -54,6 +54,7 @@ namespace OC
 
         virtual OCStackResult GetResourceRepresentation(
                         const OCDevAddr& devAddr,
+                        bool useHostString,
                         const std::string& uri,
                         const QueryParamsMap& queryParams,
                         const HeaderOptions& headerOptions,
@@ -61,6 +62,7 @@ namespace OC
 
         virtual OCStackResult PutResourceRepresentation(
                         const OCDevAddr& devAddr,
+                        bool useHostString,
                         const std::string& uri,
                         const OCRepresentation& rep, const QueryParamsMap& queryParams,
                         const HeaderOptions& headerOptions,
@@ -68,6 +70,7 @@ namespace OC
 
         virtual OCStackResult PostResourceRepresentation(
                         const OCDevAddr& devAddr,
+                        bool useHostString,
                         const std::string& uri,
                         const OCRepresentation& rep, const QueryParamsMap& queryParams,
                         const HeaderOptions& headerOptions,
@@ -75,6 +78,7 @@ namespace OC
 
         virtual OCStackResult DeleteResource(
                         const OCDevAddr& devAddr,
+                        bool useHostString,
                         const std::string& uri,
                         const HeaderOptions& headerOptions,
                         DeleteCallback& callback, QualityOfService QoS) = 0;
@@ -82,6 +86,7 @@ namespace OC
         virtual OCStackResult ObserveResource(
                         ObserveType observeType, OCDoHandle* handle,
                         const OCDevAddr& devAddr,
+                        bool useHostString,
                         const std::string& uri,
                         const QueryParamsMap& queryParams,
                         const HeaderOptions& headerOptions, ObserveCallback& callback,
index ddcc86c..4e116f1 100644 (file)
@@ -101,32 +101,32 @@ namespace OC
             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);
index a86badc..57f18db 100644 (file)
@@ -508,6 +508,7 @@ namespace OC
         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;
index 6305851..99aa5a2 100644 (file)
@@ -50,14 +50,14 @@ namespace OC
             {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,
@@ -65,14 +65,14 @@ namespace OC
             {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)
@@ -80,7 +80,7 @@ namespace OC
 
         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)
index f0ffb65..52ea2b7 100644 (file)
@@ -347,8 +347,53 @@ namespace OC
         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)
@@ -459,7 +504,7 @@ namespace OC
     }
 
     OCStackResult InProcClientWrapper::PostResourceRepresentation(
-        const OCDevAddr& devAddr,
+        const OCDevAddr& devAddr, bool useHostString,
         const std::string& uri,
         const OCRepresentation& rep,
         const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
@@ -505,7 +550,7 @@ namespace OC
     }
 
     OCStackResult InProcClientWrapper::PutResourceRepresentation(
-        const OCDevAddr& devAddr,
+        const OCDevAddr& devAddr, bool useHostString,
         const std::string& uri,
         const OCRepresentation& rep,
         const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
@@ -568,7 +613,7 @@ namespace OC
     }
 
     OCStackResult InProcClientWrapper::DeleteResource(
-        const OCDevAddr& devAddr,
+        const OCDevAddr& devAddr, bool useHostString,
         const std::string& uri,
         const HeaderOptions& headerOptions, DeleteCallback& callback, QualityOfService QoS)
     {
@@ -643,7 +688,7 @@ namespace OC
     }
 
     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)
index e46ef16..44506e0 100644 (file)
@@ -22,6 +22,7 @@
 #include "OCUtilities.h"
 
 #include <boost/lexical_cast.hpp>
+#include <sstream>
 
 namespace OC {
 
@@ -35,7 +36,7 @@ OCResource::OCResource(std::weak_ptr<IClientWrapper> clientWrapper,
                         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)
@@ -62,6 +63,7 @@ OCResource::OCResource(std::weak_ptr<IClientWrapper> clientWrapper,
  :  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)
@@ -99,7 +101,7 @@ OCStackResult OCResource::get(const QueryParamsMap& queryParametersMap,
 {
     return checked_guard(m_clientWrapper.lock(),
                             &IClientWrapper::GetResourceRepresentation,
-                            m_devAddr, m_uri,
+                            m_devAddr, m_useHostString, m_uri,
                             queryParametersMap, m_headerOptions,
                             attributeHandler, QoS);
 }
@@ -145,7 +147,7 @@ OCStackResult OCResource::put(const OCRepresentation& rep,
                               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);
 }
 
@@ -195,7 +197,7 @@ OCStackResult OCResource::post(const OCRepresentation& rep,
                                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);
 }
 
@@ -243,7 +245,7 @@ OCStackResult OCResource::post(const std::string& resourceType,
 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)
@@ -265,7 +267,7 @@ OCStackResult OCResource::observe(ObserveType observeType,
 
     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);
 }
 
@@ -306,7 +308,33 @@ OCStackResult OCResource::cancelObserve(QualityOfService 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