pacemaker  2.1.9-49aab99839
Scalable High-Availability cluster resource manager
lrmd_output.c
Go to the documentation of this file.
1 /*
2  * Copyright 2020-2024 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>
14 #include <crm/common/xml.h>
16 
17 static int
18 default_list(pcmk__output_t *out, lrmd_list_t *list, const char *title) {
19  lrmd_list_t *iter = NULL;
20 
21  out->begin_list(out, NULL, NULL, "%s", title);
22 
23  for (iter = list; iter != NULL; iter = iter->next) {
24  out->list_item(out, NULL, "%s", iter->val);
25  }
26 
27  out->end_list(out);
28  lrmd_list_freeall(list);
29  return pcmk_rc_ok;
30 }
31 
32 static int
33 xml_list(pcmk__output_t *out, lrmd_list_t *list, const char *ele) {
34  lrmd_list_t *iter = NULL;
35 
36  for (iter = list; iter != NULL; iter = iter->next) {
37  pcmk__output_create_xml_text_node(out, ele, iter->val);
38  }
39 
40  lrmd_list_freeall(list);
41  return pcmk_rc_ok;
42 }
43 
44 PCMK__OUTPUT_ARGS("alternatives-list", "lrmd_list_t *", "const char *")
45 static int
46 lrmd__alternatives_list_xml(pcmk__output_t *out, va_list args) {
47  lrmd_list_t *list = va_arg(args, lrmd_list_t *);
48  const char *agent_spec = va_arg(args, const char *);
49 
50  int rc = pcmk_rc_ok;
51 
53  PCMK_XA_FOR, agent_spec,
54  NULL);
55  rc = xml_list(out, list, PCMK_XE_PROVIDER);
57  return rc;
58 }
59 
60 PCMK__OUTPUT_ARGS("alternatives-list", "lrmd_list_t *", "const char *")
61 static int
62 lrmd__alternatives_list(pcmk__output_t *out, va_list args) {
63  lrmd_list_t *list = va_arg(args, lrmd_list_t *);
64  const char *agent_spec G_GNUC_UNUSED = va_arg(args, const char *);
65 
66  return default_list(out, list, "Providers");
67 }
68 
69 PCMK__OUTPUT_ARGS("agents-list", "lrmd_list_t *", "const char *", "const char *")
70 static int
71 lrmd__agents_list_xml(pcmk__output_t *out, va_list args) {
72  lrmd_list_t *list = va_arg(args, lrmd_list_t *);
73  const char *agent_spec = va_arg(args, const char *);
74  const char *provider = va_arg(args, const char *);
75 
76  int rc = pcmk_rc_ok;
77  xmlNodePtr node = NULL;
78 
80  PCMK_XA_STANDARD, agent_spec,
81  NULL);
82 
83  if (!pcmk__str_empty(provider)) {
84  crm_xml_add(node, PCMK_XA_PROVIDER, provider);
85  }
86 
87  rc = xml_list(out, list, PCMK_XE_AGENT);
89  return rc;
90 }
91 
92 PCMK__OUTPUT_ARGS("agents-list", "lrmd_list_t *", "const char *", "const char *")
93 static int
94 lrmd__agents_list(pcmk__output_t *out, va_list args) {
95  lrmd_list_t *list = va_arg(args, lrmd_list_t *);
96  const char *agent_spec = va_arg(args, const char *);
97  const char *provider = va_arg(args, const char *);
98 
99  int rc;
100  char *title = crm_strdup_printf("%s agents", pcmk__str_empty(provider) ? agent_spec : provider);
101 
102  rc = default_list(out, list, title);
103  free(title);
104  return rc;
105 }
106 
107 PCMK__OUTPUT_ARGS("providers-list", "lrmd_list_t *", "const char *")
108 static int
109 lrmd__providers_list_xml(pcmk__output_t *out, va_list args) {
110  lrmd_list_t *list = va_arg(args, lrmd_list_t *);
111  const char *agent_spec = va_arg(args, const char *);
112 
113  int rc = pcmk_rc_ok;
114  xmlNodePtr node = pcmk__output_xml_create_parent(out, PCMK_XE_PROVIDERS,
115  PCMK_XA_STANDARD, "ocf",
116  NULL);
117 
118  if (agent_spec != NULL) {
119  crm_xml_add(node, PCMK_XA_AGENT, agent_spec);
120  }
121 
122  rc = xml_list(out, list, PCMK_XE_PROVIDER);
124  return rc;
125 }
126 
127 PCMK__OUTPUT_ARGS("providers-list", "lrmd_list_t *", "const char *")
128 static int
129 lrmd__providers_list(pcmk__output_t *out, va_list args) {
130  lrmd_list_t *list = va_arg(args, lrmd_list_t *);
131  const char *agent_spec G_GNUC_UNUSED = va_arg(args, const char *);
132 
133  return default_list(out, list, "Providers");
134 }
135 
136 PCMK__OUTPUT_ARGS("standards-list", "lrmd_list_t *")
137 static int
138 lrmd__standards_list(pcmk__output_t *out, va_list args) {
139  lrmd_list_t *list = va_arg(args, lrmd_list_t *);
140 
141  return default_list(out, list, "Standards");
142 }
143 
144 static pcmk__message_entry_t fmt_functions[] = {
145  { "alternatives-list", "default", lrmd__alternatives_list },
146  { "alternatives-list", "xml", lrmd__alternatives_list_xml },
147  { "agents-list", "default", lrmd__agents_list },
148  { "agents-list", "xml", lrmd__agents_list_xml },
149  { "providers-list", "default", lrmd__providers_list },
150  { "providers-list", "xml", lrmd__providers_list_xml },
151  { "standards-list", "default", lrmd__standards_list },
152 
153  { NULL, NULL, NULL }
154 };
155 
156 void
158  pcmk__register_messages(out, fmt_functions);
159 }
void(* end_list)(pcmk__output_t *out)
void pcmk__register_messages(pcmk__output_t *out, const pcmk__message_entry_t *table)
Definition: output.c:204
void lrmd__register_messages(pcmk__output_t *out)
Definition: lrmd_output.c:157
void lrmd_list_freeall(lrmd_list_t *head)
Definition: lrmd_client.c:137
xmlNodePtr pcmk__output_xml_create_parent(pcmk__output_t *out, const char *name,...) G_GNUC_NULL_TERMINATED
Definition: output_xml.c:478
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:313
#define PCMK_XA_PROVIDER
Definition: xml_names.h:364
#define PCMK_XE_PROVIDERS
Definition: xml_names.h:167
const char * val
Definition: lrmd.h:190
#define PCMK_XA_AGENT
Definition: xml_names.h:234
Formatted output for pacemaker tools.
#define PCMK_XE_PROVIDER
Definition: xml_names.h:166
struct lrmd_list_s * next
Definition: lrmd.h:191
#define PCMK__OUTPUT_ARGS(ARGS...)
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
Wrappers for and extensions to libxml2.
void pcmk__output_xml_pop_parent(pcmk__output_t *out)
Definition: output_xml.c:562
#define PCMK_XA_FOR
Definition: xml_names.h:290
#define PCMK_XA_STANDARD
Definition: xml_names.h:405
void(*) void(* list_item)(pcmk__output_t *out, const char *name, const char *format,...) G_GNUC_PRINTF(3
This structure contains everything that makes up a single output formatter.
void(* begin_list)(pcmk__output_t *out, const char *singular_noun, const char *plural_noun, const char *format,...) G_GNUC_PRINTF(4
#define PCMK_XE_AGENT
Definition: xml_names.h:62
xmlNodePtr pcmk__output_create_xml_text_node(pcmk__output_t *out, const char *name, const char *content)
Definition: output_xml.c:536
#define PCMK_XE_AGENTS
Definition: xml_names.h:64