From: Jaeho Lee Date: Fri, 7 Dec 2012 02:20:40 +0000 (+0900) Subject: support wildcard for uri path X-Git-Tag: 2.1b_release~2^2~13 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1d6058631764d25163b836e9622c196707809411;p=framework%2Fappfw%2Fapp-svc.git support wildcard for uri path Signed-off-by: Jaeho Lee --- diff --git a/include/appsvc.h b/include/appsvc.h index 95602dc..4a98f39 100755 --- a/include/appsvc.h +++ b/include/appsvc.h @@ -97,11 +97,6 @@ extern "C" { /** APP SVC internal private key */ #define APP_SVC_K_URI_R_INFO "__APP_SVC_URI_R_INFO__" -/** APP SVC internal private value */ -#define APP_SVC_V_SCHEME_AND_HOST "__SCHEME_AND_HOST__" -/** APP SVC internal private value */ -#define APP_SVC_V_SCHEME "__SCHEME__" - /** * @brief Return values in appsvc. diff --git a/include/appsvc_db.h b/include/appsvc_db.h index 711611c..b9ef5c8 100755 --- a/include/appsvc_db.h +++ b/include/appsvc_db.h @@ -37,6 +37,8 @@ int _svc_db_add_app(const char *op, const char *mime_type, const char *uri, cons int _svc_db_delete_with_pkgname(const char *pkg_name); char* _svc_db_get_app(const char *op, const char *mime_type, const char *uri); int _svc_db_is_defapp(const char *pkg_name); +int _svc_db_get_list_with_collation(char *op, char *uri, char *mime, GSList **pkg_list); + #ifdef __cplusplus diff --git a/packaging/app-svc.spec b/packaging/app-svc.spec index 2e7bc2f..78ecd06 100644 --- a/packaging/app-svc.spec +++ b/packaging/app-svc.spec @@ -1,7 +1,7 @@ #sbs-git:slp/pkgs/a/app-svc app-svc 0.1.19 de68cdc468eaded317b4f5be9cdafebb01639aa0 Name: app-svc Summary: App svc -Version: 0.1.34 +Version: 0.1.37 Release: 1 Group: System/Libraries License: Apache License, Version 2.0 diff --git a/src/appsvc.c b/src/appsvc.c index 772407b..37fabb8 100755 --- a/src/appsvc.c +++ b/src/appsvc.c @@ -515,6 +515,14 @@ static int __get_list_with_condition_mime_extened(char *op, char *uri, char *mim return 0; } +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) +{ + _svc_db_get_list_with_collation(op, uri, mime, pkg_list); + + return 0; +} + GSList *tmp_list; static int __app_list_cb(pkgmgrinfo_appinfo_h handle, void *user_data) { @@ -601,6 +609,54 @@ SLPAPI int appsvc_run_service(bundle *b, int request_code, appsvc_res_fn cbfunc, return ret; } + /*uri*/ + pkgname = _svc_db_get_app(info.op, info.origin_mime, info.uri); + if(pkgname==NULL){ + __get_list_with_condition_mime_extened_with_collation(info.op, info.uri, + info.mime, info.m_type, info.s_type, &pkg_list); + 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); + } + + __get_list_with_condition_mime_extened(info.op, info.scheme, + info.mime, info.m_type, info.s_type, &pkg_list); + + if(info.category) { + __get_list_with_category(info.category, &pkg_list); + } + + pkg_count = g_slist_length(pkg_list); + _D("pkg_count : %d", pkg_count); + + if(pkg_count == 1){ + pkgname = (char *)pkg_list->data; + if(pkgname != NULL){ + ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data); + goto end; + } + } else { + bundle_add(b, APP_SVC_K_URI_R_INFO, info.uri); + ret = __run_svc_with_pkgname(APP_SELECTOR, b, request_code, cbfunc, data); + goto end; + } + for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) { + list_item = (char *)iter->data; + g_free(list_item); + } + g_slist_free(pkg_list); + pkg_list = NULL; + } + } else { + ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data); + free(pkgname); + goto end; + } + + /*scheme & host*/ if(info.uri_r_info) { pkgname = _svc_db_get_app(info.op, info.origin_mime, info.uri_r_info); @@ -626,7 +682,7 @@ SLPAPI int appsvc_run_service(bundle *b, int request_code, appsvc_res_fn cbfunc, goto end; } } else { - bundle_add(b, APP_SVC_K_URI_R_INFO, APP_SVC_V_SCHEME_AND_HOST); + bundle_add(b, APP_SVC_K_URI_R_INFO, info.uri_r_info); ret = __run_svc_with_pkgname(APP_SELECTOR, b, request_code, cbfunc, data); goto end; } @@ -643,7 +699,8 @@ SLPAPI int appsvc_run_service(bundle *b, int request_code, appsvc_res_fn cbfunc, goto end; } } - + + /*scheme*/ pkgname = _svc_db_get_app(info.op, info.origin_mime, info.scheme); if(pkgname==NULL){ @@ -666,7 +723,7 @@ SLPAPI int appsvc_run_service(bundle *b, int request_code, appsvc_res_fn cbfunc, __free_resolve_info_data(&info); return APPSVC_RET_ENOMATCH; } else { - bundle_add(b, APP_SVC_K_URI_R_INFO, APP_SVC_V_SCHEME); + bundle_add(b, APP_SVC_K_URI_R_INFO, info.scheme); ret = __run_svc_with_pkgname(APP_SELECTOR, b, request_code, cbfunc, data); } @@ -714,6 +771,9 @@ SLPAPI int appsvc_get_list(bundle *b, appsvc_info_iter_fn iter_fn, void *data) _D("operation - %s / shceme - %s / mime - %s\n", info.op, info.scheme, info.mime); + __get_list_with_condition_mime_extened_with_collation(info.op, info.uri, + info.mime, info.m_type, info.s_type, &pkg_list); + 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); @@ -722,6 +782,10 @@ SLPAPI int appsvc_get_list(bundle *b, appsvc_info_iter_fn iter_fn, void *data) __get_list_with_condition_mime_extened(info.op, info.scheme, info.mime, info.m_type, info.s_type, &pkg_list); + if(info.category) { + __get_list_with_category(info.category, &pkg_list); + } + pkg_count = g_slist_length(pkg_list); if (pkg_count == 0) { _E("Cannot find associated application"); diff --git a/src/appsvc_db.c b/src/appsvc_db.c index 3edcbdb..800e644 100755 --- a/src/appsvc_db.c +++ b/src/appsvc_db.c @@ -23,16 +23,23 @@ #include #include #include +#include #include "appsvc_db.h" #include "internal.h" #define SVC_DB_PATH "/opt/dbspace/.appsvc.db" +#define APP_INFO_DB_PATH "/opt/dbspace/.app_info.db" + #define QUERY_MAXLEN 4096 #define BUF_MAX_LEN 1024 +#define APPSVC_COLLATION "appsvc_collation" + static sqlite3 *svc_db = NULL; +static sqlite3 *app_info_db = NULL; + /** @@ -66,6 +73,104 @@ err: return -1; } +static int __collate_appsvc(void *ucol, int str1_len, const void *str1, int str2_len, const void *str2) +{ + char *saveptr1, *saveptr2; + char *dup_str1; + char *dup_str2; + char *token; + char *in_op; + char *in_uri; + char *in_mime; + char *op; + char *uri; + char *mime; + int i; + + if(str1 == NULL || str2 == NULL) + return -1; + + dup_str1 = strdup(str1); + dup_str2 = strdup(str2); + + in_op = strtok_r(dup_str2, "|", &saveptr1); + in_uri = strtok_r(NULL, "|", &saveptr1); + in_mime = strtok_r(NULL, "|", &saveptr1); + + token = strtok_r(dup_str1, ";", &saveptr1); + + if(token == NULL) { + free(dup_str1); + free(dup_str2); + return -1; + } + + do { + //_D("token : %s", token); + op = strtok_r(token, "|", &saveptr2); + uri = strtok_r(NULL, "|", &saveptr2); + mime = strtok_r(NULL, "|", &saveptr2); + + if( (strcmp(op, in_op) == 0) && (strcmp(mime, in_mime) == 0) ) { + _D("%s %s %s %s %s %s", op, in_op, mime, in_mime, uri, in_uri); + if(strcmp(uri, in_uri) == 0) { + free(dup_str1); + free(dup_str2); + return 0; + } else { + for(i=0; uri[i]!=0; i++) { + if(uri[i] == '*') { + uri[i] = 0; + if(strstr(in_uri, uri)) { + _D("in_uri : %s | uri : %s", in_uri, uri); + free(dup_str1); + free(dup_str2); + return 0; + } + } + } + } + } + } while(token = strtok_r(NULL, ";", &saveptr1)); + + free(dup_str1); + free(dup_str2); + + return -1; +} + +static int __init_app_info_db(void) +{ + int rc; + + if (app_info_db) { + _D("Already initialized\n"); + return 0; + } + + rc = sqlite3_open(APP_INFO_DB_PATH, &app_info_db); + if(rc) { + _E("Can't open database: %s", sqlite3_errmsg(app_info_db)); + goto err; + } + + // Enable persist journal mode + rc = sqlite3_exec(app_info_db, "PRAGMA journal_mode = PERSIST", NULL, NULL, NULL); + if(SQLITE_OK!=rc){ + _D("Fail to change journal mode\n"); + goto err; + } + + sqlite3_create_collation(app_info_db, APPSVC_COLLATION, SQLITE_UTF8, NULL, + __collate_appsvc); + + return 0; +err: + sqlite3_close(app_info_db); + return -1; +} + + static int __fini(void) { if (svc_db) { @@ -233,3 +338,49 @@ char* _svc_db_get_app(const char *op, const char *mime_type, const char *uri) return pkgname; } +int _svc_db_get_list_with_collation(char *op, char *uri, char *mime, GSList **pkg_list) +{ + char query[BUF_MAX_LEN]; + sqlite3_stmt* stmt; + int ret; + GSList *iter = NULL; + char *str = NULL; + char *pkgname = NULL; + int found; + + if(__init_app_info_db()<0) + return 0; + + sprintf(query,"select package from app_info where x_slp_svc='%s|%s|%s' collate appsvc_collation", op,uri,mime); + _D("query : %s\n",query); + + ret = sqlite3_prepare(app_info_db, query, strlen(query), &stmt, NULL); + + if ( ret != SQLITE_OK) { + _E("prepare error\n"); + return -1; + } + + while (sqlite3_step(stmt) == SQLITE_ROW) { + str = 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; +} + +