77255699f484f69515bacc0519fb572499c84964
[platform/core/api/media-content.git] / src / media_filter.c
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17
18 #include <media_info_private.h>
19
20 static char *media_token[] =
21 {
22         " ",
23         "\"",
24         "'",
25         "(",
26         ")",
27         "=",
28         "<=",
29         "<",
30         ">=",
31         ">",
32 };
33
34
35 typedef struct _token_t
36 {
37         int type;
38         char *str;
39 }token_t;
40
41
42 #define MAX_LEFT_VALUE 512
43 #define SPACE_LEN 1
44 #define SPACE " "
45 #define UNKNOWN_TYPE 1000
46 #define STRING_TYPE 100
47
48 static char *__get_order_str(media_content_order_e order_enum);
49 static char *__get_collate_str(media_content_collation_e collate_type);
50 static void __filter_attribute_free_value(gpointer key, gpointer value, gpointer user_data);
51 static char *__media_filter_replace_attr(attribute_h attr, char *name);
52 static int __tokenize_operator(token_t *token, const char *str, int op_type);
53 static int __tokenize(GList **token_list, const char *str);
54
55 static bool __is_pinyin_needed(void)
56 {
57 #if 0
58         char *lang = NULL;
59         char *china = "zh_CN";
60         char *hongkong = "zh_HK";
61 #endif
62         int ret = FALSE;
63 #if 0
64         /*Check CSC first*/
65         bool pinyin_support = FALSE;
66         media_svc_check_pinyin_support(&pinyin_support);
67         if(pinyin_support)
68         {
69                 /*Check Language Setting*/
70                 lang = vconf_get_str(VCONFKEY_LANGSET);
71                 if (lang == NULL)
72                 {
73                         media_content_error("Fail to get string of language set");
74                         return ret;
75                 }
76                 if((strncmp(china, lang, strlen(china)) == 0) ||
77                         (strncmp(hongkong, lang, strlen(hongkong)) == 0))
78                 {
79                         ret = TRUE;
80                 }
81
82                 SAFE_FREE(lang);
83         }
84 #endif
85         return ret;
86 }
87
88 static char *__get_order_str(media_content_order_e order_enum)
89 {
90         switch(order_enum) {
91                 case MEDIA_CONTENT_ORDER_ASC:
92                         return "ASC";
93                 case MEDIA_CONTENT_ORDER_DESC:
94                         return "DESC";
95                 default:
96                         return " ";
97         }
98 }
99
100 static char *__get_collate_str(media_content_collation_e collate_type)
101 {
102         switch(collate_type) {
103                 case MEDIA_CONTENT_COLLATE_NOCASE:
104                         return "NOCASE";
105                 case MEDIA_CONTENT_COLLATE_RTRIM:
106                         return "RTRIM";
107                 case MEDIA_CONTENT_COLLATE_LOCALIZED:
108                         if(__is_pinyin_needed())
109                                 return "NOCASE";
110                         else
111                                 return "localized";
112                 default: return " ";
113         }
114 }
115
116 static void __filter_attribute_free_value(gpointer key, gpointer value, gpointer user_data)
117 {
118         SAFE_FREE(key);
119         SAFE_FREE(value);
120 }
121
122 static char *__media_filter_replace_attr(attribute_h attr, char *name)
123 {
124         char *key_temp = NULL;
125         char *generated_value = NULL;
126         attribute_s *_attr = (attribute_s *)attr;
127
128         if(!g_hash_table_lookup_extended(_attr->attr_map,
129                                                                                 name,
130                                                                                 (gpointer)&key_temp, (gpointer)&generated_value))
131         {
132                 //can't find the value
133                 //media_content_error("NOT_FOUND_VALUE(%s)", name);
134                 return NULL;
135         }
136
137         if(STRING_VALID(generated_value))
138         {
139                 return strdup(generated_value);
140         }
141
142         media_content_error("__media_filter_replace_attr fail");
143
144         return NULL;
145 }
146
147 static int __tokenize_operator(token_t *token, const char *str, int op_type)
148 {
149         int ret = 0;
150         const char *tmp = str;
151
152         if(token != NULL && STRING_VALID(tmp))
153         {
154                 token->type = op_type;
155                 int token_size = strlen(media_token[op_type]);
156                 if(token_size == 0)
157                 {
158                         media_content_error("Invalid token_size. op_type[%d]", op_type);
159                         return -1;
160                 }
161
162                 token->str = (char*)calloc(token_size+1, sizeof(char));
163                 if(token->str == NULL)
164                 {
165                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
166                         return -1;
167                 }
168
169                 strncpy(token->str, tmp, token_size);
170                 //media_content_debug("type : [%d] str : [%s]", token->type, token->str);
171                 ret = token_size;
172         }
173         else
174         {
175                 ret = -1;
176         }
177
178         return ret;
179 }
180
181 static int __tokenize_string(token_t *token, const char *str, int size)
182 {
183         int ret = size;
184         const char *tmp = str;
185
186         if(token != NULL && STRING_VALID(tmp) && size > 0)
187         {
188                 token->str = (char*)calloc(size+1, sizeof(char));
189                 if(token->str == NULL)
190                 {
191                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
192                         return -1;
193                 }
194                 token->type = UNKNOWN_TYPE;
195                 strncpy(token->str, tmp, size);
196                 //media_content_debug("type : [%d] str : [%s]", token->type, token->str);
197         }
198         else
199         {
200                 ret = -1;
201         }
202
203         return ret;
204 }
205
206 static int __tokenize_attribute(GList **token_list, const char *str)
207 {
208         int ret = 0;
209         int idx = 0;
210
211         if(!STRING_VALID(str)) {
212                 media_content_error("Parameter string in invalid");
213                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
214         }
215
216         const char *tmp = str;
217         const char *dst_ptr = str + strlen(str);
218
219         for (idx = 0; (*(tmp+idx)) && (tmp < dst_ptr); idx++)
220         {
221                 //media_content_debug("[%d] '%c'", idx, tmp[idx]);
222                 if(tmp[idx] == ' ')             //" "
223                 {
224                         if(idx == 0)            // ignore the space.
225                         {
226                                 tmp++;
227                                 idx = -1;
228                                 continue;
229                         }
230                         token_t *token = (token_t*)calloc(1, sizeof(token_t));
231                         if(token == NULL)
232                         {
233                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
234                                 return -1;
235                         }
236                         token->type = UNKNOWN_TYPE;
237                         token->str = (char*)calloc(idx+1, sizeof(char));
238                         if(token->str == NULL)
239                         {
240                                 SAFE_FREE(token);
241                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
242                                 return -1;
243                         }
244                         strncpy(token->str, tmp, idx);
245                         //media_content_debug("type : [%d] str : [%s]", token->type, token->str);
246                         *token_list = g_list_append(*token_list, token);
247                         tmp = tmp +idx + strlen(media_token[0]);
248                         idx = -1;
249                 }
250                 else if(tmp[idx] == ',')        // " , "
251                 {
252                         if(idx != 0)
253                         {
254                                 token_t *token = (token_t*)calloc(1, sizeof(token_t));
255                                 if(token == NULL)
256                                 {
257                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
258                                         return -1;
259                                 }
260                                 ret = __tokenize_string(token, tmp, idx);
261                                 if (ret < 0)
262                                 {
263                                         SAFE_FREE(token);
264                                         media_content_error("tokenize error occured");
265                                         return -1;
266                                 }
267                                 else
268                                 {
269                                         *token_list = g_list_append(*token_list, token);
270                                         tmp = tmp + idx;
271                                 }
272                         }
273
274                         token_t *token = (token_t*)calloc(1, sizeof(token_t));
275                         int size = __tokenize_operator(token, tmp,3);
276
277                         if(token != NULL && STRING_VALID(token->str))
278                         {
279                                 *token_list = g_list_append(*token_list, token);
280                                 tmp += size;
281                                 idx = -1;
282                         }
283                         else
284                         {
285                                 SAFE_FREE(token);
286                                 media_content_error("tokenize error occured");
287                                 return -1;
288                         }
289                 }
290         }
291
292         if(*tmp)                        //remained string
293         {
294                 token_t *token = (token_t*)calloc(1, sizeof(token_t));
295                 if(token == NULL)
296                 {
297                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
298                         return -1;
299                 }
300
301                 ret = __tokenize_string(token, tmp, idx);
302                 if (ret < 0)
303                 {
304                         SAFE_FREE(token);
305                         media_content_error("tokenize error occured");
306                         return -1;
307                 }
308
309                 if(token != NULL && STRING_VALID(token->str))
310                 {
311                         *token_list = g_list_append(*token_list, token);
312                 }
313                 else
314                 {
315                         SAFE_FREE(token);
316                         media_content_error("tokenize error occured");
317                         return -1;
318                 }
319         }
320
321         return MEDIA_CONTENT_ERROR_NONE;
322 }
323
324 static int __tokenize(GList **token_list, const char *str)
325 {
326         int ret = 0;
327         int idx = 0;
328
329         if(!STRING_VALID(str)) {
330                 media_content_error("Parameter string in invalid");
331                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
332         }
333
334         const char *tmp = str;
335         const char *dst_ptr = str + strlen(str);
336
337         for (idx = 0; (*(tmp+idx)) && (tmp < dst_ptr); idx++)
338         {
339                 //media_content_debug("[%d] '%c'", idx, tmp[idx]);
340                 if(tmp[idx] == media_token[0][0])               //" "
341                 {
342                         if(idx == 0)            // ignore the space.
343                         {
344                                 tmp++;
345                                 idx = -1;
346                                 continue;
347                         }
348
349                         token_t *token = (token_t*)calloc(1, sizeof(token_t));
350                         if(token == NULL)
351                         {
352                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
353                                 return -1;
354                         }
355                         token->type = UNKNOWN_TYPE;
356                         token->str = (char*)calloc(idx+1, sizeof(char));
357                         if(token->str == NULL)
358                         {
359                                 SAFE_FREE(token);
360                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
361                                 return -1;
362                         }
363                         strncpy(token->str, tmp, idx);
364                         //media_content_debug("type : [%d] str : [%s]", token->type, token->str);
365                         *token_list = g_list_append(*token_list, token);
366                         tmp = tmp +idx + strlen(media_token[0]);
367                         idx = -1;
368                 }
369                 else if(tmp[idx] == media_token[1][0])  // " \" "
370                 {
371                         int j;
372                         bool flag = false;
373                         for(j = idx+1; tmp[j]; j++)     //find next quotation
374                         {
375                                 if(tmp[j] == media_token[1][0] && tmp[j+1] == media_token[1][0])
376                                 {
377                                         j += 1;
378                                         continue;
379                                 }
380                                 if(tmp[j] == media_token[1][0])
381                                 {
382                                         token_t *token = (token_t*)calloc(1, sizeof(token_t));
383                                         if(token == NULL)
384                                         {
385                                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
386                                                 return -1;
387                                         }
388                                         token->str = (char*) calloc(j+1+1, sizeof(char));
389                                         if(token->str == NULL)
390                                         {
391                                                 SAFE_FREE(token);
392                                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
393                                                 return -1;
394                                         }
395                                         token->type = STRING_TYPE;
396                                         strncpy(token->str, tmp, j+1);
397                                         //media_content_debug("type : [%d] str : [%s], j : %d", token->type, token->str, j);
398                                         *token_list = g_list_append(*token_list, token);
399                                         tmp = tmp + strlen(token->str);
400                                         idx = -1;
401                                         flag = true;
402                                         break;
403                                 }
404                         }
405
406                         if(!flag && *tmp != '\0' && tmp[j]=='\0')
407                         {
408                                 token_t *token = (token_t*)calloc(1, sizeof(token_t));
409                                 if(token == NULL)
410                                 {
411                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
412                                         return -1;
413                                 }
414                                 token->str = (char*) calloc(j+1,sizeof(char));
415                                 if(token->str == NULL)
416                                 {
417                                         SAFE_FREE(token);
418                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
419                                         return -1;
420                                 }
421                                 token->type = UNKNOWN_TYPE;
422                                 strncpy(token->str, tmp,j);
423                                 //media_content_debug("type : [%d] str : [%s]", token->type, token->str);
424                                 *token_list = g_list_append(*token_list, token);
425                                 tmp = tmp +strlen(token->str);
426                                 idx = -1;
427                         }
428                 }
429                 else if(tmp[idx] == media_token[2][0])  // " \' "
430                 {
431                         int j;
432                         bool flag = false;
433                         for(j = idx+1; tmp[j]; j++)
434                         {
435                                 if(tmp[j] == media_token[2][0] && tmp[j+1] == media_token[2][0])
436                                 {
437                                         j += 1;
438                                         continue;
439                                 }
440                                 if(tmp[j] == media_token[2][0])
441                                 {
442                                         token_t *token = (token_t*)calloc(1, sizeof(token_t));
443                                         if(token == NULL)
444                                         {
445                                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
446                                                 return -1;
447                                         }
448                                         token->str = (char*) calloc(j+1+1, sizeof(char));
449                                         if(token->str == NULL)
450                                         {
451                                                 SAFE_FREE(token);
452                                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
453                                                 return -1;
454                                         }
455                                         token->type = STRING_TYPE;
456                                         strncpy(token->str, tmp, j+1);
457                                         //media_content_debug("type : [%d] str : [%s]", token->type, token->str);
458                                         *token_list = g_list_append(*token_list, token);
459                                         tmp = tmp + strlen(token->str);
460                                         idx = -1;
461                                         flag = true;
462                                         break;
463                                 }
464                         }
465
466                         if(!flag && *tmp != '\0' && tmp[j]=='\0')
467                         {
468                                 token_t *token = (token_t*)calloc(1, sizeof(token_t));
469                                 if(token == NULL)
470                                 {
471                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
472                                         return -1;
473                                 }
474                                 token->str = (char*) calloc(j+1,sizeof(char));
475                                 if(token->str == NULL)
476                                 {
477                                         SAFE_FREE(token);
478                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
479                                         return -1;
480                                 }
481                                 token->type = UNKNOWN_TYPE;
482                                 strncpy(token->str, tmp,j);
483                                 //media_content_debug("type : [%d] str : [%s]", token->type, token->str);
484                                 *token_list = g_list_append(*token_list, token);
485                                 tmp = tmp + strlen(token->str);
486                                 idx = -1;
487                         }
488                 }
489                 else if(tmp[idx] == media_token[3][0])  //"("
490                 {
491                         if(idx != 0)
492                         {
493                                 token_t *token = (token_t*)calloc(1, sizeof(token_t));
494                                 if(token == NULL)
495                                 {
496                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
497                                         return -1;
498                                 }
499                                 ret = __tokenize_string(token, tmp, idx);
500                                 if (ret < 0)
501                                 {
502                                         SAFE_FREE(token);
503                                         media_content_error("tokenize error occured");
504                                         return -1;
505                                 }
506                                 else
507                                 {
508                                         *token_list = g_list_append(*token_list, token);
509                                         tmp = tmp + idx;
510                                 }
511                         }
512                         token_t *token = (token_t*)calloc(1, sizeof(token_t));
513                         int size = __tokenize_operator(token, tmp,3);
514
515                         if(token != NULL && STRING_VALID(token->str))
516                         {
517                                 *token_list = g_list_append(*token_list, token);
518                                 tmp += size;
519                                 idx = -1;
520                         }
521                         else
522                         {
523                                 SAFE_FREE(token);
524                                 media_content_error("tokenize error occured");
525                                 return -1;
526                         }
527
528                 }
529                 else if(tmp[idx] == media_token[4][0])  //")"
530                 {
531                         if(idx != 0)
532                         {
533                                 token_t *token = (token_t*)calloc(1, sizeof(token_t));
534                                 if(token == NULL)
535                                 {
536                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
537                                         return -1;
538                                 }
539
540                                 ret = __tokenize_string(token, tmp, idx);
541                                 if (ret < 0)
542                                 {
543                                         SAFE_FREE(token);
544                                         media_content_error("tokenize error occured");
545                                         return -1;
546                                 }
547                                 else
548                                 {
549                                         *token_list = g_list_append(*token_list, token);
550                                         tmp = tmp + idx;
551                                 }
552                         }
553                         token_t *token = (token_t*)calloc(1, sizeof(token_t));
554                         int size = __tokenize_operator(token, tmp,4);
555
556                         if(token != NULL && STRING_VALID(token->str))
557                         {
558                                 *token_list = g_list_append(*token_list, token);
559                                 tmp += size;
560                                 idx = -1;
561                         }
562                         else
563                         {
564                                 SAFE_FREE(token);
565                                 media_content_error("tokenize error occured");
566                                 return -1;
567                         }
568
569                 }
570                 else if(tmp[idx] == media_token[5][0])  //"="
571                 {
572                         if(idx != 0)
573                         {
574                                 token_t *token = (token_t*)calloc(1, sizeof(token_t));
575                                 if(token == NULL)
576                                 {
577                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
578                                         return -1;
579                                 }
580
581                                 ret = __tokenize_string(token, tmp, idx);
582                                 if (ret < 0)
583                                 {
584                                         SAFE_FREE(token);
585                                         media_content_error("tokenize error occured");
586                                         return -1;
587                                 }
588                                 else
589                                 {
590                                         *token_list = g_list_append(*token_list, token);
591                                         tmp = tmp + idx;
592                                 }
593                         }
594                         token_t *token = (token_t*)calloc(1, sizeof(token_t));
595                         int size = __tokenize_operator(token, tmp,5);
596
597                         if(token != NULL && STRING_VALID(token->str))
598                         {
599                                 *token_list = g_list_append(*token_list, token);
600                                 tmp += size;
601                                 idx = -1;
602                         }
603                         else
604                         {
605                                 SAFE_FREE(token);
606                                 media_content_error("tokenize error occured");
607                                 return -1;
608                         }
609
610                 }
611                 else if(tmp[idx] == media_token[6][0] && tmp[idx+1] == media_token[6][1])       //"<=",
612                 {
613                         if(idx != 0)
614                         {
615                                 token_t *token = (token_t*)calloc(1, sizeof(token_t));
616                                 if(token == NULL)
617                                 {
618                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
619                                         return -1;
620                                 }
621
622                                 ret = __tokenize_string(token, tmp, idx);
623                                 if (ret < 0)
624                                 {
625                                         SAFE_FREE(token);
626                                         media_content_error("tokenize error occured");
627                                         return -1;
628                                 }
629                                 else
630                                 {
631                                         *token_list = g_list_append(*token_list, token);
632                                         tmp = tmp + idx;
633                                 }
634                         }
635                         token_t *token = (token_t*)calloc(1, sizeof(token_t));
636                         int size = __tokenize_operator(token, tmp,6);
637
638                         if(token != NULL && STRING_VALID(token->str))
639                         {
640                                 *token_list = g_list_append(*token_list, token);
641                                 tmp += size;
642                                 idx = -1;
643                         }
644                         else
645                         {
646                                 SAFE_FREE(token);
647                                 media_content_error("tokenize error occured");
648                                 return -1;
649                         }
650
651                 }
652                 else if(tmp[idx] == media_token[7][0])  //"<",
653                 {
654                         if(idx != 0)
655                         {
656                                 token_t *token = (token_t*)calloc(1, sizeof(token_t));
657                                 if(token == NULL)
658                                 {
659                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
660                                         return -1;
661                                 }
662
663                                 ret = __tokenize_string(token, tmp, idx);
664                                 if (ret < 0)
665                                 {
666                                         SAFE_FREE(token);
667                                         media_content_error("tokenize error occured");
668                                         return -1;
669                                 }
670                                 else
671                                 {
672                                         *token_list = g_list_append(*token_list, token);
673                                         tmp = tmp + idx;
674                                 }
675                         }
676                         token_t *token = (token_t*)calloc(1, sizeof(token_t));
677                         int size = __tokenize_operator(token, tmp,7);
678
679                         if(token != NULL && STRING_VALID(token->str))
680                         {
681                                 *token_list = g_list_append(*token_list, token);
682                                 tmp += size;
683                                 idx = -1;
684                         }
685                         else
686                         {
687                                 SAFE_FREE(token);
688                                 media_content_error("tokenize error occured");
689                                 return -1;
690                         }
691
692                 }
693                 else if(tmp[idx] == media_token[8][0] && tmp[idx+1] == media_token[8][1])       //">=",
694                 {
695                         if(idx != 0)
696                         {
697                                 token_t *token = (token_t*)calloc(1, sizeof(token_t));
698                                 if(token == NULL)
699                                 {
700                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
701                                         return -1;
702                                 }
703
704                                 ret = __tokenize_string(token, tmp, idx);
705                                 if (ret < 0)
706                                 {
707                                         SAFE_FREE(token);
708                                         media_content_error("tokenize error occured");
709                                         return -1;
710                                 }
711                                 else
712                                 {
713                                         *token_list = g_list_append(*token_list, token);
714                                         tmp = tmp + idx;
715                                 }
716                         }
717                         token_t *token = (token_t*)calloc(1, sizeof(token_t));
718                         int size = __tokenize_operator(token, tmp,8);
719
720                         if(token != NULL && STRING_VALID(token->str))
721                         {
722                                 *token_list = g_list_append(*token_list, token);
723                                 tmp += size;
724                                 idx = -1;
725                         }
726                         else
727                         {
728                                 SAFE_FREE(token);
729                                 media_content_error("tokenize error occured");
730                                 return -1;
731                         }
732
733                 }
734                 else if(tmp[idx] == media_token[9][0])  //">",
735                 {
736                         if(idx != 0)
737                         {
738                                 token_t *token = (token_t*)calloc(1, sizeof(token_t));
739                                 if(token == NULL)
740                                 {
741                                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
742                                         return -1;
743                                 }
744
745                                 ret = __tokenize_string(token, tmp, idx);
746                                 if (ret < 0)
747                                 {
748                                         SAFE_FREE(token);
749                                         media_content_error("tokenize error occured");
750                                         return -1;
751                                 }
752                                 else
753                                 {
754                                         *token_list = g_list_append(*token_list, token);
755                                         tmp = tmp + idx;
756                                 }
757                         }
758                         token_t *token = (token_t*)calloc(1, sizeof(token_t));
759                         int size = __tokenize_operator(token, tmp,9);
760
761                         if(token != NULL && STRING_VALID(token->str))
762                         {
763                                 *token_list = g_list_append(*token_list, token);
764                                 tmp += size;
765                                 idx = -1;
766                         }
767                         else
768                         {
769                                 SAFE_FREE(token);
770                                 media_content_error("tokenize error occured");
771                                 return -1;
772                         }
773
774                 }
775         }
776
777         if(*tmp)                        //remained string
778         {
779                 token_t *token = (token_t*)calloc(1, sizeof(token_t));
780                 if(token == NULL)
781                 {
782                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
783                         return -1;
784                 }
785
786                 ret = __tokenize_string(token, tmp, idx);
787                 if (ret < 0)
788                 {
789                         SAFE_FREE(token);
790                         media_content_error("tokenize error occured");
791                         return -1;
792                 }
793
794                 if(token != NULL && STRING_VALID(token->str))
795                 {
796                         *token_list = g_list_append(*token_list, token);
797                 }
798                 else
799                 {
800                         SAFE_FREE(token);
801                         media_content_error("tokenize error occured");
802                         return -1;
803                 }
804         }
805
806         return MEDIA_CONTENT_ERROR_NONE;
807 }
808
809 int _media_filter_attribute_create(attribute_h *attr)
810 {
811         int ret = MEDIA_CONTENT_ERROR_NONE;
812
813         if(attr == NULL)
814         {
815                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
816                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
817         }
818
819         attribute_s *_attr = (attribute_s*)calloc(1, sizeof(attribute_s));
820
821         if(_attr == NULL)
822         {
823                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
824                 ret = MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
825         }
826         else
827         {
828                 _attr->attr_map = g_hash_table_new (g_str_hash, g_str_equal);
829                 *attr = (attribute_h)_attr;
830         }
831
832         return ret;
833 }
834
835 int _media_filter_attribute_add(attribute_h attr, char *user_attr, char *platform_attr)
836 {
837         int ret = MEDIA_CONTENT_ERROR_NONE;
838         char *_user = NULL;
839         char *_platform = NULL;
840         attribute_s *_attr = (attribute_s*)attr;
841
842         if(_attr != NULL)
843         {
844                 if(STRING_VALID(user_attr) && STRING_VALID(platform_attr))
845                 {
846                         _user = strdup(user_attr);
847                         if(_user == NULL)
848                         {
849                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
850                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
851                         }
852
853                         _platform = strdup(platform_attr);
854                         if(_platform == NULL)
855                         {
856                                 SAFE_FREE(_user);
857                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
858                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
859                         }
860
861                         g_hash_table_insert (_attr->attr_map, _user, _platform);
862                 }
863                 else
864                 {
865                         media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
866                         return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
867                 }
868         }
869         else
870         {
871                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
872                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
873         }
874
875         return ret;
876 }
877
878 int _media_filter_attribute_destory(attribute_h attr)
879 {
880         int ret = MEDIA_CONTENT_ERROR_NONE;
881         attribute_s *_attr = (attribute_s*)attr;
882
883         if(_attr != NULL)
884         {
885                 if(_attr->attr_map != NULL)
886                 {
887                         g_hash_table_foreach(_attr->attr_map, __filter_attribute_free_value, NULL);
888                         g_hash_table_destroy(_attr->attr_map);
889                 }
890
891                 SAFE_FREE(_attr);
892         }
893         else
894         {
895                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
896                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
897         }
898
899         return ret;
900 }
901
902 int _media_filter_attribute_generate(attribute_h attr, char *condition, media_content_collation_e collate_type, char **generated_condition)
903 {
904         int idx = 0;
905         GList *token_list = NULL;
906         int size = 0;
907         int ret = MEDIA_CONTENT_ERROR_NONE;
908         int total_str_size = 0;
909         token_t *token;
910
911         if((condition == NULL) || (generated_condition == NULL))
912         {
913                 media_content_error("INVALID_PARAMETER(0x%08x):Invalid the condition", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
914                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
915         }
916
917         if(attr != NULL)
918         {
919                 if(__tokenize(&token_list, condition) < 0)
920                 {
921                         media_content_error("INVALID_PARAMETER(0x%08x):Invalid the condition", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
922                         return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
923                 }
924
925                 for(idx = 0; idx < g_list_length(token_list); idx++)
926                 {
927                         token = (token_t*)g_list_nth_data(token_list, idx);
928
929                         if(token->type == UNKNOWN_TYPE)
930                         {
931                                 char *replace_str = __media_filter_replace_attr(attr, token->str);
932                                 if(STRING_VALID(replace_str))
933                                 {
934                                         SAFE_FREE(token->str);
935                                         token->str = replace_str;
936                                 }
937                         }
938
939                         total_str_size += strlen(token->str)+1;
940                         //media_content_debug("[%d][type:%d]:%s", idx, token->type, token->str);
941                 }
942
943                 //make the statment
944                 size = total_str_size + COLLATE_STR_SIZE + 1;
945                 * generated_condition = (char*)calloc(size, sizeof(char));
946
947                 for(idx = 0; idx < g_list_length(token_list); idx++)
948                 {
949                         token = (token_t*)g_list_nth_data(token_list, idx);
950
951                         if((token != NULL) && STRING_VALID(token->str))
952                         {
953                                 SAFE_STRLCAT(*generated_condition, token->str, size);
954                                 SAFE_STRLCAT(*generated_condition, SPACE, size);
955
956                                 SAFE_FREE(token->str);
957                                 SAFE_FREE(token);
958                         }
959                 }
960
961                 if(collate_type == MEDIA_CONTENT_COLLATE_NOCASE || collate_type == MEDIA_CONTENT_COLLATE_RTRIM ||collate_type == MEDIA_CONTENT_COLLATE_LOCALIZED) {
962                         SAFE_STRLCAT(*generated_condition, "COLLATE ", size);
963                         SAFE_STRLCAT(*generated_condition, __get_collate_str(collate_type), size);
964                         SAFE_STRLCAT(*generated_condition, SPACE, size);
965                 }
966
967                 //media_content_debug("statement : %s(%d) (total:%d)", *generated_condition, strlen(*generated_condition), total_str_size);
968                 media_content_sec_debug("Condition : %s", *generated_condition);
969
970                 //if(*generated_condition != NULL)
971                 //      res = 1;
972
973                 if(token_list != NULL)
974                         g_list_free(token_list);
975         }
976         else
977         {
978                 media_content_error("DB field mapping table doesn't exist. Check db connection", MEDIA_CONTENT_ERROR_DB_FAILED);
979                 return MEDIA_CONTENT_ERROR_DB_FAILED;
980         }
981
982         return ret;
983 }
984
985 int _media_filter_attribute_option_generate(attribute_h attr, filter_h filter, char **generated_option)
986 {
987         int ret = MEDIA_CONTENT_ERROR_NONE;
988         filter_s *_filter = NULL;
989         char option_query[DEFAULT_QUERY_SIZE] = {0, };
990         char condition[DEFAULT_QUERY_SIZE] = {0, };
991         int size = 0;
992         //bool order_by = true;
993
994         if(filter == NULL)
995         {
996                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
997                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
998         }
999
1000         if(attr == NULL)
1001         {
1002                 media_content_error("DB field mapping table doesn't exist. Check db connection", MEDIA_CONTENT_ERROR_DB_FAILED);
1003                 return MEDIA_CONTENT_ERROR_DB_FAILED;
1004         }
1005
1006         _filter = (filter_s*)filter;
1007
1008         memset(option_query, 0x00, sizeof(option_query));
1009
1010         /* Order by*/
1011         if(STRING_VALID(_filter->order_keyword) && ((_filter->order_type == MEDIA_CONTENT_ORDER_ASC) ||(_filter->order_type == MEDIA_CONTENT_ORDER_DESC)))
1012         {
1013                 int idx = 0;
1014                 int total_str_size = 0;
1015                 GList *token_list = NULL;
1016                 token_t *token;
1017                 char *attr_str;
1018
1019                 if(__tokenize_attribute(&token_list, _filter->order_keyword) < 0)
1020                 {
1021                         media_content_error("INVALID_PARAMETER(0x%08x):Invalid the condition", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1022                         return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1023                 }
1024
1025                 for(idx = 0; idx < g_list_length(token_list); idx++)
1026                 {
1027                         token = (token_t*)g_list_nth_data(token_list, idx);
1028
1029                         if(token->type == UNKNOWN_TYPE)
1030                         {
1031                                 char *replace_str = __media_filter_replace_attr(attr, token->str);
1032                                 if(STRING_VALID(replace_str))
1033                                 {
1034                                         attr_str = (char*)calloc(strlen(replace_str) + COLLATE_STR_SIZE + 1, sizeof(char));
1035                                         if(attr_str == NULL)
1036                                         {
1037                                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1038                                                 SAFE_FREE(replace_str);
1039                                                 continue;
1040                                         }
1041
1042                                         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) {
1043                                                 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));
1044                                         } else {
1045                                                 snprintf(attr_str, strlen(replace_str) + COLLATE_STR_SIZE + 1, "%s %s", replace_str, __get_order_str(_filter->order_type));
1046                                         }
1047
1048                                         SAFE_FREE(token->str);
1049                                         token->str = attr_str;
1050                                         SAFE_FREE(replace_str);
1051                                 }
1052                                 else
1053                                 {
1054                                         media_content_error("There is no matched db field for %s", token->str);
1055                                 }
1056                         }
1057
1058                         total_str_size += strlen(token->str) + 1;
1059                         //media_content_debug("[%d][type:%d]:%s", idx, token->type, token->str);
1060                 }
1061
1062                 //make the statment
1063                 char *generated_condition = NULL;
1064                 size = total_str_size + COLLATE_STR_SIZE + 1;
1065                 generated_condition = (char*)calloc(size, sizeof(char));
1066
1067                 for(idx = 0; idx < g_list_length(token_list); idx++)
1068                 {
1069                         token = (token_t*)g_list_nth_data(token_list, idx);
1070
1071                         if((token != NULL) && STRING_VALID(token->str))
1072                         {
1073                                 //media_content_debug("[%d] %s", idx, token->str);
1074                                 SAFE_STRLCAT(generated_condition, token->str, size);
1075                                 SAFE_STRLCAT(generated_condition, SPACE, size);
1076
1077                                 SAFE_FREE(token->str);
1078                                 SAFE_FREE(token);
1079                         }
1080                 }
1081
1082                 snprintf(condition, sizeof(condition), "ORDER BY %s", generated_condition);
1083                 SAFE_STRLCAT(option_query, condition, sizeof(option_query));
1084
1085                 if(token_list != NULL)
1086                         g_list_free(token_list);
1087
1088                 SAFE_FREE(generated_condition);
1089         }
1090
1091         /* offset */
1092         SAFE_STRLCAT(option_query, SPACE, sizeof(option_query));
1093         snprintf(condition, sizeof(condition), "LIMIT %d, %d", _filter->offset, _filter->count);
1094         SAFE_STRLCAT(option_query, condition, sizeof(option_query));
1095
1096         if(STRING_VALID(option_query))
1097         {
1098                 *generated_option = strdup(option_query);
1099         }
1100         else
1101         {
1102                 *generated_option = NULL;
1103         }
1104
1105         return ret;
1106 }
1107
1108 int media_filter_create(filter_h *filter)
1109 {
1110         int ret = MEDIA_CONTENT_ERROR_NONE;
1111
1112         if(filter == NULL)
1113         {
1114                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1115                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1116         }
1117
1118         filter_s *_filter = (filter_s*)calloc(1, sizeof(filter_s));
1119
1120         if(_filter == NULL)
1121         {
1122                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1123                 ret = MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1124         }
1125         else
1126         {
1127                 _filter->storage_id = NULL;
1128                 _filter->condition = NULL;
1129                 _filter->order_keyword = NULL;
1130                 _filter->order_type = -1;
1131                 _filter->condition_collate_type = MEDIA_CONTENT_COLLATE_DEFAULT;
1132                 _filter->order_collate_type = MEDIA_CONTENT_COLLATE_DEFAULT;
1133                 _filter->offset = -1;
1134                 _filter->count = -1;
1135
1136                 *filter = (filter_h)_filter;
1137         }
1138
1139         return ret;
1140 }
1141
1142 int media_filter_destroy(filter_h filter)
1143 {
1144         int ret = MEDIA_CONTENT_ERROR_NONE;
1145         filter_s *_filter = (filter_s*)filter;
1146
1147         if(_filter)
1148         {
1149                 SAFE_FREE(_filter->storage_id);
1150                 SAFE_FREE(_filter->condition);
1151                 SAFE_FREE(_filter->order_keyword);
1152                 SAFE_FREE(_filter);
1153
1154                 ret = MEDIA_CONTENT_ERROR_NONE;
1155         }
1156         else
1157         {
1158                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1159                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1160         }
1161
1162         return ret;
1163 }
1164
1165 int media_filter_set_offset(filter_h filter, int offset, int count)
1166 {
1167         int ret = MEDIA_CONTENT_ERROR_NONE;
1168         filter_s *_filter = (filter_s*)filter;
1169
1170         if(_filter != NULL)
1171         {
1172                 _filter->offset = offset;
1173                 _filter->count = count;
1174         }
1175         else
1176         {
1177                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1178                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1179         }
1180
1181         return ret;
1182 }
1183
1184 int media_filter_set_condition(filter_h filter, const char *condition, media_content_collation_e collate_type)
1185 {
1186         int ret = MEDIA_CONTENT_ERROR_NONE;
1187         filter_s *_filter = (filter_s*)filter;
1188
1189         if((_filter != NULL) && STRING_VALID(condition)
1190                 && ((collate_type >= MEDIA_CONTENT_COLLATE_DEFAULT) && (collate_type <= MEDIA_CONTENT_COLLATE_LOCALIZED)))
1191         {
1192                 if(STRING_VALID(_filter->condition))
1193                 {
1194                         SAFE_FREE(_filter->condition);
1195                 }
1196
1197                 _filter->condition = strdup(condition);
1198                 if(_filter->condition == NULL)
1199                 {
1200                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1201                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1202                 }
1203
1204                 media_content_sec_debug("Condition string : %s", _filter->condition);
1205
1206                 _filter->condition_collate_type = collate_type;
1207         }
1208         else
1209         {
1210                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1211                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1212         }
1213
1214         return ret;
1215 }
1216
1217 int media_filter_set_order(filter_h filter, media_content_order_e order_type, const char *order_keyword, media_content_collation_e collate_type)
1218 {
1219         int ret = MEDIA_CONTENT_ERROR_NONE;
1220         filter_s *_filter = (filter_s*)filter;
1221
1222         if((_filter != NULL) && STRING_VALID(order_keyword)
1223                 && ((order_type == MEDIA_CONTENT_ORDER_ASC) ||(order_type == MEDIA_CONTENT_ORDER_DESC))
1224                 && ((collate_type >= MEDIA_CONTENT_COLLATE_DEFAULT) && (collate_type <= MEDIA_CONTENT_COLLATE_LOCALIZED)))
1225         {
1226                 SAFE_FREE(_filter->order_keyword);
1227
1228                 if(STRING_VALID(order_keyword))
1229                 {
1230                         _filter->order_keyword = strdup(order_keyword);
1231
1232                         if(_filter->order_keyword == NULL)
1233                         {
1234                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1235                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1236                         }
1237                         _filter->order_type = order_type;
1238                         _filter->order_collate_type = collate_type;
1239                 }
1240                 else
1241                 {
1242                         media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1243                         ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1244                 }
1245         }
1246         else
1247         {
1248                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1249                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1250         }
1251
1252         return ret;
1253 }
1254
1255 int media_filter_set_storage(filter_h filter, const char *storage_id)
1256 {
1257         int ret = MEDIA_CONTENT_ERROR_NONE;
1258         filter_s *_filter = (filter_s*)filter;
1259
1260         if((_filter != NULL) && STRING_VALID(storage_id))
1261         {
1262                 if(STRING_VALID(_filter->storage_id))
1263                 {
1264                         SAFE_FREE(_filter->storage_id);
1265                 }
1266
1267                 _filter->storage_id = strdup(storage_id);
1268                 if(_filter->storage_id == NULL)
1269                 {
1270                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1271                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1272                 }
1273
1274                 media_content_sec_debug("storage_id : %s", _filter->storage_id);
1275         }
1276         else
1277         {
1278                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1279                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1280         }
1281
1282         return ret;
1283 }
1284
1285 int media_filter_get_offset(filter_h filter, int *offset, int *count)
1286 {
1287         int ret = MEDIA_CONTENT_ERROR_NONE;
1288         filter_s *_filter = (filter_s*)filter;
1289
1290         if(_filter)
1291         {
1292                 *offset = _filter->offset;
1293                 *count = _filter->count;
1294         }
1295         else
1296         {
1297                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1298                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1299         }
1300
1301         return ret;
1302 }
1303
1304 int media_filter_get_condition(filter_h filter, char **condition, media_content_collation_e *collate_type)
1305 {
1306         int ret = MEDIA_CONTENT_ERROR_NONE;
1307         filter_s *_filter = (filter_s*)filter;
1308
1309         if(_filter)
1310         {
1311                 if(STRING_VALID(_filter->condition))
1312                 {
1313                         *condition = strdup(_filter->condition);
1314                         if(*condition == NULL)
1315                         {
1316                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1317                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1318                         }
1319                 }
1320                 else
1321                 {
1322                         *condition = NULL;
1323                 }
1324
1325                 *collate_type = _filter->condition_collate_type;
1326         }
1327         else
1328         {
1329                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1330                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1331         }
1332
1333         return ret;
1334 }
1335
1336 int media_filter_get_order(filter_h filter, media_content_order_e* order_type, char **order_keyword, media_content_collation_e *collate_type)
1337 {
1338         int ret = MEDIA_CONTENT_ERROR_NONE;
1339         filter_s *_filter = (filter_s*)filter;
1340
1341         if(_filter)
1342         {
1343                 if(STRING_VALID(_filter->order_keyword))
1344                 {
1345                         *order_keyword = strdup(_filter->order_keyword);
1346                         if(*order_keyword == NULL)
1347                         {
1348                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1349                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1350                         }
1351                 }
1352                 else
1353                 {
1354                         *order_keyword = NULL;
1355                 }
1356
1357                 *order_type = _filter->order_type;
1358                 *collate_type = _filter->order_collate_type;
1359         }
1360         else
1361         {
1362                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1363                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1364         }
1365
1366         return ret;
1367 }
1368
1369 int media_filter_get_storage(filter_h filter, char **storage_id)
1370 {
1371         int ret = MEDIA_CONTENT_ERROR_NONE;
1372         filter_s *_filter = (filter_s*)filter;
1373
1374         if(_filter)
1375         {
1376                 if(STRING_VALID(_filter->storage_id))
1377                 {
1378                         *storage_id = strdup(_filter->storage_id);
1379                         if(*storage_id == NULL)
1380                         {
1381                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1382                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1383                         }
1384                 }
1385                 else
1386                 {
1387                         *storage_id = NULL;
1388                 }
1389         }
1390         else
1391         {
1392                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1393                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1394         }
1395
1396         return ret;
1397 }