Parcourir la source

Add configuration option to allow empty variable values

Julius Pfrommer il y a 6 ans
Parent
commit
07eeb6ee94
3 fichiers modifiés avec 19 ajouts et 14 suppressions
  1. 5 0
      include/ua_server_config.h
  2. 3 0
      plugins/ua_config_default.c
  3. 11 14
      src/server/ua_services_attribute.c

+ 5 - 0
include/ua_server_config.h

@@ -118,6 +118,11 @@ struct UA_ServerConfig {
     /* Certificate Verification */
     UA_CertificateVerification certificateVerification;
 
+    /* Relax constraints for the InformationModel */
+    UA_Boolean relaxEmptyValueConstraint; /* Nominally, only variables with data
+                                           * type BaseDataType can have an empty
+                                           * value. */
+
     /* Limits for SecureChannels */
     UA_UInt16 maxSecureChannels;
     UA_UInt32 maxSecurityTokenLifetime; /* in ms */

+ 3 - 0
plugins/ua_config_default.c

@@ -249,6 +249,9 @@ createDefaultConfig(void) {
     /* Access Control. Anonymous Login only. */
     conf->accessControl = UA_AccessControl_default(true, usernamePasswordsSize, usernamePasswords);
 
+    /* Relax constraints for the InformationModel */
+    conf->relaxEmptyValueConstraint = true; /* Allow empty values */
+
     /* Limits for SecureChannels */
     conf->maxSecureChannels = 40;
     conf->maxSecurityTokenLifetime = 10 * 60 * 1000; /* 10 minutes */

+ 11 - 14
src/server/ua_services_attribute.c

@@ -764,22 +764,19 @@ compatibleValue(UA_Server *server, UA_Session *session, const UA_NodeId *targetD
            UA_NodeId_equal(targetDataTypeId, &UA_NODEID_NULL))
             return true;
 
-        /* Workaround: Allow empty value if the target data type is abstract */
-        const UA_Node *datatype = UA_Nodestore_get(server, targetDataTypeId);
-        if(datatype && datatype->nodeClass == UA_NODECLASS_DATATYPE) {
-            UA_Boolean isAbstract = ((const UA_DataTypeNode*)datatype)->isAbstract;
-            UA_Nodestore_release(server, datatype);
-            if(isAbstract)
-                return true;
+        /* Allow empty node values since existing information models may have
+         * variables with no value, e.g. OldValues - ns=0;i=3024. See also
+         * #1889, https://github.com/open62541/open62541/pull/1889#issuecomment-403506538 */
+        if(server->config.relaxEmptyValueConstraint) {
+            UA_LOG_DEBUG_SESSION(server->config.logger, session,
+                                 "Only Variables with data type BaseDataType can contain an "
+                                 "empty value. Allow via explicit constraint relaxation.");
+            return true;
         }
 
-        UA_LOG_INFO(server->config.logger, UA_LOGCATEGORY_SERVER,
-                    "Only Variables with data type BaseDataType should contain "
-                    "a null (empty) value");
-        /* we allow addition of the node anyways since existing information models may have
-           variables with no value, e.g. OldValues - ns=0;i=3024.
-           See also #1889, https://github.com/open62541/open62541/pull/1889#issuecomment-403506538 */
-        return true;
+        UA_LOG_INFO_SESSION(server->config.logger, session,
+                            "Only Variables with data type BaseDataType can contain an empty value");
+        return false;
     }
 
     /* Has the value a subtype of the required type? BaseDataType (Variant) can