sctp_core.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (C) 2013 Daniel-Constantin Mierla (asipto.com)
  3. *
  4. * This file is part of Kamailio, a free SIP server.
  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 core :: SCTP support
  21. * \ingroup core
  22. * Module: \ref core
  23. */
  24. #include "sctp_core.h"
  25. /**
  26. *
  27. */
  28. static sctp_srapi_t _sctp_srapi = { 0 };
  29. static int _sctp_srapi_set = 0;
  30. /**
  31. *
  32. */
  33. int sctp_core_init(void)
  34. {
  35. if(_sctp_srapi_set==0) {
  36. LM_ERR("SCTP API not initialized\n");
  37. return -1;
  38. }
  39. return _sctp_srapi.init();
  40. }
  41. /**
  42. *
  43. */
  44. void sctp_core_destroy(void)
  45. {
  46. if(_sctp_srapi_set==0) {
  47. LM_INFO("SCTP API not initialized\n");
  48. return;
  49. }
  50. _sctp_srapi.destroy();
  51. }
  52. /**
  53. *
  54. */
  55. int sctp_core_init_sock(struct socket_info* sock_info)
  56. {
  57. return _sctp_srapi.init_sock(sock_info);
  58. }
  59. /**
  60. *
  61. */
  62. int sctp_core_check_support(void)
  63. {
  64. if(_sctp_srapi_set==0) {
  65. LM_INFO("SCTP API not enabled"
  66. " - if you want to use it, load sctp module\n");
  67. return -1;
  68. }
  69. return _sctp_srapi.check_support();
  70. }
  71. /**
  72. *
  73. */
  74. int sctp_core_rcv_loop(void)
  75. {
  76. return _sctp_srapi.rcv_loop();
  77. }
  78. /**
  79. *
  80. */
  81. int sctp_core_msg_send(struct dest_info* dst, char* buf, unsigned len)
  82. {
  83. return _sctp_srapi.msg_send(dst, buf, len);
  84. }
  85. /**
  86. *
  87. */
  88. int sctp_core_register_api(sctp_srapi_t *api)
  89. {
  90. if(api==NULL || api->init==NULL) {
  91. LM_ERR("invalid parameters\n");
  92. return -1;
  93. }
  94. if(_sctp_srapi_set==1) {
  95. LM_ERR("SCTP API already initialized\n");
  96. return -1;
  97. }
  98. _sctp_srapi_set = 1;
  99. memcpy(&_sctp_srapi, api, sizeof(sctp_srapi_t));
  100. return 0;
  101. }