14 #include <libxml/tree.h> 18 static GHashTable *formatters = NULL;
20 #if defined(PCMK__UNIT_TESTING) 23 pcmk__output_formatters(
void) {
64 const char *filename,
char **argv)
73 if (fmt_name == NULL) {
74 create = g_hash_table_lookup(formatters,
"text");
76 create = g_hash_table_lookup(formatters, fmt_name);
89 (*out)->dest = stdout;
91 (*out)->dest = fopen(filename,
"w");
92 if ((*out)->dest == NULL) {
99 (*out)->
quiet =
false;
102 if ((*out)->init(*out) ==
false) {
107 setenv(
"OCF_OUTPUT_FORMAT", (*out)->fmt_name, 1);
114 const char *filename,
char **argv)
129 const GOptionEntry *options)
131 char *name_copy = NULL;
135 name_copy = strdup(
name);
136 if (name_copy == NULL) {
140 if (formatters == NULL) {
144 if (options != NULL && group != NULL) {
145 g_option_group_add_entries(group, options);
148 g_hash_table_insert(formatters, name_copy, create);
156 if (formats == NULL) {
167 if (formatters != NULL) {
168 g_hash_table_destroy(formatters);
179 pcmk__assert((out != NULL) && !pcmk__str_empty(message_id));
181 fn = g_hash_table_lookup(out->
messages, message_id);
183 crm_debug(
"Called unknown output message '%s' for format '%s'",
188 va_start(args, message_id);
199 pcmk__assert((out != NULL) && !pcmk__str_empty(message_id) && (fn != NULL));
217 if (error == NULL || *error == NULL) {
222 out->
err(out,
"%s: %s", g_get_prgname(), (*error)->
message);
224 fprintf(stderr,
"%s: %s\n", g_get_prgname(), (*error)->message);
227 g_clear_error(error);
278 out->
finish(out, exit_status, FALSE, (
void **) xml);
294 const char* argv[] = {
"", NULL };
303 crm_err(
"Can't log certain messages due to internal error: %s",
323 const char* argv[] = {
"", NULL };
332 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
G_GNUC_INTERNAL void pcmk__register_option_messages(pcmk__output_t *out)
enum crm_exit_e crm_exit_t
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.
void pcmk__xml_output_finish(pcmk__output_t *out, crm_exit_t exit_status, xmlNodePtr *xml)
#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)
void free_xml(xmlNode *child)
int pcmk__call_message(pcmk__output_t *out, const char *message_id,...)
#define pcmk__str_copy(str)
int pcmk__bare_output_new(pcmk__output_t **out, const char *fmt_name, const char *filename, char **argv)
#define pcmk__assert(expr)
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)