tls_util.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * TLS module
  3. *
  4. * Copyright (C) 2010 iptelorg GmbH
  5. *
  6. * Permission to use, copy, modify, and distribute this software for any
  7. * purpose with or without fee is hereby granted, provided that the above
  8. * copyright notice and this permission notice appear in all copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  11. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  13. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  16. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. /*!
  19. * \file
  20. * \brief Kamailio TLS support :: Common functions
  21. * \ingroup tls
  22. * Module: \ref tls
  23. */
  24. #ifndef _TLS_UTIL_H
  25. #define _TLS_UTIL_H
  26. #include <openssl/err.h>
  27. #include "../../dprint.h"
  28. #include "../../str.h"
  29. #include "tls_domain.h"
  30. static inline int tls_err_ret(char *s, tls_domains_cfg_t **tls_domains_cfg) {
  31. long err;
  32. int ret = 0;
  33. if ((*tls_domains_cfg)->srv_default->ctx &&
  34. (*tls_domains_cfg)->srv_default->ctx[0])
  35. {
  36. while((err = ERR_get_error())) {
  37. ret = 1;
  38. ERR("%s%s\n", s ? s : "", ERR_error_string(err, 0));
  39. }
  40. }
  41. return ret;
  42. }
  43. #define TLS_ERR_RET(r, s) \
  44. do { \
  45. (r) = tls_err_ret((s), tls_domains_cfg); \
  46. } while(0)
  47. #define TLS_ERR(s) \
  48. do { \
  49. tls_err_ret((s), tls_domains_cfg); \
  50. } while(0)
  51. /*
  52. * Make a shared memory copy of ASCII zero terminated string
  53. * Return value: -1 on error
  54. * 0 on success
  55. */
  56. int shm_asciiz_dup(char** dest, char* val);
  57. /*
  58. * Delete old TLS configuration that is not needed anymore
  59. */
  60. void collect_garbage(void);
  61. #endif /* _TLS_UTIL_H */