Adding OK Response Code for POST
authoromkar <omkar.m.hegde@intel.com>
Wed, 7 Jan 2015 22:38:14 +0000 (14:38 -0800)
committeromkar <omkar.m.hegde@intel.com>
Thu, 8 Jan 2015 21:23:17 +0000 (13:23 -0800)
Earlier, we were setting response code for POST only if a new resource
is created assuming that the value is by default OK.
TE tests showed error on using different version of Ubuntu.
Modified simpleserver to explicitly add OK status.
Added constructors to OCResourceRequest and
OCResourceResponse classes to avoid undefined behavior.
This Fixes IOT-128.

Change-Id: I13faff2fb254c777ccc8c8979824d53f5111ab3e
Signed-off-by: omkar <omkar.m.hegde@intel.com>
resource/examples/simpleserver.cpp
resource/include/OCResourceRequest.h
resource/include/OCResourceResponse.h

index 86b1546..a4146c6 100644 (file)
@@ -325,6 +325,10 @@ OCEntityHandlerResult entityHandler(std::shared_ptr<OCResourceRequest> request)
                     pResponse->setResponseResult(OC_EH_RESOURCE_CREATED);
                     pResponse->setNewResourceUri(rep_post.getValue<std::string>("createduri"));
                 }
+                else
+                {
+                    pResponse->setResponseResult(OC_EH_OK);
+                }
 
                 if(OC_STACK_OK == OCPlatform::sendResponse(pResponse))
                 {
index 101f6fb..4ec5645 100644 (file)
@@ -44,6 +44,19 @@ namespace OC
     public:
         typedef std::shared_ptr<OCResourceRequest> Ptr;
 
+        OCResourceRequest():
+            m_requestType{},
+            m_resourceUri{},
+            m_queryParameters{},
+            m_requestHandlerFlag{},
+            m_representation{},
+            m_observationInfo{},
+            m_headerOptions{},
+            m_requestHandle{nullptr},
+            m_resourceHandle{nullptr}
+        {
+        }
+
         /**
         *  Virtual destructor
         */
index 1c8e3fa..7671019 100644 (file)
@@ -45,8 +45,17 @@ namespace OC
     public:
         typedef std::shared_ptr<OCResourceResponse> Ptr;
 
-        OCResourceResponse()
-        {}
+        OCResourceResponse():
+            m_newResourceUri{},
+            m_errorCode{},
+            m_headerOptions{},
+            m_interface{},
+            m_representation{},
+            m_requestHandle{nullptr},
+            m_resourceHandle{nullptr},
+            m_responseResult{}
+        {
+        }
 
         virtual ~OCResourceResponse(void) {}