Update snapshot(2018-01-04)
[platform/upstream/iotivity.git] / resource / src / InProcClientWrapper.cpp
index abea511..b4a2af8 100644 (file)
@@ -648,6 +648,12 @@ namespace OC
             return OC_STACK_INVALID_PARAM;
         }
 
+        if (headerOptions.size() > MAX_HEADER_OPTIONS)
+        {
+            oclog() << "ListenForMQTopic: Header options are more than MAX_HEADER_OPTIONS" << std::flush;
+            return OC_STACK_INVALID_PARAM;
+        }
+
         ClientCallbackContext::MQTopicContext* context =
             new ClientCallbackContext::MQTopicContext(callback, shared_from_this());
         OCCallbackData cbdata;
@@ -662,7 +668,7 @@ namespace OC
         if (cLock)
         {
             std::lock_guard<std::recursive_mutex> lock(*cLock);
-            OCHeaderOption options[MAX_HEADER_OPTIONS];
+            OCHeaderOption *options = assembleHeaderOptions(headerOptions);
             result = OCDoResource(
                                   nullptr, OC_REST_GET,
                                   uri.c_str(),
@@ -670,8 +676,9 @@ namespace OC
                                   CT_DEFAULT,
                                   static_cast<OCQualityOfService>(QoS),
                                   &cbdata,
-                                  assembleHeaderOptions(options, headerOptions),
+                                  options,
                                   headerOptions.size());
+            delete[] options;
         }
         else
         {
@@ -865,6 +872,13 @@ namespace OC
         {
             return OC_STACK_INVALID_PARAM;
         }
+
+        if (headerOptions.size() > MAX_HEADER_OPTIONS)
+        {
+            oclog() << "PutMQTopicRepresentation: Header options are more than MAX_HEADER_OPTIONS" << std::flush;
+            return OC_STACK_INVALID_PARAM;
+        }
+
         OCStackResult result;
         ClientCallbackContext::MQTopicContext* ctx =
                 new ClientCallbackContext::MQTopicContext(callback, shared_from_this());
@@ -880,7 +894,7 @@ namespace OC
         if (cLock)
         {
             std::lock_guard<std::recursive_mutex> lock(*cLock);
-            OCHeaderOption options[MAX_HEADER_OPTIONS];
+            OCHeaderOption *options = assembleHeaderOptions(headerOptions);
 
             result = OCDoResource(nullptr, OC_REST_PUT,
                                   url.c_str(), &devAddr,
@@ -888,8 +902,9 @@ namespace OC
                                   CT_DEFAULT,
                                   static_cast<OCQualityOfService>(QoS),
                                   &cbdata,
-                                  assembleHeaderOptions(options, headerOptions),
+                                  options,
                                   headerOptions.size());
+             delete[] options;
         }
         else
         {
@@ -937,6 +952,13 @@ namespace OC
         {
             return OC_STACK_INVALID_PARAM;
         }
+
+        if (headerOptions.size() > MAX_HEADER_OPTIONS)
+        {
+            oclog() << "GetResourceRepresentation: Header options are more than MAX_HEADER_OPTIONS" << std::flush;
+            return OC_STACK_INVALID_PARAM;
+        }
+
         OCStackResult result;
         ClientCallbackContext::GetContext* ctx =
             new ClientCallbackContext::GetContext(callback);
@@ -953,7 +975,7 @@ namespace OC
         if (cLock)
         {
             std::lock_guard<std::recursive_mutex> lock(*cLock);
-            OCHeaderOption options[MAX_HEADER_OPTIONS];
+            OCHeaderOption *options = assembleHeaderOptions(headerOptions);
 
             result = OCDoResource(
                                   nullptr, OC_REST_GET,
@@ -962,8 +984,9 @@ namespace OC
                                   connectivityType,
                                   static_cast<OCQualityOfService>(QoS),
                                   &cbdata,
-                                  assembleHeaderOptions(options, headerOptions),
+                                  options,
                                   headerOptions.size());
+            delete[] options;
         }
         else
         {
@@ -1104,6 +1127,13 @@ namespace OC
         {
             return OC_STACK_INVALID_PARAM;
         }
+
+        if (headerOptions.size() > MAX_HEADER_OPTIONS)
+        {
+            oclog() << "PostResourceRepresentation: Header options are more than MAX_HEADER_OPTIONS" << std::flush;
+            return OC_STACK_INVALID_PARAM;
+        }
+
         OCStackResult result;
         ClientCallbackContext::SetContext* ctx = new ClientCallbackContext::SetContext(callback);
         OCCallbackData cbdata;
@@ -1119,7 +1149,7 @@ namespace OC
         if (cLock)
         {
             std::lock_guard<std::recursive_mutex> lock(*cLock);
-            OCHeaderOption options[MAX_HEADER_OPTIONS];
+            OCHeaderOption *options = assembleHeaderOptions(headerOptions);
 
             result = OCDoResource(nullptr, OC_REST_POST,
                                   url.c_str(), &devAddr,
@@ -1127,8 +1157,9 @@ namespace OC
                                   connectivityType,
                                   static_cast<OCQualityOfService>(QoS),
                                   &cbdata,
-                                  assembleHeaderOptions(options, headerOptions),
+                                  options,
                                   headerOptions.size());
+            delete[] options;
         }
         else
         {
@@ -1150,6 +1181,13 @@ namespace OC
         {
             return OC_STACK_INVALID_PARAM;
         }
+
+        if (headerOptions.size() > MAX_HEADER_OPTIONS)
+        {
+            oclog() << "PutResourceRepresentation: Header options are more than MAX_HEADER_OPTIONS" << std::flush;
+            return OC_STACK_INVALID_PARAM;
+        }
+
         OCStackResult result;
         ClientCallbackContext::SetContext* ctx = new ClientCallbackContext::SetContext(callback);
         OCCallbackData cbdata;
@@ -1166,7 +1204,7 @@ namespace OC
         {
             std::lock_guard<std::recursive_mutex> lock(*cLock);
             OCDoHandle handle;
-            OCHeaderOption options[MAX_HEADER_OPTIONS];
+            OCHeaderOption *options = assembleHeaderOptions(headerOptions);
 
             result = OCDoResource(&handle, OC_REST_PUT,
                                   url.c_str(), &devAddr,
@@ -1174,8 +1212,9 @@ namespace OC
                                   CT_DEFAULT,
                                   static_cast<OCQualityOfService>(QoS),
                                   &cbdata,
-                                  assembleHeaderOptions(options, headerOptions),
+                                  options,
                                   headerOptions.size());
+            delete[] options;
         }
         else
         {
@@ -1214,6 +1253,13 @@ namespace OC
         {
             return OC_STACK_INVALID_PARAM;
         }
+
+        if (headerOptions.size() > MAX_HEADER_OPTIONS)
+        {
+            oclog() << "DeleteResource: Header options are more than MAX_HEADER_OPTIONS" << std::flush;
+            return OC_STACK_INVALID_PARAM;
+        }
+
         OCStackResult result;
         ClientCallbackContext::DeleteContext* ctx =
             new ClientCallbackContext::DeleteContext(callback);
@@ -1227,7 +1273,7 @@ namespace OC
 
         if (cLock)
         {
-            OCHeaderOption options[MAX_HEADER_OPTIONS];
+            OCHeaderOption *options = assembleHeaderOptions(headerOptions);
 
             std::lock_guard<std::recursive_mutex> lock(*cLock);
 
@@ -1237,8 +1283,9 @@ namespace OC
                                   connectivityType,
                                   static_cast<OCQualityOfService>(m_cfg.QoS),
                                   &cbdata,
-                                  assembleHeaderOptions(options, headerOptions),
+                                  options,
                                   headerOptions.size());
+            delete[] options;
         }
         else
         {
@@ -1292,6 +1339,13 @@ namespace OC
         {
             return OC_STACK_INVALID_PARAM;
         }
+
+        if (headerOptions.size() > MAX_HEADER_OPTIONS)
+        {
+            oclog() << "ObserveResource: Header options are more than MAX_HEADER_OPTIONS" << std::flush;
+            return OC_STACK_INVALID_PARAM;
+        }
+
         OCStackResult result;
 
         ClientCallbackContext::ObserveContext* ctx =
@@ -1323,7 +1377,7 @@ namespace OC
         if (cLock)
         {
             std::lock_guard<std::recursive_mutex> lock(*cLock);
-            OCHeaderOption options[MAX_HEADER_OPTIONS];
+            OCHeaderOption *options = assembleHeaderOptions(headerOptions);
 
             result = OCDoResource(handle, method,
                                   url.c_str(), &devAddr,
@@ -1331,8 +1385,9 @@ namespace OC
                                   CT_DEFAULT,
                                   static_cast<OCQualityOfService>(QoS),
                                   &cbdata,
-                                  assembleHeaderOptions(options, headerOptions),
+                                  options,
                                   headerOptions.size());
+            delete[] options;
         }
         else
         {
@@ -1350,18 +1405,25 @@ namespace OC
             const HeaderOptions& headerOptions,
             QualityOfService QoS)
     {
+        if (headerOptions.size() > MAX_HEADER_OPTIONS)
+        {
+            oclog() << "CancelObserveResource: Header options are more than MAX_HEADER_OPTIONS" << std::flush;
+            return OC_STACK_INVALID_PARAM;
+        }
+
         OCStackResult result;
         auto cLock = m_csdkLock.lock();
 
         if (cLock)
         {
             std::lock_guard<std::recursive_mutex> lock(*cLock);
-            OCHeaderOption options[MAX_HEADER_OPTIONS];
+            OCHeaderOption *options = assembleHeaderOptions(headerOptions);
 
             result = OCCancel(handle,
                     static_cast<OCQualityOfService>(QoS),
-                    assembleHeaderOptions(options, headerOptions),
+                    options,
                     headerOptions.size());
+            delete[] options;
         }
         else
         {
@@ -1502,16 +1564,15 @@ namespace OC
         return OC_STACK_OK;
     }
 
-    OCHeaderOption* InProcClientWrapper::assembleHeaderOptions(OCHeaderOption options[],
-           const HeaderOptions& headerOptions)
+    OCHeaderOption* InProcClientWrapper::assembleHeaderOptions(const HeaderOptions& headerOptions)
     {
-        int i = 0;
-
         if ( headerOptions.size() == 0)
         {
             return nullptr;
         }
 
+        OCHeaderOption* options = new OCHeaderOption[headerOptions.size()];
+        int i = 0;
         for (auto it=headerOptions.begin(); it != headerOptions.end(); ++it)
         {
             options[i] = OCHeaderOption();