#endif
#define LOG_TAG "STICKER_DBUS"
+#define STICKER_DIRECTORY tzplatform_mkpath(TZ_SYS_SHARE, "sticker-data")
+
static int is_server_started = 0;
static void _server_appeared_cb(GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer user_data)
return ret;
}
- if (sticker_data->uri && strcmp(sticker_data->uri, origin_data->uri) != 0) {
- LOGD("origin_uri : %s, new_uri : %s", origin_data->uri, sticker_data->uri);
- int is_exist = 0;
- ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", sticker_data->uri), &reply, "check_file_exists");
- if (ret == STICKER_CLIENT_ERROR_NONE) {
- reply_body = g_dbus_message_get_body(reply);
- g_variant_get(reply_body, "(i)", &is_exist);
-
- if (is_exist) {
- LOGE("file already exists");
- ret = STICKER_CLIENT_ERROR_FILE_EXISTS;
+ if (sticker_data->uri) {
+ int len;
+ char *conv_path = NULL;
+ if (sticker_data->type == STICKER_DATA_URI_LOCAL_PATH) {
+ len = strlen(STICKER_DIRECTORY) + strlen(sticker_data->app_id) + strlen(sticker_data->uri) + 2;
+ conv_path = (char *)calloc(len, sizeof(char));
+ snprintf(conv_path, len, "%s/%s%s", STICKER_DIRECTORY, sticker_data->app_id, sticker_data->uri);
+ } else
+ conv_path = strdup(sticker_data->uri);
+
+ if (strcmp(conv_path, origin_data->uri) != 0) {
+ LOGD("origin_uri : %s, new_uri : %s", origin_data->uri, conv_path);
+ int is_exist = 0;
+ ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", sticker_data->uri), &reply, "check_file_exists");
+ if (ret == STICKER_CLIENT_ERROR_NONE) {
+ reply_body = g_dbus_message_get_body(reply);
+ g_variant_get(reply_body, "(i)", &is_exist);
+
+ if (is_exist) {
+ LOGE("file already exists");
+ ret = STICKER_CLIENT_ERROR_FILE_EXISTS;
+ free(conv_path);
+ goto cleanup;
+ }
+ } else {
+ LOGE("failed to check file exists");
+ free(conv_path);
goto cleanup;
}
- } else {
- LOGE("failed to check file exists");
- goto cleanup;
- }
- ret = _send_sync_message(gdbus_connection, g_variant_new("(isis)", sticker_data->sticker_info_id, sticker_data->app_id, sticker_data->type, sticker_data->uri), &reply, "update_sticker_uri");
- if (ret != STICKER_CLIENT_ERROR_NONE) {
- LOGE("failed to update sticker uri");
- goto cleanup;
+ ret = _send_sync_message(gdbus_connection, g_variant_new("(isis)", sticker_data->sticker_info_id, sticker_data->app_id, sticker_data->type, sticker_data->uri), &reply, "update_sticker_uri");
+ if (ret != STICKER_CLIENT_ERROR_NONE) {
+ LOGE("failed to update sticker uri");
+ free(conv_path);
+ goto cleanup;
+ }
}
+ free(conv_path);
}
if (sticker_data->type != 0 && sticker_data->type != origin_data->type) {
}
}
- if (sticker_data->thumbnail && strcmp(sticker_data->thumbnail, origin_data->thumbnail) != 0) {
- LOGD("origin_thumbnail : %s, new_thumbnail : %s", origin_data->thumbnail, sticker_data->thumbnail);
- ret = _send_sync_message(gdbus_connection, g_variant_new("(iss)", sticker_data->sticker_info_id, sticker_data->app_id, sticker_data->thumbnail), &reply, "update_sticker_thumbnail");
- if (ret != STICKER_CLIENT_ERROR_NONE) {
- LOGE("failed to update sticker thumbnail");
- goto cleanup;
+ if (sticker_data->thumbnail) {
+ int len = strlen(STICKER_DIRECTORY) + strlen(sticker_data->app_id) + strlen(sticker_data->thumbnail) + 2;
+ char *conv_path = (char *)calloc(len, sizeof(char));
+ snprintf(conv_path, len, "%s/%s%s", STICKER_DIRECTORY, sticker_data->app_id, sticker_data->thumbnail);
+ if (strcmp(conv_path, origin_data->thumbnail) != 0) {
+ LOGD("origin_thumbnail : %s, new_thumbnail : %s", origin_data->thumbnail, conv_path);
+ ret = _send_sync_message(gdbus_connection, g_variant_new("(iss)", sticker_data->sticker_info_id, sticker_data->app_id, sticker_data->thumbnail), &reply, "update_sticker_thumbnail");
+ if (ret != STICKER_CLIENT_ERROR_NONE) {
+ LOGE("failed to update sticker thumbnail");
+ free(conv_path);
+ goto cleanup;
+ }
}
+ free(conv_path);
}
if (sticker_data->description && strcmp(sticker_data->description, origin_data->description) != 0) {
#define STICKER_DB_GET_LATEST_RECORD_ID "SELECT sticker_info_id FROM sticker_info ORDER BY sticker_info_id DESC LIMIT 1"
#define STICKER_DB_GET_STICKER_INFO_BY_RECORD_ID "SELECT * FROM sticker_info WHERE sticker_info_id = ?"
#define STICKER_DB_GET_KEYWORD_INFO_BY_RECORD_ID "SELECT keyword FROM sticker_keyword_info WHERE sticker_info_id = ?"
+#define STICKER_DB_GET_IMAGE_INFO_BY_RECORED_ID "SELECT type, uri, thumbnail FROM sticker_info WHERE sticker_info_id = ?"
+#define STICKER_DB_GET_IMAGE_INFO_BY_URI "SELECT type, thumbnail FROM sticker_info WHERE uri = ?"
#define STICKER_DB_GET_ALL_GROUP_LIST "SELECT DISTINCT group_name FROM sticker_info WHERE app_id NOT IN (SELECT DISTINCT provider_id FROM sticker_whitelist_info WHERE provider_id NOT IN (SELECT provider_id FROM sticker_whitelist_info WHERE consumer_id = ?))"
#define STICKER_DB_GET_ALL_KEYWORD_LIST "SELECT DISTINCT keyword FROM sticker_keyword_info WHERE sticker_info_id IN (SELECT sticker_info_id from sticker_info WHERE app_id NOT IN (SELECT DISTINCT provider_id FROM sticker_whitelist_info WHERE provider_id NOT IN (SELECT provider_id FROM sticker_whitelist_info WHERE consumer_id = ?)))"
#define STICKER_DB_GET_STICKER_COUNT "SELECT count(*) FROM sticker_info WHERE app_id = ?"
if (!db)
return STICKERD_SERVER_ERROR_DB_FAILED;
+ ret = sqlite3_prepare_v2(db, STICKER_DB_GET_IMAGE_INFO_BY_RECORED_ID, -1, &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ LOGE("fail to get image files : %s", sqlite3_errmsg(db));
+ goto cleanup;
+ }
+
+ sqlite3_bind_int(stmt, 1, record_id);
+
+ ret = sqlite3_step(stmt);
+ if (ret == SQLITE_ERROR) {
+ LOGE("sqlite3_step() failed : ret(%d)", ret);
+ goto cleanup;
+ }
+
+ int uri_type = sqlite3_column_int(stmt, 0);
+ const unsigned char *uri = sqlite3_column_text(stmt, 1);
+ const unsigned char *thumbnail = sqlite3_column_text(stmt, 2);
+
+ if (uri_type == 1 && unlink((const char *)uri) == -1)
+ LOGE("fail to delete sticker file");
+
+ if (thumbnail && unlink((const char *)thumbnail) == -1)
+ LOGE("fail to delete thumbnail image");
+
+ sqlite3_finalize(stmt);
+ stmt = NULL;
+
ret = sqlite3_prepare_v2(db, STICKER_DB_DELETE_STICKER_INFO, -1, &stmt, NULL);
if (ret != SQLITE_OK) {
LOGE("fail to delete sticker information : %s", sqlite3_errmsg(db));
if (!db)
return STICKERD_SERVER_ERROR_DB_FAILED;
+ ret = sqlite3_prepare_v2(db, STICKER_DB_GET_IMAGE_INFO_BY_URI, -1, &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ LOGE("fail to delete sticker information : %s", sqlite3_errmsg(db));
+ goto cleanup;
+ }
+
+ sqlite3_bind_text(stmt, 1, uri, -1, SQLITE_TRANSIENT);
+
+ ret = sqlite3_step(stmt);
+ if (ret == SQLITE_ERROR) {
+ LOGE("sqlite3_step() failed : ret(%d)", ret);
+ goto cleanup;
+ }
+
+ int uri_type = sqlite3_column_int(stmt, 0);
+ const unsigned char *thumbnail = sqlite3_column_text(stmt, 1);
+
+ if (uri_type == 1 && unlink((const char *)uri) == -1)
+ LOGE("fail to delete sticker file");
+
+ if (thumbnail && unlink((const char *)thumbnail) == -1)
+ LOGE("fail to delete thumbnail image");
+
+ sqlite3_finalize(stmt);
+ stmt = NULL;
+
ret = sqlite3_prepare_v2(db, STICKER_DB_DELETE_STICKER_INFO_BY_URI, -1, &stmt, NULL);
if (ret != SQLITE_OK) {
LOGE("fail to delete sticker information : %s", sqlite3_errmsg(db));