Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Provide invalid node callback for server #6545

Open
2 of 7 tasks
smitha-cgi opened this issue Jun 16, 2024 · 0 comments
Open
2 of 7 tasks

Feature Request: Provide invalid node callback for server #6545

smitha-cgi opened this issue Jun 16, 2024 · 0 comments

Comments

@smitha-cgi
Copy link

It would be useful for the server to receive a callback when a client attempts to read a node that does not exist (to log an error message or take some other sort of action). I believe this could be done by changing 4 files:

server.h - callback definition

typedef void(*UA_InvalidNodeCallback)(const UA_NodeId *sessionId, const UA_NodeId *nodeId);
void UA_Server_set_invalid_node_callback(UA_Server *server, UA_InvalidNodeCallback cb);

ua_services_attribute.c - invoke the callback when bad node read occurs:


void
Operation_Read(UA_Server *server, UA_Session *session, UA_TimestampsToReturn *ttr,
               const UA_ReadValueId *rvi, UA_DataValue *dv) {
    /* Get the node (with only the selected attribute if the NodeStore supports that) */
    const UA_Node *node =
        UA_NODESTORE_GET_SELECTIVE(server, &rvi->nodeId,
                                   attributeId2AttributeMask((UA_AttributeId)rvi->attributeId),
                                   UA_REFERENCETYPESET_NONE,
                                   UA_BROWSEDIRECTION_INVALID);
    if(!node) {
        dv->hasStatus = true;
        dv->status = UA_STATUSCODE_BADNODEIDUNKNOWN;
		
        if (server->invalidNodeCallback)
        {
	    UA_UNLOCK(server->serviceMutex);
	    server->invalidNodeCallback(session ? &session->sessionId : NULL, &rvi->nodeId);
	    UA_LOCK(server->serviceMutex);
        }
		
        return;
    }

    /* Perform the read operation */
    ReadWithNode(node, server, session, *ttr, rvi, dv);
    UA_NODESTORE_RELEASE(server, node);
}

ua_server_internal.h - callback property

UA_InvalidNodeCallback invalidNodeCallback;

ua_server.c - provide function to set the callback

void UA_Server_set_invalid_node_callback(UA_Server *server, UA_InvalidNodeCallback cb)
{
    server->invalidNodeCallback = cb;
}

Checklist

Please provide the following information:

  • open62541 Version (release number or git tag): 1.4.1
  • Other OPC UA SDKs used (client or server):
  • Operating system: Windows 11
  • Logs (with UA_LOGLEVEL set as low as necessary) attached
  • Wireshark network dump attached
  • Self-contained code example attached
  • Critical issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant