123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- /* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
- * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
- #include <signal.h>
- #include <stdio.h>
- #include "open62541.h"
- static UA_Boolean
- allowAddNode(UA_Server *server, UA_AccessControl *ac,
- const UA_NodeId *sessionId, void *sessionContext,
- const UA_AddNodesItem *item) {
- printf("Called allowAddNode\n");
- return UA_TRUE;
- }
- static UA_Boolean
- allowAddReference(UA_Server *server, UA_AccessControl *ac,
- const UA_NodeId *sessionId, void *sessionContext,
- const UA_AddReferencesItem *item) {
- printf("Called allowAddReference\n");
- return UA_TRUE;
- }
- static UA_Boolean
- allowDeleteNode(UA_Server *server, UA_AccessControl *ac,
- const UA_NodeId *sessionId, void *sessionContext,
- const UA_DeleteNodesItem *item) {
- printf("Called allowDeleteNode\n");
- return UA_FALSE; // Do not allow deletion from client
- }
- static UA_Boolean
- allowDeleteReference(UA_Server *server, UA_AccessControl *ac,
- const UA_NodeId *sessionId, void *sessionContext,
- const UA_DeleteReferencesItem *item) {
- printf("Called allowDeleteReference\n");
- return UA_TRUE;
- }
- UA_Boolean running = true;
- static void stopHandler(int sign) {
- UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "received ctrl-c");
- running = false;
- }
- int main(void) {
- signal(SIGINT, stopHandler);
- signal(SIGTERM, stopHandler);
- UA_ServerConfig *config = UA_ServerConfig_new_default();
- // Set accessControl functions for nodeManagement
- config->accessControl.allowAddNode = allowAddNode;
- config->accessControl.allowAddReference = allowAddReference;
- config->accessControl.allowDeleteNode = allowDeleteNode;
- config->accessControl.allowDeleteReference = allowDeleteReference;
- UA_Server *server = UA_Server_new(config);
- UA_StatusCode retval = UA_Server_run(server, &running);
- UA_Server_delete(server);
- UA_ServerConfig_delete(config);
- return (int)retval;
- }
|