20 static gboolean legacy_xml = FALSE;
21 static gboolean simple_list = FALSE;
22 static gboolean substitute = FALSE;
25 {
"xml-legacy", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &legacy_xml,
28 {
"xml-simple-list", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &simple_list,
31 {
"xml-substitute", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &substitute,
38 typedef struct subst_s {
43 static subst_t substitutions[] = {
44 {
"Active Resources",
"resources" },
45 {
"Allocation Scores",
"allocations" },
46 {
"Allocation Scores and Utilization Information",
"allocations_utilizations" },
47 {
"Cluster Summary",
"summary" },
48 {
"Current cluster status",
"cluster_status" },
49 {
"Executing Cluster Transition",
"transition" },
50 {
"Failed Resource Actions",
"failures" },
51 {
"Fencing History",
"fence_history" },
52 {
"Full List of Resources",
"resources" },
53 {
"Inactive Resources",
"resources" },
54 {
"Migration Summary",
"node_history" },
55 {
"Negative Location Constraints",
"bans" },
56 {
"Node Attributes",
"node_attributes" },
57 {
"Operations",
"node_history" },
58 {
"Resource Config",
"resource_config" },
59 {
"Resource Operations",
"operations" },
60 {
"Revised Cluster Status",
"revised_cluster_status" },
61 {
"Transition Summary",
"actions" },
62 {
"Utilization Information",
"utilizations" },
73 typedef struct private_data_s {
91 g_queue_free(priv->parent_q);
92 g_slist_free(priv->errors);
102 if (out->
priv != NULL) {
106 if (out->
priv == NULL) {
125 priv->parent_q = g_queue_new();
127 g_queue_push_tail(priv->parent_q, priv->root);
133 priv->legacy_xml = legacy_xml;
139 add_error_node(gpointer
data, gpointer user_data) {
140 char *str = (
char *) data;
141 xmlNodePtr node = (xmlNodePtr) user_data;
156 if (priv == NULL || priv->root == NULL) {
161 GSList *node = priv->errors;
167 while (node != NULL) {
168 fprintf(stderr,
"%s\n", (
char *) node->data);
172 char *rc_as_str = pcmk__itoa(exit_status);
179 if (g_slist_length(priv->errors) > 0) {
181 g_slist_foreach(priv->errors, add_error_node, (gpointer) errors_node);
189 fprintf(out->
dest,
"%s", buf);
194 if (copy_dest != NULL) {
203 out->
dest = freopen(NULL,
"w", out->
dest);
212 const char *proc_stdout,
const char *proc_stderr) {
213 xmlNodePtr node, child_node;
214 char *rc_as_str = NULL;
218 rc_as_str = pcmk__itoa(exit_status);
224 if (proc_stdout != NULL) {
229 if (proc_stderr != NULL) {
243 "program",
"Pacemaker",
245 "author",
"Andrew Beekhof",
262 va_start(ap, format);
263 len = vasprintf(&buf, format, ap);
267 priv->errors = g_slist_append(priv->errors, buf);
278 xmlNodePtr parent = NULL;
279 xmlNodePtr cdata_node = NULL;
285 xmlAddChild(parent, cdata_node);
290 xml_begin_list(
pcmk__output_t *out, const
char *singular_noun, const
char *plural_noun,
291 const
char *format, ...) {
299 va_start(ap, format);
300 len = vasprintf(&buf, format, ap);
305 for (
subst_t *s = substitutions; s->from != NULL; s++) {
306 if (!strcmp(s->from, buf)) {
307 name = g_strdup(s->to);
314 name = g_ascii_strdown(buf, -1);
317 if (legacy_xml || simple_list) {
331 xml_list_item(
pcmk__output_t *out, const
char *name, const
char *format, ...) {
332 xmlNodePtr item_node = NULL;
339 va_start(ap, format);
340 len = vasprintf(&buf, format, ap);
365 if (priv->legacy_xml || simple_list) {
366 g_queue_pop_tail(priv->parent_q);
371 node = g_queue_pop_tail(priv->parent_q);
397 if (retval == NULL) {
402 retval->
request = argv == NULL ? NULL : g_strjoinv(
" ", argv);
404 retval->
init = xml_init;
406 retval->
finish = xml_finish;
407 retval->
reset = xml_reset;
414 retval->
info = xml_info;
415 retval->
err = xml_err;
424 retval->
spacer = xml_spacer;
434 xmlNodePtr node = NULL;
440 va_start(args, name);
461 xmlAddChild(g_queue_peek_tail(priv->parent_q), node);
466 xmlNodePtr node = NULL;
476 va_start(args, name);
485 xmlNodePtr node = NULL;
490 xmlNodeSetContent(node, (
pcmkXmlStr) content);
507 g_queue_push_tail(priv->parent_q, parent);
522 CRM_ASSERT(g_queue_get_length(priv->parent_q) > 0);
523 g_queue_pop_tail(priv->parent_q);
536 return g_queue_peek_tail(priv->parent_q);
bool(* init)(pcmk__output_t *out)
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)
void(* register_message)(pcmk__output_t *out, const char *message_id, pcmk__message_fn_t fn)
const char * fmt_name
The name of this output formatter.
void(* reset)(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)
int(* message)(pcmk__output_t *out, const char *message_id,...)
void pcmk__output_xml_add_node(pcmk__output_t *out, xmlNodePtr node)
void pcmk__xe_set_props(xmlNodePtr node,...)
enum crm_exit_e crm_exit_t
int(*) void(* err)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
void pcmk__xe_set_propv(xmlNodePtr node, va_list pairs)
#define PACEMAKER_VERSION
xmlDoc * getDocPtr(xmlNode *node)
GOptionEntry pcmk__xml_output_entries[]
int pcmk__call_message(pcmk__output_t *out, const char *message_id,...)
void * priv
Implementation-specific private data.
xmlNode * copy_xml(xmlNode *src_node)
bool(* is_quiet)(pcmk__output_t *out)
#define PCMK__API_VERSION
void(* end_list)(pcmk__output_t *out)
const char * crm_exit_str(crm_exit_t exit_code)
void pcmk__output_xml_push_parent(pcmk__output_t *out, xmlNodePtr node)
void(* begin_list)(pcmk__output_t *out, const char *singular_noun, const char *plural_noun, const char *format,...) G_GNUC_PRINTF(4
xmlNode * pcmk_create_xml_text_node(xmlNode *parent, const char *name, const char *content)
struct private_data_s private_data_t
void(* subprocess_output)(pcmk__output_t *out, int exit_status, const char *proc_stdout, const char *proc_stderr)
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
int(* info)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
Wrappers for and extensions to libxml2.
xmlNode * create_xml_node(xmlNode *parent, const char *name)
void(* spacer)(pcmk__output_t *out)
void free_xml(xmlNode *child)
bool pcmk__str_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
void pcmk__output_xml_pop_parent(pcmk__output_t *out)
void(* progress)(pcmk__output_t *out, bool end)
pcmk__output_t * pcmk__mk_xml_output(char **argv)
FILE * dest
Where output should be written.
const xmlChar * pcmkXmlStr
void(*) void(*) void(* increment_list)(pcmk__output_t *out)
void(* finish)(pcmk__output_t *out, crm_exit_t exit_status, bool print, void **copy_dest)
void(* free_priv)(pcmk__output_t *out)
gchar * request
A copy of the request that generated this output.
This structure contains everything that makes up a single output formatter.
void(* version)(pcmk__output_t *out, bool extended)
void(* prompt)(const char *prompt, bool echo, char **dest)
xmlNodePtr pcmk__output_create_xml_text_node(pcmk__output_t *out, const char *name, const char *content)
char * dump_xml_formatted_with_text(xmlNode *msg)
xmlNodePtr pcmk__output_xml_create_parent(pcmk__output_t *out, const char *name,...)
int(*) void(*) void(* output_xml)(pcmk__output_t *out, const char *name, const char *buf)
void(*) void(* list_item)(pcmk__output_t *out, const char *name, const char *format,...) G_GNUC_PRINTF(3