Sfoglia il codice sorgente

Correct Event validity check

Make sure the EventType is not a Subtype of CondtionType (Part 9 not supported yet).
1) The check should ignore the "ConditionId" Clause set by UaExpert and ignore all Events which are Conditions. (However, if a Condition Event was created and UaExpert is used, then all the Fields of that Event except the "ConditionId" will be presenet in the Event View) -> The User should not use Events which are Conditions in that case!
2) The second check is to make sure the Event has a TypeDefinition of an BaseEventType SubType.
Sameer AL-Qadasi 6 anni fa
parent
commit
d6f650c36b
1 ha cambiato i file con 30 aggiunte e 3 eliminazioni
  1. 30 3
      src/server/ua_subscription_events.c

+ 30 - 3
src/server/ua_subscription_events.c

@@ -143,9 +143,36 @@ isValidEvent(UA_Server *server, const UA_NodeId *validEventParent, const UA_Node
         UA_BrowsePathResult_deleteMembers(&bpr);
         return UA_FALSE;
     }
+    
+	/* get the EventType Property Node */
+    const UA_Node* tLeafNode = UA_Nodestore_get(server, &bpr.targets[0].targetId.nodeId);
+    UA_Variant tOutVariant;
+    /* read the Value of EventType Property Node (the Value should be a NodeId) */
+    UA_Server_readValue(server, tLeafNode->nodeId, &tOutVariant);
+    UA_NodeId tEventType = *((UA_NodeId*)tOutVariant.data);
+
+    /* Make sure the EventType is not a Subtype of CondtionType
+     * First check for filter set using UaExpert
+     * (ConditionId Clause won't be present in Events, which are not Conditions)
+     * Second check for Events which are Conditions or Alarms (Part 9 not supported yet) */
+    UA_NodeId conditionTypeId = UA_NODEID_NUMERIC(0, UA_NS0ID_CONDITIONTYPE);
     UA_NodeId hasSubtypeId = UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE);
-    UA_Boolean tmp = isNodeInTree(&server->config.nodestore, &bpr.targets[0].targetId.nodeId,
-                                  validEventParent, &hasSubtypeId, 1);
+    if(UA_NodeId_equal(validEventParent, &conditionTypeId) ||
+       isNodeInTree(&server->config.nodestore, &tEventType, 
+    		         &conditionTypeId, &hasSubtypeId, 1)){
+        UA_LOG_ERROR(server->config.logger, UA_LOGCATEGORY_USERLAND,
+    	         "Alarms and Conditions are not supported yet!");
+        UA_Nodestore_release(server, (const UA_Node *) tLeafNode);
+        UA_BrowsePathResult_deleteMembers(&bpr);
+        return UA_FALSE;
+    }
+
+    /* check whether Valid Event other than Conditions */
+    UA_NodeId baseEventTypeId = UA_NODEID_NUMERIC(0, UA_NS0ID_BASEEVENTTYPE);
+    UA_Boolean tmp = isNodeInTree(&server->config.nodestore, &tEventType,
+                                  &baseEventTypeId, &hasSubtypeId, 1);
+
+    UA_Nodestore_release(server, (const UA_Node *) tLeafNode);
     UA_BrowsePathResult_deleteMembers(&bpr);
     return tmp;
 }
@@ -248,7 +275,7 @@ UA_Server_filterEvent(UA_Server *server, UA_Session *session,
     /* iterate over the selectClauses */
     for(size_t i = 0; i < filter->selectClausesSize; i++) {
         if(!UA_NodeId_equal(&filter->selectClauses[i].typeDefinitionId, &baseEventTypeId) &&
-           !isValidEvent(server, &filter->selectClauses[0].typeDefinitionId, eventNode)) {
+           !isValidEvent(server, &filter->selectClauses[i].typeDefinitionId, eventNode)) {
             UA_Variant_init(&notification->fields.eventFields[i]);
             /* EventFilterResult currently isn't being used
             notification->result.selectClauseResults[i] = UA_STATUSCODE_BADTYPEDEFINITIONINVALID; */