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