Skip to content

Commit 5b8b280

Browse files
committed
API: libcrmcommon: Deprecate crm_xml_add()
Signed-off-by: Reid Wahl <[email protected]>
1 parent aab0fc3 commit 5b8b280

File tree

3 files changed

+44
-59
lines changed

3 files changed

+44
-59
lines changed

include/crm/common/xml_element.h

-7
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
#ifndef PCMK__CRM_COMMON_XML_ELEMENT__H
1111
#define PCMK__CRM_COMMON_XML_ELEMENT__H
1212

13-
#include <sys/time.h> // struct timeval
14-
15-
#include <glib.h> // guint
16-
#include <libxml/tree.h> // xmlNode
17-
1813
#ifdef __cplusplus
1914
extern "C" {
2015
#endif
@@ -25,8 +20,6 @@ extern "C" {
2520
* \ingroup core
2621
*/
2722

28-
const char *crm_xml_add(xmlNode *node, const char *name, const char *value);
29-
3023
#ifdef __cplusplus
3124
}
3225
#endif

include/crm/common/xml_element_compat.h

+3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ const char *crm_xml_add_ll(xmlNode *node, const char *name, long long value);
7878
//! \deprecated Do not use
7979
const char *crm_xml_add_int(xmlNode *node, const char *name, int value);
8080

81+
//! \deprecated Do not use
82+
const char *crm_xml_add(xmlNode *node, const char *name, const char *value);
83+
8184
#ifdef __cplusplus
8285
}
8386
#endif

lib/common/xml_element.c

+41-52
Original file line numberDiff line numberDiff line change
@@ -997,58 +997,6 @@ pcmk__xe_foreach_child(xmlNode *xml, const char *child_element_name,
997997

998998
// XML attribute handling
999999

1000-
/*!
1001-
* \brief Create an XML attribute with specified name and value
1002-
*
1003-
* \param[in,out] node XML node to modify
1004-
* \param[in] name Attribute name to set
1005-
* \param[in] value Attribute value to set
1006-
*
1007-
* \return New value on success, \c NULL otherwise
1008-
* \note This does nothing if node, name, or value are \c NULL or empty.
1009-
*/
1010-
const char *
1011-
crm_xml_add(xmlNode *node, const char *name, const char *value)
1012-
{
1013-
// @TODO Replace with internal function that returns the new attribute
1014-
bool dirty = FALSE;
1015-
xmlAttr *attr = NULL;
1016-
1017-
CRM_CHECK(node != NULL, return NULL);
1018-
CRM_CHECK(name != NULL, return NULL);
1019-
1020-
if (value == NULL) {
1021-
return NULL;
1022-
}
1023-
1024-
if (pcmk__xml_doc_all_flags_set(node->doc, pcmk__xf_tracking)) {
1025-
const char *old = pcmk__xe_get(node, name);
1026-
1027-
if (old == NULL || value == NULL || strcmp(old, value) != 0) {
1028-
dirty = TRUE;
1029-
}
1030-
}
1031-
1032-
if (dirty && (pcmk__check_acl(node, name, pcmk__xf_acl_create) == FALSE)) {
1033-
crm_trace("Cannot add %s=%s to %s", name, value, node->name);
1034-
return NULL;
1035-
}
1036-
1037-
attr = xmlSetProp(node, (const xmlChar *) name, (const xmlChar *) value);
1038-
1039-
/* If the attribute already exists, this does nothing. Attribute values
1040-
* don't get private data.
1041-
*/
1042-
pcmk__xml_new_private_data((xmlNode *) attr);
1043-
1044-
if (dirty) {
1045-
pcmk__mark_xml_attr_dirty(attr);
1046-
}
1047-
1048-
CRM_CHECK(attr && attr->children && attr->children->content, return NULL);
1049-
return (char *)attr->children->content;
1050-
}
1051-
10521000
/*!
10531001
* \internal
10541002
* \brief Retrieve the value of an XML attribute
@@ -1618,6 +1566,47 @@ expand_idref(xmlNode *input, xmlNode *top)
16181566
return pcmk__xe_resolve_idref(input, top);
16191567
}
16201568

1569+
const char *
1570+
crm_xml_add(xmlNode *node, const char *name, const char *value)
1571+
{
1572+
bool dirty = FALSE;
1573+
xmlAttr *attr = NULL;
1574+
1575+
CRM_CHECK(node != NULL, return NULL);
1576+
CRM_CHECK(name != NULL, return NULL);
1577+
1578+
if (value == NULL) {
1579+
return NULL;
1580+
}
1581+
1582+
if (pcmk__xml_doc_all_flags_set(node->doc, pcmk__xf_tracking)) {
1583+
const char *old = pcmk__xe_get(node, name);
1584+
1585+
if (old == NULL || value == NULL || strcmp(old, value) != 0) {
1586+
dirty = TRUE;
1587+
}
1588+
}
1589+
1590+
if (dirty && (pcmk__check_acl(node, name, pcmk__xf_acl_create) == FALSE)) {
1591+
crm_trace("Cannot add %s=%s to %s", name, value, node->name);
1592+
return NULL;
1593+
}
1594+
1595+
attr = xmlSetProp(node, (const xmlChar *) name, (const xmlChar *) value);
1596+
1597+
/* If the attribute already exists, this does nothing. Attribute values
1598+
* don't get private data.
1599+
*/
1600+
pcmk__xml_new_private_data((xmlNode *) attr);
1601+
1602+
if (dirty) {
1603+
pcmk__mark_xml_attr_dirty(attr);
1604+
}
1605+
1606+
CRM_CHECK(attr && attr->children && attr->children->content, return NULL);
1607+
return (char *)attr->children->content;
1608+
}
1609+
16211610
void
16221611
crm_xml_set_id(xmlNode *xml, const char *format, ...)
16231612
{

0 commit comments

Comments
 (0)