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) {
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);
void(* end_list)(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)
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)
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)