- 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;
- }