21 static gboolean legacy_xml = FALSE;
22 static gboolean simple_list = FALSE;
23 static gboolean substitute = FALSE;
26 {
"xml-legacy", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &legacy_xml,
29 {
"xml-simple-list", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &simple_list,
32 {
"xml-substitute", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &substitute,
39 typedef struct subst_s {
44 static subst_t substitutions[] = {
45 {
"Active Resources",
"resources" },
46 {
"Allocation Scores",
"allocations" },
47 {
"Allocation Scores and Utilization Information",
"allocations_utilizations" },
48 {
"Cluster Summary",
"summary" },
49 {
"Current cluster status",
"cluster_status" },
50 {
"Executing Cluster Transition",
"transition" },
51 {
"Failed Resource Actions",
"failures" },
52 {
"Fencing History",
"fence_history" },
53 {
"Full List of Resources",
"resources" },
54 {
"Inactive Resources",
"resources" },
55 {
"Migration Summary",
"node_history" },
56 {
"Negative Location Constraints",
"bans" },
57 {
"Node Attributes",
"node_attributes" },
58 {
"Operations",
"node_history" },
59 {
"Resource Config",
"resource_config" },
60 {
"Resource Operations",
"operations" },
61 {
"Revised Cluster Status",
"revised_cluster_status" },
62 {
"Transition Summary",
"actions" },
63 {
"Utilization Information",
"utilizations" },
74 typedef struct private_data_s {
87 if (out == NULL || out->
priv == NULL) {
94 g_queue_free(priv->parent_q);
95 g_slist_free(priv->errors);
107 if (out->
priv != NULL) {
111 if (out->
priv == NULL) {
130 priv->parent_q = g_queue_new();
132 g_queue_push_tail(priv->parent_q, priv->root);
138 priv->legacy_xml = legacy_xml;
144 add_error_node(gpointer
data, gpointer user_data) {
145 char *str = (
char *)
data;
146 xmlNodePtr node = (xmlNodePtr) user_data;
161 if (priv == NULL || priv->root == NULL) {
166 GSList *node = priv->errors;
172 while (node != NULL) {
173 fprintf(stderr,
"%s\n", (
char *) node->data);
177 char *rc_as_str = pcmk__itoa(exit_status);
184 if (g_slist_length(priv->errors) > 0) {
186 g_slist_foreach(priv->errors, add_error_node, (gpointer) errors_node);
194 fprintf(out->
dest,
"%s", buf);
199 if (copy_dest != NULL) {
208 out->
dest = freopen(NULL,
"w", out->
dest);
217 const char *proc_stdout,
const char *proc_stderr) {
218 xmlNodePtr node, child_node;
219 char *rc_as_str = NULL;
223 rc_as_str = pcmk__itoa(exit_status);
229 if (proc_stdout != NULL) {
234 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;
291 xmlAddChild(
parent, cdata_node);
296 xml_begin_list(
pcmk__output_t *out, const
char *singular_noun, const
char *plural_noun,
297 const
char *format, ...) {
305 va_start(ap, format);
306 len = vasprintf(&buf, format, ap);
311 for (
subst_t *s = substitutions; s->from != NULL; s++) {
312 if (!strcmp(s->from, buf)) {
313 name = g_strdup(s->to);
320 name = g_ascii_strdown(buf, -1);
323 if (legacy_xml || simple_list) {
338 xmlNodePtr item_node = NULL;
345 va_start(ap, format);
346 len = vasprintf(&buf, format, ap);
371 if (priv->legacy_xml || simple_list) {
372 g_queue_pop_tail(priv->parent_q);
377 node = g_queue_pop_tail(priv->parent_q);
403 if (retval == NULL) {
410 retval->
init = xml_init;
412 retval->
finish = xml_finish;
413 retval->
reset = xml_reset;
420 retval->
info = xml_info;
421 retval->
err = xml_err;
430 retval->
spacer = xml_spacer;
440 xmlNodePtr node = NULL;
447 va_start(args,
name);
465 xmlAddChild(g_queue_peek_tail(priv->parent_q), node);
470 xmlNodePtr node = NULL;
480 va_start(args,
name);
489 xmlNodePtr node = NULL;
495 xmlNodeSetContent(node, (
pcmkXmlStr) content);
509 g_queue_push_tail(priv->parent_q,
parent);
521 CRM_ASSERT(g_queue_get_length(priv->parent_q) > 0);
522 g_queue_pop_tail(priv->parent_q);
535 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,...)
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)
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)
int(*) void(*) void(* output_xml)(pcmk__output_t *out, const char *name, const char *buf)
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_pop_parent(pcmk__output_t *out)
#define PACEMAKER_VERSION
xmlDoc * getDocPtr(xmlNode *node)
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)
#define PCMK__API_VERSION
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
bool(* init)(pcmk__output_t *out)
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)
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)
gchar * pcmk__quote_cmdline(gchar **argv)
GOptionEntry pcmk__xml_output_entries[]
void(*) void(*) void(* increment_list)(pcmk__output_t *out)
char * dump_xml_formatted_with_text(xmlNode *msg)
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)
void pcmk__output_xml_add_node(pcmk__output_t *out, xmlNodePtr node)