server_access_control.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  2. * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
  3. #include <signal.h>
  4. #include <stdio.h>
  5. #include "open62541.h"
  6. static UA_Boolean
  7. allowAddNode(const UA_NodeId *sessionId, void *sessionContext,
  8. const UA_AddNodesItem *item)
  9. {
  10. printf("Called allowAddNode\n");
  11. return UA_TRUE;
  12. }
  13. static UA_Boolean
  14. allowAddReference(const UA_NodeId *sessionId, void *sessionContext,
  15. const UA_AddReferencesItem *item)
  16. {
  17. printf("Called allowAddReference\n");
  18. return UA_TRUE;
  19. }
  20. static UA_Boolean
  21. allowDeleteNode(const UA_NodeId *sessionId, void *sessionContext,
  22. const UA_DeleteNodesItem *item)
  23. {
  24. printf("Called allowDeleteNode\n");
  25. return UA_FALSE; // Do not allow deletion from client
  26. }
  27. static UA_Boolean
  28. allowDeleteReference(const UA_NodeId *sessionId, void *sessionContext,
  29. const UA_DeleteReferencesItem *item)
  30. {
  31. printf("Called allowDeleteReference\n");
  32. return UA_TRUE;
  33. }
  34. UA_Boolean running = true;
  35. static void stopHandler(int sign) {
  36. UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "received ctrl-c");
  37. running = false;
  38. }
  39. int main(void) {
  40. signal(SIGINT, stopHandler);
  41. signal(SIGTERM, stopHandler);
  42. UA_ServerConfig *config = UA_ServerConfig_new_default();
  43. // Set accessControl functions for nodeManagement
  44. config->accessControl.allowAddNode = allowAddNode;
  45. config->accessControl.allowAddReference = allowAddReference;
  46. config->accessControl.allowDeleteNode = allowDeleteNode;
  47. config->accessControl.allowDeleteReference = allowDeleteReference;
  48. UA_Server *server = UA_Server_new(config);
  49. UA_StatusCode retval = UA_Server_run(server, &running);
  50. UA_Server_delete(server);
  51. UA_ServerConfig_delete(config);
  52. return (int)retval;
  53. }