/src/kamailio/src/core/sctp_core.c
Line | Count | Source (jump to first uncovered line) |
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 | | /*! |
20 | | * \file |
21 | | * \brief Kamailio core :: SCTP support |
22 | | * \ingroup core |
23 | | * Module: \ref core |
24 | | */ |
25 | | |
26 | | #include "sctp_core.h" |
27 | | |
28 | | /** |
29 | | * |
30 | | */ |
31 | | static sctp_srapi_t _sctp_srapi = {0}; |
32 | | static int _sctp_srapi_set = 0; |
33 | | |
34 | | /** |
35 | | * |
36 | | */ |
37 | | int sctp_core_init(void) |
38 | 0 | { |
39 | 0 | if(_sctp_srapi_set == 0) { |
40 | 0 | LM_ERR("SCTP API not initialized\n"); |
41 | 0 | return -1; |
42 | 0 | } |
43 | | |
44 | 0 | return _sctp_srapi.init(); |
45 | 0 | } |
46 | | |
47 | | /** |
48 | | * |
49 | | */ |
50 | | void sctp_core_destroy(void) |
51 | 0 | { |
52 | 0 | if(_sctp_srapi_set == 0) { |
53 | 0 | LM_INFO("SCTP API not initialized\n"); |
54 | 0 | return; |
55 | 0 | } |
56 | | |
57 | 0 | _sctp_srapi.destroy(); |
58 | 0 | } |
59 | | |
60 | | /** |
61 | | * |
62 | | */ |
63 | | int sctp_core_init_sock(struct socket_info *sock_info) |
64 | 0 | { |
65 | 0 | return _sctp_srapi.init_sock(sock_info); |
66 | 0 | } |
67 | | |
68 | | /** |
69 | | * |
70 | | */ |
71 | | int sctp_core_check_support(void) |
72 | 0 | { |
73 | 0 | if(_sctp_srapi_set == 0) { |
74 | 0 | LM_INFO("SCTP API not enabled" |
75 | 0 | " - if you want to use it, load sctp module\n"); |
76 | 0 | return -1; |
77 | 0 | } |
78 | | |
79 | 0 | return _sctp_srapi.check_support(); |
80 | 0 | } |
81 | | |
82 | | /** |
83 | | * |
84 | | */ |
85 | | int sctp_core_rcv_loop(void) |
86 | 0 | { |
87 | 0 | return _sctp_srapi.rcv_loop(); |
88 | 0 | } |
89 | | |
90 | | /** |
91 | | * |
92 | | */ |
93 | | int sctp_core_msg_send(struct dest_info *dst, char *buf, unsigned len) |
94 | 0 | { |
95 | 0 | return _sctp_srapi.msg_send(dst, buf, len); |
96 | 0 | } |
97 | | |
98 | | /** |
99 | | * |
100 | | */ |
101 | | int sctp_core_register_api(sctp_srapi_t *api) |
102 | 0 | { |
103 | 0 | if(api == NULL || api->init == NULL) { |
104 | 0 | LM_ERR("invalid parameters\n"); |
105 | 0 | return -1; |
106 | 0 | } |
107 | 0 | if(_sctp_srapi_set == 1) { |
108 | 0 | LM_ERR("SCTP API already initialized\n"); |
109 | 0 | return -1; |
110 | 0 | } |
111 | 0 | _sctp_srapi_set = 1; |
112 | 0 | memcpy(&_sctp_srapi, api, sizeof(sctp_srapi_t)); |
113 | 0 | return 0; |
114 | 0 | } |