Fix bugs in things manager reported as defects
authorJihun Ha <jihun.ha@samsung.com>
Mon, 21 Sep 2015 10:10:51 +0000 (19:10 +0900)
committerMadan Lanka <lanka.madan@samsung.com>
Mon, 21 Sep 2015 12:58:28 +0000 (12:58 +0000)
CIDs: 65815, 65820, 65838, 65877, 77411, 77412, 81301, 81305, 81306, 81584

Additionally, modify resource type to be compatible to RFC 6690 guideline
for factory set resource.

Change-Id: Ia598cc00f8b3810a14a6341e941f20b11e3c4bfd
Signed-off-by: Jihun Ha <jihun.ha@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2843
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
extlibs/timer/timer.c [changed mode: 0644->0755]
resource/csdk/stack/src/oicgroup.c
service/things-manager/sampleapp/android/Sample/src/com/tm/sample/ConfigurationApiActivity.java [changed mode: 0644->0755]
service/things-manager/sampleapp/android/con-server/src/com/example/con_server/ConfigurationServer.java [changed mode: 0644->0755]
service/things-manager/sampleapp/android/con-server/src/com/example/con_server/FactorySetResource.java [changed mode: 0644->0755]
service/things-manager/sampleapp/linux/configuration/FactorySetCollection.cpp [changed mode: 0644->0755]
service/things-manager/sampleapp/linux/configuration/con-client.cpp [changed mode: 0644->0755]
service/things-manager/sampleapp/tizen/ConServerApp/src/factorysetresource.cpp [changed mode: 0644->0755]
service/things-manager/sampleapp/tizen/TMSampleApp/src/configuration.cpp [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 0dccd4e..d86bdef
@@ -105,6 +105,13 @@ long int getRelativeIntervalOfWeek(struct tm* tp)
     time(&current_time);
     current = localtime(&current_time);
     midnight = (struct tm* )malloc(sizeof(struct tm));
+
+    if(midnight == NULL)
+    {
+        printf("ERROR; Memory allocation fails\n");
+        return 0;
+    }
+
     memcpy(midnight, current, sizeof(struct tm));
 
     midnight->tm_hour = 0;
@@ -117,6 +124,8 @@ long int getRelativeIntervalOfWeek(struct tm* tp)
     delayed_time = getRelativeSecondsOfDayofweek(current->tm_wday, tp->tm_wday) - delayed_time;
     delayed_time = delayed_time + getSeconds(tp);
 
+    free(midnight);
+
     return delayed_time;
 }
 
@@ -193,7 +202,7 @@ time_t registerTimer(const time_t seconds, int *id, void *cb)
 
 void unregisterTimer(int idx)
 {
-    if( 0 <= idx && idx <= TIMEOUTS)
+    if( 0 <= idx && idx < TIMEOUTS)
         timeout_list[idx].timeout_state = TIMEOUT_UNUSED;
 }
 
index fd08907..f0df295 100755 (executable)
@@ -600,16 +600,20 @@ exit:
         OCFREE(*value)
     }
 
+    OCFREE(actionSetStr);
+
     return result;
 }
 
 OCStackResult ExtractActionSetNameAndDelaytime(char *pChar, char **setName,
         long int *pa)
 {
-    char *token, *tokenPtr;
+    char *token = NULL, *tokenPtr = NULL;
     OCStackResult result = OC_STACK_OK;
 
     token = (char*) strtok_r(pChar, ACTION_DELIMITER, &tokenPtr);
+    VARIFY_POINTER_NULL(token, result, exit)
+
     *setName = (char *) OICMalloc(strlen(token) + 1);
     VARIFY_POINTER_NULL(*setName, result, exit)
     VARIFY_PARAM_NULL(token, result, exit)
@@ -661,7 +665,11 @@ OCStackResult BuildActionSetFromString(OCActionSet **set, char* actiondesc)
     iterToken = (char *) strtok_r(NULL, ACTION_DELIMITER, &iterTokenPtr);
     VARIFY_PARAM_NULL(iterToken, result, exit)
 #ifndef WITH_ARDUINO
-    sscanf(iterToken, "%ld %u", &(*set)->timesteps, &(*set)->type);
+    if( 2 != sscanf(iterToken, "%ld %u", &(*set)->timesteps, &(*set)->type) )
+    {
+        // If the return value should be 2, the number of items in the argument. Otherwise, it fails.
+        goto exit;
+    }
 #endif
 
     OC_LOG_V(INFO, TAG, "ActionSet Name : %s", (*set)->actionsetName);
@@ -684,6 +692,8 @@ OCStackResult BuildActionSetFromString(OCActionSet **set, char* actiondesc)
 
             attrIterToken = (char *) strtok_r(attr, ATTR_ASSIGN,
                     &attrIterTokenPtr);
+            VARIFY_POINTER_NULL(attrIterToken, result, exit);
+
             key = (char *) OICMalloc(strlen(attrIterToken) + 1);
             VARIFY_POINTER_NULL(key, result, exit)
             VARIFY_PARAM_NULL(attrIterToken, result, exit)
@@ -1024,7 +1034,10 @@ OCStackResult DoAction(OCResource* resource, OCActionSet* actionset,
                 sizeof(ClientRequestInfo));
 
         if( info == NULL )
+        {
+            OCFREE(payload);
             return OC_STACK_NO_MEMORY;
+        }
 
         memset(info, 0, sizeof(ClientRequestInfo));
 
@@ -1329,6 +1342,8 @@ OCStackResult BuildCollectionGroupActionCBORResponse(
                             {
                                 stackRet = OC_STACK_ERROR;
                             }
+
+                            OICFree(schedule);
                         }
                     }
                 }
