1
0
Fork 0

Merging upstream version 3.7.8.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-05 08:08:50 +01:00
parent 099007bbc4
commit a3c6363c26
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
52 changed files with 13518 additions and 998 deletions

View file

@ -12,6 +12,7 @@
* https://opensource.org/licenses/BSD-3-Clause
*/
#define _GNU_SOURCE /* asprintf, strdup */
#define _DEFAULT_SOURCE /* fmodl */
#include "xpath.h"
@ -4098,6 +4099,29 @@ cleanup:
return ret;
}
/**
* @brief Get the module of an identity used in derived-from(-or-self)() functions.
*
* @param[in,out] qname Qualified node name. If includes prefix, it is skipped.
* @param[in,out] qname_len Length of @p qname, is updated accordingly.
* @param[in] set Set with general XPath context.
* @param[out] mod Module of the identity.
* @return LY_ERR
*/
static LY_ERR
xpath_derived_ident_module(const char **qname, uint32_t *qname_len, const struct lyxp_set *set,
const struct lys_module **mod)
{
LY_CHECK_RET(moveto_resolve_model(qname, qname_len, set, set->cur_node ? set->cur_node->schema : NULL, mod));
if (!*mod) {
/* unprefixed JSON identity */
assert(set->format == LY_VALUE_JSON);
*mod = set->cur_mod;
}
return LY_SUCCESS;
}
static LY_ERR
xpath_derived_(struct lyxp_set **args, struct lyxp_set *set, uint32_t options, ly_bool self_match, const char *func)
{
@ -4147,12 +4171,8 @@ xpath_derived_(struct lyxp_set **args, struct lyxp_set *set, uint32_t options, l
/* parse the identity */
id_name = args[1]->val.str;
id_len = strlen(id_name);
rc = moveto_resolve_model(&id_name, &id_len, set, set->cur_node ? set->cur_node->schema : NULL, &mod);
rc = xpath_derived_ident_module(&id_name, &id_len, set, &mod);
LY_CHECK_RET(rc);
if (!mod) {
LOGVAL(set->ctx, LYVE_XPATH, "Identity \"%.*s\" without a prefix.", (int)id_len, id_name);
return LY_EVALID;
}
/* find the identity */
found = 0;
@ -5631,14 +5651,14 @@ xpath_pi_text(struct lyxp_set *set, enum lyxp_axis axis, uint32_t options)
}
/**
* @brief Skip prefix and return corresponding model if there is a prefix. Logs directly.
* @brief Skip prefix and return corresponding model. Logs directly.
*
* XPath @p set is expected to be a (sc)node set!
*
* @param[in,out] qname Qualified node name. If includes prefix, it is skipped.
* @param[in,out] qname_len Length of @p qname, is updated accordingly.
* @param[in] set Set with general XPath context.
* @param[in] ctx_scnode Context node to inherit module for unprefixed node for ::LY_PREF_JSON.
* @param[in] ctx_scnode Current context schema node (parent).
* @param[out] moveto_mod Expected module of a matching node.
* @return LY_ERR
*/
@ -5683,6 +5703,7 @@ moveto_resolve_model(const char **qname, uint32_t *qname_len, const struct lyxp_
if (ctx_scnode) {
mod = ctx_scnode->module;
} else {
/* JSON XPath is our own format (except for identityref), which supports node names matching all the modules */
mod = NULL;
}
break;
@ -7455,7 +7476,7 @@ moveto_op_math(struct lyxp_set *set1, struct lyxp_set *set2, const char *op)
/* 'mod' */
case 'm':
set1->val.num = ((long long)set1->val.num) % ((long long)set2->val.num);
set1->val.num = fmodl(set1->val.num, set2->val.num);
break;
default:
@ -7677,7 +7698,7 @@ eval_name_test_try_compile_predicate_key(const char *nametest, uint32_t len, con
/* prefix (module) */
LY_CHECK_RET(moveto_resolve_model(&nametest, &len, set, ctx_scnode, &mod));
if (mod != key->module) {
if (mod && (mod != key->module)) {
return LY_ENOT;
}