apply encoded name to the source file of losetup.
[platform/core/appfw/app2sd.git] / plugin / app2sd / src / app2sd_internals_utils.c
index 83e415e..300f86b 100644 (file)
@@ -60,9 +60,9 @@ int _xsystem(const char *argv[])
        case 0:
                /* child */
                strerror_r(errno, err_buf, sizeof(err_buf));
-               if (execvp(argv[0], (char *const *)argv) < 0) {
-                       fprintf(stderr, "execvp failed %d....%s\n", errno, err_buf);    /*Don't use d_msg_app2sd */
-               }
+               if (execvp(argv[0], (char *const *)argv) < 0)
+                       fprintf(stderr, "execvp failed %d....%s\n",
+                               errno, err_buf);
                _exit(-1);
        default:
                /* parent */
@@ -611,9 +611,9 @@ char *_app2sd_find_free_device(void)
 */
 char *_app2sd_generate_password(const char *pkgid)
 {
-       char passwd[PASSWD_LEN+1] = { 0, };
+       char passwd[PASSWD_LEN + 1] = { 0, };
        char *ret_result = NULL;
-       char set[ASCII_PASSWD_CHAR+1] =
+       char set[ASCII_PASSWD_CHAR + 1] =
                "!\"#$%&()*+,-./0123456789:;<=>?@ABCDE" \
                "FGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
        unsigned char char_1;
@@ -646,3 +646,23 @@ char *_app2sd_generate_password(const char *pkgid)
 
        return ret_result;
 }
+
+char *_app2sd_get_encoded_name(const char *pkgid, uid_t uid)
+{
+       char *new_name = NULL;
+       char *temp_string = NULL;
+       char source_name[FILENAME_MAX] = { 0, };
+       GChecksum *checksum;
+
+       snprintf(source_name, FILENAME_MAX - 1, "%s_%d", pkgid, uid);
+       checksum = g_checksum_new(G_CHECKSUM_MD5);
+       g_checksum_update(checksum, (const guchar *)source_name, strlen(source_name));
+       temp_string = (char *)g_checksum_get_string(checksum);
+       _D("temp_string(%s)", temp_string);
+       new_name = strdup(temp_string);
+       g_checksum_free(checksum);
+
+       _D("new_name(%s)", new_name);
+
+       return new_name;
+}