Skip to content

Commit

Permalink
refactor(util): Reuse printing of RelativePaths for UA_SimpleAttribut…
Browse files Browse the repository at this point in the history
…eOperand_print
  • Loading branch information
jpfr committed Oct 25, 2024
1 parent 85f0fca commit 21da77f
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions src/util/ua_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -781,8 +781,8 @@ static const UA_NodeId hierarchicalRefs =
static const UA_NodeId aggregatesRefs =
{0, UA_NODEIDTYPE_NUMERIC, {UA_NS0ID_AGGREGATES}};

UA_StatusCode
UA_RelativePath_print(const UA_RelativePath *rp, UA_String *out) {
static UA_StatusCode
printRelativePath(const UA_RelativePath *rp, UA_String *out, UA_Boolean extEscape) {
UA_String tmp = UA_STRING_NULL;
UA_StatusCode res = UA_STATUSCODE_GOOD;
for(size_t i = 0; i < rp->elementsSize && res == UA_STATUSCODE_GOOD; i++) {
Expand All @@ -805,7 +805,7 @@ UA_RelativePath_print(const UA_RelativePath *rp, UA_String *out) {
res |= getRefTypeBrowseName(&elm->referenceTypeId, &bnBufStr);
if(res != UA_STATUSCODE_GOOD)
break;
res |= UA_String_escapeAppend(&tmp, bnBufStr, false);
res |= UA_String_escapeAppend(&tmp, bnBufStr, extEscape);
res |= UA_String_append(&tmp, UA_STRING(">"));
}

Expand All @@ -817,7 +817,7 @@ UA_RelativePath_print(const UA_RelativePath *rp, UA_String *out) {
res |= UA_String_append(&tmp, UA_STRING(nsStr));
res |= UA_String_append(&tmp, UA_STRING(":"));
}
res |= UA_String_escapeAppend(&tmp, qn->name, false);
res |= UA_String_escapeAppend(&tmp, qn->name, extEscape);
}

/* Encoding failed, clean up */
Expand All @@ -829,6 +829,11 @@ UA_RelativePath_print(const UA_RelativePath *rp, UA_String *out) {
return moveTmpToOut(&tmp, out);
}

UA_StatusCode
UA_RelativePath_print(const UA_RelativePath *rp, UA_String *out) {
return printRelativePath(rp, out, false);
}

static UA_NodeId baseEventTypeId = {0, UA_NODEIDTYPE_NUMERIC, {UA_NS0ID_BASEEVENTTYPE}};

UA_StatusCode
Expand All @@ -850,18 +855,17 @@ UA_SimpleAttributeOperand_print(const UA_SimpleAttributeOperand *sao,
}

/* Print the BrowsePath */
UA_RelativePathElement rpe;
UA_RelativePathElement_init(&rpe);
rpe.includeSubtypes = true;
rpe.referenceTypeId = hierarchicalRefs;
UA_RelativePath rp = {1, &rpe};
for(size_t i = 0; i < sao->browsePathSize; i++) {
res |= UA_String_append(&tmp, UA_STRING("/"));
UA_QualifiedName *qn = &sao->browsePath[i];
if(qn->namespaceIndex > 0) {
char nsStr[8]; /* Enough for a uint16 */
itoaUnsigned(qn->namespaceIndex, nsStr, 10);
res |= UA_String_append(&tmp, UA_STRING(nsStr));
res |= UA_String_append(&tmp, UA_STRING(":"));
}
res |= UA_String_escapeAppend(&tmp, qn->name, true);
if(res != UA_STATUSCODE_GOOD)
goto cleanup;
UA_String rpstr = UA_STRING_NULL;
rpe.targetName = sao->browsePath[i];
res |= printRelativePath(&rp, &rpstr, true);
res |= UA_String_append(&tmp, rpstr);
UA_String_clear(&rpstr);
}

/* Print the attribute name */
Expand Down Expand Up @@ -907,8 +911,8 @@ UA_AttributeOperand_print(const UA_AttributeOperand *ao,

/* Print the BrowsePath */
UA_String rpstr = UA_STRING_NULL;
res |= UA_RelativePath_print(&ao->browsePath, &rpstr);
res |= UA_String_escapeAppend(&tmp, rpstr, true);
res |= printRelativePath(&ao->browsePath, &rpstr, true);
res |= UA_String_append(&tmp, rpstr);
UA_String_clear(&rpstr);

/* Print the attribute name */
Expand Down

0 comments on commit 21da77f

Please sign in to comment.