This source file includes following definitions.
- create_request_adv
- create_reply_adv
- get_message_xml
- add_message_xml
- pcmk__message_name
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <stdio.h>
13 #include <sys/types.h>
14
15 #include <glib.h>
16 #include <libxml/tree.h>
17
18 #include <crm/msg_xml.h>
19 #include <crm/common/xml_internal.h>
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 xmlNode *
40 create_request_adv(const char *task, xmlNode * msg_data,
41 const char *host_to, const char *sys_to,
42 const char *sys_from, const char *uuid_from,
43 const char *origin)
44 {
45 static uint ref_counter = 0;
46
47 char *true_from = NULL;
48 xmlNode *request = NULL;
49 char *reference = crm_strdup_printf("%s-%s-%lld-%u",
50 (task? task : "_empty_"),
51 (sys_from? sys_from : "_empty_"),
52 (long long) time(NULL), ref_counter++);
53
54 if (uuid_from != NULL) {
55 true_from = crm_strdup_printf("%s_%s", uuid_from,
56 (sys_from? sys_from : "none"));
57 } else if (sys_from != NULL) {
58 true_from = strdup(sys_from);
59 } else {
60 crm_err("Cannot create IPC request: No originating system specified");
61 }
62
63
64 request = create_xml_node(NULL, __func__);
65 crm_xml_add(request, F_CRM_ORIGIN, origin);
66 crm_xml_add(request, F_TYPE, T_CRM);
67 crm_xml_add(request, F_CRM_VERSION, CRM_FEATURE_SET);
68 crm_xml_add(request, F_CRM_MSG_TYPE, XML_ATTR_REQUEST);
69 crm_xml_add(request, F_CRM_REFERENCE, reference);
70 crm_xml_add(request, F_CRM_TASK, task);
71 crm_xml_add(request, F_CRM_SYS_TO, sys_to);
72 crm_xml_add(request, F_CRM_SYS_FROM, true_from);
73
74
75 if (host_to != NULL && strlen(host_to) > 0) {
76 crm_xml_add(request, F_CRM_HOST_TO, host_to);
77 }
78
79 if (msg_data != NULL) {
80 add_message_xml(request, F_CRM_DATA, msg_data);
81 }
82 free(reference);
83 free(true_from);
84
85 return request;
86 }
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101 xmlNode *
102 create_reply_adv(xmlNode *original_request, xmlNode *xml_response_data,
103 const char *origin)
104 {
105 xmlNode *reply = NULL;
106
107 const char *host_from = crm_element_value(original_request, F_CRM_HOST_FROM);
108 const char *sys_from = crm_element_value(original_request, F_CRM_SYS_FROM);
109 const char *sys_to = crm_element_value(original_request, F_CRM_SYS_TO);
110 const char *type = crm_element_value(original_request, F_CRM_MSG_TYPE);
111 const char *operation = crm_element_value(original_request, F_CRM_TASK);
112 const char *crm_msg_reference = crm_element_value(original_request, F_CRM_REFERENCE);
113
114 if (type == NULL) {
115 crm_err("Cannot create new_message, no message type in original message");
116 CRM_ASSERT(type != NULL);
117 return NULL;
118 #if 0
119 } else if (strcasecmp(XML_ATTR_REQUEST, type) != 0) {
120 crm_err("Cannot create new_message, original message was not a request");
121 return NULL;
122 #endif
123 }
124 reply = create_xml_node(NULL, __func__);
125 if (reply == NULL) {
126 crm_err("Cannot create new_message, malloc failed");
127 return NULL;
128 }
129
130 crm_xml_add(reply, F_CRM_ORIGIN, origin);
131 crm_xml_add(reply, F_TYPE, T_CRM);
132 crm_xml_add(reply, F_CRM_VERSION, CRM_FEATURE_SET);
133 crm_xml_add(reply, F_CRM_MSG_TYPE, XML_ATTR_RESPONSE);
134 crm_xml_add(reply, F_CRM_REFERENCE, crm_msg_reference);
135 crm_xml_add(reply, F_CRM_TASK, operation);
136
137
138 crm_xml_add(reply, F_CRM_SYS_TO, sys_from);
139 crm_xml_add(reply, F_CRM_SYS_FROM, sys_to);
140
141
142 if (host_from != NULL && strlen(host_from) > 0) {
143 crm_xml_add(reply, F_CRM_HOST_TO, host_from);
144 }
145
146 if (xml_response_data != NULL) {
147 add_message_xml(reply, F_CRM_DATA, xml_response_data);
148 }
149
150 return reply;
151 }
152
153 xmlNode *
154 get_message_xml(xmlNode *msg, const char *field)
155 {
156 xmlNode *tmp = first_named_child(msg, field);
157
158 return pcmk__xml_first_child(tmp);
159 }
160
161 gboolean
162 add_message_xml(xmlNode *msg, const char *field, xmlNode *xml)
163 {
164 xmlNode *holder = create_xml_node(msg, field);
165
166 add_node_copy(holder, xml);
167 return TRUE;
168 }
169
170
171
172
173
174
175
176
177
178
179
180
181 const char *
182 pcmk__message_name(const char *name)
183 {
184 if (name == NULL) {
185 return "unknown";
186
187 } else if (!strcmp(name, "pacemaker-attrd")) {
188 return "attrd";
189
190 } else if (!strcmp(name, "pacemaker-based")) {
191 return CRM_SYSTEM_CIB;
192
193 } else if (!strcmp(name, "pacemaker-controld")) {
194 return CRM_SYSTEM_CRMD;
195
196 } else if (!strcmp(name, "pacemaker-execd")) {
197 return CRM_SYSTEM_LRMD;
198
199 } else if (!strcmp(name, "pacemaker-fenced")) {
200 return "stonith-ng";
201
202 } else if (!strcmp(name, "pacemaker-schedulerd")) {
203 return CRM_SYSTEM_PENGINE;
204
205 } else {
206 return name;
207 }
208 }