root/include/crm/common/messages_internal.h

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

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. pcmk__request_origin_type
  2. pcmk__request_origin

   1 /*
   2  * Copyright 2018-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__CRM_COMMON_MESSAGES_INTERNAL__H
  11 #define PCMK__CRM_COMMON_MESSAGES_INTERNAL__H
  12 
  13 #include <stdint.h>                         // uint32_t
  14 #include <libxml/tree.h>                    // xmlNode
  15 #include <crm/common/ipc_internal.h>        // pcmk__client_t
  16 #include <crm/common/results_internal.h>    // pcmk__action_result_t
  17 
  18 enum pcmk__request_flags {
  19     pcmk__request_none          = UINT32_C(0),
  20 
  21     /* It would be nice if we could check for synchronous requests generically,
  22      * but each daemon uses its own call options, so the daemons are responsible
  23      * for setting this flag when appropriate.
  24      */
  25     pcmk__request_sync          = (UINT32_C(1) << 0),
  26 
  27     /* Whether reply must use original call options (the library code does not
  28      * use this, so it is for internal daemon use)
  29      */
  30     pcmk__request_reuse_options = (UINT32_C(1) << 1),
  31 };
  32 
  33 // Server request (whether from an IPC client or cluster peer)
  34 typedef struct {
  35     // If request is from an IPC client
  36     pcmk__client_t *ipc_client;     // IPC client (NULL if not via IPC)
  37     uint32_t ipc_id;                // IPC message ID
  38     uint32_t ipc_flags;             // IPC message flags
  39 
  40     // If message is from a cluster peer
  41     const char *peer;       // Peer name (NULL if not via cluster)
  42 
  43     // Common information regardless of origin
  44     xmlNode *xml;                   // Request XML
  45     int call_options;               // Call options set on request
  46     uint32_t flags;                 // Flag group of pcmk__request_flags
  47     pcmk__action_result_t result;   // Where to store operation result
  48 
  49     /* It would be nice if we could pull the IPC command from the XML
  50      * generically, but each daemon uses a different XML attribute for it,
  51      * so the daemon is responsible for populating this field.
  52      *
  53      * This must be a copy of the XML field, and not just a pointer into xml,
  54      * because handlers might modify the original XML.
  55      *
  56      * @TODO Create a per-daemon struct with IPC handlers, IPC endpoints, etc.,
  57      * and the name of the XML attribute for IPC commands, then replace this
  58      * with a convenience function to copy the command.
  59      */
  60     char *op;                       // IPC command name
  61 } pcmk__request_t;
  62 
  63 #define pcmk__set_request_flags(request, flags_to_set) do {         \
  64         (request)->flags = pcmk__set_flags_as(__func__, __LINE__,   \
  65         LOG_TRACE, "Request", "message", (request)->flags,          \
  66         (flags_to_set), #flags_to_set);                             \
  67     } while (0)
  68 
  69 // Type for mapping a server command to a handler
  70 typedef struct {
  71     const char *command;
  72     xmlNode *(*handler)(pcmk__request_t *request);
  73 } pcmk__server_command_t;
  74 
  75 const char *pcmk__message_name(const char *name);
  76 GHashTable *pcmk__register_handlers(const pcmk__server_command_t handlers[]);
  77 xmlNode *pcmk__process_request(pcmk__request_t *request, GHashTable *handlers);
  78 void pcmk__reset_request(pcmk__request_t *request);
  79 
  80 /*!
  81  * \internal
  82  * \brief Get a loggable description of a request's origin
  83  *
  84  * \param[in] request
  85  *
  86  * \return "peer" if request was via CPG, "client" if via IPC, or "originator"
  87  *         if unknown
  88  */
  89 static inline const char *
  90 pcmk__request_origin_type(const pcmk__request_t *request)
     /* [previous][next][first][last][top][bottom][index][help] */
  91 {
  92     if ((request != NULL) && (request->ipc_client != NULL)) {
  93         return "client";
  94     } else if ((request != NULL) && (request->peer != NULL)) {
  95         return "peer";
  96     } else {
  97         return "originator";
  98     }
  99 }
 100 
 101 /*!
 102  * \internal
 103  * \brief Get a loggable name for a request's origin
 104  *
 105  * \param[in] request
 106  *
 107  * \return Peer name if request was via CPG, client name if via IPC, or
 108  *         "(unspecified)" if unknown
 109  */
 110 static inline const char *
 111 pcmk__request_origin(const pcmk__request_t *request)
     /* [previous][next][first][last][top][bottom][index][help] */
 112 {
 113     if ((request != NULL) && (request->ipc_client != NULL)) {
 114         return pcmk__client_name(request->ipc_client);
 115     } else if ((request != NULL) && (request->peer != NULL)) {
 116         return request->peer;
 117     } else {
 118         return "(unspecified)";
 119     }
 120 }
 121 
 122 #endif // PCMK__CRM_COMMON_MESSAGES_INTERNAL__H

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