pacemaker  2.1.3-ea053b43a
Scalable High-Availability cluster resource manager
messages_internal.h
Go to the documentation of this file.
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 
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  * @TODO Create a per-daemon struct with IPC handlers, IPC endpoints, etc.,
54  * and the name of the XML attribute for IPC commands, then replace this
55  * with a convenience function to grab the command.
56  */
57  const char *op; // IPC command from xml
59 
60 #define pcmk__set_request_flags(request, flags_to_set) do { \
61  (request)->flags = pcmk__set_flags_as(__func__, __LINE__, \
62  LOG_TRACE, "Request", "message", (request)->flags, \
63  (flags_to_set), #flags_to_set); \
64  } while (0)
65 
66 // Type for mapping a server command to a handler
67 typedef struct {
68  const char *command;
69  xmlNode *(*handler)(pcmk__request_t *request);
71 
72 const char *pcmk__message_name(const char *name);
73 GHashTable *pcmk__register_handlers(pcmk__server_command_t handlers[]);
74 xmlNode *pcmk__process_request(pcmk__request_t *request, GHashTable *handlers);
75 
85 static inline const char *
86 pcmk__request_origin_type(pcmk__request_t *request)
87 {
88  if ((request != NULL) && (request->ipc_client != NULL)) {
89  return "client";
90  } else if ((request != NULL) && (request->peer != NULL)) {
91  return "peer";
92  } else {
93  return "originator";
94  }
95 }
96 
106 static inline const char *
107 pcmk__request_origin(pcmk__request_t *request)
108 {
109  if ((request != NULL) && (request->ipc_client != NULL)) {
110  return pcmk__client_name(request->ipc_client);
111  } else if ((request != NULL) && (request->peer != NULL)) {
112  return request->peer;
113  } else {
114  return "(unspecified)";
115  }
116 }
117 
118 #endif // PCMK__CRM_COMMON_MESSAGES_INTERNAL__H
const char * name
Definition: cib.c:24
xmlNode * pcmk__process_request(pcmk__request_t *request, GHashTable *handlers)
Definition: messages.c:253
pcmk__client_t * ipc_client
pcmk__request_flags
GHashTable * pcmk__register_handlers(pcmk__server_command_t handlers[])
pcmk__action_result_t result
const char * pcmk__message_name(const char *name)
Get name to be used as identifier for cluster messages.
Definition: messages.c:182
const char * peer
const char * pcmk__client_name(pcmk__client_t *c)
Definition: ipc_server.c:99