41 xml_show_patchset_header(
pcmk__output_t *out,
const xmlNode *patchset)
44 int add[] = { 0, 0, 0 };
45 int del[] = { 0, 0, 0 };
49 if ((add[0] != del[0]) || (add[1] != del[1]) || (add[2] != del[2])) {
53 out->
info(out,
"Diff: --- %d.%d.%d %s", del[0], del[1], del[2], fmt);
54 rc = out->
info(out,
"Diff: +++ %d.%d.%d %s",
55 add[0], add[1], add[2], digest);
57 }
else if ((add[0] != 0) || (add[1] != 0) || (add[2] != 0)) {
58 rc = out->
info(out,
"Local-only Change: %d.%d.%d",
59 add[0], add[1], add[2]);
80 xml_show_patchset_v1_recursive(
pcmk__output_t *out,
const char *prefix,
81 const xmlNode *
data,
int depth, uint32_t options)
83 if ((
data->children == NULL)
100 for (
const xmlNode *child = pcmk__xml_first_child(
data); child != NULL;
101 child = pcmk__xml_next(child)) {
102 int temp_rc = xml_show_patchset_v1_recursive(out, prefix, child,
104 rc = pcmk__output_select_rc(rc, temp_rc);
132 xml_show_patchset_v1(
pcmk__output_t *out,
const xmlNode *patchset,
135 const xmlNode *removed = NULL;
136 const xmlNode *added = NULL;
137 const xmlNode *child = NULL;
138 bool is_first =
true;
139 int rc = xml_show_patchset_header(out, patchset);
147 for (child = pcmk__xml_first_child(removed); child != NULL;
148 child = pcmk__xml_next(child)) {
149 int temp_rc = xml_show_patchset_v1_recursive(out,
"- ", child, 0,
152 rc = pcmk__output_select_rc(rc, temp_rc);
157 rc = pcmk__output_select_rc(rc, out->
info(out,
" --- "));
163 for (child = pcmk__xml_first_child(added); child != NULL;
164 child = pcmk__xml_next(child)) {
165 int temp_rc = xml_show_patchset_v1_recursive(out,
"+ ", child, 0,
168 rc = pcmk__output_select_rc(rc, temp_rc);
173 rc = pcmk__output_select_rc(rc, out->
info(out,
" +++ "));
195 xml_show_patchset_v2(
pcmk__output_t *out,
const xmlNode *patchset)
197 int rc = xml_show_patchset_header(out, patchset);
200 for (
const xmlNode *change = pcmk__xml_first_child(patchset);
201 change != NULL; change = pcmk__xml_next(change)) {
209 if (strcmp(op,
"create") == 0) {
215 rc = pcmk__output_select_rc(rc, temp_rc);
218 for (
char *ch = prefix + 2; *ch !=
'\0'; ch++) {
226 rc = pcmk__output_select_rc(rc, temp_rc);
229 }
else if (strcmp(op,
"move") == 0) {
232 temp_rc = out->
info(out,
235 rc = pcmk__output_select_rc(rc, temp_rc);
237 }
else if (strcmp(op,
"modify") == 0) {
239 GString *buffer_set = NULL;
240 GString *buffer_unset = NULL;
242 for (
const xmlNode *child = pcmk__xml_first_child(clist);
243 child != NULL; child = pcmk__xml_next(child)) {
251 if (strcmp(op,
"set") == 0) {
257 }
else if (strcmp(op,
"unset") == 0) {
259 g_string_append(buffer_unset,
name);
263 if (buffer_set != NULL) {
264 temp_rc = out->
info(out,
"+ %s: %s", xpath, buffer_set->str);
265 rc = pcmk__output_select_rc(rc, temp_rc);
266 g_string_free(buffer_set, TRUE);
269 if (buffer_unset != NULL) {
270 temp_rc = out->
info(out,
"-- %s: %s",
271 xpath, buffer_unset->str);
272 rc = pcmk__output_select_rc(rc, temp_rc);
273 g_string_free(buffer_unset, TRUE);
276 }
else if (strcmp(op,
"delete") == 0) {
281 temp_rc = out->
info(out,
"-- %s (%d)", xpath, position);
283 temp_rc = out->
info(out,
"-- %s", xpath);
285 rc = pcmk__output_select_rc(rc, temp_rc);
310 const xmlNode *patchset = va_arg(args,
const xmlNode *);
314 if (patchset == NULL) {
324 return xml_show_patchset_v2(out, patchset);
326 crm_err(
"Unknown patch format: %d", format);
349 static struct qb_log_callsite *patchset_cs = NULL;
351 const xmlNode *patchset = va_arg(args,
const xmlNode *);
360 if (patchset == NULL) {
365 if (patchset_cs == NULL) {
366 patchset_cs = qb_log_callsite_get(__func__, __FILE__,
"xml-patchset",
379 if (log_level < LOG_DEBUG) {
380 return xml_show_patchset_v1(out, patchset,
386 return xml_show_patchset_v2(out, patchset);
388 crm_err(
"Unknown patch format: %d", format);
411 const xmlNode *patchset = va_arg(args,
const xmlNode *);
413 if (patchset != NULL) {
416 out->output_xml(out,
"xml-patchset", buf);
425 {
"xml-patchset",
"default", xml_patchset_default },
426 {
"xml-patchset",
"log", xml_patchset_log },
427 {
"xml-patchset",
"xml", xml_patchset_xml },
450 const xmlNode *patchset)
460 static struct qb_log_callsite *patchset_cs = NULL;
473 if (patchset_cs == NULL) {
474 patchset_cs = qb_log_callsite_get(__func__, __FILE__,
475 "xml-patchset", log_level,
487 if (patchset == NULL) {
496 if (log_level < LOG_DEBUG) {
497 rc = xml_show_patchset_v1(out, patchset,
505 rc = xml_show_patchset_v2(out, patchset);
508 crm_err(
"Unknown patch format: %d", format);
#define CRM_CHECK(expr, failure_action)
void pcmk__register_messages(pcmk__output_t *out, const pcmk__message_entry_t *table)
xmlNode * first_named_child(const xmlNode *parent, const char *name)
void xml_log_patchset(uint8_t log_level, const char *function, const xmlNode *patchset)
xmlNode * find_xml_node(const xmlNode *root, const char *search_path, gboolean must_find)
crm_exit_t pcmk_rc2exitc(int rc)
Map a function return code to the most similar exit code.
Include the opening tag of an XML element, and include XML comments.
void pcmk__register_patchset_messages(pcmk__output_t *out)
#define PCMK__XML_PREFIX_MOVED
XML has been moved.
void pcmk__add_separated_word(GString **list, size_t init_size, const char *word, const char *separator)
int(* info)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
unsigned int crm_trace_nonlog
void pcmk__output_set_log_level(pcmk__output_t *out, uint8_t log_level)
int crm_element_value_int(const xmlNode *data, const char *name, int *dest)
Retrieve the integer value of an XML attribute.
Include indentation and newlines.
Deprecated Pacemaker XML API.
Log a created XML subtree.
#define XML_TAG_DIFF_ADDED
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
#define PCMK__OUTPUT_ARGS(ARGS...)
Include the children of an XML element.
#define crm_trace(fmt, args...)
void pcmk__g_strcat(GString *buffer,...) G_GNUC_NULL_TERMINATED
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
#define pcmk_is_set(g, f)
Convenience alias for pcmk_all_flags_set(), to check single flag.
void(* finish)(pcmk__output_t *out, crm_exit_t exit_status, bool print, void **copy_dest)
#define XML_DIFF_POSITION
#define PCMK__XML_PREFIX_CREATED
XML is newly created.
void pcmk__output_free(pcmk__output_t *out)
char * dump_xml_formatted_with_text(const xmlNode *xml)
gboolean crm_is_callsite_active(struct qb_log_callsite *cs, uint8_t level, uint32_t tags)
Log a removed XML subtree.
int pcmk__xml_show(pcmk__output_t *out, const char *prefix, const xmlNode *data, int depth, uint32_t options)
Include the closing tag of an XML element.
#define crm_err(fmt, args...)
#define PCMK__XML_PREFIX_DELETED
XML has been deleted.
This structure contains everything that makes up a single output formatter.
Log a minimal version of an XML diff (only showing the changes)
bool xml_patch_versions(const xmlNode *patchset, int add[3], int del[3])
#define XML_TAG_DIFF_REMOVED
uint8_t pcmk__output_get_log_level(const pcmk__output_t *out)
int pcmk__text_output_new(pcmk__output_t **out, const char *filename)
int pcmk__log_output_new(pcmk__output_t **out)