return alias_id;
}
-static int __get_list_with_condition_mime_extened(char *op, char *uri,
- char *mime, char *m_type, char *s_type,
- GSList **pkg_list, uid_t uid)
+static char* __make_query(char *query, char *op, char *uri,
+ char *mime, char *m_type, char *s_type)
{
- char *tmp;
+ char tmp[MAX_MIME_STR_SIZE] = { 0, };
- tmp = malloc(MAX_MIME_STR_SIZE);
- if (tmp == NULL) {
- _E("out of memory");
- return -1;
- }
-
- _svc_db_get_list_with_condition(op, uri, mime, pkg_list, uid);
+ query = _svc_db_query_builder_add(query, op, uri, mime, false);
if ((strncmp(mime, "NULL", 4) != 0) && (strncmp(s_type, "%", 1) != 0)) {
snprintf(tmp, MAX_MIME_STR_SIZE - 1, "%s/*", m_type);
- _svc_db_get_list_with_condition(op, uri, tmp, pkg_list, uid);
+ query = _svc_db_query_builder_add(query, op, uri, tmp, false);
}
+
if ((strncmp(mime, "NULL", 4) != 0) && (strncmp(m_type, "%", 1) != 0)) {
snprintf(tmp, MAX_MIME_STR_SIZE - 1, "*/*");
- _svc_db_get_list_with_condition(op, uri, tmp, pkg_list, uid);
+ query = _svc_db_query_builder_add(query, op, uri, tmp, false);
}
- free(tmp);
-
- return 0;
+ return query;
}
static int __get_list_with_condition_mime_extened_with_collation(char *op,
char *uri, char *mime, char *m_type,
char *s_type, GSList **pkg_list, uid_t uid)
{
- char *tmp;
+ char tmp[MAX_MIME_STR_SIZE];
+ char *query = NULL;
- tmp = malloc(MAX_MIME_STR_SIZE);
- if (tmp == NULL) {
- _E("out of memory");
- return -1;
- }
+ query = _svc_db_query_builder_add(query, op, uri, mime, true);
- _svc_db_get_list_with_collation(op, uri, mime, pkg_list, uid);
if ((strncmp(mime, "NULL", 4) != 0) && (strncmp(s_type, "%", 1) != 0)) {
snprintf(tmp, MAX_MIME_STR_SIZE - 1, "%s/*", m_type);
- _svc_db_get_list_with_collation(op, uri, tmp, pkg_list, uid);
+ query = _svc_db_query_builder_add(query, op, uri, tmp, true);
}
if ((strncmp(mime, "NULL", 4) != 0) && (strncmp(m_type, "%", 1) != 0)) {
snprintf(tmp, MAX_MIME_STR_SIZE - 1, "*/*");
- _svc_db_get_list_with_collation(op, uri, tmp, pkg_list, uid);
+ query = _svc_db_query_builder_add(query, op, uri, tmp, true);
}
- free(tmp);
+ query = _svc_db_query_builder_build(query, true);
+ _svc_db_exec_query(query, pkg_list, uid);
+ if (query)
+ free(query);
return 0;
}
GSList *pkg_list = NULL;
GSList *iter = NULL;
char *list_item;
+ char *query = NULL;
if (b == NULL) {
_E("bundle for aul_svc_set_appid is NULL");
info.mime, info.m_type, info.s_type, &pkg_list, uid);
pkg_count = g_slist_length(pkg_list);
if (pkg_count > 0) {
-
if (info.uri_r_info) {
- __get_list_with_condition_mime_extened(info.op, info.uri_r_info,
- info.mime, info.m_type, info.s_type, &pkg_list, uid);
+ query = __make_query(query, info.op, info.uri_r_info,
+ info.mime, info.m_type, info.s_type);
}
- __get_list_with_condition_mime_extened(info.op, info.scheme,
- info.mime, info.m_type, info.s_type, &pkg_list, uid);
+ query = __make_query(query, info.op, info.scheme,
+ info.mime, info.m_type, info.s_type);
- __get_list_with_condition_mime_extened(info.op, "*",
- info.mime, info.m_type, info.s_type, &pkg_list, uid);
+ query = __make_query(query, info.op, "*",
+ info.mime, info.m_type, info.s_type);
if (info.scheme && (strcmp(info.scheme, "file") == 0)
&& info.mime && (strcmp(info.mime, "NULL") != 0)) {
- __get_list_with_condition_mime_extened(info.op, "NULL",
- info.mime, info.m_type, info.s_type, &pkg_list, uid);
+ query = __make_query(query, info.op, "NULL",
+ info.mime, info.m_type, info.s_type);
+ }
+
+ query = _svc_db_query_builder_build(query, false);
+ _svc_db_exec_query(query, &pkg_list, uid);
+ if (query) {
+ free(query);
+ query = NULL;
}
if (info.category)
pkgname = _svc_db_get_app(info.op, info.origin_mime, info.uri_r_info, uid);
if (pkgname == NULL) {
- __get_list_with_condition_mime_extened(info.op, info.uri_r_info,
- info.mime, info.m_type, info.s_type, &pkg_list, uid);
+ query = __make_query(query, info.op, info.uri_r_info,
+ info.mime, info.m_type, info.s_type);
pkg_count = g_slist_length(pkg_list);
if (pkg_count > 0) {
- __get_list_with_condition_mime_extened(info.op, info.scheme,
- info.mime, info.m_type, info.s_type, &pkg_list, uid);
+ query = __make_query(query, info.op, info.scheme,
+ info.mime, info.m_type, info.s_type);
- __get_list_with_condition_mime_extened(info.op, "*",
- info.mime, info.m_type, info.s_type, &pkg_list, uid);
+ query = __make_query(query, info.op, "*",
+ info.mime, info.m_type, info.s_type);
if (info.scheme && (strcmp(info.scheme, "file") == 0)
&& info.mime && (strcmp(info.mime, "NULL") != 0)) {
- __get_list_with_condition_mime_extened(info.op, "NULL",
- info.mime, info.m_type, info.s_type, &pkg_list, uid);
+ query = __make_query(query, info.op, "NULL",
+ info.mime, info.m_type, info.s_type);
+ }
+
+ query = _svc_db_query_builder_build(query, false);
+ _svc_db_exec_query(query, &pkg_list, uid);
+ if (query) {
+ free(query);
+ query = NULL;
}
if (info.category)
cbfunc, data, uid);
goto end;
}
+ } else {
+ query = _svc_db_query_builder_build(query, false);
+ _svc_db_exec_query(query, &pkg_list, uid);
+ if (query) {
+ free(query);
+ query = NULL;
+ }
}
for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) {
list_item = (char *)iter->data;
pkgname = _svc_db_get_app(info.op, info.origin_mime, info.scheme, uid);
if (pkgname == NULL) {
- __get_list_with_condition_mime_extened(info.op, info.scheme,
- info.mime, info.m_type, info.s_type, &pkg_list, uid);
+ query = __make_query(query, info.op, info.scheme,
+ info.mime, info.m_type, info.s_type);
- __get_list_with_condition_mime_extened(info.op, "*",
- info.mime, info.m_type, info.s_type, &pkg_list, uid);
+ query = __make_query(query, info.op, "*",
+ info.mime, info.m_type, info.s_type);
if (info.scheme && (strcmp(info.scheme, "file") == 0)
&& info.mime && (strcmp(info.mime, "NULL") != 0)) {
- __get_list_with_condition_mime_extened(info.op, "NULL",
- info.mime, info.m_type, info.s_type, &pkg_list, uid);
+ query = __make_query(query, info.op, "NULL",
+ info.mime, info.m_type, info.s_type);
+ }
+
+ query = _svc_db_query_builder_build(query, false);
+ _svc_db_exec_query(query, &pkg_list, uid);
+
+ if (query) {
+ free(query);
+ query = NULL;
}
if (info.category)
GSList *pkg_list = NULL;
GSList *iter = NULL;
+ char *query = NULL;
if (b == NULL) {
_E("bundle for aul_svc_run_service is NULL");
info.mime, info.m_type, info.s_type, &pkg_list, uid);
if (info.uri_r_info) {
- __get_list_with_condition_mime_extened(info.op, info.uri_r_info,
- info.mime, info.m_type, info.s_type, &pkg_list, uid);
+ query = __make_query(query, info.op, info.uri_r_info,
+ info.mime, info.m_type, info.s_type);
}
- __get_list_with_condition_mime_extened(info.op, info.scheme,
- info.mime, info.m_type, info.s_type, &pkg_list, uid);
+ query = __make_query(query, info.op, info.scheme,
+ info.mime, info.m_type, info.s_type);
- __get_list_with_condition_mime_extened(info.op, "*",
- info.mime, info.m_type, info.s_type, &pkg_list, uid);
+ query = __make_query(query, info.op, "*",
+ info.mime, info.m_type, info.s_type);
if (info.scheme && (strcmp(info.scheme, "file") == 0)
&& info.mime && (strcmp(info.mime, "NULL") != 0)) {
- __get_list_with_condition_mime_extened(info.op, "NULL",
- info.mime, info.m_type, info.s_type, &pkg_list, uid);
+ query = __make_query(query, info.op, "NULL",
+ info.mime, info.m_type, info.s_type);
+ }
+
+ query = _svc_db_query_builder_build(query, false);
+ _svc_db_exec_query(query, &pkg_list, uid);
+ if (query) {
+ free(query);
+ query = NULL;
}
if (info.category)
return 0;
}
-int _svc_db_get_list_with_condition(char *op, char *uri, char *mime,
- GSList **pkg_list, uid_t uid)
+int _svc_db_get_list_with_all_defapps(GSList **pkg_list, uid_t uid)
{
char query[QUERY_MAX_LEN];
sqlite3_stmt* stmt;
char *pkgname = NULL;
int found;
- if (__init_app_info_db(uid) < 0)
- return 0;
+ if (__init(uid, true) < 0)
+ return -1;
- snprintf(query, QUERY_MAX_LEN,
- "select ac.app_id from package_app_app_control as ac, package_app_info ai where ac.app_id = ai.app_id and ac.app_control like '%%%s|%s|%s%%' and ai.component_type='uiapp'",
- op, uri, mime);
- SECURE_LOGD("query : %s\n", query);
+ snprintf(query, QUERY_MAX_LEN, "select pkg_name from appsvc");
- ret = sqlite3_prepare(app_info_db, query, strlen(query), &stmt, NULL);
+ ret = sqlite3_prepare(svc_db, query, sizeof(query), &stmt, NULL);
if (ret != SQLITE_OK) {
_E("prepare error, ret = %d, extended = %d\n",
- ret, sqlite3_extended_errcode(app_info_db));
+ ret, sqlite3_extended_errcode(svc_db));
return -1;
}
if (found == 0) {
pkgname = strdup(str);
*pkg_list = g_slist_append(*pkg_list, (void *)pkgname);
- _D("%s is added", pkgname);
+ _D("[%s] is def app", pkgname);
}
}
return 0;
}
-int _svc_db_get_list_with_collation(char *op, char *uri, char *mime,
- GSList **pkg_list, uid_t uid)
+char *_svc_db_query_builder_add(char *old_query, char *op, char *uri, char *mime, bool collate)
{
char query[QUERY_MAX_LEN];
- sqlite3_stmt* stmt;
- int ret;
- GSList *iter = NULL;
- char *str = NULL;
- char *pkgname = NULL;
- int found;
- if (__init_app_info_db(uid) < 0)
- return 0;
+ if (collate) {
+ if (old_query) {
+ snprintf(query, QUERY_MAX_LEN,
+ "%s, '%s|%s|%s' collate appsvc_collation ",
+ old_query, op, uri, mime);
+ free(old_query);
+ } else {
+ snprintf(query, QUERY_MAX_LEN,
+ "'%s|%s|%s' collate appsvc_collation ",
+ op, uri, mime);
+ }
- snprintf(query, QUERY_MAX_LEN,
- "select ac.app_id from package_app_app_control as ac, package_app_info ai where ac.app_id = ai.app_id and ac.app_control='%s|%s|%s' collate appsvc_collation and ai.component_type='uiapp'",
+ } else {
+ if (old_query) {
+ snprintf(query, QUERY_MAX_LEN,
+ "%s OR ac.app_control like '%%%s|%s|%s%%' ",
+ old_query, op, uri, mime);
+ free(old_query);
+ } else {
+ snprintf(query, QUERY_MAX_LEN,
+ "ac.app_control like '%%%s|%s|%s%%' ",
op, uri, mime);
- SECURE_LOGD("query : %s\n", query);
-
- ret = sqlite3_prepare(app_info_db, query, strlen(query), &stmt, NULL);
- if (ret != SQLITE_OK) {
- _E("prepare error, ret = %d, extended = %d\n",
- ret, sqlite3_extended_errcode(app_info_db));
- return -1;
- }
-
- while (sqlite3_step(stmt) == SQLITE_ROW) {
- str = (char *)sqlite3_column_text(stmt, 0);
- found = 0;
- for (iter = *pkg_list; iter != NULL; iter = g_slist_next(iter)) {
- pkgname = (char *)iter->data;
- if (strncmp(str, pkgname, MAX_PACKAGE_STR_SIZE - 1) == 0) {
- found = 1;
- break;
- }
- }
- if (found == 0) {
- pkgname = strdup(str);
- *pkg_list = g_slist_append(*pkg_list, (void *)pkgname);
- _D("%s is added", pkgname);
}
}
- ret = sqlite3_finalize(stmt);
-
- return 0;
+ return strdup(query);
}
-int _svc_db_get_list_with_all_defapps(GSList **pkg_list, uid_t uid)
+char *_svc_db_query_builder_build(char *old_query, bool collate)
{
char query[QUERY_MAX_LEN];
+
+ if (old_query == NULL)
+ return NULL;
+
+ if (collate) {
+ snprintf(query, QUERY_MAX_LEN,
+ "select ac.app_id from package_app_app_control as ac, package_app_info ai where ac.app_id = ai.app_id and ai.component_type='uiapp' and ac.app_control in(%s)",
+ old_query);
+ } else {
+ snprintf(query, QUERY_MAX_LEN,
+ "select ac.app_id from package_app_app_control as ac, package_app_info ai where ac.app_id = ai.app_id and ai.component_type='uiapp' and (%s)",
+ old_query);
+ }
+ free(old_query);
+
+ return strdup(query);
+}
+
+int _svc_db_exec_query(const char *query, GSList **pkg_list, uid_t uid)
+{
sqlite3_stmt* stmt;
int ret;
GSList *iter = NULL;
char *pkgname = NULL;
int found;
- if (__init(uid, true) < 0)
- return -1;
+ if (__init_app_info_db(uid) < 0)
+ return 0;
- snprintf(query, QUERY_MAX_LEN, "select pkg_name from appsvc");
+ SECURE_LOGD("query : %s\n", query);
- ret = sqlite3_prepare(svc_db, query, sizeof(query), &stmt, NULL);
+ ret = sqlite3_prepare(app_info_db, query, strlen(query), &stmt, NULL);
if (ret != SQLITE_OK) {
_E("prepare error, ret = %d, extended = %d\n",
- ret, sqlite3_extended_errcode(svc_db));
+ ret, sqlite3_extended_errcode(app_info_db));
return -1;
}
if (found == 0) {
pkgname = strdup(str);
*pkg_list = g_slist_append(*pkg_list, (void *)pkgname);
- _D("[%s] is def app", pkgname);
+ _D("%s is added", pkgname);
}
}
return 0;
}
+