Skip to content

Commit b765bde

Browse files
committed
Refactor: libcib: New cib__get_calldata()
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
1 parent b04f6c5 commit b765bde

6 files changed

Lines changed: 14 additions & 26 deletions

File tree

daemons/based/based_callbacks.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,7 @@ process_ping_reply(xmlNode *reply)
195195
uint64_t seq = 0;
196196
const char *host = pcmk__xe_get(reply, PCMK__XA_SRC);
197197

198-
xmlNode *wrapper = pcmk__xe_first_child(reply, PCMK__XE_CIB_CALLDATA, NULL,
199-
NULL);
200-
xmlNode *pong = pcmk__xe_first_child(wrapper, NULL, NULL, NULL);
201-
198+
xmlNode *pong = cib__get_calldata(reply);
202199
const char *seq_s = pcmk__xe_get(pong, PCMK__XA_CIB_PING_ID);
203200
const char *digest = pcmk__xe_get(pong, PCMK_XA_DIGEST);
204201

@@ -240,10 +237,7 @@ process_ping_reply(xmlNode *reply)
240237
pcmk__trace("Processing ping reply %s from %s (%s)", seq_s, host,
241238
digest);
242239
if (!pcmk__str_eq(ping_digest, digest, pcmk__str_casei)) {
243-
xmlNode *wrapper = pcmk__xe_first_child(pong, PCMK__XE_CIB_CALLDATA,
244-
NULL, NULL);
245-
xmlNode *remote_versions = pcmk__xe_first_child(wrapper, NULL, NULL,
246-
NULL);
240+
xmlNode *remote_versions = cib__get_calldata(pong);
247241

248242
const char *admin_epoch_s = NULL;
249243
const char *epoch_s = NULL;

daemons/based/based_messages.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ int
156156
based_process_schemas(xmlNode *req, xmlNode *input, xmlNode **cib,
157157
xmlNode **answer)
158158
{
159-
xmlNode *wrapper = NULL;
160159
xmlNode *data = NULL;
161160

162161
const char *after_ver = NULL;
@@ -165,8 +164,7 @@ based_process_schemas(xmlNode *req, xmlNode *input, xmlNode **cib,
165164

166165
*answer = pcmk__xe_create(NULL, PCMK__XA_SCHEMAS);
167166

168-
wrapper = pcmk__xe_first_child(req, PCMK__XE_CIB_CALLDATA, NULL, NULL);
169-
data = pcmk__xe_first_child(wrapper, NULL, NULL, NULL);
167+
data = cib__get_calldata(req);
170168
if (data == NULL) {
171169
pcmk__warn("No data specified in request");
172170
return EPROTO;

include/crm/cib/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ cib__client_triggers_refresh(const char *name)
190190
}
191191

192192
int cib__get_notify_patchset(const xmlNode *msg, const xmlNode **patchset);
193+
xmlNode *cib__get_calldata(const xmlNode *request);
193194

194195
int cib__perform_query(cib__op_fn_t fn, xmlNode *req, xmlNode **current_cib,
195196
xmlNode **output);

lib/cib/cib_native.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ cib_native_perform_op_delegate(cib_t *cib, const char *op, const char *host,
103103
rc = pcmk_ok;
104104
pcmk__xe_get_int(op_reply, PCMK__XA_CIB_CALLID, &reply_id);
105105
if (reply_id == cib->call_id) {
106-
xmlNode *wrapper = pcmk__xe_first_child(op_reply, PCMK__XE_CIB_CALLDATA,
107-
NULL, NULL);
108-
xmlNode *tmp = pcmk__xe_first_child(wrapper, NULL, NULL, NULL);
106+
xmlNode *tmp = cib__get_calldata(op_reply);
109107

110108
pcmk__trace("Synchronous reply %d received", reply_id);
111109
if (pcmk__xe_get_int(op_reply, PCMK__XA_CIB_RC, &rc) != pcmk_rc_ok) {

lib/cib/cib_remote.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,7 @@ cib_remote_perform_op(cib_t *cib, const char *op, const char *host,
179179
/* do nothing more */
180180

181181
} else if (!(call_options & cib_discard_reply)) {
182-
xmlNode *wrapper = pcmk__xe_first_child(op_reply, PCMK__XE_CIB_CALLDATA,
183-
NULL, NULL);
184-
xmlNode *tmp = pcmk__xe_first_child(wrapper, NULL, NULL, NULL);
182+
xmlNode *tmp = cib__get_calldata(op_reply);
185183

186184
if (tmp == NULL) {
187185
pcmk__trace("No output in reply to \"%s\" command %d", op,

lib/cib/cib_utils.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,14 @@ cib_acl_enabled(xmlNode *xml, const char *user)
173173

174174
/*!
175175
* \internal
176-
* \brief Get input data from a CIB request
176+
* \brief Get call data from a CIB request
177177
*
178178
* \param[in] request CIB request XML
179+
*
180+
* \return Call data, or \c NULL if none is found
179181
*/
180-
static xmlNode *
181-
get_op_input(const xmlNode *request)
182+
xmlNode *
183+
cib__get_calldata(const xmlNode *request)
182184
{
183185
xmlNode *wrapper = pcmk__xe_first_child(request, PCMK__XE_CIB_CALLDATA,
184186
NULL, NULL);
@@ -209,7 +211,7 @@ cib__perform_query(cib__op_fn_t fn, xmlNode *req, xmlNode **current_cib,
209211
user = pcmk__xe_get(req, PCMK__XA_CIB_USER);
210212
pcmk__xe_get_flags(req, PCMK__XA_CIB_CALLOPT, &call_options, cib_none);
211213

212-
input = get_op_input(req);
214+
input = cib__get_calldata(req);
213215
cib = *current_cib;
214216

215217
if (cib_acl_enabled(*current_cib, user)
@@ -497,7 +499,7 @@ cib_perform_op(enum cib_variant variant, cib__op_fn_t fn, xmlNode *req,
497499
user = pcmk__xe_get(req, PCMK__XA_CIB_USER);
498500
pcmk__xe_get_flags(req, PCMK__XA_CIB_CALLOPT, &call_options, cib_none);
499501

500-
input = get_op_input(req);
502+
input = cib__get_calldata(req);
501503
enable_acl = cib_acl_enabled(*cib, user);
502504

503505
pcmk__trace("Processing %s for section '%s', user '%s'", op,
@@ -735,12 +737,9 @@ cib_native_callback(cib_t * cib, xmlNode * msg, int call_id, int rc)
735737
cib_callback_client_t *blob = NULL;
736738

737739
if (msg != NULL) {
738-
xmlNode *wrapper = NULL;
739-
740740
pcmk__xe_get_int(msg, PCMK__XA_CIB_RC, &rc);
741741
pcmk__xe_get_int(msg, PCMK__XA_CIB_CALLID, &call_id);
742-
wrapper = pcmk__xe_first_child(msg, PCMK__XE_CIB_CALLDATA, NULL, NULL);
743-
output = pcmk__xe_first_child(wrapper, NULL, NULL, NULL);
742+
output = cib__get_calldata(msg);
744743
}
745744

746745
blob = cib__lookup_id(call_id);

0 commit comments

Comments
 (0)