+++ /dev/null
-#include <stdbool.h>
-#include <Eina.h>
-#include "xml_parser.h"
-#include "logger.h"
-
-#define BUF_SIZE 1024
-
-
-void test_fun()
-{
- DEBUG("HELLO LIB\n");
-}
-
-
-typedef struct
-{
- char *key;
- int values_count;
- char **values;
-} Attribute_Info;
-
-
-typedef struct
-{
- int attribute_count;
- char *tag_type;
- Eina_Simple_XML_Type type;
- Attribute_Info **available_arguments;
-} Item_Info;
-
-typedef struct
-{
- const char *descr;
- Item_Info *item_info;
-
- const char *current_tag;
- int current_tag_len;
- int current_offset;
- const char *error_message;
-
- Eina_Bool xml_header;
- Eina_Bool complex_header;
- Eina_Bool tag_validation;
-
- Eina_List *tag_stash;
- Eina_List *available_tags;
-
- int call_count;
- int last_error_offset;
- int last_error_line;
-
-
- Eina_List *found_names;
-} S_is_xml;
-
-S_is_xml is_xml;
-
-#ifndef EINA_INLIST_FREE
- #define EINA_INLIST_FREE(list, it) \
- for(it = (__typeof__(it)) list; list; it = (__typeof__(it)) list)
-#endif
-
-
-// =========================================== Print ==============================
-
-void print_tree(Eina_Simple_XML_Node_Tag *tag, int text_offset)
-{
- DEBUG(": %s start\n", __FUNCTION__);
-
- if(tag == NULL)
- {
- DEBUG("No tree found\n");
- }
- else if(tag->base.type == EINA_SIMPLE_XML_NODE_ROOT)
- {
- DEBUG("Tree of root\n");
- }
-
- DEBUG("%s\n\n", eina_simple_xml_node_dump(&tag->base, " "));
-}
-
-// ========================= is xml description callbacks =========================
-
-static Eina_Bool
-is_xml_description_cb(void *data, Eina_Simple_XML_Type type, const char *content, unsigned offset, unsigned length)
-{
- DEBUG(": %s start\n", __FUNCTION__);
-
- S_is_xml *is_xml = data;
-
- if(type != EINA_SIMPLE_XML_IGNORED)
- {
- is_xml->call_count++;
- }
-
- DEBUG("CONTENT: %.*s\n", length, content);
-
- switch(type)
- {
- case EINA_SIMPLE_XML_PROCESSING:
- DEBUG("EINA_SIMPLE_XML_PROCESSING\n");
- if(!strncmp(content, "xml version=\"1.0\" encoding=\"UTF-8\"", length) && is_xml->call_count <= 2)
- {
- is_xml->xml_header = true;
- }
- break;
- case EINA_SIMPLE_XML_OPEN_EMPTY:
- DEBUG("EINA_SIMPLE_XML_OPEN_EMPTY\n");
- if(!strncmp(content, "org_tizen_complex_desc", length) && is_xml->call_count <= 2)
- {
- is_xml->complex_header = true;
- }
- break;
- default:
- break;
- }
-
- if(is_xml->complex_header && is_xml->xml_header)
- {
- return EINA_FALSE;
- }
-
- return EINA_TRUE;
-}
-
-// ========================= is xml description =========================
-S_is_xml is_xml;
-
-Attribute_Info *attribute_info_new(char *key, char **values, int count)
-{
- Attribute_Info *attr = calloc(1, sizeof(Attribute_Info));
-
- attr->key = key;
- attr->values = values;
- attr->values_count = count;
-
- return attr;
-}
-
-void add_test_tag(char *tag, Eina_Simple_XML_Type type, Attribute_Info **attr, int attribute_count)
-{
- Item_Info *ii = calloc(1, sizeof(Item_Info));
- ii->tag_type = tag;
- ii->type = type;
- ii->attribute_count = attribute_count;
- ii->available_arguments = attr;
-
-
- is_xml.available_tags = eina_list_append(is_xml.available_tags, ii);
-}
-
-Eina_Bool is_xml_description(char *desc)
-{
- is_xml.descr = desc;
- is_xml.xml_header = false;
- is_xml.complex_header = false;
- is_xml.tag_validation = true;
- is_xml.available_tags = NULL;
-
- is_xml.call_count = 0;
- is_xml.last_error_offset = 0;
- is_xml.last_error_line = 1;
-
- is_xml.found_names = NULL;
-
- Attribute_Info *attr_info[3];
- attr_info[0] = attribute_info_new("name", NULL, 0);
- attr_info[1] = attribute_info_new("level", NULL, 0);
- char *actions_info[2];
- actions_info[0] = "on_focus";
- actions_info[1] = "on_activate";
- attr_info[2] = attribute_info_new("action", actions_info, 2);
- add_test_tag("Information_Level", EINA_SIMPLE_XML_OPEN, attr_info, 3);
-
- int size = strlen(desc);
-
- eina_simple_xml_parse(desc, size, EINA_TRUE, is_xml_description_cb, &is_xml);
-
- if(is_xml.complex_header && is_xml.xml_header)
- {
- return true;
- }
- else
- {
- return false;
- }
-}
-
-/* ****************************************************************************************************** */
-
-
-// =========================================== Create Tree ==============================
-Eina_Simple_XML_Node_Tag *find_item_by_params(Eina_Simple_XML_Attribute **pairs, const char *name, Eina_Simple_XML_Node_Tag *tag);
-const char *get_param(Eina_Simple_XML_Node_Tag *item, char *key);
-
-int find_children_count_by_params(Eina_Simple_XML_Attribute **pairs,
- const char *searched_tag_name, Eina_Inlist *first, int limit)
-{
- DEBUG(" ");
- Eina_Simple_XML_Node *child_node;
- Eina_Simple_XML_Node_Tag *to_ret;
- Eina_Simple_XML_Attribute *attr;
- int counter = 0;
- int attr_count;
-
- DEBUG("============================\n");
- DEBUG("SEARCHED: %s\n",searched_tag_name);
-
- int i =0;
- for(i = 0; pairs[i] != NULL; ++i)
- {
- DEBUG("%s = \"%s\"\n", pairs[i]->key, pairs[i]->value);
- }
-
- DEBUG("END PAIRS\n");
-
- if(first && eina_inlist_count(first) > 0)
- {
- EINA_INLIST_FOREACH(first, child_node)
- {
- if(child_node->type == EINA_SIMPLE_XML_NODE_TAG)
- {
- Eina_Simple_XML_Node_Tag *child_tag = (Eina_Simple_XML_Node_Tag *)child_node;
-
- const char *name = get_param(child_tag, "name");
- int param_count = 0;
-
- for(i = 0; pairs[i] != NULL; ++i)
- {
- param_count++;
- }
-
- if(name != NULL)
- {
- attr_count = eina_inlist_count(child_tag->attributes) - 1;
- }
- else
- {
- attr_count = eina_inlist_count(child_tag->attributes);
- }
-
- DEBUG("Child: %s > ", child_tag->name);
- EINA_INLIST_FOREACH(child_tag->attributes, attr)
- {
- DEBUG("%s = \"%s\" ", attr->key, attr->value);
- }
-
- DEBUG("\n");
-
- DEBUG("ATTR COUNT: %d <> PARAM_COUT: %d\n", attr_count, param_count);
-
- if(attr_count == param_count)
- {
- to_ret = find_item_by_params(pairs, searched_tag_name, child_tag);
-
- if(to_ret)
- {
- DEBUG("to_ret: %s > ", to_ret->name);
- EINA_INLIST_FOREACH(to_ret->attributes, attr)
- {
- DEBUG("%s = \"%s\" ", attr->key, attr->value);
- }
- }
- else
- {
- DEBUG("to_ret == NULL");
- }
-
- DEBUG("\n");
-
- if(to_ret != NULL)
- {
- counter++;
- }
-
-
- if(counter >= limit)
- {
- DEBUG("ERROR \n");
- return counter;
- }
- }
- }
- }
- }
-
- return counter;
-}
-
-void find_duplicates(Eina_Simple_XML_Node_Tag *pattern, Eina_Inlist *first)
-{
- Eina_Simple_XML_Attribute **pairs = NULL;
- int attr_count = eina_inlist_count(pattern->attributes);
-
- Eina_Simple_XML_Attribute *key = NULL;
-
- pairs = calloc(attr_count + 1, sizeof(Eina_Simple_XML_Attribute **));
-
- int i = 0;
- EINA_INLIST_FOREACH(pattern->attributes, key)
- {
-
- if(strcmp(key->key, "name") != 0)
- {
- pairs[i] = key;
- ++i;
- }
- }
-
- int found_count = 0;
- if(strcmp(pattern->name, "Information_Level") == 0)
- {
- found_count = find_children_count_by_params(pairs, pattern->name, first, 1);
- DEBUG("FOUND COUNT %d\n", found_count);
- }
-
-
- if(found_count >= 1)
- {
- DEBUG("Found widgets: %d\n", found_count);
- DEBUG("->->->->->->->->-> Error in XML tree: duplicate of %s found\n", pattern->name);
- }
-
-
-}
-
-
-void traverse_xml_tree(Eina_Simple_XML_Node_Tag *top)
-{
- Eina_Simple_XML_Node *node;
- Eina_Simple_XML_Node_Tag *child;
-
- EINA_INLIST_FOREACH(top->children, node)
- {
- if(node->type == EINA_SIMPLE_XML_NODE_TAG)
- {
- child = (Eina_Simple_XML_Node_Tag *)node;
-
- DEBUG(">>>>>>>>>>>>>>> CHILD TYPE: %s\n", child->name);
-
- find_duplicates(child, EINA_INLIST_GET(node)->next);
- traverse_xml_tree(child);
- }
- }
-}
-
-
-Eina_Simple_XML_Node_Root *create_tree(char *desc, bool test_duplicates)
-{
- DEBUG(": %s start\n", __FUNCTION__);
- Eina_Simple_XML_Node_Root* root = eina_simple_xml_node_load(desc, strlen(desc) - 1, true);
-
- print_tree(root, 4);
-
- if(test_duplicates == true)
- {
- traverse_xml_tree(root);
- }
-
- return root;
-}
-
-
-// ========================= Search functions =========================
-Eina_Simple_XML_Node_Tag *find_item_by_params(Eina_Simple_XML_Attribute **pairs, const char *name, Eina_Simple_XML_Node_Tag *tag)
-{
- int i = 0;
-
- Eina_Simple_XML_Attribute *arg;
-
- int conditions = 0;
- int found_matches = 0;
-
- DEBUG(": %s start\n", __FUNCTION__);
-
- if(tag->base.type != EINA_SIMPLE_XML_NODE_TAG )
- {
- DEBUG("Not a tag\n");
- return NULL;
- }
-
- if(name == NULL || !strcmp(name, tag->name)) //tag == NULL means that we don't care about tag name
- {
- DEBUG("Found tag with name: %s\n", tag->name);
-
- if(pairs) //no attributes means that we search only by tag name
- {
- for(i = 0; pairs[i] != NULL; ++i)
- {
- conditions++;
- }
-
- EINA_INLIST_FOREACH(tag->attributes, arg)
- {
- for(i = 0; pairs[i] != NULL; ++i)
- {
- int cmp1 = strcmp(pairs[i]->key, arg->key);
- int cmp2 = strcmp(pairs[i]->value, arg->value); //Strange code needed for debuging
-
- if(!cmp1 && !cmp2)
- {
- found_matches++;
- }
- }
-
- if(found_matches == conditions)
- {
- return tag;
- }
- }
- }
- else
- {
- return tag;
- }
- }
-
- DEBUG("%s RETURNING NULL\n", __FUNCTION__);
- return NULL;
-}
-
-
-Eina_Simple_XML_Node_Tag *find_child_by_params(Eina_Simple_XML_Attribute **pairs, const char *searched_tag_name, Eina_Simple_XML_Node_Tag *tag)
-{
- DEBUG(" ");
- Eina_Simple_XML_Node *child_node;
- Eina_Simple_XML_Node_Tag *to_ret;
-
- if(tag->base.type != EINA_SIMPLE_XML_NODE_TAG && tag->base.type != EINA_SIMPLE_XML_NODE_ROOT)
- {
- return NULL;
- }
-
- if(tag->children && eina_inlist_count(tag->children) > 0)
- {
- EINA_INLIST_FOREACH(tag->children, child_node)
- {
- to_ret = find_item_by_params(pairs, searched_tag_name, (Eina_Simple_XML_Node_Tag *)child_node);
-
- if(to_ret != NULL)
- return to_ret;
- }
- }
-
- DEBUG("%s RETURNING NULL\n", __FUNCTION__);
- return NULL;
-}
-
-Eina_Simple_XML_Node_Tag *find_item_by_params_recursive(Eina_Simple_XML_Attribute **pairs, const char *name, Eina_Simple_XML_Node_Tag *top_tag)
-{
- Eina_Simple_XML_Node_Tag *tag = find_item_by_params(pairs, name, top_tag);
-
- if(tag != NULL)
- {
- return tag;
- }
- else
- {
- return find_child_by_params(pairs, name, top_tag);
- }
-
- //TODO: Czy to napewno zadziała bo chyba nie
-
-}
-
-
-
-const char *get_param(Eina_Simple_XML_Node_Tag *item, char *key)
-{
- DEBUG(" ");
- Eina_Simple_XML_Attribute *attribute;
-
- EINA_INLIST_FOREACH(item->attributes, attribute)
- {
- if(strcmp(attribute->key, key) == 0)
- {
- return attribute->value;
- }
- }
-
- return NULL;
-}
-
-Eina_Inlist *find_refs(Eina_Simple_XML_Node_Tag *root, Eina_Simple_XML_Node_Tag *tag, Eina_Inlist *refs)
-{
- DEBUG(" ");
- Eina_Simple_XML_Node *child;
-
- Eina_Simple_XML_Attribute *names[2] = {NULL, NULL};
- DEBUG("Tag name: %s\n", tag->name);
-
- EINA_INLIST_FOREACH(tag->children, child)
- {
- DEBUG("Child type: %d\n", child->type);
-
- if(child->type == EINA_SIMPLE_XML_NODE_TAG || child->type == EINA_SIMPLE_XML_NODE_ROOT)
- {
- Eina_Simple_XML_Node_Tag *child_tag = (Eina_Simple_XML_Node_Tag *)child;
- DEBUG("CHILD TAG NAME: %s\n", child_tag->name);
-
- if(!strcmp(child_tag->name, "Ref"))
- {
- DEBUG("Ref found\n");
- const char *value = get_param(child_tag, "name");
- names[0] = eina_simple_xml_attribute_new(NULL, "name", value);
-
-
- Eina_Simple_XML_Node_Tag *found_child_tag = find_item_by_params_recursive(names, NULL, root);
- Eina_Simple_XML_Node *found_child = &found_child_tag->base;
-
- refs = eina_inlist_append(refs, EINA_INLIST_GET(found_child));
-
- refs = find_refs(root, found_child_tag, refs);
- }
- }
- }
-
- return refs;
-}
-
-Eina_Inlist *find_refs_and_children(Eina_Simple_XML_Node_Tag *root, Eina_Simple_XML_Node_Tag *tag, Eina_Inlist *refs, char **children_xml, Tag *tags, bool *selected)
-{
- DEBUG(" ");
- Eina_Simple_XML_Node *child;
-
- Eina_Simple_XML_Attribute *names[2] = {NULL, NULL};
- DEBUG("Tag name: %s\n", tag->name);
-
- EINA_INLIST_FOREACH(tag->children, child)
- {
- DEBUG("Child type: %d\n", child->type);
-
- if(child->type == EINA_SIMPLE_XML_NODE_TAG || child->type == EINA_SIMPLE_XML_NODE_ROOT)
- {
- Eina_Simple_XML_Node_Tag *child_tag = (Eina_Simple_XML_Node_Tag *)child;
- DEBUG("CHILD TAG NAME: %s\n", child_tag->name);
-
- if(strcmp(child_tag->name, "Ref") == 0 || strcmp(child_tag->name, "Read_Children") == 0 || strcmp(child_tag->name, "Text_Block") == 0)
- {
- if(child_tag->name[2] == 'f')
- {
- DEBUG("Ref found\n");
- const char *value = get_param(child_tag, "name");
- names[0] = eina_simple_xml_attribute_new(NULL, "name", value);
-
-
- Eina_Simple_XML_Node_Tag *found_child_tag = find_item_by_params_recursive(names, NULL, root);
- Eina_Simple_XML_Node *found_child = &found_child_tag->base;
-
- refs = eina_inlist_append(refs, EINA_INLIST_GET(found_child));
- refs = find_refs_and_children(root, found_child_tag, refs, children_xml, tags, selected);
- }
- /*else if(child_tag->name[2] == 'x') //TODO
- {
- DEBUG("Text_Block found\n");
- refs = eina_inlist_append(refs, child);
- refs = find_refs_and_children(root, child, refs, children_xml, tags, selected);
- }*/
- else if(child_tag->name[2] == 'a')
- {
- int i = 0;
- DEBUG("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! CHILDREN FOUND \n");
-
- for(i = 0; children_xml[i] != NULL; ++i)
- {
- Eina_Simple_XML_Attribute *child_xml_attr[2] = {NULL, NULL};
- const char *value = get_param(child_tag, "level");
- const char *mode = get_param(child_tag, "mode");
- bool mode_val;
-
- if(mode != NULL && strcmp(mode, "selected") == 0)
- mode_val = true;
- else
- mode_val = false;
-
- DEBUG("selected: %d\n", selected[i]);
- if((mode_val == true && selected[i] == true) || mode_val == false)
- {
- child_xml_attr[0] = eina_simple_xml_attribute_new(NULL, "level", value);
-
- DEBUG("Attribute: %s=%s\n", child_xml_attr[0]->key, child_xml_attr[0]->value);
-
- char *string = get_string_str(tags, children_xml[i], child_xml_attr, "Information_Level");
-
- DEBUG("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! String from child %s\n", string);
-
- Eina_Simple_XML_Node_Data *found_node_data = eina_simple_xml_node_data_new(NULL, string, strlen(string)+ 1);
- Eina_Simple_XML_Node *found_data = &found_node_data->base;
-
-
- DEBUG("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! AFTER NEW NODE\n");
-
- refs = eina_inlist_append(refs, EINA_INLIST_GET(found_data));
- eina_simple_xml_attribute_free(child_xml_attr[0]);
- }
- }
- }
- }
- }
- }
-
-
- DEBUG("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! RETURNING\n");
- return refs;
-}
-
-
-char *concat_string(Eina_Inlist *nodes)
-{
- DEBUG(" ");
- Eina_Simple_XML_Node *node = NULL;
- Eina_Simple_XML_Node_Tag *tag = NULL;
-
- Eina_Simple_XML_Node *child_node = NULL;
- Eina_Simple_XML_Node_Data *data = NULL;
-
- Eina_Strbuf *buf = eina_strbuf_new();
-
- EINA_INLIST_FOREACH(nodes, node)
- {
- tag = (Eina_Simple_XML_Node_Tag *)node;
-
- if(node->type == EINA_SIMPLE_XML_NODE_TAG)
- {
- EINA_INLIST_FOREACH(tag->children, child_node)
- {
- if(child_node->type == EINA_SIMPLE_XML_NODE_DATA)
- {
- data = (Eina_Simple_XML_Node_Data *)child_node;
- eina_strbuf_append_n(buf, data->data, data->length);
- eina_strbuf_append(buf, ". ");
- }
-
- }
- }
- else if(node->type == EINA_SIMPLE_XML_NODE_DATA)
- {
- data = (Eina_Simple_XML_Node_Data *)node;
- eina_strbuf_append_n(buf, data->data, data->length);
- eina_strbuf_append(buf, ". ");
- }
- }
-
- char *to_ret = eina_strbuf_string_steal(buf);
- eina_strbuf_free(buf);
- return to_ret;
-}
-
-/* ========================= get string from description ========================= */
-char *get_string_tree(Tag *tags, Eina_Simple_XML_Node_Tag *root, Eina_Simple_XML_Attribute **pairs, char *tag_name)
-{
- DEBUG(" ");
- Eina_Simple_XML_Node_Tag *top_tag = root;
- int i = 0;
- Tag *current_tag = NULL;
-
- DEBUG("BEFORE TAGS\n");
- if(tags != NULL)
- {
- DEBUG("IN TAGS\n");
- current_tag = &tags[0];
-
- while(current_tag->tag_type != NULL)
- {
- DEBUG("Top item before: %s\n", top_tag->name);
-
- top_tag = find_child_by_params(current_tag->pairs, current_tag->tag_type, top_tag);
-
- DEBUG("Top item after: %p\n", top_tag);
-
- i++;
- current_tag = &tags[i];
- }
-
- if(top_tag == NULL)
- {
- DEBUG("%s RETURNING NULL\n", __FUNCTION__);
- return NULL;
- }
-
- }
-
-
-
- DEBUG("-----------================ Searching... ================-----------\n");
-
- if(top_tag->base.type == EINA_SIMPLE_XML_NODE_TAG)
- {
- DEBUG("SEARCH TOP LEVEL: %s\n", top_tag->name);
- }
- else if(top_tag->base.type == EINA_SIMPLE_XML_NODE_ROOT)
- {
- DEBUG("SEARCH FROM ROOT\n");
- }
-
- Eina_Simple_XML_Node_Tag *tag = find_child_by_params(pairs, tag_name, top_tag);
-
- Eina_Inlist *refs = NULL;
-
- if(tag == NULL)
- {
- DEBUG("returning NULL %s\n", __FUNCTION__);
- return NULL;
- }
-
- refs = find_refs(root, tag, refs);
-
- Eina_Simple_XML_Node *node = &tag->base;
- refs = eina_inlist_prepend(refs, EINA_INLIST_GET(node)); //need to add the found item to the list so it's
- //string can be added to output
-
- char *the_string = concat_string(refs);
-
- return the_string;
-}
-
-char *get_string_str(Tag *tags, char *descr, Eina_Simple_XML_Attribute **pairs, char *tag_name)
-{
- DEBUG(" ");
- bool xml = is_xml_description(descr);
-
- if(xml == true)
- {
- Eina_Simple_XML_Node_Root *root = create_tree(descr, false);
- char *the_string = get_string_tree(tags, root, pairs, tag_name);
-
- return the_string;
- }
- else
- {
- return descr;
- }
-}
-
-const char *list_pop(Eina_List **list)
-{
- DEBUG("Popping tag\n");
- Eina_List *l;
- DEBUG("Get Last\n");
- l = eina_list_last(*list);
- DEBUG("Get data\n");
- const char *content = eina_list_data_get(l);
- DEBUG("Remove\n");
- *list = eina_list_remove_list(*list, l);
- return content;
-}
-
-
-//void get_error_messgage(const char *message, const char *tag, S_is_xml *is_xml, int offset, int length)
-void get_error_messgage(S_is_xml *is_xml)
-{
- int line_count =is_xml->last_error_line;
- int i = 0;
- for(i = is_xml->last_error_offset; i < is_xml->current_offset; ++i)
- {
- if(is_xml->descr[i] == '\n')
- {
- line_count++;
- }
- }
-
- DEBUG("->->->->->->->->-> Error in XML validation: %s", is_xml->error_message);
-
- if(is_xml->current_tag)
- {
- DEBUG(" %*.*s\n", is_xml->current_tag_len, is_xml->current_tag_len, is_xml->current_tag);
- }
-
- DEBUG(" line: %d\n", line_count);
-
- is_xml->last_error_offset = is_xml->current_offset;
- is_xml->last_error_line = line_count;
-
-}
-
-static Eina_Bool
-_xml_attr_cb(void *data, const char *key, const char *value)
-{
- DEBUG("Test attribute\n");
-
- S_is_xml *is_xml = data;
- Item_Info *ii = is_xml->item_info;
- Attribute_Info *ai;
- int i, j;
- Eina_Bool key_found = EINA_FALSE;
- DEBUG("Tag NAME: %s\n", ii->tag_type);
- Eina_List *l;
- char *name = NULL;
- bool name_found = false;
-
- if(strcmp(key, "name") == 0)
- {
- DEBUG("NAME key found\n");
- EINA_LIST_FOREACH(is_xml->found_names, l, name)
- {
- DEBUG("Testing names: %s vs %s\n", name, value);
-
- if(name != NULL && strcmp(value, name) == 0)
- {
- name_found = true;
- break;
- }
- }
-
- DEBUG("After Loop\n");
-
- if(name_found == false)
- {
- DEBUG("Add name to list: %s\n", value);
- is_xml->found_names = eina_list_append(is_xml->found_names, eina_stringshare_add(value));
- }
- else
- {
- DEBUG("Name already exists: %s\n", value);
- is_xml->error_message = "Name already exists";
- is_xml->tag_validation = 0;
- get_error_messgage(is_xml);
- }
- }
- else if(strcmp(key, "refs") == 0)
- {
- DEBUG("NAME key found\n");
- EINA_LIST_FOREACH(is_xml->found_names, l, name)
- {
- DEBUG("Testing names: %s vs %s\n", name, value);
-
- if(name != NULL && strcmp(value, name) == 0)
- {
- name_found = true;
- break;
- }
- }
-
- DEBUG("Name already exists: %s\n", value);
- is_xml->error_message = "Cannot reference tag with given name";
- is_xml->tag_validation = 0;
- get_error_messgage(is_xml);
-
- DEBUG("After Loop\n");
-
- if(name_found == false)
- {
- DEBUG("Add name to list: %s\n", value);
- is_xml->found_names = eina_list_append(is_xml->found_names, eina_stringshare_add(value));
- }
- else
- {
-
- }
- }
-
-
-
- if(ii->attribute_count > 0)
- {
- for(i = 0; i < ii->attribute_count; ++i)
- {
- DEBUG("Get attribute\n");
-
- ai = ii->available_arguments[i];
-
- DEBUG("Test attribute: \n%s\n%s key_found: %d\n", key, ai->key, key_found);
- if(strcmp(key, ai->key) == 0)
- {
- DEBUG("Attribute found: \n%s\n%s\n", key, ai->key);
- key_found = EINA_TRUE;
-
- DEBUG("Iterate values count: %d\n", ai->values_count);
- if(ai->values_count)
- {
- for(j = 0; j < ai->values_count; ++j)
- {
- DEBUG("Compare values \n%s\n%s\n", value, ai->values[j]);
- if(strcmp(ai->values[j], value) == 0)
- {
- return EINA_TRUE;
- }
- }
- }
- else
- {
- DEBUG("KEY OK\n");
- return EINA_TRUE;
- }
- }
- }
- }
- else
- {
- DEBUG("->->->->->->->->->->->-> Argument in no-argument tag: %s in tag: %s\n", key, ii->tag_type);
-
- is_xml->error_message = "Argument in no-argument tag";
- is_xml->tag_validation = 0;
- get_error_messgage(is_xml);
- return EINA_FALSE;
- }
-
- DEBUG("key_found %d\n", key_found);
-
- if(key_found == EINA_FALSE)
- {
- DEBUG("->->->->->->->->->->->-> Unknown attribute: %s in tag: %s\n", key, ii->tag_type);
- is_xml->error_message = "Unknown attribute in";
- is_xml->tag_validation = 0;
- get_error_messgage(is_xml);
- }
- else
- {
- DEBUG("->->->->->->->->->->->-> Unknown attribute value: %s with key: %s. Tag: %s\n", value, key, ii->tag_type);
- is_xml->error_message = "Unknown attribute value ";
- is_xml->tag_validation = 0;
- get_error_messgage(is_xml);
- }
-
- return EINA_TRUE;
-}
-
-
-Eina_Bool check_tag(S_is_xml *is_xml, Eina_Simple_XML_Type type, const char *tag, const char *attr, int str_len)
-{
- DEBUG(" ");
-
- if(is_xml->available_tags == NULL)
- {
- DEBUG("No available tags\n");
- return true;
- }
-
- Eina_List *l;
- Item_Info *ii;
-
- int len = 0;
- if(attr)
- {
- len = attr - tag - 1;
- }
- else
- {
- len = str_len;
- }
-
- DEBUG("TAG: %*.*s type: %d\n", len, len, tag, type);
-
- EINA_LIST_FOREACH(is_xml->available_tags, l, ii)
- {
- DEBUG("Wzorzec: %*.*s %d\n", len, len, ii->tag_type, ii->type);
-
- if(strncmp(tag, ii->tag_type, len - 1) == 0 && type == ii->type)
- {
- is_xml->item_info = ii;
- is_xml->current_offset = tag - is_xml->descr;
- is_xml->current_tag_len = str_len;
- is_xml->current_tag = tag;
- eina_simple_xml_attributes_parse(attr, str_len - (attr - tag), _xml_attr_cb, is_xml);
- return EINA_TRUE;
- }
- }
-
- return EINA_FALSE;
-}
-
-
-
-Eina_Simple_XML_Node_Tag *modify_tag(Tag *tags, Eina_Simple_XML_Node_Tag *root,
- const char *tag_name, Eina_Simple_XML_Attribute **pairs,
- const char *new_tag_name, Eina_Simple_XML_Attribute **new_pairs, const char *new_data)
-{
- DEBUG(": %s start\n", __FUNCTION__);
-
- Eina_Simple_XML_Node_Tag *top_tag = NULL;
- Eina_Simple_XML_Node_Tag *tag = NULL;
- Tag *current_tag = NULL;
-
- if(root == NULL)
- {
- DEBUG("Root == NULL\n");
-
- char *buf = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
- "<org_tizen_complex_desc/>\n";
-
- root = eina_simple_xml_node_load (buf, strlen(buf), EINA_TRUE);
- top_tag = root;
- }
- else
- {
- DEBUG("Root != NULL\n");
- top_tag = root;
-
- if(tags != NULL)
- {
- DEBUG("Tags != NULL\n");
- DEBUG("IN TAGS\n");
- current_tag = &tags[0];
-
- int i = 0;
- while(current_tag->tag_type != NULL)
- {
- DEBUG("Top item before: %s\n", top_tag->name);
-
- top_tag = find_child_by_params(current_tag->pairs, current_tag->tag_type, top_tag);
-
- DEBUG("Top item after: %s\n", top_tag->name);
-
- i++;
- current_tag = &tags[i];
- }
-
- if(top_tag == NULL)
- {
- return NULL;
- }
- }
-
- if(top_tag->base.type == EINA_SIMPLE_XML_NODE_TAG)
- {
- DEBUG("SEARCH TOP LEVEL: %s\n", top_tag->name);
- }
- else if(top_tag->base.type == EINA_SIMPLE_XML_NODE_ROOT)
- {
- DEBUG("SEARCH FROM ROOT\n");
- }
-
- tag = find_child_by_params(pairs, tag_name, top_tag);
- }
-
- //add new tag to xml tree
- if(tag == NULL)
- {
- DEBUG("Adding new tag\n");
-
- tag = eina_simple_xml_node_tag_new(top_tag, new_tag_name);
-
- DEBUG("Adding new tag %s\n", __FUNCTION__);
-
- //removing attibutes;
- Eina_Simple_XML_Attribute *attr;
-
- EINA_INLIST_FOREACH(tag->attributes, attr)
- {
- eina_simple_xml_attribute_free(attr);
- }
-
- int i = 0;
- while(pairs[i] != NULL)
- {
- Eina_Simple_XML_Attribute *attr = new_pairs[i];
- eina_simple_xml_attribute_new(tag, attr->key, attr->value);
- ++i;
- }
- }
- //Modify existing tag
- else
- {
- DEBUG("Modifying tag %s\n", tag->name);
-
- Eina_Simple_XML_Node *node;
- Eina_Simple_XML_Node_Tag *to_remove_tag;
- Eina_Simple_XML_Node_Data *to_remove_data;
-
- DEBUG("Removing children\n");
- EINA_INLIST_FREE(tag->children, node)
- {
- switch(node->type)
- {
- case EINA_SIMPLE_XML_NODE_ROOT:
- case EINA_SIMPLE_XML_NODE_TAG:
- to_remove_tag = (Eina_Simple_XML_Node_Tag *)node;
- eina_simple_xml_node_tag_free(to_remove_tag);
- break;
- case EINA_SIMPLE_XML_NODE_DATA:
- to_remove_data = (Eina_Simple_XML_Node_Data *)node;
- eina_simple_xml_node_data_free(to_remove_data);
- break;
- default:
- break;
- }
-
- }
-
- DEBUG("Adding attributes\n");
-
- Eina_Simple_XML_Attribute *attr;
-
- DEBUG("Removing old attributes\n");
- EINA_INLIST_FREE(tag->attributes, attr)
- {
- eina_simple_xml_attribute_free(attr);
- }
-
- DEBUG("Adding new attributes\n");
-
- int i = 0;
- while(pairs[i] != NULL)
- {
- Eina_Simple_XML_Attribute *attr = new_pairs[i];
- eina_simple_xml_attribute_new(tag, attr->key, attr->value);
- ++i;
- }
-
- DEBUG("Setting name\n");
- tag->name = eina_stringshare_add(new_tag_name);
- }
-
- if(new_data != NULL)
- {
- eina_simple_xml_node_data_new(tag, new_data, strlen(new_data));
- }
-
- return root;
-}
-
-Eina_Simple_XML_Node_Tag *add_tag(Tag *tags, Eina_Simple_XML_Node_Tag *root,
- const char *tag, const char *data, Eina_Simple_XML_Attribute **pairs)
-{
- Eina_Simple_XML_Node_Tag * ret = modify_tag(tags, root,
- tag, pairs,
- tag, pairs, data);
-
- return ret;
-}
-
-Eina_Simple_XML_Node_Tag *add_tag_str(Tag *tags, Eina_Simple_XML_Node_Root *root, const char *tag_str)
-{
- Eina_Simple_XML_Node_Root *tag = eina_simple_xml_node_load (tag_str, strlen(tag_str) - 1, EINA_TRUE);
- Eina_Simple_XML_Node_Tag * ret = root;
-
- DEBUG("the tag tree:\n");
- print_tree(tag, 4);
-
-
- if(tag)
- {
- Eina_Simple_XML_Node *root_child_node = NULL;
- Eina_Simple_XML_Node *child_node = NULL;
- Eina_Simple_XML_Node_Data *child_node_data = NULL;
- Eina_Simple_XML_Node_Tag *child_tag =NULL;
- Eina_Simple_XML_Attribute *attr = NULL;
- Eina_Simple_XML_Attribute **array = NULL;
-
- DEBUG("finding data\n");
-
- EINA_INLIST_FOREACH(tag->children, root_child_node)
- {
- DEBUG("checking children list\n");
-
- if(root_child_node->type == EINA_SIMPLE_XML_NODE_TAG)
- {
- child_tag = (Eina_Simple_XML_Node_Tag *)root_child_node;
-
- EINA_INLIST_FOREACH(child_tag->children, child_node)
- {
- if(child_node->type == EINA_SIMPLE_XML_NODE_DATA)
- {
- child_node_data = (Eina_Simple_XML_Node_Data *)child_node;
- }
- }
-
- int list_count = eina_inlist_count(child_tag->attributes);
- array = calloc(list_count, sizeof(Eina_Simple_XML_Attribute *));
-
- DEBUG("creating attribute array\n");
-
- int i = 0;
- EINA_INLIST_FOREACH(child_tag->attributes, attr)
- {
- array[i] = attr;
- i++;
- }
-
- DEBUG("Calling modify\n");
- DEBUG("Tag name: %s\n", child_tag->name);
-
- if(child_node_data != NULL)
- {
- ret = modify_tag(tags, ret,
- child_tag->name, array,
- child_tag->name, array, child_node_data->data);
- }
- else
- {
- ret = modify_tag(tags, ret,
- child_tag->name, array,
- child_tag->name, array, NULL);
- }
-
- free(array);
- }
- }
-
- return ret;
- }
- else
- {
- return NULL;
- }
-}