2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @file AccountWrapper.cpp
19 * @author Jihwa Park (jh7979.park@samsung.com)
27 #include <dpl/log/log.h>
28 #include <Commons/Exception.h>
29 #include "AccountWrapper.h"
30 //#include "AccountService.h"
35 using namespace TizenApis::Api::Account;
36 using namespace WrtDeviceApis::Commons;
37 //using namespace WrtDeviceApis::CommonsJavaScript;
41 #define _QUERY_DB_NAME "/opt/dbspace/.test-accounts.db"
42 #define _QUERY_SQL_STRING_LEN 4096 //short sql string length
43 #define _USER_ACCOUNT_TABLE_NAME "user_account"
44 #define _SERVICES_TABLE_NAME "service"
45 #define _SERVICETYPE_TABLE_NAME "service_type"
46 #define _PROVIDER_LIST_TABLE_NAME "provider_list"
47 #define _TAGS_MIME_TABLE_NAME "tags_mime"
48 #define _RELATION_TABLE_NAME "relation"
49 #define _REL_PROVIDER_TABLE_NAME "provider_to_svctype"
51 #define QUERY_MAX_LEN 4096
52 #define SUB_QUERY_LEN 2048
55 static sqlite3 *test_hDBCt;
56 typedef sqlite3_stmt* stmt;
58 #define __USER_ACCOUNT_SCHEMA "create table %s \n"\
60 "user_id INTEGER PRIMARY KEY AUTOINCREMENT, "\
64 "enable INTEGER DEFAULT 0, "\
65 "credential_id REAL, "\
72 #define __SERVICE_SCHEMA "create table %s \n"\
74 "_svc_id INTEGER PRIMARY KEY AUTOINCREMENT, "\
76 "service_name TEXT, "\
77 "application_id TEXT, "\
78 "display_name TEXT, "\
80 "serviceType_id TEXT, "\
83 "enable INTEGER DEFAULT 0"\
86 #define __SERVICETYPE_SCHEMA "create table %s \n"\
88 "type_id INTEGER PRIMARY KEY AUTOINCREMENT, "\
89 "serviceType_id TEXT, "\
90 "display_name TEXT, "\
94 #define __TAGS_MIMETYPE_SCHEMA "create table %s \n"\
96 "tags_id INTEGER PRIMARY KEY AUTOINCREMENT, "\
100 #define __RELATION_SCHEMA "create table %s \n"\
102 "relation_id INTEGER PRIMARY KEY AUTOINCREMENT, "\
109 #define __REL_PROVIDER_SCHEMA "create table %s \n"\
111 "_id INTEGER PRIMARY KEY AUTOINCREMENT, "\
112 "_list_id INTEGER, "\
116 #define __PROVIDER_LIST_SCHEMA "create table %s \n"\
118 "_list_id INTEGER PRIMARY KEY AUTOINCREMENT, "\
119 "provider_id TEXT, "\
120 "display_name TEXT, "\
124 stmt __query_prepare(char *query) {
128 printf("!! query : %s \n", query);
130 rc = sqlite3_prepare_v2(test_hDBCt, query, strlen(query), &pStmt, NULL);
132 if (SQLITE_OK != rc) {
139 int _query_exec(char *query) {
141 char* pszErrorMsg = NULL;
143 rc = sqlite3_exec(test_hDBCt, query, NULL, NULL, &pszErrorMsg);
144 if (SQLITE_OK != rc) {
145 sqlite3_free(pszErrorMsg);
151 int _query_column_int(stmt pStmt, int pos)
153 return sqlite3_column_int(pStmt, pos);
156 char* _query_column_text(stmt pStmt, int pos)
158 return (char *)sqlite3_column_text(pStmt, pos);
161 double _query_column_double(stmt pStmt, int pos)
163 return sqlite3_column_double(pStmt, pos);
167 _create_all_tables(void)
171 char query[_QUERY_SQL_STRING_LEN + 1] = { 0, };
175 memset(query, 0, sizeof(query));
176 snprintf(query, sizeof(query) - 1, __USER_ACCOUNT_SCHEMA, _USER_ACCOUNT_TABLE_NAME);
177 rc = _query_exec(query);
179 memset(query, 0, sizeof(query));
180 snprintf(query, sizeof(query) - 1, __SERVICE_SCHEMA, _SERVICES_TABLE_NAME);
181 rc = _query_exec(query);
183 memset(query, 0, sizeof(query));
184 snprintf(query, sizeof(query) - 1, __SERVICETYPE_SCHEMA, _SERVICETYPE_TABLE_NAME);
185 rc = _query_exec(query);
187 memset(query, 0, sizeof(query));
188 snprintf(query, sizeof(query) - 1, __TAGS_MIMETYPE_SCHEMA, _TAGS_MIME_TABLE_NAME);
189 rc = _query_exec(query);
191 memset(query, 0, sizeof(query));
192 snprintf(query, sizeof(query) - 1, __RELATION_SCHEMA, _RELATION_TABLE_NAME);
193 rc = _query_exec(query);
195 memset(query, 0, sizeof(query));
196 snprintf(query, sizeof(query) - 1, __REL_PROVIDER_SCHEMA, _REL_PROVIDER_TABLE_NAME);
197 rc = _query_exec(query);
199 memset(query, 0, sizeof(query));
200 snprintf(query, sizeof(query) - 1, __PROVIDER_LIST_SCHEMA, _PROVIDER_LIST_TABLE_NAME);
201 rc = _query_exec(query);
208 int _query_bind_text(stmt pStmt, int pos, char* str)
213 return sqlite3_bind_text(pStmt, pos, (const char*) str, len, SQLITE_STATIC);
218 int _query_step(stmt pStmt) {
219 return sqlite3_step(pStmt);
222 void _query_finalize(stmt pStmt) {
228 rc = sqlite3_finalize(pStmt);
229 if (rc != SQLITE_OK) {
234 int _query_bind_int(stmt pStmt, int pos, int num) {
235 return sqlite3_bind_int(pStmt, pos, num);
238 void insert_dummy_data()
241 char query[_QUERY_SQL_STRING_LEN + 1] = {0,};
245 _create_all_tables();
247 // insert to tag_name to tag_mime table
248 memset(query, 0x00, sizeof(query));
249 sprintf(query, "insert into %s(tag_name) values (?) ", _TAGS_MIME_TABLE_NAME);
251 const char* tag_name[] =
262 for(i = 0; i < 7; i++)
264 hstmt = __query_prepare(query);
266 _query_bind_text(hstmt, 1, (char*)tag_name[i]);
267 rc = _query_step(hstmt);
268 if(rc != SQLITE_DONE)
270 printf("\n !! rc : %d \n", rc);
273 _query_finalize(hstmt);
277 // rc = sqlite3_exec(test_hDBCt, "BEGIN IMMEDIATE TRANSACTION", NULL, NULL, &pszErrorMsg);
279 // insert to _USER_ACCOUNT_TABLE_NAME
280 memset(query, 0x00, sizeof(query));
281 sprintf(query, "insert into %s(displayname, icon, account_id, provider_id, login_id) values "
282 "(?, ?, ?, ?, ?) ", _USER_ACCOUNT_TABLE_NAME);
284 const char* displayname[] =
286 "Jamie's google account",
287 "William's facebook account",
288 "Craig's twitter account",
294 "/opt/icon/image1.jpg",
296 "/opt/icon/image1.jpg",
297 "/opt/icon/image2.jpg"
300 const char* account_id[] =
302 "com.google:Jamie@gmail.com",
303 "com.facebook:William@facebook.com",
304 "com.twitter:Craig@twitter.com",
305 "com.custom:Lucille@gmail.com"
308 const char* provider_id[] =
316 const char* login_id[] =
319 "William@facebook.com",
324 for(i = 0; i < 4; i++)
326 hstmt = __query_prepare(query);
328 _query_bind_text(hstmt, 1, (char*)displayname[i]);
329 _query_bind_text(hstmt, 2, (char*)icon[i]);
330 _query_bind_text(hstmt, 3, (char*)account_id[i]);
331 _query_bind_text(hstmt, 4, (char*)provider_id[i]);
332 _query_bind_text(hstmt, 5, (char*)login_id[i]);
334 rc = _query_step(hstmt);
335 if(rc != SQLITE_DONE)
337 printf("\n !! rc : %d \n", rc);
340 _query_finalize(hstmt);
344 // insert to _SERVICETYPE_TABLE_NAME
345 memset(query, 0x00, sizeof(query));
346 sprintf(query, "insert into %s(serviceType_id, display_name) values (?, ?) ", _SERVICETYPE_TABLE_NAME);
348 const char* service_type_id[] =
355 const char* service_type_display_name[] =
362 for(i = 0; i < 3; i++)
364 hstmt = __query_prepare(query);
365 _query_bind_text(hstmt, 1, (char*)service_type_id[i]);
366 _query_bind_text(hstmt, 2, (char*)service_type_display_name[i]);
368 rc = _query_step(hstmt);
369 if(rc != SQLITE_DONE)
371 printf("\n !! rc : %d \n", rc);
374 _query_finalize(hstmt);
378 // insert to _SERVICE_TABLE_NAME
379 memset(query, 0x00, sizeof(query));
380 sprintf(query, "insert into %s(service_id, provider_id, serviceType_id, service_name, display_name) values "
381 "(?, ?, ?, ?, ?) ", _SERVICES_TABLE_NAME);
383 const char* service_id[] =
385 "com.google.gmail:Jamie@gmail.com",
386 "com.google.gtalk:Jamie@gmail.com",
387 "com.google.picasa:Jamie@gmail.com",
388 "com.facebook.facebook:William@facebook.com",
389 "com.twitter.twitter:Craig@twitter.com",
390 "com.custom.custom:Lucille@gmail.com",
393 const char* service_name[] =
398 "com.facebook.facebook",
399 "com.twitter.twitter",
403 const char* service_display_name[] =
408 "facebook's service",
410 "custom's new service",
413 for(i = 0; i < 6; i++)
415 hstmt = __query_prepare(query);
417 _query_bind_text(hstmt, 1, (char*)service_id[i]);
421 _query_bind_text(hstmt, 2, (char*)provider_id[0]);
422 _query_bind_text(hstmt, 3, (char*)service_type_id[i]);
425 _query_bind_text(hstmt, 2, (char*)provider_id[i-2]);
426 _query_bind_text(hstmt, 3, (char*)service_type_id[2]);
429 _query_bind_text(hstmt, 4, (char*)service_name[i]);
430 _query_bind_text(hstmt, 5, (char*)service_display_name[i]);
432 rc = _query_step(hstmt);
433 if(rc != SQLITE_DONE)
435 printf("\n !! rc : %d \n", rc);
438 _query_finalize(hstmt);
442 // insert to _PROVIDER_LIST_TABLE_NAME
443 memset(query, 0x00, sizeof(query));
444 sprintf(query, "insert into %s(provider_id, display_name) values (?, ?) ", _PROVIDER_LIST_TABLE_NAME);
446 const char* provider_display_name[] =
448 "provider:com.google",
449 "provider:com.facebook",
450 "provider:com.twitter",
451 "provider:com.custom",
454 for(i = 0; i < 4; i++)
456 hstmt = __query_prepare(query);
458 _query_bind_text(hstmt, 1, (char*)provider_id[i]);
459 _query_bind_text(hstmt, 2, (char*)provider_display_name[i]);
461 rc = _query_step(hstmt);
462 if(rc != SQLITE_DONE)
464 printf("\n !! rc : %d \n", rc);
467 _query_finalize(hstmt);
471 // insert to _RELATION_TABLE_NAME
472 memset(query, 0x00, sizeof(query));
473 sprintf(query, "insert into %s(tags_id, _svc_id, type_id, tag_name) values (?, ?, ?, ?) ", _RELATION_TABLE_NAME);
475 hstmt = __query_prepare(query);
477 _query_bind_int(hstmt, 1, 2);
478 _query_bind_int(hstmt, 2, 1);
479 _query_bind_int(hstmt, 3, 0);
480 _query_bind_text(hstmt, 4, (char*)tag_name[1]);
482 rc = _query_step(hstmt);
483 if(rc != SQLITE_DONE)
484 printf("\n !! rc : %d \n", rc);
485 _query_finalize(hstmt);
488 hstmt = __query_prepare(query);
489 _query_bind_int(hstmt, 1, 5);
490 _query_bind_int(hstmt, 2, 2);
491 _query_bind_int(hstmt, 3, 0);
492 _query_bind_text(hstmt, 4, (char*)tag_name[4]);
494 rc = _query_step(hstmt);
495 if(rc != SQLITE_DONE)
496 printf("\n !! rc : %d \n", rc);
497 _query_finalize(hstmt);
500 hstmt = __query_prepare(query);
501 _query_bind_int(hstmt, 1, 7);
502 _query_bind_int(hstmt, 2, 3);
503 _query_bind_int(hstmt, 3, 0);
504 _query_bind_text(hstmt, 4, (char*)tag_name[6]);
506 rc = _query_step(hstmt);
507 if(rc != SQLITE_DONE)
508 printf("\n !! rc : %d \n", rc);
509 _query_finalize(hstmt);
512 hstmt = __query_prepare(query);
514 _query_bind_int(hstmt, 1, 7);
515 _query_bind_int(hstmt, 2, 4);
516 _query_bind_int(hstmt, 3, 0);
517 _query_bind_text(hstmt, 4, (char*)tag_name[6]);
519 rc = _query_step(hstmt);
520 if(rc != SQLITE_DONE)
521 printf("\n !! rc : %d \n", rc);
522 _query_finalize(hstmt);
525 hstmt = __query_prepare(query);
527 _query_bind_int(hstmt, 1, 7);
528 _query_bind_int(hstmt, 2, 5);
529 _query_bind_int(hstmt, 3, 0);
530 _query_bind_text(hstmt, 4, (char*)tag_name[6]);
532 rc = _query_step(hstmt);
533 if(rc != SQLITE_DONE)
534 printf("\n !! rc : %d \n", rc);
535 _query_finalize(hstmt);
538 hstmt = __query_prepare(query);
540 _query_bind_int(hstmt, 1, 7);
541 _query_bind_int(hstmt, 2, 6);
542 _query_bind_int(hstmt, 3, 0);
543 _query_bind_text(hstmt, 4, (char*)tag_name[6]);
545 rc = _query_step(hstmt);
546 if(rc != SQLITE_DONE)
547 printf("\n !! rc : %d \n", rc);
548 _query_finalize(hstmt);
551 hstmt = __query_prepare(query);
553 _query_bind_int(hstmt, 1, 1);
554 _query_bind_int(hstmt, 2, 0);
555 _query_bind_int(hstmt, 3, 1);
556 _query_bind_text(hstmt, 4, (char*)tag_name[0]);
558 rc = _query_step(hstmt);
559 if(rc != SQLITE_DONE)
560 printf("\n !! rc : %d \n", rc);
561 _query_finalize(hstmt);
564 hstmt = __query_prepare(query);
566 _query_bind_int(hstmt, 1, 3);
567 _query_bind_int(hstmt, 2, 0);
568 _query_bind_int(hstmt, 3, 1);
569 _query_bind_text(hstmt, 4, (char*)tag_name[2]);
571 rc = _query_step(hstmt);
572 if(rc != SQLITE_DONE)
573 printf("\n !! rc : %d \n", rc);
574 _query_finalize(hstmt);
577 hstmt = __query_prepare(query);
579 _query_bind_int(hstmt, 1, 4);
580 _query_bind_int(hstmt, 2, 0);
581 _query_bind_int(hstmt, 3, 1);
582 _query_bind_text(hstmt, 4, (char*)tag_name[3]);
584 rc = _query_step(hstmt);
585 if(rc != SQLITE_DONE)
586 printf("\n !! rc : %d \n", rc);
587 _query_finalize(hstmt);
590 hstmt = __query_prepare(query);
592 _query_bind_int(hstmt, 1, 1);
593 _query_bind_int(hstmt, 2, 0);
594 _query_bind_int(hstmt, 3, 2);
595 _query_bind_text(hstmt, 4, (char*)tag_name[0]);
597 rc = _query_step(hstmt);
598 if(rc != SQLITE_DONE)
599 printf("\n !! rc : %d \n", rc);
600 _query_finalize(hstmt);
603 hstmt = __query_prepare(query);
605 _query_bind_int(hstmt, 1, 4);
606 _query_bind_int(hstmt, 2, 0);
607 _query_bind_int(hstmt, 3, 2);
608 _query_bind_text(hstmt, 4, (char*)tag_name[3]);
610 rc = _query_step(hstmt);
611 if(rc != SQLITE_DONE)
612 printf("\n !! rc : %d \n", rc);
613 _query_finalize(hstmt);
616 hstmt = __query_prepare(query);
618 _query_bind_int(hstmt, 1, 5);
619 _query_bind_int(hstmt, 2, 0);
620 _query_bind_int(hstmt, 3, 3);
621 _query_bind_text(hstmt, 4, (char*)tag_name[4]);
623 rc = _query_step(hstmt);
624 if(rc != SQLITE_DONE)
625 printf("\n !! rc : %d \n", rc);
626 _query_finalize(hstmt);
629 hstmt = __query_prepare(query);
631 _query_bind_int(hstmt, 1, 6);
632 _query_bind_int(hstmt, 2, 0);
633 _query_bind_int(hstmt, 3, 3);
634 _query_bind_text(hstmt, 4, (char*)tag_name[5]);
636 rc = _query_step(hstmt);
637 if(rc != SQLITE_DONE)
638 printf("\n !! rc : %d \n", rc);
639 _query_finalize(hstmt);
642 // insert to _REL_PROVIDER_TABLE_NAME
643 memset(query, 0x00, sizeof(query));
644 sprintf(query, "insert into %s(_list_id, type_id) values (?, ?) ", _REL_PROVIDER_TABLE_NAME);
646 for(i = 0; i < 6; i++)
648 hstmt = __query_prepare(query);
652 _query_bind_int(hstmt, 1, 1);
653 _query_bind_int(hstmt, 2, i+1);
656 _query_bind_int(hstmt, 1, i-1);
657 _query_bind_int(hstmt, 2, 3);
660 rc = _query_step(hstmt);
661 if(rc != SQLITE_DONE)
663 printf("\n !! rc : %d \n", rc);
666 _query_finalize(hstmt);
669 // rc = sqlite3_exec(test_hDBCt, "COMMIT TRANSACTION", NULL, NULL, &pszErrorMsg);
696 char* AccountServiceTypeId;
699 GList* tags_info; // tags_info_t
700 }AccountServiceType_t;
704 char* AccountServiceId;
710 char* AccountServiceTypeId;
711 char* AccountServiceProviderId;
713 GList* tags_info; // tags_info_t
719 char* AccountServiceProviderId;
730 UserAccount_t user_account = {0, };
731 UserProperties_t property = {0, };
732 AccountServiceType_t serviceType = {0, };
733 provider_t provider = {0, };
735 int check_provider_activate(char* providerId, int* activate, char** package_name)
739 char query[QUERY_MAX_LEN + 1] = {0, };
741 snprintf(query, sizeof(query) - 1, "select package_name, activate from provider_list where provider_id = ? ");
743 stmt hstmt = __query_prepare(query);
745 _query_bind_text(hstmt, 1, providerId);
747 rc = _query_step(hstmt);
750 *package_name = g_strdup(_query_column_text(hstmt, 0));
751 *activate = _query_column_int(hstmt, 1);
752 rc = _query_step(hstmt);
755 _query_finalize(hstmt);
759 int _add_platform_to_web()
762 // update provider_list table
764 // update user_account table
768 int addAccount(char* providerId, UserProperties_t* properties, UserAccount_t* account)
772 char query[QUERY_MAX_LEN + 1] = {0, };
774 snprintf(query, sizeof(query) - 1, "insert into user_account(display_name, icon, provider_id) value (?, ?, ?)");
776 stmt hstmt = __query_prepare(query);
778 _query_bind_text(hstmt, 1, properties->displayName);
779 _query_bind_text(hstmt, 2, properties->icon);
780 _query_bind_text(hstmt, 3, providerId);
782 rc = _query_step(hstmt);
783 if(rc != SQLITE_DONE)
788 _query_finalize(hstmt);
800 filter_e filter_type;
804 int set_account_filter(search_list_t* search_list, filter_e filter_type, const char* value)
806 if(value == NULL || value[0] == '\0')
808 printf("value is null \n");
811 printf("value : %s \n", value);
813 filter_value_t* object = NULL;
814 object = g_new0(filter_value_t, 1);
816 object->filter_type = filter_type;
817 object->value = g_strdup(value);
818 if (filter_type == TAGS)
819 search_list->tags_count++;
820 search_list->filter_list = g_list_append(search_list->filter_list, object);
825 const static char* filter_attribute[FILTER_ATTRIBUTE_MAX] =
833 USE_FILTER_NONE = 0x00000000, USE_SERVICE_TYPE_ID = 0x00000001, USE_TAGS = 0x00000002, USE_PROVIDER_ID = 0x00000004
837 TAG_SERVICE, TAG_SERVICE_TYPE
841 FIND_ACCOUNT, FIND_SERVICE
844 void _get_tags(tags_owner owner, int id, GList** tags_list)
847 char query[QUERY_MAX_LEN + 1] = { 0, };
851 snprintf(query, sizeof(query) - 1, "select tag_name from relation where _svc_id = %d", id);
853 case TAG_SERVICE_TYPE:
854 snprintf(query, sizeof(query) - 1, "select tag_name from relation where type_id = %d", id);
859 stmt hstmt = __query_prepare(query);
861 rc = _query_step(hstmt);
862 while (rc == SQLITE_ROW) {
863 tags_info_t* tag_info = NULL;
864 tag_info = g_new0(tags_info_t, 1);
865 tag_info->tag_info = g_strdup(_query_column_text(hstmt, 0));
867 *tags_list = g_list_append(*tags_list, tag_info);
868 rc = _query_step(hstmt);
870 _query_finalize(hstmt);
873 char* _make_condition_part(search_list_t* search_list, query_type_e type) {
875 char tmp_query[SUB_QUERY_LEN + 1] = { 0, };
876 char pre_query[TABLE_LEN + 1] = { 0, };
877 char table[TABLE_LEN + 1] = { 0, };
878 used_filter_attr use_filter = USE_FILTER_NONE;
879 int filter_count = 0;
882 query = g_new0(char, QUERY_MAX_LEN);
884 if (type == FIND_ACCOUNT)
885 snprintf(pre_query, sizeof(pre_query) - 1, "where user_account.provider_id in (select a.provider_id from service a ");
887 snprintf(pre_query, sizeof(pre_query) - 1, "where service._svc_id in (select a._svc_id from service a ");
889 GList* tmp_filter_list = search_list->filter_list;
890 while (tmp_filter_list) {
891 filter_value_t* object = (filter_value_t*) tmp_filter_list->data;
893 if (object->value != NULL) {
894 if (object->filter_type == SERVICE_TYPE_ID) {
895 use_filter = (used_filter_attr) (use_filter | USE_SERVICE_TYPE_ID);
897 if (tmp_query[0] == '\0')
898 sprintf(tmp_query, "a.%s = ? ", filter_attribute[object->filter_type]);
900 sprintf(tmp_query, "and %s a.%s = ? ", tmp_query, filter_attribute[object->filter_type]);
902 } else if (object->filter_type == TAGS) {
903 use_filter = (used_filter_attr) (use_filter | USE_TAGS);
906 if (tags_count == 1) {
907 if (table[0] == '\0')
908 sprintf(table, ", relation b ");
910 sprintf(table, "%s, relation b ", table);
912 if (tmp_query[0] == '\0') {
913 if (search_list->tags_count > 1)
914 sprintf(tmp_query, "(a._svc_id = b._svc_id) and (b.%s = ? ", filter_attribute[object->filter_type]);
916 sprintf(tmp_query, "(a._svc_id = b._svc_id) and b.%s = ? ", filter_attribute[object->filter_type]);
918 if (search_list->tags_count > 1)
919 sprintf(tmp_query, "%s and (a._svc_id = b._svc_id) and (b.%s = ? ", tmp_query, filter_attribute[object->filter_type]);
921 sprintf(tmp_query, "%s and (a._svc_id = b._svc_id) and b.%s = ? ", tmp_query, filter_attribute[object->filter_type]);
924 sprintf(tmp_query, "%s or b.%s = ? ", tmp_query, filter_attribute[object->filter_type]);
925 if (search_list->tags_count > 1 && search_list->tags_count == tags_count)
926 sprintf(tmp_query, "%s) ", tmp_query);
928 } else if (object->filter_type == PROVIDER_ID) {
929 use_filter = (used_filter_attr) (use_filter | USE_PROVIDER_ID);
931 if (tmp_query[0] == '\0')
932 sprintf(tmp_query, "a.%s = ? ", filter_attribute[object->filter_type]);
934 sprintf(tmp_query, "%s and a.%s = ? ", tmp_query, filter_attribute[object->filter_type]);
938 tmp_filter_list = g_list_next(tmp_filter_list);
941 if (table[0] != '\0')
942 snprintf(query, QUERY_MAX_LEN, "%s %s where %s)", pre_query, table, tmp_query);
944 snprintf(query, QUERY_MAX_LEN, "%s where %s)", pre_query, tmp_query);
946 if (type == FIND_ACCOUNT) {
947 if ((use_filter | USE_PROVIDER_ID) == USE_PROVIDER_ID && filter_count == 1) {
948 memset(query, 0x00, QUERY_MAX_LEN);
949 snprintf(query, QUERY_MAX_LEN, "where user_account.provider_id = ? ");
950 } else if ((use_filter | USE_SERVICE_TYPE_ID) == USE_SERVICE_TYPE_ID && filter_count == 1) {
951 memset(query, 0x00, QUERY_MAX_LEN);
952 snprintf(query, QUERY_MAX_LEN, ",service where (user_account.provider_id = service.provider_id) and service.serviceType_id = ? ");
955 if ((use_filter | USE_PROVIDER_ID) == USE_PROVIDER_ID && filter_count == 1) {
956 memset(query, 0x00, QUERY_MAX_LEN);
957 snprintf(query, QUERY_MAX_LEN, ",user_account where (user_account.provider_id = service.provider_id) and user_account.provider_id = ? ");
958 }else if((use_filter | USE_SERVICE_TYPE_ID) == USE_SERVICE_TYPE_ID && filter_count == 1)
960 memset(query, 0x00, QUERY_MAX_LEN);
961 snprintf(query, QUERY_MAX_LEN, " where service.serviceType_id = ? ");
965 if (filter_count == 0)
971 void _get_service_list_by_account(char* provider_id, GList** service_list) {
974 char query[QUERY_MAX_LEN + 1] = { 0, };
976 snprintf(query, sizeof(query) - 1, "select service_id, service_name, application_id, display_name, icon, serviceType_id, provider_id, setting, enable, _svc_id "
977 "from %s where provider_id = ?", _SERVICES_TABLE_NAME);
979 stmt hstmt = __query_prepare(query);
981 _query_bind_text(hstmt, 1, provider_id);
983 rc = _query_step(hstmt);
984 while (rc == SQLITE_ROW) {
985 AccountService_t* service_info = NULL;
986 service_info = g_new0(AccountService_t, 1);
988 service_info->AccountServiceId = g_strdup(_query_column_text(hstmt, 0));
989 service_info->serviceName = g_strdup(_query_column_text(hstmt, 1));
990 service_info->applicationId = g_strdup(_query_column_text(hstmt, 2));
991 service_info->displayName = g_strdup(_query_column_text(hstmt, 3));
992 service_info->icon = g_strdup(_query_column_text(hstmt, 4));
993 service_info->AccountServiceTypeId = g_strdup(_query_column_text(hstmt, 5));
994 service_info->AccountServiceProviderId = g_strdup(_query_column_text(hstmt, 6));
995 service_info->setting = g_strdup(_query_column_text(hstmt, 7));
996 service_info->enabled = _query_column_int(hstmt, 8);
997 id = _query_column_int(hstmt, 9);
999 _get_tags(TAG_SERVICE, id, &(service_info->tags_info));
1001 *service_list = g_list_append(*service_list, service_info);
1002 rc = _query_step(hstmt);
1004 _query_finalize(hstmt);
1007 void _make_account_info(int user_id, UserAccount_t* account_info) {
1008 char query[QUERY_MAX_LEN + 1] = { 0, };
1012 snprintf(query, sizeof(query) - 1, "select displayname, icon, account_id, enable, credential_id, settings, provider_id "
1013 "from %s where user_id = %d", _USER_ACCOUNT_TABLE_NAME, user_id);
1015 stmt hstmt = __query_prepare(query);
1017 rc = _query_step(hstmt);
1018 account_info->displayName = g_strdup(_query_column_text(hstmt, 0));
1019 account_info->icon = g_strdup(_query_column_text(hstmt, 1));
1020 account_info->AccountId = g_strdup(_query_column_text(hstmt, 2));
1021 account_info->enabled = _query_column_int(hstmt, 3);
1022 account_info->credentialId = _query_column_double(hstmt, 4);
1023 account_info->settings = g_strdup(_query_column_text(hstmt, 5));
1024 account_info->AccountServiceProviderId = g_strdup(_query_column_text(hstmt, 6));
1026 _query_finalize(hstmt);
1030 _get_service_list_by_account(account_info->AccountServiceProviderId, &(account_info->services));
1033 void _make_service_info(int id, AccountService_t* service_info) {
1034 char query[QUERY_MAX_LEN + 1] = { 0, };
1039 snprintf(query, sizeof(query) - 1, "select service_id, service_name, application_id, display_name, icon, serviceType_id, provider_id, setting, enable "
1040 "from %s where _svc_id = %d", _SERVICES_TABLE_NAME, id);
1042 hstmt = __query_prepare(query);
1044 rc = _query_step(hstmt);
1045 service_info->AccountServiceId = g_strdup(_query_column_text(hstmt, 0));
1046 service_info->serviceName = g_strdup(_query_column_text(hstmt, 1));
1047 service_info->applicationId = g_strdup(_query_column_text(hstmt, 2));
1048 service_info->displayName = g_strdup(_query_column_text(hstmt, 3));
1049 service_info->icon = g_strdup(_query_column_text(hstmt, 4));
1050 service_info->AccountServiceTypeId = g_strdup(_query_column_text(hstmt, 5));
1051 service_info->AccountServiceProviderId = g_strdup(_query_column_text(hstmt, 6));
1052 service_info->setting = g_strdup(_query_column_text(hstmt, 7));
1053 service_info->enabled = _query_column_int(hstmt, 8);
1055 _query_finalize(hstmt);
1059 snprintf(query, sizeof(query) - 1, "select account_id from %s where provider_id = %s", _USER_ACCOUNT_TABLE_NAME, service_info->AccountServiceProviderId);
1061 hstmt = __query_prepare(query);
1063 rc = _query_step(hstmt);
1064 service_info->AccountId = g_strdup(_query_column_text(hstmt, 0));
1066 _query_finalize(hstmt);
1070 _get_tags(TAG_SERVICE, id, &(service_info->tags_info));
1074 int find_accounts(search_list_t* search_list, status_e status, GList** account_list) {
1076 char query[QUERY_MAX_LEN + 1] = { 0, };
1078 int index_list[SUB_QUERY_LEN + 1] = { 0, };
1079 int index_count = 0;
1083 char* filter = _make_condition_part(search_list, FIND_ACCOUNT);
1090 snprintf(query, sizeof(query) - 1, "select distinct(user_account.user_id) from user_account %s and user_account.enable = 1", filter);
1092 snprintf(query, sizeof(query) - 1, "select distinct(user_account.user_id) from user_account where user_account.enable = 1");
1098 snprintf(query, sizeof(query) - 1, "select distinct(user_account.user_id) from user_account %s and user_account.enable = 0", filter);
1100 snprintf(query, sizeof(query) - 1, "select distinct(user_account.user_id) from user_account where user_account.enable = 0");
1107 snprintf(query, sizeof(query) - 1, "select distinct(user_account.user_id) from user_account %s", filter);
1109 snprintf(query, sizeof(query) - 1, "select distinct(user_account.user_id) from user_account");
1114 hstmt = __query_prepare(query);
1116 GList* filter_list_val = search_list->filter_list;
1117 while (filter_list_val) {
1118 filter_value_t* object = (filter_value_t*) filter_list_val->data;
1120 if (object->value != NULL)
1121 _query_bind_text(hstmt, i++, object->value);
1122 filter_list_val = g_list_next(filter_list_val);
1125 rc = _query_step(hstmt);
1127 while (rc == SQLITE_ROW) {
1128 ret = _query_column_int(hstmt, 0);
1129 index_list[index_count++] = ret;
1130 rc = _query_step(hstmt);
1133 _query_finalize(hstmt);
1135 // make account object by index_list
1136 for (i = 0; i < index_count; i++) {
1138 UserAccount_t* account_info = NULL;
1139 account_info = g_new0(UserAccount_t, 1);
1140 _make_account_info(index_list[i], account_info);
1142 // Generate account list
1143 *account_list = g_list_append(*account_list, account_info);
1152 int find_services(search_list_t* search_list, status_e status, GList** service_list) {
1154 char query[QUERY_MAX_LEN + 1] = { 0, };
1156 int index_list[SUB_QUERY_LEN + 1] = { 0, };
1157 int index_count = 0;
1160 char* filter = _make_condition_part(search_list, FIND_SERVICE);
1167 snprintf(query, sizeof(query) - 1, "select distinct(service._svc_id) from service %s and service.enable = 1", filter);
1169 snprintf(query, sizeof(query) - 1, "select distinct(service._svc_id) from service where service.enable = 1");
1175 snprintf(query, sizeof(query) - 1, "select distinct(service._svc_id) from service %s and service.enable = 0", filter);
1177 snprintf(query, sizeof(query) - 1, "select distinct(service._svc_id) from service where service.enable = 0");
1184 snprintf(query, sizeof(query) - 1, "select distinct(service._svc_id) from service %s", filter);
1186 snprintf(query, sizeof(query) - 1, "select distinct(service._svc_id) from service");
1191 stmt hstmt = __query_prepare(query);
1193 GList* filter_list_val = search_list->filter_list;
1194 while (filter_list_val) {
1195 filter_value_t* object = (filter_value_t*) filter_list_val->data;
1197 if (object->value != NULL)
1198 _query_bind_text(hstmt, i++, object->value);
1200 filter_list_val = g_list_next(filter_list_val);
1203 rc = _query_step(hstmt);
1204 while (rc == SQLITE_ROW) {
1205 index_list[index_count++] = _query_column_int(hstmt, 0);
1206 rc = _query_step(hstmt);
1209 _query_finalize(hstmt);
1211 for (i = 0; i < index_count; i++) {
1213 AccountService_t* service_info = NULL;
1214 service_info = g_new0(AccountService_t, 1);
1215 _make_service_info(index_list[i], service_info);
1217 // Generate service list
1218 *service_list = g_list_append(*service_list, service_info);
1227 int find_providers(char* serviceTypeId, GList** provider_list)
1231 char query[QUERY_MAX_LEN + 1] = { 0, };
1232 char sub_query[SUB_QUERY_LEN + 1] = { 0, };
1234 if (serviceTypeId == NULL) {
1235 snprintf(query, sizeof(query) - 1, "select provider_id, display_name, icon from provider_list");
1237 snprintf(sub_query, sizeof(sub_query) - 1, "select type_id from service_type where serviceType_id = ?");
1238 snprintf(query, sizeof(query) - 1, "select a.provider_id, a.display_name, a.icon from provider_list a, provider_to_svctype b "
1239 "where (a._list_id = b._list_id) and b.type_id in (%s) ", sub_query);
1242 stmt hstmt = __query_prepare(query);
1244 if(serviceTypeId != NULL)
1245 _query_bind_text(hstmt, 1, serviceTypeId);
1247 rc = _query_step(hstmt);
1248 while (rc == SQLITE_ROW) {
1249 provider_t* provider = NULL;
1250 provider = g_new0(provider_t, 1);
1251 provider->AccountServiceProviderId = g_strdup(_query_column_text(hstmt, 0));
1252 provider->displayName = g_strdup(_query_column_text(hstmt, 1));
1253 provider->icon = g_strdup(_query_column_text(hstmt, 2));
1255 *provider_list = g_list_append(*provider_list, provider);
1256 rc = _query_step(hstmt);
1259 _query_finalize(hstmt);
1264 int find_service_types(char* prefix, GList** servicetype_list)
1269 char query[QUERY_MAX_LEN + 1] = { 0, };
1272 snprintf(query, sizeof(query) - 1, "select type_id, serviceType_id, display_name, icon from service_type");
1274 snprintf(query, sizeof(query) - 1, "select type_id, serviceType_id, display_name, icon from service_type where serviceType_id like (? || '%%')");
1276 stmt hstmt = __query_prepare(query);
1279 _query_bind_text(hstmt, 1, prefix);
1281 rc = _query_step(hstmt);
1282 while (rc == SQLITE_ROW) {
1283 type_id = _query_column_int(hstmt, 0);
1285 AccountServiceType_t* servicetype = NULL;
1286 servicetype = g_new0(AccountServiceType_t, 1);
1287 servicetype->AccountServiceTypeId = g_strdup(_query_column_text(hstmt, 1));
1288 servicetype->displayName = g_strdup(_query_column_text(hstmt, 2));
1289 servicetype->icon = g_strdup(_query_column_text(hstmt, 3));
1291 _get_tags(TAG_SERVICE_TYPE, type_id, &(servicetype->tags_info));
1293 *servicetype_list = g_list_append(*servicetype_list, servicetype);
1294 rc = _query_step(hstmt);
1296 _query_finalize(hstmt);
1301 // use mandatory input parameter
1302 int getAccountById(char* accountId, UserAccount_t* account) {
1306 char query[QUERY_MAX_LEN + 1] = { 0, };
1308 snprintf(query, sizeof(query) - 1, "select user_id from user_account where account_id = ?");
1310 stmt hstmt = __query_prepare(query);
1311 _query_bind_text(hstmt, 1, accountId);
1313 rc = _query_step(hstmt);
1315 user_id = _query_column_int(hstmt, 0);
1316 _query_finalize(hstmt);
1318 _make_account_info(user_id, account);
1323 int getServiceTypeById(char* serviceTypeId, AccountServiceType_t* serviceType) {
1327 char query[QUERY_MAX_LEN + 1] = {0, };
1328 printf("serviceTypeid : %s \n", serviceTypeId);
1330 snprintf(query, sizeof(query) - 1, "select type_id, serviceType_id, display_name, icon from service_type where serviceType_id = ?");
1332 stmt hstmt = __query_prepare(query);
1333 _query_bind_text(hstmt, 1, serviceTypeId);
1335 rc = _query_step(hstmt);
1336 printf("rc : %d \n", rc);
1338 type_id = _query_column_int(hstmt, 0);
1340 serviceType->AccountServiceTypeId = g_strdup(_query_column_text(hstmt, 1));
1341 serviceType->displayName = g_strdup(_query_column_text(hstmt, 2));
1342 serviceType->icon = g_strdup(_query_column_text(hstmt, 3));
1344 _get_tags(TAG_SERVICE_TYPE, type_id, &(serviceType->tags_info));
1346 _query_finalize(hstmt);
1351 void free_single_value(char* value)
1360 void _free_tags_list_info(gpointer data, gpointer user_data)
1362 free(((tags_info_t*)data)->tag_info);
1366 void free_tags_list(GList* list)
1370 // g_list_foreach(list, _free_tags_list_info, NULL);
1371 // g_list_free(list);
1375 void _free_service_list_info(gpointer data, gpointer user_data)
1377 free(((AccountService_t*)data)->AccountServiceId);
1378 free(((AccountService_t*)data)->serviceName);
1379 free(((AccountService_t*)data)->applicationId);
1380 free(((AccountService_t*)data)->displayName);
1381 free(((AccountService_t*)data)->icon);
1382 free(((AccountService_t*)data)->AccountId);
1383 free(((AccountService_t*)data)->AccountServiceTypeId);
1384 free(((AccountService_t*)data)->AccountServiceProviderId);
1385 free(((AccountService_t*)data)->setting);
1386 free_tags_list(((AccountService_t*)data)->tags_info);
1391 void free_service_list(GList* list)
1395 // g_list_foreach(list, _free_service_list_info, NULL);
1396 // g_list_free(list);
1400 void _free_serviceType_list_info(gpointer data, gpointer user_data)
1402 free(((AccountServiceType_t*)data)->AccountServiceTypeId);
1403 free(((AccountServiceType_t*)data)->displayName);
1404 free(((AccountServiceType_t*)data)->icon);
1405 free_tags_list(((AccountService_t*)data)->tags_info);
1409 void free_serviceType_list(GList* list)
1413 // g_list_foreach(list, _free_serviceType_list_info, NULL);
1414 // g_list_free(list);
1418 void _free_provider_list_info(gpointer data, gpointer user_data)
1420 free(((provider_t*)data)->AccountServiceProviderId);
1421 free(((provider_t*)data)->displayName);
1422 free(((provider_t*)data)->icon);
1426 void free_provider_list(GList* list)
1430 // g_list_foreach(list, _free_provider_list_info, NULL);
1431 // g_list_free(list);
1435 int getProviderById(char* serviceProviderId, provider_t* provider)
1439 char query[QUERY_MAX_LEN + 1] = {0, };
1441 snprintf(query, sizeof(query) - 1, "select provider_id, display_name, icon from provider_list where provider_id = ?");
1443 stmt hstmt = __query_prepare(query);
1444 _query_bind_text(hstmt, 1, serviceProviderId);
1446 rc = _query_step(hstmt);
1448 provider->AccountServiceProviderId = g_strdup(_query_column_text(hstmt, 0));
1449 provider->displayName = g_strdup(_query_column_text(hstmt, 1));
1450 provider->icon = g_strdup(_query_column_text(hstmt, 2));
1452 _query_finalize(hstmt);
1457 int getServiceById(char* serviceId, AccountService_t* service_info)
1461 char query[QUERY_MAX_LEN + 1] = {0, };
1463 snprintf(query, sizeof(query) - 1, "select _svc_id where service_id = ?");
1465 stmt hstmt = __query_prepare(query);
1466 _query_bind_text(hstmt, 1, serviceId);
1467 rc = _query_step(hstmt);
1468 int index = _query_column_int(hstmt, 0);
1469 _query_finalize(hstmt);
1471 _make_service_info(index, service_info);
1476 int getServiceByName(char* serviceName, AccountService_t* service_info)
1480 char query[QUERY_MAX_LEN + 1] = {0, };
1482 snprintf(query, sizeof(query) - 1, "select _svc_id where service_name = ?");
1484 stmt hstmt = __query_prepare(query);
1485 _query_bind_text(hstmt, 1, serviceName);
1487 rc = _query_step(hstmt);
1488 int index = _query_column_int(hstmt, 0);
1489 _query_finalize(hstmt);
1491 _make_service_info(index, service_info);
1496 void test_find_accounts()
1498 GList* account_list = NULL;
1500 search_list_t search_list = {0, };
1501 set_account_filter(&search_list, SERVICE_TYPE_ID, "tizen.sms");
1502 find_accounts(&search_list, DISABLE, &account_list);
1505 UserAccount_t* account_info = (UserAccount_t*)account_list->data;
1506 printf("account_info->AccountId : %s \n", account_info->AccountId);
1507 printf("account_info->AccountServiceProviderId : %s \n", account_info->AccountServiceProviderId);
1508 account_list = g_list_next(account_list);
1512 search_list_t search_list1 = {0, };
1513 set_account_filter(&search_list1, TAGS, "tizen.sharing");
1514 find_accounts(&search_list1, DISABLE, &account_list);
1517 UserAccount_t* account_info = (UserAccount_t*)account_list->data;
1518 printf("account_info->AccountId : %s \n", account_info->AccountId);
1519 printf("account_info->AccountServiceProviderId : %s \n", account_info->AccountServiceProviderId);
1520 account_list = g_list_next(account_list);
1524 search_list_t search_list2 = {0, };
1525 set_account_filter(&search_list2, PROVIDER_ID, "com.google");
1526 find_accounts(&search_list2, DISABLE, &account_list);
1529 UserAccount_t* account_info = (UserAccount_t*)account_list->data;
1530 printf("account_info->AccountId : %s \n", account_info->AccountId);
1531 printf("account_info->AccountServiceProviderId : %s \n", account_info->AccountServiceProviderId);
1532 account_list = g_list_next(account_list);
1536 search_list_t search_list3 = {0, };
1537 set_account_filter(&search_list3, SERVICE_TYPE_ID, "tizen.sms");
1538 set_account_filter(&search_list3, TAGS, "tizen.sharing");
1539 set_account_filter(&search_list3, TAGS, "tizen.email");
1540 set_account_filter(&search_list3, PROVIDER_ID, "com.google");
1541 find_accounts(&search_list3, DISABLE, &account_list);
1544 UserAccount_t* account_info = (UserAccount_t*)account_list->data;
1545 printf("account_info->AccountId : %s \n", account_info->AccountId);
1546 printf("account_info->AccountServiceProviderId : %s \n", account_info->AccountServiceProviderId);
1547 account_list = g_list_next(account_list);
1551 search_list_t search_list4 = {0, };
1552 find_accounts(&search_list4, DISABLE, &account_list);
1555 UserAccount_t* account_info = (UserAccount_t*)account_list->data;
1556 printf("account_info->AccountId : %s \n", account_info->AccountId);
1557 printf("account_info->AccountServiceProviderId : %s \n\n\n", account_info->AccountServiceProviderId);
1558 account_list = g_list_next(account_list);
1562 search_list_t search_list5 = {0, };
1563 set_account_filter(&search_list5, TAGS, "tizen.sms");
1564 set_account_filter(&search_list5, TAGS, "tizen.mms");
1565 find_accounts(&search_list5, DISABLE, &account_list);
1569 UserAccount_t* account_info = (UserAccount_t*)account_list->data;
1570 printf("account_info->AccountId : %s \n", account_info->AccountId);
1571 printf("account_info->AccountServiceProviderId : %s \n", account_info->AccountServiceProviderId);
1572 account_list = g_list_next(account_list);
1576 void test_find_service_types()
1578 GList* servicetype_list = NULL;
1580 find_service_types((char*)"tizen", &servicetype_list);
1581 while(servicetype_list)
1583 AccountServiceType_t* service_type_info = (AccountServiceType_t*)servicetype_list->data;
1584 printf("service_type_info->AccountServiceTypeId : %s \n", service_type_info->AccountServiceTypeId);
1585 printf("service_type_info->displayName : %s \n", service_type_info->displayName);
1586 printf("service_type_info->icon : %s \n", service_type_info->icon);
1588 GList* tmp_tag_list = service_type_info->tags_info;
1592 tags_info_t* tag = (tags_info_t*)tmp_tag_list->data;
1593 printf("tag->tag_info : %s \n", tag->tag_info);
1595 tmp_tag_list = g_list_next(tmp_tag_list);
1598 servicetype_list = g_list_next(servicetype_list);
1602 void test_find_services()
1604 GList* service_list = NULL;
1605 search_list_t search_list = {0, };
1606 set_account_filter(&search_list, SERVICE_TYPE_ID, "tizen.tel");
1607 find_services(&search_list, DISABLE, &service_list);
1610 AccountService_t* service_info = (AccountService_t*)service_list->data;
1611 printf("service_info->AccountServiceId : %s \n", service_info->AccountServiceId);
1612 printf("service_info->AccountServiceProviderId : %s \n", service_info->AccountServiceProviderId);
1613 service_list = g_list_next(service_list);
1616 search_list_t search_list1 = {0, };
1617 set_account_filter(&search_list1, PROVIDER_ID, "com.google");
1618 find_services(&search_list1, DISABLE, &service_list);
1621 AccountService_t* service_info = (AccountService_t*)service_list->data;
1622 printf("service_info->AccountServiceId : %s \n", service_info->AccountServiceId);
1623 printf("service_info->AccountServiceProviderId : %s \n", service_info->AccountServiceProviderId);
1624 service_list = g_list_next(service_list);
1628 void test_find_providers()
1630 GList* provider_list = NULL;
1632 find_providers(NULL, &provider_list);
1633 while(provider_list)
1635 provider_t* provider_info = (provider_t*)provider_list->data;
1636 printf("provider_info->AccountId : %s \n", provider_info->AccountServiceProviderId);
1637 provider_list = g_list_next(provider_list);
1641 find_providers((char*)"tizen.sms", &provider_list);
1642 while(provider_list)
1644 provider_t* provider_info = (provider_t*)provider_list->data;
1645 printf("provider_info->AccountId : %s \n", provider_info->AccountServiceProviderId);
1646 provider_list = g_list_next(provider_list);
1650 void test_get_account_by_id()
1652 UserAccount_t account = {0, };
1653 getAccountById((char*)"com.facebook:William@facebook.com", &account);
1655 printf("account->AccountId : %s \n", account.AccountId);
1658 void test_get_service_type_by_id()
1660 AccountServiceType_t serviceType = {0, };
1662 getServiceTypeById((char*)"tizen.tel", &serviceType);
1663 printf("serviceType->AccountServiceTypeId : %s \n", serviceType.AccountServiceTypeId);
1666 void test_get_provider_by_id()
1668 provider_t provider = {0, };
1670 getProviderById((char*)"com.google", &provider);
1671 printf("provider->AccountServiceProviderId : %s \n", provider.AccountServiceProviderId);
1674 void test_get_service_by_id()
1676 AccountService_t service = {0, };
1678 getServiceById((char*)"com.google.gtalk", &service);
1679 printf("service->AccountServiceProviderId : %s \n", service.AccountServiceId);
1682 void test_get_service_by_name()
1684 AccountService_t service = {0, };
1686 getServiceByName((char*)"com.google.gmail", &service);
1687 printf("service->AccountServiceProviderId : %s \n", service.AccountServiceId);
1692 db_util_open(_QUERY_DB_NAME, &test_hDBCt, 0);
1693 // insert_dummy_data();
1694 printf("\n -------------------------------------------- test_find_accounts --------------------------------------------\n");
1695 test_find_accounts();
1697 printf("\n -------------------------------------------- test_find_services --------------------------------------------\n");
1698 test_find_services();
1700 printf("\n -------------------------------------------- test_find_providers -------------------------------------------\n");
1701 test_find_providers();
1703 printf("\n -------------------------------------------- test_get_account_by_id ----------------------------------------\n");
1704 test_get_account_by_id();
1706 printf("\n -------------------------------------------- test_get_service_type_by_id -----------------------------------\n");
1707 test_get_service_type_by_id();
1709 printf("\n -------------------------------------------- test_get_provider_by_id ---------------------------------------\n");
1710 test_get_provider_by_id();
1712 printf("\n -------------------------------------------- test_find_service_types--------------------------------------- \n");
1713 test_find_service_types();
1715 printf("\n -------------------------------------------- test_get_service_by_id--------------------------------------- \n");
1716 test_get_service_by_id();
1718 printf("\n -------------------------------------------- test_get_service_by_name--------------------------------------- \n");
1719 test_get_service_by_name();
1723 namespace TizenApis {
1724 namespace Platform {
1726 AccountWrapper::AccountWrapper() : m_platformAccount(NULL), m_abstractAccount(NULL)
1728 LogDebug("entered");
1729 m_abstractAccount = EventAccountPtr(new EventAccount());
1730 if (!m_abstractAccount) {
1731 ThrowMsg(UnknownException, "abstract object is not created");
1735 AccountWrapper::AccountWrapper(const EventAccountPtr &event) : m_platformAccount(NULL), m_abstractAccount(event)
1737 LogDebug("entered");
1740 AccountWrapper::~AccountWrapper()
1742 LogDebug("entered");
1743 //TODO: After inserting ,It seems like F/W frees handle. I need to review this later.
1744 // After inserting and call freePlatformAccount, Segment fault occurs.
1745 //freePlatformAccount();
1748 int AccountWrapper::getIDFromPlatformAccount() const
1750 LogDebug("Entered");
1751 int error_code = -1;
1753 if (m_platformAccount == NULL) {
1754 ThrowMsg(NullPointerException, "m_platformAccount is not set");
1757 error_code = account_get_account_id(m_platformAccount, &accountid);
1759 if(ACCOUNT_ERROR_NONE != error_code)
1761 ThrowMsg(PlatformException, "Can't get a account id");
1766 //TODO: check if it works to dicriminate update/insert with account id.
1767 void AccountWrapper::saveAccount()
1769 LogDebug("entered");
1772 //Check if platform struct is set.
1773 //It could be set here, but forcing user to do it manually can help to avoid problems.
1774 if (m_platformAccount == NULL) {
1775 ThrowMsg(NullPointerException, "m_platformAccount is not set");
1778 accountID = m_abstractAccount->getID();
1780 displayPlatformAccount();
1784 //insert new record or update existing one
1785 if (accountID < 0) { // insert new account
1787 // err = addAccount(m_abstractAccount->getProviderName().c_str(), &property, &user_account);
1788 user_account.AccountId = g_strdup("com.google:myaccount1@gmail.com");
1790 // int err = account_insert_to_db(m_platformAccount, &returnID);
1791 if (ACCOUNT_ERROR_NONE != err) {
1792 LogError("Can't insert new account, error code: " << returnID);
1793 ThrowMsg(PlatformException, "Can't insert new account.");
1795 m_abstractAccount->setID(returnID);
1796 m_abstractAccount->setAccountId(user_account.AccountId);
1798 LogInfo("New event inserted");
1801 //accountID = getIDFromPlatformAccount();
1802 LogDebug("accountID: " << accountID);
1803 if (ACCOUNT_ERROR_NONE != account_update_to_db_by_id(m_platformAccount, accountID)) {
1804 ThrowMsg(PlatformException, "Can't update new account.");
1806 LogDebug("Account updated");
1811 void AccountWrapper::loadAccount(int id)
1813 LogDebug("Entered. ID of account to load: " << id);
1815 freePlatformAccount();
1817 if (ACCOUNT_ERROR_NONE != account_create(&m_platformAccount)) {
1818 ThrowMsg(PlatformException, "Can't create handle");
1821 int errorCode = account_query_account_by_account_id(id, &m_platformAccount);
1823 if (ACCOUNT_ERROR_NONE != errorCode) {
1824 LogError("Can't get account with ID = " << id << ", error code: " << errorCode);
1825 ThrowMsg(PlatformException, "Can't get account with ID = " << id << ", error code: " << errorCode);
1827 convertPlatformAccountToAbstractAccount();
1828 displayAbstractAccount();
1831 void AccountWrapper::deleteAccount()
1833 if (m_platformAccount == NULL) {
1834 ThrowMsg(NullPointerException, "Failed to delete event (m_platformAccount==NULL)");
1836 int accountID = m_abstractAccount->getID();
1837 LogDebug("accountID : " << accountID);
1838 if (accountID < 0) {
1839 ThrowMsg(InvalidArgumentException, "Failed to delete account from account DB (account is not saved in account DB)");
1843 err = account_delete_from_db_by_id(accountID);
1844 if (ACCOUNT_ERROR_NONE != err) {
1845 ThrowMsg(PlatformException, "Can't delete account. Error code " << err);
1847 //TODO: Is it necessary?
1848 //m_abstractAccount->resetId();
1849 //setIDToPlatformAccount();
1852 void AccountWrapper::getAccountbyId()
1854 account = g_new0(UserAccount_t, 1);
1856 // int errorCode = getAccountById((char*)m_abstractAccount->getAccountId().c_str(), account);
1857 getAccountById((char*)m_abstractAccount->getAccountId().c_str(), account);
1859 if (ACCOUNT_ERROR_NONE != errorCode) {
1860 LogError("Can't get account with ID = " << id << ", error code: " << errorCode);
1861 ThrowMsg(PlatformException, "Can't get account with ID = " << id << ", error code: " << errorCode);
1864 if(account->AccountId)
1865 m_abstractAccount->setAccountId(account->AccountId);
1867 if(account->displayName)
1868 m_abstractAccount->setDisplayName(account->displayName);
1871 m_abstractAccount->setIconPath(account->icon);
1873 if(account->AccountServiceProviderId)
1874 m_abstractAccount->setProviderName(account->AccountServiceProviderId);
1876 m_abstractAccount->setEnabled(account->enabled);
1877 std::stringstream sstream;
1878 sstream << account->credentialId;
1879 m_abstractAccount->setCredentailId(sstream.str());
1881 if(account->settings)
1882 m_abstractAccount->setSettings(account->settings);
1884 getAccountServices();
1885 // convertPlatformAccountToAbstractAccount();
1887 free_single_value(account->AccountId);
1888 free_single_value(account->displayName);
1889 free_single_value(account->icon);
1890 free_single_value(account->AccountServiceProviderId);
1891 free_single_value(account->settings);
1896 AccountServiceProviderPropertyArrayPtr AccountWrapper::findProviders(std::string serviceTypeId)
1900 AccountServiceProviderPropertyArrayPtr serviceProviderPropertiesPtr(new AccountServiceProviderPropertyArray);
1902 GList* provider_list = NULL;
1903 GList* tmp_list = NULL;
1905 find_providers((char*)serviceTypeId.c_str(), &provider_list);
1906 tmp_list = provider_list;
1910 provider_t* provider = (provider_t*)tmp_list->data;
1912 AccountServiceProviderPropertyPtr serviceProviderPropertyPtr(new AccountServiceProviderProperty());
1914 if(provider->AccountServiceProviderId)
1915 serviceProviderPropertyPtr->setId(provider->AccountServiceProviderId);
1917 if(provider->displayName)
1918 serviceProviderPropertyPtr->setDisplayName(provider->displayName);
1921 serviceProviderPropertyPtr->setIconPath(provider->icon);
1923 serviceProviderPropertiesPtr->push_back(serviceProviderPropertyPtr);
1925 tmp_list = g_list_next(tmp_list);
1927 free_provider_list(provider_list);
1930 return serviceProviderPropertiesPtr;
1933 void AccountWrapper::setTags(std::vector<std::string> &tagsVector, GList* tags_list)
1935 GList* tmp_tags_list = tags_list;
1936 while(tmp_tags_list)
1938 tags_info_t* tag = (tags_info_t*)tmp_tags_list->data;
1939 tagsVector.push_back(tag->tag_info);
1940 tmp_tags_list = g_list_next(tmp_tags_list);
1944 AccountServiceTypePropertyArrayPtr AccountWrapper::findServiceTypes()
1946 AccountServiceTypePropertyArrayPtr servicetypes(new AccountServiceTypePropertyArray());
1948 GList* servicetype_list = NULL;
1949 find_service_types((char*)m_abstractAccount->getprefix().c_str(), &servicetype_list);
1951 GList* tmp_list = servicetype_list;
1954 AccountServiceType_t* serviceType_info = (AccountServiceType_t*)tmp_list->data;
1956 AccountServiceTypePropertyPtr serviceType(new AccountServiceTypeProperty());
1958 if(serviceType_info->AccountServiceTypeId)
1959 serviceType->setId(serviceType_info->AccountServiceTypeId);
1961 if(serviceType_info->displayName)
1962 serviceType->setDisplayName(serviceType_info->displayName);
1964 if(serviceType_info->icon)
1965 serviceType->setIconPath(serviceType_info->icon);
1968 std::vector<std::string> tagsVector;
1970 setTags(tagsVector, serviceType_info->tags_info);
1971 if(serviceType_info->tags_info)
1972 serviceType->setTags(tagsVector);
1974 servicetypes->push_back(serviceType);
1975 tmp_list = g_list_next(tmp_list);
1977 free_serviceType_list(servicetype_list);
1979 return servicetypes;
1982 char *AccountWrapper::getPlatformAccount() const
1984 LogDebug("entered");
1985 return (char*)m_platformAccount;
1988 EventAccountPtr AccountWrapper::getAbstractAccount() const {
1989 LogDebug("entered");
1990 return m_abstractAccount;
1993 void AccountWrapper::freePlatformAccount() {
1994 LogDebug("entered");
1995 if (m_platformAccount != NULL) {
1996 if (ACCOUNT_ERROR_NONE != account_destroy(m_platformAccount)) {
1997 LogError("Can't free account handle.");
1999 m_platformAccount = NULL;
2003 char *AccountWrapper::convertAbstractAccountToPlatformAccount() {
2004 LogDebug("entered");
2005 freePlatformAccount();
2007 if (ACCOUNT_ERROR_NONE != account_create(&m_platformAccount)) {
2008 ThrowMsg(PlatformException, "Can't create handle");
2011 property.displayName = g_strdup(m_abstractAccount->getDisplayName().c_str());
2012 property.icon = g_strdup(m_abstractAccount->getIconPath().c_str());
2014 setDisplayNameToPlatformAccount();
2015 setIconPathToPlatformAccount();
2016 setProviderNameToPlatformAccount();
2018 setUserNameToPlatformAccount();
2019 setPackageNameToPlatformAccount();
2021 //TODO: check if we need to have user be able to set the ID.
2022 //setIDToPlatformAccount();
2023 setEmailAddressToPlatformAccount();
2024 setDomainNameToPlatformAccount();
2026 setAccountServices();
2028 return getPlatformAccount();
2031 void AccountWrapper::setIDToPlatformAccount() {
2032 LogDebug("entered");
2034 //TODO: check if we need to have user be able to set the ID.
2037 if (!m_platformAccount) {
2038 ThrowMsg(UnknownException, "Null platform pointer.");
2040 if (m_abstractAccount->getIdIsSet()) {
2041 if (CAL_SUCCESS != calendar_svc_struct_set_int(m_platformEvent,
2042 CAL_VALUE_INT_INDEX,
2043 m_abstractEvent->getId()))
2045 ThrowMsg(PlatformException, "Can't set event ID.");
2048 if (CAL_SUCCESS != calendar_svc_struct_set_int(m_platformEvent,
2049 CAL_VALUE_INT_INDEX,
2051 ThrowMsg(PlatformException, "Can't set event ID.");
2057 void AccountWrapper::setDisplayNameToPlatformAccount()
2059 LogDebug("entered");
2060 if (!m_platformAccount) {
2061 ThrowMsg(UnknownException, "Null platform pointer.");
2064 if (ACCOUNT_ERROR_NONE != account_set_display_name(m_platformAccount, m_abstractAccount->getDisplayName().c_str()))
2066 ThrowMsg(PlatformException, "Can't set displayname.");
2071 void AccountWrapper::setIconPathToPlatformAccount() {
2072 LogDebug("entered");
2073 if (!m_platformAccount) {
2074 ThrowMsg(UnknownException, "Null platform pointer.");
2077 if (ACCOUNT_ERROR_NONE != account_set_icon_path(m_platformAccount, m_abstractAccount->getIconPath().c_str())) {
2078 ThrowMsg(PlatformException, "Can't set iconPath.");
2083 void AccountWrapper::setProviderNameToPlatformAccount()
2085 LogDebug("entered");
2086 if (!m_platformAccount) {
2087 ThrowMsg(UnknownException, "Null platform pointer.");
2090 if (ACCOUNT_ERROR_NONE != account_set_source(m_platformAccount, m_abstractAccount->getProviderName().c_str()))
2092 ThrowMsg(PlatformException, "Can't set providername.");
2096 void AccountWrapper::setEmailAddressToPlatformAccount() {
2097 LogDebug("entered");
2098 if (!m_platformAccount) {
2099 ThrowMsg(UnknownException, "Null platform pointer.");
2102 if (ACCOUNT_ERROR_NONE != account_set_email_address(m_platformAccount, m_abstractAccount->getEmailAddress().c_str())) {
2103 ThrowMsg(PlatformException, "Can't set packagename.");
2107 void AccountWrapper::setDomainNameToPlatformAccount() {
2108 LogDebug("entered");
2109 if (!m_platformAccount) {
2110 ThrowMsg(UnknownException, "Null platform pointer.");
2113 if (ACCOUNT_ERROR_NONE != account_set_domain_name(m_platformAccount, m_abstractAccount->getDomainName().c_str())) {
2114 ThrowMsg(PlatformException, "Can't set packagename.");
2119 void AccountWrapper::setHasContactFeatureToPlatformAccount()
2121 LogDebug("entered");
2122 if (!m_platformAccount) {
2123 ThrowMsg(UnknownException, "Null platform pointer.");
2125 account_set_capability(m_platformAccount, ACCOUNT_CAPABILITY_CONTACT, ACCOUNT_CAPABILITY_ENABLED);
2129 void AccountWrapper::setAccountServices() {
2130 LogDebug("entered");
2131 if (!m_platformAccount) {
2132 ThrowMsg(UnknownException, "Null platform pointer.");
2135 AccountServicesArrayPtr services = m_abstractAccount->getService();
2136 if ((services == NULL) || (services->size() == 0))
2140 for (size_t i = 0; i < services->size(); ++i) {
2141 LogDebug("getServiceName : " << services->at(i)->getName().c_str());
2142 // LogDebug("getServiceType : " << services->at(i)->getServiceType().c_str());
2147 void AccountWrapper::getAccountServices()
2149 LogDebug("entered");
2151 ThrowMsg(UnknownException, "Null platform pointer.");
2154 AccountServicesArrayPtr services(new AccountServicesArray());
2156 GList* tmp_service_list = account->services;
2157 while(tmp_service_list)
2159 AccountService_t* service_info = (AccountService_t*)tmp_service_list->data;
2161 AccountServicesPtr service(new AccountServices());
2163 if(service_info->AccountServiceId)
2164 service->setId(service_info->AccountServiceId);
2166 if(service_info->serviceName)
2167 service->setName(service_info->serviceName);
2169 if(service_info->applicationId)
2170 service->setApplicationId(service_info->applicationId);
2172 if(service_info->displayName)
2173 service->setDisplayName(service_info->displayName);
2175 if(service_info->icon)
2176 service->setIcon(service_info->icon);
2178 if(service_info->AccountId)
2179 service->setAccountId(service_info->AccountId);
2181 if(service_info->AccountServiceTypeId)
2182 service->setServiceTypeId(service_info->AccountServiceTypeId);
2184 if(service_info->AccountServiceProviderId)
2185 service->setProviderId(service_info->AccountServiceProviderId);
2187 if(service_info->setting)
2188 service->setSettings(service_info->setting);
2191 std::vector<std::string> tagsVector;
2192 setTags(tagsVector, service_info->tags_info);
2193 if(service_info->tags_info)
2194 service->setTags(tagsVector);
2196 services->push_back(service);
2197 tmp_service_list = g_list_next(tmp_service_list);
2201 m_abstractAccount->setService(services);
2203 free_service_list(account->services);
2206 AccountServiceTypePropertyPtr AccountWrapper::getAccountServiceTypebyId()
2208 std::string serviceTypeId = m_abstractAccount->getServiceTypeId();
2209 AccountServiceTypePropertyPtr accountServiceTypePropertyPtr(new AccountServiceTypeProperty);
2211 db_util_open(_QUERY_DB_NAME, &test_hDBCt, 0);
2213 AccountServiceType_t serviceType = {0, };
2214 getServiceTypeById((char*)serviceTypeId.c_str(), &serviceType);
2216 if(serviceType.AccountServiceTypeId)
2217 accountServiceTypePropertyPtr->setId(serviceType.AccountServiceTypeId);
2219 if(serviceType.displayName)
2220 accountServiceTypePropertyPtr->setDisplayName(serviceType.displayName);
2222 if(serviceType.icon)
2223 accountServiceTypePropertyPtr->setIconPath(serviceType.icon);
2226 std::vector<std::string> tagsVector;
2227 setTags(tagsVector, serviceType.tags_info);
2228 if(serviceType.tags_info)
2229 accountServiceTypePropertyPtr->setTags(tagsVector);
2231 free_single_value(serviceType.AccountServiceTypeId);
2232 free_single_value(serviceType.displayName);
2233 free_single_value(serviceType.icon);
2234 free_tags_list(serviceType.tags_info);
2236 return accountServiceTypePropertyPtr;
2239 AccountServiceProviderPropertyPtr AccountWrapper::getAccountServiceProviderProperty()
2241 std::string accountServiceProviderId = m_abstractAccount->getProviderId();
2243 provider_t provider = {0, };
2244 getProviderById((char*)accountServiceProviderId.c_str(), &provider);
2246 AccountServiceProviderPropertyPtr accountServiceProviderPropertyPtr(new AccountServiceProviderProperty);
2248 if(provider.AccountServiceProviderId)
2249 accountServiceProviderPropertyPtr->setId(provider.AccountServiceProviderId);
2251 if(provider.displayName)
2252 accountServiceProviderPropertyPtr->setDisplayName(provider.displayName);
2255 accountServiceProviderPropertyPtr->setIconPath(provider.icon);
2257 free_single_value(provider.AccountServiceProviderId);
2258 free_single_value(provider.displayName);
2259 free_single_value(provider.icon);
2261 return accountServiceProviderPropertyPtr;
2264 void AccountWrapper::setDummyServices(){
2267 AccountServicesArrayPtr services(new AccountServicesArray());
2268 for (int i = 0; i < 2; i++) {
2269 AccountServicesPtr service(new AccountServices());
2271 service->setId("dummy_id");
2272 service->setName("dummy_name");
2273 service->setApplicationId("dummy_applicationId");
2274 service->setDisplayName("dummy_displayName");
2275 service->setIcon("dummy_Icon");
2276 service->setAccountId("dummy_accountId");
2277 service->setServiceTypeId("dummy_serviceTypeId");
2278 service->setProviderId("dummy_ProviderId");
2279 // service->setTags("dummy_");
2280 service->setSettings("dummy_settings");
2282 services->push_back(service);
2285 m_abstractAccount->setService(services);
2290 EventAccountListPtr AccountWrapper::findAccountsByFilter(AccountServiceFilterPropertyPtr filterPropertyPtr)
2292 std::string provider = filterPropertyPtr->getProvider();
2293 std::string serviceTypeId = filterPropertyPtr->getServiceTypeId();
2294 std::vector<std::string> tags = filterPropertyPtr->getTags();
2296 EventAccountListPtr retAccountListPtr(new EventAccountList);
2298 GList* account_list = NULL;
2299 search_list_t search_list = {0, };
2300 set_account_filter(&search_list, PROVIDER_ID, (char*)provider.c_str());
2301 set_account_filter(&search_list, SERVICE_TYPE_ID, (char*)serviceTypeId.c_str());
2302 for (unsigned int i=0; i<tags.size(); i++)
2303 set_account_filter(&search_list, TAGS, (char*)tags[i].c_str());
2305 find_accounts(&search_list, DISABLE, &account_list);
2308 UserAccount_t* account_info = (UserAccount_t*)account_list->data;
2309 EventAccountPtr account_ptr(new EventAccount());
2311 if(account_info->AccountId)
2312 account_ptr->setAccountId(account_info->AccountId);
2314 if(account_info->displayName)
2315 account_ptr->setDisplayName(account_info->displayName);
2317 if(account_info->icon)
2318 account_ptr->setIconPath(account_info->icon);
2320 if(account_info->AccountServiceProviderId)
2321 account_ptr->setProviderName(account_info->AccountServiceProviderId);
2323 account_ptr->setEnabled(account_info->enabled);
2324 std::stringstream sstream;
2325 sstream << account_info->credentialId;
2326 account_ptr->setCredentailId(sstream.str());
2328 if(account_info->settings)
2329 account_ptr->setSettings(account_info->settings);
2331 AccountServicesArrayPtr services(new AccountServicesArray());
2332 GList* tmp_service_list = account_info->services;
2333 while(tmp_service_list)
2335 AccountService_t* service_info = (AccountService_t*)tmp_service_list->data;
2337 AccountServicesPtr service(new AccountServices());
2339 if(service_info->AccountServiceId)
2340 service->setId(service_info->AccountServiceId);
2342 if(service_info->serviceName)
2343 service->setName(service_info->serviceName);
2345 if(service_info->applicationId)
2346 service->setApplicationId(service_info->applicationId);
2348 if(service_info->displayName)
2349 service->setDisplayName(service_info->displayName);
2351 if(service_info->icon)
2352 service->setIcon(service_info->icon);
2354 if(service_info->AccountId)
2355 service->setAccountId(service_info->AccountId);
2357 if(service_info->AccountServiceTypeId)
2358 service->setServiceTypeId(service_info->AccountServiceTypeId);
2360 if(service_info->AccountServiceProviderId)
2361 service->setProviderId(service_info->AccountServiceProviderId);
2363 if(service_info->setting)
2364 service->setSettings(service_info->setting);
2367 std::vector<std::string> tagsVector;
2368 setTags(tagsVector, service_info->tags_info);
2369 if(service_info->tags_info)
2370 service->setTags(tagsVector);
2372 services->push_back(service);
2373 tmp_service_list = g_list_next(tmp_service_list);
2376 account_ptr->setService(services);
2377 free_service_list(account_info->services);
2379 free_single_value(account_info->AccountId);
2380 free_single_value(account_info->displayName);
2381 free_single_value(account_info->icon);
2382 free_single_value(account_info->AccountServiceProviderId);
2383 free_single_value(account_info->settings);
2386 retAccountListPtr->push_back(account_ptr);
2387 account_list = g_list_next(account_list);
2390 return retAccountListPtr;
2393 AccountServicesArrayPtr AccountWrapper::findServiceByFilter(AccountServiceFilterPropertyPtr filterPropertyPtr)
2395 std::string provider = filterPropertyPtr->getProvider();
2396 std::string serviceTypeId = filterPropertyPtr->getServiceTypeId();
2397 std::vector<std::string> tags = filterPropertyPtr->getTags();
2399 AccountServicesArrayPtr retServiceListPtr(new AccountServicesArray);
2401 GList* service_list = NULL;
2402 GList* tmp_service_list = NULL;
2403 search_list_t search_list = {0, };
2404 set_account_filter(&search_list, PROVIDER_ID, (char*)provider.c_str());
2405 set_account_filter(&search_list, SERVICE_TYPE_ID, (char*)serviceTypeId.c_str());
2406 for (unsigned int i=0; i<tags.size(); i++)
2407 set_account_filter(&search_list, TAGS, (char*)tags[i].c_str());
2409 find_services(&search_list, DISABLE, &service_list);
2410 tmp_service_list = service_list;
2411 while(tmp_service_list)
2413 AccountService_t* service_info = (AccountService_t*)tmp_service_list->data;
2415 AccountServicesPtr service(new AccountServices());
2417 if(service_info->AccountServiceId)
2418 service->setId(service_info->AccountServiceId);
2420 if(service_info->serviceName)
2421 service->setName(service_info->serviceName);
2423 if(service_info->applicationId)
2424 service->setApplicationId(service_info->applicationId);
2426 if(service_info->displayName)
2427 service->setDisplayName(service_info->displayName);
2429 if(service_info->icon)
2430 service->setIcon(service_info->icon);
2432 if(service_info->AccountId)
2433 service->setAccountId(service_info->AccountId);
2435 if(service_info->AccountServiceTypeId)
2436 service->setServiceTypeId(service_info->AccountServiceTypeId);
2438 if(service_info->AccountServiceProviderId)
2439 service->setProviderId(service_info->AccountServiceProviderId);
2441 if(service_info->setting)
2442 service->setSettings(service_info->setting);
2445 std::vector<std::string> tagsVector;
2446 setTags(tagsVector, service_info->tags_info);
2447 if(service_info->tags_info)
2448 service->setTags(tagsVector);
2450 retServiceListPtr->push_back(service);
2451 tmp_service_list = g_list_next(tmp_service_list);
2454 free_service_list(service_list);
2456 return retServiceListPtr;
2459 EventAccountPtr AccountWrapper::convertPlatformAccountToAbstractAccount()
2461 LogDebug("entered");
2462 setDisplayNameFromPlatformAccount();
2463 setIconPathFromPlatformAccount();
2464 setProviderNameFromPlatformAccount();
2467 setUserNameFromPlatformAccount();
2468 setPackageNameFromPlatformAccount();
2469 setIDFromPlatformAccount();
2470 setEmailAddressFromPlatformAccount();
2471 setDomainNameFromPlatformAccount();
2473 getAccountServices();
2475 displayPlatformAccount();
2476 return getAbstractAccount();
2479 EventAccountPtr AccountWrapper::convertPlatformAccountToAbstractAccount(account_h account_info)
2481 LogDebug("entered");
2482 m_platformAccount = account_info;
2483 setDisplayNameFromPlatformAccount();
2484 setIconPathFromPlatformAccount();
2485 setProviderNameFromPlatformAccount();
2487 setUserNameFromPlatformAccount();
2488 setPackageNameFromPlatformAccount();
2489 setIDFromPlatformAccount();
2490 setEmailAddressFromPlatformAccount();
2491 setDomainNameFromPlatformAccount();
2493 getAccountServices();
2495 displayPlatformAccount();
2496 return getAbstractAccount();
2499 void AccountWrapper::setIDFromPlatformAccount()
2501 LogDebug("entered");
2502 if (!m_platformAccount) {
2503 ThrowMsg(UnknownException, "Null platform pointer.");
2505 m_abstractAccount->setID(getIDFromPlatformAccount());
2508 void AccountWrapper::setDisplayNameFromPlatformAccount()
2510 LogDebug("entered");
2511 if (!m_platformAccount) {
2512 ThrowMsg(UnknownException, "Null platform pointer.");
2515 char *displayname = NULL;
2516 account_get_display_name(m_platformAccount, &displayname);
2518 m_abstractAccount->setDisplayName(displayname);
2522 void AccountWrapper::setIconPathFromPlatformAccount()
2524 LogDebug("entered");
2525 if (!m_platformAccount) {
2526 ThrowMsg(UnknownException, "Null platform pointer.");
2529 char *iconPath = NULL;
2530 account_get_icon_path(m_platformAccount, &iconPath);
2532 m_abstractAccount->setIconPath(iconPath);
2536 void AccountWrapper::setProviderNameFromPlatformAccount() {
2537 LogDebug("entered");
2538 if (!m_platformAccount) {
2539 ThrowMsg(UnknownException, "Null platform pointer.");
2542 char *providername = NULL;
2543 account_get_source(m_platformAccount, &providername);
2545 m_abstractAccount->setProviderName(providername);
2549 void AccountWrapper::setEmailAddressFromPlatformAccount() {
2550 LogDebug("entered");
2551 if (!m_platformAccount) {
2552 ThrowMsg(UnknownException, "Null platform pointer.");
2555 char *emailaddress = NULL;
2556 account_get_email_address(m_platformAccount, &emailaddress);
2558 m_abstractAccount->setEmailAddress(emailaddress);
2562 void AccountWrapper::setDomainNameFromPlatformAccount() {
2563 LogDebug("entered");
2564 if (!m_platformAccount) {
2565 ThrowMsg(UnknownException, "Null platform pointer.");
2568 char *domainname = NULL;
2569 account_get_domain_name(m_platformAccount, &domainname);
2571 m_abstractAccount->setDomainName(domainname);
2575 void AccountWrapper::displayAbstractAccount() {
2576 LogDebug("account id : " << m_abstractAccount->getID());
2577 LogDebug("Display name : " << m_abstractAccount->getDisplayName());
2580 void AccountWrapper::displayPlatformAccount() {