#ifndef __PKGMGRINFO_PRIVATE_H__
#define __PKGMGRINFO_PRIVATE_H__
+#include <stdbool.h>
#include <unistd.h>
#include <sys/types.h>
int _check_create_cert_db(sqlite3 *certdb);
int __close_manifest_db(void);
-int __open_manifest_db(uid_t uid);
+int __open_manifest_db(uid_t uid, bool readonly);
int __close_cert_db(void);
-int __open_cert_db(uid_t uid, char* mode);
+int __open_cert_db(uid_t uid, bool readonly);
void _save_column_str(sqlite3_stmt *stmt, int idx, const char **str);
char *_get_system_locale(void);
void __get_filter_condition(gpointer data, char **condition);
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
return PMINFO_R_EINVAL;
}
- if (__open_manifest_db(uid) < 0)
+ if (__open_manifest_db(uid, true) < 0)
return PMINFO_R_ERROR;
locale = _get_system_locale();
char *locale;
int stop = 0;
- if (__open_manifest_db(uid) < 0)
+ if (__open_manifest_db(uid, true) < 0)
return PMINFO_R_ERROR;
locale = _get_system_locale();
sqlite3_stmt *stmt = NULL;
/*open db*/
- ret = __open_manifest_db(uid);
+ ret = __open_manifest_db(uid, true);
retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
/*Start constructing query*/
sqlite3_stmt *stmt = NULL;
/*open db*/
- ret = __open_manifest_db(uid);
+ ret = __open_manifest_db(uid, true);
retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
/*Start constructing query*/
return PMINFO_R_ERROR;
}
- ret = __open_manifest_db(uid);
+ ret = __open_manifest_db(uid, true);
if (ret == -1) {
_LOGE("Fail to open manifest DB\n");
free(locale);
return PMINFO_R_EINVAL;
}
- if (__open_manifest_db(uid) < 0)
+ if (__open_manifest_db(uid, true) < 0)
return PMINFO_R_ERROR;
list = _appinfo_get_metadata_filtered_list(handle);
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <ctype.h>
+#include <stdbool.h>
#include <unistd.h>
#include <sys/types.h>
goto err;
}
- __open_cert_db(uid, "w");
+ __open_cert_db(uid, false);
/*populate certinfo from DB*/
snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
ret = __exec_certinfo_query(query, (void *)certinfo);
retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
- ret = __open_cert_db(uid, "r");
+ ret = __open_cert_db(uid, true);
if (ret != 0) {
ret = PMINFO_R_ERROR;
goto err;
info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
- ret = __open_manifest_db(uid);
+ ret = __open_manifest_db(uid, true);
if (ret != SQLITE_OK) {
_LOGE("connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
ret = PMINFO_R_ERROR;
int i = 0;
/*Open db.*/
- ret = __open_cert_db(uid,"r");
+ ret = __open_cert_db(uid, true);
if (ret != SQLITE_OK) {
_LOGE("connect db [%s] failed!\n");
ret = PMINFO_R_ERROR;
info->pkgid = strdup(pkgid);
/*Open db.*/
- ret =__open_cert_db(uid, "w");
+ ret =__open_cert_db(uid, false);
if (ret != 0) {
ret = PMINFO_R_ERROR;
_LOGE("Failed to open cert db \n");
retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
int ret = -1;
/*Open db.*/
- ret = __open_cert_db(uid, "w");
+ ret = __open_cert_db(uid, false);
if (ret != 0) {
_LOGE("connect db [%s] failed!\n", getUserPkgCertDBPathUID(uid));
ret = PMINFO_R_ERROR;
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <grp.h>
NULL
};
-int __open_manifest_db(uid_t uid)
+int __open_manifest_db(uid_t uid, bool readonly)
{
- int ret = -1;
+ int ret;
+ const char *user_pkg_parser;
+ int flags;
+
if (manifest_db.ref) {
manifest_db.ref ++;
return 0;
}
- const char* user_pkg_parser = getUserPkgParserDBPathUID(uid);
- if (access(user_pkg_parser, F_OK) != 0) {
- _LOGE("Manifest DB does not exists !! try to create\n");
-
- if (pkgmgr_parser_check_and_create_db(uid)) {
- _LOGE("create db failed");
- return -1;
- }
- if (pkgmgr_parser_initialize_db(uid)) {
- _LOGE("initialize db failed");
- return -1;
- }
+ user_pkg_parser = getUserPkgParserDBPathUID(uid);
+ if (access(user_pkg_parser, F_OK) != 0) {
+ _LOGE("Manifest DB does not exists !!");
+ return -1;
}
+ flags = readonly ? SQLITE_OPEN_READONLY : SQLITE_OPEN_READWRITE;
ret = db_util_open_with_options(user_pkg_parser, &GET_DB(manifest_db),
- SQLITE_OPEN_READONLY, NULL);
- retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", user_pkg_parser);
- manifest_db.ref ++;
- ret = __attach_and_create_view(GET_DB(manifest_db), MANIFEST_DB, parserdb_tables, uid);
- retvm_if(ret != SQLITE_OK, -1, "attach db [%s] failed!\n", user_pkg_parser);
-
+ flags, NULL);
+ retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n",
+ user_pkg_parser);
+ manifest_db.ref++;
+ if (readonly) {
+ ret = __attach_and_create_view(GET_DB(manifest_db), MANIFEST_DB,
+ parserdb_tables, uid);
+ retvm_if(ret != SQLITE_OK, -1, "attach db [%s] failed!\n",
+ user_pkg_parser);
+ }
return 0;
}
NULL
};
-int __open_cert_db(uid_t uid, char* mode)
+int __open_cert_db(uid_t uid, bool readonly)
{
- int ret = -1;
+ int ret;
+ const char *user_cert_parser;
+ int flags;
+
if (cert_db.ref) {
cert_db.ref ++;
return 0;
}
- const char* user_cert_parser = getUserPkgCertDBPathUID(uid);
- if (access(user_cert_parser, F_OK) == 0) {
- ret = db_util_open_with_options(user_cert_parser, &GET_DB(cert_db),
- SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
- retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", user_cert_parser);
- cert_db.ref ++;
- if ((strcmp(mode, "w") != 0)) {
- ret = __attach_and_create_view(GET_DB(cert_db), CERT_DB, certdb_tables, uid);
- retvm_if(ret != SQLITE_OK, -1, "attach db [%s] failed!\n", user_cert_parser);
- }
- return 0;
+ user_cert_parser = getUserPkgCertDBPathUID(uid);
+ if (access(user_cert_parser, F_OK) != 0) {
+ _LOGE("Cert DB does not exists !!");
+ return -1;
}
- _LOGE("Cert DB does not exists !!\n");
- return -1;
+
+ flags = readonly ? SQLITE_OPEN_READONLY : SQLITE_OPEN_READWRITE;
+ ret = db_util_open_with_options(user_cert_parser, &GET_DB(cert_db),
+ flags, NULL);
+ retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!",
+ user_cert_parser);
+ cert_db.ref++;
+ if (readonly) {
+ ret = __attach_and_create_view(GET_DB(cert_db), CERT_DB,
+ certdb_tables, uid);
+ retvm_if(ret != SQLITE_OK, -1, "attach db [%s] failed!",
+ user_cert_parser);
+ }
+ return 0;
}
void _save_column_str(sqlite3_stmt *stmt, int idx, const char **str)
retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
/* Open db.*/
- ret = __open_manifest_db(uid);
+ ret = __open_manifest_db(uid, false);
if (ret != SQLITE_OK) {
_LOGE("connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
return PMINFO_R_ERROR;
retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
- ret = __open_manifest_db(uid);
+ ret = __open_manifest_db(uid, false);
if (ret == -1) {
_LOGE("Fail to open manifest DB\n");
return PMINFO_R_ERROR;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <stdbool.h>
#include <unistd.h>
#include <ctype.h>
#include <sys/smack.h>
char *locale;
int stop = 0;
- if (__open_manifest_db(uid) < 0)
+ if (__open_manifest_db(uid, true) < 0)
return PMINFO_R_ERROR;
locale = _get_system_locale();
return PMINFO_R_EINVAL;
}
- if (__open_manifest_db(uid) < 0)
+ if (__open_manifest_db(uid, true) < 0)
return PMINFO_R_ERROR;
return PMINFO_R_ERROR;
}
- ret = __open_manifest_db(uid);
+ ret = __open_manifest_db(uid, true);
if (ret == -1) {
_LOGE("Fail to open manifest DB\n");
free(locale);