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);
void(* end_list)(pcmk__output_t *out)
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)
xmlNodePtr pcmk__output_xml_create_parent(pcmk__output_t *out, const char *name)
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__output_xml_pop_parent(pcmk__output_t *out)
void(*) void(* err)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
#define PACEMAKER_VERSION
xmlDoc * getDocPtr(xmlNode *node)
int pcmk__call_message(pcmk__output_t *out, const char *message_id,...)
void(* info)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
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
Formatted output for pacemaker tools.
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)
bool(* init)(pcmk__output_t *out)
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(*) void(*) void(* output_xml)(pcmk__output_t *out, const char *name, const char *buf)
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)
xmlNodePtr pcmk__output_create_xml_node(pcmk__output_t *out, const char *name)
pcmk__output_t * pcmk__mk_xml_output(char **argv)
char * crm_strdup_printf(char const *format,...) __attribute__((__format__(__printf__
GOptionEntry pcmk__xml_output_entries[]
void(*) void(*) void(* increment_list)(pcmk__output_t *out)
char * dump_xml_formatted_with_text(xmlNode *msg)
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)