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

📄 tree.c

📁 Vovida 社区开源的 SIP 协议源码
💻 C
📖 第 1 页 / 共 5 页
字号:
 * * Returns 0 if success and -1 in case of error. */intxmlRemoveProp(xmlAttrPtr cur) {    xmlAttrPtr tmp;    if (cur == NULL) {#ifdef DEBUG_TREE        fprintf(stderr, "xmlRemoveProp : cur == NULL\n");#endif	return(-1);    }    if (cur->parent == NULL) {#ifdef DEBUG_TREE        fprintf(stderr, "xmlRemoveProp : cur->parent == NULL\n");#endif	return(-1);    }    tmp = cur->parent->properties;    if (tmp == cur) {        cur->parent->properties = cur->next;	xmlFreeProp(cur);	return(0);    }    while (tmp != NULL) {	if (tmp->next == cur) {	    tmp->next = cur->next;	    if (tmp->next != NULL)		tmp->next->prev = tmp;	    xmlFreeProp(cur);	    return(0);	}        tmp = tmp->next;    }#ifdef DEBUG_TREE    fprintf(stderr, "xmlRemoveProp : attribute not owned by its node\n");#endif    return(-1);}/** * xmlNewPI: * @name:  the processing instruction name * @content:  the PI content * * Creation of a processing instruction element. * Returns a pointer to the new node object. */xmlNodePtrxmlNewPI(const xmlChar *name, const xmlChar *content) {    xmlNodePtr cur;    if (name == NULL) {#ifdef DEBUG_TREE        fprintf(stderr, "xmlNewPI : name == NULL\n");#endif	return(NULL);    }    /*     * Allocate a new node and fill the fields.     */    cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode));    if (cur == NULL) {        fprintf(stderr, "xmlNewPI : malloc failed\n");	return(NULL);    }    memset(cur, 0, sizeof(xmlNode));    cur->type = XML_PI_NODE;    cur->name = xmlStrdup(name);    if (content != NULL) {#ifndef XML_USE_BUFFER_CONTENT	cur->content = xmlStrdup(content);#else	cur->content = xmlBufferCreateSize(0);	xmlBufferSetAllocationScheme(cur->content,		                     xmlGetBufferAllocationScheme());	xmlBufferAdd(cur->content, content, -1);#endif    }    return(cur);}/** * xmlNewNode: * @ns:  namespace if any * @name:  the node name * * Creation of a new node element. @ns and @content are optionnal (NULL). * If content is non NULL, a child list containing the TEXTs and * ENTITY_REFs node will be created. * Returns a pointer to the new node object. */xmlNodePtrxmlNewNode(xmlNsPtr ns, const xmlChar *name) {    xmlNodePtr cur;    if (name == NULL) {#ifdef DEBUG_TREE        fprintf(stderr, "xmlNewNode : name == NULL\n");#endif	return(NULL);    }    /*     * Allocate a new node and fill the fields.     */    cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode));    if (cur == NULL) {        fprintf(stderr, "xmlNewNode : malloc failed\n");	return(NULL);    }    memset(cur, 0, sizeof(xmlNode));    cur->type = XML_ELEMENT_NODE;        cur->name = xmlStrdup(name);    cur->ns = ns;    return(cur);}/** * xmlNewDocNode: * @doc:  the document * @ns:  namespace if any * @name:  the node name * @content:  the XML text content if any * * Creation of a new node element within a document. @ns and @content * are optionnal (NULL). * NOTE: @content is supposed to be a piece of XML CDATA, so it allow entities *       references, but XML special chars need to be escaped first by using *       xmlEncodeEntitiesReentrant(). Use xmlNewDocRawNode() if you don't *       need entities support. * * Returns a pointer to the new node object. */xmlNodePtrxmlNewDocNode(xmlDocPtr doc, xmlNsPtr ns,              const xmlChar *name, const xmlChar *content) {    xmlNodePtr cur;    cur = xmlNewNode(ns, name);    if (cur != NULL) {        cur->doc = doc;	if (content != NULL) {	    cur->children = xmlStringGetNodeList(doc, content);	    UPDATE_LAST_CHILD(cur)	}    }    return(cur);}/** * xmlNewDocRawNode: * @doc:  the document * @ns:  namespace if any * @name:  the node name * @content:  the text content if any * * Creation of a new node element within a document. @ns and @content * are optionnal (NULL). * * Returns a pointer to the new node object. */xmlNodePtrxmlNewDocRawNode(xmlDocPtr doc, xmlNsPtr ns,                 const xmlChar *name, const xmlChar *content) {    xmlNodePtr cur;    cur = xmlNewNode(ns, name);    if (cur != NULL) {        cur->doc = doc;	if (content != NULL) {	    cur->children = xmlNewDocText(doc, content);	    UPDATE_LAST_CHILD(cur)	}    }    return(cur);}/** * xmlNewDocFragment: * @doc:  the document owning the fragment * * Creation of a new Fragment node. * Returns a pointer to the new node object. */xmlNodePtrxmlNewDocFragment(xmlDocPtr doc) {    xmlNodePtr cur;    /*     * Allocate a new DocumentFragment node and fill the fields.     */    cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode));    if (cur == NULL) {        fprintf(stderr, "xmlNewDocFragment : malloc failed\n");	return(NULL);    }    memset(cur, 0, sizeof(xmlNode));    cur->type = XML_DOCUMENT_FRAG_NODE;    cur->doc = doc;    return(cur);}/** * xmlNewText: * @content:  the text content * * Creation of a new text node. * Returns a pointer to the new node object. */xmlNodePtrxmlNewText(const xmlChar *content) {    xmlNodePtr cur;    /*     * Allocate a new node and fill the fields.     */    cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode));    if (cur == NULL) {        fprintf(stderr, "xmlNewText : malloc failed\n");	return(NULL);    }    memset(cur, 0, sizeof(xmlNode));    cur->type = XML_TEXT_NODE;    cur->name = xmlStrdup(xmlStringText);    if (content != NULL) {#ifndef XML_USE_BUFFER_CONTENT	cur->content = xmlStrdup(content);#else	cur->content = xmlBufferCreateSize(0);	xmlBufferSetAllocationScheme(cur->content,		                     xmlGetBufferAllocationScheme());	xmlBufferAdd(cur->content, content, -1);#endif    }    return(cur);}/** * xmlNewTextChild: * @parent:  the parent node * @ns:  a namespace if any * @name:  the name of the child * @content:  the text content of the child if any. * * Creation of a new child element, added at the end of @parent children list. * @ns and @content parameters are optionnal (NULL). If content is non NULL, * a child TEXT node will be created containing the string content. * * Returns a pointer to the new node object. */xmlNodePtrxmlNewTextChild(xmlNodePtr parent, xmlNsPtr ns,            const xmlChar *name, const xmlChar *content) {    xmlNodePtr cur, prev;    if (parent == NULL) {#ifdef DEBUG_TREE        fprintf(stderr, "xmlNewTextChild : parent == NULL\n");#endif	return(NULL);    }    if (name == NULL) {#ifdef DEBUG_TREE        fprintf(stderr, "xmlNewTextChild : name == NULL\n");#endif	return(NULL);    }    /*     * Allocate a new node     */    if (ns == NULL)	cur = xmlNewDocRawNode(parent->doc, parent->ns, name, content);    else	cur = xmlNewDocRawNode(parent->doc, ns, name, content);    if (cur == NULL) return(NULL);    /*     * add the new element at the end of the children list.     */    cur->type = XML_ELEMENT_NODE;    cur->parent = parent;    cur->doc = parent->doc;    if (parent->children == NULL) {        parent->children = cur;	parent->last = cur;    } else {        prev = parent->last;	prev->next = cur;	cur->prev = prev;	parent->last = cur;    }    return(cur);}/** * xmlNewCharRef: * @doc: the document * @name:  the char ref string, starting with # or "&# ... ;" * * Creation of a new character reference node. * Returns a pointer to the new node object. */xmlNodePtrxmlNewCharRef(xmlDocPtr doc, const xmlChar *name) {    xmlNodePtr cur;    /*     * Allocate a new node and fill the fields.     */    cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode));    if (cur == NULL) {        fprintf(stderr, "xmlNewText : malloc failed\n");	return(NULL);    }    memset(cur, 0, sizeof(xmlNode));    cur->type = XML_ENTITY_REF_NODE;    cur->doc = doc;    if (name[0] == '&') {        int len;        name++;	len = xmlStrlen(name);	if (name[len - 1] == ';')	    cur->name = xmlStrndup(name, len - 1);	else	    cur->name = xmlStrndup(name, len);    } else	cur->name = xmlStrdup(name);    return(cur);}/** * xmlNewReference: * @doc: the document * @name:  the reference name, or the reference string with & and ; * * Creation of a new reference node. * Returns a pointer to the new node object. */xmlNodePtrxmlNewReference(xmlDocPtr doc, const xmlChar *name) {    xmlNodePtr cur;    xmlEntityPtr ent;    /*     * Allocate a new node and fill the fields.     */    cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode));    if (cur == NULL) {        fprintf(stderr, "xmlNewText : malloc failed\n");	return(NULL);    }    memset(cur, 0, sizeof(xmlNode));    cur->type = XML_ENTITY_REF_NODE;    cur->doc = doc;    if (name[0] == '&') {        int len;        name++;	len = xmlStrlen(name);	if (name[len - 1] == ';')	    cur->name = xmlStrndup(name, len - 1);	else	    cur->name = xmlStrndup(name, len);    } else	cur->name = xmlStrdup(name);    ent = xmlGetDocEntity(doc, cur->name);    if (ent != NULL) {#ifndef XML_USE_BUFFER_CONTENT	cur->content = ent->content;#else	/*	 * CJN 11.18.99 this might be a problem, since the xmlBuffer gets	 * a copy of this pointer.  Let's hope we don't manipulate it	 * later 	 */	cur->content = xmlBufferCreateSize(0);	xmlBufferSetAllocationScheme(cur->content,		                     xmlGetBufferAllocationScheme());	if (ent->content != NULL)	    xmlBufferAdd(cur->content, ent->content, -1);#endif	cur->children = (xmlNodePtr) ent;    }    return(cur);}/** * xmlNewDocText: * @doc: the document * @content:  the text content * * Creation of a new text node within a document. * Returns a pointer to the new node object. */xmlNodePtrxmlNewDocText(xmlDocPtr doc, const xmlChar *content) {    xmlNodePtr cur;    cur = xmlNewText(content);    if (cur != NULL) cur->doc = doc;    return(cur);}/** * xmlNewTextLen: * @content:  the text content * @len:  the text len. * * Creation of a new text node with an extra parameter for the content's lenght * Returns a pointer to the new node object. */xmlNodePtrxmlNewTextLen(const xmlChar *content, int len) {    xmlNodePtr cur;    /*     * Allocate a new node and fill the fields.     */    cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode));    if (cur == NULL) {        fprintf(stderr, "xmlNewText : malloc failed\n");	return(NULL);    }    memset(cur, 0, sizeof(xmlNode));    cur->type = XML_TEXT_NODE;    cur->name = xmlStrdup(xmlStringText);    if (content != NULL) {#ifndef XML_USE_BUFFER_CONTENT	cur->content = xmlStrndup(content, len);#else	cur->content = xmlBufferCreateSize(len);	xmlBufferSetAllocationScheme(cur->content,		                     xmlGetBufferAllocationScheme());	xmlBufferAdd(cur->content, content, len);#endif    }    return(cur);}/** * xmlNewDocTextLen: * @doc: the document * @content:  the text content * @len:  the text len. * * Creation of a new text node with an extra content lenght parameter. The * text node pertain to a given document. * Returns a pointer to the new node object. */xmlNodePtrxmlNewDocTextLen(xmlDocPtr doc, const xmlChar *content, int len) {    xmlNodePtr cur;    cur = xmlNewTextLen(content, len);    if (cur != NULL) cur->doc = doc;    return(cur);}/** * xmlNewComment: * @content:  the comment content * * Creation of a new node containing a comment. * Returns a pointer to the new node object. */xmlNodePtrxmlNewComment(const xmlChar *content) {    xmlNodePtr cur;    /*     * Allocate a new node and fill the fields.     */    cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode));    if (cur == NULL) {        fprintf(stderr, "xmlNewComment : malloc failed\n");	return(NULL);    }    memset(cur, 0, sizeof(xmlNode));    cur->type = XML_COMMENT_NODE;    cur->name = xmlStrdup(xmlStringComment);    if (content != NULL) {#ifndef XML_USE_BUFFER_CONTENT	cur->content = xmlStrdup(content);#else	cur->content = xmlBufferCreateSize(0);	xmlBufferSetAllocationScheme(cur->content,		                     xmlGetBufferAllocationScheme());	xmlBufferAdd(cur->content, content, -1);#endif    }    return(cur);}/** * xmlNewCDataBlock: * @doc:  the document * @content:  the CData block content content * @len:  the length of the block * * Creation of a new node containing a CData block. * Returns a pointer to the new node object. */xmlNodePtrxmlNewCDataBlock(xmlDocPtr doc, const xmlChar *content, int len) {    xmlNodePtr cur;    /*     * Allocate a new node and fill the fields.     */    cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode));    if (cur == NULL) {        fprintf(stderr, "xmlNewCDataBlock : malloc failed\n");	return(NULL);    }    memset(cur, 0, sizeof(xmlNode));    cur->type = XML_CDATA_SECTION_NODE;    if (content != NULL) {#ifndef XML_USE_BUFFER_CONTENT	cur->content = xmlStrndup(content, len);#else	cur->content = xmlBufferCreateSize(len);	xmlBufferSetAllocationScheme(cur->content,		                     xmlGetBufferAllocationScheme());

⌨️ 快捷键说明

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