}
}
+static bool __check_order_type(media_content_order_e order)
+{
+ switch (order) {
+ case MEDIA_CONTENT_ORDER_ASC:
+ case MEDIA_CONTENT_ORDER_DESC:
+ case MEDIA_CONTENT_ORDER_OTHER:
+ return true;
+ default:
+ return false;
+ }
+}
+
int _media_filter_build_condition(bool is_full, const char *condition, media_content_collation_e collate_type, char **result)
{
- media_content_retvm_if(result == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid out param");
- media_content_retvm_if(!STRING_VALID(condition), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid condition");
- media_content_retvm_if(!__check_collate_type(collate_type), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid condition collate");
+ media_content_retvm_if(!result, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid result");
+ media_content_retvm_if(!STRING_VALID(condition), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid condition");
+ media_content_retvm_if(!__check_collate_type(collate_type), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid collate_type");
if (is_full)
*result = g_strdup_printf("(%s)", condition);
filter_s *_filter = (filter_s *)filter;
media_content_retvm_if(!_filter, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid filter");
- media_content_retvm_if(!result, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid out param");
+ media_content_retvm_if(!result, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid result");
if (!STRING_VALID(_filter->order_keyword)) {
*result = g_strdup_printf(" LIMIT %d, %d", _filter->offset, _filter->count);
int media_filter_destroy(filter_h filter)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
filter_s *_filter = (filter_s *)filter;
+ media_content_retvm_if(!_filter, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid filter");
- if (_filter) {
- SAFE_FREE(_filter->storage_id);
- SAFE_FREE(_filter->condition);
- SAFE_FREE(_filter->order_keyword);
- SAFE_FREE(_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;
- }
+ SAFE_FREE(_filter->storage_id);
+ SAFE_FREE(_filter->condition);
+ SAFE_FREE(_filter->order_keyword);
+ SAFE_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;
+ media_content_retvm_if(!_filter, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid 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;
- }
+ _filter->offset = offset;
+ _filter->count = count;
- return ret;
+ 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;
+ media_content_retvm_if(!_filter, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid filter");
+ media_content_retvm_if(!STRING_VALID(condition), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid condition");
+ media_content_retvm_if(!__check_collate_type(collate_type), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid collate_type");
- if ((_filter != NULL) && STRING_VALID(condition)
- && ((collate_type >= MEDIA_CONTENT_COLLATE_DEFAULT) && (collate_type <= MEDIA_CONTENT_COLLATE_LOCALIZED))) {
-
- _filter->is_full_condition = false;
-
- if (STRING_VALID(_filter->condition))
- SAFE_FREE(_filter->condition);
+ _filter->is_full_condition = false;
+ SAFE_FREE(_filter->condition);
- _filter->condition = _media_content_replace_path_in_condition(condition);
+ _filter->condition = _media_content_replace_path_in_condition(condition);
- /* FIXME
- If an error is occured in _media_content_replace_path_in_condition(),
- A suitable return value is 'MEDIA_CONTENT_ERROR_INVALID_OPERATION'.
- However, it is not stated in the description of media_filter_set_condition().
- Therefore, use 'MEDIA_CONTENT_ERROR_OUT_OF_MEMORY' temporarily.
- It will be modified after removing _media_content_replace_path_in_condition() function.
- */
- media_content_retvm_if(_filter->condition == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "Fail to _media_content_replace_path_in_condition");
+ /* FIXME
+ If an error is occured in _media_content_replace_path_in_condition(),
+ A suitable return value is 'MEDIA_CONTENT_ERROR_INVALID_OPERATION'.
+ However, it is not stated in the description of media_filter_set_condition().
+ Therefore, use 'MEDIA_CONTENT_ERROR_OUT_OF_MEMORY' temporarily.
+ It will be modified after removing _media_content_replace_path_in_condition() function.
+ */
+ media_content_retvm_if(_filter->condition == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "Fail to set condition");
- media_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;
+ media_content_retvm_if(!_filter, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid filter");
+ media_content_retvm_if(!STRING_VALID(order_keyword), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid order_keyword");
+ media_content_retvm_if(!__check_order_type(order_type), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid order_type");
+ media_content_retvm_if(!__check_collate_type(collate_type), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid collate_type");
- 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))) {
-
- _filter->is_full_order = false;
-
- SAFE_FREE(_filter->order_keyword);
+ _filter->is_full_order = false;
+ SAFE_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;
}
int media_filter_set_storage(filter_h filter, const char *storage_id)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
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.");
filter_s *_filter = (filter_s *)filter;
+ media_content_retvm_if(!_filter || !STRING_VALID(storage_id), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid parameter");
- if ((_filter != NULL) && STRING_VALID(storage_id)) {
- if (STRING_VALID(_filter->storage_id))
- SAFE_FREE(_filter->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");
+ SAFE_FREE(_filter->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;
- }
+ _filter->storage_id = g_strdup(storage_id);
+ media_content_sec_debug("storage_id : %s", _filter->storage_id);
- return ret;
+ return MEDIA_CONTENT_ERROR_NONE;
}
int media_filter_get_offset(filter_h filter, int *offset, int *count)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
filter_s *_filter = (filter_s *)filter;
+ media_content_retvm_if(!_filter || !offset || !count, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid parameter");
- 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;
- }
+ *offset = _filter->offset;
+ *count = _filter->count;
- return ret;
+ 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;
+ media_content_retvm_if(!_filter, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid _filter");
+ media_content_retvm_if(!condition, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid condition");
+ media_content_retvm_if(!collate_type, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid collate_type");
- if (_filter) {
- if (STRING_VALID(_filter->condition) && _filter->is_full_condition == false) {
- *condition = strdup(_filter->condition);
- media_content_retvm_if(*condition == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
- } else {
- *condition = NULL;
- }
+ if (!_filter->is_full_condition)
+ *condition = g_strdup(_filter->condition);
- *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;
- }
+ *collate_type = _filter->condition_collate_type;
- return ret;
+ return MEDIA_CONTENT_ERROR_NONE;
}
-int media_filter_get_order(filter_h filter, media_content_order_e* order_type, char **order_keyword, media_content_collation_e *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;
+ media_content_retvm_if(!_filter || !order_type, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid parameter");
+ media_content_retvm_if(!order_keyword || !collate_type, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid parameter");
- 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;
- }
+ if (!_filter->is_full_order)
+ *order_keyword = g_strdup(_filter->order_keyword);
- *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;
- }
+ *order_type = _filter->order_type;
+ *collate_type = _filter->order_collate_type;
- return ret;
+ return MEDIA_CONTENT_ERROR_NONE;
}
int media_filter_get_storage(filter_h filter, char **storage_id)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
media_content_warn("DEPRECATION WARNING: media_filter_get_storage() is deprecated and will be removed from next release.");
filter_s *_filter = (filter_s *)filter;
+ media_content_retvm_if(!_filter || !storage_id, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid parameter");
- 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;
- }
+ *storage_id = g_strdup(_filter->storage_id);
- return ret;
+ 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;
+ media_content_retvm_if(!_filter || !STRING_VALID(condition), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid parameter");
- if ((_filter != NULL) && STRING_VALID(condition)) {
- _filter->is_full_condition = true;
+ _filter->is_full_condition = true;
+ SAFE_FREE(_filter->condition);
- if (STRING_VALID(_filter->condition))
- SAFE_FREE(_filter->condition);
+ /* FIXME
+ If an error is occured in _media_content_replace_path_in_condition(),
+ A suitable return value is 'MEDIA_CONTENT_ERROR_INVALID_OPERATION'.
+ However, it is not stated in the description of media_filter_set_condition().
+ Therefore, use 'MEDIA_CONTENT_ERROR_OUT_OF_MEMORY' temporarily.
+ It will be modified after removing _media_content_replace_path_in_condition() function.
+ */
+ _filter->condition = _media_content_replace_path_in_condition(condition);
+ media_content_retvm_if(_filter->condition == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "Fail to set condition");
- /* FIXME
- If an error is occured in _media_content_replace_path_in_condition(),
- A suitable return value is 'MEDIA_CONTENT_ERROR_INVALID_OPERATION'.
- However, it is not stated in the description of media_filter_set_condition().
- Therefore, use 'MEDIA_CONTENT_ERROR_OUT_OF_MEMORY' temporarily.
- It will be modified after removing _media_content_replace_path_in_condition() function.
- */
- _filter->condition = _media_content_replace_path_in_condition(condition);
- media_content_retvm_if(_filter->condition == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "Fail to _media_content_replace_path_in_condition");
+ media_content_sec_debug("Condition string : %s", _filter->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;
- }
-
- 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;
+ media_content_retvm_if(!_filter || !condition, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid parameter");
- if (_filter) {
- if (STRING_VALID(_filter->condition) && _filter->is_full_condition == true) {
- *condition = strdup(_filter->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;
- }
+ if (_filter->is_full_condition)
+ *condition = g_strdup(_filter->condition);
- return ret;
+ 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;
+ media_content_retvm_if(!_filter || !STRING_VALID(order), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid parameter");
- if ((_filter != NULL) && STRING_VALID(order)) {
- _filter->is_full_order = true;
+ _filter->is_full_order = true;
+ SAFE_FREE(_filter->order_keyword);
- SAFE_FREE(_filter->order_keyword);
+ _filter->order_keyword = g_strdup(order);
- _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;
- }
-
- 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;
+ media_content_retvm_if(!_filter || !order, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid parameter");
- 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;
- }
+ if (_filter->is_full_order)
+ *order = g_strdup(_filter->order_keyword);
- return ret;
+ return MEDIA_CONTENT_ERROR_NONE;
}