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)
88 char *key_temp = NULL;
89 char *generated_value = NULL;
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]);
122 media_content_error("Invalid token_size. op_type[%d]", op_type);
126 token->str = (char*)calloc(token_size+1, sizeof(char));
127 if(token->str == NULL)
129 media_content_error("OUT_OF_MEMORY");
133 strncpy(token->str, tmp, token_size);
134 //media_content_debug("type : [%d] str : [%s]", token->type, token->str);
145 static int __tokenize_string(token_t *token, const char *str, int size)
148 const char *tmp = str;
150 if(token != NULL && STRING_VALID(tmp) && size > 0)
152 token->str = (char*)calloc(size+1, sizeof(char));
153 if(token->str == NULL)
155 media_content_error("OUT_OF_MEMORY");
158 token->type = UNKNOWN_TYPE;
159 strncpy(token->str, tmp, size);
160 //media_content_debug("type : [%d] str : [%s]", token->type, token->str);
170 static int __tokenize_attribute(GList **token_list, const char *str)
175 if(!STRING_VALID(str)) {
176 media_content_error("Parameter string in invalid");
177 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
180 const char *tmp = str;
181 const char *dst_ptr = str + strlen(str);
183 for (idx = 0; (*(tmp+idx)) && (tmp < dst_ptr); idx++)
185 //media_content_debug("[%d] '%c'", idx, tmp[idx]);
186 if(tmp[idx] == ' ') //" "
188 if(idx == 0) // ignore the space.
194 token_t *token = (token_t*)calloc(1, sizeof(token_t));
195 token->type = UNKNOWN_TYPE;
196 token->str = (char*)calloc(idx+1, sizeof(char));
197 strncpy(token->str, tmp, idx);
198 media_content_debug("type : [%d] str : [%s]", token->type, token->str);
199 *token_list = g_list_append(*token_list, token);
200 tmp = tmp +idx + strlen(media_token[0]);
203 else if(tmp[idx] == ',') // " , "
207 token_t *token = (token_t*)calloc(1, sizeof(token_t));
210 media_content_error("OUT_OF_MEMORY");
213 ret = __tokenize_string(token, tmp, idx);
217 media_content_error("tokenize error occued");
222 *token_list = g_list_append(*token_list, token);
227 token_t *token = (token_t*)calloc(1, sizeof(token_t));
228 int size = __tokenize_operator(token, tmp,3);
230 if(token != NULL && STRING_VALID(token->str))
232 *token_list = g_list_append(*token_list, token);
239 media_content_error("tokenize error occued");
245 if(*tmp) //remained string
247 token_t *token = (token_t*)calloc(1, sizeof(token_t));
250 media_content_error("OUT_OF_MEMORY");
254 ret = __tokenize_string(token, tmp, idx);
258 media_content_error("tokenize error occued");
262 if(token != NULL && STRING_VALID(token->str))
264 *token_list = g_list_append(*token_list, token);
269 media_content_error("tokenize error occued");
274 return MEDIA_CONTENT_ERROR_NONE;
277 static int __tokenize(GList **token_list, const char *str)
282 if(!STRING_VALID(str)) {
283 media_content_error("Parameter string in invalid");
284 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
287 const char *tmp = str;
288 const char *dst_ptr = str + strlen(str);
290 for (idx = 0; (*(tmp+idx)) && (tmp < dst_ptr); idx++)
292 //media_content_debug("[%d] '%c'", idx, tmp[idx]);
293 if(tmp[idx] == media_token[0][0]) //" "
295 if(idx == 0) // ignore the space.
302 token_t *token = (token_t*)calloc(1, sizeof(token_t));
303 token->type = UNKNOWN_TYPE;
304 token->str = (char*)calloc(idx+1, sizeof(char));
305 strncpy(token->str, tmp, idx);
306 //media_content_debug("type : [%d] str : [%s]", token->type, token->str);
307 *token_list = g_list_append(*token_list, token);
308 tmp = tmp +idx + strlen(media_token[0]);
311 else if(tmp[idx] == media_token[1][0]) // " \" "
315 for(j = idx+1; tmp[j]; j++) //find next quotation
317 if(tmp[j] == media_token[1][0] && tmp[j+1] == media_token[1][0])
322 if(tmp[j] == media_token[1][0])
324 token_t *token = (token_t*)calloc(1, sizeof(token_t));
325 token->str = (char*) calloc(j+1+1, sizeof(char));
326 token->type = STRING_TYPE;
327 strncpy(token->str, tmp, j+1);
328 media_content_debug("type : [%d] str : [%s], j : %d", token->type, token->str, j);
329 *token_list = g_list_append(*token_list, token);
330 tmp = tmp + strlen(token->str);
337 if(!flag && *tmp != '\0' && tmp[j]=='\0')
339 token_t *token = (token_t*)calloc(1, sizeof(token_t));
340 token->str = (char*) calloc(j+1,sizeof(char));
341 token->type = UNKNOWN_TYPE;
342 strncpy(token->str, tmp,j);
343 media_content_debug("type : [%d] str : [%s]", token->type, token->str);
344 *token_list = g_list_append(*token_list, token);
345 tmp = tmp +strlen(token->str);
349 else if(tmp[idx] == media_token[2][0]) // " \' "
353 for(j = idx+1; tmp[j]; j++)
355 if(tmp[j] == media_token[2][0] && tmp[j+1] == media_token[2][0])
360 if(tmp[j] == media_token[2][0])
362 token_t *token = (token_t*)calloc(1, sizeof(token_t));
363 token->str = (char*) calloc(j+1+1, sizeof(char));
364 token->type = STRING_TYPE;
365 strncpy(token->str, tmp, j+1);
366 //media_content_debug("type : [%d] str : [%s]", token->type, token->str);
367 *token_list = g_list_append(*token_list, token);
368 tmp = tmp + strlen(token->str);
375 if(!flag && *tmp != '\0' && tmp[j]=='\0')
377 token_t *token = (token_t*)calloc(1, sizeof(token_t));
378 token->str = (char*) calloc(j+1,sizeof(char));
379 token->type = UNKNOWN_TYPE;
380 strncpy(token->str, tmp,j);
381 media_content_debug("type : [%d] str : [%s]", token->type, token->str);
382 *token_list = g_list_append(*token_list, token);
383 tmp = tmp + strlen(token->str);
387 else if(tmp[idx] == media_token[3][0]) //"("
391 token_t *token = (token_t*)calloc(1, sizeof(token_t));
394 media_content_error("OUT_OF_MEMORY");
397 ret = __tokenize_string(token, tmp, idx);
401 media_content_error("tokenize error occued");
406 *token_list = g_list_append(*token_list, token);
410 token_t *token = (token_t*)calloc(1, sizeof(token_t));
411 int size = __tokenize_operator(token, tmp,3);
413 if(token != NULL && STRING_VALID(token->str))
415 *token_list = g_list_append(*token_list, token);
422 media_content_error("tokenize error occued");
427 else if(tmp[idx] == media_token[4][0]) //")"
431 token_t *token = (token_t*)calloc(1, sizeof(token_t));
434 media_content_error("OUT_OF_MEMORY");
438 ret = __tokenize_string(token, tmp, idx);
442 media_content_error("tokenize error occued");
447 *token_list = g_list_append(*token_list, token);
451 token_t *token = (token_t*)calloc(1, sizeof(token_t));
452 int size = __tokenize_operator(token, tmp,4);
454 if(token != NULL && STRING_VALID(token->str))
456 *token_list = g_list_append(*token_list, token);
463 media_content_error("tokenize error occued");
468 else if(tmp[idx] == media_token[5][0]) //"="
472 token_t *token = (token_t*)calloc(1, sizeof(token_t));
475 media_content_error("OUT_OF_MEMORY");
479 ret = __tokenize_string(token, tmp, idx);
483 media_content_error("tokenize error occued");
488 *token_list = g_list_append(*token_list, token);
492 token_t *token = (token_t*)calloc(1, sizeof(token_t));
493 int size = __tokenize_operator(token, tmp,5);
495 if(token != NULL && STRING_VALID(token->str))
497 *token_list = g_list_append(*token_list, token);
504 media_content_error("tokenize error occued");
509 else if(tmp[idx] == media_token[6][0] && tmp[idx+1] == media_token[6][1]) //"<=",
513 token_t *token = (token_t*)calloc(1, sizeof(token_t));
516 media_content_error("OUT_OF_MEMORY");
520 ret = __tokenize_string(token, tmp, idx);
524 media_content_error("tokenize error occued");
529 *token_list = g_list_append(*token_list, token);
533 token_t *token = (token_t*)calloc(1, sizeof(token_t));
534 int size = __tokenize_operator(token, tmp,6);
536 if(token != NULL && STRING_VALID(token->str))
538 *token_list = g_list_append(*token_list, token);
545 media_content_error("tokenize error occued");
550 else if(tmp[idx] == media_token[7][0]) //"<",
554 token_t *token = (token_t*)calloc(1, sizeof(token_t));
557 media_content_error("OUT_OF_MEMORY");
561 ret = __tokenize_string(token, tmp, idx);
565 media_content_error("tokenize error occued");
570 *token_list = g_list_append(*token_list, token);
574 token_t *token = (token_t*)calloc(1, sizeof(token_t));
575 int size = __tokenize_operator(token, tmp,7);
577 if(token != NULL && STRING_VALID(token->str))
579 *token_list = g_list_append(*token_list, token);
586 media_content_error("tokenize error occued");
591 else if(tmp[idx] == media_token[8][0] && tmp[idx+1] == media_token[8][1]) //">=",
595 token_t *token = (token_t*)calloc(1, sizeof(token_t));
598 media_content_error("OUT_OF_MEMORY");
602 ret = __tokenize_string(token, tmp, idx);
606 media_content_error("tokenize error occued");
611 *token_list = g_list_append(*token_list, token);
615 token_t *token = (token_t*)calloc(1, sizeof(token_t));
616 int size = __tokenize_operator(token, tmp,8);
618 if(token != NULL && STRING_VALID(token->str))
620 *token_list = g_list_append(*token_list, token);
627 media_content_error("tokenize error occued");
632 else if(tmp[idx] == media_token[9][0]) //">",
636 token_t *token = (token_t*)calloc(1, sizeof(token_t));
639 media_content_error("OUT_OF_MEMORY");
643 ret = __tokenize_string(token, tmp, idx);
647 media_content_error("tokenize error occued");
652 *token_list = g_list_append(*token_list, token);
656 token_t *token = (token_t*)calloc(1, sizeof(token_t));
657 int size = __tokenize_operator(token, tmp,9);
659 if(token != NULL && STRING_VALID(token->str))
661 *token_list = g_list_append(*token_list, token);
668 media_content_error("tokenize error occued");
675 if(*tmp) //remained string
677 token_t *token = (token_t*)calloc(1, sizeof(token_t));
680 media_content_error("OUT_OF_MEMORY");
684 ret = __tokenize_string(token, tmp, idx);
688 media_content_error("tokenize error occued");
692 if(token != NULL && STRING_VALID(token->str))
694 *token_list = g_list_append(*token_list, token);
699 media_content_error("tokenize error occued");
704 return MEDIA_CONTENT_ERROR_NONE;
707 int _media_filter_attribute_create(attribute_h *attr)
709 int ret = MEDIA_CONTENT_ERROR_NONE;
713 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
714 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
717 attribute_s *_attr = (attribute_s*)calloc(1, sizeof(attribute_s));
721 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
722 ret = MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
726 _attr->attr_map = g_hash_table_new (g_str_hash, g_str_equal);
727 *attr = (attribute_h)_attr;
733 int _media_filter_attribute_add(attribute_h attr, char *user_attr, char *platform_attr)
735 int ret = MEDIA_CONTENT_ERROR_NONE;
737 char *_platform = NULL;
738 attribute_s *_attr = (attribute_s*)attr;
742 if(STRING_VALID(user_attr) && STRING_VALID(platform_attr))
744 _user = strdup(user_attr);
747 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
748 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
751 _platform = strdup(platform_attr);
752 if(_platform == NULL)
755 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
756 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
759 g_hash_table_insert (_attr->attr_map, _user, _platform);
763 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
764 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
769 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
770 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
776 int _media_filter_attribute_destory(attribute_h attr)
778 int ret = MEDIA_CONTENT_ERROR_NONE;
779 attribute_s *_attr = (attribute_s*)attr;
783 if(_attr->attr_map != NULL)
785 g_hash_table_foreach(_attr->attr_map, __filter_attribute_free_value, NULL);
786 g_hash_table_destroy(_attr->attr_map);
793 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
794 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
800 int _media_filter_attribute_generate(attribute_h attr, char *condition, media_content_collation_e collate_type, char **generated_condition)
803 GList *token_list = NULL;
805 int ret = MEDIA_CONTENT_ERROR_NONE;
806 int total_str_size = 0;
809 if((condition == NULL) || (generated_condition == NULL))
811 media_content_error("INVALID_PARAMETER(0x%08x):Invalid the condition", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
812 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
817 if(__tokenize(&token_list, condition) < 0)
819 media_content_error("INVALID_PARAMETER(0x%08x):Invalid the condition", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
820 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
823 for(idx = 0; idx < g_list_length(token_list); idx++)
825 token = (token_t*)g_list_nth_data(token_list, idx);
827 if(token->type == UNKNOWN_TYPE)
829 char *replace_str = __media_filter_replace_attr(attr, token->str);
830 if(STRING_VALID(replace_str))
832 SAFE_FREE(token->str);
833 token->str = replace_str;
837 total_str_size += strlen(token->str)+1;
838 //media_content_debug("[%d][type:%d]:%s", idx, token->type, token->str);
842 size = total_str_size + COLLATE_STR_SIZE + 1;
843 * generated_condition = (char*)calloc(size, sizeof(char));
845 for(idx = 0; idx < g_list_length(token_list); idx++)
847 token = (token_t*)g_list_nth_data(token_list, idx);
849 if((token != NULL) && STRING_VALID(token->str))
851 SAFE_STRLCAT(*generated_condition, token->str, size);
852 SAFE_STRLCAT(*generated_condition, SPACE, size);
854 SAFE_FREE(token->str);
859 if(collate_type == MEDIA_CONTENT_COLLATE_NOCASE || collate_type == MEDIA_CONTENT_COLLATE_RTRIM) {
860 SAFE_STRLCAT(*generated_condition, "COLLATE ", size);
861 SAFE_STRLCAT(*generated_condition, __get_collate_str(collate_type), size);
862 SAFE_STRLCAT(*generated_condition, SPACE, size);
865 media_content_debug("statement : %s(%d) (total:%d)", *generated_condition, strlen(*generated_condition), total_str_size);
866 media_content_debug("Condition : %s", *generated_condition);
868 //if(*generated_condition != NULL)
871 if(token_list != NULL)
872 g_list_free(token_list);
876 media_content_error("DB field mapping table doesn't exist. Check db connection", MEDIA_CONTENT_ERROR_DB_FAILED);
877 return MEDIA_CONTENT_ERROR_DB_FAILED;
883 int _media_filter_attribute_option_generate(attribute_h attr, filter_h filter, char **generated_option)
885 int ret = MEDIA_CONTENT_ERROR_NONE;
886 filter_s *_filter = NULL;
887 char option_query[DEFAULT_QUERY_SIZE] = {0, };
888 char condition[DEFAULT_QUERY_SIZE] = {0, };
890 //bool order_by = true;
892 media_content_debug_func();
896 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
897 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
902 media_content_error("DB field mapping table doesn't exist. Check db connection", MEDIA_CONTENT_ERROR_DB_FAILED);
903 return MEDIA_CONTENT_ERROR_DB_FAILED;
906 _filter = (filter_s*)filter;
908 memset(option_query, 0x00, sizeof(option_query));
911 if(STRING_VALID(_filter->order_keyword) && ((_filter->order_type == MEDIA_CONTENT_ORDER_ASC) ||(_filter->order_type == MEDIA_CONTENT_ORDER_DESC)))
914 int total_str_size = 0;
915 GList *token_list = NULL;
919 media_content_debug("Tokenize for [%s]", _filter->order_keyword);
920 if(__tokenize_attribute(&token_list, _filter->order_keyword) < 0)
922 media_content_error("INVALID_PARAMETER(0x%08x):Invalid the condition", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
923 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
926 for(idx = 0; idx < g_list_length(token_list); idx++)
928 token = (token_t*)g_list_nth_data(token_list, idx);
930 if(token->type == UNKNOWN_TYPE)
932 char *replace_str = __media_filter_replace_attr(attr, token->str);
933 if(STRING_VALID(replace_str))
935 attr_str = (char*)calloc(strlen(replace_str) + COLLATE_STR_SIZE + 1, sizeof(char));
937 if(_filter->order_collate_type == MEDIA_CONTENT_COLLATE_NOCASE || _filter->order_collate_type == MEDIA_CONTENT_COLLATE_RTRIM) {
938 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));
940 snprintf(attr_str, strlen(replace_str) + COLLATE_STR_SIZE + 1, "%s %s", replace_str, __get_order_str(_filter->order_type));
943 SAFE_FREE(token->str);
944 token->str = attr_str;
945 SAFE_FREE(replace_str);
949 media_content_error("There is no matched db field for %s", token->str);
953 total_str_size += strlen(token->str) + 1;
954 media_content_debug("[%d][type:%d]:%s", idx, token->type, token->str);
958 char *generated_condition = NULL;
959 size = total_str_size + COLLATE_STR_SIZE + 1;
960 generated_condition = (char*)calloc(size, sizeof(char));
962 for(idx = 0; idx < g_list_length(token_list); idx++)
964 token = (token_t*)g_list_nth_data(token_list, idx);
966 if((token != NULL) && STRING_VALID(token->str))
968 media_content_debug("[%d] %s", idx, token->str);
969 SAFE_STRLCAT(generated_condition, token->str, size);
970 SAFE_STRLCAT(generated_condition, SPACE, size);
972 SAFE_FREE(token->str);
977 snprintf(condition, sizeof(condition), "ORDER BY %s", generated_condition);
978 SAFE_STRLCAT(option_query, condition, sizeof(option_query));
980 if(token_list != NULL)
981 g_list_free(token_list);
983 SAFE_FREE(generated_condition);
987 SAFE_STRLCAT(option_query, SPACE, sizeof(option_query));
988 snprintf(condition, sizeof(condition), "LIMIT %d, %d", _filter->offset, _filter->count);
989 SAFE_STRLCAT(option_query, condition, sizeof(option_query));
991 if(STRING_VALID(option_query))
993 *generated_option = strdup(option_query);
997 *generated_option = NULL;
1003 int media_filter_create(filter_h *filter)
1005 int ret = MEDIA_CONTENT_ERROR_NONE;
1009 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1010 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1013 filter_s *_filter = (filter_s*)calloc(1, sizeof(filter_s));
1017 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1018 ret = MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1022 _filter->condition = NULL;
1023 _filter->order_keyword = NULL;
1024 _filter->order_type = -1;
1025 _filter->condition_collate_type = MEDIA_CONTENT_COLLATE_DEFAULT;
1026 _filter->order_collate_type = MEDIA_CONTENT_COLLATE_DEFAULT;
1027 _filter->offset = -1;
1028 _filter->count = -1;
1030 *filter = (filter_h)_filter;
1036 int media_filter_destroy(filter_h filter)
1038 int ret = MEDIA_CONTENT_ERROR_NONE;
1039 filter_s *_filter = (filter_s*)filter;
1043 SAFE_FREE(_filter->condition);
1044 SAFE_FREE(_filter->order_keyword);
1047 ret = MEDIA_CONTENT_ERROR_NONE;
1051 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1052 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1058 int media_filter_set_offset(filter_h filter, int offset, int count)
1060 int ret = MEDIA_CONTENT_ERROR_NONE;
1061 filter_s *_filter = (filter_s*)filter;
1065 _filter->offset = offset;
1066 _filter->count = count;
1070 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1071 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1077 int media_filter_set_condition(filter_h filter, const char *condition, media_content_collation_e collate_type)
1079 int ret = MEDIA_CONTENT_ERROR_NONE;
1080 filter_s *_filter = (filter_s*)filter;
1082 if((_filter != NULL) && STRING_VALID(condition)
1083 && ((collate_type >= MEDIA_CONTENT_COLLATE_DEFAULT) && (collate_type <= MEDIA_CONTENT_COLLATE_RTRIM)))
1085 if(STRING_VALID(_filter->condition))
1087 SAFE_FREE(_filter->condition);
1090 _filter->condition = strdup(condition);
1091 if(_filter->condition == NULL)
1093 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1094 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1097 media_content_debug("Condition string : %s", _filter->condition);
1099 _filter->condition_collate_type = collate_type;
1103 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1104 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1110 int media_filter_set_order(filter_h filter, media_content_order_e order_type, const char *order_keyword, media_content_collation_e collate_type)
1112 int ret = MEDIA_CONTENT_ERROR_NONE;
1113 filter_s *_filter = (filter_s*)filter;
1115 if((_filter != NULL) && STRING_VALID(order_keyword)
1116 && ((order_type == MEDIA_CONTENT_ORDER_ASC) ||(order_type == MEDIA_CONTENT_ORDER_DESC))
1117 && ((collate_type >= MEDIA_CONTENT_COLLATE_DEFAULT) && (collate_type <= MEDIA_CONTENT_COLLATE_RTRIM)))
1119 SAFE_FREE(_filter->order_keyword);
1121 if(STRING_VALID(order_keyword))
1123 _filter->order_keyword = strdup(order_keyword);
1125 if(_filter->order_keyword == NULL)
1127 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1128 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1130 _filter->order_type = order_type;
1131 _filter->order_collate_type = collate_type;
1135 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1136 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1141 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1142 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1148 int media_filter_get_offset(filter_h filter, int *offset, int *count)
1150 int ret = MEDIA_CONTENT_ERROR_NONE;
1151 filter_s *_filter = (filter_s*)filter;
1155 *offset = _filter->offset;
1156 *count = _filter->count;
1160 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1161 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1167 int media_filter_get_condition(filter_h filter, char **condition, media_content_collation_e *collate_type)
1169 int ret = MEDIA_CONTENT_ERROR_NONE;
1170 filter_s *_filter = (filter_s*)filter;
1174 if(STRING_VALID(_filter->condition))
1176 *condition = strdup(_filter->condition);
1177 if(*condition == NULL)
1179 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1180 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1188 *collate_type = _filter->condition_collate_type;
1192 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1193 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1199 int media_filter_get_order(filter_h filter, media_content_order_e* order_type, char **order_keyword, media_content_collation_e *collate_type)
1201 int ret = MEDIA_CONTENT_ERROR_NONE;
1202 filter_s *_filter = (filter_s*)filter;
1206 if(STRING_VALID(_filter->order_keyword))
1208 *order_keyword = strdup(_filter->order_keyword);
1209 if(*order_keyword == NULL)
1211 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1212 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1217 *order_keyword = NULL;
1220 *order_type = _filter->order_type;
1221 *collate_type = _filter->order_collate_type;
1225 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1226 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;