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