12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- /* 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 "open62541.h"
- #include <signal.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;
- }
|