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 #include <media_info_private.h>
19 #include <media_util_private.h>
22 static bool __is_pinyin_needed(void)
25 const char *china = "zh_CN";
26 const char *hongkong = "zh_HK";
30 bool pinyin_support = FALSE;
31 media_svc_check_pinyin_support(&pinyin_support);
33 /*Check Language Setting*/
34 lang = vconf_get_str(VCONFKEY_LANGSET);
35 media_content_retvm_if(lang == NULL, ret, "Fail to get string of language set");
37 if ((strncmp(china, lang, strlen(china)) == 0) ||
38 (strncmp(hongkong, lang, strlen(hongkong)) == 0)) {
48 static char *__get_order_str(media_content_order_e order_enum)
51 case MEDIA_CONTENT_ORDER_ASC:
52 return (char *)"ASC ";
53 case MEDIA_CONTENT_ORDER_DESC:
54 return (char *)"DESC ";
60 static char *__get_collate_str(media_content_collation_e collate_type)
62 switch (collate_type) {
63 case MEDIA_CONTENT_COLLATE_NOCASE:
64 return (char *)"NOCASE ";
65 case MEDIA_CONTENT_COLLATE_RTRIM:
66 return (char *)"RTRIM ";
67 case MEDIA_CONTENT_COLLATE_LOCALIZED:
68 if (__is_pinyin_needed())
69 return (char *)"NOCASE ";
71 return (char *)"localized ";
72 default: return (char *)" ";
76 int _media_filter_attribute_generate(filter_h filter, char **generated_condition)
78 int ret = MEDIA_CONTENT_ERROR_NONE;
79 filter_s *_filter = NULL;
80 char tmp_condition[MAX_QUERY_SIZE] = {0, };
82 media_content_retvm_if(filter == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid filter");
83 media_content_retvm_if(generated_condition == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid generated_condition");
85 _filter = (filter_s*)filter;
87 media_content_retvm_if(_filter->condition == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid condition");
88 media_content_retvm_if(_filter->condition_collate_type < MEDIA_CONTENT_COLLATE_DEFAULT ||
89 _filter->condition_collate_type > MEDIA_CONTENT_COLLATE_LOCALIZED, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid condition collate");
91 /* make the statment */
92 memset(tmp_condition, 0, sizeof(tmp_condition));
93 SAFE_STRLCAT(tmp_condition, QUERY_KEYWORD_OPEN_BRACKET, sizeof(tmp_condition));
94 SAFE_STRLCAT(tmp_condition, _filter->condition, sizeof(tmp_condition));
96 /* Process for filter v1 */
97 if (_filter->is_full_condition == false && _filter->condition_collate_type != MEDIA_CONTENT_COLLATE_DEFAULT) {
98 SAFE_STRLCAT(tmp_condition, QUERY_KEYWORD_COLLATE, sizeof(tmp_condition));
99 SAFE_STRLCAT(tmp_condition, __get_collate_str(_filter->condition_collate_type), sizeof(tmp_condition));
102 SAFE_STRLCAT(tmp_condition, QUERY_KEYWORD_BRACKET, sizeof(tmp_condition));
104 if (STRING_VALID(tmp_condition))
105 *generated_condition = g_strdup(tmp_condition);
107 *generated_condition = NULL;
109 media_content_sec_debug("Condition : %s", *generated_condition);
114 int _media_filter_attribute_option_generate(filter_h filter, char **generated_option)
116 int ret = MEDIA_CONTENT_ERROR_NONE;
117 filter_s *_filter = NULL;
118 char query[DEFAULT_QUERY_SIZE] = {0, };
119 char option[DEFAULT_QUERY_SIZE] = {0, };
121 media_content_retvm_if(filter == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid filter");
123 _filter = (filter_s*)filter;
125 memset(query, 0x00, sizeof(query));
128 if (STRING_VALID(_filter->order_keyword)) {
129 if ((_filter->order_type == MEDIA_CONTENT_ORDER_ASC) || (_filter->order_type == MEDIA_CONTENT_ORDER_DESC)) {
130 SAFE_STRLCAT(query, QUERY_KEYWORD_ORDER_BY, sizeof(query));
131 SAFE_STRLCAT(query, _filter->order_keyword, sizeof(query));
133 if (_filter->order_collate_type == MEDIA_CONTENT_COLLATE_NOCASE || _filter->order_collate_type == MEDIA_CONTENT_COLLATE_RTRIM || _filter->order_collate_type == MEDIA_CONTENT_COLLATE_LOCALIZED) {
134 SAFE_STRLCAT(query, QUERY_KEYWORD_COLLATE, sizeof(query));
135 SAFE_STRLCAT(query, __get_collate_str(_filter->order_collate_type), sizeof(query));
137 SAFE_STRLCAT(query, QUERY_KEYWORD_SPACE, sizeof(query));
139 SAFE_STRLCAT(query, __get_order_str(_filter->order_type), sizeof(query));
141 SAFE_STRLCAT(query, _filter->order_keyword, sizeof(query));
146 SAFE_STRLCAT(query, QUERY_KEYWORD_SPACE, sizeof(query));
148 memset(option, 0, sizeof(option));
149 snprintf(option, sizeof(option), "%s %d, %d", QUERY_KEYWORD_LIMIT, _filter->offset, _filter->count);
151 SAFE_STRLCAT(query, option, sizeof(query));
153 if (STRING_VALID(query)) {
154 *generated_option = g_strdup(query);
155 media_content_sec_debug("Option : %s", *generated_option);
157 *generated_option = NULL;
163 int _media_filter_attribute_option_generate_with_full_query(filter_h filter, char **generated_option)
165 int ret = MEDIA_CONTENT_ERROR_NONE;
166 filter_s * _filter = NULL;
167 char query[DEFAULT_QUERY_SIZE] = {0, };
168 char option[DEFAULT_QUERY_SIZE] = {0, };
170 media_content_retvm_if(filter == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid filter");
171 media_content_retvm_if(generated_option == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid generated_option");
173 _filter = (filter_s*)filter;
175 memset(query, 0, sizeof(query));
178 if (STRING_VALID(_filter->order_keyword)) {
179 SAFE_STRLCAT(query, QUERY_KEYWORD_ORDER_BY, sizeof(query));
180 SAFE_STRLCAT(query, _filter->order_keyword, sizeof(query));
184 SAFE_STRLCAT(query, QUERY_KEYWORD_SPACE, sizeof(query));
186 memset(option, 0, sizeof(option));
187 snprintf(option, sizeof(option), "%s %d, %d", QUERY_KEYWORD_LIMIT, _filter->offset, _filter->count);
188 SAFE_STRLCAT(query, option, sizeof(query));
190 if (STRING_VALID(query)) {
191 *generated_option = g_strdup(query);
192 media_content_sec_debug("Option : %s", *generated_option);
194 *generated_option = NULL;
201 int media_filter_create(filter_h *filter)
203 int ret = MEDIA_CONTENT_ERROR_NONE;
205 media_content_retvm_if(filter == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid filter");
207 filter_s *_filter = (filter_s*)calloc(1, sizeof(filter_s));
208 media_content_retvm_if(_filter == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
210 _filter->storage_id = NULL;
211 _filter->condition = NULL;
212 _filter->order_keyword = NULL;
213 _filter->order_type = -1;
214 _filter->condition_collate_type = MEDIA_CONTENT_COLLATE_DEFAULT;
215 _filter->order_collate_type = MEDIA_CONTENT_COLLATE_DEFAULT;
216 _filter->offset = -1;
218 _filter->is_full_condition = false;
219 _filter->is_full_order = false;
221 *filter = (filter_h)_filter;
226 int media_filter_destroy(filter_h filter)
228 int ret = MEDIA_CONTENT_ERROR_NONE;
229 filter_s *_filter = (filter_s*)filter;
232 SAFE_FREE(_filter->storage_id);
233 SAFE_FREE(_filter->condition);
234 SAFE_FREE(_filter->order_keyword);
237 ret = MEDIA_CONTENT_ERROR_NONE;
239 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
240 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
246 int media_filter_set_offset(filter_h filter, int offset, int count)
248 int ret = MEDIA_CONTENT_ERROR_NONE;
249 filter_s *_filter = (filter_s*)filter;
251 if (_filter != NULL) {
252 _filter->offset = offset;
253 _filter->count = count;
255 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
256 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
262 int media_filter_set_condition(filter_h filter, const char *condition, media_content_collation_e collate_type)
264 int ret = MEDIA_CONTENT_ERROR_NONE;
265 filter_s *_filter = (filter_s*)filter;
267 if ((_filter != NULL) && STRING_VALID(condition)
268 && ((collate_type >= MEDIA_CONTENT_COLLATE_DEFAULT) && (collate_type <= MEDIA_CONTENT_COLLATE_LOCALIZED))) {
270 _filter->is_full_condition = false;
272 if (STRING_VALID(_filter->condition))
273 SAFE_FREE(_filter->condition);
275 char new_condition[MAX_QUERY_SIZE] = {0, };
276 memset(new_condition, 0, sizeof(new_condition));
277 ret = _media_content_replace_path_in_condition(condition, new_condition, TRUE);
278 media_content_retvm_if(!STRING_VALID(new_condition), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed");
280 _filter->condition = strdup(new_condition);
281 media_content_retvm_if(_filter->condition == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
283 media_content_sec_debug("Condition string : %s", _filter->condition);
285 _filter->condition_collate_type = collate_type;
287 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
288 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
294 int media_filter_set_order(filter_h filter, media_content_order_e order_type, const char *order_keyword, media_content_collation_e collate_type)
296 int ret = MEDIA_CONTENT_ERROR_NONE;
297 filter_s *_filter = (filter_s*)filter;
299 if ((_filter != NULL) && STRING_VALID(order_keyword)
300 && ((order_type == MEDIA_CONTENT_ORDER_ASC) || (order_type == MEDIA_CONTENT_ORDER_DESC))
301 && ((collate_type >= MEDIA_CONTENT_COLLATE_DEFAULT) && (collate_type <= MEDIA_CONTENT_COLLATE_LOCALIZED))) {
303 _filter->is_full_order = false;
305 SAFE_FREE(_filter->order_keyword);
307 _filter->order_keyword = strdup(order_keyword);
308 media_content_retvm_if(_filter->order_keyword == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
310 _filter->order_type = order_type;
311 _filter->order_collate_type = collate_type;
313 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
314 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
320 int media_filter_set_storage(filter_h filter, const char *storage_id)
322 int ret = MEDIA_CONTENT_ERROR_NONE;
323 media_content_warn("DEPRECATION WARNING: media_filter_set_storage() is deprecated and will be removed from next release. Use media_filter_set_condition() with MEDIA_PATH keyword instead.");
324 filter_s *_filter = (filter_s*)filter;
326 if ((_filter != NULL) && STRING_VALID(storage_id)) {
327 if (STRING_VALID(_filter->storage_id))
328 SAFE_FREE(_filter->storage_id);
330 _filter->storage_id = strdup(storage_id);
331 media_content_retvm_if(_filter->storage_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
333 media_content_sec_debug("storage_id : %s", _filter->storage_id);
335 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
336 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
342 int media_filter_get_offset(filter_h filter, int *offset, int *count)
344 int ret = MEDIA_CONTENT_ERROR_NONE;
345 filter_s *_filter = (filter_s*)filter;
348 *offset = _filter->offset;
349 *count = _filter->count;
351 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
352 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
358 int media_filter_get_condition(filter_h filter, char **condition, media_content_collation_e *collate_type)
360 int ret = MEDIA_CONTENT_ERROR_NONE;
361 filter_s *_filter = (filter_s*)filter;
364 if (STRING_VALID(_filter->condition) && _filter->is_full_condition == false) {
365 char new_condition[MAX_QUERY_SIZE] = {0, };
366 memset(new_condition, 0, sizeof(new_condition));
367 ret = _media_content_replace_path_in_condition(_filter->condition, new_condition, FALSE);
368 media_content_retvm_if(!STRING_VALID(new_condition), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed");
370 *condition = strdup(new_condition);
371 media_content_retvm_if(*condition == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
376 *collate_type = _filter->condition_collate_type;
378 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
379 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
385 int media_filter_get_order(filter_h filter, media_content_order_e* order_type, char **order_keyword, media_content_collation_e *collate_type)
387 int ret = MEDIA_CONTENT_ERROR_NONE;
388 filter_s *_filter = (filter_s*)filter;
391 if (STRING_VALID(_filter->order_keyword) && _filter->is_full_order == false) {
392 *order_keyword = strdup(_filter->order_keyword);
393 media_content_retvm_if(*order_keyword == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
395 *order_keyword = NULL;
398 *order_type = _filter->order_type;
399 *collate_type = _filter->order_collate_type;
401 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
402 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
408 int media_filter_get_storage(filter_h filter, char **storage_id)
410 int ret = MEDIA_CONTENT_ERROR_NONE;
411 media_content_warn("DEPRECATION WARNING: media_filter_get_storage() is deprecated and will be removed from next release.");
412 filter_s *_filter = (filter_s*)filter;
415 if (STRING_VALID(_filter->storage_id)) {
416 *storage_id = strdup(_filter->storage_id);
417 media_content_retvm_if(*storage_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
422 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
423 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
429 int media_filter_set_condition_v2(filter_h filter, const char *condition)
431 int ret = MEDIA_CONTENT_ERROR_NONE;
432 filter_s *_filter = (filter_s*)filter;
434 if ((_filter != NULL) && STRING_VALID(condition)) {
435 _filter->is_full_condition = true;
437 if (STRING_VALID(_filter->condition))
438 SAFE_FREE(_filter->condition);
440 char new_condition[MAX_QUERY_SIZE] = {0, };
441 memset(new_condition, 0, sizeof(new_condition));
442 ret = _media_content_replace_path_in_condition(condition, new_condition, TRUE);
443 media_content_retvm_if(!STRING_VALID(new_condition), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed");
445 _filter->condition = strdup(new_condition);
446 media_content_retvm_if(_filter->condition == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
448 media_content_sec_debug("Condition string : %s", _filter->condition);
450 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
451 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
457 int media_filter_get_condition_v2(filter_h filter, char **condition)
459 int ret = MEDIA_CONTENT_ERROR_NONE;
460 filter_s *_filter = (filter_s*)filter;
463 if (STRING_VALID(_filter->condition) && _filter->is_full_condition == true) {
464 char new_condition[MAX_QUERY_SIZE] = {0, };
465 memset(new_condition, 0, sizeof(new_condition));
466 ret = _media_content_replace_path_in_condition(_filter->condition, new_condition, FALSE);
467 media_content_retvm_if(!STRING_VALID(new_condition), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed");
469 *condition = strdup(new_condition);
470 media_content_retvm_if(*condition == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
475 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
476 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
482 int media_filter_set_order_v2(filter_h filter, const char *order)
484 int ret = MEDIA_CONTENT_ERROR_NONE;
485 filter_s *_filter = (filter_s*)filter;
487 if ((_filter != NULL) && STRING_VALID(order)) {
488 _filter->is_full_order = true;
490 SAFE_FREE(_filter->order_keyword);
492 _filter->order_keyword = strdup(order);
493 media_content_retvm_if(_filter->order_keyword == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
495 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
496 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
502 int media_filter_get_order_v2(filter_h filter, char **order)
504 int ret = MEDIA_CONTENT_ERROR_NONE;
505 filter_s *_filter = (filter_s*)filter;
508 if (STRING_VALID(_filter->order_keyword) && _filter->is_full_order == true) {
509 *order = strdup(_filter->order_keyword);
510 media_content_retvm_if(*order == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
515 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
516 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;