qos.c

00001 /*
00002  * $Id$
00003  *
00004  * QoS module - support for tracking dialogs and SDP
00005  *
00006  * Copyright (C) 2007 SOMA Networks, Inc.
00007  * Written by: Ovidiu Sas (osas)
00008  *
00009  * This file is part of Kamailio, a free SIP server.
00010  *
00011  * Kamailio is free software; you can redistribute it and/or modify it
00012  * under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version
00015  *
00016  * Kamailio is distributed in the hope that it will be useful, but
00017  * WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  * General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024  * USA
00025  *
00026  * History:
00027  * --------
00028  * 2007-07-16 initial version (osas)
00029  */
00030 
00031 #include <stdio.h>
00032 #include <string.h>
00033 #include <stdlib.h>
00034 
00035 #include "../../sr_module.h"
00036 #include "qos_load.h"
00037 #include "qos_handlers.h" /* also includes sr_module.h needed by
00038                              handlers */
00039 
00040 MODULE_VERSION
00041 
00042 static int mod_init(void);
00043 static void mod_destroy(void);
00044 
00045 
00046 /* The qos message flag value */
00047 static int qos_flag = -1;
00048 
00049 /*
00050  * Binding to the dialog module
00051  */
00052 struct dlg_binds dialog_st;
00053 struct dlg_binds *dlg_binds = &dialog_st;
00054 
00055 
00056 static cmd_export_t cmds[]={
00057         {"load_qos", (cmd_function)load_qos, 0, 0, 0, 0},
00058         {0,0,0,0,0,0}
00059 };
00060 
00061 /*
00062  * Script parameters
00063  */
00064 static param_export_t mod_params[]={
00065         { "qos_flag",           INT_PARAM, &qos_flag},
00066         { 0,0,0 }
00067 };
00068 
00069 
00070 struct module_exports exports= {
00071         "qos",           /* module's name */
00072         DEFAULT_DLFLAGS, /* dlopen flags */
00073         cmds,            /* exported functions */
00074         mod_params,      /* param exports */
00075         0,               /* exported statistics */
00076         0,               /* exported MI functions */
00077         0,               /* exported pseudo-variables */
00078         0,               /* extra processes */
00079         mod_init,        /* module initialization function */
00080         0,               /* reply processing function */
00081         mod_destroy,     /* Destroy function */
00082         0                /* per-child init function */
00083 };
00084 
00085 int load_qos( struct qos_binds *qosb)
00086 {
00087         qosb->register_qoscb = register_qoscb;
00088         return 1;
00089 }
00090 
00091 
00099 static int mod_init(void) 
00100 {
00101         if (qos_flag == -1) {
00102                 LM_ERR("no qos flag set!!\n");
00103                 return -1;
00104         } 
00105         else if (qos_flag > MAX_FLAG) {
00106                 LM_ERR("invalid qos flag %d!!\n", qos_flag);
00107                 return -1;
00108         }
00109 
00110         /* init callbacks */
00111         if (init_qos_callbacks()!=0) {
00112                 LM_ERR("cannot init callbacks\n");
00113                 return -1;
00114         }
00115 
00116         /* Register the main (static) dialog call back.  */
00117         if (load_dlg_api(&dialog_st) != 0) {
00118                 LM_ERR("Can't load dialog hooks");
00119                 return(-1);
00120         }
00121 
00122         /* Load dialog hooks */
00123         dialog_st.register_dlgcb(NULL, DLGCB_CREATED, qos_dialog_created_CB, NULL, NULL);
00124 
00125         /*
00126          * We are GOOD-TO-GO.
00127          */
00128         return 0;
00129 }
00130 
00131 static void mod_destroy(void)
00132 {
00133         destroy_qos_callbacks();
00134 }
00135