Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

rr_mod.c

Go to the documentation of this file.
00001 /*
00002  * Route & Record-Route module
00003  *
00004  * $Id: rr_mod.c,v 1.54 2007/07/24 12:17:27 tma0 Exp $
00005  *
00006  * Copyright (C) 2001-2003 FhG Fokus
00007  *
00008  * This file is part of ser, a free SIP server.
00009  *
00010  * ser is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version
00014  *
00015  * For a license to use the ser software under conditions
00016  * other than those described here, or to purchase support for this
00017  * software, please contact iptel.org by e-mail at the following addresses:
00018  *    info@iptel.org
00019  *
00020  * ser is distributed in the hope that it will be useful,
00021  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  * GNU General Public License for more details.
00024  *
00025  * You should have received a copy of the GNU General Public License
00026  * along with this program; if not, write to the Free Software
00027  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00028  */
00029 /* History:
00030  * --------
00031  *  2003-03-11  updated to the new module interface (andrei)
00032  *  2003-03-16  flags export parameter added (janakj)
00033  *  2003-03-19  all mallocs/frees replaced w/ pkg_malloc/pkg_free (andrei)
00034  *  2003-04-01  Added record_route with ip address parameter (janakj)
00035  *  2003-04-14  enable_full_lr parameter introduced (janakj)
00036  */
00037 
00038 
00039 #include <stdio.h>
00040 #include <stdlib.h>
00041 #include "rr_mod.h"
00042 #include "../../sr_module.h"
00043 #include "../../ut.h"
00044 #include "../../error.h"
00045 #include "../../mem/mem.h"
00046 #include "loose.h"
00047 #include "record.h"
00048 #include "avp_cookie.h"
00049 #include <sys/types.h> /* for regex */
00050 #include <regex.h>
00051 #include "../../script_cb.h"
00052 #include "../../usr_avp.h"
00053 #include "../../crc.h"
00054 #include "../../select.h"
00055 #include "../domain/domain.h"
00056 #include "../../select_buf.h"
00057 
00058 int append_fromtag = 1;
00059 int enable_double_rr = 1; /* Enable using of 2 RR by default */
00060 int enable_full_lr = 0;   /* Disabled by default */
00061 str add_username = STR_NULL;   /* Do not add username by default */
00062 char *cookie_filter = 0;       /* filter cookies restored in loose_route, potential security problem */
00063 str user_part_avp = STR_NULL;  /* AVP identification where user part of Route URI is stored after loose/strict routing */
00064 str next_route_avp = STR_NULL; /* AVP identification where next route (if exists) would be stored after loose/strict routing */
00065 static str crc_secret_str = STR_NULL;
00066 avp_ident_t user_part_avp_ident;
00067 avp_ident_t next_route_avp_ident;
00068 
00069 fparam_t* fparam_username = NULL;
00070 
00071 MODULE_VERSION
00072 
00073 static int mod_init(void);
00074 
00075 domain_get_did_t dm_get_did = 0;
00076 
00077 /*
00078  * Exported functions
00079  */
00080 /*
00081  * I do not want people to use strict routing so it is disabled by default,
00082  * you should always use loose routing, if you really need strict routing then
00083  * you can replace the last zeroes with REQUEST_ROUTE to enable strict_route and
00084  * record_route_strict. Don't do that unless you know what you are really doing !
00085  * Oh, BTW, have I mentioned already that you shouldn't use strict routing ?
00086  */
00087 static cmd_export_t cmds[] = {
00088         {"loose_route",          loose_route,         0, 0,           REQUEST_ROUTE},
00089         {"record_route",         record_route,        0, 0,           REQUEST_ROUTE},
00090         {"record_route_preset",  record_route_preset, 1, fixup_str_1, REQUEST_ROUTE},
00091         {"record_route_strict" , record_route_strict, 0, 0,           0            },
00092         {"remove_record_route",  remove_record_route, 0, 0,           REQUEST_ROUTE|FAILURE_ROUTE},
00093         {0, 0, 0, 0, 0}
00094 };
00095 
00096 
00097 /*
00098  * Exported parameters
00099  */
00100 static param_export_t params[] ={
00101         {"append_fromtag",   PARAM_INT,    &append_fromtag  },
00102         {"enable_double_rr", PARAM_INT,    &enable_double_rr},
00103         {"enable_full_lr",   PARAM_INT,    &enable_full_lr  },
00104 #ifdef ENABLE_USER_CHECK
00105         {"ignore_user",      PARAM_STR,    &i_user     },
00106 #endif
00107         {"add_username",     PARAM_STR,    &add_username    },
00108         {"cookie_filter",    PARAM_STRING, &cookie_filter   },
00109         {"cookie_secret",    PARAM_STR,    &crc_secret_str  },
00110         {"user_part_avp",    PARAM_STR,    &user_part_avp   },
00111         {"next_route_avp",   PARAM_STR,    &next_route_avp  },
00112         {0, 0, 0 }
00113 };
00114 
00115 
00116 struct module_exports exports = {
00117         "rr",
00118         cmds,        /* Exported functions */
00119         0,           /* RPC methods */
00120         params,      /* Exported parameters */
00121         mod_init,    /* initialize module */
00122         0,           /* response function*/
00123         0,           /* destroy function */
00124         0,           /* oncancel function */
00125         0            /* per-child init function */
00126 };
00127 
00128 
00129 static ABSTRACT_F(select_rrmod)
00130 
00131 static int select_rr_avpcookie(str* res, struct select* s, struct sip_msg* msg) {
00132         str *s2;
00133         int ret;
00134         s2 = rr_get_avp_cookies();
00135         if (s2) {
00136             ret = str_to_static_buffer(res, s2);
00137             pkg_free(s2);
00138             return ret;
00139         }
00140         else
00141             return -1;
00142 }
00143 
00144 static select_row_t rr_select_table[] = {
00145         { NULL, SEL_PARAM_STR, STR_STATIC_INIT("rr"), select_rrmod, SEL_PARAM_EXPECTED},
00146         { select_rrmod, SEL_PARAM_STR, STR_STATIC_INIT("dialog_cookie"), select_rr_avpcookie, 0},
00147         { NULL, SEL_PARAM_INT, STR_NULL, NULL, 0}
00148 };
00149  
00150 
00151 static int mod_init(void)
00152 {
00153         void* param;
00154 
00155         DBG("rr - initializing\n");
00156         crc_secret = crcitt_string(crc_secret_str.s, crc_secret_str.len);
00157         if (cookie_filter && strlen(cookie_filter)) {
00158                 cookie_filter_re = (regex_t*)pkg_malloc(sizeof(regex_t));
00159                 memset(cookie_filter_re, 0, sizeof(regex_t));
00160                 if (regcomp(cookie_filter_re, cookie_filter, REG_EXTENDED|REG_ICASE|REG_NEWLINE) ) {
00161                         LOG(L_ERR, "ERROR: %s : bad cookie_filter regex '%s'\n", exports.name, cookie_filter);
00162                         return E_BAD_RE;
00163                 }
00164         }
00165 
00166         memset (&user_part_avp_ident, 0, sizeof(avp_ident_t));
00167         if (user_part_avp.s && user_part_avp.len) {
00168                 if (parse_avp_ident(&user_part_avp, &user_part_avp_ident)!=0) {
00169                         ERR("modparam \"user_part_avp\" : error while parsing\n");
00170                         return E_CFG;
00171                 }
00172         }
00173         memset (&next_route_avp_ident, 0, sizeof(avp_ident_t));
00174         if (next_route_avp.s && next_route_avp.len) {
00175                 if (parse_avp_ident(&next_route_avp, &next_route_avp_ident)!=0) {
00176                         ERR("modparam \"next_route_avp\" : error while parsing\n");
00177                         return E_CFG;
00178                 }
00179         }
00180         avp_flag_dialog = register_avpflag(AVP_FLAG_DIALOG_COOKIE);
00181         if (avp_flag_dialog == 0) {
00182                 LOG(L_ERR, "ERROR: %s: cannot register avpflag \"%s\"\n", exports.name, AVP_FLAG_DIALOG_COOKIE);
00183                 return E_CFG;
00184         }
00185 
00186         register_select_table(rr_select_table);
00187 
00188         dm_get_did = (domain_get_did_t)find_export("get_did", 0, 0);
00189         if (!dm_get_did) {
00190             DBG("Domain module not found, rr support for multidomain disabled\n");
00191         }
00192         
00193         if (add_username.s) {
00194                 param=(void*)add_username.s;
00195                 if (fixup_var_str_12(&param,1)<0) {
00196                         ERR("rr:mod_init:can't fixup add_username parameter\n");
00197                         return E_CFG;
00198                 }
00199                 fparam_username=(fparam_t*)param;
00200         }
00201 
00202         return 0;
00203 }

Generated on Thu Sep 9 04:15:57 2010 for SIPExpressRouter by  doxygen 1.3.9.1