14 #include <libxml/tree.h> 18 static GHashTable *formatters = NULL;
20 #if defined(PCMK__UNIT_TESTING) 22 pcmk__output_formatters(
void) {
62 const char *filename,
char **argv)
71 if (fmt_name == NULL) {
72 create = g_hash_table_lookup(formatters,
"text");
74 create = g_hash_table_lookup(formatters, fmt_name);
87 (*out)->dest = stdout;
89 (*out)->dest = fopen(filename,
"w");
90 if ((*out)->dest == NULL) {
97 (*out)->
quiet =
false;
100 if ((*out)->init(*out) ==
false) {
105 setenv(
"OCF_OUTPUT_FORMAT", (*out)->fmt_name, 1);
112 const char *filename,
char **argv)
128 const GOptionEntry *options)
132 if (formatters == NULL) {
136 if (options != NULL && group != NULL) {
137 g_option_group_add_entries(group, options);
140 g_hash_table_insert(formatters, strdup(
name), create);
148 if (formats == NULL) {
159 if (formatters != NULL) {
160 g_hash_table_destroy(formatters);
171 CRM_ASSERT(out != NULL && !pcmk__str_empty(message_id));
173 fn = g_hash_table_lookup(out->
messages, message_id);
175 crm_debug(
"Called unknown output message '%s' for format '%s'",
180 va_start(args, message_id);
190 CRM_ASSERT(out != NULL && !pcmk__str_empty(message_id) && fn != NULL);
192 g_hash_table_replace(out->
messages, strdup(message_id), fn);
209 if (error == NULL || *error == NULL) {
214 out->
err(out,
"%s: %s", g_get_prgname(), (*error)->
message);
216 fprintf(stderr,
"%s: %s\n", g_get_prgname(), (*error)->message);
219 g_clear_error(error);
259 out->
finish(out, 0, FALSE, (
void **) xml);
275 const char* argv[] = {
"", NULL };
284 crm_err(
"Can't log certain messages due to internal error: %s",
304 const char* argv[] = {
"", NULL };
313 crm_err(
"Can't create text output object to internal error: %s",
int(* pcmk__message_fn_t)(pcmk__output_t *out, va_list args)
#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
void pcmk__unregister_formats(void)
const char * fmt_name
The name of this output formatter.
#define PCMK__SUPPORTED_FORMAT_TEXT
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?
void pcmk__register_messages(pcmk__output_t *out, const pcmk__message_entry_t *table)
void(* free_priv)(pcmk__output_t *out)
int(*) 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,...)
int pcmk__bare_output_new(pcmk__output_t **out, const char *fmt_name, const char *filename, char **argv)
int pcmk__text_output_new(pcmk__output_t **out, const char *filename)
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.
void pcmk__output_and_clear_error(GError **error, pcmk__output_t *out)
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)
G_GNUC_INTERNAL void pcmk__register_patchset_messages(pcmk__output_t *out)