14 #include <libxml/tree.h> 16 static GHashTable *formatters = NULL;
18 #if defined(PCMK__UNIT_TESTING) 20 pcmk__output_formatters(
void) {
51 if (fmt_name == NULL) {
52 create = g_hash_table_lookup(formatters,
"text");
54 create = g_hash_table_lookup(formatters, fmt_name);
67 (*out)->dest = stdout;
69 (*out)->dest = fopen(filename,
"w");
70 if ((*out)->dest == NULL) {
77 (*out)->
quiet =
false;
80 if ((*out)->init(*out) ==
false) {
85 setenv(
"OCF_OUTPUT_FORMAT", (*out)->fmt_name, 1);
93 const GOptionEntry *options)
97 if (formatters == NULL) {
101 if (options != NULL && group != NULL) {
102 g_option_group_add_entries(group, options);
105 g_hash_table_insert(formatters, strdup(
name), create);
113 if (formats == NULL) {
124 if (formatters != NULL) {
125 g_hash_table_destroy(formatters);
136 CRM_ASSERT(out != NULL && !pcmk__str_empty(message_id));
138 fn = g_hash_table_lookup(out->
messages, message_id);
140 crm_debug(
"Called unknown output message '%s' for format '%s'",
145 va_start(args, message_id);
155 CRM_ASSERT(out != NULL && !pcmk__str_empty(message_id) && fn != NULL);
157 g_hash_table_replace(out->
messages, strdup(message_id), fn);
179 out->
err(out,
"%s: %s", g_get_prgname(), error->
message);
181 fprintf(stderr,
"%s: %s\n", g_get_prgname(), error->message);
184 g_clear_error(&error);
224 out->
finish(out, 0, FALSE, (
void **) xml);
240 const char* argv[] = {
"", NULL };
249 crm_err(
"Can't log certain messages due to internal error: %s",
int(* pcmk__message_fn_t)(pcmk__output_t *out, va_list args)
void pcmk__output_and_clear_error(GError *error, pcmk__output_t *out)
#define PCMK__SUPPORTED_FORMAT_LOG
bool pcmk__strcase_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
int(* message)(pcmk__output_t *out, const char *message_id,...)
#define PCMK__SUPPORTED_FORMAT_XML
const char * fmt_name
The name of this output formatter.
void pcmk__xml_output_finish(pcmk__output_t *out, xmlNodePtr *xml)
const char * pcmk_rc_str(int rc)
Get a user-friendly description of a return code.
void pcmk__register_formats(GOptionGroup *group, const pcmk__supported_format_t *formats)
GHashTable * messages
Custom messages that are currently registered on this formatter.
#define crm_debug(fmt, args...)
bool quiet
Should this formatter supress most output?
int setenv(const char *name, const char *value, int why)
void pcmk__register_messages(pcmk__output_t *out, const pcmk__message_entry_t *table)
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.
void(* finish)(pcmk__output_t *out, crm_exit_t exit_status, bool print, void **copy_dest)
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()
int pcmk__xml_output_new(pcmk__output_t **out, xmlNodePtr *xml)
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)
#define crm_err(fmt, args...)
gchar * request
A copy of the request that generated this output.
int pcmk__log_output_new(pcmk__output_t **out)
This structure contains everything that makes up a single output formatter.
const char * message_id
The message to be handled.
int pcmk__register_format(GOptionGroup *group, const char *name, pcmk__output_factory_t create, const GOptionEntry *options)