Launch sticker-receiver for receiving sticker feature
[platform/core/uifw/capi-ui-sticker.git] / sticker-parser / sticker-parser.c
index d5a3bd4..a54e9ab 100644 (file)
 #endif
 #define LOG_TAG "STICKER_PARSER"
 
-#define STICKER_DIRECTORY tzplatform_mkpath(TZ_SYS_SHARE, "sticker-data")
+#define STICKER_DIRECTORY "/opt/usr/share/sticker-data"
 #define STICKER_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_info(sticker_info_id INTEGER PRIMARY KEY AUTOINCREMENT, app_id TEXT NOT NULL, type INTEGER NOT NULL, uri TEXT NOT NULL, thumbnail TEXT, description TEXT, group_name TEXT NOT NULL, date TEXT NOT NULL, display_type INTEGER)"
 #define STICKER_KEYWORD_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_keyword_info(keyword_id INTEGER PRIMARY KEY AUTOINCREMENT, sticker_info_id INTEGER, keyword TEXT NOT NULL, FOREIGN KEY (sticker_info_id) REFERENCES sticker_info(sticker_info_id) ON DELETE CASCADE)"
 #define STICKER_WHITELIST_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_whitelist_info(whitelist_id INTEGER PRIMARY KEY AUTOINCREMENT, provider_id TEXT NOT NULL, consumer_id TEXT NOT NULL)"
+#define STICKER_RECENT_HISTORY_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_recent_history_info(history_id INTEGER PRIMARY KEY AUTOINCREMENT, sticker_info_id INTEGER, count INTEGER NOT NULL, timestamp TEXT NOT NULL, FOREIGN KEY (sticker_info_id) REFERENCES sticker_info(sticker_info_id) ON DELETE CASCADE)"
 #define UIFW_ID           502
 #define APPFW_ID          301
 #define MAX_ERROR_BUFFER  256
@@ -130,6 +131,12 @@ static void __recover_db()
         goto cleanup;
     }
 
+    ret = sqlite3_exec(db, STICKER_RECENT_HISTORY_INFO_CREATE_TABLE, NULL, NULL, &err);
+    if (ret != SQLITE_OK) {
+        LOGE("Failed to create sticker_recent_history_info table : %s", err);
+        goto cleanup;
+    }
+
     is_corrupted = FALSE;
 
 cleanup:
@@ -186,6 +193,12 @@ static void __db_init()
         goto cleanup;
     }
 
+    ret = sqlite3_exec(db, STICKER_RECENT_HISTORY_INFO_CREATE_TABLE, NULL, NULL, &err);
+    if (ret != SQLITE_OK) {
+        LOGE("Failed to create sticker_recent_history_info table : %s", err);
+        goto cleanup;
+    }
+
     ret = sqlite3_exec(db, "PRAGMA journal_mode = WAL", NULL, NULL, &err);
     if (ret != SQLITE_OK) {
         LOGE("Failed to set journal_mode : %s", err);
@@ -348,21 +361,17 @@ cleanup:
     return ret;
 }
 
-static char* __convert_sticker_uri(const char *uri, const char *appid, const char *app_path)
+static char* __convert_sticker_uri(char *uri, const char *appid, const char *app_path)
 {
     int ret;
-    char *rel_path = strdup(uri);
 
-    __remove_app_path(rel_path, app_path);
-    int len = strlen(STICKER_DIRECTORY) + strlen(appid) + strlen(rel_path) + 2;
+    __remove_app_path(uri, app_path);
+    int len = strlen(STICKER_DIRECTORY) + strlen(appid) + strlen(uri) + 2;
     char *new_path = (char *)calloc(len, sizeof(char));
-    if (new_path == NULL) {
-        free(rel_path);
-        rel_path = NULL;
+    if (new_path == NULL)
         return NULL;
-    }
 
-    snprintf(new_path, len, "%s/%s%s",STICKER_DIRECTORY, appid, rel_path);
+    snprintf(new_path, len, "%s/%s%s",STICKER_DIRECTORY, appid, uri);
 
     if (access(new_path, F_OK) == 0) {
         LOGE("sticker file already exists");
@@ -393,9 +402,6 @@ static char* __convert_sticker_uri(const char *uri, const char *appid, const cha
         LOGE("failed to change ownership");
 
 cleanup:
-    free(rel_path);
-    rel_path = NULL;
-
     if (ret == 0) {
         return new_path;
     } else {
@@ -543,7 +549,7 @@ static int __get_sticker_info_from_json(const char *appid, const char *file_path
     char *uri = NULL;
     char *group = NULL;
     char *description = NULL;
-    char *thumbnail = NULL;
+    char *thumbnail_path = NULL;
     char *uri_path = NULL;
 
     parser = json_parser_new();
@@ -598,9 +604,13 @@ static int __get_sticker_info_from_json(const char *appid, const char *file_path
             if (!group)
                 goto free_memory;
 
-            thumbnail = __get_string_from_object(info_object, "thumbnail");
-            if (thumbnail)
-                thumbnail = __convert_sticker_uri(thumbnail, appid, app_path);
+            char *rel_thumbnail = __get_string_from_object(info_object, "thumbnail");
+            if (rel_thumbnail) {
+                if (rel_thumbnail[0] != '\0')
+                    thumbnail_path = __convert_sticker_uri(rel_thumbnail, appid, app_path);
+
+                free(rel_thumbnail);
+            }
 
             description = __get_string_from_object(info_object, "description");
             int disp_type = __get_int_from_object(info_object, "display_type");
@@ -615,7 +625,7 @@ static int __get_sticker_info_from_json(const char *appid, const char *file_path
                     char *new_uri = __convert_sticker_uri(uri, appid, app_path);
                     if (!new_uri)
                         goto free_memory;
-                    __insert_sticker_info(appid, type, new_uri, group, thumbnail, description, disp_type);
+                    __insert_sticker_info(appid, type, new_uri, group, thumbnail_path, description, disp_type);
 
                     if (new_uri) {
                         free(new_uri);
@@ -641,7 +651,7 @@ static int __get_sticker_info_from_json(const char *appid, const char *file_path
                             uri_path = NULL;
                             goto free_memory;
                         }
-                        __insert_sticker_info(appid, type, new_uri, group, thumbnail, description, disp_type);
+                        __insert_sticker_info(appid, type, new_uri, group, thumbnail_path, description, disp_type);
 
                         free(new_uri);
                         new_uri = NULL;
@@ -656,7 +666,7 @@ static int __get_sticker_info_from_json(const char *appid, const char *file_path
                     }
                 }
             } else {
-                __insert_sticker_info(appid, type, uri, group, thumbnail, description, disp_type);
+                __insert_sticker_info(appid, type, uri, group, thumbnail_path, description, disp_type);
             }
 
             for (int j = 0; j < keyword_arr_len; j++) {
@@ -674,9 +684,9 @@ free_memory:
                 group = NULL;
             }
 
-            if (thumbnail) {
-                free(thumbnail);
-                thumbnail = NULL;
+            if (thumbnail_path) {
+                free(thumbnail_path);
+                thumbnail_path = NULL;
             }
 
             if (description) {