root/lib/common/xml_attr.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. pcmk__mark_xml_attr_dirty
  2. pcmk__marked_as_deleted
  3. pcmk__dump_xml_attr

   1 /*
   2  * Copyright 2004-2023 the Pacemaker project contributors
   3  *
   4  * The version control history for this file may have further details.
   5  *
   6  * This source code is licensed under the GNU Lesser General Public License
   7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
   8  */
   9 
  10 #include <crm_internal.h>
  11 
  12 #include <stdio.h>
  13 #include <sys/types.h>
  14 #include <unistd.h>
  15 #include <time.h>
  16 #include <string.h>
  17 #include <stdlib.h>
  18 #include <stdarg.h>
  19 #include <bzlib.h>
  20 
  21 #include <libxml/parser.h>
  22 #include <libxml/tree.h>
  23 #include <libxml/xmlIO.h>  /* xmlAllocOutputBuffer */
  24 
  25 #include <crm/crm.h>
  26 #include <crm/msg_xml.h>
  27 #include <crm/common/xml.h>
  28 #include <crm/common/xml_internal.h>  // PCMK__XML_LOG_BASE, etc.
  29 #include "crmcommon_private.h"
  30 
  31 void
  32 pcmk__mark_xml_attr_dirty(xmlAttr *a) 
     /* [previous][next][first][last][top][bottom][index][help] */
  33 {
  34     xmlNode *parent = a->parent;
  35     xml_node_private_t *nodepriv = a->_private;
  36 
  37     pcmk__set_xml_flags(nodepriv, pcmk__xf_dirty|pcmk__xf_modified);
  38     pcmk__clear_xml_flags(nodepriv, pcmk__xf_deleted);
  39     pcmk__mark_xml_node_dirty(parent);
  40 }
  41 
  42 // This also clears attribute's flags if not marked as deleted
  43 bool
  44 pcmk__marked_as_deleted(xmlAttrPtr a, void *user_data)
     /* [previous][next][first][last][top][bottom][index][help] */
  45 {
  46     xml_node_private_t *nodepriv = a->_private;
  47 
  48     if (pcmk_is_set(nodepriv->flags, pcmk__xf_deleted)) {
  49         return true;
  50     }
  51     nodepriv->flags = pcmk__xf_none;
  52     return false;
  53 }
  54 
  55 /*!
  56  * \internal
  57  * \brief Append an XML attribute to a buffer
  58  *
  59  * \param[in]     attr     Attribute to append
  60  * \param[in,out] buffer   Where to append the content (must not be \p NULL)
  61  */
  62 void
  63 pcmk__dump_xml_attr(const xmlAttr *attr, GString *buffer)
     /* [previous][next][first][last][top][bottom][index][help] */
  64 {
  65     char *p_value = NULL;
  66     const char *p_name = NULL;
  67     xml_node_private_t *nodepriv = NULL;
  68 
  69     if (attr == NULL || attr->children == NULL) {
  70         return;
  71     }
  72 
  73     nodepriv = attr->_private;
  74     if (nodepriv && pcmk_is_set(nodepriv->flags, pcmk__xf_deleted)) {
  75         return;
  76     }
  77 
  78     p_name = (const char *) attr->name;
  79     p_value = crm_xml_escape((const char *)attr->children->content);
  80     pcmk__g_strcat(buffer, " ", p_name, "=\"", pcmk__s(p_value, "<null>"), "\"",
  81                    NULL);
  82 
  83     free(p_value);

/* [previous][next][first][last][top][bottom][index][help] */