1 /**
2  *
3  * Copyright (C) 2009 SIP-Router.org
4  *
5  * This file is part of Kamailio, a free SIP server.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef _SR_EVENTS_H_
21 #define _SR_EVENTS_H_
22 
23 #include "parser/msg_parser.h"
24 
25 #define SREV_NET_DATA_IN		1
26 #define SREV_NET_DATA_OUT		2
27 #define SREV_CORE_STATS			3
28 #define SREV_CFG_RUN_ACTION		4
29 #define SREV_PKG_UPDATE_STATS		5
30 #define SREV_RCV_NOSIP			6
31 #define SREV_NET_DGRAM_IN		7
32 #define SREV_TCP_HTTP_100C		8
33 #define SREV_TCP_MSRP_FRAME		9
34 #define SREV_TCP_WS_FRAME_IN		10
35 #define SREV_TCP_WS_FRAME_OUT		11
36 #define SREV_STUN_IN			12
37 #define SREV_TCP_CLOSED			13
38 #define SREV_NET_DATA_RECV		14
39 #define SREV_NET_DATA_SENT		15
40 #define SREV_SIP_REPLY_OUT		16
41 
42 #define SREV_CB_LIST_SIZE	8
43 
44 typedef struct sr_event_param {
45 	void *data;
46 	str obuf;
47 	receive_info_t* rcv;
48 	dest_info_t *dst;
49 	sip_msg_t *req;
50 	sip_msg_t *rpl;
51 	int rplcode;
52 	int mode;
53 } sr_event_param_t;
54 
55 typedef int (*sr_event_cb_f)(sr_event_param_t *evp);
56 
57 typedef struct sr_event_cb {
58 	sr_event_cb_f net_data_in[SREV_CB_LIST_SIZE];
59 	sr_event_cb_f net_data_out[SREV_CB_LIST_SIZE];
60 	sr_event_cb_f core_stats;
61 	sr_event_cb_f run_action;
62 	sr_event_cb_f pkg_update_stats;
63 	sr_event_cb_f net_dgram_in;
64 	sr_event_cb_f tcp_http_100c;
65 	sr_event_cb_f tcp_msrp_frame;
66 	sr_event_cb_f tcp_ws_frame_in;
67 	sr_event_cb_f tcp_ws_frame_out;
68 	sr_event_cb_f stun_in;
69 	sr_event_cb_f rcv_nosip;
70 	sr_event_cb_f tcp_closed;
71 	sr_event_cb_f net_data_recv;
72 	sr_event_cb_f net_data_sent;
73 	sr_event_cb_f sip_reply_out[SREV_CB_LIST_SIZE];
74 } sr_event_cb_t;
75 
76 void sr_event_cb_init(void);
77 int sr_event_register_cb(int type, sr_event_cb_f f);
78 int sr_event_exec(int type, sr_event_param_t *evp);
79 int sr_event_enabled(int type);
80 
81 
82 /* shortcut types for core event routes */
83 /* initial parsing error in message receive function */
84 #define SR_CORE_ERT_RECEIVE_PARSE_ERROR		1
85 
86 void sr_core_ert_init(void);
87 void sr_core_ert_run(sip_msg_t *msg, int e);
88 
89 typedef void (*sr_corecb_void_f)(void);
90 typedef struct sr_corecb {
91 	sr_corecb_void_f app_ready;
92 	sr_corecb_void_f app_shutdown;
93 } sr_corecb_t;
94 
95 sr_corecb_t *sr_corecb_get(void);
96 
97 #define sr_corecb_void_exec(fname) \
98 	do { \
99 		sr_corecb_t *__cbp = sr_corecb_get(); \
100 		if(__cbp && __cbp->fname) { \
101 			__cbp->fname(); \
102 		} \
103 	} while(0);
104 
105 #endif
106