X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fmedia_filter.c;h=afb90d99c766352e201e4da3b1041712ffb72d6d;hb=9d15701e2caada225fd93cd0b4b14fee53a9263d;hp=bcdc68d1ee2bccb7af84f285280a603ad89dab59;hpb=7bc47091ecdf4768cef5c6781d025a9d373f78fe;p=platform%2Fcore%2Fapi%2Fmedia-content.git diff --git a/src/media_filter.c b/src/media_filter.c index bcdc68d..afb90d9 100755 --- a/src/media_filter.c +++ b/src/media_filter.c @@ -17,938 +17,116 @@ #include #include -#include - -static const char *media_token[] = { - " ", - "\"", - "'", - "(", - ")", - "=", - "<=", - "<", - ">=", - ">", - "!=", -}; - - -typedef struct _token_t { - int type; - char *str; -} token_t; - -#define UNKNOWN_TYPE 1000 -#define STRING_TYPE 100 - -static char *__get_order_str(media_content_order_e order_enum); -static char *__get_collate_str(media_content_collation_e collate_type); -static void __filter_attribute_free_value(gpointer key, gpointer value, gpointer user_data); -static char *__media_filter_replace_attr(attribute_h attr, char *name); -static int __tokenize_operator(token_t *token, const char *str, int op_type); -static int __tokenize(GList **token_list, const char *str); - -static bool __is_pinyin_needed(void) -{ - char *lang = NULL; - const char *china = "zh_CN"; - const char *hongkong = "zh_HK"; - int ret = FALSE; - - /*Check CSC first*/ - bool pinyin_support = FALSE; - media_svc_check_pinyin_support(&pinyin_support); - if (pinyin_support) { - /*Check Language Setting*/ - lang = vconf_get_str(VCONFKEY_LANGSET); - media_content_retvm_if(lang == NULL, ret, "Fail to get string of language set"); - - if ((strncmp(china, lang, strlen(china)) == 0) || - (strncmp(hongkong, lang, strlen(hongkong)) == 0)) { - ret = TRUE; - } - - SAFE_FREE(lang); - } - return ret; -} - -static char *__get_order_str(media_content_order_e order_enum) +static const char *__get_order_str(media_content_order_e order_enum) { switch (order_enum) { case MEDIA_CONTENT_ORDER_ASC: - return (char *)"ASC"; + return "ASC "; case MEDIA_CONTENT_ORDER_DESC: - return (char *)"DESC"; + return "DESC "; default: - return (char *)" "; + return " "; } } -static char *__get_collate_str(media_content_collation_e collate_type) +static const char *__get_collate_str(media_content_collation_e collate_type) { switch (collate_type) { case MEDIA_CONTENT_COLLATE_NOCASE: - return (char *)"NOCASE"; + return " COLLATE NOCASE "; case MEDIA_CONTENT_COLLATE_RTRIM: - return (char *)"RTRIM"; + return " COLLATE RTRIM "; case MEDIA_CONTENT_COLLATE_LOCALIZED: - if (__is_pinyin_needed()) - return (char *)"NOCASE"; - else - return (char *)"localized"; - default: return (char *)" "; - } -} - -static void __filter_attribute_free_value(gpointer key, gpointer value, gpointer user_data) -{ - SAFE_G_FREE(key); - SAFE_G_FREE(value); -} - -static char *__media_filter_replace_attr(attribute_h attr, char *name) -{ - char *key_temp = NULL; - char *generated_value = NULL; - attribute_s *_attr = (attribute_s *)attr; - - if (!g_hash_table_lookup_extended(_attr->attr_map, name, (gpointer)&key_temp, (gpointer)&generated_value)) { - /* can't find the value */ - /* media_content_error("NOT_FOUND_VALUE(%s)", name); */ - return NULL; - } - - if (STRING_VALID(generated_value)) - return strdup(generated_value); - - media_content_error("__media_filter_replace_attr fail"); - - return NULL; -} - -static int __tokenize_operator(token_t *token, const char *str, int op_type) -{ - int ret = 0; - const char *tmp = str; - - if (token != NULL && STRING_VALID(tmp)) { - token->type = op_type; - int token_size = strlen(media_token[op_type]); - media_content_retvm_if(token_size == 0, -1, "Invalid token_size. op_type[%d]", op_type); - - token->str = (char*)calloc(token_size+1, sizeof(char)); - media_content_retvm_if(token->str == NULL, -1, "OUT_OF_MEMORY"); - - strncpy(token->str, tmp, token_size); - /*media_content_debug("type : [%d] str : [%s]", token->type, token->str);*/ - ret = token_size; - } else { - ret = -1; - } - - return ret; -} - -static int __tokenize_string(token_t *token, const char *str, int size) -{ - int ret = size; - const char *tmp = str; - - if (token != NULL && STRING_VALID(tmp) && size > 0) { - token->str = (char*)calloc(size+1, sizeof(char)); - media_content_retvm_if(token->str == NULL, -1, "OUT_OF_MEMORY"); - - token->type = UNKNOWN_TYPE; - strncpy(token->str, tmp, size); - /*media_content_debug("type : [%d] str : [%s]", token->type, token->str);*/ - } else { - ret = -1; - } - - return ret; -} - -static int __tokenize_attribute(GList **token_list, const char *str) -{ - int ret = 0; - int idx = 0; - - media_content_retvm_if(!STRING_VALID(str), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Parameter string is invalid"); - - const char *tmp = str; - const char *dst_ptr = str + strlen(str); - - for (idx = 0; (*(tmp+idx)) && (tmp < dst_ptr); idx++) { - /*media_content_debug("[%d] '%c'", idx, tmp[idx]);*/ - if (tmp[idx] == ' ') { /* " " */ - if (idx == 0) { /* ignore the space. */ - tmp++; - idx = -1; - continue; - } - token_t *token = (token_t*)calloc(1, sizeof(token_t)); - media_content_retvm_if(token == NULL, -1, "OUT_OF_MEMORY"); - - token->type = UNKNOWN_TYPE; - token->str = (char*)calloc(idx+1, sizeof(char)); - if (token->str == NULL) { - SAFE_FREE(token); - media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); - return -1; - } - strncpy(token->str, tmp, idx); - /*media_content_debug("type : [%d] str : [%s]", token->type, token->str);*/ - *token_list = g_list_append(*token_list, token); - tmp = tmp +idx + strlen(media_token[0]); - idx = -1; - } else if (tmp[idx] == ',') { /* " , " */ - if (idx != 0) { - token_t *token = (token_t*)calloc(1, sizeof(token_t)); - media_content_retvm_if(token == NULL, -1, "OUT_OF_MEMORY"); - - ret = __tokenize_string(token, tmp, idx); - if (ret < 0) { - SAFE_FREE(token); - media_content_error("tokenize error occured"); - return -1; - } else { - *token_list = g_list_append(*token_list, token); - tmp = tmp + idx; - } - } - - token_t *token = (token_t*)calloc(1, sizeof(token_t)); - int size = __tokenize_operator(token, tmp, 3); - - if (token != NULL && STRING_VALID(token->str)) { - *token_list = g_list_append(*token_list, token); - tmp += size; - idx = -1; - } else { - SAFE_FREE(token); - media_content_error("tokenize error occured"); - return -1; - } - } - } - - if (*tmp) { /* remained string */ - token_t *token = (token_t*)calloc(1, sizeof(token_t)); - media_content_retvm_if(token == NULL, -1, "OUT_OF_MEMORY"); - - ret = __tokenize_string(token, tmp, idx); - if (ret < 0) { - SAFE_FREE(token); - media_content_error("tokenize error occured"); - return -1; - } - - if (token != NULL && STRING_VALID(token->str)) { - *token_list = g_list_append(*token_list, token); - } else { - SAFE_FREE(token); - media_content_error("tokenize error occured"); - return -1; - } - } - - return MEDIA_CONTENT_ERROR_NONE; -} - -static int __tokenize(GList **token_list, const char *str) -{ - int ret = 0; - int idx = 0; - - media_content_retvm_if(!STRING_VALID(str), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Parameter string is invalid"); - - const char *tmp = str; - const char *dst_ptr = str + strlen(str); - - for (idx = 0; (*(tmp+idx)) && (tmp < dst_ptr); idx++) { - /* media_content_debug("[%d] '%c'", idx, tmp[idx]); */ - if (tmp[idx] == media_token[0][0]) { /* " " */ - if (idx == 0) { /* ignore the space. */ - tmp++; - idx = -1; - continue; - } - - token_t *token = (token_t*)calloc(1, sizeof(token_t)); - media_content_retvm_if(token == NULL, -1, "OUT_OF_MEMORY"); - - token->type = UNKNOWN_TYPE; - token->str = (char *)calloc(idx+1, sizeof(char)); - if (token->str == NULL) { - SAFE_FREE(token); - media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); - return -1; - } - strncpy(token->str, tmp, idx); - /* media_content_debug("type : [%d] str : [%s]", token->type, token->str); */ - *token_list = g_list_append(*token_list, token); - tmp = tmp +idx + strlen(media_token[0]); - idx = -1; - } else if (tmp[idx] == media_token[1][0]) { /* " \" " */ - int j; - bool flag = false; - for (j = idx+1; tmp[j]; j++) { /* find next quotation */ - if (tmp[j] == media_token[1][0] && tmp[j+1] == media_token[1][0]) { - j += 1; - continue; - } - if (tmp[j] == media_token[1][0]) { - token_t *token = (token_t*)calloc(1, sizeof(token_t)); - media_content_retvm_if(token == NULL, -1, "OUT_OF_MEMORY"); - - token->str = (char*) calloc(j+1+1, sizeof(char)); - if (token->str == NULL) { - SAFE_FREE(token); - media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); - return -1; - } - token->type = STRING_TYPE; - strncpy(token->str, tmp, j+1); - /* media_content_debug("type : [%d] str : [%s], j : %d", token->type, token->str, j); */ - *token_list = g_list_append(*token_list, token); - tmp = tmp + strlen(token->str); - idx = -1; - flag = true; - break; - } - } - - if (!flag && *tmp != '\0' && tmp[j] == '\0') { - token_t *token = (token_t*)calloc(1, sizeof(token_t)); - media_content_retvm_if(token == NULL, -1, "OUT_OF_MEMORY"); - - token->str = (char *) calloc(j+1, sizeof(char)); - if (token->str == NULL) { - SAFE_FREE(token); - media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); - return -1; - } - token->type = UNKNOWN_TYPE; - strncpy(token->str, tmp, j); - /* media_content_debug("type : [%d] str : [%s]", token->type, token->str);*/ - *token_list = g_list_append(*token_list, token); - tmp = tmp +strlen(token->str); - idx = -1; - } - } else if (tmp[idx] == media_token[2][0]) { /* " \' "*/ - int j; - bool flag = false; - for (j = idx+1; tmp[j]; j++) { - if (tmp[j] == media_token[2][0] && tmp[j+1] == media_token[2][0]) { - j += 1; - continue; - } - if (tmp[j] == media_token[2][0]) { - token_t *token = (token_t*)calloc(1, sizeof(token_t)); - media_content_retvm_if(token == NULL, -1, "OUT_OF_MEMORY"); - - token->str = (char *) calloc(j+1+1, sizeof(char)); - if (token->str == NULL) { - SAFE_FREE(token); - media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); - return -1; - } - token->type = STRING_TYPE; - strncpy(token->str, tmp, j+1); - /* media_content_debug("type : [%d] str : [%s]", token->type, token->str); */ - *token_list = g_list_append(*token_list, token); - tmp = tmp + strlen(token->str); - idx = -1; - flag = true; - break; - } - } - - if (!flag && *tmp != '\0' && tmp[j] == '\0') { - token_t *token = (token_t*)calloc(1, sizeof(token_t)); - media_content_retvm_if(token == NULL, -1, "OUT_OF_MEMORY"); - - token->str = (char*) calloc(j+1, sizeof(char)); - if (token->str == NULL) { - SAFE_FREE(token); - media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); - return -1; - } - token->type = UNKNOWN_TYPE; - strncpy(token->str, tmp, j); - /* media_content_debug("type : [%d] str : [%s]", token->type, token->str); */ - *token_list = g_list_append(*token_list, token); - tmp = tmp + strlen(token->str); - idx = -1; - } - } else if (tmp[idx] == media_token[3][0]) { /* "(" */ - if (idx != 0) { - token_t *token = (token_t*)calloc(1, sizeof(token_t)); - media_content_retvm_if(token == NULL, -1, "OUT_OF_MEMORY"); - - ret = __tokenize_string(token, tmp, idx); - if (ret < 0) { - SAFE_FREE(token); - media_content_error("tokenize error occured"); - return -1; - } else { - *token_list = g_list_append(*token_list, token); - tmp = tmp + idx; - } - } - token_t *token = (token_t*)calloc(1, sizeof(token_t)); - int size = __tokenize_operator(token, tmp, 3); - - if (token != NULL && STRING_VALID(token->str)) { - *token_list = g_list_append(*token_list, token); - tmp += size; - idx = -1; - } else { - SAFE_FREE(token); - media_content_error("tokenize error occured"); - return -1; - } - - } else if (tmp[idx] == media_token[4][0]) { /* ")" */ - if (idx != 0) { - token_t *token = (token_t*)calloc(1, sizeof(token_t)); - media_content_retvm_if(token == NULL, -1, "OUT_OF_MEMORY"); - - ret = __tokenize_string(token, tmp, idx); - if (ret < 0) { - SAFE_FREE(token); - media_content_error("tokenize error occured"); - return -1; - } else { - *token_list = g_list_append(*token_list, token); - tmp = tmp + idx; - } - } - token_t *token = (token_t*)calloc(1, sizeof(token_t)); - int size = __tokenize_operator(token, tmp, 4); - - if (token != NULL && STRING_VALID(token->str)) { - *token_list = g_list_append(*token_list, token); - tmp += size; - idx = -1; - } else { - SAFE_FREE(token); - media_content_error("tokenize error occured"); - return -1; - } - - } else if (tmp[idx] == media_token[5][0]) { /* "=" */ - if (idx != 0) { - token_t *token = (token_t*)calloc(1, sizeof(token_t)); - media_content_retvm_if(token == NULL, -1, "OUT_OF_MEMORY"); - - ret = __tokenize_string(token, tmp, idx); - if (ret < 0) { - SAFE_FREE(token); - media_content_error("tokenize error occured"); - return -1; - } else { - *token_list = g_list_append(*token_list, token); - tmp = tmp + idx; - } - } - token_t *token = (token_t*)calloc(1, sizeof(token_t)); - int size = __tokenize_operator(token, tmp, 5); - - if (token != NULL && STRING_VALID(token->str)) { - *token_list = g_list_append(*token_list, token); - tmp += size; - idx = -1; - } else { - SAFE_FREE(token); - media_content_error("tokenize error occured"); - return -1; - } - - } else if (tmp[idx] == media_token[6][0] && tmp[idx+1] == media_token[6][1]) { /* "<=", */ - if (idx != 0) { - token_t *token = (token_t*)calloc(1, sizeof(token_t)); - media_content_retvm_if(token == NULL, -1, "OUT_OF_MEMORY"); - - ret = __tokenize_string(token, tmp, idx); - if (ret < 0) { - SAFE_FREE(token); - media_content_error("tokenize error occured"); - return -1; - } else { - *token_list = g_list_append(*token_list, token); - tmp = tmp + idx; - } - } - token_t *token = (token_t*)calloc(1, sizeof(token_t)); - int size = __tokenize_operator(token, tmp, 6); - - if (token != NULL && STRING_VALID(token->str)) { - *token_list = g_list_append(*token_list, token); - tmp += size; - idx = -1; - } else { - SAFE_FREE(token); - media_content_error("tokenize error occured"); - return -1; - } - - } else if (tmp[idx] == media_token[7][0]) { /* "<", */ - if (idx != 0) { - token_t *token = (token_t*)calloc(1, sizeof(token_t)); - media_content_retvm_if(token == NULL, -1, "OUT_OF_MEMORY"); - - ret = __tokenize_string(token, tmp, idx); - if (ret < 0) { - SAFE_FREE(token); - media_content_error("tokenize error occured"); - return -1; - } else { - *token_list = g_list_append(*token_list, token); - tmp = tmp + idx; - } - } - token_t *token = (token_t*)calloc(1, sizeof(token_t)); - int size = __tokenize_operator(token, tmp, 7); - - if (token != NULL && STRING_VALID(token->str)) { - *token_list = g_list_append(*token_list, token); - tmp += size; - idx = -1; - } else { - SAFE_FREE(token); - media_content_error("tokenize error occured"); - return -1; - } - - } else if (tmp[idx] == media_token[8][0] && tmp[idx+1] == media_token[8][1]) { /* ">=", */ - if (idx != 0) { - token_t *token = (token_t*)calloc(1, sizeof(token_t)); - media_content_retvm_if(token == NULL, -1, "OUT_OF_MEMORY"); - - ret = __tokenize_string(token, tmp, idx); - if (ret < 0) { - SAFE_FREE(token); - media_content_error("tokenize error occured"); - return -1; - } else { - *token_list = g_list_append(*token_list, token); - tmp = tmp + idx; - } - } - token_t *token = (token_t*)calloc(1, sizeof(token_t)); - int size = __tokenize_operator(token, tmp, 8); - - if (token != NULL && STRING_VALID(token->str)) { - *token_list = g_list_append(*token_list, token); - tmp += size; - idx = -1; - } else { - SAFE_FREE(token); - media_content_error("tokenize error occured"); - return -1; - } - - } else if (tmp[idx] == media_token[9][0]) { /* ">", */ - if (idx != 0) { - token_t *token = (token_t*)calloc(1, sizeof(token_t)); - media_content_retvm_if(token == NULL, -1, "OUT_OF_MEMORY"); - - ret = __tokenize_string(token, tmp, idx); - if (ret < 0) { - SAFE_FREE(token); - media_content_error("tokenize error occured"); - return -1; - } else { - *token_list = g_list_append(*token_list, token); - tmp = tmp + idx; - } - } - token_t *token = (token_t*)calloc(1, sizeof(token_t)); - int size = __tokenize_operator(token, tmp, 9); - - if (token != NULL && STRING_VALID(token->str)) { - *token_list = g_list_append(*token_list, token); - tmp += size; - idx = -1; - } else { - SAFE_FREE(token); - media_content_error("tokenize error occured"); - return -1; - } - } else if (tmp[idx] == media_token[10][0] && tmp[idx+1] == media_token[10][1]) { /* "!=", */ - if (idx != 0) { - token_t *token = (token_t*)calloc(1, sizeof(token_t)); - media_content_retvm_if(token == NULL, -1, "OUT_OF_MEMORY"); - - ret = __tokenize_string(token, tmp, idx); - if (ret < 0) { - SAFE_FREE(token); - media_content_error("tokenize error occured"); - return -1; - } else { - *token_list = g_list_append(*token_list, token); - tmp = tmp + idx; - } - } - token_t *token = (token_t*)calloc(1, sizeof(token_t)); - int size = __tokenize_operator(token, tmp, 10); - - if (token != NULL && STRING_VALID(token->str)) { - *token_list = g_list_append(*token_list, token); - tmp += size; - idx = -1; - } else { - SAFE_FREE(token); - media_content_error("tokenize error occured"); - return -1; - } - } - } - - if (*tmp) { /* remained string */ - token_t *token = (token_t*)calloc(1, sizeof(token_t)); - media_content_retvm_if(token == NULL, -1, "OUT_OF_MEMORY"); - - ret = __tokenize_string(token, tmp, idx); - if (ret < 0) { - SAFE_FREE(token); - media_content_error("tokenize error occured"); - return -1; - } - - if (token != NULL && STRING_VALID(token->str)) { - *token_list = g_list_append(*token_list, token); - } else { - SAFE_FREE(token); - media_content_error("tokenize error occured"); - return -1; - } + return " COLLATE localized "; + default: + return " "; } - - return MEDIA_CONTENT_ERROR_NONE; } -int _media_filter_attribute_create(attribute_h *attr) +static bool __check_collate_type(media_content_collation_e collate_type) { - int ret = MEDIA_CONTENT_ERROR_NONE; - - media_content_retvm_if(attr == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid attr"); - - attribute_s *_attr = (attribute_s*)calloc(1, sizeof(attribute_s)); - media_content_retvm_if(_attr == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); - - _attr->attr_map = g_hash_table_new(g_str_hash, g_str_equal); - *attr = (attribute_h)_attr; - - return ret; -} - -int _media_filter_attribute_add(attribute_h attr, const char *user_attr, const char *platform_attr) -{ - int ret = MEDIA_CONTENT_ERROR_NONE; - char *_user = NULL; - char *_platform = NULL; - attribute_s *_attr = (attribute_s*)attr; - - media_content_retvm_if(_attr == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid attr"); - - if (STRING_VALID(user_attr) && STRING_VALID(platform_attr)) { - _user = g_strdup(user_attr); - media_content_retvm_if(_user == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); - - _platform = g_strdup(platform_attr); - if (_platform == NULL) { - SAFE_G_FREE(_user); - media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); - return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; - } - - g_hash_table_insert(_attr->attr_map, _user, _platform); - } else { - media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; + switch (collate_type) { + case MEDIA_CONTENT_COLLATE_DEFAULT: + case MEDIA_CONTENT_COLLATE_NOCASE: + case MEDIA_CONTENT_COLLATE_RTRIM: + case MEDIA_CONTENT_COLLATE_LOCALIZED: + return true; + default: + return false; } - - return ret; } -int _media_filter_attribute_destory(attribute_h attr) +static bool __check_order_type(media_content_order_e order) { - int ret = MEDIA_CONTENT_ERROR_NONE; - attribute_s *_attr = (attribute_s*)attr; - - media_content_retvm_if(_attr == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid attr"); - - if (_attr->attr_map != NULL) { - g_hash_table_foreach(_attr->attr_map, __filter_attribute_free_value, NULL); - g_hash_table_destroy(_attr->attr_map); + switch (order) { + case MEDIA_CONTENT_ORDER_ASC: + case MEDIA_CONTENT_ORDER_DESC: + case MEDIA_CONTENT_ORDER_OTHER: + return true; + default: + return false; } - - SAFE_FREE(_attr); - - return ret; } -int _media_filter_attribute_generate(attribute_h attr, filter_h filter, char **generated_condition) +int _media_filter_build_condition(bool is_full, const char *condition, media_content_collation_e collate_type, char **result) { - unsigned int idx = 0; - GList *token_list = NULL; - int ret = MEDIA_CONTENT_ERROR_NONE; - token_t *token; - filter_s *_filter = NULL; - char tmp_condition[MAX_QUERY_SIZE] = {0, }; - - media_content_retvm_if(attr == NULL, MEDIA_CONTENT_ERROR_DB_FAILED, "DB field mapping table doesn't exist. Check db connection"); - media_content_retvm_if(filter == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid filter"); - media_content_retvm_if(generated_condition == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid generated_condition"); - - _filter = (filter_s*)filter; - - media_content_retvm_if(_filter->condition == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid condition"); - media_content_retvm_if(_filter->condition_collate_type < MEDIA_CONTENT_COLLATE_DEFAULT || - _filter->condition_collate_type > MEDIA_CONTENT_COLLATE_LOCALIZED, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid condition collate"); - - if (__tokenize(&token_list, _filter->condition) < 0) { - media_content_error("INVALID_PARAMETER(0x%08x):Invalid the condition", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } + content_retip_if_fail(condition); + content_retip_if_fail(__check_collate_type(collate_type)); + content_retip_if_fail(result); - for (idx = 0; idx < g_list_length(token_list); idx++) { - token = (token_t*)g_list_nth_data(token_list, idx); - - if (token->type == UNKNOWN_TYPE) { - char *replace_str = __media_filter_replace_attr(attr, token->str); - if (STRING_VALID(replace_str)) { - SAFE_FREE(token->str); - token->str = replace_str; - } - } - } - - /* make the statment */ - memset(tmp_condition, 0, sizeof(tmp_condition)); - SAFE_STRLCAT(tmp_condition, QUERY_KEYWORD_OPEN_BRACKET, sizeof(tmp_condition)); - - for (idx = 0; idx < g_list_length(token_list); idx++) { - token = (token_t*)g_list_nth_data(token_list, idx); - - if ((token != NULL) && STRING_VALID(token->str)) { - SAFE_STRLCAT(tmp_condition, token->str, sizeof(tmp_condition)); - SAFE_STRLCAT(tmp_condition, QUERY_KEYWORD_SPACE, sizeof(tmp_condition)); - - SAFE_FREE(token->str); - SAFE_FREE(token); - } - } - - /* Process for filter v1 */ - if (_filter->is_full_condition == false && _filter->condition_collate_type != MEDIA_CONTENT_COLLATE_DEFAULT) { - SAFE_STRLCAT(tmp_condition, QUERY_KEYWORD_COLLATE, sizeof(tmp_condition)); - SAFE_STRLCAT(tmp_condition, __get_collate_str(_filter->condition_collate_type), sizeof(tmp_condition)); - SAFE_STRLCAT(tmp_condition, QUERY_KEYWORD_SPACE, sizeof(tmp_condition)); - } - - SAFE_STRLCAT(tmp_condition, QUERY_KEYWORD_BRACKET, sizeof(tmp_condition)); - - if (STRING_VALID(tmp_condition)) - *generated_condition = g_strdup(tmp_condition); + if (is_full) + *result = g_strdup_printf("(%s)", condition); else - *generated_condition = NULL; + *result = g_strdup_printf("(%s%s)", condition, __get_collate_str(collate_type)); - media_content_sec_debug("Condition : %s", *generated_condition); + content_sec_debug("Condition : %s", *result); - if (token_list != NULL) { - g_list_free(token_list); - token_list = NULL; - } - - return ret; + return MEDIA_CONTENT_ERROR_NONE; } -int _media_filter_attribute_option_generate(attribute_h attr, filter_h filter, char **generated_option) +int _media_filter_build_option(filter_h filter, char **result) { - int ret = MEDIA_CONTENT_ERROR_NONE; - filter_s *_filter = NULL; - char query[DEFAULT_QUERY_SIZE] = {0, }; - char option[DEFAULT_QUERY_SIZE] = {0, }; - - media_content_retvm_if(attr == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid attr"); - media_content_retvm_if(filter == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid filter"); - - _filter = (filter_s*)filter; - - memset(query, 0x00, sizeof(query)); - - /* Order by*/ - if (STRING_VALID(_filter->order_keyword)) { - if ((_filter->order_type == MEDIA_CONTENT_ORDER_ASC) || (_filter->order_type == MEDIA_CONTENT_ORDER_DESC)) { - unsigned int idx = 0; - GList *token_list = NULL; - token_t *token; - char *attr_str; - - if (__tokenize_attribute(&token_list, _filter->order_keyword) < 0) { - media_content_error("INVALID_PARAMETER(0x%08x):Invalid the condition", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } - - for (idx = 0; idx < g_list_length(token_list); idx++) { - token = (token_t*)g_list_nth_data(token_list, idx); - - if (token->type == UNKNOWN_TYPE) { - char *replace_str = __media_filter_replace_attr(attr, token->str); - if (STRING_VALID(replace_str)) { - attr_str = (char*)calloc(strlen(replace_str) + COLLATE_STR_SIZE + 1, sizeof(char)); - if (attr_str == NULL) { - media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); - SAFE_FREE(replace_str); - continue; - } - - 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) - 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)); - else - snprintf(attr_str, strlen(replace_str) + COLLATE_STR_SIZE + 1, "%s %s", replace_str, __get_order_str(_filter->order_type)); - - SAFE_FREE(token->str); - token->str = attr_str; - SAFE_FREE(replace_str); - } else { - media_content_error("There is no matched db field for %s", token->str); - } - } - } - - /* make the statment */ - SAFE_STRLCAT(query, QUERY_KEYWORD_ORDER_BY, sizeof(query)); - - for (idx = 0; idx < g_list_length(token_list); idx++) { - token = (token_t*)g_list_nth_data(token_list, idx); - - if ((token != NULL) && STRING_VALID(token->str)) { - SAFE_STRLCAT(query, token->str, sizeof(query)); - SAFE_STRLCAT(query, QUERY_KEYWORD_SPACE, sizeof(query)); - - SAFE_FREE(token->str); - SAFE_FREE(token); - } - } - - if (token_list != NULL) { - g_list_free(token_list); - token_list = NULL; - } - } else { - SAFE_STRLCAT(query, _filter->order_keyword, sizeof(query)); - } - } - - /* offset */ - SAFE_STRLCAT(query, QUERY_KEYWORD_SPACE, sizeof(query)); - - memset(option, 0, sizeof(option)); - snprintf(option, sizeof(option), "%s %d, %d", QUERY_KEYWORD_LIMIT, _filter->offset, _filter->count); + filter_s *_filter = (filter_s *)filter; - SAFE_STRLCAT(query, option, sizeof(query)); + content_retip_if_fail(filter); + content_retip_if_fail(result); - if (STRING_VALID(query)) { - *generated_option = g_strdup(query); - media_content_sec_debug("Option : %s", *generated_option); - } else { - *generated_option = NULL; + if (!STRING_VALID(_filter->order_keyword)) { + *result = g_strdup_printf(" LIMIT %d, %d", _filter->offset, _filter->count); + return MEDIA_CONTENT_ERROR_NONE; } - return ret; -} - -int _media_filter_attribute_option_generate_with_full_query(attribute_h attr, filter_h filter, char **generated_option) -{ - unsigned int idx = 0; - GList *token_list = NULL; - int ret = MEDIA_CONTENT_ERROR_NONE; - token_t *token; - filter_s * _filter = NULL; - char query[DEFAULT_QUERY_SIZE] = {0, }; - char option[DEFAULT_QUERY_SIZE] = {0, }; - - media_content_retvm_if(attr == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid attr"); - media_content_retvm_if(filter == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid filter"); - media_content_retvm_if(generated_option == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid generated_option"); - - _filter = (filter_s*)filter; - - memset(query, 0, sizeof(query)); - - /* Order by*/ - if (STRING_VALID(_filter->order_keyword)) { - if (__tokenize_attribute(&token_list, _filter->order_keyword) < 0) { - media_content_error("INVALID_PARAMETER(0x%08x):Invalid the order", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } - - for (idx = 0; idx < g_list_length(token_list); idx++) { - token = (token_t*)g_list_nth_data(token_list, idx); - - if (token->type == UNKNOWN_TYPE) { - char *replace_str = __media_filter_replace_attr(attr, token->str); - if (STRING_VALID(replace_str)) { - SAFE_FREE(token->str); - token->str = replace_str; - } - } - } - - /* make the statment */ - SAFE_STRLCAT(query, QUERY_KEYWORD_ORDER_BY, sizeof(query)); - - for (idx = 0; idx < g_list_length(token_list); idx++) { - token = (token_t*)g_list_nth_data(token_list, idx); - - if ((token != NULL) && STRING_VALID(token->str)) { - SAFE_STRLCAT(query, token->str, sizeof(query)); - SAFE_STRLCAT(query, QUERY_KEYWORD_SPACE, sizeof(query)); - - SAFE_FREE(token->str); - SAFE_FREE(token); - } - } - - if (token_list != NULL) { - g_list_free(token_list); - token_list = NULL; - } + if (_filter->is_full_order) { + *result = g_strdup_printf("ORDER BY %s LIMIT %d, %d", _filter->order_keyword, _filter->offset, _filter->count); + return MEDIA_CONTENT_ERROR_NONE; } - /* offset */ - SAFE_STRLCAT(query, QUERY_KEYWORD_SPACE, sizeof(query)); - - memset(option, 0, sizeof(option)); - snprintf(option, sizeof(option), "%s %d, %d", QUERY_KEYWORD_LIMIT, _filter->offset, _filter->count); - SAFE_STRLCAT(query, option, sizeof(query)); - - if (STRING_VALID(query)) { - *generated_option = g_strdup(query); - media_content_sec_debug("Option : %s", *generated_option); + if (_filter->order_type == MEDIA_CONTENT_ORDER_ASC || _filter->order_type == MEDIA_CONTENT_ORDER_DESC) { + *result = g_strdup_printf("ORDER BY %s%s%s LIMIT %d, %d", + _filter->order_keyword, + __get_collate_str(_filter->order_collate_type), + __get_order_str(_filter->order_type), + _filter->offset, + _filter->count); } else { - *generated_option = NULL; +#ifdef _USE_TVPD_MODE + *result = g_strdup_printf("%s LIMIT %d, %d", _filter->order_keyword, _filter->offset, _filter->count); +#else + *result = g_strdup_printf("ORDER BY %s LIMIT %d, %d", _filter->order_keyword, _filter->offset, _filter->count); +#endif } - return ret; + return MEDIA_CONTENT_ERROR_NONE; } - int media_filter_create(filter_h *filter) { int ret = MEDIA_CONTENT_ERROR_NONE; - media_content_retvm_if(filter == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid filter"); + content_retip_if_fail(filter); - filter_s *_filter = (filter_s*)calloc(1, sizeof(filter_s)); - media_content_retvm_if(_filter == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); + filter_s *_filter = g_new0(filter_s, 1); _filter->storage_id = NULL; _filter->condition = NULL; @@ -968,295 +146,189 @@ int media_filter_create(filter_h *filter) int media_filter_destroy(filter_h filter) { - int ret = MEDIA_CONTENT_ERROR_NONE; - filter_s *_filter = (filter_s*)filter; + filter_s *_filter = (filter_s *)filter; - if (_filter) { - SAFE_FREE(_filter->storage_id); - SAFE_FREE(_filter->condition); - SAFE_FREE(_filter->order_keyword); - SAFE_FREE(_filter); + content_retip_if_fail(filter); - ret = MEDIA_CONTENT_ERROR_NONE; - } else { - media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } + g_free(_filter->storage_id); + g_free(_filter->condition); + g_free(_filter->order_keyword); + g_free(_filter); - return ret; + return MEDIA_CONTENT_ERROR_NONE; } int media_filter_set_offset(filter_h filter, int offset, int count) { - int ret = MEDIA_CONTENT_ERROR_NONE; - filter_s *_filter = (filter_s*)filter; + filter_s *_filter = (filter_s *)filter; - if (_filter != NULL) { - _filter->offset = offset; - _filter->count = count; - } else { - media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } + content_retip_if_fail(filter); - return ret; + _filter->offset = offset; + _filter->count = count; + + return MEDIA_CONTENT_ERROR_NONE; } int media_filter_set_condition(filter_h filter, const char *condition, media_content_collation_e collate_type) { int ret = MEDIA_CONTENT_ERROR_NONE; - filter_s *_filter = (filter_s*)filter; + filter_s *_filter = (filter_s *)filter; - if ((_filter != NULL) && STRING_VALID(condition) - && ((collate_type >= MEDIA_CONTENT_COLLATE_DEFAULT) && (collate_type <= MEDIA_CONTENT_COLLATE_LOCALIZED))) { + content_retip_if_fail(filter); + content_retip_if_fail(STRING_VALID(condition)); + content_retip_if_fail(__check_collate_type(collate_type)); - _filter->is_full_condition = false; - - if (STRING_VALID(_filter->condition)) - SAFE_FREE(_filter->condition); + _filter->is_full_condition = false; + g_free(_filter->condition); - char new_condition[MAX_QUERY_SIZE] = {0, }; - memset(new_condition, 0, sizeof(new_condition)); - ret = _media_content_replace_path_in_condition(condition, new_condition, TRUE); - media_content_retvm_if(!STRING_VALID(new_condition), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed"); + _filter->condition = g_strdup(condition); - _filter->condition = strdup(new_condition); - media_content_retvm_if(_filter->condition == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); + content_sec_debug("Condition string : %s", _filter->condition); - media_content_sec_debug("Condition string : %s", _filter->condition); - - _filter->condition_collate_type = collate_type; - } else { - media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } + _filter->condition_collate_type = collate_type; return ret; } int media_filter_set_order(filter_h filter, media_content_order_e order_type, const char *order_keyword, media_content_collation_e collate_type) { - int ret = MEDIA_CONTENT_ERROR_NONE; - filter_s *_filter = (filter_s*)filter; + filter_s *_filter = (filter_s *)filter; - if ((_filter != NULL) && STRING_VALID(order_keyword) - && ((order_type == MEDIA_CONTENT_ORDER_ASC) || (order_type == MEDIA_CONTENT_ORDER_DESC)) - && ((collate_type >= MEDIA_CONTENT_COLLATE_DEFAULT) && (collate_type <= MEDIA_CONTENT_COLLATE_LOCALIZED))) { + content_retip_if_fail(filter); + content_retip_if_fail(STRING_VALID(order_keyword)); + content_retip_if_fail(__check_order_type(order_type)); + content_retip_if_fail(__check_collate_type(collate_type)); - _filter->is_full_order = false; + _filter->is_full_order = false; - SAFE_FREE(_filter->order_keyword); + g_free(_filter->order_keyword); - _filter->order_keyword = strdup(order_keyword); - media_content_retvm_if(_filter->order_keyword == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); + _filter->order_keyword = g_strdup(order_keyword); + _filter->order_type = order_type; + _filter->order_collate_type = collate_type; - _filter->order_type = order_type; - _filter->order_collate_type = collate_type; - } else { - media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } - - return ret; + return MEDIA_CONTENT_ERROR_NONE; } - +#ifdef _USE_TVPD_MODE int media_filter_set_storage(filter_h filter, const char *storage_id) { - int ret = MEDIA_CONTENT_ERROR_NONE; - filter_s *_filter = (filter_s*)filter; + filter_s *_filter = (filter_s *)filter; - if ((_filter != NULL) && STRING_VALID(storage_id)) { - if (STRING_VALID(_filter->storage_id)) - SAFE_FREE(_filter->storage_id); + content_retip_if_fail(filter); + content_retip_if_fail(STRING_VALID(storage_id)); - _filter->storage_id = strdup(storage_id); - media_content_retvm_if(_filter->storage_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); + g_free(_filter->storage_id); + _filter->storage_id = g_strdup(storage_id); - media_content_sec_debug("storage_id : %s", _filter->storage_id); - } else { - media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } + content_sec_debug("storage_id : %s", _filter->storage_id); - return ret; + return MEDIA_CONTENT_ERROR_NONE; } - +#endif int media_filter_get_offset(filter_h filter, int *offset, int *count) { - int ret = MEDIA_CONTENT_ERROR_NONE; - filter_s *_filter = (filter_s*)filter; + filter_s *_filter = (filter_s *)filter; - if (_filter) { - *offset = _filter->offset; - *count = _filter->count; - } else { - media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } + content_retip_if_fail(filter); + content_retip_if_fail(offset); + content_retip_if_fail(count); - return ret; + *offset = _filter->offset; + *count = _filter->count; + + return MEDIA_CONTENT_ERROR_NONE; } int media_filter_get_condition(filter_h filter, char **condition, media_content_collation_e *collate_type) { - int ret = MEDIA_CONTENT_ERROR_NONE; - filter_s *_filter = (filter_s*)filter; - - if (_filter) { - if (STRING_VALID(_filter->condition) && _filter->is_full_condition == false) { - char new_condition[MAX_QUERY_SIZE] = {0, }; - memset(new_condition, 0, sizeof(new_condition)); - ret = _media_content_replace_path_in_condition(_filter->condition, new_condition, FALSE); - media_content_retvm_if(!STRING_VALID(new_condition), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed"); - - *condition = strdup(new_condition); - media_content_retvm_if(*condition == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); - } else { - *condition = NULL; - } - - *collate_type = _filter->condition_collate_type; - } else { - media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } + filter_s *_filter = (filter_s *)filter; - return ret; -} + content_retip_if_fail(filter); + content_retip_if_fail(condition); + content_retip_if_fail(collate_type); -int media_filter_get_order(filter_h filter, media_content_order_e* order_type, char **order_keyword, media_content_collation_e *collate_type) -{ - int ret = MEDIA_CONTENT_ERROR_NONE; - filter_s *_filter = (filter_s*)filter; - - if (_filter) { - if (STRING_VALID(_filter->order_keyword) && _filter->is_full_order == false) { - *order_keyword = strdup(_filter->order_keyword); - media_content_retvm_if(*order_keyword == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); - } else { - *order_keyword = NULL; - } - - *order_type = _filter->order_type; - *collate_type = _filter->order_collate_type; - } else { - media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } + if (!_filter->is_full_condition) + *condition = g_strdup(_filter->condition); - return ret; + *collate_type = _filter->condition_collate_type; + + return MEDIA_CONTENT_ERROR_NONE; } -int media_filter_get_storage(filter_h filter, char **storage_id) +int media_filter_get_order(filter_h filter, media_content_order_e *order_type, char **order_keyword, media_content_collation_e *collate_type) { - int ret = MEDIA_CONTENT_ERROR_NONE; - filter_s *_filter = (filter_s*)filter; - - if (_filter) { - if (STRING_VALID(_filter->storage_id)) { - *storage_id = strdup(_filter->storage_id); - media_content_retvm_if(*storage_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); - } else { - *storage_id = NULL; - } - } else { - media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } + filter_s *_filter = (filter_s *)filter; - return ret; + content_retip_if_fail(filter); + content_retip_if_fail(order_type); + content_retip_if_fail(order_keyword); + content_retip_if_fail(collate_type); + + if (!_filter->is_full_order) + *order_keyword = g_strdup(_filter->order_keyword); + + *order_type = _filter->order_type; + *collate_type = _filter->order_collate_type; + + return MEDIA_CONTENT_ERROR_NONE; } int media_filter_set_condition_v2(filter_h filter, const char *condition) { - int ret = MEDIA_CONTENT_ERROR_NONE; - filter_s *_filter = (filter_s*)filter; + filter_s *_filter = (filter_s *)filter; - if ((_filter != NULL) && STRING_VALID(condition)) { - _filter->is_full_condition = true; + content_retip_if_fail(filter); + content_retip_if_fail(STRING_VALID(condition)); - if (STRING_VALID(_filter->condition)) - SAFE_FREE(_filter->condition); + _filter->is_full_condition = true; - char new_condition[MAX_QUERY_SIZE] = {0, }; - memset(new_condition, 0, sizeof(new_condition)); - ret = _media_content_replace_path_in_condition(condition, new_condition, TRUE); - media_content_retvm_if(!STRING_VALID(new_condition), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed"); + g_free(_filter->condition); - _filter->condition = strdup(new_condition); - media_content_retvm_if(_filter->condition == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); + _filter->condition = g_strdup(condition); - media_content_sec_debug("Condition string : %s", _filter->condition); - } else { - media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } + content_sec_debug("Condition string : %s", _filter->condition); - return ret; + return MEDIA_CONTENT_ERROR_NONE; } int media_filter_get_condition_v2(filter_h filter, char **condition) { - int ret = MEDIA_CONTENT_ERROR_NONE; - filter_s *_filter = (filter_s*)filter; - - if (_filter) { - if (STRING_VALID(_filter->condition) && _filter->is_full_condition == true) { - char new_condition[MAX_QUERY_SIZE] = {0, }; - memset(new_condition, 0, sizeof(new_condition)); - ret = _media_content_replace_path_in_condition(_filter->condition, new_condition, FALSE); - media_content_retvm_if(!STRING_VALID(new_condition), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed"); - - *condition = strdup(new_condition); - media_content_retvm_if(*condition == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); - } else { - *condition = NULL; - } - } else { - media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } + filter_s *_filter = (filter_s *)filter; - return ret; + content_retip_if_fail(filter); + content_retip_if_fail(condition); + + if (_filter->is_full_condition) + *condition = g_strdup(_filter->condition); + + return MEDIA_CONTENT_ERROR_NONE; } int media_filter_set_order_v2(filter_h filter, const char *order) { - int ret = MEDIA_CONTENT_ERROR_NONE; - filter_s *_filter = (filter_s*)filter; + filter_s *_filter = (filter_s *)filter; - if ((_filter != NULL) && STRING_VALID(order)) { - _filter->is_full_order = true; + content_retip_if_fail(filter); + content_retip_if_fail(STRING_VALID(order)); - SAFE_FREE(_filter->order_keyword); + _filter->is_full_order = true; - _filter->order_keyword = strdup(order); - media_content_retvm_if(_filter->order_keyword == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); - } else { - media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } + g_free(_filter->order_keyword); + _filter->order_keyword = g_strdup(order); - return ret; + return MEDIA_CONTENT_ERROR_NONE; } int media_filter_get_order_v2(filter_h filter, char **order) { - int ret = MEDIA_CONTENT_ERROR_NONE; - filter_s *_filter = (filter_s*)filter; - - if (_filter) { - if (STRING_VALID(_filter->order_keyword) && _filter->is_full_order == true) { - *order = strdup(_filter->order_keyword); - media_content_retvm_if(*order == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); - } else { - *order = NULL; - } - } else { - media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); - ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER; - } + filter_s *_filter = (filter_s *)filter; - return ret; -} + content_retip_if_fail(filter); + content_retip_if_fail(order); + if (_filter->is_full_order) + *order = g_strdup(_filter->order_keyword); + + return MEDIA_CONTENT_ERROR_NONE; +}