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_content.h>
19 #include <media_info_private.h>
20 #include <media-svc.h>
22 static char *media_token[] =
37 typedef struct _token_t
44 #define MAX_LEFT_VALUE 512
47 #define UNKNOWN_TYPE 1000
48 #define STRING_TYPE 100
50 static char *__get_order_str(media_content_order_e order_enum);
51 static char *__get_collate_str(media_content_collation_e collate_type);
52 static void __filter_attribute_free_value(gpointer key, gpointer value, gpointer user_data);
53 static char *__media_filter_replace_attr(attribute_h attr, char *name);
54 static int __tokenize_operator(token_t *token, const char *str, int op_type);
55 static int __tokenize(GList **token_list, const char *str);
57 static char *__get_order_str(media_content_order_e order_enum)
60 case MEDIA_CONTENT_ORDER_ASC:
62 case MEDIA_CONTENT_ORDER_DESC:
69 static char *__get_collate_str(media_content_collation_e collate_type)
71 switch(collate_type) {
72 case MEDIA_CONTENT_COLLATE_NOCASE:
74 case MEDIA_CONTENT_COLLATE_RTRIM:
80 static void __filter_attribute_free_value(gpointer key, gpointer value, gpointer user_data)
86 static char *__media_filter_replace_attr(attribute_h attr, char *name)
89 char *generated_value;
90 attribute_s *_attr = (attribute_s *)attr;
92 if(!g_hash_table_lookup_extended(_attr->attr_map,
94 (gpointer)&key_temp, (gpointer)&generated_value))
96 //can't find the value
97 //media_content_error("NOT_FOUND_VALUE(%s)", name);
101 if(STRING_VALID(generated_value))
103 return strdup(generated_value);
106 media_content_error("__media_filter_replace_attr fail");
111 static int __tokenize_operator(token_t *token, const char *str, int op_type)
114 const char *tmp = str;
116 if(token != NULL && STRING_VALID(tmp))
118 token->type = op_type;
119 int token_size = strlen(media_token[op_type]);
120 token->str = (char*)calloc(token_size+1, sizeof(char));
121 strncpy(token->str, tmp, token_size);
122 media_content_debug("type : [%d] str : [%s] \n", token->type, token->str);
133 static int __tokenize_string(token_t *token, const char *str, int size)
136 const char *tmp = str;
138 if(token != NULL && STRING_VALID(tmp) && size > 0)
140 token->str = (char*)calloc(size+1, sizeof(char));
141 token->type = UNKNOWN_TYPE;
142 strncpy(token->str, tmp, size);
143 media_content_debug("type : [%d] str : [%s] \n", token->type, token->str);
153 static int __tokenize_attribute(GList **token_list, const char *str)
158 if(!STRING_VALID(str)) {
159 media_content_error("Parameter string in invalid");
160 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
163 const char *tmp = str;
164 const char *dst_ptr = str + strlen(str);
166 for (idx = 0; (*(tmp+idx)) && (tmp < dst_ptr); idx++)
168 //media_content_debug("[%d] '%c'", idx, tmp[idx]);
169 if(tmp[idx] == ' ') //" "
171 if(idx == 0) // ignore the space.
178 token_t *token = (token_t*)calloc(1, sizeof(token_t));
179 token->type = UNKNOWN_TYPE;
180 token->str = (char*)calloc(idx+1, sizeof(char));
181 strncpy(token->str, tmp, idx);
182 media_content_debug("type : [%d] str : [%s] \n", token->type, token->str);
183 *token_list = g_list_append(*token_list, token);
184 tmp = tmp +idx + strlen(media_token[0]);
187 else if(tmp[idx] == ',') // " , "
191 token_t *token = (token_t*)calloc(1, sizeof(token_t));
192 ret = __tokenize_string(token, tmp, idx);
195 media_content_error("tokenize error occued");
200 *token_list = g_list_append(*token_list, token);
204 token_t *token = (token_t*)calloc(1, sizeof(token_t));
205 int size = __tokenize_operator(token, tmp,3);
207 if(token != NULL && STRING_VALID(token->str))
209 *token_list = g_list_append(*token_list, token);
215 media_content_error("tokenize error occued");
221 if(*tmp) //remained string
223 token_t *token = (token_t*)calloc(1, sizeof(token_t));
224 __tokenize_string(token, tmp, idx);
225 if(token != NULL && STRING_VALID(token->str))
227 *token_list = g_list_append(*token_list, token);
231 media_content_error("tokenize error occued");
236 return MEDIA_CONTENT_ERROR_NONE;
239 static int __tokenize(GList **token_list, const char *str)
244 if(!STRING_VALID(str)) {
245 media_content_error("Parameter string in invalid");
246 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
249 const char *tmp = str;
250 const char *dst_ptr = str + strlen(str);
252 for (idx = 0; (*(tmp+idx)) && (tmp < dst_ptr); idx++)
254 //media_content_debug("[%d] '%c'", idx, tmp[idx]);
255 if(tmp[idx] == media_token[0][0]) //" "
257 if(idx == 0) // ignore the space.
264 token_t *token = (token_t*)calloc(1, sizeof(token_t));
265 token->type = UNKNOWN_TYPE;
266 token->str = (char*)calloc(idx+1, sizeof(char));
267 strncpy(token->str, tmp, idx);
268 media_content_debug("type : [%d] str : [%s] \n", token->type, token->str);
269 *token_list = g_list_append(*token_list, token);
270 tmp = tmp +idx + strlen(media_token[0]);
273 else if(tmp[idx] == media_token[1][0]) // " \" "
276 for(j = idx+1; tmp[j]; j++) //find next quotation
278 if(tmp[j] == media_token[1][0] && tmp[j+1] == media_token[1][0])
283 if(tmp[j] == media_token[1][0])
285 token_t *token = (token_t*)calloc(1, sizeof(token_t));
286 token->str = (char*) calloc(j+1+1, sizeof(char));
287 token->type = STRING_TYPE;
288 strncpy(token->str, tmp, j+1);
289 media_content_debug("type : [%d] str : [%s], j : %d \n", token->type, token->str, j);
290 *token_list = g_list_append(*token_list, token);
291 tmp = tmp + strlen(token->str);
297 if(*tmp != '\0' && tmp[j]=='\0')
299 token_t *token = (token_t*)calloc(1, sizeof(token_t));
300 token->str = (char*) calloc(j+1,sizeof(char));
301 token->type = UNKNOWN_TYPE;
302 strncpy(token->str, tmp,j);
303 media_content_debug("type : [%d] str : [%s] \n", token->type, token->str);
304 *token_list = g_list_append(*token_list, token);
305 tmp = tmp +strlen(token->str);
309 else if(tmp[idx] == media_token[2][0]) // " \' "
312 for(j = idx+1; tmp[j]; j++)
314 if(tmp[j] == media_token[2][0] && tmp[j+1] == media_token[2][0])
319 if(tmp[j] == media_token[2][0])
321 token_t *token = (token_t*)calloc(1, sizeof(token_t));
322 token->str = (char*) calloc(j+1+1, sizeof(char));
323 token->type = STRING_TYPE;
324 strncpy(token->str, tmp, j+1);
325 media_content_debug("type : [%d] str : [%s] \n", token->type, token->str);
326 *token_list = g_list_append(*token_list, token);
327 tmp = tmp + strlen(token->str);
333 if(*tmp != '\0' && tmp[j]=='\0')
335 token_t *token = (token_t*)calloc(1, sizeof(token_t));
336 token->str = (char*) calloc(j+1,sizeof(char));
337 token->type = UNKNOWN_TYPE;
338 strncpy(token->str, tmp,j);
339 media_content_debug("type : [%d] str : [%s] \n", token->type, token->str);
340 *token_list = g_list_append(*token_list, token);
341 tmp = tmp + strlen(token->str);
345 else if(tmp[idx] == media_token[3][0]) //"("
349 token_t *token = (token_t*)calloc(1, sizeof(token_t));
350 ret = __tokenize_string(token, tmp, idx);
353 media_content_error("tokenize error occued");
358 *token_list = g_list_append(*token_list, token);
362 token_t *token = (token_t*)calloc(1, sizeof(token_t));
363 int size = __tokenize_operator(token, tmp,3);
365 if(token != NULL && STRING_VALID(token->str))
367 *token_list = g_list_append(*token_list, token);
373 media_content_error("tokenize error occued");
378 else if(tmp[idx] == media_token[4][0]) //")"
382 token_t *token = (token_t*)calloc(1, sizeof(token_t));
383 ret = __tokenize_string(token, tmp, idx);
386 media_content_error("tokenize error occued");
391 *token_list = g_list_append(*token_list, token);
395 token_t *token = (token_t*)calloc(1, sizeof(token_t));
396 int size = __tokenize_operator(token, tmp,4);
398 if(token != NULL && STRING_VALID(token->str))
400 *token_list = g_list_append(*token_list, token);
406 media_content_error("tokenize error occued");
411 else if(tmp[idx] == media_token[5][0]) //"="
415 token_t *token = (token_t*)calloc(1, sizeof(token_t));
416 ret = __tokenize_string(token, tmp, idx);
419 media_content_error("tokenize error occued");
424 *token_list = g_list_append(*token_list, token);
428 token_t *token = (token_t*)calloc(1, sizeof(token_t));
429 int size = __tokenize_operator(token, tmp,5);
431 if(token != NULL && STRING_VALID(token->str))
433 *token_list = g_list_append(*token_list, token);
439 media_content_error("tokenize error occued");
444 else if(tmp[idx] == media_token[6][0] && tmp[idx+1] == media_token[6][1]) //"<=",
448 token_t *token = (token_t*)calloc(1, sizeof(token_t));
449 ret = __tokenize_string(token, tmp, idx);
452 media_content_error("tokenize error occued");
457 *token_list = g_list_append(*token_list, token);
461 token_t *token = (token_t*)calloc(1, sizeof(token_t));
462 int size = __tokenize_operator(token, tmp,6);
464 if(token != NULL && STRING_VALID(token->str))
466 *token_list = g_list_append(*token_list, token);
472 media_content_error("tokenize error occued");
477 else if(tmp[idx] == media_token[7][0]) //"<",
481 token_t *token = (token_t*)calloc(1, sizeof(token_t));
482 ret = __tokenize_string(token, tmp, idx);
485 media_content_error("tokenize error occued");
490 *token_list = g_list_append(*token_list, token);
494 token_t *token = (token_t*)calloc(1, sizeof(token_t));
495 int size = __tokenize_operator(token, tmp,7);
497 if(token != NULL && STRING_VALID(token->str))
499 *token_list = g_list_append(*token_list, token);
505 media_content_error("tokenize error occued");
510 else if(tmp[idx] == media_token[8][0] && tmp[idx+1] == media_token[8][1]) //">=",
514 token_t *token = (token_t*)calloc(1, sizeof(token_t));
515 ret = __tokenize_string(token, tmp, idx);
518 media_content_error("tokenize error occued");
523 *token_list = g_list_append(*token_list, token);
527 token_t *token = (token_t*)calloc(1, sizeof(token_t));
528 int size = __tokenize_operator(token, tmp,8);
530 if(token != NULL && STRING_VALID(token->str))
532 *token_list = g_list_append(*token_list, token);
538 media_content_error("tokenize error occued");
543 else if(tmp[idx] == media_token[9][0]) //">",
547 token_t *token = (token_t*)calloc(1, sizeof(token_t));
548 ret = __tokenize_string(token, tmp, idx);
551 media_content_error("tokenize error occued");
556 *token_list = g_list_append(*token_list, token);
560 token_t *token = (token_t*)calloc(1, sizeof(token_t));
561 int size = __tokenize_operator(token, tmp,9);
563 if(token != NULL && STRING_VALID(token->str))
565 *token_list = g_list_append(*token_list, token);
571 media_content_error("tokenize error occued");
578 if(*tmp) //remained string
580 token_t *token = (token_t*)calloc(1, sizeof(token_t));
581 __tokenize_string(token, tmp, idx);
582 if(token != NULL && STRING_VALID(token->str))
584 *token_list = g_list_append(*token_list, token);
588 media_content_error("tokenize error occued");
593 return MEDIA_CONTENT_ERROR_NONE;
596 int _media_filter_attribute_create(attribute_h *attr)
598 int ret = MEDIA_CONTENT_ERROR_NONE;
602 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
603 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
606 attribute_s *_attr = (attribute_s*)calloc(1, sizeof(attribute_s));
610 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
611 ret = MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
615 _attr->attr_map = g_hash_table_new (g_str_hash, g_str_equal);
616 *attr = (attribute_h)_attr;
622 int _media_filter_attribute_add(attribute_h attr, char *user_attr, char *platform_attr)
624 int ret = MEDIA_CONTENT_ERROR_NONE;
626 char *_platform = NULL;
627 attribute_s *_attr = (attribute_s*)attr;
631 if(STRING_VALID(user_attr) && STRING_VALID(platform_attr))
633 _user = strdup(user_attr);
636 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
637 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
640 _platform = strdup(platform_attr);
641 if(_platform == NULL)
644 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
645 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
648 g_hash_table_insert (_attr->attr_map, _user, _platform);
652 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
653 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
658 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
659 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
665 int _media_filter_attribute_destory(attribute_h attr)
667 int ret = MEDIA_CONTENT_ERROR_NONE;
668 attribute_s *_attr = (attribute_s*)attr;
672 if(_attr->attr_map != NULL)
674 g_hash_table_foreach(_attr->attr_map, __filter_attribute_free_value, NULL);
675 g_hash_table_destroy(_attr->attr_map);
682 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
683 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
689 int _media_filter_attribute_generate(attribute_h attr, char *condition, media_content_collation_e collate_type, char **generated_condition)
692 GList *token_list = NULL;
694 int ret = MEDIA_CONTENT_ERROR_NONE;
695 int total_str_size = 0;
698 if((condition == NULL) || (generated_condition == NULL))
700 media_content_error("INVALID_PARAMETER(0x%08x):Invalid the condition", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
701 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
706 if(__tokenize(&token_list, condition) < 0)
708 media_content_error("INVALID_PARAMETER(0x%08x):Invalid the condition", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
709 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
712 for(idx = 0; idx < g_list_length(token_list); idx++)
714 token = (token_t*)g_list_nth_data(token_list, idx);
716 if(token->type == UNKNOWN_TYPE)
718 char *replace_str = __media_filter_replace_attr(attr, token->str);
719 if(STRING_VALID(replace_str))
721 SAFE_FREE(token->str);
722 token->str = replace_str;
726 total_str_size += strlen(token->str)+1;
727 media_content_debug("[%d][type:%d]:%s\n", idx, token->type, token->str);
731 size = total_str_size + COLLATE_STR_SIZE + 1;
732 * generated_condition = (char*)calloc(size, sizeof(char));
734 for(idx = 0; idx < g_list_length(token_list); idx++)
736 token = (token_t*)g_list_nth_data(token_list, idx);
738 if((token != NULL) && STRING_VALID(token->str))
740 SAFE_STRLCAT(*generated_condition, token->str, size);
741 SAFE_STRLCAT(*generated_condition, SPACE, size);
743 SAFE_FREE(token->str);
748 if(collate_type == MEDIA_CONTENT_COLLATE_NOCASE || collate_type == MEDIA_CONTENT_COLLATE_RTRIM) {
749 SAFE_STRLCAT(*generated_condition, "COLLATE ", size);
750 SAFE_STRLCAT(*generated_condition, __get_collate_str(collate_type), size);
751 SAFE_STRLCAT(*generated_condition, SPACE, size);
754 media_content_debug("statement : %s(%d) (total:%d) \n", *generated_condition, strlen(*generated_condition), total_str_size);
755 media_content_debug("Condition : %s", *generated_condition);
757 //if(*generated_condition != NULL)
760 if(token_list != NULL)
761 g_list_free(token_list);
765 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
766 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
772 int _media_filter_attribute_option_generate(attribute_h attr, filter_h filter, char **generated_option)
774 int ret = MEDIA_CONTENT_ERROR_NONE;
775 filter_s *_filter = NULL;
776 char option_query[DEFAULT_QUERY_SIZE] = {0, };
777 char condition[DEFAULT_QUERY_SIZE] = {0, };
779 //bool order_by = true;
781 media_content_debug_func();
785 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
786 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
791 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
792 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
795 _filter = (filter_s*)filter;
797 memset(option_query, 0x00, sizeof(option_query));
800 if(STRING_VALID(_filter->order_keyword) && ((_filter->order_type == MEDIA_CONTENT_ORDER_ASC) ||(_filter->order_type == MEDIA_CONTENT_ORDER_DESC)))
803 int total_str_size = 0;
804 GList *token_list = NULL;
808 media_content_debug("Tokenize for [%s]", _filter->order_keyword);
809 if(__tokenize_attribute(&token_list, _filter->order_keyword) < 0)
811 media_content_error("INVALID_PARAMETER(0x%08x):Invalid the condition", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
812 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
815 for(idx = 0; idx < g_list_length(token_list); idx++)
817 token = (token_t*)g_list_nth_data(token_list, idx);
819 if(token->type == UNKNOWN_TYPE)
821 char *replace_str = __media_filter_replace_attr(attr, token->str);
822 if(STRING_VALID(replace_str))
824 attr_str = (char*)calloc(strlen(replace_str) + COLLATE_STR_SIZE + 1, sizeof(char));
826 if(_filter->order_collate_type == MEDIA_CONTENT_COLLATE_NOCASE || _filter->order_collate_type == MEDIA_CONTENT_COLLATE_RTRIM) {
827 snprintf(attr_str, strlen(replace_str) + COLLATE_STR_SIZE + 1, "%s COLLATE %s %s", replace_str, __get_collate_str(_filter->order_collate_type), __get_order_str(_filter->order_type));
829 snprintf(attr_str, strlen(replace_str) + COLLATE_STR_SIZE + 1, "%s %s", replace_str, __get_order_str(_filter->order_type));
832 SAFE_FREE(token->str);
833 token->str = attr_str;
834 SAFE_FREE(replace_str);
838 media_content_error("There is no matched db field for %s", token->str);
842 total_str_size += strlen(token->str) + 1;
843 media_content_debug("[%d][type:%d]:%s\n", idx, token->type, token->str);
847 char *generated_condition = NULL;
848 size = total_str_size + COLLATE_STR_SIZE + 1;
849 generated_condition = (char*)calloc(size, sizeof(char));
851 for(idx = 0; idx < g_list_length(token_list); idx++)
853 token = (token_t*)g_list_nth_data(token_list, idx);
855 if((token != NULL) && STRING_VALID(token->str))
857 media_content_debug("[%d] %s", idx, token->str);
858 SAFE_STRLCAT(generated_condition, token->str, size);
859 SAFE_STRLCAT(generated_condition, SPACE, size);
861 SAFE_FREE(token->str);
866 snprintf(condition, sizeof(condition), "ORDER BY %s", generated_condition);
867 SAFE_STRLCAT(option_query, condition, sizeof(option_query));
869 if(token_list != NULL)
870 g_list_free(token_list);
874 if((_filter->offset >= 0) && (_filter->count >= 0))
876 SAFE_STRLCAT(option_query, SPACE, sizeof(option_query));
877 snprintf(condition, sizeof(condition), "LIMIT %d, %d", _filter->offset, _filter->count);
878 SAFE_STRLCAT(option_query, condition, sizeof(option_query));
881 if(STRING_VALID(option_query))
883 *generated_option = strdup(option_query);
887 *generated_option = NULL;
893 int media_filter_create(filter_h *filter)
895 int ret = MEDIA_CONTENT_ERROR_NONE;
899 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
900 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
903 filter_s *_filter = (filter_s*)calloc(1, sizeof(filter_s));
907 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
908 ret = MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
912 _filter->condition = NULL;
913 _filter->order_keyword = NULL;
914 _filter->order_type = -1;
915 _filter->condition_collate_type = MEDIA_CONTENT_COLLATE_DEFAULT;
916 _filter->order_collate_type = MEDIA_CONTENT_COLLATE_DEFAULT;
917 _filter->offset = -1;
920 *filter = (filter_h)_filter;
926 int media_filter_destroy(filter_h filter)
928 int ret = MEDIA_CONTENT_ERROR_NONE;
929 filter_s *_filter = (filter_s*)filter;
933 SAFE_FREE(_filter->condition);
934 SAFE_FREE(_filter->order_keyword);
937 ret = MEDIA_CONTENT_ERROR_NONE;
941 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
942 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
948 int media_filter_set_offset(filter_h filter, int offset, int count)
950 int ret = MEDIA_CONTENT_ERROR_NONE;
951 filter_s *_filter = (filter_s*)filter;
955 _filter->offset = offset;
956 _filter->count = count;
960 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
961 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
967 int media_filter_set_condition(filter_h filter, const char *condition, media_content_collation_e collate_type)
969 int ret = MEDIA_CONTENT_ERROR_NONE;
970 filter_s *_filter = (filter_s*)filter;
972 if((_filter != NULL) && STRING_VALID(condition)
973 && ((collate_type >= MEDIA_CONTENT_COLLATE_DEFAULT) && (collate_type <= MEDIA_CONTENT_COLLATE_RTRIM)))
975 if(STRING_VALID(_filter->condition))
977 SAFE_FREE(_filter->condition);
980 _filter->condition = strdup(condition);
981 if(_filter->condition == NULL)
983 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
984 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
987 media_content_debug("Condition string : %s", _filter->condition);
989 _filter->condition_collate_type = collate_type;
993 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
994 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1000 int media_filter_set_order(filter_h filter, media_content_order_e order_type, const char *order_keyword, media_content_collation_e collate_type)
1002 int ret = MEDIA_CONTENT_ERROR_NONE;
1003 filter_s *_filter = (filter_s*)filter;
1005 if((_filter != NULL) && STRING_VALID(order_keyword)
1006 && ((order_type == MEDIA_CONTENT_ORDER_ASC) ||(order_type == MEDIA_CONTENT_ORDER_DESC))
1007 && ((collate_type >= MEDIA_CONTENT_COLLATE_DEFAULT) && (collate_type <= MEDIA_CONTENT_COLLATE_RTRIM)))
1009 SAFE_FREE(_filter->order_keyword);
1011 if(STRING_VALID(order_keyword))
1013 _filter->order_keyword = strdup(order_keyword);
1015 if(_filter->order_keyword == NULL)
1017 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1018 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1020 _filter->order_type = order_type;
1021 _filter->order_collate_type = collate_type;
1025 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1026 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1031 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1032 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1038 int media_filter_get_offset(filter_h filter, int *offset, int *count)
1040 int ret = MEDIA_CONTENT_ERROR_NONE;
1041 filter_s *_filter = (filter_s*)filter;
1045 *offset = _filter->offset;
1046 *count = _filter->count;
1050 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1051 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1057 int media_filter_get_condition(filter_h filter, char **condition, media_content_collation_e *collate_type)
1059 int ret = MEDIA_CONTENT_ERROR_NONE;
1060 filter_s *_filter = (filter_s*)filter;
1064 if(STRING_VALID(_filter->condition))
1066 *condition = strdup(_filter->condition);
1067 if(*condition == NULL)
1069 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1070 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1078 *collate_type = _filter->condition_collate_type;
1082 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1083 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1089 int media_filter_get_order(filter_h filter, media_content_order_e* order_type, char **order_keyword, media_content_collation_e *collate_type)
1091 int ret = MEDIA_CONTENT_ERROR_NONE;
1092 filter_s *_filter = (filter_s*)filter;
1096 if(STRING_VALID(_filter->order_keyword))
1098 *order_keyword = strdup(_filter->order_keyword);
1099 if(*order_keyword == NULL)
1101 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1102 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1107 *order_keyword = NULL;
1110 *order_type = _filter->order_type;
1111 *collate_type = _filter->order_collate_type;
1115 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1116 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;