sst.c

Go to the documentation of this file.
00001 /*
00002  * $Id: sst.c 5776 2009-03-30 19:28:47Z henningw $
00003  *
00004  * SIP Session Timer (sst) module - support for tracking dialogs and
00005  * SIP Session Timers.
00006  *
00007  * Copyright (C) 2006 SOMA Networks, INC.
00008  * Written by: Ron Winacott (karwin)
00009  *
00010  * This file is part of Kamailio, a free SIP server.
00011  *
00012  * Kamailio is free software; you can redistribute it and/or modify it
00013  * under the terms of the GNU General Public License as published by
00014  * the Free Software Foundation; either version 2 of the License, or
00015  * (at your option) any later version
00016  *
00017  * Kamailio is distributed in the hope that it will be useful, but
00018  * WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020  * General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU General Public License
00023  * along with this program; if not, write to the Free Software
00024  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00025  * USA
00026  *
00027  * History:
00028  * --------
00029  * 2006-05-11 initial version (karwin)
00030  * 2006-10-10 RFC compilent changes. Added the other flags (karwin)
00031  */
00032 
00033 /*! \file sst/sst.c
00034  *  \brief SST :: Core
00035  *  \ingroup sst
00036  *  Modules: \ref sst
00037  */
00038 
00039 /*! \defgroup sst SIP Session Timers module
00040  * Implementation of SIP Session Timers - a way to make sure a SIP dialog is alive
00041  * and force hangup if a UA involved in a dialog stops responding.
00042  *
00043  *  - \ref SST_support
00044  */
00045 
00046 #include <stdio.h>
00047 #include <string.h>
00048 #include <stdlib.h>
00049 
00050 #include "../sl/sl_api.h"
00051 #include "sst_handlers.h" /* also includes sr_module.h needed by
00052                              handlers */
00053 
00054 MODULE_VERSION
00055 
00056 static int mod_init(void);
00057 
00058 
00059 /** SL binds */
00060 struct sl_binds slb;
00061 
00062 /*
00063  * statistic variables 
00064  */
00065 int sst_enable_stats = 1;
00066 stat_var *expired_sst = 0;
00067 
00068 /*!
00069  * The name of the AVP the dialog module will use to hold the timeout
00070  * value so we can set the AVP in the dialog callbacks so the dialog
00071  * code will set the dialog lifetime when it returns from the INVITE
00072  * and IN_ROUTE callbacks.
00073  */
00074 pv_spec_t timeout_avp; 
00075 static char* timeout_spec = 0; /*!< Place holder for the passed in name */
00076 
00077 /*!
00078  * The default or script parameter for the requested MIN-SE: value for
00079  * this proxy. (in seconds) If the passed in value is 0, then this
00080  * proxy will except any value from the UAC as its min-SE value. If
00081  * the value is NOT set then the default will be asserted.
00082  */
00083 unsigned int sst_minSE = 90; 
00084 
00085 /*!
00086  * Should the PROXY (us) reject (with a 422 reply) and SE < sst_minSE
00087  * requests is it can. Default is YES.
00088  */
00089 unsigned int sst_reject = 1;
00090 
00091 /*! The sst message flag value */
00092 static int sst_flag = -1;
00093 
00094 
00095 /*
00096  * Binding to the dialog module
00097  */
00098 struct dlg_binds dialog_st;
00099 struct dlg_binds *dlg_binds = &dialog_st;
00100 
00101 /*
00102  * Script commands we export.
00103  */
00104 static cmd_export_t cmds[]={
00105    {"sstCheckMin", (cmd_function)sst_check_min, 1, 0, 0, REQUEST_ROUTE | ONREPLY_ROUTE },
00106    {0,0,0,0,0,0}
00107 };
00108 
00109 /*
00110  * Script parameters
00111  */
00112 static param_export_t mod_params[]={
00113    { "enable_stats", INT_PARAM, &sst_enable_stats        },
00114    { "min_se", INT_PARAM, &sst_minSE            },
00115    { "timeout_avp", STR_PARAM, &timeout_spec       },
00116    { "reject_to_small",    INT_PARAM, &sst_reject     },
00117    { "sst_flag",           INT_PARAM, &sst_flag },
00118    { 0,0,0 }
00119 };
00120 
00121 /*
00122  * Export the statistics we have
00123  */
00124 static stat_export_t mod_stats[] = {
00125    {"expired_sst", 0,  &expired_sst},
00126    {0,0,0}
00127 };
00128 
00129 struct module_exports exports= {
00130    "sst",        /* module's name */
00131    DEFAULT_DLFLAGS, /* dlopen flags */
00132    cmds,         /* exported functions */
00133    mod_params,   /* param exports */
00134    mod_stats,    /* exported statistics */
00135    0,            /* exported MI functions */
00136    0,            /* exported pseudo-variables */
00137    0,            /* extra processes */
00138    mod_init,     /* module initialization function */
00139    0,            /* reply processing function */
00140    0,            /* Destroy function */
00141    0             /* per-child init function */
00142 };
00143 
00144 /**
00145  * The initialization function, called when the module is loaded by
00146  * the script. This function is called only once.
00147  *
00148  * Bind to the dialog module and setup the callbacks. Also initialize
00149  * the shared memory to store our interninal information in.
00150  *
00151  * @return 0 to continue to load the Kamailio, -1 to stop the loading
00152  * and abort Kamailio.
00153  */
00154 static int mod_init(void) 
00155 {
00156    str s;
00157    /* if statistics are disabled, prevent their registration to core. */
00158    if (sst_enable_stats==0) {
00159       exports.stats = 0;
00160    }
00161 
00162    if (sst_flag == -1) {
00163       LM_ERR("no sst flag set!!\n");
00164       return -1;
00165    } 
00166    else if (sst_flag > MAX_FLAG) {
00167       LM_ERR("invalid sst flag %d!!\n", sst_flag);
00168       return -1;
00169    }
00170 
00171    if (timeout_spec != NULL) {
00172       LM_DBG("Dialog AVP is %s", timeout_spec);
00173       s.s = timeout_spec; s.len = strlen(s.s);
00174       if (pv_parse_spec(&s, &timeout_avp)==0 
00175       && (timeout_avp.type != PVT_AVP)){
00176          LM_ERR("malformed or non AVP timeout AVP definition in '%s'\n",
00177                timeout_spec);
00178          return -1;
00179       }
00180    }
00181 
00182    /* load the SL API */
00183    if (load_sl_api(&slb)!=0) {
00184       LM_ERR("failed to load SL API\n");
00185       return -1;
00186    }
00187 
00188    /* Init the handlers */
00189    sst_handler_init((timeout_spec?&timeout_avp:0), sst_minSE, 
00190          sst_flag, sst_reject);
00191 
00192    /* Register the main (static) dialog call back. */
00193    if (load_dlg_api(&dialog_st) != 0) {
00194       LM_ERR("failed to load dialog hooks");
00195       return(-1);
00196    }
00197 
00198    /* Load dialog hooks */
00199    dialog_st.register_dlgcb(NULL, DLGCB_CREATED, sst_dialog_created_CB, NULL, NULL);
00200 
00201    return 0;
00202 }

Generated on Thu May 24 12:00:31 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6