Browse Source

remove magic constants with definitions for the access level bits

Julius Pfrommer 7 years ago
parent
commit
19d8c9a70a
2 changed files with 52 additions and 51 deletions
  1. 32 31
      include/ua_constants.h
  2. 20 20
      src/server/ua_services_attribute.c

+ 32 - 31
include/ua_constants.h

@@ -49,42 +49,43 @@ typedef enum {
 /**
  * Access Level Masks
  * ------------------
- * The access level to a node is given by the following constants that are XORed
- * for the overall access level. */
-#define UA_ACCESSLEVELMASK_READ 0x01
-#define UA_ACCESSLEVELMASK_WRITE 0x02
-#define UA_ACCESSLEVELMASK_HISTORYREAD 0x4
-#define UA_ACCESSLEVELMASK_HISTORYWRITE 0x08
-#define UA_ACCESSLEVELMASK_SEMANTICCHANGE 0x10
+ * The access level to a node is given by the following constants that are ANDed
+ * with the overall access level. */
+#define UA_ACCESSLEVELMASK_READ           1<<0
+#define UA_ACCESSLEVELMASK_WRITE          1<<1
+#define UA_ACCESSLEVELMASK_HISTORYREAD    1<<2
+#define UA_ACCESSLEVELMASK_HISTORYWRITE   1<<3
+#define UA_ACCESSLEVELMASK_SEMANTICCHANGE 1<<4
+#define UA_ACCESSLEVELMASK_STATUSWRITE    1<<5
+#define UA_ACCESSLEVELMASK_TIMESTAMPWRITE 1<<6
 
 /**
  * Write Masks
  * -----------
  * The write mask and user write mask is given by the following constants that
- * are XORed for the overall write mask. Part 3: 5.2.7 Table 2
- */
-#define UA_WRITEMASK_ACCESSLEVEL                1<<0
-#define UA_WRITEMASK_ARRRAYDIMENSIONS           1<<1
-#define UA_WRITEMASK_BROWSENAME                 1<<2
-#define UA_WRITEMASK_CONTAINSNOLOOPS            1<<3
-#define UA_WRITEMASK_DATATYPE                   1<<4
-#define UA_WRITEMASK_DESCRIPTION                1<<5
-#define UA_WRITEMASK_DISPLAYNAME                1<<6
-#define UA_WRITEMASK_EVENTNOTIFIER              1<<7
-#define UA_WRITEMASK_EXECUTABLE                 1<<8
-#define UA_WRITEMASK_HISTORIZING                1<<9
-#define UA_WRITEMASK_INVERSENAME                1<<10
-#define UA_WRITEMASK_ISABSTRACT                 1<<11
-#define UA_WRITEMASK_MINIMUMSAMPLINGINTERVAL    1<<12
-#define UA_WRITEMASK_NODECLASS                  1<<13
-#define UA_WRITEMASK_NODEID                     1<<14
-#define UA_WRITEMASK_SYMMETRIC                  1<<15
-#define UA_WRITEMASK_USERACCESSLEVEL            1<<16
-#define UA_WRITEMASK_USEREXECUTABLE             1<<17
-#define UA_WRITEMASK_USERWRITEMASK              1<<18
-#define UA_WRITEMASK_VALUERANK                  1<<19
-#define UA_WRITEMASK_WRITEMASK                  1<<20
-#define UA_WRITEMASK_VALUEFORVARIABLETYPE       1<<21
+ * are ANDed for the overall write mask. Part 3: 5.2.7 Table 2 */
+#define UA_WRITEMASK_ACCESSLEVEL             1<<0
+#define UA_WRITEMASK_ARRRAYDIMENSIONS        1<<1
+#define UA_WRITEMASK_BROWSENAME              1<<2
+#define UA_WRITEMASK_CONTAINSNOLOOPS         1<<3
+#define UA_WRITEMASK_DATATYPE                1<<4
+#define UA_WRITEMASK_DESCRIPTION             1<<5
+#define UA_WRITEMASK_DISPLAYNAME             1<<6
+#define UA_WRITEMASK_EVENTNOTIFIER           1<<7
+#define UA_WRITEMASK_EXECUTABLE              1<<8
+#define UA_WRITEMASK_HISTORIZING             1<<9
+#define UA_WRITEMASK_INVERSENAME             1<<10
+#define UA_WRITEMASK_ISABSTRACT              1<<11
+#define UA_WRITEMASK_MINIMUMSAMPLINGINTERVAL 1<<12
+#define UA_WRITEMASK_NODECLASS               1<<13
+#define UA_WRITEMASK_NODEID                  1<<14
+#define UA_WRITEMASK_SYMMETRIC               1<<15
+#define UA_WRITEMASK_USERACCESSLEVEL         1<<16
+#define UA_WRITEMASK_USEREXECUTABLE          1<<17
+#define UA_WRITEMASK_USERWRITEMASK           1<<18
+#define UA_WRITEMASK_VALUERANK               1<<19
+#define UA_WRITEMASK_WRITEMASK               1<<20
+#define UA_WRITEMASK_VALUEFORVARIABLETYPE    1<<21
 
 /**
  * .. _statuscodes:

+ 20 - 20
src/server/ua_services_attribute.c

@@ -1038,8 +1038,8 @@ __UA_Server_read(UA_Server *server, const UA_NodeId *nodeId,
         break;                                                          \
     }
 
-#define CHECK_USERWRITEMASK(BITPOS)                         \
-    if(!(userWriteMask & (((UA_UInt32)0x01) << BITPOS ))) { \
+#define CHECK_USERWRITEMASK(mask)                           \
+    if(!(userWriteMask & (mask))) {                         \
         retval = UA_STATUSCODE_BADUSERACCESSDENIED;         \
         break;                                              \
     }
@@ -1062,55 +1062,55 @@ copyAttributeIntoNode(UA_Server *server, UA_Session *session,
         retval = UA_STATUSCODE_BADWRITENOTSUPPORTED;
         break;
     case UA_ATTRIBUTEID_BROWSENAME:
-        CHECK_USERWRITEMASK(2);
+        CHECK_USERWRITEMASK(UA_WRITEMASK_BROWSENAME);
         CHECK_DATATYPE_SCALAR(QUALIFIEDNAME);
         UA_QualifiedName_deleteMembers(&node->browseName);
         UA_QualifiedName_copy((const UA_QualifiedName *)value, &node->browseName);
         break;
     case UA_ATTRIBUTEID_DISPLAYNAME:
-        CHECK_USERWRITEMASK(6);
+        CHECK_USERWRITEMASK(UA_WRITEMASK_DISPLAYNAME);
         CHECK_DATATYPE_SCALAR(LOCALIZEDTEXT);
         UA_LocalizedText_deleteMembers(&node->displayName);
         UA_LocalizedText_copy((const UA_LocalizedText *)value, &node->displayName);
         break;
     case UA_ATTRIBUTEID_DESCRIPTION:
-        CHECK_USERWRITEMASK(5);
+        CHECK_USERWRITEMASK(UA_WRITEMASK_DESCRIPTION);
         CHECK_DATATYPE_SCALAR(LOCALIZEDTEXT);
         UA_LocalizedText_deleteMembers(&node->description);
         UA_LocalizedText_copy((const UA_LocalizedText *)value, &node->description);
         break;
     case UA_ATTRIBUTEID_WRITEMASK:
-        CHECK_USERWRITEMASK(20);
+        CHECK_USERWRITEMASK(UA_WRITEMASK_WRITEMASK);
         CHECK_DATATYPE_SCALAR(UINT32);
         node->writeMask = *(const UA_UInt32*)value;
         break;
     case UA_ATTRIBUTEID_ISABSTRACT:
-        CHECK_USERWRITEMASK(11);
+        CHECK_USERWRITEMASK(UA_WRITEMASK_ISABSTRACT);
         CHECK_DATATYPE_SCALAR(BOOLEAN);
         retval = writeIsAbstractAttribute(node, *(const UA_Boolean*)value);
         break;
     case UA_ATTRIBUTEID_SYMMETRIC:
         CHECK_NODECLASS_WRITE(UA_NODECLASS_REFERENCETYPE);
-        CHECK_USERWRITEMASK(15);
+        CHECK_USERWRITEMASK(UA_WRITEMASK_SYMMETRIC);
         CHECK_DATATYPE_SCALAR(BOOLEAN);
         ((UA_ReferenceTypeNode*)node)->symmetric = *(const UA_Boolean*)value;
         break;
     case UA_ATTRIBUTEID_INVERSENAME:
         CHECK_NODECLASS_WRITE(UA_NODECLASS_REFERENCETYPE);
-        CHECK_USERWRITEMASK(10);
+        CHECK_USERWRITEMASK(UA_WRITEMASK_INVERSENAME);
         CHECK_DATATYPE_SCALAR(LOCALIZEDTEXT);
         UA_LocalizedText_deleteMembers(&((UA_ReferenceTypeNode*)node)->inverseName);
         UA_LocalizedText_copy((const UA_LocalizedText *)value, &((UA_ReferenceTypeNode*)node)->inverseName);
         break;
     case UA_ATTRIBUTEID_CONTAINSNOLOOPS:
         CHECK_NODECLASS_WRITE(UA_NODECLASS_VIEW);
-        CHECK_USERWRITEMASK(3);
+        CHECK_USERWRITEMASK(UA_WRITEMASK_CONTAINSNOLOOPS);
         CHECK_DATATYPE_SCALAR(BOOLEAN);
         ((UA_ViewNode*)node)->containsNoLoops = *(const UA_Boolean*)value;
         break;
     case UA_ATTRIBUTEID_EVENTNOTIFIER:
         CHECK_NODECLASS_WRITE(UA_NODECLASS_VIEW | UA_NODECLASS_OBJECT);
-        CHECK_USERWRITEMASK(7);
+        CHECK_USERWRITEMASK(UA_WRITEMASK_EVENTNOTIFIER);
         CHECK_DATATYPE_SCALAR(BYTE);
         ((UA_ViewNode*)node)->eventNotifier = *(const UA_Byte*)value;
         break;
@@ -1119,31 +1119,31 @@ copyAttributeIntoNode(UA_Server *server, UA_Session *session,
         if(node->nodeClass == UA_NODECLASS_VARIABLE) {
             /* The access to a value variable is granted via the AccessLevel Byte */
             UA_Byte userAccessLevel = getUserAccessLevel(server, session, (const UA_VariableNode*)node);
-            if(!(userAccessLevel & 0x02)) {
+            if(!(userAccessLevel & (UA_ACCESSLEVELMASK_WRITE))) {
                 retval = UA_STATUSCODE_BADUSERACCESSDENIED;
                 break;
             }
         } else { /* UA_NODECLASS_VARIABLETYPE */
-            CHECK_USERWRITEMASK(21);
+            CHECK_USERWRITEMASK(UA_WRITEMASK_VALUEFORVARIABLETYPE);
         }
         retval = writeValueAttribute(server, (UA_VariableNode*)node,
                                      &wvalue->value, &wvalue->indexRange);
         break;
     case UA_ATTRIBUTEID_DATATYPE:
         CHECK_NODECLASS_WRITE(UA_NODECLASS_VARIABLE | UA_NODECLASS_VARIABLETYPE);
-        CHECK_USERWRITEMASK(4);
+        CHECK_USERWRITEMASK(UA_WRITEMASK_DATATYPE);
         CHECK_DATATYPE_SCALAR(NODEID);
         retval = writeDataTypeAttributeWithVT(server, (UA_VariableNode*)node, (const UA_NodeId*)value);
         break;
     case UA_ATTRIBUTEID_VALUERANK:
         CHECK_NODECLASS_WRITE(UA_NODECLASS_VARIABLE | UA_NODECLASS_VARIABLETYPE);
-        CHECK_USERWRITEMASK(19);
+        CHECK_USERWRITEMASK(UA_WRITEMASK_VALUERANK);
         CHECK_DATATYPE_SCALAR(INT32);
         retval = writeValueRankAttributeWithVT(server, (UA_VariableNode*)node, *(const UA_Int32*)value);
         break;
     case UA_ATTRIBUTEID_ARRAYDIMENSIONS:
         CHECK_NODECLASS_WRITE(UA_NODECLASS_VARIABLE | UA_NODECLASS_VARIABLETYPE);
-        CHECK_USERWRITEMASK(1);
+        CHECK_USERWRITEMASK(UA_WRITEMASK_ARRRAYDIMENSIONS);
         CHECK_DATATYPE_ARRAY(UINT32);
         retval = writeArrayDimensionsAttribute(server, (UA_VariableNode*)node,
                                                wvalue->value.value.arrayLength,
@@ -1151,25 +1151,25 @@ copyAttributeIntoNode(UA_Server *server, UA_Session *session,
         break;
     case UA_ATTRIBUTEID_ACCESSLEVEL:
         CHECK_NODECLASS_WRITE(UA_NODECLASS_VARIABLE);
-        CHECK_USERWRITEMASK(0);
+        CHECK_USERWRITEMASK(UA_WRITEMASK_ACCESSLEVEL);
         CHECK_DATATYPE_SCALAR(BYTE);
         ((UA_VariableNode*)node)->accessLevel = *(const UA_Byte*)value;
         break;
     case UA_ATTRIBUTEID_MINIMUMSAMPLINGINTERVAL:
         CHECK_NODECLASS_WRITE(UA_NODECLASS_VARIABLE);
-        CHECK_USERWRITEMASK(12);
+        CHECK_USERWRITEMASK(UA_WRITEMASK_MINIMUMSAMPLINGINTERVAL);
         CHECK_DATATYPE_SCALAR(DOUBLE);
         ((UA_VariableNode*)node)->minimumSamplingInterval = *(const UA_Double*)value;
         break;
     case UA_ATTRIBUTEID_HISTORIZING:
         CHECK_NODECLASS_WRITE(UA_NODECLASS_VARIABLE);
-        CHECK_USERWRITEMASK(9);
+        CHECK_USERWRITEMASK(UA_WRITEMASK_HISTORIZING);
         CHECK_DATATYPE_SCALAR(BOOLEAN);
         ((UA_VariableNode*)node)->historizing = *(const UA_Boolean*)value;
         break;
     case UA_ATTRIBUTEID_EXECUTABLE:
         CHECK_NODECLASS_WRITE(UA_NODECLASS_METHOD);
-        CHECK_USERWRITEMASK(8);
+        CHECK_USERWRITEMASK(UA_WRITEMASK_EXECUTABLE);
         CHECK_DATATYPE_SCALAR(BOOLEAN);
         ((UA_MethodNode*)node)->executable = *(const UA_Boolean*)value;
         break;