4 * Copyright (c) 2010 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
23 #include "ctsvc_internal.h"
24 #include "ctsvc_db_schema.h"
25 #include "ctsvc_db_sqlite.h"
26 #include "ctsvc_db_utils.h"
27 #include "ctsvc_db_plugin_group_helper.h"
28 #include "ctsvc_notify.h"
29 #include "ctsvc_normalize.h"
30 #include "ctsvc_server_setting.h"
31 #include "ctsvc_localize.h"
34 * Whenever deleting group, this function will be called
35 * in order to deleting group image file
37 void ctsvc_db_group_delete_callback(sqlite3_context *context, int argc, sqlite3_value **argv)
40 const unsigned char *path;
43 sqlite3_result_null(context);
46 path = sqlite3_value_text(argv[0]);
49 char full_path[CTSVC_IMG_FULL_PATH_SIZE_MAX] = {0};
50 snprintf(full_path, sizeof(full_path), "%s/%s", CTS_GROUP_IMAGE_LOCATION, path);
51 ret = unlink(full_path);
53 WARN("unlink() Fail(%d)", errno);
59 static int _ctsvc_db_group_name_collation_str(const char *str1, const char *str2)
63 char *str_dest1 = NULL;
64 char *str_dest2 = NULL;
66 ctsvc_collation_str((char *)str1, &str_dest1);
67 ctsvc_collation_str((char *)str2, &str_dest2);
69 len1 = strlen(str_dest1);
70 len2 = strlen(str_dest2);
72 ret = strncmp(str_dest1, str_dest2, len1);
74 ret = strncmp(str_dest1, str_dest2, len2);
81 int ctsvc_db_group_name_sort_callback(void *context, int str1_len, const void *str1, int str2_len, const void *str2)
86 char str_src1[CTSVC_STR_SHORT_LEN] = {0};
87 char str_src2[CTSVC_STR_SHORT_LEN] = {0};
88 int prim_sort = ctsvc_get_primary_sort();
90 if (CTSVC_STR_SHORT_LEN <= str1_len)
91 str1_len = CTSVC_STR_SHORT_LEN -1;
92 if (CTSVC_STR_SHORT_LEN <= str2_len)
93 str2_len = CTSVC_STR_SHORT_LEN -1;
95 strncpy(str_src1, str1, str1_len);
96 strncpy(str_src2, str2, str2_len);
98 str1_sort_type = ctsvc_get_name_sort_type(str_src1);
99 str2_sort_type = ctsvc_get_name_sort_type(str_src2);
101 switch (str1_sort_type) {
102 case CTSVC_SORT_NUMBER:
103 if (CTSVC_SORT_OTHERS == str2_sort_type)
105 else if (CTSVC_SORT_NUMBER == str2_sort_type)
106 ret = _ctsvc_db_group_name_collation_str(str_src1, str_src2);
111 case CTSVC_SORT_OTHERS:
112 if (CTSVC_SORT_OTHERS == str2_sort_type)
113 ret = _ctsvc_db_group_name_collation_str(str_src1, str_src2);
119 if (CTSVC_SORT_NUMBER >= str2_sort_type) {
122 if (str1_sort_type != str2_sort_type) {
123 if (str1_sort_type == prim_sort)
125 else if (str2_sort_type == prim_sort)
128 ret = _ctsvc_db_group_name_collation_str(str_src1, str_src2);
130 ret = _ctsvc_db_group_name_collation_str(str_src1, str_src2);