14 #ifndef PCMK__CONFIG_H
15 # define PCMK__CONFIG_H
29 static gboolean legacy_xml = FALSE;
30 static gboolean simple_list = FALSE;
31 static gboolean substitute = FALSE;
34 {
"xml-legacy", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &legacy_xml,
37 {
"xml-simple-list", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &simple_list,
40 {
"xml-substitute", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &substitute,
47 typedef struct subst_s {
52 static subst_t substitutions[] = {
53 {
"Attributes",
"attributes" },
54 {
"Active Resources",
"resources" },
55 {
"Full List of Resources",
"resources" },
56 {
"Inactive Resources",
"resources" },
57 {
"Cluster Summary",
"summary" },
58 {
"Failed Resource Actions",
"failures" },
59 {
"Fencing History",
"fence_history" },
60 {
"Migration Summary",
"node_history" },
61 {
"Operations",
"node_history" },
62 {
"Negative Location Constraints",
"bans" },
63 {
"Node Attributes",
"node_attributes" },
64 {
"Resources",
"resources" },
65 {
"Tickets",
"tickets" },
70 typedef struct private_data_s {
85 xmlFreeNode(priv->root);
86 g_queue_free(priv->parent_q);
87 g_slist_free(priv->errors);
97 if (out->
priv != NULL) {
101 if (out->
priv == NULL) {
120 priv->parent_q = g_queue_new();
122 g_queue_push_tail(priv->parent_q, priv->root);
128 priv->legacy_xml = legacy_xml;
134 add_error_node(gpointer
data, gpointer user_data) {
135 char *str = (
char *)
data;
136 xmlNodePtr node = (xmlNodePtr) user_data;
146 GSList *node = priv->errors;
152 while (node != NULL) {
153 fprintf(stderr,
"%s\n", (
char *) node->data);
157 char *rc_as_str = crm_itoa(exit_status);
163 if (g_slist_length(priv->errors) > 0) {
165 g_slist_foreach(priv->errors, add_error_node, (gpointer) errors_node);
173 fprintf(out->
dest,
"%s", buf);
185 if (priv == NULL || priv->root == NULL) {
189 finish_reset_common(out, exit_status, print);
191 if (copy_dest != NULL) {
200 out->
dest = freopen(NULL,
"w", out->
dest);
203 if (out->
priv != NULL) {
204 finish_reset_common(out,
CRM_EX_OK,
true);
213 const char *proc_stdout,
const char *proc_stderr) {
214 xmlNodePtr node, child_node;
215 char *rc_as_str = NULL;
217 rc_as_str = crm_itoa(exit_status);
222 if (proc_stdout != NULL) {
227 if (proc_stderr != NULL) {
259 va_start(ap, format);
260 len = vasprintf(&buf, format, ap);
264 priv->errors = g_slist_append(priv->errors, buf);
275 xmlNodePtr parent = NULL;
276 xmlNodePtr cdata_node = NULL;
283 xmlAddChild(parent, cdata_node);
288 xml_begin_list(
pcmk__output_t *out, const
char *singular_noun, const
char *plural_noun,
289 const
char *format, ...) {
291 const char *
name = NULL;
295 va_start(ap, format);
296 len = vasprintf(&buf, format, ap);
301 for (
subst_t *s = substitutions; s->from != NULL; s++) {
302 if (!strcmp(s->from, buf)) {
313 if (legacy_xml || simple_list) {
316 xmlNodePtr list_node = NULL;
329 xmlNodePtr item_node = NULL;
336 va_start(ap, format);
337 len = vasprintf(&buf, format, ap);
361 if (priv->legacy_xml || simple_list) {
362 g_queue_pop_tail(priv->parent_q);
367 node = g_queue_pop_tail(priv->parent_q);
383 if (retval == NULL) {
388 retval->
request = argv == NULL ? NULL : g_strjoinv(
" ", argv);
390 retval->
init = xml_init;
392 retval->
finish = xml_finish;
393 retval->
reset = xml_reset;
400 retval->
info = xml_info;
401 retval->
err = xml_err;
428 xmlAddChild(g_queue_peek_tail(priv->parent_q), node);
443 xmlNodeSetContent(node, (
pcmkXmlStr) content);
454 g_queue_push_tail(priv->parent_q, parent);
462 CRM_ASSERT(g_queue_get_length(priv->parent_q) > 0);
464 g_queue_pop_tail(priv->parent_q);
474 return g_queue_peek_tail(priv->parent_q);