root/lib/lrmd/lrmd_output.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. default_list
  2. xml_list
  3. PCMK__OUTPUT_ARGS
  4. PCMK__OUTPUT_ARGS
  5. PCMK__OUTPUT_ARGS
  6. PCMK__OUTPUT_ARGS
  7. PCMK__OUTPUT_ARGS
  8. PCMK__OUTPUT_ARGS
  9. PCMK__OUTPUT_ARGS
  10. lrmd__register_messages

   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>
  15 #include <crm/common/output_internal.h>
  16 
  17 static int
  18 default_list(pcmk__output_t *out, lrmd_list_t *list, const char *title) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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 *")
     /* [previous][next][first][last][top][bottom][index][help] */
  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 
  52     pcmk__output_xml_create_parent(out, PCMK_XE_PROVIDERS,
  53                                    PCMK_XA_FOR, agent_spec,
  54                                    NULL);
  55     rc = xml_list(out, list, PCMK_XE_PROVIDER);
  56     pcmk__output_xml_pop_parent(out);
  57     return rc;
  58 }
  59 
  60 PCMK__OUTPUT_ARGS("alternatives-list", "lrmd_list_t *", "const char *")
     /* [previous][next][first][last][top][bottom][index][help] */
  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 *")
     /* [previous][next][first][last][top][bottom][index][help] */
  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 
  79     node = pcmk__output_xml_create_parent(out, PCMK_XE_AGENTS,
  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);
  88     pcmk__output_xml_pop_parent(out);
  89     return rc;
  90 }
  91 
  92 PCMK__OUTPUT_ARGS("agents-list", "lrmd_list_t *", "const char *", "const char *")
     /* [previous][next][first][last][top][bottom][index][help] */
  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 *")
     /* [previous][next][first][last][top][bottom][index][help] */
 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);
 123     pcmk__output_xml_pop_parent(out);
 124     return rc;
 125 }
 126 
 127 PCMK__OUTPUT_ARGS("providers-list", "lrmd_list_t *", "const char *")
     /* [previous][next][first][last][top][bottom][index][help] */
 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 *")
     /* [previous][next][first][last][top][bottom][index][help] */
 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
 157 lrmd__register_messages(pcmk__output_t *out) {
     /* [previous][next][first][last][top][bottom][index][help] */
 158     pcmk__register_messages(out, fmt_functions);
 159 }

/* [previous][next][first][last][top][bottom][index][help] */