| 1659 | #endif /* LIBXML_TREE_ENABLED */ |
| 1660 | |
| 1661 | static xmlAttrPtr |
| 1662 | xmlNewPropInternal(xmlNodePtr node, xmlNsPtr ns, |
| 1663 | const xmlChar * name, const xmlChar * value, |
| 1664 | int eatname) |
| 1665 | { |
| 1666 | xmlAttrPtr cur; |
| 1667 | xmlDocPtr doc = NULL; |
| 1668 | |
| 1669 | if ((node != NULL) && (node->type != XML_ELEMENT_NODE)) { |
| 1670 | if ((eatname == 1) && |
| 1671 | ((node->doc == NULL) || (node->doc->dict == NULL) || |
| 1672 | (!(xmlDictOwns(node->doc->dict, name))))) |
| 1673 | xmlFree((xmlChar *) name); |
| 1674 | return (NULL); |
| 1675 | } |
| 1676 | |
| 1677 | /* |
| 1678 | * Allocate a new property and fill the fields. |
| 1679 | */ |
| 1680 | cur = (xmlAttrPtr) xmlMalloc(sizeof(xmlAttr)); |
| 1681 | if (cur == NULL) { |
| 1682 | if ((eatname == 1) && |
| 1683 | ((node == NULL) || (node->doc == NULL) || |
| 1684 | (node->doc->dict == NULL) || |
| 1685 | (!(xmlDictOwns(node->doc->dict, name))))) |
| 1686 | xmlFree((xmlChar *) name); |
| 1687 | return (NULL); |
| 1688 | } |
| 1689 | memset(cur, 0, sizeof(xmlAttr)); |
| 1690 | cur->type = XML_ATTRIBUTE_NODE; |
| 1691 | |
| 1692 | cur->parent = node; |
| 1693 | if (node != NULL) { |
| 1694 | doc = node->doc; |
| 1695 | cur->doc = doc; |
| 1696 | } |
| 1697 | cur->ns = ns; |
| 1698 | |
| 1699 | if (eatname == 0) { |
| 1700 | if ((doc != NULL) && (doc->dict != NULL)) |
| 1701 | cur->name = (xmlChar *) xmlDictLookup(doc->dict, name, -1); |
| 1702 | else |
| 1703 | cur->name = xmlStrdup(name); |
| 1704 | if (cur->name == NULL) |
| 1705 | goto error; |
| 1706 | } else |
| 1707 | cur->name = name; |
| 1708 | |
| 1709 | if (value != NULL) { |
| 1710 | xmlNodePtr tmp; |
| 1711 | |
| 1712 | cur->children = xmlNewDocText(doc, value); |
| 1713 | if (cur->children == NULL) |
| 1714 | goto error; |
| 1715 | cur->last = NULL; |
| 1716 | tmp = cur->children; |
| 1717 | while (tmp != NULL) { |
| 1718 | tmp->parent = (xmlNodePtr) cur; |
no test coverage detected