pacemaker  2.1.5-b7adf64e51
Scalable High-Availability cluster resource manager
output_internal.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019-2022 the Pacemaker project contributors
3  *
4  * The version control history for this file may have further details.
5  *
6  * This source code is licensed under the GNU Lesser General Public License
7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8  */
9 
10 #ifndef PCMK__OUTPUT_INTERNAL__H
11 # define PCMK__OUTPUT_INTERNAL__H
12 
13 # include <stdbool.h>
14 # include <stdio.h>
15 # include <libxml/tree.h>
16 # include <libxml/HTMLtree.h>
17 
18 # include <glib.h>
19 # include <crm/common/results.h>
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
31 # define PCMK__API_VERSION "2.25"
32 
33 #if defined(PCMK__WITH_ATTRIBUTE_OUTPUT_ARGS)
34 # define PCMK__OUTPUT_ARGS(ARGS...) __attribute__((output_args(ARGS)))
35 #else
36 # define PCMK__OUTPUT_ARGS(ARGS...)
37 #endif
38 
40 
51 typedef pcmk__output_t * (*pcmk__output_factory_t)(char **argv);
52 
70 typedef int (*pcmk__message_fn_t)(pcmk__output_t *out, va_list args);
71 
93 typedef struct pcmk__message_entry_s {
100  const char *message_id;
101 
110  const char *fmt_name;
111 
118 
124 typedef struct pcmk__supported_format_s {
129  const char *name;
130 
135 
140  GOptionEntry *options;
142 
143 /* The following three blocks need to be updated each time a new base formatter
144  * is added.
145  */
146 
147 extern GOptionEntry pcmk__html_output_entries[];
148 extern GOptionEntry pcmk__log_output_entries[];
149 extern GOptionEntry pcmk__none_output_entries[];
150 extern GOptionEntry pcmk__text_output_entries[];
151 extern GOptionEntry pcmk__xml_output_entries[];
152 
154 pcmk__output_t *pcmk__mk_log_output(char **argv);
157 pcmk__output_t *pcmk__mk_xml_output(char **argv);
158 
159 #define PCMK__SUPPORTED_FORMAT_HTML { "html", pcmk__mk_html_output, pcmk__html_output_entries }
160 #define PCMK__SUPPORTED_FORMAT_LOG { "log", pcmk__mk_log_output, pcmk__log_output_entries }
161 #define PCMK__SUPPORTED_FORMAT_NONE { PCMK__VALUE_NONE, pcmk__mk_none_output, \
162  pcmk__none_output_entries }
163 #define PCMK__SUPPORTED_FORMAT_TEXT { "text", pcmk__mk_text_output, pcmk__text_output_entries }
164 #define PCMK__SUPPORTED_FORMAT_XML { "xml", pcmk__mk_xml_output, pcmk__xml_output_entries }
165 
178  const char *fmt_name;
179 
188  bool quiet;
189 
196  gchar *request;
197 
204  FILE *dest;
205 
212  GHashTable *messages;
213 
221  void *priv;
222 
237  bool (*init) (pcmk__output_t *out);
238 
248  void (*free_priv) (pcmk__output_t *out);
249 
284  void (*finish) (pcmk__output_t *out, crm_exit_t exit_status, bool print,
285  void **copy_dest);
286 
302  void (*reset) (pcmk__output_t *out);
303 
315  void (*register_message) (pcmk__output_t *out, const char *message_id,
316  pcmk__message_fn_t fn);
317 
333  int (*message) (pcmk__output_t *out, const char *message_id, ...);
334 
344  void (*subprocess_output) (pcmk__output_t *out, int exit_status,
345  const char *proc_stdout, const char *proc_stderr);
346 
355  void (*version) (pcmk__output_t *out, bool extended);
356 
377  int (*info) (pcmk__output_t *out, const char *format, ...) G_GNUC_PRINTF(2, 3);
378 
394  void (*err) (pcmk__output_t *out, const char *format, ...) G_GNUC_PRINTF(2, 3);
395 
404  void (*output_xml) (pcmk__output_t *out, const char *name, const char *buf);
405 
425  void (*begin_list) (pcmk__output_t *out, const char *singular_noun,
426  const char *plural_noun, const char *format, ...)
427  G_GNUC_PRINTF(4, 5);
428 
438  void (*list_item) (pcmk__output_t *out, const char *name, const char *format, ...)
439  G_GNUC_PRINTF(3, 4);
440 
454 
465  void (*end_list) (pcmk__output_t *out);
466 
478  bool (*is_quiet) (pcmk__output_t *out);
479 
486  void (*spacer) (pcmk__output_t *out);
487 
498  void (*progress) (pcmk__output_t *out, bool end);
499 
516  void (*prompt) (const char *prompt, bool echo, char **dest);
517 };
518 
531 int
532 pcmk__call_message(pcmk__output_t *out, const char *message_id, ...);
533 
547 
562 int pcmk__output_new(pcmk__output_t **out, const char *fmt_name,
563  const char *filename, char **argv);
564 
581 int
582 pcmk__register_format(GOptionGroup *group, const char *name,
583  pcmk__output_factory_t create,
584  const GOptionEntry *options);
585 
597 void
598 pcmk__register_formats(GOptionGroup *group,
599  const pcmk__supported_format_t *table);
600 
606 void
608 
620 void
621 pcmk__register_message(pcmk__output_t *out, const char *message_id,
622  pcmk__message_fn_t fn);
623 
635 void
637  const pcmk__message_entry_t *table);
638 
639 /* Functions that are useful for implementing custom message formatters */
640 
656 void
657 pcmk__indented_printf(pcmk__output_t *out, const char *format, ...) G_GNUC_PRINTF(2, 3);
658 
673 void
674 pcmk__indented_vprintf(pcmk__output_t *out, const char *format, va_list args) G_GNUC_PRINTF(2, 0);
675 
676 
689 void
690 pcmk__formatted_printf(pcmk__output_t *out, const char *format, ...) G_GNUC_PRINTF(2, 3);
691 
705 void
706 pcmk__formatted_vprintf(pcmk__output_t *out, const char *format, va_list args) G_GNUC_PRINTF(2, 0);
707 
717 void
718 pcmk__text_prompt(const char *prompt, bool echo, char **dest);
719 
732 void
733 pcmk__output_set_log_level(pcmk__output_t *out, int log_level);
734 
746 xmlNodePtr
747 pcmk__output_xml_create_parent(pcmk__output_t *out, const char *name, ...)
748 G_GNUC_NULL_TERMINATED;
749 
758 void
759 pcmk__output_xml_add_node(pcmk__output_t *out, xmlNodePtr node);
760 
770 xmlNodePtr
771 pcmk__output_create_xml_node(pcmk__output_t *out, const char *name, ...)
772 G_GNUC_NULL_TERMINATED;
773 
783 xmlNodePtr
784 pcmk__output_create_xml_text_node(pcmk__output_t *out, const char *name, const char *content);
785 
800 void
802 
817 void
819 
834 xmlNodePtr
836 
850 xmlNodePtr
851 pcmk__output_create_html_node(pcmk__output_t *out, const char *element_name, const char *id,
852  const char *class_name, const char *text);
853 
869 void
870 pcmk__html_add_header(const char *name, ...)
871 G_GNUC_NULL_TERMINATED;
872 
882 void pcmk__output_and_clear_error(GError *error, pcmk__output_t *out);
883 
884 int pcmk__xml_output_new(pcmk__output_t **out, xmlNodePtr *xml);
885 void pcmk__xml_output_finish(pcmk__output_t *out, xmlNodePtr *xml);
887 
888 #if defined(PCMK__UNIT_TESTING)
889 /* If we are building libcrmcommon_test.a, add this accessor function so we can
890  * inspect the internal formatters hash table.
891  */
892 GHashTable *pcmk__output_formatters(void);
893 #endif
894 
895 #define PCMK__OUTPUT_SPACER_IF(out_obj, cond) \
896  if (cond) { \
897  out->spacer(out); \
898  }
899 
900 #define PCMK__OUTPUT_LIST_HEADER(out_obj, cond, retcode, title...) \
901  if (retcode == pcmk_rc_no_output) { \
902  PCMK__OUTPUT_SPACER_IF(out_obj, cond); \
903  retcode = pcmk_rc_ok; \
904  out_obj->begin_list(out_obj, NULL, NULL, title); \
905  }
906 
907 #define PCMK__OUTPUT_LIST_FOOTER(out_obj, retcode) \
908  if (retcode == pcmk_rc_ok) { \
909  out_obj->end_list(out_obj); \
910  }
911 
912 #ifdef __cplusplus
913 }
914 #endif
915 
916 #endif
int(* pcmk__message_fn_t)(pcmk__output_t *out, va_list args)
void(* end_list)(pcmk__output_t *out)
void void void void pcmk__formatted_vprintf(pcmk__output_t *out, const char *format, va_list args) G_GNUC_PRINTF(2
void pcmk__output_xml_push_parent(pcmk__output_t *out, xmlNodePtr parent)
Definition: output_xml.c:500
pcmk__output_t * pcmk__mk_text_output(char **argv)
Definition: output_text.c:294
void void pcmk__indented_vprintf(pcmk__output_t *out, const char *format, va_list args) G_GNUC_PRINTF(2
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__register_messages(pcmk__output_t *out, const pcmk__message_entry_t *table)
Definition: output.c:161
void pcmk__output_and_clear_error(GError *error, pcmk__output_t *out)
Definition: output.c:172
void void void void void pcmk__text_prompt(const char *prompt, bool echo, char **dest)
Definition: output_text.c:394
const char * name
Definition: cib.c:24
int(* message)(pcmk__output_t *out, const char *message_id,...)
void pcmk__html_add_header(const char *name,...) G_GNUC_NULL_TERMINATED
Definition: output_html.c:454
void pcmk__output_set_log_level(pcmk__output_t *out, int log_level)
Definition: output_log.c:309
const char * fmt_name
The name of this output formatter.
bool(* is_quiet)(pcmk__output_t *out)
void(* spacer)(pcmk__output_t *out)
xmlNodePtr pcmk__output_xml_create_parent(pcmk__output_t *out, const char *name,...) G_GNUC_NULL_TERMINATED
Definition: output_xml.c:438
void pcmk__register_message(pcmk__output_t *out, const char *message_id, pcmk__message_fn_t fn)
Definition: output.c:153
struct pcmk__message_entry_s pcmk__message_entry_t
pcmk__output_t * pcmk__mk_html_output(char **argv)
Definition: output_html.c:395
xmlNodePtr pcmk__output_xml_peek_parent(pcmk__output_t *out)
Definition: output_xml.c:526
void pcmk__output_xml_add_node(pcmk__output_t *out, xmlNodePtr node)
Definition: output_xml.c:456
int(*) void(*) void(* output_xml)(pcmk__output_t *out, const char *name, const char *buf)
enum crm_exit_e crm_exit_t
int(* info)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
xmlNodePtr pcmk__output_create_html_node(pcmk__output_t *out, const char *element_name, const char *id, const char *class_name, const char *text)
Definition: output_html.c:433
GOptionEntry pcmk__html_output_entries[]
Definition: output_html.c:44
pcmk__output_t * pcmk__mk_log_output(char **argv)
Definition: output_log.c:272
GOptionEntry pcmk__xml_output_entries[]
Definition: output_xml.c:25
int pcmk__call_message(pcmk__output_t *out, const char *message_id,...)
Definition: output.c:131
void void void pcmk__formatted_printf(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
GHashTable * messages
Custom messages that are currently registered on this formatter.
void(* prompt)(const char *prompt, bool echo, char **dest)
void * priv
Implementation-specific private data.
void pcmk__register_formats(GOptionGroup *group, const pcmk__supported_format_t *table)
Definition: output.c:110
void(* register_message)(pcmk__output_t *out, const char *message_id, pcmk__message_fn_t fn)
GOptionEntry * options
Format-specific command line options. This can be NULL if no command line options should be supported...
pcmk__output_t * pcmk__mk_none_output(char **argv)
Definition: output_none.c:116
const char * fmt_name
The format type this handler is for.
int pcmk__xml_output_new(pcmk__output_t **out, xmlNodePtr *xml)
Definition: output.c:201
bool quiet
Should this formatter supress most output?
void(* free_priv)(pcmk__output_t *out)
bool(* init)(pcmk__output_t *out)
GOptionEntry pcmk__log_output_entries[]
Definition: output_log.c:18
int(*) void(* err)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
void(* finish)(pcmk__output_t *out, crm_exit_t exit_status, bool print, void **copy_dest)
void pcmk__indented_printf(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
xmlNodePtr pcmk__output_create_xml_node(pcmk__output_t *out, const char *name,...) G_GNUC_NULL_TERMINATED
Definition: output_xml.c:469
pcmk__output_factory_t create
A function that creates a pcmk__output_t.
int pcmk__register_format(GOptionGroup *group, const char *name, pcmk__output_factory_t create, const GOptionEntry *options)
Definition: output.c:91
void pcmk__output_xml_pop_parent(pcmk__output_t *out)
Definition: output_xml.c:513
Function and executable result codes.
pcmk__output_t * pcmk__mk_xml_output(char **argv)
Definition: output_xml.c:400
FILE * dest
Where output should be written.
void pcmk__output_free(pcmk__output_t *out)
Definition: output.c:26
void pcmk__unregister_formats(void)
Definition: output.c:123
GOptionEntry pcmk__text_output_entries[]
Definition: output_text.c:20
GOptionEntry pcmk__none_output_entries[]
Definition: output_none.c:18
pcmk__output_t *(* pcmk__output_factory_t)(char **argv)
const char * name
The name of this output formatter, which should match the fmt_name parameter in some pcmk__output_t s...
void(*) void(* list_item)(pcmk__output_t *out, const char *name, const char *format,...) G_GNUC_PRINTF(3
gchar * request
A copy of the request that generated this output.
This structure contains everything that makes up a single output formatter.
void(* version)(pcmk__output_t *out, bool extended)
void(* begin_list)(pcmk__output_t *out, const char *singular_noun, const char *plural_noun, const char *format,...) G_GNUC_PRINTF(4
void pcmk__xml_output_finish(pcmk__output_t *out, xmlNodePtr *xml)
Definition: output.c:223
void(* reset)(pcmk__output_t *out)
int pcmk__output_new(pcmk__output_t **out, const char *fmt_name, const char *filename, char **argv)
Definition: output.c:42
void(* progress)(pcmk__output_t *out, bool end)
const char * parent
Definition: cib.c:25
xmlNodePtr pcmk__output_create_xml_text_node(pcmk__output_t *out, const char *name, const char *content)
Definition: output_xml.c:488
const char * message_id
The message to be handled.
void(*) void(*) void(* increment_list)(pcmk__output_t *out)
void(* subprocess_output)(pcmk__output_t *out, int exit_status, const char *proc_stdout, const char *proc_stderr)
int pcmk__log_output_new(pcmk__output_t **out)
Definition: output.c:237
struct pcmk__supported_format_s pcmk__supported_format_t