X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fail_package.c;h=7b67dec8a4c8a91843ede5501d575eb91ae2ea85;hb=refs%2Ftags%2Fsubmit%2Ftizen_common%2F20151229.144031;hp=82af08d630df9547c816b4393f9e5f58e51a5812;hpb=130c893b2773b18220cfc48794d0e86c1d822a90;p=platform%2Fcore%2Fappfw%2Fail.git diff --git a/src/ail_package.c b/src/ail_package.c index 82af08d..7b67dec 100755 --- a/src/ail_package.c +++ b/src/ail_package.c @@ -23,20 +23,25 @@ #include #include +#include +#include +#include #include +#include #include + #include "ail.h" #include "ail_private.h" #include "ail_convert.h" #include "ail_db.h" #include "ail_sql.h" #include "ail_package.h" -#include -#include #define LANGUAGE_LENGTH 2 #define DEFAULT_LOCALE "No Locale" #define MAX_QUERY_LEN 4096 +#define PKG_SD_PATH tzplatform_mkpath(TZ_SYS_STORAGE, "sdcard/app2sd/") +#define QUERY_GET_LOCALNAME "select name from localname where package='%s' and locale='%s'" struct ail_appinfo { char **values; @@ -47,7 +52,6 @@ typedef struct _pkgmgr_locale_x { char *locale; } pkgmgr_locale_x; - /* get the first locale value*/ static int __fallback_locale_cb(void *data, int ncols, char **coltxt, char **colname) { @@ -61,9 +65,9 @@ static int __fallback_locale_cb(void *data, int ncols, char **coltxt, char **col return 0; } -static int __check_validation_of_qurey_cb(void *data, int ncols, char **coltxt, char **colname) +static int __check_validation_of_query_cb(void *data, int ncols, char **coltxt, char **colname) { - int *p = (int*)data; + int *p = (int *)data; *p = atoi(coltxt[0]); return 0; } @@ -74,7 +78,7 @@ static int __check_app_locale_from_app_localized_info_by_exact(const char *appid char query[MAX_QUERY_LEN]; snprintf(query, MAX_QUERY_LEN, "select exists(select locale from localname where package='%s' and locale='%s')", appid, locale); - db_exec_sqlite_query(query, __check_validation_of_qurey_cb, (void *)&result_query); + db_exec_sqlite_query(query, __check_validation_of_query_cb, (void *)&result_query); return result_query; } @@ -82,20 +86,20 @@ static int __check_app_locale_from_app_localized_info_by_exact(const char *appid static int __check_app_locale_from_app_localized_info_by_fallback(const char *appid, const char *locale) { int result_query = -1; - char wildcard[2] = {'%','\0'}; + char wildcard[2] = {'%', '\0'}; char query[MAX_QUERY_LEN]; char lang[3] = {'\0'}; strncpy(lang, locale, LANGUAGE_LENGTH); snprintf(query, MAX_QUERY_LEN, "select exists(select locale from localname where package='%s' and locale like '%s%s')", appid, lang, wildcard); - db_exec_sqlite_query(query, __check_validation_of_qurey_cb, (void *)&result_query); + db_exec_sqlite_query(query, __check_validation_of_query_cb, (void *)&result_query); return result_query; } static char* __get_app_locale_from_app_localized_info_by_fallback(const char *appid, const char *locale) { - char wildcard[2] = {'%','\0'}; + char wildcard[2] = {'%', '\0'}; char lang[3] = {'\0'}; char query[MAX_QUERY_LEN]; char *locale_new = NULL; @@ -106,7 +110,7 @@ static char* __get_app_locale_from_app_localized_info_by_fallback(const char *ap _E("Out of Memory!!!\n"); return NULL; } - memset(info, NULL, sizeof(*info)); + memset(info, 0x00, sizeof(*info)); strncpy(lang, locale, 2); snprintf(query, MAX_QUERY_LEN, "select locale from localname where package='%s' and locale like '%s%s'", appid, lang, wildcard); @@ -117,7 +121,7 @@ static char* __get_app_locale_from_app_localized_info_by_fallback(const char *ap return locale_new; } -static char* __convert_syslocale_to_manifest_locale(char *syslocale) +static char* __convert_syslocale_to_manifest_locale(const char *syslocale) { char *locale = malloc(6); if (!locale) { @@ -125,7 +129,7 @@ static char* __convert_syslocale_to_manifest_locale(char *syslocale) return NULL; } - sprintf(locale, "%c%c_%c%c", syslocale[0], syslocale[1], toupper(syslocale[3]), toupper(syslocale[4])); + snprintf(locale, 6, "%c%c_%c%c", syslocale[0], syslocale[1], toupper(syslocale[3]), toupper(syslocale[4])); return locale; } @@ -151,7 +155,7 @@ static char* __get_app_locale_by_fallback(const char *appid, const char *sysloca /* fallback matching */ check_result = __check_app_locale_from_app_localized_info_by_fallback(appid, locale); - if(check_result == 1) { + if (check_result == 1) { locale_new = __get_app_locale_from_app_localized_info_by_fallback(appid, locale); _D("%s found (%s) language-locale in DB by fallback!\n", appid, locale_new); free(locale); @@ -166,30 +170,7 @@ static char* __get_app_locale_by_fallback(const char *appid, const char *sysloca return strdup(DEFAULT_LOCALE); } -void appinfo_set_stmt(ail_appinfo_h ai, sqlite3_stmt *stmt) -{ - ai->stmt = stmt; -} - -ail_appinfo_h appinfo_create(void) -{ - ail_appinfo_h ai; - ai = calloc(1, sizeof(struct ail_appinfo)); - retv_if (NULL == ai, NULL); - ai->stmt = NULL; - - return ai; -} - -void appinfo_destroy(ail_appinfo_h ai) -{ - if (ai) - free(ai); -} - - - -static ail_error_e _retrieve_all_column(ail_appinfo_h ai) +static ail_error_e __retrieve_all_column(ail_appinfo_h ai) { int i, j; ail_error_e err; @@ -203,7 +184,7 @@ static ail_error_e _retrieve_all_column(ail_appinfo_h ai) for (i = 0; i < NUM_OF_PROP; i++) { err = db_column_str(ai->stmt, i, &col); - if (AIL_ERROR_OK != err) + if (AIL_ERROR_OK != err) break; if (!col) { @@ -229,6 +210,65 @@ static ail_error_e _retrieve_all_column(ail_appinfo_h ai) return AIL_ERROR_OK; } +int _appinfo_check_installed_storage(ail_appinfo_h ai) +{ + int index = 0; + ail_prop_str_e prop = -1; + char *pkgid = NULL; + char *installed_storage = NULL; + char buf[AIL_SQL_QUERY_MAX_LEN] = {'\0'}; + + retv_if(!ai, AIL_ERROR_OK); + + if (ai->stmt) { + prop = _ail_convert_to_prop_str(AIL_PROP_X_SLP_INSTALLEDSTORAGE_STR); + index = sql_get_app_info_idx(prop); + if (db_column_str(ai->stmt, index, &installed_storage) < 0) + return AIL_ERROR_OK; + + prop = _ail_convert_to_prop_str(AIL_PROP_X_SLP_PKGID_STR); + index = sql_get_app_info_idx(prop); + if (db_column_str(ai->stmt, index, &pkgid) < 0) + return AIL_ERROR_OK; + } else { + prop = _ail_convert_to_prop_str(AIL_PROP_X_SLP_INSTALLEDSTORAGE_STR); + installed_storage = ai->values[prop]; + + prop = _ail_convert_to_prop_str(AIL_PROP_X_SLP_PKGID_STR); + pkgid = ai->values[prop]; + } + + if (strcmp(installed_storage, "installed_external") == 0) { + snprintf(buf, AIL_SQL_QUERY_MAX_LEN - 1, "%s%s", PKG_SD_PATH, pkgid); + if (access(buf, R_OK) != 0) { + _E("can not access [%s]", buf); + return AIL_ERROR_OK; /* tmep, it will be fixed to :: return AIL_ERROR_FAIL; */ + } + } + + return AIL_ERROR_OK; +} + +void appinfo_set_stmt(ail_appinfo_h ai, sqlite3_stmt *stmt) +{ + ai->stmt = stmt; +} + +ail_appinfo_h appinfo_create(void) +{ + ail_appinfo_h ai; + ai = calloc(1, sizeof(struct ail_appinfo)); + retv_if(ai == NULL, NULL); + ai->stmt = NULL; + + return ai; +} + +void appinfo_destroy(ail_appinfo_h ai) +{ + if (ai) + free(ai); +} EXPORT_API ail_error_e ail_package_destroy_appinfo(ail_appinfo_h ai) { @@ -243,23 +283,26 @@ EXPORT_API ail_error_e ail_destroy_appinfo(ail_appinfo_h ai) retv_if(!ai->values, AIL_ERROR_INVALID_PARAMETER); for (i = 0; i < NUM_OF_PROP; i++) { - if (ai->values[i]) { + if (ai->values[i]) free(ai->values[i]); - } } free(ai->values); free(ai); + db_close(); return AIL_ERROR_OK; } - EXPORT_API ail_error_e ail_package_get_appinfo(const char *package, ail_appinfo_h *ai) { return ail_get_appinfo(package, ai); } +EXPORT_API ail_error_e ail_package_get_usr_appinfo(const char *package, uid_t uid, ail_appinfo_h *ai) +{ + return ail_get_usr_appinfo(package, uid, ai); +} EXPORT_API ail_error_e ail_get_appinfo(const char *appid, ail_appinfo_h *ai) { @@ -267,6 +310,7 @@ EXPORT_API ail_error_e ail_get_appinfo(const char *appid, ail_appinfo_h *ai) char query[AIL_SQL_QUERY_MAX_LEN]; sqlite3_stmt *stmt = NULL; char w[AIL_SQL_QUERY_MAX_LEN]; + const char *filter; retv_if(!appid, AIL_ERROR_INVALID_PARAMETER); retv_if(!ai, AIL_ERROR_INVALID_PARAMETER); @@ -274,16 +318,25 @@ EXPORT_API ail_error_e ail_get_appinfo(const char *appid, ail_appinfo_h *ai) *ai = appinfo_create(); retv_if(!*ai, AIL_ERROR_OUT_OF_MEMORY); - snprintf(w, sizeof(w), sql_get_filter(E_AIL_PROP_X_SLP_APPID_STR), appid); + filter = sql_get_filter(E_AIL_PROP_X_SLP_APPID_STR); + if (filter == NULL) { + appinfo_destroy(*ai); + 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, appid); + 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); - if (ret < 0) break; + ret = db_open(DB_OPEN_RO, GLOBAL_USER); + if (ret < 0) + break; - ret = db_prepare(query, &stmt); - if (ret < 0) break; + /* is_admin */ + ret = db_prepare_globalro(query, &stmt); + if (ret < 0) + break; ret = db_step(stmt); if (ret < 0) { @@ -293,24 +346,99 @@ EXPORT_API ail_error_e ail_get_appinfo(const char *appid, ail_appinfo_h *ai) (*ai)->stmt = stmt; - ret = _retrieve_all_column(*ai); + ret = _appinfo_check_installed_storage(*ai); + if (ret < 0) { + db_finalize((*ai)->stmt); + break; + } + + ret = __retrieve_all_column(*ai); if (ret < 0) { db_finalize((*ai)->stmt); break; } ret = db_finalize((*ai)->stmt); - if (ret < 0) break; + if (ret < 0) + break; + (*ai)->stmt = NULL; return AIL_ERROR_OK; - } while(0); + } while (0); appinfo_destroy(*ai); return ret; } +EXPORT_API ail_error_e ail_get_usr_appinfo(const char *appid, uid_t uid, ail_appinfo_h *ai) +{ + ail_error_e ret; + char query[AIL_SQL_QUERY_MAX_LEN]; + sqlite3_stmt *stmt = NULL; + char w[AIL_SQL_QUERY_MAX_LEN]; + const char *filter; + + retv_if(!appid, AIL_ERROR_INVALID_PARAMETER); + retv_if(!ai, AIL_ERROR_INVALID_PARAMETER); + + *ai = appinfo_create(); + retv_if(!*ai, AIL_ERROR_OUT_OF_MEMORY); + + filter = sql_get_filter(E_AIL_PROP_X_SLP_APPID_STR); + if (filter == NULL) { + appinfo_destroy(*ai); + return AIL_ERROR_FAIL; + } + + snprintf(w, sizeof(w), filter, appid); + 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); + if (ret < 0) + break; + + ret = db_step(stmt); + if (ret < 0) { + db_finalize(stmt); + break; + } + + (*ai)->stmt = stmt; + + ret = _appinfo_check_installed_storage(*ai); + if (ret < 0) { + db_finalize((*ai)->stmt); + break; + } + + ret = __retrieve_all_column(*ai); + if (ret < 0) { + db_finalize((*ai)->stmt); + break; + } + + ret = db_finalize((*ai)->stmt); + if (ret < 0) + break; + + (*ai)->stmt = NULL; + + return AIL_ERROR_OK; + } while (0); + + appinfo_destroy(*ai); + + return ret; +} EXPORT_API ail_error_e ail_appinfo_get_bool(const ail_appinfo_h ai, const char *property, bool *value) { @@ -325,7 +453,7 @@ EXPORT_API ail_error_e ail_appinfo_get_bool(const ail_appinfo_h ai, const char * if (prop < E_AIL_PROP_BOOL_MIN || prop > E_AIL_PROP_BOOL_MAX) return AIL_ERROR_INVALID_PARAMETER; - + if (ai->stmt) { int index; index = sql_get_app_info_idx(prop); @@ -333,13 +461,11 @@ EXPORT_API ail_error_e ail_appinfo_get_bool(const ail_appinfo_h ai, const char * return AIL_ERROR_DB_FAILED; } else { val = atoi(ai->values[prop]); - *value = (val == 0? false : true); + *value = (val == 0) ? false : true; } return AIL_ERROR_OK; } - - EXPORT_API ail_error_e ail_appinfo_get_int(const ail_appinfo_h ai, const char *property, int *value) { ail_prop_int_e prop; @@ -354,7 +480,7 @@ EXPORT_API ail_error_e ail_appinfo_get_int(const ail_appinfo_h ai, const char *p return AIL_ERROR_INVALID_PARAMETER; if (ai->stmt) { - int index; + int index; index = sql_get_app_info_idx(prop); if (db_column_int(ai->stmt, index, value) < 0) return AIL_ERROR_DB_FAILED; @@ -364,20 +490,20 @@ EXPORT_API ail_error_e ail_appinfo_get_int(const ail_appinfo_h ai, const char *p return AIL_ERROR_OK; } -#define QUERY_GET_LOCALNAME "select name from localname where package='%s' and locale='%s'" - -char *appinfo_get_localname(const char *package, char *locale) +char *appinfo_get_localname(const char *package, char *locale, uid_t uid) { - db_open(DB_OPEN_RO); + db_open(DB_OPEN_RO, uid); sqlite3_stmt *stmt; char *str = NULL; char *localname; char query[512]; - + snprintf(query, sizeof(query), QUERY_GET_LOCALNAME, package, locale); - _D("Query = %s",query); - retv_if (db_prepare(query, &stmt) < 0, NULL); + if (uid != GLOBAL_USER) + retv_if(db_prepare(query, &stmt) < 0, NULL); + else + retv_if(db_prepare_globalro(query, &stmt) < 0, NULL); do { if (db_step(stmt) < 0) @@ -392,13 +518,12 @@ char *appinfo_get_localname(const char *package, char *locale) db_finalize(stmt); return localname; - } while(0); + } while (0); db_finalize(stmt); return NULL; } - EXPORT_API ail_error_e ail_appinfo_get_str(const ail_appinfo_h ai, const char *property, char **str) { int index; @@ -424,22 +549,21 @@ EXPORT_API ail_error_e ail_appinfo_get_str(const ail_appinfo_h ai, const char *p if (ai->stmt) { if (db_column_str(ai->stmt, E_AIL_PROP_X_SLP_PACKAGETYPE_STR, &pkg_type) < 0) return AIL_ERROR_DB_FAILED; - if(pkg_type && (strcasecmp(pkg_type, "tpk") ==0)) - { + if (pkg_type && (strcasecmp(pkg_type, "tpk") == 0)) { locale = sql_get_locale(); - retv_if (NULL == locale, AIL_ERROR_FAIL); + retv_if(locale == NULL, AIL_ERROR_FAIL); - if (db_column_str(ai->stmt, E_AIL_PROP_PACKAGE_STR, &pkg) < 0){ + if (db_column_str(ai->stmt, E_AIL_PROP_PACKAGE_STR, &pkg) < 0) { free(locale); return AIL_ERROR_DB_FAILED; } - if (pkg == NULL){ + if (pkg == NULL) { free(locale); return AIL_ERROR_DB_FAILED; } locale_new = __get_app_locale_by_fallback(pkg, locale); - localname = (char *)appinfo_get_localname(pkg,locale_new); + localname = (char *)appinfo_get_localname(pkg, locale_new, GLOBAL_USER); free(locale); free(locale_new); } else { @@ -449,19 +573,18 @@ EXPORT_API ail_error_e ail_appinfo_get_str(const ail_appinfo_h ai, const char *p } else { pkg_type = ai->values[E_AIL_PROP_X_SLP_PACKAGETYPE_STR]; pkg = ai->values[E_AIL_PROP_PACKAGE_STR]; - retv_if (NULL == pkg, AIL_ERROR_FAIL); + retv_if(pkg == NULL, AIL_ERROR_FAIL); locale = sql_get_locale(); - retv_if (NULL == locale, AIL_ERROR_FAIL); + retv_if(locale == NULL, AIL_ERROR_FAIL); - if(pkg_type && (strcasecmp(pkg_type, "tpk") ==0)) - { + if (pkg_type && (strcasecmp(pkg_type, "tpk") == 0)) { locale_new = __get_app_locale_by_fallback(pkg, locale); - localname = (char *)appinfo_get_localname(pkg,locale_new); + localname = (char *)appinfo_get_localname(pkg, locale_new, GLOBAL_USER); free(locale); free(locale_new); } else { - localname = (char *)appinfo_get_localname(pkg,locale); + localname = (char *)appinfo_get_localname(pkg, locale, GLOBAL_USER); free(locale); } } @@ -481,9 +604,9 @@ EXPORT_API ail_error_e ail_appinfo_get_str(const ail_appinfo_h ai, const char *p if (ai->stmt) { index = sql_get_app_info_idx(prop); - if (db_column_str(ai->stmt, index, &value) < 0){ + if (db_column_str(ai->stmt, index, &value) < 0) return AIL_ERROR_DB_FAILED; - } + *str = value; } else *str = ai->values[prop]; @@ -491,5 +614,97 @@ EXPORT_API ail_error_e ail_appinfo_get_str(const ail_appinfo_h ai, const char *p return AIL_ERROR_OK; } +EXPORT_API ail_error_e ail_appinfo_get_usr_str(const ail_appinfo_h ai, const char *property, uid_t uid, char **str) +{ + int index; + char *value; + char *pkg; + char *pkg_type; + char *locale, *localname; + ail_prop_str_e prop; + char *locale_new; + + retv_if(!ai, AIL_ERROR_INVALID_PARAMETER); + retv_if(!property, AIL_ERROR_INVALID_PARAMETER); + retv_if(!str, AIL_ERROR_INVALID_PARAMETER); + + prop = _ail_convert_to_prop_str(property); + + if (prop < E_AIL_PROP_STR_MIN || prop > E_AIL_PROP_STR_MAX) + return AIL_ERROR_INVALID_PARAMETER; + + localname = NULL; + + if (E_AIL_PROP_NAME_STR == prop) { + if (ai->stmt) { + if (db_column_str(ai->stmt, E_AIL_PROP_X_SLP_PACKAGETYPE_STR, &pkg_type) < 0) + return AIL_ERROR_DB_FAILED; + if (pkg_type && (strcasecmp(pkg_type, "tpk") == 0)) { + locale = sql_get_locale(); + retv_if(locale == NULL, AIL_ERROR_FAIL); + + if (db_column_str(ai->stmt, E_AIL_PROP_PACKAGE_STR, &pkg) < 0) { + free(locale); + return AIL_ERROR_DB_FAILED; + } + if (pkg == NULL) { + free(locale); + return AIL_ERROR_DB_FAILED; + } + + locale_new = __get_app_locale_by_fallback(pkg, locale); + localname = (char *)appinfo_get_localname(pkg, locale_new, uid); + free(locale); + free(locale_new); + } else { + if (db_column_str(ai->stmt, SQL_LOCALNAME_IDX, &localname) < 0) + return AIL_ERROR_DB_FAILED; + } + } else { + pkg_type = ai->values[E_AIL_PROP_X_SLP_PACKAGETYPE_STR]; + pkg = ai->values[E_AIL_PROP_PACKAGE_STR]; + retv_if(pkg == NULL, AIL_ERROR_FAIL); + + locale = sql_get_locale(); + retv_if(locale == NULL, AIL_ERROR_FAIL); -// End of file + if (pkg_type && (strcasecmp(pkg_type, "tpk") == 0)) { + locale_new = __get_app_locale_by_fallback(pkg, locale); + localname = (char *)appinfo_get_localname(pkg, locale_new, uid); + free(locale); + free(locale_new); + } else { + localname = (char *)appinfo_get_localname(pkg, locale, uid); + free(locale); + } + } + + if (localname) { + if (!ai->stmt) { + if (ai->values) { + if (ai->values[prop]) + free(ai->values[prop]); + ai->values[prop] = localname; + } + } + *str = localname; + return AIL_ERROR_OK; + } + } + + if (ai->stmt) { + index = sql_get_app_info_idx(prop); + if (db_column_str(ai->stmt, index, &value) < 0) + return AIL_ERROR_DB_FAILED; + + *str = value; + } else + *str = ai->values[prop]; + + return AIL_ERROR_OK; +} + +EXPORT_API ail_error_e ail_close_appinfo_db(void) +{ + return db_close(); +}