@@ -1412,4 +1427,3 @@ exit:
 
     return stackRet;
 }
-
old mode 100644 (file)
new mode 100755 (executable)
index 25eef14..67dd4df
@@ -82,7 +82,7 @@ public class ConfigurationApiActivity extends Activity {
 
     private final String                     CONFIGURATION_RESOURCE_URI             = "/oic/con";
     private final String                     MAINTENANCE_RESOURCE_URI               = "/oic/mnt";
-    private final String                     FACTORYSET_RESOURCE_URI                = "/factorySet";
+    private final String                     FACTORYSET_RESOURCE_URI                = "/factoryset";
 
     private ListView                         list;
     private ArrayAdapter<String>             configurationApis;
@@ -101,7 +101,7 @@ public class ConfigurationApiActivity extends Activity {
     private Map<String, ResourceInformation> collectionList                         = null;
 
     public boolean                           configurationResourceFlag              = false;
-    public boolean                           factorySetResourceFlag                 = false;
+    public boolean                           factorysetResourceFlag                 = false;
     public boolean                           maintenanceResourceFlag                = false;
 
     public static Context                    mcontext;
@@ -188,7 +188,7 @@ public class ConfigurationApiActivity extends Activity {
                         messageCount++;
 
                         resourceTypes.clear();
-                        resourceTypes.add("factorySet");
+                        resourceTypes.add("factoryset");
                         findCandidateResources(resourceTypes);
 
                         messageCount++;
@@ -714,7 +714,7 @@ public class ConfigurationApiActivity extends Activity {
 
             resourceList.put(uri + host, resourceInfo);
             maintenanceResourceFlag = true;
-        } else if (uri.equalsIgnoreCase("/factorySet")) {
+        } else if (uri.equalsIgnoreCase("/factoryset")) {
             ResourceInformation factorysetResource = collectionList
                     .get(FACTORYSET_COLLECTION_RESOURCE_URI);
             if (null == factorysetResource
@@ -733,7 +733,7 @@ public class ConfigurationApiActivity extends Activity {
                     resource, handle);
 
             resourceList.put(uri + host, resourceInfo);
-            factorySetResourceFlag = true;
+            factorysetResourceFlag = true;
         } else {
             Log.e(LOG_TAG, "Resource is of different type: " + uri);
             return;
old mode 100644 (file)
new mode 100755 (executable)
index 7cbb4ff..ab4bcab
@@ -54,7 +54,7 @@ public class ConfigurationServer {
     private ThingsMaintenance                 thingsmnt          = null;
     private ConfigurationResource             conResource        = null;
     private MaintenanceResource               mntResource        = null;
-    private FactorySetResource                factorySetResource = null;
+    private FactorySetResource                factorysetResource = null;
 
     private final ThingsConfigurationListener thingConfigurationListener;
     private final ThingsMaintenanceListener   thingsMaintenanceListener;
@@ -85,8 +85,8 @@ public class ConfigurationServer {
             mntResource = new MaintenanceResource();
             mntResource.createResource(requestHandler);
 
-            factorySetResource = new FactorySetResource();
-            factorySetResource.createResource(requestHandler);
+            factorysetResource = new FactorySetResource();
+            factorysetResource.createResource(requestHandler);
         } catch (OcException e) {
             Log.e(LOG_TAG, "OcException occured: " + e.toString());
         }
@@ -207,8 +207,8 @@ public class ConfigurationServer {
             conResource.deleteResource();
         if (null != mntResource)
             mntResource.deleteResource();
-        if (null != factorySetResource)
-            factorySetResource.deleteResource();
+        if (null != factorysetResource)
+            factorysetResource.deleteResource();
     }
 
     private class RequestHandler implements OcPlatform.EntityHandler {
@@ -248,8 +248,8 @@ public class ConfigurationServer {
                     } else if (request.getResourceUri().equalsIgnoreCase(
                             mntResource.getUri())) {
 
-                        String factorySetAtt = rep.getValueString("fr");
-                        if (factorySetAtt.equalsIgnoreCase("true")) {
+                        String factorysetAtt = rep.getValueString("fr");
+                        if (factorysetAtt.equalsIgnoreCase("true")) {
                             conResource.factoryReset();
                         }
                         mntResource.setDiagnosticsRepresentation(rep);
old mode 100644 (file)
new mode 100755 (executable)
index 79b555b..b5cb94c
@@ -37,9 +37,9 @@ public class FactorySetResource extends ConfigurationResource {
     public FactorySetResource() {
         Log.i(LOG_TAG, "FactorySetCollection: enter");
 
-        configurationUri = "/factorySet"; // uri of the resource
+        configurationUri = "/factoryset"; // uri of the resource
         configurationTypes.clear();
-        configurationTypes.add("factorySet");
+        configurationTypes.add("factoryset");
         configurationRep.setUri(configurationUri);
         configurationRep.setResourceTypes(configurationTypes);
     }
old mode 100644 (file)
new mode 100755 (executable)
index bab6112..acef45b
@@ -35,9 +35,9 @@ using namespace std;
 
 FactorySetResource::FactorySetResource()
 {
-    m_configurationUri = "/factorySet"; // URI of the resource
+    m_configurationUri = "/factoryset"; // URI of the resource
     m_configurationTypes.clear();
-    m_configurationTypes.push_back("factorySet"); // resource type name.
+    m_configurationTypes.push_back("factoryset"); // resource type name.
     m_configurationRep.setUri(m_configurationUri);
     m_configurationRep.setResourceTypes(m_configurationTypes);
 }
old mode 100644 (file)
new mode 100755 (executable)
index b59e983..6bc0e04
@@ -192,7 +192,9 @@ void onFoundCollectionResource(std::vector< std::shared_ptr< OCResource > > reso
         std::cout << "Exception: " << e.what() << std::endl;
     }
 
+    pthread_mutex_lock(&mutex_lock);
     isWaiting = 0;
+    pthread_mutex_unlock(&mutex_lock);
 }
 
 // Callback to found resources
@@ -240,7 +242,7 @@ void onFoundCandidateResource(std::vector< std::shared_ptr< OCResource > > resou
                             if (g_maintenanceResource == NULL)
                                 g_maintenanceResource = resource;
                         }
-                        else if (resource->uri() == "/factorySet")
+                        else if (resource->uri() == "/factoryset")
                         {
                             OCPlatform::bindResource(setCollectionHandle, foundResourceHandle);
                             if (g_setResource == NULL)
@@ -393,7 +395,7 @@ int main(int argc, char* argv[])
 
                 types.push_back("oic.wk.con");
                 types.push_back("oic.wk.mnt");
-                types.push_back("factorySet");
+                types.push_back("factoryset");
 
                 std::cout << "Finding Configuration Resource... " << std::endl;
                 std::cout << "Finding Maintenance Resource... " << std::endl;
old mode 100644 (file)
new mode 100755 (executable)
index b856107..f40de59
@@ -32,9 +32,9 @@ using namespace OC;
 
 FactorySetResource::FactorySetResource()
 {
-    m_configurationUri = "/factorySet"; // URI of the resource
+    m_configurationUri = "/factoryset"; // URI of the resource
     m_configurationTypes.clear();
-    m_configurationTypes.push_back("factorySet"); // resource type name.
+    m_configurationTypes.push_back("factoryset"); // resource type name.
     m_configurationRep.setUri(m_configurationUri);
     m_configurationRep.setResourceTypes(m_configurationTypes);
 }
old mode 100644 (file)
new mode 100755 (executable)
index bdeccb0..0f965a8
@@ -60,7 +60,7 @@ string FACTORYSET_COLLECTION_RESOURCE_TYPE    = "core.factoryset.resourceset";
 
 string CONFIGURATION_RESOURCE_URI             = "/oic/con";
 string MAINTENANCE_RESOURCE_URI                = "/oic/mnt";
-string FACTORYSET_RESOURCE_URI                = "/factorySet";
+string FACTORYSET_RESOURCE_URI                = "/factoryset";
 
 GroupManager *g_groupManager = nullptr;
 ThingsConfiguration *g_thingsConfig = nullptr;
@@ -537,7 +537,7 @@ static void findAllResources(void *data, Evas_Object *obj, void *event_info)
     }
 
     resourceTypes.clear();
-    resourceTypes.push_back("factorySet");
+    resourceTypes.push_back("factoryset");
     if (NULL != g_groupManager)
     {
         g_groupManager->findCandidateResources(resourceTypes, &onFoundCandidateResource,