server_certificate.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. #ifdef _MSC_VER
  4. #define _CRT_SECURE_NO_WARNINGS //disable fopen deprication warning in msvs
  5. #endif
  6. #include <stdio.h>
  7. #include <signal.h>
  8. #include <errno.h> // errno, EINTR
  9. #include <stdlib.h>
  10. #include "open62541.h"
  11. #include "common.h"
  12. UA_Boolean running = true;
  13. UA_Logger logger = UA_Log_Stdout;
  14. static void stopHandler(int sign) {
  15. UA_LOG_INFO(logger, UA_LOGCATEGORY_SERVER, "received ctrl-c");
  16. running = false;
  17. }
  18. int main(int argc, char** argv) {
  19. signal(SIGINT, stopHandler); /* catches ctrl-c */
  20. UA_ServerConfig *config = UA_ServerConfig_new_default();
  21. /* load certificate */
  22. config->serverCertificate = loadFile("server_cert.der");
  23. if(config->serverCertificate.length > 0)
  24. UA_LOG_INFO(logger, UA_LOGCATEGORY_SERVER, "Certificate loaded");
  25. UA_Server *server = UA_Server_new(config);
  26. UA_StatusCode retval = UA_Server_run(server, &running);
  27. /* deallocate certificate's memory */
  28. UA_ByteString_deleteMembers(&config->serverCertificate);
  29. UA_Server_delete(server);
  30. UA_ServerConfig_delete(config);
  31. return (int)retval;
  32. }