25 static gboolean legacy_xml = FALSE;
26 static gboolean simple_list = FALSE;
27 static gboolean substitute = FALSE;
30 {
"xml-legacy", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &legacy_xml,
33 {
"xml-simple-list", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &simple_list,
36 {
"xml-substitute", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &substitute,
43 typedef struct subst_s {
48 static subst_t substitutions[] = {
49 {
"Active Resources",
"resources" },
50 {
"Assignment Scores",
"allocations" },
51 {
"Assignment Scores and Utilization Information",
"allocations_utilizations" },
52 {
"Cluster Summary",
"summary" },
53 {
"Current cluster status",
"cluster_status" },
54 {
"Executing Cluster Transition",
"transition" },
55 {
"Failed Resource Actions",
"failures" },
56 {
"Fencing History",
"fence_history" },
57 {
"Full List of Resources",
"resources" },
58 {
"Inactive Resources",
"resources" },
59 {
"Migration Summary",
"node_history" },
60 {
"Negative Location Constraints",
"bans" },
61 {
"Node Attributes",
"node_attributes" },
62 {
"Operations",
"node_history" },
63 {
"Resource Config",
"resource_config" },
64 {
"Resource Operations",
"operations" },
65 {
"Revised Cluster Status",
"revised_cluster_status" },
66 {
"Transition Summary",
"actions" },
67 {
"Utilization Information",
"utilizations" },
78 typedef struct private_data_s {
91 if (out == NULL || out->
priv == NULL) {
98 g_queue_free(priv->parent_q);
99 g_slist_free(priv->errors);
111 if (out->
priv != NULL) {
115 if (out->
priv == NULL) {
134 priv->parent_q = g_queue_new();
136 g_queue_push_tail(priv->parent_q, priv->root);
142 priv->legacy_xml = legacy_xml;
148 add_error_node(gpointer
data, gpointer user_data) {
149 char *str = (
char *)
data;
150 xmlNodePtr node = (xmlNodePtr) user_data;
165 if (priv == NULL || priv->root == NULL) {
170 GSList *node = priv->errors;
176 while (node != NULL) {
177 fprintf(stderr,
"%s\n", (
char *) node->data);
181 char *rc_as_str = pcmk__itoa(exit_status);
188 if (g_slist_length(priv->errors) > 0) {
190 g_slist_foreach(priv->errors, add_error_node, (gpointer) errors_node);
200 if (copy_dest != NULL) {
209 out->
dest = freopen(NULL,
"w", out->
dest);
218 const char *proc_stdout,
const char *proc_stderr) {
219 xmlNodePtr node, child_node;
220 char *rc_as_str = NULL;
224 rc_as_str = pcmk__itoa(exit_status);
230 if (proc_stdout != NULL) {
235 if (proc_stderr != NULL) {
248 "program",
"Pacemaker",
250 "author",
"Andrew Beekhof and the " 251 "Pacemaker project contributors",
268 va_start(ap, format);
269 len = vasprintf(&buf, format, ap);
273 priv->errors = g_slist_append(priv->errors, buf);
285 xmlNodePtr cdata_node = NULL;
294 xmlAddChild(
parent, cdata_node);
299 xml_begin_list(
pcmk__output_t *out, const
char *singular_noun, const
char *plural_noun,
300 const
char *format, ...) {
308 va_start(ap, format);
309 len = vasprintf(&buf, format, ap);
314 for (
subst_t *s = substitutions; s->from != NULL; s++) {
315 if (!strcmp(s->from, buf)) {
316 name = g_strdup(s->to);
323 name = g_ascii_strdown(buf, -1);
326 if (legacy_xml || simple_list) {
341 xmlNodePtr item_node = NULL;
348 va_start(ap, format);
349 len = vasprintf(&buf, format, ap);
374 if (priv->legacy_xml || simple_list) {
375 g_queue_pop_tail(priv->parent_q);
380 node = g_queue_pop_tail(priv->parent_q);
406 if (retval == NULL) {
413 retval->
init = xml_init;
415 retval->
finish = xml_finish;
416 retval->
reset = xml_reset;
423 retval->
info = xml_info;
425 retval->
err = xml_err;
434 retval->
spacer = xml_spacer;
444 xmlNodePtr node = NULL;
451 va_start(args,
name);
469 parent = g_queue_peek_tail(priv->parent_q);
479 xmlNodePtr node = NULL;
489 va_start(args,
name);
498 xmlNodePtr node = NULL;
504 xmlNodeSetContent(node, (
pcmkXmlStr) content);
518 g_queue_push_tail(priv->parent_q,
parent);
530 CRM_ASSERT(g_queue_get_length(priv->parent_q) > 0);
531 g_queue_pop_tail(priv->parent_q);
544 return g_queue_peek_tail(priv->parent_q);
void(* end_list)(pcmk__output_t *out)
#define CRM_CHECK(expr, failure_action)
xmlNodePtr pcmk__output_create_xml_node(pcmk__output_t *out, const char *name,...)
Control output from tools.
void void void void void pcmk__text_prompt(const char *prompt, bool echo, char **dest)
int(* message)(pcmk__output_t *out, const char *message_id,...)
const char * fmt_name
The name of this output formatter.
bool(* is_quiet)(pcmk__output_t *out)
#define PCMK__API_VERSION
void(* spacer)(pcmk__output_t *out)
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
void pcmk__register_message(pcmk__output_t *out, const char *message_id, pcmk__message_fn_t fn)
xmlNodePtr pcmk__output_xml_peek_parent(pcmk__output_t *out)
xmlNodePtr pcmk__output_create_xml_text_node(pcmk__output_t *out, const char *name, const char *content)
enum crm_exit_e crm_exit_t
void pcmk__xe_set_propv(xmlNodePtr node, va_list pairs)
int(* info)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
void pcmk__output_xml_add_node_copy(pcmk__output_t *out, xmlNodePtr node)
void pcmk__output_xml_pop_parent(pcmk__output_t *out)
#define PACEMAKER_VERSION
int pcmk__call_message(pcmk__output_t *out, const char *message_id,...)
void(* prompt)(const char *prompt, bool echo, char **dest)
void pcmk__output_xml_push_parent(pcmk__output_t *out, xmlNodePtr parent)
void * priv
Implementation-specific private data.
xmlNode * copy_xml(xmlNode *src_node)
const char * crm_exit_str(crm_exit_t exit_code)
void(* register_message)(pcmk__output_t *out, const char *message_id, pcmk__message_fn_t fn)
xmlNode * pcmk_create_xml_text_node(xmlNode *parent, const char *name, const char *content)
struct private_data_s private_data_t
void(* free_priv)(pcmk__output_t *out)
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
xmlNode * add_node_copy(xmlNode *new_parent, xmlNode *xml_node)
bool(* init)(pcmk__output_t *out)
int(*) int(*) void(*) void(* output_xml)(pcmk__output_t *out, const char *name, const char *buf)
int(*) int(*) void(* err)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
Wrappers for and extensions to libxml2.
void(* finish)(pcmk__output_t *out, crm_exit_t exit_status, bool print, void **copy_dest)
xmlNode * create_xml_node(xmlNode *parent, const char *name)
int(*) int(* transient)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
void free_xml(xmlNode *child)
bool pcmk__str_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
void pcmk__xe_set_props(xmlNodePtr node,...) G_GNUC_NULL_TERMINATED
FILE * dest
Where output should be written.
const xmlChar * pcmkXmlStr
void(*) void(* list_item)(pcmk__output_t *out, const char *name, const char *format,...) G_GNUC_PRINTF(3
gchar * request
A copy of the request that generated this output.
This structure contains everything that makes up a single output formatter.
struct private_data_s private_data_t
void(* version)(pcmk__output_t *out, bool extended)
void(* begin_list)(pcmk__output_t *out, const char *singular_noun, const char *plural_noun, const char *format,...) G_GNUC_PRINTF(4
void(* reset)(pcmk__output_t *out)
void(* progress)(pcmk__output_t *out, bool end)
pcmk__output_t * pcmk__mk_xml_output(char **argv)
int pcmk__xml2fd(int fd, xmlNode *cur)
gchar * pcmk__quote_cmdline(gchar **argv)
GOptionEntry pcmk__xml_output_entries[]
void(*) void(*) void(* increment_list)(pcmk__output_t *out)
xmlNodePtr pcmk__output_xml_create_parent(pcmk__output_t *out, const char *name,...)
void(* subprocess_output)(pcmk__output_t *out, int exit_status, const char *proc_stdout, const char *proc_stderr)