14 #include <libxml/tree.h>
16 static GHashTable *formatters = NULL;
35 if (formatters == NULL) {
42 if (fmt_name == NULL) {
43 create = g_hash_table_lookup(formatters,
"text");
45 create = g_hash_table_lookup(formatters, fmt_name);
58 (*out)->dest = stdout;
60 (*out)->dest = fopen(filename,
"w");
61 if ((*out)->dest == NULL) {
66 (*out)->quiet =
false;
69 if ((*out)->init(*out) ==
false) {
84 if (formatters == NULL) {
88 if (options != NULL && group != NULL) {
89 g_option_group_add_entries(group, options);
92 g_hash_table_insert(formatters, strdup(name), create);
100 if (formats == NULL) {
104 for (entry = formats; entry->
name != NULL; entry++) {
111 if (formatters != NULL) {
112 g_hash_table_destroy(formatters);
122 fn = g_hash_table_lookup(out->
messages, message_id);
124 crm_debug(
"Called unknown output message '%s' for format '%s'",
129 va_start(args, message_id);
139 g_hash_table_replace(out->
messages, strdup(message_id), fn);
146 for (entry = table; entry->
message_id != NULL; entry++) {
161 out->
err(out,
"%s: %s", g_get_prgname(), error->
message);
163 fprintf(stderr,
"%s: %s\n", g_get_prgname(), error->message);
166 g_clear_error(&error);
pcmk__output_t *(* pcmk__output_factory_t)(char **argv)
pcmk__message_fn_t fn
The function to be called for message_id given a match on fmt_name. See comments on pcmk__message_fn_...
void pcmk__output_and_clear_error(GError *error, pcmk__output_t *out)
bool pcmk__strcase_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
const char * fmt_name
The name of this output formatter.
void pcmk__register_message(pcmk__output_t *out, const char *message_id, pcmk__message_fn_t fn)
int(* message)(pcmk__output_t *out, const char *message_id,...)
int(*) void(* err)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
void pcmk__register_formats(GOptionGroup *group, pcmk__supported_format_t *table)
int pcmk__call_message(pcmk__output_t *out, const char *message_id,...)
GHashTable * messages
Custom messages that are currently registered on this formatter.
#define crm_debug(fmt, args...)
const char * fmt_name
The format type this handler is for.
int pcmk__register_format(GOptionGroup *group, const char *name, pcmk__output_factory_t create, GOptionEntry *options)
int(* pcmk__message_fn_t)(pcmk__output_t *out, va_list args)
Wrappers for and extensions to libxml2.
void pcmk__output_free(pcmk__output_t *out)
void pcmk__unregister_formats(void)
GHashTable * pcmk__strkey_table(GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func)
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 pcmk__register_messages(pcmk__output_t *out, pcmk__message_entry_t *table)
int pcmk__output_new(pcmk__output_t **out, const char *fmt_name, const char *filename, char **argv)
const char * message_id
The message to be handled.