server_certificate.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 <ua_server.h>
  7. #include <ua_config_default.h>
  8. #include <ua_log_stdout.h>
  9. #include "common.h"
  10. #include <signal.h>
  11. UA_Boolean running = true;
  12. static void stopHandler(int sign) {
  13. UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "received ctrl-c");
  14. running = false;
  15. }
  16. int main(int argc, char** argv) {
  17. signal(SIGINT, stopHandler); /* catches ctrl-c */
  18. UA_ServerConfig *config = UA_ServerConfig_new_default();
  19. /* load certificate */
  20. config->serverCertificate = loadFile("server_cert.der");
  21. if(config->serverCertificate.length > 0)
  22. UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "Certificate loaded");
  23. UA_Server *server = UA_Server_new(config);
  24. UA_StatusCode retval = UA_Server_run(server, &running);
  25. /* deallocate certificate's memory */
  26. UA_ByteString_clear(&config->serverCertificate);
  27. UA_Server_delete(server);
  28. UA_ServerConfig_delete(config);
  29. return (int)retval;
  30. }