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>
33 #define ACCOUNT_API __attribute__ ((visibility("default")))
36 #define ACCOUNT_XML_DIR "/usr/share/account"
37 #define ACCOUNT_XML_OPT_DIR "/opt/usr/share/account"
40 static void _account_parse_doc(xmlDocPtr doc, xmlNodePtr cur,
41 char *capability_filter, bool *supported)
44 cur = cur->xmlChildrenNode;
45 while ((cur != NULL) && (*supported != true)) {
46 if ((!xmlStrcmp(cur->name, (const xmlChar *)"capability"))) {
47 key = xmlNodeGetContent(cur);
48 ACCOUNT_DEBUG("Capability String is : %s\n", key);
49 if (!strcmp(capability_filter, (char *)key)) {
59 static bool _account_check_file_exists(char *f_path)
62 if ((file = fopen(f_path, "r")) != NULL) {
69 ACCOUNT_API int account_get_application_capability_support(char *package_name,
70 char *capability_filter, bool *supported)
73 ACCOUNT_ERROR("package_name can not be NULL \n");
74 return ACCOUNT_ERROR_INVALID_PARAMETER;
76 if (!capability_filter) {
77 ACCOUNT_ERROR("capability_filter can not be NULL \n");
78 return ACCOUNT_ERROR_INVALID_PARAMETER;
81 ACCOUNT_ERROR("supported pointer can not be NULL \n");
82 return ACCOUNT_ERROR_INVALID_PARAMETER;
84 char xml_file_path[BUFSIZE] = {0, };
86 xmlNodePtr cur = NULL;
89 ACCOUNT_MEMSET(xml_file_path, 0, sizeof(xml_file_path));
90 ACCOUNT_SNPRINTF(xml_file_path, BUFSIZE, "%s/%s.account.xml",
91 ACCOUNT_XML_DIR, package_name);
93 ACCOUNT_INFO("xml_file_path = %s \n",xml_file_path);
95 if (!_account_check_file_exists(xml_file_path)) {
96 ACCOUNT_ERROR("XML file not found for %s \n", package_name);
98 /*Check if file exists in /opt directory*/
99 ACCOUNT_MEMSET(xml_file_path, 0, sizeof(xml_file_path));
100 ACCOUNT_SNPRINTF(xml_file_path, BUFSIZE, "%s/%s.account.xml",
101 ACCOUNT_XML_OPT_DIR, package_name);
103 ACCOUNT_INFO("xml_file_path = %s \n",xml_file_path);
105 if (!_account_check_file_exists(xml_file_path)) {
106 ACCOUNT_ERROR("XML file not found for %s \n", package_name);
107 return ACCOUNT_ERROR_XML_FILE_NOT_FOUND;
111 doc = xmlParseFile(xml_file_path);
113 ACCOUNT_ERROR("Document not parsed successfully. \n");
114 return ACCOUNT_ERROR_XML_PARSE_FAILED;
117 cur = xmlDocGetRootElement(doc);
119 ACCOUNT_ERROR("empty document\n");
121 return ACCOUNT_ERROR_XML_PARSE_FAILED;
124 if (xmlStrcmp(cur->name, (const xmlChar *) "account")) {
125 ACCOUNT_ERROR("document of the wrong type, root node != account");
127 return ACCOUNT_ERROR_XML_PARSE_FAILED;
129 _account_parse_doc(doc, cur, capability_filter, supported);
132 return ACCOUNT_ERROR_NONE;
135 ACCOUNT_API int account_get_application_multiple_account_support(
140 ACCOUNT_ERROR("package_name can not be NULL \n");
141 return ACCOUNT_ERROR_INVALID_PARAMETER;
144 ACCOUNT_ERROR("supported pointer can not be NULL \n");
145 return ACCOUNT_ERROR_INVALID_PARAMETER;
147 char xml_file_path[BUFSIZE] = {0, };
148 xmlDocPtr doc = NULL;
149 xmlNodePtr cur = NULL;
150 xmlChar *attr = NULL;
153 ACCOUNT_MEMSET(xml_file_path, 0, sizeof(xml_file_path));
154 ACCOUNT_SNPRINTF(xml_file_path, BUFSIZE, "%s/%s.account.xml",
155 ACCOUNT_XML_DIR, package_name);
157 ACCOUNT_VERBOSE("xml_file_path = %s \n",xml_file_path);
159 if (!_account_check_file_exists(xml_file_path)) {
160 ACCOUNT_ERROR("XML file not found for %s \n", package_name);
162 /*Check if file exists in /opt directory*/
163 ACCOUNT_MEMSET(xml_file_path, 0, sizeof(xml_file_path));
164 ACCOUNT_SNPRINTF(xml_file_path, BUFSIZE, "%s/%s.account.xml",
165 ACCOUNT_XML_OPT_DIR, package_name);
167 ACCOUNT_VERBOSE("xml_file_path = %s \n",xml_file_path);
169 if (!_account_check_file_exists(xml_file_path)) {
170 ACCOUNT_ERROR("XML file not found for %s \n", package_name);
171 return ACCOUNT_ERROR_XML_FILE_NOT_FOUND;
175 doc = xmlParseFile(xml_file_path);
177 ACCOUNT_ERROR("Document not parsed successfully. \n");
178 return ACCOUNT_ERROR_XML_PARSE_FAILED;
181 cur = xmlDocGetRootElement(doc);
183 ACCOUNT_ERROR("empty document\n");
185 return ACCOUNT_ERROR_XML_PARSE_FAILED;
188 if (xmlStrcmp(cur->name, (const xmlChar *) "account")) {
189 ACCOUNT_ERROR("document of the wrong type, root node != account");
191 return ACCOUNT_ERROR_XML_PARSE_FAILED;
193 attr = xmlGetProp(cur, (const xmlChar *)"multiple");
194 ACCOUNT_INFO("Multiple = %s \n",(char *)attr);
198 else if (!strcmp("false", (char *)attr))
200 else if (!strcmp("true", (char *)attr))
207 return ACCOUNT_ERROR_NONE;
210 ACCOUNT_API int account_get_application_icon_path(const char *package_name,
214 ACCOUNT_ERROR("package_name can not be NULL \n");
215 return ACCOUNT_ERROR_INVALID_PARAMETER;
218 ACCOUNT_ERROR("icon_path pointer can not be NULL \n");
219 return ACCOUNT_ERROR_INVALID_PARAMETER;
221 char xml_file_path[BUFSIZE] = {0, };
222 xmlDocPtr doc = NULL;
223 xmlNodePtr cur = NULL;
224 xmlChar *attr = NULL;
227 ACCOUNT_MEMSET(xml_file_path, 0, sizeof(xml_file_path));
228 ACCOUNT_SNPRINTF(xml_file_path, BUFSIZE, "%s/%s.account.xml",
229 ACCOUNT_XML_DIR, package_name);
231 ACCOUNT_INFO("xml_file_path = %s \n",xml_file_path);
233 if (!_account_check_file_exists(xml_file_path)) {
234 ACCOUNT_ERROR("XML file not found for %s \n", package_name);
236 /*Check if file exists in /opt directory*/
237 ACCOUNT_MEMSET(xml_file_path, 0, sizeof(xml_file_path));
238 ACCOUNT_SNPRINTF(xml_file_path, BUFSIZE, "%s/%s.account.xml",
239 ACCOUNT_XML_OPT_DIR, package_name);
241 ACCOUNT_INFO("xml_file_path = %s \n",xml_file_path);
243 if (!_account_check_file_exists(xml_file_path)) {
244 ACCOUNT_ERROR("XML file not found for %s \n", package_name);
245 return ACCOUNT_ERROR_XML_FILE_NOT_FOUND;
249 doc = xmlParseFile(xml_file_path);
251 ACCOUNT_ERROR("Document not parsed successfully. \n");
252 return ACCOUNT_ERROR_XML_PARSE_FAILED;
255 cur = xmlDocGetRootElement(doc);
257 ACCOUNT_ERROR("empty document\n");
259 return ACCOUNT_ERROR_XML_PARSE_FAILED;
262 if (xmlStrcmp(cur->name, (const xmlChar *) "account")) {
263 ACCOUNT_ERROR("document of the wrong type, root node != account");
265 return ACCOUNT_ERROR_XML_PARSE_FAILED;
267 attr = xmlGetProp(cur, (const xmlChar *)"icon_path");
268 ACCOUNT_DEBUG("icon_path = %s \n",(char *)attr);
273 *icon_path = strdup((char *)attr);
277 return ACCOUNT_ERROR_NONE;
280 static bool __service_iter_func(service_h service, const char* pkg_name,
284 ACCOUNT_ERROR("__service_iter_func: pkg name NULL \n");
287 GList **pkg_list = (GList **)data;
288 char *pkgname = NULL;
289 pkgname = strdup(pkg_name);
290 *pkg_list = g_list_append(*pkg_list, pkgname);
294 ACCOUNT_API int account_query_service_list_by_capability(service_list_cb callback,
295 const char* capability_type,
298 int ret = SERVICE_ERROR_NONE;
299 GList *pkg_list = NULL;
300 service_h service = NULL;
302 char *list_item = NULL;
303 char *capability_filter = NULL;
304 bool supported = false;
305 char *icon_path = NULL;
306 bool multiple = false;
307 int error_code = ACCOUNT_ERROR_NONE;
309 ACCOUNT_RETURN_VAL((capability_type != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CAPABILITY TYPE IS NULL"));
310 ACCOUNT_RETURN_VAL((callback != NULL), {}, ACCOUNT_ERROR_INVALID_PARAMETER, ("CALL BACK IS NULL"));
312 ACCOUNT_VERBOSE("account_query_service_list_by_capability START \n");
313 ret = service_create(&service);
314 if (ret != SERVICE_ERROR_NONE) {
315 ACCOUNT_ERROR("Owner Check : service_create fail ret=%d\n", ret);
318 ACCOUNT_VERBOSE("service_list_by: service_create SUCCESS!!!!!! ret=%d\n", ret);
320 ret = service_set_operation(service, ACCOUNT_OPERATION_SIGNIN);
321 if (ret != SERVICE_ERROR_NONE) {
322 ACCOUNT_ERROR("service_list_by : service_set_operation fail ret=%d\n", ret);
323 service_destroy(service);
326 ACCOUNT_VERBOSE("service_list_by : service_set_operation SUCCESS!!!!!! ret=%d\n",
329 ret = service_foreach_app_matched(service, __service_iter_func, &pkg_list);
330 if (ret != SERVICE_ERROR_NONE) {
331 ACCOUNT_ERROR("service_list_by : service_foreach_app_matched fail ret=%d\n",
333 service_destroy(service);
336 ACCOUNT_VERBOSE("service_list_by : service_foreach_app_matched SUCCESS!!!!!! ret=%d\n",
340 ret = service_destroy(service);
341 if (ret != SERVICE_ERROR_NONE) {
342 ACCOUNT_ERROR("service_list_by : service_destroy fail ret=%d\n", ret);
343 for (iter = pkg_list; iter != NULL; iter = g_list_next(iter)) {
344 list_item = (char *)iter->data;
347 g_list_free(pkg_list);
350 ACCOUNT_VERBOSE("service_list_by : service_destroy SUCCESS!!!!!! ret=%d\n", ret);
353 capability_filter = strdup(capability_type);
355 for (iter = pkg_list; iter != NULL; iter = g_list_next(iter)) {
356 list_item = (char *)iter->data;
357 error_code = account_get_application_capability_support(list_item,
361 if ((error_code != ACCOUNT_ERROR_NONE)
362 && (error_code != ACCOUNT_ERROR_XML_FILE_NOT_FOUND)) {
363 ACCOUNT_ERROR("service_list_by : account_get_application_capability_support fail error_code=%d\n", error_code);
364 for (iter = pkg_list; iter != NULL; iter = g_list_next(iter)) {
365 list_item = (char *)iter->data;
368 g_list_free(pkg_list);
369 _ACCOUNT_FREE(capability_filter);
374 error_code = account_get_application_icon_path(list_item, &icon_path);
375 if (error_code != ACCOUNT_ERROR_NONE) {
376 ACCOUNT_ERROR("service_list_by : account_get_application_capability_support fail error_code=%d\n", error_code);
377 for (iter = pkg_list; iter != NULL; iter = g_list_next(iter)) {
378 list_item = (char *)iter->data;
381 g_list_free(pkg_list);
382 _ACCOUNT_FREE(capability_filter);
385 error_code = account_get_application_multiple_account_support(list_item, &multiple);
386 if (error_code != ACCOUNT_ERROR_NONE) {
387 ACCOUNT_ERROR("service_list_by : account_get_application_capability_support fail error_code=%d\n", error_code);
388 for (iter = pkg_list; iter != NULL; iter = g_list_next(iter)) {
389 list_item = (char *)iter->data;
392 g_list_free(pkg_list);
393 _ACCOUNT_FREE(capability_filter);
396 callback(list_item, icon_path, multiple, user_data);
400 for (iter = pkg_list; iter != NULL; iter = g_list_next(iter)) {
401 list_item = (char *)iter->data;
404 g_list_free(pkg_list);
405 _ACCOUNT_FREE(capability_filter);
406 return ACCOUNT_ERROR_NONE;