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