pacemaker  2.1.6-802a72226b
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  * 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
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);
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);
79 
89 static inline const char *
90 pcmk__request_origin_type(const pcmk__request_t *request)
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 
110 static inline const char *
111 pcmk__request_origin(const pcmk__request_t *request)
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
GHashTable * pcmk__register_handlers(const pcmk__server_command_t handlers[])
Definition: messages.c:222
void pcmk__reset_request(pcmk__request_t *request)
Definition: messages.c:285
const char * name
Definition: cib.c:24
xmlNode * pcmk__process_request(pcmk__request_t *request, GHashTable *handlers)
Definition: messages.c:251
pcmk__client_t * ipc_client
pcmk__request_flags
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:180
const char * peer
const char * pcmk__client_name(const pcmk__client_t *c)
Definition: ipc_server.c:98