Procházet zdrojové kódy

use only a single UA_NodeId_isNull for all nodeid types

Julius Pfrommer před 8 roky
rodič
revize
ce4031ef8d
3 změnil soubory, kde provedl 28 přidání a 40 odebrání
  1. 1 37
      include/ua_types.h
  2. 3 3
      src/server/ua_services_view.c
  3. 24 0
      src/ua_types.c

+ 1 - 37
include/ua_types.h

@@ -332,43 +332,7 @@ typedef struct {
 
 UA_EXPORT extern const UA_NodeId UA_NODEID_NULL;
 
-static UA_INLINE UA_Boolean
-UA_NodeId_isNull(const UA_NodeId *p) {
-    return (p->namespaceIndex == 0 &&
-            p->identifierType == UA_NODEIDTYPE_NUMERIC &&
-            p->identifier.numeric == 0);
-}
-
-static UA_INLINE UA_Boolean
-UA_NodeId_isEmptyString(const UA_NodeId *p) {
-    return (p->namespaceIndex == 0 &&
-            p->identifierType == UA_NODEIDTYPE_STRING &&
-            p->identifier.string.length == 0);
-}
-
-static UA_INLINE UA_Boolean
-UA_NodeId_isEmptyGUID(const UA_NodeId *p) {
-    return (p->namespaceIndex == 0 &&
-            p->identifierType == UA_NODEIDTYPE_GUID &&
-            p->identifier.guid.data1 == 0 &&
-            p->identifier.guid.data2 == 0 &&
-            p->identifier.guid.data3 == 0 &&
-            p->identifier.guid.data4[0] == 0 &&
-            p->identifier.guid.data4[1] == 0 &&
-            p->identifier.guid.data4[2] == 0 &&
-            p->identifier.guid.data4[3] == 0 &&
-            p->identifier.guid.data4[4] == 0 &&
-            p->identifier.guid.data4[5] == 0 &&
-            p->identifier.guid.data4[6] == 0 &&
-            p->identifier.guid.data4[7] == 0);
-}
-
-static UA_INLINE UA_Boolean
-UA_NodeId_isEmptyByteString(const UA_NodeId *p) {
-    return (p->namespaceIndex == 0 &&
-            p->identifierType == UA_NODEIDTYPE_BYTESTRING &&
-            p->identifier.byteString.length == 0);
-}
+UA_Boolean UA_EXPORT UA_NodeId_isNull(const UA_NodeId *p);
 
 UA_Boolean UA_EXPORT UA_NodeId_equal(const UA_NodeId *n1, const UA_NodeId *n2);
 

+ 3 - 3
src/server/ua_services_view.c

@@ -459,11 +459,11 @@ walkBrowsePath(UA_Server *server, UA_Session *session, const UA_Node *node, cons
     UA_NodeId *reftypes = NULL;
     size_t reftypes_count = 1; // all_refs or no subtypes => 1
     UA_Boolean all_refs = false;
-    if(UA_NodeId_isNull(&elem->referenceTypeId) || UA_NodeId_isEmptyString(&elem->referenceTypeId) || UA_NodeId_isEmptyGUID(&elem->referenceTypeId) || UA_NodeId_isEmptyByteString(&elem->referenceTypeId))
+    if(UA_NodeId_isNull(&elem->referenceTypeId)) {
         all_refs = true;
-    else if(!elem->includeSubtypes)
+    } else if(!elem->includeSubtypes) {
         reftypes = (UA_NodeId*)(uintptr_t)&elem->referenceTypeId; // ptr magic due to const cast
-    else {
+    } else {
         retval = findSubTypes(server->nodestore, &elem->referenceTypeId, &reftypes, &reftypes_count);
         if(retval != UA_STATUSCODE_GOOD)
             return retval;

+ 24 - 0
src/ua_types.c

@@ -234,6 +234,30 @@ static UA_StatusCode NodeId_copy(UA_NodeId const *src, UA_NodeId *dst, const UA_
     return retval;
 }
 
+UA_Boolean UA_NodeId_isNull(const UA_NodeId *p) {
+    if(p->namespaceIndex != 0)
+        return false;
+    switch(p->identifierType) {
+    case UA_NODEIDTYPE_NUMERIC:
+        return (p->identifier.numeric == 0);
+    case UA_NODEIDTYPE_GUID:
+        return (p->identifier.guid.data1 == 0 &&
+                p->identifier.guid.data2 == 0 &&
+                p->identifier.guid.data3 == 0 &&
+                p->identifier.guid.data4[0] == 0 &&
+                p->identifier.guid.data4[1] == 0 &&
+                p->identifier.guid.data4[2] == 0 &&
+                p->identifier.guid.data4[3] == 0 &&
+                p->identifier.guid.data4[4] == 0 &&
+                p->identifier.guid.data4[5] == 0 &&
+                p->identifier.guid.data4[6] == 0 &&
+                p->identifier.guid.data4[7] == 0);
+    default:
+        break;
+    }
+    return (p->identifier.string.length == 0);
+}
+
 UA_Boolean UA_NodeId_equal(const UA_NodeId *n1, const UA_NodeId *n2) {
     if(n1->namespaceIndex != n2->namespaceIndex || n1->identifierType!=n2->identifierType)
         return false;