4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Wonyoung Lee <wy1115.lee@samsung.com>, Sungchan Kim <sungchan81.kim@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
27 #include <account-private.h>
28 #include <libxml/xmlmemory.h>
29 #include <libxml/parser.h>
31 #include <tzplatform_config.h>
34 #define ACCOUNT_API __attribute__ ((visibility("default")))
37 #define ACCOUNT_XML_DIR tzplatform_mkpath(TZ_SYS_SHARE, "account")
38 #define ACCOUNT_XML_OPT_DIR tzplatform_mkpath(TZ_USER_SHARE, "account")
41 static void _account_parse_doc(xmlDocPtr doc, xmlNodePtr cur,
42 char *capability_filter, bool *supported)
45 cur = cur->xmlChildrenNode;
46 while ((cur != NULL) && (*supported != true)) {
47 if ((!xmlStrcmp(cur->name, (const xmlChar *)"capability"))) {
48 key = xmlNodeGetContent(cur);
49 ACCOUNT_DEBUG("Capability String is : %s\n", key);
50 if (!strcmp(capability_filter, (char *)key)) {
60 static bool _account_check_file_exists(char *f_path)
63 if ((file = fopen(f_path, "r")) != NULL) {
70 ACCOUNT_API int account_get_application_capability_support(char *package_name,
71 char *capability_filter, bool *supported)
74 ACCOUNT_ERROR("package_name can not be NULL \n");
75 return ACCOUNT_ERROR_INVALID_PARAMETER;
77 if (!capability_filter) {
78 ACCOUNT_ERROR("capability_filter can not be NULL \n");
79 return ACCOUNT_ERROR_INVALID_PARAMETER;
82 ACCOUNT_ERROR("supported pointer can not be NULL \n");
83 return ACCOUNT_ERROR_INVALID_PARAMETER;
85 char xml_file_path[BUFSIZE] = {0, };
87 xmlNodePtr cur = NULL;
90 ACCOUNT_MEMSET(xml_file_path, 0, sizeof(xml_file_path));
91 ACCOUNT_SNPRINTF(xml_file_path, BUFSIZE, "%s/%s.account.xml",
92 ACCOUNT_XML_DIR, package_name);
94 ACCOUNT_INFO("xml_file_path = %s \n",xml_file_path);
96 if (!_account_check_file_exists(xml_file_path)) {
97 ACCOUNT_ERROR("XML file not found for %s \n", package_name);
99 /*Check if file exists in /opt directory*/
100 ACCOUNT_MEMSET(xml_file_path, 0, sizeof(xml_file_path));
101 ACCOUNT_SNPRINTF(xml_file_path, BUFSIZE, "%s/%s.account.xml",
102 ACCOUNT_XML_OPT_DIR, package_name);
104 ACCOUNT_INFO("xml_file_path = %s \n",xml_file_path);
106 if (!_account_check_file_exists(xml_file_path)) {
107 ACCOUNT_ERROR("XML file not found for %s \n", package_name);
108 return ACCOUNT_ERROR_XML_FILE_NOT_FOUND;
112 doc = xmlParseFile(xml_file_path);
114 ACCOUNT_ERROR("Document not parsed successfully. \n");
115 return ACCOUNT_ERROR_XML_PARSE_FAILED;
118 cur = xmlDocGetRootElement(doc);
120 ACCOUNT_ERROR("empty document\n");
122 return ACCOUNT_ERROR_XML_PARSE_FAILED;
125 if (xmlStrcmp(cur->name, (const xmlChar *) "account")) {
126 ACCOUNT_ERROR("document of the wrong type, root node != account");
128 return ACCOUNT_ERROR_XML_PARSE_FAILED;
130 _account_parse_doc(doc, cur, capability_filter, supported);
133 return ACCOUNT_ERROR_NONE;
136 ACCOUNT_API int account_get_application_multiple_account_support(
141 ACCOUNT_ERROR("package_name can not be NULL \n");
142 return ACCOUNT_ERROR_INVALID_PARAMETER;
145 ACCOUNT_ERROR("supported pointer can not be NULL \n");
146 return ACCOUNT_ERROR_INVALID_PARAMETER;
148 char xml_file_path[BUFSIZE] = {0, };
149 xmlDocPtr doc = NULL;
150 xmlNodePtr cur = NULL;
151 xmlChar *attr = NULL;
154 ACCOUNT_MEMSET(xml_file_path, 0, sizeof(xml_file_path));
155 ACCOUNT_SNPRINTF(xml_file_path, BUFSIZE, "%s/%s.account.xml",
156 ACCOUNT_XML_DIR, package_name);
158 ACCOUNT_VERBOSE("xml_file_path = %s \n",xml_file_path);
160 if (!_account_check_file_exists(xml_file_path)) {
161 ACCOUNT_ERROR("XML file not found for %s \n", package_name);
163 /*Check if file exists in /opt directory*/
164 ACCOUNT_MEMSET(xml_file_path, 0, sizeof(xml_file_path));
165 ACCOUNT_SNPRINTF(xml_file_path, BUFSIZE, "%s/%s.account.xml",
166 ACCOUNT_XML_OPT_DIR, package_name);
168 ACCOUNT_VERBOSE("xml_file_path = %s \n",xml_file_path);
170 if (!_account_check_file_exists(xml_file_path)) {
171 ACCOUNT_ERROR("XML file not found for %s \n", package_name);
172 return ACCOUNT_ERROR_XML_FILE_NOT_FOUND;
176 doc = xmlParseFile(xml_file_path);
178 ACCOUNT_ERROR("Document not parsed successfully. \n");
179 return ACCOUNT_ERROR_XML_PARSE_FAILED;
182 cur = xmlDocGetRootElement(doc);
184 ACCOUNT_ERROR("empty document\n");
186 return ACCOUNT_ERROR_XML_PARSE_FAILED;
189 if (xmlStrcmp(cur->name, (const xmlChar *) "account")) {
190 ACCOUNT_ERROR("document of the wrong type, root node != account");
192 return ACCOUNT_ERROR_XML_PARSE_FAILED;
194 attr = xmlGetProp(cur, (const xmlChar *)"multiple");
195 ACCOUNT_INFO("Multiple = %s \n",(char *)attr);
199 else if (!strcmp("false", (char *)attr))
201 else if (!strcmp("true", (char *)attr))
208 return ACCOUNT_ERROR_NONE;
211 ACCOUNT_API int account_get_application_icon_path(const char *package_name,
215 ACCOUNT_ERROR("package_name can not be NULL \n");
216 return ACCOUNT_ERROR_INVALID_PARAMETER;
219 ACCOUNT_ERROR("icon_path pointer can not be NULL \n");
220 return ACCOUNT_ERROR_INVALID_PARAMETER;
222 char xml_file_path[BUFSIZE] = {0, };
223 xmlDocPtr doc = NULL;
224 xmlNodePtr cur = NULL;
225 xmlChar *attr = NULL;
228 ACCOUNT_MEMSET(xml_file_path, 0, sizeof(xml_file_path));
229 ACCOUNT_SNPRINTF(xml_file_path, BUFSIZE, "%s/%s.account.xml",
230 ACCOUNT_XML_DIR, package_name);
232 ACCOUNT_INFO("xml_file_path = %s \n",xml_file_path);
234 if (!_account_check_file_exists(xml_file_path)) {
235 ACCOUNT_ERROR("XML file not found for %s \n", package_name);
237 /*Check if file exists in /opt directory*/
238 ACCOUNT_MEMSET(xml_file_path, 0, sizeof(xml_file_path));
239 ACCOUNT_SNPRINTF(xml_file_path, BUFSIZE, "%s/%s.account.xml",
240 ACCOUNT_XML_OPT_DIR, package_name);
242 ACCOUNT_INFO("xml_file_path = %s \n",xml_file_path);
244 if (!_account_check_file_exists(xml_file_path)) {
245 ACCOUNT_ERROR("XML file not found for %s \n", package_name);
246 return ACCOUNT_ERROR_XML_FILE_NOT_FOUND;
250 doc = xmlParseFile(xml_file_path);
252 ACCOUNT_ERROR("Document not parsed successfully. \n");
253 return ACCOUNT_ERROR_XML_PARSE_FAILED;
256 cur = xmlDocGetRootElement(doc);
258 ACCOUNT_ERROR("empty document\n");
260 return ACCOUNT_ERROR_XML_PARSE_FAILED;
263 if (xmlStrcmp(cur->name, (const xmlChar *) "account")) {
264 ACCOUNT_ERROR("document of the wrong type, root node != account");
266 return ACCOUNT_ERROR_XML_PARSE_FAILED;
268 attr = xmlGetProp(cur, (const xmlChar *)"icon_path");
269 ACCOUNT_DEBUG("icon_path = %s \n",(char *)attr);
274 *icon_path = strdup((char *)attr);
278 return ACCOUNT_ERROR_NONE;
281 static bool __service_iter_func(service_h service, const char* pkg_name,
285 ACCOUNT_ERROR("__service_iter_func: pkg name NULL \n");
288 GList **pkg_list = (GList **)data;
289 char *pkgname = NULL;
290 pkgname = strdup(pkg_name);
291 *pkg_list = g_list_append(*pkg_list, pkgname);
295 ACCOUNT_API int account_query_service_list_by_capability(service_list_cb callback,
296 const char* capability_type,
299 int ret = SERVICE_ERROR_NONE;
300 GList *pkg_list = NULL;
301 service_h service = NULL;
303 char *list_item = NULL;
304 char *capability_filter = NULL;
305 bool supported = false;
306 char *icon_path = NULL;
307 bool multiple = false;
308 int error_code = ACCOUNT_ERROR_NONE;
310 ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CAPABILITY TYPE IS NULL"));
311 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
313 ACCOUNT_VERBOSE("account_query_service_list_by_capability START \n");
314 ret = service_create(&service);
315 if (ret != SERVICE_ERROR_NONE) {
316 ACCOUNT_ERROR("Owner Check : service_create fail ret=%d\n", ret);
319 ACCOUNT_VERBOSE("service_list_by: service_create SUCCESS!!!!!! ret=%d\n", ret);
321 ret = service_set_operation(service, ACCOUNT_OPERATION_SIGNIN);
322 if (ret != SERVICE_ERROR_NONE) {
323 ACCOUNT_ERROR("service_list_by : service_set_operation fail ret=%d\n", ret);
324 service_destroy(service);
327 ACCOUNT_VERBOSE("service_list_by : service_set_operation SUCCESS!!!!!! ret=%d\n",
330 ret = service_foreach_app_matched(service, __service_iter_func, &pkg_list);
331 if (ret != SERVICE_ERROR_NONE) {
332 ACCOUNT_ERROR("service_list_by : service_foreach_app_matched fail ret=%d\n",
334 service_destroy(service);
337 ACCOUNT_VERBOSE("service_list_by : service_foreach_app_matched SUCCESS!!!!!! ret=%d\n",
341 ret = service_destroy(service);
342 if (ret != SERVICE_ERROR_NONE) {
343 ACCOUNT_ERROR("service_list_by : service_destroy fail ret=%d\n", ret);
344 for (iter = pkg_list; iter != NULL; iter = g_list_next(iter)) {
345 list_item = (char *)iter->data;
348 g_list_free(pkg_list);
351 ACCOUNT_VERBOSE("service_list_by : service_destroy SUCCESS!!!!!! ret=%d\n", ret);
354 capability_filter = strdup(capability_type);
356 for (iter = pkg_list; iter != NULL; iter = g_list_next(iter)) {
357 list_item = (char *)iter->data;
358 error_code = account_get_application_capability_support(list_item,
362 if ((error_code != ACCOUNT_ERROR_NONE)
363 && (error_code != ACCOUNT_ERROR_XML_FILE_NOT_FOUND)) {
364 ACCOUNT_ERROR("service_list_by : account_get_application_capability_support fail error_code=%d\n", error_code);
365 for (iter = pkg_list; iter != NULL; iter = g_list_next(iter)) {
366 list_item = (char *)iter->data;
369 g_list_free(pkg_list);
370 _ACCOUNT_FREE(capability_filter);
375 error_code = account_get_application_icon_path(list_item, &icon_path);
376 if (error_code != ACCOUNT_ERROR_NONE) {
377 ACCOUNT_ERROR("service_list_by : account_get_application_capability_support fail error_code=%d\n", error_code);
378 for (iter = pkg_list; iter != NULL; iter = g_list_next(iter)) {
379 list_item = (char *)iter->data;
382 g_list_free(pkg_list);
383 _ACCOUNT_FREE(capability_filter);
386 error_code = account_get_application_multiple_account_support(list_item, &multiple);
387 if (error_code != ACCOUNT_ERROR_NONE) {
388 ACCOUNT_ERROR("service_list_by : account_get_application_capability_support fail error_code=%d\n", error_code);
389 for (iter = pkg_list; iter != NULL; iter = g_list_next(iter)) {
390 list_item = (char *)iter->data;
393 g_list_free(pkg_list);
394 _ACCOUNT_FREE(capability_filter);
397 callback(list_item, icon_path, multiple, user_data);
401 for (iter = pkg_list; iter != NULL; iter = g_list_next(iter)) {
402 list_item = (char *)iter->data;
405 g_list_free(pkg_list);
406 _ACCOUNT_FREE(capability_filter);
407 return ACCOUNT_ERROR_NONE;