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) {
74 setenv(
"OCF_OUTPUT_FORMAT", (*out)->fmt_name, 1);
86 if (formatters == NULL) {
90 if (options != NULL && group != NULL) {
91 g_option_group_add_entries(group, options);
94 g_hash_table_insert(formatters, strdup(
name), create);
102 if (formats == NULL) {
106 for (entry = formats; entry->
name != NULL; entry++) {
113 if (formatters != NULL) {
114 g_hash_table_destroy(formatters);
124 fn = g_hash_table_lookup(out->
messages, message_id);
126 crm_debug(
"Called unknown output message '%s' for format '%s'",
131 va_start(args, message_id);
141 g_hash_table_replace(out->
messages, strdup(message_id), fn);
148 for (entry = table; entry->
message_id != NULL; entry++) {
163 out->
err(out,
"%s: %s", g_get_prgname(), error->
message);
165 fprintf(stderr,
"%s: %s\n", g_get_prgname(), error->message);
168 g_clear_error(&error);
int(* pcmk__message_fn_t)(pcmk__output_t *out, va_list args)
void pcmk__output_and_clear_error(GError *error, pcmk__output_t *out)
void pcmk__register_formats(GOptionGroup *group, pcmk__supported_format_t *formats)
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_...
bool pcmk__strcase_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
int(* message)(pcmk__output_t *out, const char *message_id,...)
const char * fmt_name
The name of this output formatter.
GHashTable * messages
Custom messages that are currently registered on this formatter.
void pcmk__register_messages(pcmk__output_t *out, pcmk__message_entry_t *table)
#define crm_debug(fmt, args...)
const char * fmt_name
The format type this handler is for.
int setenv(const char *name, const char *value, int why)
void(* free_priv)(pcmk__output_t *out)
int(*) void(* err)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
Wrappers for and extensions to libxml2.
int pcmk__output_new(pcmk__output_t **out, const char *fmt_name, const char *filename, char **argv)
int pcmk__call_message(pcmk__output_t *out, const char *message_id,...)
void pcmk__unregister_formats()
pcmk__output_t *(* pcmk__output_factory_t)(char **argv)
void pcmk__register_message(pcmk__output_t *out, const char *message_id, pcmk__message_fn_t fn)
GHashTable * pcmk__strkey_table(GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func)
void pcmk__output_free(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.
int pcmk__register_format(GOptionGroup *group, const char *name, pcmk__output_factory_t create, GOptionEntry *options)
const char * message_id
The message to be handled.