1 /*
2  * QoS module - support for tracking dialogs and SDP
3  *
4  * Copyright (C) 2007 SOMA Networks, Inc.
5  * Written by: Ovidiu Sas (osas)
6  *
7  * This file is part of Kamailio, a free SIP server.
8  *
9  * Kamailio is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version
13  *
14  * Kamailio is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
22  * USA
23  *
24  */
25 
26 #include <stdio.h>
27 #include <string.h>
28 #include <stdlib.h>
29 
30 #include "../../core/sr_module.h"
31 #include "qos_load.h"
32 #include "qos_handlers.h" /* also includes sr_module.h needed by
33                              handlers */
34 
35 MODULE_VERSION
36 
37 static int mod_init(void);
38 static void mod_destroy(void);
39 
40 
41 /* The qos message flag value */
42 static int qos_flag = -1;
43 
44 /*
45  * Binding to the dialog module
46  */
47 struct dlg_binds dialog_st;
48 struct dlg_binds *dlg_binds = &dialog_st;
49 
50 
51 static cmd_export_t cmds[]={
52 	{"load_qos", (cmd_function)load_qos, 0, 0, 0, 0},
53 	{0,0,0,0,0,0}
54 };
55 
56 /*
57  * Script parameters
58  */
59 static param_export_t mod_params[]={
60 	{ "qos_flag",		INT_PARAM, &qos_flag},
61 	{ 0,0,0 }
62 };
63 
64 
65 struct module_exports exports= {
66 	"qos",           /* module's name */
67 	DEFAULT_DLFLAGS, /* dlopen flags */
68 	cmds,            /* exported functions */
69 	mod_params,      /* param exports */
70 	0,               /* exported RPC functions */
71 	0,               /* exported pseudo-variables */
72 	0,               /* reply processing function */
73 	mod_init,        /* module initialization function */
74 	0,               /* per-child init function */
75 	mod_destroy      /* module destroy function */
76 };
77 
load_qos(struct qos_binds * qosb)78 int load_qos( struct qos_binds *qosb)
79 {
80 	qosb->register_qoscb = register_qoscb;
81 	return 1;
82 }
83 
84 
85 /**
86  * The initialization function, called when the module is loaded by
87  * the script. This function is called only once.
88  *
89  * Bind to the dialog module and setup the callbacks. Also initialize
90  * the shared memory to store our interninal information in.
91  */
mod_init(void)92 static int mod_init(void)
93 {
94 	if (qos_flag == -1) {
95 		LM_ERR("no qos flag set!!\n");
96 		return -1;
97 	}
98 	else if (qos_flag > MAX_FLAG) {
99 		LM_ERR("invalid qos flag %d!!\n", qos_flag);
100 		return -1;
101 	}
102 
103 	/* init callbacks */
104 	if (init_qos_callbacks()!=0) {
105 		LM_ERR("cannot init callbacks\n");
106 		return -1;
107 	}
108 
109 	/* Register the main (static) dialog call back.  */
110 	if (load_dlg_api(&dialog_st) != 0) {
111 		LM_ERR("Can't load dialog hooks\n");
112 		return(-1);
113 	}
114 
115 	/* Load dialog hooks */
116 	dialog_st.register_dlgcb(NULL, DLGCB_CREATED, qos_dialog_created_CB, NULL, NULL);
117 
118 	/*
119 	 * We are GOOD-TO-GO.
120 	 */
121 	return 0;
122 }
123 
mod_destroy(void)124 static void mod_destroy(void)
125 {
126 	destroy_qos_callbacks();
127 }
128 
129