Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (C) 2016 OpenSIPS Solutions |
3 | | * |
4 | | * This file is part of opensips, a free SIP server. |
5 | | * |
6 | | * opensips is free software; you can redistribute it and/or |
7 | | * modify it under the terms of the GNU General Public License |
8 | | * as published by the Free Software Foundation; either version 2 |
9 | | * of the License, or (at your option) any later version. |
10 | | * |
11 | | * opensips is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | * GNU General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU General Public License |
17 | | * along with this program; if not, write to the Free Software |
18 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
19 | | * |
20 | | * |
21 | | * History: |
22 | | * --------- |
23 | | * 2016-02-01 first version (bogdan) |
24 | | */ |
25 | | |
26 | | |
27 | | #include "mem/mem.h" |
28 | | #include "sl_cb.h" |
29 | | |
30 | | |
31 | | struct sl_callback { |
32 | | sl_cb_t* callback; /* callback function */ |
33 | | unsigned int fmask; /* bitmask to match msg_flags */ |
34 | | struct sl_callback* next; /* next callback element*/ |
35 | | }; |
36 | | |
37 | | struct sl_callback* slcb_hl[SLCB_LAST]; /* heads of lists (per type) */ |
38 | | |
39 | | |
40 | | |
41 | | void destroy_slcb_lists(void) |
42 | 0 | { |
43 | 0 | struct sl_callback *cbp, *cbp_tmp; |
44 | 0 | unsigned int i; |
45 | |
|
46 | 0 | for( i=0 ; i<SLCB_LAST ; i++) { |
47 | 0 | for( cbp=slcb_hl[i]; cbp ; ) { |
48 | 0 | cbp_tmp = cbp; |
49 | 0 | cbp = cbp->next; |
50 | 0 | pkg_free( cbp_tmp ); |
51 | 0 | } |
52 | 0 | } |
53 | 0 | } |
54 | | |
55 | | |
56 | | int register_slcb(enum sl_cb_type type, unsigned int fmask, sl_cb_t f) |
57 | 0 | { |
58 | 0 | struct sl_callback *cbp; |
59 | | |
60 | | /* build a new callback structure */ |
61 | 0 | if (!(cbp=pkg_malloc( sizeof( struct sl_callback)))) { |
62 | 0 | LM_ERR("out of pkg. mem\n"); |
63 | 0 | return -1; |
64 | 0 | } |
65 | | |
66 | | /* fill it up */ |
67 | 0 | cbp->callback = f; |
68 | 0 | cbp->fmask = fmask; |
69 | | /* link it at the beginning of the list */ |
70 | 0 | cbp->next = slcb_hl[type]; |
71 | 0 | slcb_hl[type] = cbp; |
72 | |
|
73 | 0 | return 0; |
74 | 0 | } |
75 | | |
76 | | |
77 | | void slcb_run_reply_out(struct sip_msg *req, str *buffer, |
78 | | union sockaddr_union *dst, int rpl_code) |
79 | 0 | { |
80 | 0 | struct sl_callback *cbp; |
81 | |
|
82 | 0 | for ( cbp=slcb_hl[SLCB_REPLY_OUT] ; cbp ; cbp=cbp->next ) { |
83 | 0 | if (cbp->fmask==0 || cbp->fmask&req->msg_flags) { |
84 | 0 | cbp->callback( req, buffer, rpl_code, dst, NULL, 0); |
85 | 0 | } |
86 | 0 | } |
87 | 0 | } |
88 | | |
89 | | |
90 | | void slcb_run_ack_in(struct sip_msg *req) |
91 | 0 | { |
92 | 0 | struct sl_callback *cbp; |
93 | |
|
94 | 0 | for ( cbp=slcb_hl[SLCB_ACK_IN] ; cbp ; cbp=cbp->next ) { |
95 | 0 | if (cbp->fmask==0 || cbp->fmask&req->msg_flags) { |
96 | 0 | cbp->callback( req, NULL, 0, NULL, NULL, 0); |
97 | 0 | } |
98 | 0 | } |
99 | 0 | } |
100 | | |
101 | | |
102 | | void slcb_run_req_out(struct sip_msg *req, str *buffer, |
103 | | const union sockaddr_union *dst, const struct socket_info *sock, int proto) |
104 | 0 | { |
105 | 0 | struct sl_callback *cbp; |
106 | |
|
107 | 0 | for ( cbp=slcb_hl[SLCB_REQUEST_OUT] ; cbp ; cbp=cbp->next ) { |
108 | 0 | if (cbp->fmask==0 || cbp->fmask&req->msg_flags) { |
109 | 0 | cbp->callback( req, buffer, 0, dst, sock, proto); |
110 | 0 | } |
111 | 0 | } |
112 | 0 | } |
113 | | |
114 | | |