Skip to content

Commit 89a4476

Browse files
committed
API: libcrmcommon: Deprecate getXpathResult()
Signed-off-by: Reid Wahl <[email protected]>
1 parent 012f8c5 commit 89a4476

3 files changed

Lines changed: 46 additions & 44 deletions

File tree

include/crm/common/xml.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ void crm_foreach_xpath_result(xmlNode *xml, const char *xpath,
5252
void (*helper)(xmlNode*, void*), void *user_data);
5353

5454
void freeXpathObject(xmlXPathObjectPtr xpathObj);
55-
xmlNode *getXpathResult(xmlXPathObjectPtr xpathObj, int index);
5655
void dedupXpathResults(xmlXPathObjectPtr xpathObj);
5756

5857
bool xml_tracking_changes(xmlNode * xml);

include/crm/common/xml_compat.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ static inline int numXpathResults(xmlXPathObjectPtr xpathObj)
8585
return xpathObj->nodesetval->nodeNr;
8686
}
8787

88+
//! \deprecated Do not use
89+
xmlNode *getXpathResult(xmlXPathObjectPtr xpathObj, int index);
90+
8891
#ifdef __cplusplus
8992
}
9093
#endif

lib/common/xpath.c

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -161,49 +161,6 @@ pcmk__xpath_match_element(xmlNode *match)
161161
}
162162
}
163163

164-
xmlNode *
165-
getXpathResult(xmlXPathObjectPtr xpathObj, int index)
166-
{
167-
xmlNode *match = NULL;
168-
int max = pcmk__xpath_num_results(xpathObj);
169-
170-
CRM_CHECK(index >= 0, return NULL);
171-
CRM_CHECK(xpathObj != NULL, return NULL);
172-
173-
if (index >= max) {
174-
crm_err("Requested index %d of only %d items", index, max);
175-
return NULL;
176-
177-
} else if(xpathObj->nodesetval->nodeTab[index] == NULL) {
178-
/* Previously requested */
179-
return NULL;
180-
}
181-
182-
match = xpathObj->nodesetval->nodeTab[index];
183-
CRM_CHECK(match != NULL, return NULL);
184-
185-
if (xpathObj->nodesetval->nodeTab[index]->type != XML_NAMESPACE_DECL) {
186-
// See the comment for pcmk__xpath_result()
187-
xpathObj->nodesetval->nodeTab[index] = NULL;
188-
}
189-
190-
switch (match->type) {
191-
case XML_ELEMENT_NODE:
192-
return match;
193-
194-
case XML_DOCUMENT_NODE: // Searched for '/'
195-
return match->children;
196-
197-
default:
198-
if ((match->parent != NULL)
199-
&& (match->parent->type == XML_ELEMENT_NODE)) {
200-
return match->parent;
201-
}
202-
crm_warn("Unsupported XPath match type %d (bug?)", match->type);
203-
return NULL;
204-
}
205-
}
206-
207164
void
208165
dedupXpathResults(xmlXPathObjectPtr xpathObj)
209166
{
@@ -506,5 +463,48 @@ xpath_search(const xmlNode *xml_top, const char *path)
506463
return pcmk__xpath_search(xml_top->doc, path);
507464
}
508465

466+
xmlNode *
467+
getXpathResult(xmlXPathObjectPtr xpathObj, int index)
468+
{
469+
xmlNode *match = NULL;
470+
int max = pcmk__xpath_num_results(xpathObj);
471+
472+
CRM_CHECK(index >= 0, return NULL);
473+
CRM_CHECK(xpathObj != NULL, return NULL);
474+
475+
if (index >= max) {
476+
crm_err("Requested index %d of only %d items", index, max);
477+
return NULL;
478+
479+
} else if(xpathObj->nodesetval->nodeTab[index] == NULL) {
480+
/* Previously requested */
481+
return NULL;
482+
}
483+
484+
match = xpathObj->nodesetval->nodeTab[index];
485+
CRM_CHECK(match != NULL, return NULL);
486+
487+
if (xpathObj->nodesetval->nodeTab[index]->type != XML_NAMESPACE_DECL) {
488+
// See the comment for pcmk__xpath_result()
489+
xpathObj->nodesetval->nodeTab[index] = NULL;
490+
}
491+
492+
switch (match->type) {
493+
case XML_ELEMENT_NODE:
494+
return match;
495+
496+
case XML_DOCUMENT_NODE: // Searched for '/'
497+
return match->children;
498+
499+
default:
500+
if ((match->parent != NULL)
501+
&& (match->parent->type == XML_ELEMENT_NODE)) {
502+
return match->parent;
503+
}
504+
crm_warn("Unsupported XPath match type %d (bug?)", match->type);
505+
return NULL;
506+
}
507+
}
508+
509509
// LCOV_EXCL_STOP
510510
// End deprecated API

0 commit comments

Comments
 (0)