Skip to content

Commit

Permalink
parser xml REFACTOR move status check into func
Browse files Browse the repository at this point in the history
  • Loading branch information
michalvasko committed Jun 13, 2023
1 parent 3fb6cbc commit f048ba5
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions src/parser_xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,11 @@ lydxml_envelope(struct lyxml_ctx *xmlctx, const char *name, const char *uri, ly_
const char *prefix;
size_t prefix_len;

assert(xmlctx->status == LYXML_ELEMENT);
if (xmlctx->status != LYXML_ELEMENT) {
/* nothing to parse */
return LY_ENOT;
}

if (ly_strncmp(name, xmlctx->name, xmlctx->name_len)) {
/* not the expected element */
return LY_ENOT;
Expand Down Expand Up @@ -1274,12 +1278,6 @@ lydxml_env_netconf_rpc(struct lyxml_ctx *xmlctx, struct lyd_node **envp, uint32_

assert(envp && !*envp);

if (xmlctx->status != LYXML_ELEMENT) {
/* nothing to parse */
assert(xmlctx->status == LYXML_END);
goto cleanup;
}

/* parse "rpc" */
r = lydxml_envelope(xmlctx, "rpc", "urn:ietf:params:xml:ns:netconf:base:1.0", 0, envp);
LY_CHECK_ERR_GOTO(r, rc = r, cleanup);
Expand Down Expand Up @@ -1328,12 +1326,6 @@ lydxml_env_netconf_notif(struct lyxml_ctx *xmlctx, struct lyd_node **envp, uint3

assert(envp && !*envp);

if (xmlctx->status != LYXML_ELEMENT) {
/* nothing to parse */
assert(xmlctx->status == LYXML_END);
goto cleanup;
}

/* parse "notification" */
r = lydxml_envelope(xmlctx, "notification", "urn:ietf:params:xml:ns:netconf:notification:1.0", 0, envp);
LY_CHECK_ERR_GOTO(r, rc = r, cleanup);
Expand Down Expand Up @@ -1749,12 +1741,6 @@ lydxml_env_netconf_reply(struct lyxml_ctx *xmlctx, struct lyd_node **envp, uint3

assert(envp && !*envp);

if (xmlctx->status != LYXML_ELEMENT) {
/* nothing to parse */
assert(xmlctx->status == LYXML_END);
goto cleanup;
}

/* parse "rpc-reply" */
r = lydxml_envelope(xmlctx, "rpc-reply", "urn:ietf:params:xml:ns:netconf:base:1.0", 0, envp);
LY_CHECK_ERR_GOTO(r, rc = r, cleanup);
Expand Down

0 comments on commit f048ba5

Please sign in to comment.