sctp_core.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. * $Id$
  3. *
  4. * Copyright (C) 2013 Daniel-Constantin Mierla (asipto.com)
  5. *
  6. * This file is part of Kamailio, a free SIP server.
  7. *
  8. * Permission to use, copy, modify, and distribute this software for any
  9. * purpose with or without fee is hereby granted, provided that the above
  10. * copyright notice and this permission notice appear in all copies.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  13. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  14. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  15. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  16. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  17. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  18. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  19. */
  20. #include "sctp_core.h"
  21. /**
  22. *
  23. */
  24. static sctp_srapi_t _sctp_srapi = { 0 };
  25. static int _sctp_srapi_set = 0;
  26. /**
  27. *
  28. */
  29. int sctp_core_init(void)
  30. {
  31. if(_sctp_srapi_set==0) {
  32. LM_ERR("SCTP API not initialized\n");
  33. return -1;
  34. }
  35. return _sctp_srapi.init();
  36. }
  37. /**
  38. *
  39. */
  40. void sctp_core_destroy(void)
  41. {
  42. if(_sctp_srapi_set==0) {
  43. LM_INFO("SCTP API not initialized\n");
  44. return;
  45. }
  46. _sctp_srapi.destroy();
  47. }
  48. /**
  49. *
  50. */
  51. int sctp_core_init_sock(struct socket_info* sock_info)
  52. {
  53. return _sctp_srapi.init_sock(sock_info);
  54. }
  55. /**
  56. *
  57. */
  58. int sctp_core_check_support(void)
  59. {
  60. if(_sctp_srapi_set==0) {
  61. LM_INFO("SCTP API not enabled"
  62. " - if you want to use it, load sctp module\n");
  63. return -1;
  64. }
  65. return _sctp_srapi.check_support();
  66. }
  67. /**
  68. *
  69. */
  70. int sctp_core_rcv_loop(void)
  71. {
  72. return _sctp_srapi.rcv_loop();
  73. }
  74. /**
  75. *
  76. */
  77. int sctp_core_msg_send(struct dest_info* dst, char* buf, unsigned len)
  78. {
  79. return _sctp_srapi.msg_send(dst, buf, len);
  80. }
  81. /**
  82. *
  83. */
  84. int sctp_core_register_api(sctp_srapi_t *api)
  85. {
  86. if(api==NULL || api->init==NULL) {
  87. LM_ERR("invalid parameters\n");
  88. return -1;
  89. }
  90. if(_sctp_srapi_set==1) {
  91. LM_ERR("SCTP API already initialized\n");
  92. return -1;
  93. }
  94. _sctp_srapi_set = 1;
  95. memcpy(&_sctp_srapi, api, sizeof(sctp_srapi_t));
  96. return 0;
  97. }