Clean up duplicated logic
authorSung-jae Park <nicesj.park@samsung.com>
Thu, 5 Feb 2015 04:36:55 +0000 (13:36 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Thu, 5 Feb 2015 04:36:55 +0000 (13:36 +0900)
[model] Redwood,Kiran,B3(Wearable)
[binary_type] AP
[customer] Docomo/Orange/ATT/Open
[issue#] N/A
[problem]
[cause]
[solution]
[team] HomeTF
[request]
[horizontal_expansion]

Change-Id: I61bb4424b5101cf6af900363e13a1a1d00587748

src/server.c

index 23fdc90..107f043 100644 (file)
@@ -109,10 +109,9 @@ struct deleted_item {
 /**
  * Returns DBox Id from provider Id
  */
-static char *is_valid_slave(pid_t pid, struct slave_node *slave, const char *provider_pkgname)
+static char *is_valid_slave(pid_t pid, const char *abi, const char *provider_pkgname)
 {
        char pid_pkgname[pathconf("/", _PC_PATH_MAX)];
-       const char *abi;
        const char *abi_pkgname;
        dynamicbox_pkglist_h list_handle;
        char *pkgid;
@@ -121,13 +120,7 @@ static char *is_valid_slave(pid_t pid, struct slave_node *slave, const char *pro
        int verified;
 
        if (aul_app_get_pkgname_bypid(pid, pid_pkgname, sizeof(pid_pkgname)) != AUL_R_OK) {
-               ErrPrint("pid[%d] is not authroized provider package, try to find it using its name[%s]\n", pid, slave_name(slave));
-               return NULL;
-       }
-
-       abi = slave_abi(slave);
-       if (!abi) {
-               ErrPrint("Slave doesn't have valid abi\n");
+               ErrPrint("pid[%d] is not authroized provider package\n", pid);
                return NULL;
        }
 
@@ -940,7 +933,7 @@ static int validate_request(pid_t pid, struct slave_node *slave, const char *pkg
                 * But the standalone providers will use its package id (ui-app, provider id)
                 * For later case, we should convert the provider pkgname to dbox id
                 */
-               dbox_id = is_valid_slave(pid, slave, pkgname);
+               dbox_id = is_valid_slave(pid, slave_abi(slave), pkgname);
                if (!dbox_id) {
                        return DBOX_STATUS_ERROR_INVALID_PARAMETER;
                }
@@ -6523,127 +6516,63 @@ static struct packet *slave_hello(pid_t pid, int handle, const struct packet *pa
                        slave_set_pid(slave, pid);
                        DbgPrint("Provider is forcely activated, pkgname(%s), abi(%s), slavename(%s)\n", pkgname, abi, slavename);
                } else {
-                       dynamicbox_pkglist_h list_handle;
-                       const char *tmp;
-
-                       tmp = abi_find_slave(abi);
-// abi == app
-// tmp == /APPID/
-// pkgname = com.samsung.watch-sample (from pid, aul_get_pkgname)
-                       if (!strcmp(tmp, pkgname)) {
-                               ErrPrint("Only 3rd or 2nd party can be connected without request of master (%s)\n", pkgname);
+                       char *dbox_id;
+                       struct pkg_info *info;
+                       int network;
+
+                       dbox_id = is_valid_slave(pid, abi, pkgname);
+                       if (!dbox_id) {
+                               goto out;
+                       }
+
+                       info = package_find(dbox_id);
+                       DbgFree(dbox_id);
+
+                       if (!info) {
+                               DbgPrint("There is no loaded package information\n");
                                goto out;
                        } else {
-                               /* In this case, we should check the whole dbox packages */
-                               char *pkgid;
-                               int matched;
-                               char *dbox_id;
-                               char *provider_pkgname;
-                               int network = 0;
-
-                               // ui-app -> PACKAGE ID
-                               pkgid = package_get_pkgid(pkgname);
-                               if (!pkgid) {
-                                       ErrPrint("Unknown package (%s)\n", pkgname);
+                               const char *category;
+                               const char *db_acceleration;
+                               int db_secured;
+                               const char *tmp;
+
+                               category = package_category(info);
+                               tmp = package_abi(info);
+                               db_secured = package_secured(info);
+                               db_acceleration = package_hw_acceleration(info);
+
+                               if (db_secured != secured) {
+                                       DbgPrint("%s secured (%d)\n", pkgname, db_secured);
                                        goto out;
                                }
 
-                               /*
-                                * Verify the dbox provider app package name
-                                */
-                               list_handle = dynamicbox_service_pkglist_create(pkgid, NULL);
-                               DbgFree(pkgid);
-
-                               matched = 0;
-
-                               while (dynamicbox_service_get_pkglist_item(list_handle, NULL, &dbox_id, NULL) == DBOX_STATUS_ERROR_NONE) {
-                                       if (!dbox_id) {
-                                               ErrPrint("Invalid dbox_id\n");
-                                               continue;
-                                       }
-
-                                       // tmp == /APPID/.provider <<- PROVIDER UI-APP
-                                       // dbox_id == com.samsung.watch-hello <<-- DBOX ID
-                                       // provider_pkgname == com.samsung.watch-hello.provider
-                                       provider_pkgname = util_replace_string(tmp, DYNAMICBOX_CONF_REPLACE_TAG_APPID, dbox_id);
-                                       if (!provider_pkgname) {
-                                               DbgFree(dbox_id);
-                                               dbox_id = NULL;
-                                               continue;
-                                       }
-
-                                       /* Verify the Package Name */
-                                       matched = !strcmp(pkgname, provider_pkgname);
-                                       DbgFree(provider_pkgname);
-                                       
-                                       if (matched) {
-                                               struct pkg_info *info;
-
-                                               info = package_find(dbox_id);
-                                               DbgFree(dbox_id);
-                                               matched = 0;
-
-                                               if (!info) {
-                                                       DbgPrint("There is no loaded package information\n");
-                                               } else {
-                                                       const char *category;
-                                                       const char *db_acceleration;
-                                                       int db_secured;
-
-                                                       category = package_category(info);
-                                                       tmp = package_abi(info);
-                                                       db_secured = package_secured(info);
-                                                       db_acceleration = package_hw_acceleration(info);
-
-                                                       if (db_secured != secured) {
-                                                               DbgPrint("%s secured (%d)\n", pkgname, db_secured);
-                                                               break;
-                                                       }
-
-                                                       if (strcmp(tmp, abi)) {
-                                                               DbgPrint("%s abi (%s)\n", pkgname, tmp);
-                                                               break;
-                                                       }
-
-                                                       if (strcmp(acceleration, db_acceleration)) {
-                                                               DbgPrint("%s accel (%s)\n", pkgname, db_acceleration);
-                                                               break;
-                                                       }
-
-                                                       if (util_string_is_in_list(category, DYNAMICBOX_CONF_CATEGORY_LIST) == 0) {
-                                                               DbgPrint("%s category (%s)\n", pkgname, category);
-                                                               break;
-                                                       }
-
-                                                       network = package_network(info);
-                                                       matched = 1;
-
-                                                       //instance_create(....)
-                                               }
-
-                                               break;
-                                       }
-
-                                       DbgFree(dbox_id);
+                               if (strcmp(tmp, abi)) {
+                                       DbgPrint("%s abi (%s)\n", pkgname, tmp);
+                                       goto out;
                                }
 
-                               dynamicbox_service_pkglist_destroy(list_handle);
-                               if (!matched) {
-                                       ErrPrint("Invalid package: %s\n", pkgname);
+                               if (strcmp(acceleration, db_acceleration)) {
+                                       DbgPrint("%s accel (%s)\n", pkgname, db_acceleration);
                                        goto out;
                                }
 
-                               slave = slave_create(slavename, secured, abi, pkgname, network, acceleration);
-                               if (!slave) {
-                                       ErrPrint("Failed to create a new slave for %s\n", slavename);
+                               if (util_string_is_in_list(category, DYNAMICBOX_CONF_CATEGORY_LIST) == 0) {
+                                       DbgPrint("%s category (%s)\n", pkgname, category);
                                        goto out;
                                }
 
-                               slave_set_pid(slave, pid);
-                               DbgPrint("Slave is activated by request: %d (%s)/(%s)\n", pid, pkgname, slavename);
+                               network = package_network(info);
+                       }
 
-                               // instance_create
+                       slave = slave_create(slavename, secured, abi, pkgname, network, acceleration);
+                       if (!slave) {
+                               ErrPrint("Failed to create a new slave for %s\n", slavename);
+                               goto out;
                        }
+
+                       slave_set_pid(slave, pid);
+                       DbgPrint("Slave is activated by request: %d (%s)/(%s)\n", pid, pkgname, slavename);
                }
        } else {
                if (slave_pid(slave) != pid) {