pacemaker  2.1.4-dc6eb4362
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.20"
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 
67 typedef int (*pcmk__message_fn_t)(pcmk__output_t *out, va_list args);
68 
90 typedef struct pcmk__message_entry_s {
97  const char *message_id;
98 
107  const char *fmt_name;
108 
115 
121 typedef struct pcmk__supported_format_s {
126  const char *name;
127 
132 
137  GOptionEntry *options;
139 
140 /* The following three blocks need to be updated each time a new base formatter
141  * is added.
142  */
143 
144 extern GOptionEntry pcmk__html_output_entries[];
145 extern GOptionEntry pcmk__log_output_entries[];
146 extern GOptionEntry pcmk__none_output_entries[];
147 extern GOptionEntry pcmk__text_output_entries[];
148 extern GOptionEntry pcmk__xml_output_entries[];
149 
151 pcmk__output_t *pcmk__mk_log_output(char **argv);
154 pcmk__output_t *pcmk__mk_xml_output(char **argv);
155 
156 #define PCMK__SUPPORTED_FORMAT_HTML { "html", pcmk__mk_html_output, pcmk__html_output_entries }
157 #define PCMK__SUPPORTED_FORMAT_LOG { "log", pcmk__mk_log_output, pcmk__log_output_entries }
158 #define PCMK__SUPPORTED_FORMAT_NONE { PCMK__VALUE_NONE, pcmk__mk_none_output, \
159  pcmk__none_output_entries }
160 #define PCMK__SUPPORTED_FORMAT_TEXT { "text", pcmk__mk_text_output, pcmk__text_output_entries }
161 #define PCMK__SUPPORTED_FORMAT_XML { "xml", pcmk__mk_xml_output, pcmk__xml_output_entries }
162 
175  const char *fmt_name;
176 
185  bool quiet;
186 
193  gchar *request;
194 
201  FILE *dest;
202 
209  GHashTable *messages;
210 
218  void *priv;
219 
234  bool (*init) (pcmk__output_t *out);
235 
245  void (*free_priv) (pcmk__output_t *out);
246 
281  void (*finish) (pcmk__output_t *out, crm_exit_t exit_status, bool print,
282  void **copy_dest);
283 
299  void (*reset) (pcmk__output_t *out);
300 
312  void (*register_message) (pcmk__output_t *out, const char *message_id,
313  pcmk__message_fn_t fn);
314 
330  int (*message) (pcmk__output_t *out, const char *message_id, ...);
331 
341  void (*subprocess_output) (pcmk__output_t *out, int exit_status,
342  const char *proc_stdout, const char *proc_stderr);
343 
352  void (*version) (pcmk__output_t *out, bool extended);
353 
371  int (*info) (pcmk__output_t *out, const char *format, ...) G_GNUC_PRINTF(2, 3);
372 
385  void (*err) (pcmk__output_t *out, const char *format, ...) G_GNUC_PRINTF(2, 3);
386 
395  void (*output_xml) (pcmk__output_t *out, const char *name, const char *buf);
396 
416  void (*begin_list) (pcmk__output_t *out, const char *singular_noun,
417  const char *plural_noun, const char *format, ...)
418  G_GNUC_PRINTF(4, 5);
419 
429  void (*list_item) (pcmk__output_t *out, const char *name, const char *format, ...)
430  G_GNUC_PRINTF(3, 4);
431 
445 
456  void (*end_list) (pcmk__output_t *out);
457 
469  bool (*is_quiet) (pcmk__output_t *out);
470 
477  void (*spacer) (pcmk__output_t *out);
478 
489  void (*progress) (pcmk__output_t *out, bool end);
490 
507  void (*prompt) (const char *prompt, bool echo, char **dest);
508 };
509 
522 int
523 pcmk__call_message(pcmk__output_t *out, const char *message_id, ...);
524 
538 
553 int pcmk__output_new(pcmk__output_t **out, const char *fmt_name,
554  const char *filename, char **argv);
555 
572 int
573 pcmk__register_format(GOptionGroup *group, const char *name,
574  pcmk__output_factory_t create, GOptionEntry *options);
575 
587 void
588 pcmk__register_formats(GOptionGroup *group, pcmk__supported_format_t *table);
589 
595 void
597 
609 void
610 pcmk__register_message(pcmk__output_t *out, const char *message_id,
611  pcmk__message_fn_t fn);
612 
624 void
626 
627 /* Functions that are useful for implementing custom message formatters */
628 
639 void
640 pcmk__indented_printf(pcmk__output_t *out, const char *format, ...) G_GNUC_PRINTF(2, 3);
641 
654 void
655 pcmk__indented_vprintf(pcmk__output_t *out, const char *format, va_list args) G_GNUC_PRINTF(2, 0);
656 
657 
667 void
668 pcmk__formatted_printf(pcmk__output_t *out, const char *format, ...) G_GNUC_PRINTF(2, 3);
669 
682 void
683 pcmk__formatted_vprintf(pcmk__output_t *out, const char *format, va_list args) G_GNUC_PRINTF(2, 0);
684 
694 void
695 pcmk__text_prompt(const char *prompt, bool echo, char **dest);
696 
709 void
710 pcmk__output_set_log_level(pcmk__output_t *out, int log_level);
711 
723 xmlNodePtr
724 pcmk__output_xml_create_parent(pcmk__output_t *out, const char *name, ...)
725 G_GNUC_NULL_TERMINATED;
726 
735 void
736 pcmk__output_xml_add_node(pcmk__output_t *out, xmlNodePtr node);
737 
747 xmlNodePtr
748 pcmk__output_create_xml_node(pcmk__output_t *out, const char *name, ...)
749 G_GNUC_NULL_TERMINATED;
750 
760 xmlNodePtr
761 pcmk__output_create_xml_text_node(pcmk__output_t *out, const char *name, const char *content);
762 
777 void
778 pcmk__output_xml_push_parent(pcmk__output_t *out, xmlNodePtr node);
779 
794 void
796 
811 xmlNodePtr
813 
827 xmlNodePtr
828 pcmk__output_create_html_node(pcmk__output_t *out, const char *element_name, const char *id,
829  const char *class_name, const char *text);
830 
846 void
847 pcmk__html_add_header(const char *name, ...)
848 G_GNUC_NULL_TERMINATED;
849 
859 void pcmk__output_and_clear_error(GError *error, pcmk__output_t *out);
860 
861 #define PCMK__OUTPUT_SPACER_IF(out_obj, cond) \
862  if (cond) { \
863  out->spacer(out); \
864  }
865 
866 #define PCMK__OUTPUT_LIST_HEADER(out_obj, cond, retcode, title...) \
867  if (retcode == pcmk_rc_no_output) { \
868  PCMK__OUTPUT_SPACER_IF(out_obj, cond); \
869  retcode = pcmk_rc_ok; \
870  out_obj->begin_list(out_obj, NULL, NULL, title); \
871  }
872 
873 #define PCMK__OUTPUT_LIST_FOOTER(out_obj, retcode) \
874  if (retcode == pcmk_rc_ok) { \
875  out_obj->end_list(out_obj); \
876  }
877 
878 #ifdef __cplusplus
879 }
880 #endif
881 
882 #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
pcmk__output_t * pcmk__mk_text_output(char **argv)
Definition: output_text.c:288
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__output_and_clear_error(GError *error, pcmk__output_t *out)
Definition: output.c:156
void void void void void pcmk__text_prompt(const char *prompt, bool echo, char **dest)
Definition: output_text.c:390
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:444
void pcmk__output_set_log_level(pcmk__output_t *out, int log_level)
Definition: output_log.c:304
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:433
void pcmk__register_message(pcmk__output_t *out, const char *message_id, pcmk__message_fn_t fn)
Definition: output.c:139
struct pcmk__message_entry_s pcmk__message_entry_t
pcmk__output_t * pcmk__mk_html_output(char **argv)
Definition: output_html.c:386
xmlNodePtr pcmk__output_xml_peek_parent(pcmk__output_t *out)
Definition: output_xml.c:528
void pcmk__output_xml_add_node(pcmk__output_t *out, xmlNodePtr node)
Definition: output_xml.c:450
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:424
void pcmk__register_formats(GOptionGroup *group, pcmk__supported_format_t *table)
Definition: output.c:99
GOptionEntry pcmk__html_output_entries[]
Definition: output_html.c:43
pcmk__output_t * pcmk__mk_log_output(char **argv)
Definition: output_log.c:267
GOptionEntry pcmk__xml_output_entries[]
Definition: output_xml.c:24
int pcmk__call_message(pcmk__output_t *out, const char *message_id,...)
Definition: output.c:119
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(* register_message)(pcmk__output_t *out, const char *message_id, pcmk__message_fn_t fn)
void pcmk__output_xml_push_parent(pcmk__output_t *out, xmlNodePtr node)
Definition: output_xml.c:496
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:115
const char * fmt_name
The format type this handler is for.
bool quiet
Should this formatter supress most output?
int pcmk__register_format(GOptionGroup *group, const char *name, pcmk__output_factory_t create, GOptionEntry *options)
Definition: output.c:80
void(* free_priv)(pcmk__output_t *out)
bool(* init)(pcmk__output_t *out)
GOptionEntry pcmk__log_output_entries[]
Definition: output_log.c:17
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:466
pcmk__output_factory_t create
A function that creates a pcmk__output_t.
void pcmk__output_xml_pop_parent(pcmk__output_t *out)
Definition: output_xml.c:512
Function and executable result codes.
pcmk__output_t * pcmk__mk_xml_output(char **argv)
Definition: output_xml.c:395
FILE * dest
Where output should be written.
void pcmk__output_free(pcmk__output_t *out)
Definition: output.c:19
void pcmk__unregister_formats(void)
Definition: output.c:112
GOptionEntry pcmk__text_output_entries[]
Definition: output_text.c:19
GOptionEntry pcmk__none_output_entries[]
Definition: output_none.c:17
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__register_messages(pcmk__output_t *out, pcmk__message_entry_t *table)
Definition: output.c:145
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:31
void(* progress)(pcmk__output_t *out, bool end)
xmlNodePtr pcmk__output_create_xml_text_node(pcmk__output_t *out, const char *name, const char *content)
Definition: output_xml.c:485
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)
struct pcmk__supported_format_s pcmk__supported_format_t