⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wbxml_tree.c

📁 WAP Binary XML 简单地说
💻 C
📖 第 1 页 / 共 3 页
字号:
            if (previous_node == NULL) {                end_of_walk = TRUE;                break;            }            else {                if (previous_node->parent == parent_node) {                    /* End of parsing, we have parsed the last child of node */                    end_of_walk = TRUE;                    break;                }                else {                    /* Let's parse next child of parent node */                                        current_node = previous_node->next;                    tmp_node = previous_node->parent;                    /* Destroy this node (leaf) */                    wbxml_tree_node_destroy(previous_node);                    previous_node = tmp_node;                }            }        }        else {            /* Go deeper in sub-tree */            previous_node = current_node;            current_node = current_node->children;                }    }    wbxml_tree_node_destroy(node);}WBXML_DECLARE(WBXMLTreeNode *) wbxml_tree_node_create_xml_elt(const WBXMLLangEntry *lang_table,                                                              const WB_UTINY *name){    const WBXMLTagEntry *tag_entry = NULL;    WBXMLTreeNode *node = NULL;    WBXMLTag *tag = NULL;        /* Search for XML Tag Name in Table */    if ((tag_entry = wbxml_tables_get_tag_from_xml(lang_table, name)) != NULL) {        /* Found : token tag */        tag = wbxml_tag_create_token(tag_entry);    }    else {        /* Not found : literal tag */        tag = wbxml_tag_create_literal((WB_UTINY *)name);    }    if (tag == NULL)        return NULL;    /* Create a new Node */    if ((node = wbxml_tree_node_create(WBXML_TREE_ELEMENT_NODE)) == NULL) {        wbxml_tag_destroy(tag);        return NULL;    }        /* Set Node Tag */    node->name = tag;        return node;}WBXML_DECLARE(WBXMLTreeNode *) wbxml_tree_node_create_xml_elt_with_text(const WBXMLLangEntry *lang_table,                                                                        const WB_UTINY *name,                                                                        const WB_UTINY *text,                                                                        WB_ULONG len){    WBXMLTreeNode *node = NULL;    WBXMLTreeNode *text_node = NULL;        /* Create element node */    if ((node = wbxml_tree_node_create_xml_elt(lang_table, name)) == NULL)        return NULL;        /* Create text node */    if ((text_node = wbxml_tree_node_create_text(text, len)) == NULL) {        wbxml_tree_node_destroy(node);        return NULL;    }        /* Add text node to element node */    if (!wbxml_tree_node_add_child(node, text_node)) {        wbxml_tree_node_destroy(node);        wbxml_tree_node_destroy(text_node);        return NULL;    }        return node;}WBXML_DECLARE(WBXMLTreeNode *) wbxml_tree_node_create_text(const WB_UTINY *text,                                                           WB_ULONG len){    WBXMLTreeNode *node = NULL;    /* Create a new Node */    if ((node = wbxml_tree_node_create(WBXML_TREE_TEXT_NODE)) == NULL) {        return NULL;    }    /* Set Content */    if ((node->content = wbxml_buffer_create(text, len, len)) == NULL) {        wbxml_tree_node_destroy(node);        return NULL;    }    return node;}WBXML_DECLARE(WBXMLTreeNode *) wbxml_tree_node_create_cdata(const WB_UTINY *text,                                                            WB_ULONG len){    WBXMLTreeNode *node = NULL;    WBXMLTreeNode *text_node = NULL;    /* Create a new node */    if ((node = wbxml_tree_node_create(WBXML_TREE_CDATA_NODE)) == NULL) {        return NULL;    }    /* Create a text node */    if ((text_node = wbxml_tree_node_create_text(text, len)) == NULL) {        wbxml_tree_node_destroy(node);        return NULL;    }        /* Add text node to cdata */    if (!wbxml_tree_node_add_child(node, text_node)) {        wbxml_tree_node_destroy_all(node);        node = NULL;    }    return node;}WBXML_DECLARE(WBXMLTreeNode *) wbxml_tree_node_create_tree(WBXMLTreeNode *root,                                                           WBXMLLanguage lang,                                                           WBXMLCharsetMIBEnum orig_charset){    WBXMLTreeNode* result = NULL;    WBXMLTree*     tree   = NULL;        if ((root == NULL) || (lang == WBXML_LANG_UNKNOWN))        return NULL;        /* Create Tree */    if ((tree = wbxml_tree_create(lang, orig_charset)) == NULL)        return NULL;        /* Fill Tree */    tree->root = root;        /* Create Tree Node */    if ((result = wbxml_tree_node_create(WBXML_TREE_TREE_NODE)) == NULL) {        wbxml_tree_destroy(tree);        return NULL;    }        /* Fill Tree Node */    result->tree = tree;        return result;}WBXML_DECLARE(WB_BOOL) wbxml_tree_node_add_child(WBXMLTreeNode *parent,                                                 WBXMLTreeNode *node){    WBXMLTreeNode *tmp = NULL;    if ((parent == NULL) || (node == NULL))        return FALSE;    /* Set parent to new node */    node->parent = parent;        /* Search for previous sibbling element */    if (parent->children != NULL) {        /* Add this Node to end of Sibbling Node list of Parent */        tmp = parent->children;        while (tmp->next != NULL)            tmp = tmp->next;                node->prev = tmp;        tmp->next = node;    }    else {        /* No previous sibbling element */        parent->children = node;    }    return TRUE;}WBXML_DECLARE(WBXMLError) wbxml_tree_node_add_attr(WBXMLTreeNode *node,                                                   WBXMLAttribute *attr){    WBXMLAttribute *new_attr = NULL;    if ((node == NULL) || (attr == NULL)) {        return WBXML_ERROR_BAD_PARAMETER;    }    /* Create list if needed */    if (node->attrs == NULL) {        if ((node->attrs = wbxml_list_create()) == NULL) {            return WBXML_ERROR_NOT_ENOUGH_MEMORY;        }    }    /* Duplicate Attribute */    if ((new_attr = wbxml_attribute_duplicate(attr)) == NULL)        return WBXML_ERROR_NOT_ENOUGH_MEMORY;        /* Add attribute to list */    if (!wbxml_list_append(node->attrs, new_attr)) {        wbxml_attribute_destroy(attr);        return WBXML_ERROR_NOT_ENOUGH_MEMORY;    }    return WBXML_OK;}WBXML_DECLARE(WBXMLError) wbxml_tree_node_add_attrs(WBXMLTreeNode *node,                                                    WBXMLAttribute **attrs){    WB_ULONG i = 0;    if ((node == NULL) || (attrs == NULL)) {        return WBXML_ERROR_BAD_PARAMETER;    }    while (attrs[i] != NULL) {        /* Add attribute */        if (wbxml_tree_node_add_attr(node, attrs[i]) != WBXML_OK)            return WBXML_ERROR_NOT_ENOUGH_MEMORY;        i++;    }    return WBXML_OK;}WBXML_DECLARE(WBXMLError) wbxml_tree_node_add_xml_attr(const WBXMLLangEntry *lang_table,                                                       WBXMLTreeNode *node,                                                       const WB_UTINY *name,                                                       const WB_UTINY *value){    WBXMLAttribute *attr = NULL;    const WBXMLAttrEntry *attr_entry = NULL;    /* Create list if needed */    if (node->attrs == NULL) {        if ((node->attrs = wbxml_list_create()) == NULL) {            return WBXML_ERROR_NOT_ENOUGH_MEMORY;        }    }    /* Create Attribute */    if ((attr = wbxml_attribute_create()) == NULL)        return WBXML_ERROR_NOT_ENOUGH_MEMORY;    /* Set Attribute Name */    if ((attr_entry = wbxml_tables_get_attr_from_xml(lang_table, (WB_UTINY *)name, (WB_UTINY *)value, NULL)) != NULL)        attr->name = wbxml_attribute_name_create_token(attr_entry);    else        attr->name = wbxml_attribute_name_create_literal((WB_UTINY *)name);    if (attr->name == NULL) {        wbxml_attribute_destroy(attr);        return WBXML_ERROR_NOT_ENOUGH_MEMORY;    }    /* Set Attribute Value */    attr->value = wbxml_buffer_create_real(value, WBXML_STRLEN(value), WBXML_STRLEN(value));    if (attr->value == NULL) {        wbxml_attribute_destroy(attr);        return WBXML_ERROR_NOT_ENOUGH_MEMORY;    }    /* Add attribute to list */    if (!wbxml_list_append(node->attrs, attr)) {        wbxml_attribute_destroy(attr);        return WBXML_ERROR_NOT_ENOUGH_MEMORY;    }    return WBXML_OK;}WBXML_DECLARE(WBXMLError) wbxml_tree_node_add_xml_attrs(const WBXMLLangEntry *lang_table,                                                        WBXMLTreeNode *node,                                                        const WB_UTINY **attrs){    const WB_UTINY **p = attrs;    if ((lang_table == NULL) || (node == NULL) || (attrs == NULL))        return WBXML_ERROR_BAD_PARAMETER;    while (p && *p) {        /* Add attribute */        if (wbxml_tree_node_add_xml_attr(lang_table, node, *p, *(p+1)) != WBXML_OK)            return WBXML_ERROR_NOT_ENOUGH_MEMORY;        p += 2;    }    return WBXML_OK;}WBXML_DECLARE(WBXMLTreeNode *) wbxml_tree_node_elt_get_from_name(WBXMLTreeNode *node, const char *name, WB_BOOL recurs){    WBXMLTreeNode *current_node = NULL;    WB_BOOL node_found = FALSE;    if ((node == NULL) || (name == NULL))        return NULL;    /** @todo Handle 'recurs' TRUE */    /* Let's go through the tree */    current_node = node;    while (current_node != NULL)    {        /* Is this the Node we searched ? */        if ((current_node->type == WBXML_TREE_ELEMENT_NODE) &&             (WBXML_STRCMP(wbxml_tag_get_xml_name(current_node->name), name) == 0))        {            node_found = TRUE;            break;        }        else {            /* Go to next Sibbling Node */            current_node = current_node->next;        }    }    if (node_found)        return current_node;    return NULL;}#if defined ( WBXML_SUPPORT_SYNCML )WBXML_DECLARE(WBXMLSyncMLDataType) wbxml_tree_node_get_syncml_data_type(WBXMLTreeNode *node){    WBXMLTreeNode *tmp_node = NULL;    if (node == NULL)        return WBXML_SYNCML_DATA_TYPE_NORMAL;    /* Are we in a <Data> ? */    if ((node->type == WBXML_TREE_ELEMENT_NODE) &&        (node->name != NULL) &&        (WBXML_STRCMP(wbxml_tag_get_xml_name(node->name), "Data") == 0))    {        /* Go to Parent element (or Parent of Parent) and search for <Meta> then <Type> */        if (((node->parent != NULL) &&              (node->parent->children != NULL) &&              ((tmp_node = wbxml_tree_node_elt_get_from_name(node->parent->children, "Meta", FALSE)) != NULL) &&             ((tmp_node = wbxml_tree_node_elt_get_from_name(tmp_node->children, "Type", FALSE)) != NULL)) ||            (((node->parent != NULL) &&               (node->parent->parent != NULL) &&               (node->parent->parent->children != NULL) &&               ((tmp_node = wbxml_tree_node_elt_get_from_name(node->parent->parent->children, "Meta", FALSE)) != NULL)) &&              ((tmp_node = wbxml_tree_node_elt_get_from_name(tmp_node->children, "Type", FALSE)) != NULL)))        {            /* Check <Type> value */            if ((tmp_node->children != NULL) && (tmp_node->children->type == WBXML_TREE_TEXT_NODE)) {                /* application/vnd.syncml-devinf+wbxml */                if (wbxml_buffer_compare_cstr(tmp_node->children->content, "application/vnd.syncml-devinf+wbxml") == 0) {                    return WBXML_SYNCML_DATA_TYPE_WBXML;                }                                /* text/clear */                if (wbxml_buffer_compare_cstr(tmp_node->children->content, "text/clear") == 0) {                    return WBXML_SYNCML_DATA_TYPE_CLEAR;                }                                /* text/directory;profile=vCard */                if (wbxml_buffer_compare_cstr(tmp_node->children->content, "text/directory;profile=vCard") == 0) {                    return WBXML_SYNCML_DATA_TYPE_DIRECTORY_VCARD;                }                                /* text/x-vcard */                if (wbxml_buffer_compare_cstr(tmp_node->children->content, "text/x-vcard") == 0) {                    return WBXML_SYNCML_DATA_TYPE_VCARD;                }                                /* text/x-vcalendar */                if (wbxml_buffer_compare_cstr(tmp_node->children->content, "text/x-vcalendar") == 0) {                    return WBXML_SYNCML_DATA_TYPE_VCALENDAR;                }            }        }                /**         * Hack: we assume that any <Data> inside a <Replace> or <Add> Item is a vObject (vCard / vCal / ...).         *         * This is because when parsing a <Data> content we really need to put a CDATA, event if we don't really         * know the content-type. For example when receiving the end of a splitted vObject with Samsung D600, we receive this:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -