00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
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>
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;
00060 int enable_full_lr = 0;
00061 str add_username = STR_NULL;
00062 char *cookie_filter = 0;
00063 str user_part_avp = STR_NULL;
00064 str next_route_avp = STR_NULL;
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
00079
00080
00081
00082
00083
00084
00085
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
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,
00119 0,
00120 params,
00121 mod_init,
00122 0,
00123 0,
00124 0,
00125 0
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(¶m,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 }