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 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/output_internal.h>
  15 
  16 static int
  17 default_list(pcmk__output_t *out, lrmd_list_t *list, const char *title) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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) {
     /* [previous][next][first][last][top][bottom][index][help] */
  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 *")
     /* [previous][next][first][last][top][bottom][index][help] */
  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 *")
     /* [previous][next][first][last][top][bottom][index][help] */
  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 *")
     /* [previous][next][first][last][top][bottom][index][help] */
  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 *")
     /* [previous][next][first][last][top][bottom][index][help] */
  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 *")
     /* [previous][next][first][last][top][bottom][index][help] */
  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 *")
     /* [previous][next][first][last][top][bottom][index][help] */
 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 *")
     /* [previous][next][first][last][top][bottom][index][help] */
 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
 144 lrmd__register_messages(pcmk__output_t *out) {
     /* [previous][next][first][last][top][bottom][index][help] */
 145     pcmk__register_messages(out, fmt_functions);
 146 }

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