X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fail_desktop.c;h=15e4fa460aefeed424767e82772e11b0af0814ae;hb=refs%2Fheads%2Faccepted%2Ftizen_mobile;hp=1e666cc53304c41b3aca708c1545529da993ad38;hpb=8bcc17cce742412499493719b2b4f11a980a1f17;p=platform%2Fcore%2Fappfw%2Fail.git diff --git a/src/ail_desktop.c b/src/ail_desktop.c index 1e666cc..15e4fa4 100755 --- a/src/ail_desktop.c +++ b/src/ail_desktop.c @@ -42,6 +42,7 @@ #include "ail_sql.h" #include "ail.h" #include "ail_vconf.h" +#include "ail_convert.h" #define BUFSIZE 4096 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) @@ -55,7 +56,7 @@ #define SQL_INSERT_LOCALNAME_INIT_STR SQL_INSERT_LOCALNAME_STR"( ?, ?, ?) " #define SQL_LOCALNAME_TRIPLET_STR ", ( ?, ?, ?)" -#define SQL_LOCALNAME_TRIPLET_STR_LEN (sizeof(SQL_LOCALNAME_TRIPLET_STR)-1) +#define SQL_LOCALNAME_TRIPLET_STR_LEN (sizeof(SQL_LOCALNAME_TRIPLET_STR) - 1) typedef enum { NOTI_ADD, @@ -69,23 +70,24 @@ struct entry_parser { ail_error_e (*value_cb)(void *data, char *tag, char *value, uid_t uid); }; -inline static char *_ltrim(char *str) +static inline char *_ltrim(char *str) { - if (!str) return NULL; + if (!str) + return NULL; - while (*str == ' ' || *str == '\t' || *str == '\n') str ++; + while (*str == ' ' || *str == '\t' || *str == '\n') + str++; return str; } - - -inline static int _rtrim(char *str) +static inline int _rtrim(char *str) { int len; len = strlen(str); - while (--len >= 0 && (str[len] == ' ' || str[len] == '\n' || str[len] == '\t')) str[len] = '\0'; + while (--len >= 0 && (str[len] == ' ' || str[len] == '\n' || str[len] == '\t')) + str[len] = '\0'; return len; } @@ -129,8 +131,6 @@ typedef struct { GSList* localname; } desktop_info_s; - - static ail_error_e _read_exec(void *data, char *tag, char *value, uid_t uid) { desktop_info_s *info = data; @@ -145,7 +145,7 @@ static ail_error_e _read_exec(void *data, char *tag, char *value, uid_t uid) retv_if(!info->exec, AIL_ERROR_OUT_OF_MEMORY); temp_exec = strdup(value); - if(!temp_exec) { + if (!temp_exec) { free(info->exec); return AIL_ERROR_OUT_OF_MEMORY; } @@ -153,7 +153,7 @@ static ail_error_e _read_exec(void *data, char *tag, char *value, uid_t uid) token_exe_path = strtok_r(temp_exec, argsdelimiter, &save_ptr); info->x_slp_exe_path = strdup(token_exe_path); - if(!info->x_slp_exe_path) { + if (!info->x_slp_exe_path) { free(info->exec); info->exec = NULL; free(temp_exec); @@ -165,8 +165,6 @@ static ail_error_e _read_exec(void *data, char *tag, char *value, uid_t uid) return AIL_ERROR_OK; } - - static ail_error_e _read_name(void *data, char *tag, char *value, uid_t uid) { desktop_info_s *info = data; @@ -178,17 +176,17 @@ static ail_error_e _read_name(void *data, char *tag, char *value, uid_t uid) if (tag && strlen(tag) > 0) { struct name_item *item; item = (struct name_item *)calloc(1, sizeof(struct name_item)); - retv_if (NULL == item, AIL_ERROR_OUT_OF_MEMORY); + retv_if(NULL == item, AIL_ERROR_OUT_OF_MEMORY); SAFE_FREE_AND_STRDUP(tag, item->locale); - if(NULL == item->locale) { + if (item->locale == NULL) { _E("(NULL == item->locale) return\n"); free(item); return AIL_ERROR_OUT_OF_MEMORY; } SAFE_FREE_AND_STRDUP(value, item->name); - if(NULL == item->name) { + if (item->name == NULL) { _E("(NULL == item->name) return\n"); free(item->locale); free(item); @@ -200,14 +198,12 @@ static ail_error_e _read_name(void *data, char *tag, char *value, uid_t uid) return AIL_ERROR_OK; } else { SAFE_FREE_AND_STRDUP(value, info->name); - retv_if (!info->name, AIL_ERROR_OUT_OF_MEMORY); + retv_if(!info->name, AIL_ERROR_OUT_OF_MEMORY); return AIL_ERROR_OK; } } - - static ail_error_e _read_type(void *data, char *tag, char *value, uid_t uid) { desktop_info_s *info = data; @@ -216,33 +212,29 @@ static ail_error_e _read_type(void *data, char *tag, char *value, uid_t uid) retv_if(!value, AIL_ERROR_INVALID_PARAMETER); SAFE_FREE_AND_STRDUP(value, info->type); - retv_if (!info->type, AIL_ERROR_OUT_OF_MEMORY); + retv_if(!info->type, AIL_ERROR_OUT_OF_MEMORY); return AIL_ERROR_OK; } - -static char* -_get_package_from_icon(char* icon) +static char *_get_package_from_icon(char* icon) { - char* package; - char* extension; + char *package; + char *extension; retv_if(!icon, NULL); package = strdup(icon); retv_if(!package, NULL); extension = rindex(package, '.'); - if (extension) { + if (extension) *extension = '\0'; - } else { + else _E("cannot extract from icon [%s] to package.", icon); - } return package; } - static char* _get_icon_with_path(char* icon, uid_t uid) { @@ -253,28 +245,22 @@ _get_icon_with_path(char* icon, uid_t uid) char* theme = NULL; char* icon_with_path = NULL; int len; - char *app_path = NULL; + const char *app_path = NULL; package = _get_package_from_icon(icon); retv_if(!package, NULL); -/* "db/setting/theme" is not exist */ -#if 0 - theme = ail_vconf_get_str("db/setting/theme"); - if (!theme) { - theme = strdup("default"); - if(!theme) { - free(package); - return NULL; - } - } -#else + /* "db/setting/theme" is not exist */ theme = strdup("default"); -#endif + if (theme == NULL) { + _E("out of memory"); + free(package); + return NULL; + } len = (0x01 << 7) + strlen(icon) + strlen(package) + strlen(theme); icon_with_path = malloc(len); - if(icon_with_path == NULL) { + if (icon_with_path == NULL) { _E("icon_with_path == NULL\n"); free(package); free(theme); @@ -282,16 +268,17 @@ _get_icon_with_path(char* icon, uid_t uid) } memset(icon_with_path, 0, len); + if (uid != GLOBAL_USER) - sqlite3_snprintf( len, icon_with_path, "%s%q", ail_get_icon_path(uid), icon); + sqlite3_snprintf(len, icon_with_path, "%s%q", ail_get_icon_path(uid), icon); else - sqlite3_snprintf( len, icon_with_path, "%s/%q/small/%q", ail_get_icon_path(GLOBAL_USER), theme, icon); - - if (access (icon_with_path, F_OK)) { + sqlite3_snprintf(len, icon_with_path, "%s/%q/small/%q", ail_get_icon_path(GLOBAL_USER), theme, icon); + + if (access(icon_with_path, F_OK)) { app_path = tzplatform_getenv(TZ_SYS_RW_APP); if (app_path) - sqlite3_snprintf( len, icon_with_path, "%s/%q/res/icons/%q/small/%q",app_path, package, theme, icon); - if (access (icon_with_path, F_OK)) + sqlite3_snprintf(len, icon_with_path, "%s/%q/res/icons/%q/small/%q", app_path, package, theme, icon); + if (access(icon_with_path, F_OK)) _E("Cannot find icon path"); } free(theme); @@ -307,7 +294,6 @@ _get_icon_with_path(char* icon, uid_t uid) } } - static ail_error_e _read_icon(void *data, char *tag, char *value, uid_t uid) { desktop_info_s *info = data; @@ -317,13 +303,11 @@ static ail_error_e _read_icon(void *data, char *tag, char *value, uid_t uid) info->icon = _get_icon_with_path(value, uid); - retv_if (!info->icon, AIL_ERROR_OUT_OF_MEMORY); + retv_if(!info->icon, AIL_ERROR_OUT_OF_MEMORY); return AIL_ERROR_OK; } - - static ail_error_e _read_categories(void *data, char *tag, char *value, uid_t uid) { desktop_info_s *info = data; @@ -332,13 +316,11 @@ static ail_error_e _read_categories(void *data, char *tag, char *value, uid_t ui retv_if(!value, AIL_ERROR_INVALID_PARAMETER); SAFE_FREE_AND_STRDUP(value, info->categories); - retv_if (!info->categories, AIL_ERROR_OUT_OF_MEMORY); + retv_if(!info->categories, AIL_ERROR_OUT_OF_MEMORY); return AIL_ERROR_OK; } - - static ail_error_e _read_version(void *data, char *tag, char *value, uid_t uid) { desktop_info_s *info = data; @@ -347,13 +329,11 @@ static ail_error_e _read_version(void *data, char *tag, char *value, uid_t uid) retv_if(!value, AIL_ERROR_INVALID_PARAMETER); SAFE_FREE_AND_STRDUP(value, info->version); - retv_if (!info->version, AIL_ERROR_OUT_OF_MEMORY); + retv_if(!info->version, AIL_ERROR_OUT_OF_MEMORY); return AIL_ERROR_OK; } - - static ail_error_e _read_mimetype(void *data, char *tag, char *value, uid_t uid) { desktop_info_s *info = data; @@ -369,7 +349,7 @@ static ail_error_e _read_mimetype(void *data, char *tag, char *value, uid_t uid) size = getpagesize(); mimes_changed = calloc(1, size); - if(mimes_changed == NULL) { + if (mimes_changed == NULL) { _E("(mimes_changed == NULL) return\n"); free(mimes_origin); return AIL_ERROR_OUT_OF_MEMORY; @@ -392,7 +372,7 @@ static ail_error_e _read_mimetype(void *data, char *tag, char *value, uid_t uid) char *tmp; size *= 2; tmp = realloc(mimes_changed, size); - if(!tmp) { + if (!tmp) { free(mimes_changed); return AIL_ERROR_OUT_OF_MEMORY; } @@ -403,9 +383,8 @@ static ail_error_e _read_mimetype(void *data, char *tag, char *value, uid_t uid) total_len += token_len; token_unalias = strtok_r(NULL, ";", &save_ptr); - if (token_unalias) { + if (token_unalias) strncat(mimes_changed, ";", size-strlen(mimes_changed)-1); - } } SAFE_FREE(info->mimetype); @@ -414,8 +393,6 @@ static ail_error_e _read_mimetype(void *data, char *tag, char *value, uid_t uid) return AIL_ERROR_OK; } - - static ail_error_e _read_nodisplay(void *data, char *tag, char *value, uid_t uid) { desktop_info_s* info = data; @@ -759,28 +736,6 @@ static struct entry_parser entry_parsers[] = { }, }; - - -/* Utility functions */ -static int _count_all(uid_t uid) -{ - ail_error_e ret; - int count; - - if (uid != GLOBAL_USER) - ret = ail_filter_count_usr_appinfo(NULL, &count, uid); - else - ret = ail_filter_count_appinfo(NULL, &count); - if(ret != AIL_ERROR_OK) { - _E("cannot count appinfo"); - count = -1; - } - - retv_if(ret != AIL_ERROR_OK, -1); - - return count; -} - char *_pkgname_to_desktop(const char *package, uid_t uid) { char *desktop; @@ -789,33 +744,43 @@ char *_pkgname_to_desktop(const char *package, uid_t uid) retv_if(!package, NULL); - desktop_path = ail_get_desktop_path(uid); + desktop_path = ail_get_desktop_path(uid); + if (desktop_path == NULL) { + _E("Failed to get desktop path"); + return NULL; + } size = strlen(desktop_path) + strlen(package) + 10; desktop = malloc(size); - retv_if(!desktop, NULL); + if (desktop == NULL) { + _E("out of memory"); + free(desktop_path); + return NULL; + } - snprintf(desktop, size, "%s/%s.desktop", desktop_path, package); + snprintf(desktop, size, "%s/%s.desktop", desktop_path, package); + _D("uid: %d / desktop: [%s]\n", uid, desktop); - _D("uid: %d / desktop: [%s]\n", uid, desktop); + free(desktop_path); return desktop; } static inline int _bind_local_info(desktop_info_s* info, sqlite3_stmt * stmt) { - int ret = 0; unsigned long i = 0; struct name_item *item; GSList* localname; + retv_if(!info, AIL_ERROR_INVALID_PARAMETER); retv_if(!info->localname, AIL_ERROR_INVALID_PARAMETER); retv_if(!stmt, AIL_ERROR_INVALID_PARAMETER); + localname = info->localname; while (localname) { item = (struct name_item *) localname->data; if (item && item->locale && item->name) { - // Bind values for a triplet : package, locale, name + /* Bind values for a triplet : package, locale, name */ retv_if(db_bind_text(stmt, i+1, info->package) != AIL_ERROR_OK, AIL_ERROR_DB_FAILED); retv_if(db_bind_text(stmt, i+2, item->locale) != AIL_ERROR_OK, AIL_ERROR_DB_FAILED); retv_if(db_bind_text(stmt, i+3, item->name) != AIL_ERROR_OK, AIL_ERROR_DB_FAILED); @@ -823,29 +788,28 @@ static inline int _bind_local_info(desktop_info_s* info, sqlite3_stmt * stmt) } localname = g_slist_next(localname); } + return AIL_ERROR_OK; } - static inline int _len_local_info(desktop_info_s* info) { int len = 0; struct name_item *item; GSList* localname; retv_if(!info, AIL_ERROR_INVALID_PARAMETER); - if(info->localname) { + if (info->localname) { localname = info->localname; while (localname) { item = (struct name_item *) localname->data; if (item && item->locale && item->name) - len ++; + len++; localname = g_slist_next(localname); } } return len; } - static inline int _insert_local_info(desktop_info_s* info, uid_t uid) { int len_query = SQL_INSERT_LOCALNAME_STR_LEN; @@ -854,46 +818,52 @@ static inline int _insert_local_info(desktop_info_s* info, uid_t uid) int ret = AIL_ERROR_OK; sqlite3_stmt *stmt = NULL; int i = 0; + retv_if(!info, AIL_ERROR_INVALID_PARAMETER); retv_if(!info->localname, AIL_ERROR_INVALID_PARAMETER); nb_locale_args = _len_local_info(info); - retv_if(!nb_locale_args, AIL_ERROR_INVALID_PARAMETER); - len_query += SQL_LOCALNAME_TRIPLET_STR_LEN*nb_locale_args +1; + len_query += SQL_LOCALNAME_TRIPLET_STR_LEN*nb_locale_args + 1; - query = (char *) malloc(len_query); + query = (char *)malloc(len_query); retv_if(!query, AIL_ERROR_OUT_OF_MEMORY); + stpncpy(query, SQL_INSERT_LOCALNAME_INIT_STR, len_query); - for (i = 0; i < nb_locale_args - 1; i++) - strcat(query, SQL_LOCALNAME_TRIPLET_STR); + for (i = 0; i < nb_locale_args - 1; i++) + strncat(query, SQL_LOCALNAME_TRIPLET_STR, len_query - strlen(query) - 1); do { - if(uid != GLOBAL_USER) + if (uid != GLOBAL_USER) ret = db_prepare_rw(query, &stmt); - else + else ret = db_prepare_globalrw(query, &stmt); - if (ret < 0) break; + + if (ret < 0) + break; ret = _bind_local_info(info, stmt); if (ret < 0) { - _E("Can't bind locale information to this query - %s. ",query); + _E("Can't bind locale information to this query - %s. ", query); db_finalize(stmt); break; } + ret = db_step(stmt); if (ret != AIL_ERROR_NO_DATA) { /* Insert Request doesn't return any data. * db_step should returns AIL_ERROR_NO_DATA in this case. */ - _E("Can't execute this query - %s. ",query); + _E("Can't execute this query - %s. ", query); db_finalize(stmt); break; } + ret = db_finalize(stmt); - } while(0); + } while (0); free(query); + return ret; } @@ -926,10 +896,9 @@ static inline int _strlen_desktop_info(desktop_info_s* info) return len; } - int __is_ail_initdb(void) { - if( getenv("AIL_INITDB") || getenv("INITDB") ) + if (getenv("AIL_INITDB") || getenv("INITDB")) return 1; else return 0; @@ -940,9 +909,9 @@ static ail_error_e _init_desktop_info(desktop_info_s *info, const char *package, { static int is_initdb = -1; - _D("package - [%s].", package); + _D("package - [%s].", package); - if(is_initdb == -1) + if (is_initdb == -1) is_initdb = __is_ail_initdb(); retv_if(!info, AIL_ERROR_INVALID_PARAMETER); @@ -955,7 +924,7 @@ static ail_error_e _init_desktop_info(desktop_info_s *info, const char *package, info->x_slp_removable = 1; info->x_slp_submode = 0; - if(is_initdb) + if (is_initdb) info->x_slp_installedtime = 0; else info->x_slp_installedtime = time(NULL); @@ -969,6 +938,7 @@ static ail_error_e _init_desktop_info(desktop_info_s *info, const char *package, info->x_slp_packageid = strdup(package); retv_if(!info->x_slp_packageid, AIL_ERROR_OUT_OF_MEMORY); + info->x_slp_appid = strdup(package); retv_if(!info->x_slp_appid, AIL_ERROR_OUT_OF_MEMORY); @@ -977,14 +947,12 @@ static ail_error_e _init_desktop_info(desktop_info_s *info, const char *package, info->desktop = _pkgname_to_desktop(package, uid); retv_if(!info->desktop, AIL_ERROR_FAIL); - _D("desktop - [%s].", info->desktop); + _D("desktop - [%s].", info->desktop); return AIL_ERROR_OK; } - - -static ail_error_e _read_desktop_info(desktop_info_s* info,uid_t uid) +static ail_error_e _read_desktop_info(desktop_info_s *info, uid_t uid) { char *line = NULL; FILE *fp; @@ -1001,9 +969,12 @@ static ail_error_e _read_desktop_info(desktop_info_s* info,uid_t uid) char *tmp, *field, *field_name, *tag, *value; tmp = _ltrim(line); - if(tmp == NULL) continue; - if (*tmp == '#') continue; - if (_rtrim(tmp) <= 0) continue; + if (tmp == NULL) + continue; + if (*tmp == '#') + continue; + if (_rtrim(tmp) <= 0) + continue; len = strlen(line) + 1; field = calloc(1, len); @@ -1011,9 +982,8 @@ static ail_error_e _read_desktop_info(desktop_info_s* info,uid_t uid) tag = calloc(1, len); value = calloc(1, len); - if (!field || !field_name || !tag || !value) { + if (!field || !field_name || !tag || !value) goto NEXT; - } sscanf(tmp, "%[^=]=%[^\n]", field, value); _rtrim(field); @@ -1021,15 +991,13 @@ static ail_error_e _read_desktop_info(desktop_info_s* info,uid_t uid) sscanf(field, "%[^[][%[^]]]", field_name, tag); - if (!field_name || !strlen(field_name)){ + if (!field_name || !strlen(field_name)) goto NEXT; - } - for (idx = 0; entry_parsers[idx].field; idx ++) { + for (idx = 0; entry_parsers[idx].field; idx++) { if (!g_ascii_strcasecmp(entry_parsers[idx].field, field_name) && entry_parsers[idx].value_cb) { - if (entry_parsers[idx].value_cb(info, tag, tmp,uid) != AIL_ERROR_OK) { + if (entry_parsers[idx].value_cb(info, tag, tmp, uid) != AIL_ERROR_OK) _E("field - [%s] is wrong.", field_name); - } break; } } @@ -1124,20 +1092,29 @@ static ail_error_e _load_desktop_info(desktop_info_s* info, uid_t uid) char query[AIL_SQL_QUERY_MAX_LEN]; sqlite3_stmt *stmt = NULL; char w[AIL_SQL_QUERY_MAX_LEN]; + const char *filter; retv_if(!info, AIL_ERROR_INVALID_PARAMETER); - snprintf(w, sizeof(w), sql_get_filter(E_AIL_PROP_X_SLP_APPID_STR), info->package); + filter = sql_get_filter(E_AIL_PROP_X_SLP_APPID_STR); + if (filter == NULL) + return AIL_ERROR_FAIL; - snprintf(query, sizeof(query), "SELECT %s FROM %s WHERE %s",SQL_FLD_APP_INFO, SQL_TBL_APP_INFO, w); + snprintf(w, sizeof(w), filter, info->package); + snprintf(query, sizeof(query), "SELECT %s FROM %s WHERE %s", SQL_FLD_APP_INFO, SQL_TBL_APP_INFO, w); do { ret = db_open(DB_OPEN_RO, uid); - if (ret < 0) break; -//is_admin - ret = db_prepare(query, &stmt); - //ret = db_prepare_globalro(query, &stmt); - if (ret < 0) break; + if (ret < 0) + break; + + if (uid != GLOBAL_USER) + ret = db_prepare(query, &stmt); + else + ret = db_prepare_globalro(query, &stmt); + + if (ret < 0) + break; ret = db_step(stmt); if (ret < 0) { @@ -1152,10 +1129,11 @@ static ail_error_e _load_desktop_info(desktop_info_s* info, uid_t uid) } ret = db_finalize(stmt); - if (ret < 0) break; + if (ret < 0) + break; return AIL_ERROR_OK; - } while(0); + } while (0); return ret; } @@ -1165,7 +1143,6 @@ static ail_error_e _modify_desktop_info_bool(desktop_info_s* info, bool value) { ail_prop_bool_e prop; - int val; retv_if(!info, AIL_ERROR_INVALID_PARAMETER); retv_if(!property, AIL_ERROR_INVALID_PARAMETER); @@ -1176,11 +1153,11 @@ static ail_error_e _modify_desktop_info_bool(desktop_info_s* info, return AIL_ERROR_INVALID_PARAMETER; switch (prop) { - case E_AIL_PROP_X_SLP_ENABLED_BOOL: - info->x_slp_enabled = (int)value; - break; - default: - return AIL_ERROR_FAIL; + case E_AIL_PROP_X_SLP_ENABLED_BOOL: + info->x_slp_enabled = (int)value; + break; + default: + return AIL_ERROR_FAIL; } return AIL_ERROR_OK; @@ -1191,8 +1168,7 @@ static ail_error_e _modify_desktop_info_str(desktop_info_s* info, const char *property, const char *value) { - ail_prop_bool_e prop; - int val; + int prop; retv_if(!info, AIL_ERROR_INVALID_PARAMETER); retv_if(!property, AIL_ERROR_INVALID_PARAMETER); @@ -1203,21 +1179,21 @@ static ail_error_e _modify_desktop_info_str(desktop_info_s* info, return AIL_ERROR_INVALID_PARAMETER; switch (prop) { - case E_AIL_PROP_NAME_STR: - SAFE_FREE_AND_STRDUP(value, info->name); - retv_if (!info->name, AIL_ERROR_OUT_OF_MEMORY); - break; - case E_AIL_PROP_X_SLP_SVC_STR: - SAFE_FREE_AND_STRDUP(value, info->x_slp_svc); - retv_if (!info->x_slp_svc, AIL_ERROR_OUT_OF_MEMORY); - break; - case E_AIL_PROP_X_SLP_INSTALLEDSTORAGE_STR: - SAFE_FREE_AND_STRDUP(value, info->x_slp_installedstorage); - retv_if (!info->x_slp_installedstorage, AIL_ERROR_OUT_OF_MEMORY); - break; - default: - _E("prop[%d] is not defined\n", prop); - return AIL_ERROR_FAIL; + case E_AIL_PROP_NAME_STR: + SAFE_FREE_AND_STRDUP(value, info->name); + retv_if(!info->name, AIL_ERROR_OUT_OF_MEMORY); + break; + case E_AIL_PROP_X_SLP_SVC_STR: + SAFE_FREE_AND_STRDUP(value, info->x_slp_svc); + retv_if(!info->x_slp_svc, AIL_ERROR_OUT_OF_MEMORY); + break; + case E_AIL_PROP_X_SLP_INSTALLEDSTORAGE_STR: + SAFE_FREE_AND_STRDUP(value, info->x_slp_installedstorage); + retv_if(!info->x_slp_installedstorage, AIL_ERROR_OUT_OF_MEMORY); + break; + default: + _E("prop[%d] is not defined\n", prop); + return AIL_ERROR_FAIL; } return AIL_ERROR_OK; @@ -1234,12 +1210,12 @@ static inline void _insert_localname(gpointer data, gpointer user_data, uid_t ui sqlite3_snprintf(sizeof(query), query, "insert into localname (package, locale, name, x_slp_pkgid) " "values ('%q', '%q', '%q', '%q');", info->package, item->locale, item->name, info->x_slp_pkgid); - if(uid != GLOBAL_USER) { + if (uid != GLOBAL_USER) { if (db_exec_usr_rw(query) < 0) - _E("Failed to insert local name of package[%s]",info->package); + _E("Failed to insert local name of package[%s]", info->package); } else { if (db_exec_glo_rw(query) < 0) - _E("Failed to insert local name of package[%s]",info->package); + _E("Failed to insert local name of package[%s]", info->package); } } @@ -1324,7 +1300,7 @@ static ail_error_e _insert_desktop_info(desktop_info_s *info, uid_t uid) ); ret = db_open(DB_OPEN_RW, uid); - if(ret != AIL_ERROR_OK) { + if (ret != AIL_ERROR_OK) { _E("(tmp == NULL) return\n"); free(query); return AIL_ERROR_DB_FAILED; @@ -1333,36 +1309,33 @@ static ail_error_e _insert_desktop_info(desktop_info_s *info, uid_t uid) ret = db_exec_usr_rw(query); else ret = db_exec_glo_rw(query); - + + _D("Add (%s).", query); free(query); + retv_if(ret != AIL_ERROR_OK, AIL_ERROR_DB_FAILED); if (info->localname) _insert_local_info(info, uid); - _D("Add (%s).", query); - return AIL_ERROR_OK; } - - static ail_error_e _update_desktop_info(desktop_info_s *info, uid_t uid) { char *query; int len; - retv_if (NULL == info, AIL_ERROR_INVALID_PARAMETER); + retv_if(NULL == info, AIL_ERROR_INVALID_PARAMETER); - if (db_open(DB_OPEN_RW, uid) < 0) { + if (db_open(DB_OPEN_RW, uid) < 0) return AIL_ERROR_DB_FAILED; - } len = _strlen_desktop_info(info) + (0x01 << 10); query = calloc(1, len); retv_if(!query, AIL_ERROR_OUT_OF_MEMORY); - sqlite3_snprintf ( len, query, "update app_info set " + sqlite3_snprintf(len, query, "update app_info set " "exec='%q', " "name='%q', " "type='%q', " @@ -1424,26 +1397,26 @@ static ail_error_e _update_desktop_info(desktop_info_s *info, uid_t uid) info->desktop, info->package); - if(uid != GLOBAL_USER) { + if (uid != GLOBAL_USER) { if (db_exec_usr_rw(query) < 0) { - free (query); + free(query); return AIL_ERROR_DB_FAILED; } } else { if (db_exec_glo_rw(query) < 0) { - free (query); + free(query); return AIL_ERROR_DB_FAILED; } } snprintf(query, len, "delete from localname where package = '%s'", info->package); if (uid != GLOBAL_USER) { if (db_exec_usr_rw(query) < 0) { - free (query); + free(query); return AIL_ERROR_DB_FAILED; } } else { if (db_exec_glo_rw(query) < 0) { - free (query); + free(query); return AIL_ERROR_DB_FAILED; } } @@ -1466,9 +1439,8 @@ static ail_error_e _remove_package(const char* package, uid_t uid) retv_if(!package, AIL_ERROR_INVALID_PARAMETER); - if (db_open(DB_OPEN_RW, uid) < 0) { + if (db_open(DB_OPEN_RW, uid) < 0) return AIL_ERROR_DB_FAILED; - } size = strlen(package) + (0x01 << 10); query = calloc(1, size); @@ -1476,7 +1448,7 @@ static ail_error_e _remove_package(const char* package, uid_t uid) snprintf(query, size, "delete from app_info where package = '%s'", package); - if(uid != GLOBAL_USER) { + if (uid != GLOBAL_USER) { if (db_exec_usr_rw(query) < 0) { free(query); return AIL_ERROR_DB_FAILED; @@ -1488,9 +1460,9 @@ static ail_error_e _remove_package(const char* package, uid_t uid) } } snprintf(query, size, "delete from localname where package = '%s'", package); - _D("query=%s",query); - - if(uid != GLOBAL_USER) { + _D("query=%s", query); + + if (uid != GLOBAL_USER) { if (db_exec_usr_rw(query) < 0) { free(query); return AIL_ERROR_DB_FAILED; @@ -1514,9 +1486,8 @@ static ail_error_e _clean_pkgid_data(const char* pkgid, uid_t uid) retv_if(!pkgid, AIL_ERROR_INVALID_PARAMETER); - if (db_open(DB_OPEN_RW, uid) ){ + if (db_open(DB_OPEN_RW, uid)) return AIL_ERROR_DB_FAILED; - } size = strlen(pkgid) + (0x01 << 10); query = calloc(1, size); @@ -1524,7 +1495,7 @@ static ail_error_e _clean_pkgid_data(const char* pkgid, uid_t uid) snprintf(query, size, "delete from app_info where x_slp_pkgid = '%s'", pkgid); - if(uid != GLOBAL_USER) { + if (uid != GLOBAL_USER) { if (db_exec_usr_rw(query) < 0) { free(query); return AIL_ERROR_DB_FAILED; @@ -1536,9 +1507,9 @@ static ail_error_e _clean_pkgid_data(const char* pkgid, uid_t uid) } } snprintf(query, size, "delete from localname where x_slp_pkgid = '%s'", pkgid); - _D("query=%s",query); + _D("query=%s", query); - if(uid != GLOBAL_USER) { + if (uid != GLOBAL_USER) { if (db_exec_usr_rw(query) < 0) { free(query); return AIL_ERROR_DB_FAILED; @@ -1547,7 +1518,7 @@ static ail_error_e _clean_pkgid_data(const char* pkgid, uid_t uid) if (db_exec_glo_rw(query) < 0) { free(query); return AIL_ERROR_DB_FAILED; - } + } } _D("Clean pkgid data (%s).", pkgid); free(query); @@ -1563,17 +1534,17 @@ static ail_error_e _send_db_done_noti(noti_type type, const char *package) retv_if(!package, AIL_ERROR_INVALID_PARAMETER); switch (type) { - case NOTI_ADD: - type_string = "create"; - break; - case NOTI_UPDATE: - type_string = "update"; - break; - case NOTI_REMOVE: - type_string = "delete"; - break; - default: - return AIL_ERROR_FAIL; + case NOTI_ADD: + type_string = "create"; + break; + case NOTI_UPDATE: + type_string = "update"; + break; + case NOTI_REMOVE: + type_string = "delete"; + break; + default: + return AIL_ERROR_FAIL; } size = snprintf(NULL, 0, "%s:%s:%u", type_string, package, getuid()); @@ -1581,8 +1552,6 @@ static ail_error_e _send_db_done_noti(noti_type type, const char *package) retv_if(!noti_string, AIL_ERROR_OUT_OF_MEMORY); snprintf(noti_string, size + 1, "%s:%s:%u", type_string, package, getuid()); - ail_vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string); - ail_vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed _D("Noti : %s", noti_string); free(noti_string); @@ -1590,11 +1559,10 @@ static ail_error_e _send_db_done_noti(noti_type type, const char *package) return AIL_ERROR_OK; } - -static void inline _name_item_free_func(gpointer data) +static inline void _name_item_free_func(gpointer data) { struct name_item *item = (struct name_item *)data; - if (item){ + if (item) { SAFE_FREE(item->locale); item->locale = NULL; SAFE_FREE(item->name); @@ -1633,16 +1601,6 @@ static void _fini_desktop_info(desktop_info_s *info) return; } -static int __is_authorized() -{ - uid_t uid = getuid(); - if ((uid_t) GLOBAL_USER == uid ) - return 1; - else - return 0; -} - - /* Public functions */ EXPORT_API ail_error_e ail_usr_desktop_add(const char *appid, uid_t uid) { @@ -1652,25 +1610,28 @@ EXPORT_API ail_error_e ail_usr_desktop_add(const char *appid, uid_t uid) retv_if(!appid, AIL_ERROR_INVALID_PARAMETER); ret = _init_desktop_info(&info, appid, uid); - retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL); + if (ret != AIL_ERROR_OK) + goto end; - ret = _read_desktop_info(&info,uid); - retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL); + ret = _read_desktop_info(&info, uid); + if (ret != AIL_ERROR_OK) + goto end; ret = _insert_desktop_info(&info, uid); - retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL); + if (ret != AIL_ERROR_OK) + goto end; ret = _send_db_done_noti(NOTI_ADD, appid); - retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL); +end: _fini_desktop_info(&info); - return AIL_ERROR_OK; + return ret; } EXPORT_API ail_error_e ail_desktop_add(const char *appid) { - return ail_usr_desktop_add(appid,GLOBAL_USER); + return ail_usr_desktop_add(appid, GLOBAL_USER); } EXPORT_API ail_error_e ail_usr_desktop_update(const char *appid, uid_t uid) @@ -1681,28 +1642,30 @@ EXPORT_API ail_error_e ail_usr_desktop_update(const char *appid, uid_t uid) retv_if(!appid, AIL_ERROR_INVALID_PARAMETER); ret = _init_desktop_info(&info, appid, uid); - retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL); + if (ret != AIL_ERROR_OK) + goto end; - ret = _read_desktop_info(&info,uid); - retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL); + ret = _read_desktop_info(&info, uid); + if (ret != AIL_ERROR_OK) + goto end; ret = _update_desktop_info(&info, uid); - retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL); + if (ret != AIL_ERROR_OK) + goto end; ret = _send_db_done_noti(NOTI_UPDATE, appid); - retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL); +end: _fini_desktop_info(&info); - return AIL_ERROR_OK; + return ret; } EXPORT_API ail_error_e ail_desktop_update(const char *appid) { - return ail_usr_desktop_update(appid,GLOBAL_USER); + return ail_usr_desktop_update(appid, GLOBAL_USER); } - EXPORT_API ail_error_e ail_usr_desktop_remove(const char *appid, uid_t uid) { ail_error_e ret; @@ -1730,7 +1693,7 @@ EXPORT_API ail_error_e ail_usr_desktop_clean(const char *pkgid, uid_t uid) retv_if(!pkgid, AIL_ERROR_INVALID_PARAMETER); - _D("ail_desktop_clean=%s",pkgid); + _D("ail_desktop_clean=%s", pkgid); ret = _clean_pkgid_data(pkgid, uid); retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL); @@ -1751,17 +1714,19 @@ EXPORT_API ail_error_e ail_usr_desktop_fota(const char *appid, uid_t uid) retv_if(!appid, AIL_ERROR_INVALID_PARAMETER); ret = _init_desktop_info(&info, appid, uid); - retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL); + if (ret != AIL_ERROR_OK) + goto end; - ret = _read_desktop_info(&info,uid); - retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL); + ret = _read_desktop_info(&info, uid); + if (ret != AIL_ERROR_OK) + goto end; ret = _insert_desktop_info(&info, uid); - retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL); +end: _fini_desktop_info(&info); - return AIL_ERROR_OK; + return ret; } EXPORT_API ail_error_e ail_desktop_fota(const char *appid) @@ -1771,9 +1736,7 @@ EXPORT_API ail_error_e ail_desktop_fota(const char *appid) EXPORT_API ail_error_e ail_desktop_appinfo_modify_usr_bool(const char *appid, - const char *property, - bool value, - bool broadcast, uid_t uid) + const char *property, bool value, bool broadcast, uid_t uid) { desktop_info_s info = {0,}; ail_error_e ret; @@ -1781,44 +1744,43 @@ EXPORT_API ail_error_e ail_desktop_appinfo_modify_usr_bool(const char *appid, retv_if(!appid, AIL_ERROR_INVALID_PARAMETER); retv_if(strcmp(property, AIL_PROP_X_SLP_ENABLED_BOOL), - AIL_ERROR_INVALID_PARAMETER); + AIL_ERROR_INVALID_PARAMETER); ret = _init_desktop_info(&info, appid, uid); - retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL); + if (ret != AIL_ERROR_OK) + goto end; ret = _load_desktop_info(&info, uid); - retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL); + if (ret != AIL_ERROR_OK) + goto end; ret = _modify_desktop_info_bool(&info, property, value); - retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL); + if (ret != AIL_ERROR_OK) + goto end; ret = _update_desktop_info(&info, uid); - retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL); + if (ret != AIL_ERROR_OK) + goto end; - if (broadcast) { + if (broadcast) ret = _send_db_done_noti(NOTI_UPDATE, appid); - retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL); - } +end: _fini_desktop_info(&info); - return AIL_ERROR_OK; + return ret; } EXPORT_API ail_error_e ail_desktop_appinfo_modify_bool(const char *appid, - const char *property, - bool value, - bool broadcast) + const char *property, bool value, bool broadcast) { - return ail_desktop_appinfo_modify_usr_bool(appid, property, value, broadcast, - GLOBAL_USER); + return ail_desktop_appinfo_modify_usr_bool(appid, property, value, + broadcast, GLOBAL_USER); } -EXPORT_API ail_error_e ail_desktop_appinfo_modify_usr_str(const char *appid, uid_t uid, - const char *property, - const char *value, - bool broadcast) +EXPORT_API ail_error_e ail_desktop_appinfo_modify_usr_str(const char *appid, + uid_t uid, const char *property, const char *value, bool broadcast) { desktop_info_s info = {0,}; ail_error_e ret; @@ -1826,36 +1788,36 @@ EXPORT_API ail_error_e ail_desktop_appinfo_modify_usr_str(const char *appid, uid retv_if(!appid, AIL_ERROR_INVALID_PARAMETER); ret = _init_desktop_info(&info, appid, uid); - retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL); + if (ret != AIL_ERROR_OK) + goto end; ret = _load_desktop_info(&info, uid); - retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL); + if (ret != AIL_ERROR_OK) + goto end; _D("info.name [%s], value [%s]", info.name, value); ret = _modify_desktop_info_str(&info, property, value); - retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL); + if (ret != AIL_ERROR_OK) + goto end; + _D("info.name [%s], value [%s]", info.name, value); ret = _update_desktop_info(&info, uid); - retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL); + if (ret != AIL_ERROR_OK) + goto end; - if (broadcast) { + if (broadcast) ret = _send_db_done_noti(NOTI_UPDATE, appid); - retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL); - } +end: _fini_desktop_info(&info); - return AIL_ERROR_OK; + return ret; } EXPORT_API ail_error_e ail_desktop_appinfo_modify_str(const char *appid, - const char *property, - const char *value, - bool broadcast) + const char *property, const char *value, bool broadcast) { - return ail_desktop_appinfo_modify_usr_str(appid, GLOBAL_USER, property, value, - broadcast); + return ail_desktop_appinfo_modify_usr_str(appid, GLOBAL_USER, property, + value, broadcast); } - -// End of File