pacemaker  2.1.0-7c3f660
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
lrmd_output.c
Go to the documentation of this file.
1 /*
2  * Copyright 2020 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 #include <crm_internal.h>
11 #include <stdarg.h>
12 
13 #include <crm/lrmd_internal.h>
15 
16 static int
17 default_list(pcmk__output_t *out, lrmd_list_t *list, const char *title) {
18  lrmd_list_t *iter = NULL;
19 
20  out->begin_list(out, NULL, NULL, "%s", title);
21 
22  for (iter = list; iter != NULL; iter = iter->next) {
23  out->list_item(out, NULL, "%s", iter->val);
24  }
25 
26  out->end_list(out);
27  lrmd_list_freeall(list);
28  return pcmk_rc_ok;
29 }
30 
31 static int
32 xml_list(pcmk__output_t *out, lrmd_list_t *list, const char *ele) {
33  lrmd_list_t *iter = NULL;
34 
35  for (iter = list; iter != NULL; iter = iter->next) {
36  pcmk__output_create_xml_text_node(out, ele, iter->val);
37  }
38 
39  lrmd_list_freeall(list);
40  return pcmk_rc_ok;
41 }
42 
43 PCMK__OUTPUT_ARGS("alternatives-list", "lrmd_list_t *", "const char *")
44 static int
45 lrmd__alternatives_list_xml(pcmk__output_t *out, va_list args) {
46  lrmd_list_t *list = va_arg(args, lrmd_list_t *);
47  const char *agent_spec = va_arg(args, const char *);
48 
49  pcmk__output_xml_create_parent(out, "providers",
50  "for", agent_spec,
51  NULL);
52  return xml_list(out, list, "provider");
53 }
54 
55 PCMK__OUTPUT_ARGS("alternatives-list", "lrmd_list_t *", "const char *")
56 static int
57 lrmd__alternatives_list(pcmk__output_t *out, va_list args) {
58  lrmd_list_t *list = va_arg(args, lrmd_list_t *);
59  const char *agent_spec G_GNUC_UNUSED = va_arg(args, const char *);
60 
61  return default_list(out, list, "Providers");
62 }
63 
64 PCMK__OUTPUT_ARGS("agents-list", "lrmd_list_t *", "const char *", "char *")
65 static int
66 lrmd__agents_list_xml(pcmk__output_t *out, va_list args) {
67  lrmd_list_t *list = va_arg(args, lrmd_list_t *);
68  const char *agent_spec = va_arg(args, const char *);
69  char *provider = va_arg(args, char *);
70 
71  xmlNodePtr node = pcmk__output_xml_create_parent(out, "agents",
72  "standard", agent_spec,
73  NULL);
74 
75  if (!pcmk__str_empty(provider)) {
76  crm_xml_add(node, "provider", provider);
77  }
78 
79  return xml_list(out, list, "agent");
80 }
81 
82 PCMK__OUTPUT_ARGS("agents-list", "lrmd_list_t *", "const char *", "char *")
83 static int
84 lrmd__agents_list(pcmk__output_t *out, va_list args) {
85  lrmd_list_t *list = va_arg(args, lrmd_list_t *);
86  const char *agent_spec = va_arg(args, const char *);
87  char *provider = va_arg(args, char *);
88 
89  int rc;
90  char *title = crm_strdup_printf("%s agents", pcmk__str_empty(provider) ? agent_spec : provider);
91 
92  rc = default_list(out, list, title);
93  free(title);
94  return rc;
95 }
96 
97 PCMK__OUTPUT_ARGS("providers-list", "lrmd_list_t *", "const char *")
98 static int
99 lrmd__providers_list_xml(pcmk__output_t *out, va_list args) {
100  lrmd_list_t *list = va_arg(args, lrmd_list_t *);
101  const char *agent_spec = va_arg(args, const char *);
102 
103  xmlNodePtr node = pcmk__output_xml_create_parent(out, "providers",
104  "standard", "ocf",
105  NULL);
106 
107  if (agent_spec != NULL) {
108  crm_xml_add(node, "agent", agent_spec);
109  }
110 
111  return xml_list(out, list, "provider");
112 }
113 
114 PCMK__OUTPUT_ARGS("providers-list", "lrmd_list_t *", "const char *")
115 static int
116 lrmd__providers_list(pcmk__output_t *out, va_list args) {
117  lrmd_list_t *list = va_arg(args, lrmd_list_t *);
118  const char *agent_spec G_GNUC_UNUSED = va_arg(args, const char *);
119 
120  return default_list(out, list, "Providers");
121 }
122 
123 PCMK__OUTPUT_ARGS("standards-list", "lrmd_list_t *")
124 static int
125 lrmd__standards_list(pcmk__output_t *out, va_list args) {
126  lrmd_list_t *list = va_arg(args, lrmd_list_t *);
127 
128  return default_list(out, list, "Standards");
129 }
130 
131 static pcmk__message_entry_t fmt_functions[] = {
132  { "alternatives-list", "default", lrmd__alternatives_list },
133  { "alternatives-list", "xml", lrmd__alternatives_list_xml },
134  { "agents-list", "default", lrmd__agents_list },
135  { "agents-list", "xml", lrmd__agents_list_xml },
136  { "providers-list", "default", lrmd__providers_list },
137  { "providers-list", "xml", lrmd__providers_list_xml },
138  { "standards-list", "default", lrmd__standards_list },
139 
140  { NULL, NULL, NULL }
141 };
142 
143 void
145  pcmk__register_messages(out, fmt_functions);
146 }
void lrmd_list_freeall(lrmd_list_t *head)
Definition: lrmd_client.c:130
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
Definition: nvpair.c:324
const char * val
Definition: lrmd.h:279
void(* end_list)(pcmk__output_t *out)
Formatted output for pacemaker tools.
int rc
Definition: pcmk_fence.c:35
void(* begin_list)(pcmk__output_t *out, const char *singular_noun, const char *plural_noun, const char *format,...) G_GNUC_PRINTF(4
struct lrmd_list_s * next
Definition: lrmd.h:280
#define PCMK__OUTPUT_ARGS(ARGS...)
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
void lrmd__register_messages(pcmk__output_t *out)
Definition: lrmd_output.c:144
This structure contains everything that makes up a single output formatter.
void pcmk__register_messages(pcmk__output_t *out, pcmk__message_entry_t *table)
Definition: output.c:143
xmlNodePtr pcmk__output_create_xml_text_node(pcmk__output_t *out, const char *name, const char *content)
Definition: output_xml.c:484
xmlNodePtr pcmk__output_xml_create_parent(pcmk__output_t *out, const char *name,...)
Definition: output_xml.c:432
void(*) void(* list_item)(pcmk__output_t *out, const char *name, const char *format,...) G_GNUC_PRINTF(3