opensips/opensips.patch.lcr

changeset 397
c98ae03f4266
parent 396
610cba0674b9
child 398
08f5eb82b58f
     1.1 --- a/opensips/opensips.patch.lcr	Thu Dec 01 13:24:24 2011 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,384 +0,0 @@
     1.4 -Index: modules/lcr/lcr_mod.c
     1.5 -diff -Nau modules/lcr/lcr_mod.c.orig modules/lcr/lcr_mod.c
     1.6 ---- modules/lcr/lcr_mod.c.orig	2009-03-09 14:42:46.000000000 +0100
     1.7 -+++ modules/lcr/lcr_mod.c	2009-03-24 22:50:37.363366116 +0100
     1.8 -@@ -114,9 +114,18 @@
     1.9 - 
    1.10 - #define PRIORITY_COL "priority"
    1.11 - 
    1.12 -+#define USER_COL "usid"
    1.13 -+
    1.14 -+#define REALM_COL "realm"
    1.15 -+
    1.16 -+#define PASSWD_COL "passwd"
    1.17 -+
    1.18 - #define MAX_NO_OF_GWS 32
    1.19 - #define MAX_NO_OF_LCRS 256
    1.20 - #define MAX_PREFIX_LEN 256
    1.21 -+#define MAX_USER_LEN 64
    1.22 -+#define MAX_REALM_LEN 64
    1.23 -+#define MAX_PASSWD_LEN 64
    1.24 - #define MAX_TAG_LEN 16
    1.25 - #define MAX_FROM_URI_LEN 256
    1.26 - 
    1.27 -@@ -141,6 +150,12 @@
    1.28 -     char tag[MAX_TAG_LEN + 1];
    1.29 -     unsigned short tag_len;
    1.30 -     unsigned int flags;
    1.31 -+    char user[MAX_USER_LEN];
    1.32 -+    unsigned short user_len;
    1.33 -+    char realm[MAX_REALM_LEN];
    1.34 -+    unsigned short realm_len;
    1.35 -+    char passwd[MAX_PASSWD_LEN];
    1.36 -+    unsigned short passwd_len;
    1.37 - };
    1.38 - 
    1.39 - struct lcr_info {
    1.40 -@@ -196,6 +211,9 @@
    1.41 - static str prefix_col       = str_init(PREFIX_COL);
    1.42 - static str from_uri_col     = str_init(FROM_URI_COL);
    1.43 - static str priority_col     = str_init(PRIORITY_COL);
    1.44 -+static str user_col         = str_init(USER_COL);
    1.45 -+static str realm_col        = str_init(REALM_COL);
    1.46 -+static str passwd_col       = str_init(PASSWD_COL);
    1.47 - 
    1.48 - /* timer */
    1.49 - int fr_inv_timer      = DEF_FR_INV_TIMER;
    1.50 -@@ -208,6 +226,9 @@
    1.51 - static char *contact_avp_param = NULL;
    1.52 - static char *rpid_avp_param = NULL;
    1.53 - static char *flags_avp_param = NULL;
    1.54 -+static char *user_avp_param = NULL;
    1.55 -+static char *realm_avp_param = NULL;
    1.56 -+static char *passwd_avp_param = NULL;
    1.57 - 
    1.58 - /* prefix mode */
    1.59 - int prefix_mode_param = DEF_PREFIX_MODE;
    1.60 -@@ -239,6 +260,12 @@
    1.61 - static int_str rpid_avp;
    1.62 - static int     flags_avp_type;
    1.63 - static int_str flags_avp;
    1.64 -+static int     user_avp_type;
    1.65 -+static int_str user_avp;
    1.66 -+static int     realm_avp_type;
    1.67 -+static int_str realm_avp;
    1.68 -+static int     passwd_avp_type;
    1.69 -+static int_str passwd_avp;
    1.70 - 
    1.71 - struct gw_info **gws;	/* Pointer to current gw table pointer */
    1.72 - struct gw_info *gws_1;	/* Pointer to gw table 1 */
    1.73 -@@ -327,6 +354,12 @@
    1.74 - 	{"fr_inv_timer",             INT_PARAM, &fr_inv_timer },
    1.75 - 	{"fr_inv_timer_next",        INT_PARAM,	&fr_inv_timer_next },
    1.76 - 	{"prefix_mode",              INT_PARAM, &prefix_mode_param },
    1.77 -+	{"user_column",              STR_PARAM, &user_col.s },
    1.78 -+	{"realm_column",             STR_PARAM, &realm_col.s },
    1.79 -+	{"passwd_column",            STR_PARAM, &passwd_col.s },
    1.80 -+	{"auth_username_avp",        STR_PARAM, &user_avp_param },
    1.81 -+	{"auth_realm_avp",           STR_PARAM, &realm_avp_param },
    1.82 -+	{"auth_password_avp",        STR_PARAM, &passwd_avp_param },
    1.83 - 	{0, 0, 0}
    1.84 - };
    1.85 - 
    1.86 -@@ -438,6 +471,9 @@
    1.87 -     prefix_col.len = strlen(prefix_col.s);
    1.88 -     from_uri_col.len = strlen(from_uri_col.s);
    1.89 -     priority_col.len = strlen(priority_col.s);
    1.90 -+    user_col.len = strlen(user_col.s);
    1.91 -+    realm_col.len = strlen(realm_col.s);
    1.92 -+    passwd_col.len = strlen(passwd_col.s);
    1.93 - 
    1.94 -     /* Bind database */
    1.95 -     if (lcr_db_bind(&db_url)) {
    1.96 -@@ -563,6 +599,60 @@
    1.97 - 	return -1;
    1.98 -     }
    1.99 - 
   1.100 -+	if (user_avp_param && *user_avp_param) {
   1.101 -+	s.s = user_avp_param; s.len = strlen(s.s);
   1.102 -+	if (pv_parse_spec(&s, &avp_spec)==0
   1.103 -+	    || avp_spec.type!=PVT_AVP) {
   1.104 -+	    LM_ERR("Malformed or non AVP definition <%s>\n", user_avp_param);
   1.105 -+	    return -1;
   1.106 -+	}
   1.107 -+	
   1.108 -+	if(pv_get_avp_name(0, &(avp_spec.pvp), &user_avp, &avp_flags)!=0) {
   1.109 -+	    LM_ERR("Invalid AVP definition <%s>\n", user_avp_param);
   1.110 -+	    return -1;
   1.111 -+	}
   1.112 -+	user_avp_type = avp_flags;
   1.113 -+    } else {
   1.114 -+	LM_ERR("AVP user_avp has not been defined\n");
   1.115 -+	return -1;
   1.116 -+    }
   1.117 -+
   1.118 -+	if (realm_avp_param && *realm_avp_param) {
   1.119 -+	s.s = realm_avp_param; s.len = strlen(s.s);
   1.120 -+	if (pv_parse_spec(&s, &avp_spec)==0
   1.121 -+	    || avp_spec.type!=PVT_AVP) {
   1.122 -+	    LM_ERR("Malformed or non AVP definition <%s>\n", realm_avp_param);
   1.123 -+	    return -1;
   1.124 -+	}
   1.125 -+	
   1.126 -+	if(pv_get_avp_name(0, &(avp_spec.pvp), &realm_avp, &avp_flags)!=0) {
   1.127 -+	    LM_ERR("Invalid AVP definition <%s>\n", realm_avp_param);
   1.128 -+	    return -1;
   1.129 -+	}
   1.130 -+	realm_avp_type = avp_flags;
   1.131 -+    } else {
   1.132 -+	LM_ERR("AVP realm_avp has not been defined\n");
   1.133 -+	return -1;
   1.134 -+    }
   1.135 -+
   1.136 -+	if (passwd_avp_param && *passwd_avp_param) {
   1.137 -+	s.s = passwd_avp_param; s.len = strlen(s.s);
   1.138 -+	if (pv_parse_spec(&s, &avp_spec)==0
   1.139 -+	    || avp_spec.type!=PVT_AVP) {
   1.140 -+	    LM_ERR("Malformed or non AVP definition <%s>\n", passwd_avp_param);
   1.141 -+	    return -1;
   1.142 -+	}
   1.143 -+	
   1.144 -+	if(pv_get_avp_name(0, &(avp_spec.pvp), &passwd_avp, &avp_flags)!=0) {
   1.145 -+	    LM_ERR("Invalid AVP definition <%s>\n", passwd_avp_param);
   1.146 -+	    return -1;
   1.147 -+	}
   1.148 -+	passwd_avp_type = avp_flags;
   1.149 -+    } else {
   1.150 -+	LM_ERR("AVP passwd_avp has not been defined\n");
   1.151 -+	return -1;
   1.152 -+    }
   1.153 -+
   1.154 -     /* Check table version */
   1.155 - 	db_con_t* dbh;
   1.156 - 	if (lcr_dbf.init==0){
   1.157 -@@ -801,16 +891,17 @@
   1.158 - int reload_gws(void)
   1.159 - {
   1.160 -     unsigned int i, port, strip, tag_len, prefix_len, from_uri_len,
   1.161 --    grp_id, priority;
   1.162 -+    user_len, realm_len, passwd_len, grp_id, priority;
   1.163 -     struct in_addr ip_addr;
   1.164 -     unsigned int flags;
   1.165 -     uri_type scheme;
   1.166 -     uri_transport transport;
   1.167 -     db_con_t* dbh;
   1.168 -     char *tag, *prefix, *from_uri;
   1.169 -+    char *user, *realm, *passwd;
   1.170 -     db_res_t* res = NULL;
   1.171 -     db_row_t* row;
   1.172 --    db_key_t gw_cols[8];
   1.173 -+    db_key_t gw_cols[11];
   1.174 -     db_key_t lcr_cols[4];
   1.175 - 
   1.176 -     gw_cols[0] = &ip_addr_col;
   1.177 -@@ -823,6 +914,9 @@
   1.178 -        in the two tables? (ge vw lcr) */
   1.179 -     gw_cols[6] = &grp_id_col;
   1.180 -     gw_cols[7] = &flags_col;
   1.181 -+    gw_cols[8] = &user_col;
   1.182 -+    gw_cols[9] = &realm_col;
   1.183 -+    gw_cols[10] = &passwd_col;
   1.184 - 
   1.185 -     lcr_cols[0] = &prefix_col;
   1.186 -     lcr_cols[1] = &from_uri_col;
   1.187 -@@ -846,7 +940,7 @@
   1.188 - 	return -1;
   1.189 -     }
   1.190 - 
   1.191 --    if (lcr_dbf.query(dbh, NULL, 0, NULL, gw_cols, 0, 8, 0, &res) < 0) {
   1.192 -+    if (lcr_dbf.query(dbh, NULL, 0, NULL, gw_cols, 0, 11, 0, &res) < 0) {
   1.193 - 	    LM_ERR("Failed to query gw data\n");
   1.194 - 	    lcr_dbf.close(dbh);
   1.195 - 	    return -1;
   1.196 -@@ -938,6 +1032,45 @@
   1.197 - 	    lcr_dbf.close(dbh);
   1.198 - 	    return -1;
   1.199 - 	}
   1.200 -+	if (VAL_NULL(ROW_VALUES(row) + 8) == 1) {
   1.201 -+	    user_len = 0;
   1.202 -+	    user = (char *)0;
   1.203 -+	} else {
   1.204 -+	    user = (char *)VAL_STRING(ROW_VALUES(row) + 8);
   1.205 -+	    user_len = strlen(user);
   1.206 -+	    if (user_len > MAX_USER_LEN) {
   1.207 -+		LM_ERR("Too long gw user <%u>\n", user_len);
   1.208 -+		lcr_dbf.free_result(dbh, res);
   1.209 -+		lcr_dbf.close(dbh);
   1.210 -+		return -1;
   1.211 -+	    }
   1.212 -+	}
   1.213 -+	if (VAL_NULL(ROW_VALUES(row) + 9) == 1) {
   1.214 -+	    realm_len = 0;
   1.215 -+	    realm = (char *)0;
   1.216 -+	} else {
   1.217 -+	    realm = (char *)VAL_STRING(ROW_VALUES(row) + 9);
   1.218 -+	    realm_len = strlen(realm);
   1.219 -+	    if (realm_len > MAX_REALM_LEN) {
   1.220 -+		LM_ERR("Too long gw realm <%u>\n", realm_len);
   1.221 -+		lcr_dbf.free_result(dbh, res);
   1.222 -+		lcr_dbf.close(dbh);
   1.223 -+		return -1;
   1.224 -+	    }
   1.225 -+	}
   1.226 -+	if (VAL_NULL(ROW_VALUES(row) + 10) == 1) {
   1.227 -+	    passwd_len = 0;
   1.228 -+	    passwd = (char *)0;
   1.229 -+	} else {
   1.230 -+	    passwd = (char *)VAL_STRING(ROW_VALUES(row) + 10);
   1.231 -+	    passwd_len = strlen(passwd);
   1.232 -+	    if (passwd_len > MAX_PASSWD_LEN) {
   1.233 -+		LM_ERR("Too long gw passwd <%u>\n", passwd_len);
   1.234 -+		lcr_dbf.free_result(dbh, res);
   1.235 -+		lcr_dbf.close(dbh);
   1.236 -+		return -1;
   1.237 -+	    }
   1.238 -+	}
   1.239 - 	if (*gws == gws_1) {
   1.240 - 	    gws_2[i].ip_addr = (unsigned int)ip_addr.s_addr;
   1.241 - 	    gws_2[i].port = port;
   1.242 -@@ -949,6 +1082,15 @@
   1.243 - 	    gws_2[i].tag_len = tag_len;
   1.244 - 	    if (tag_len)
   1.245 - 		memcpy(&(gws_2[i].tag[0]), tag, tag_len);
   1.246 -+	    gws_2[i].user_len = user_len;
   1.247 -+	    if (user_len)
   1.248 -+	    memcpy(&(gws_2[i].user[0]), user, user_len);
   1.249 -+	    gws_2[i].realm_len = realm_len;
   1.250 -+	    if (realm_len)
   1.251 -+	    memcpy(&(gws_2[i].realm[0]), realm, realm_len);
   1.252 -+	    gws_2[i].passwd_len = passwd_len;
   1.253 -+	    if (passwd_len)
   1.254 -+	    memcpy(&(gws_2[i].passwd[0]), passwd, passwd_len);
   1.255 - 	} else {
   1.256 - 	    gws_1[i].ip_addr = (unsigned int)ip_addr.s_addr;
   1.257 - 	    gws_1[i].port = port;
   1.258 -@@ -960,6 +1102,15 @@
   1.259 - 	    gws_1[i].tag_len = tag_len;
   1.260 - 	    if (tag_len)
   1.261 - 		memcpy(&(gws_1[i].tag[0]), tag, tag_len);
   1.262 -+	    gws_1[i].user_len = user_len;
   1.263 -+	    if (user_len)
   1.264 -+	    memcpy(&(gws_1[i].user[0]), user, user_len);
   1.265 -+	    gws_1[i].realm_len = realm_len;
   1.266 -+	    if (realm_len)
   1.267 -+	    memcpy(&(gws_1[i].realm[0]), realm, realm_len);
   1.268 -+	    gws_1[i].passwd_len = passwd_len;
   1.269 -+	    if (passwd_len)
   1.270 -+	    memcpy(&(gws_1[i].passwd[0]), passwd, passwd_len);
   1.271 - 	}
   1.272 -     }
   1.273 - 
   1.274 -@@ -1141,6 +1292,21 @@
   1.275 - 	attr = add_mi_attr(node, MI_DUP_VALUE, "FLAGS", 5, p, len);
   1.276 - 	if(attr == NULL)
   1.277 - 	    return -1;
   1.278 -+
   1.279 -+	attr = add_mi_attr(node, MI_DUP_VALUE, "USER", 6,
   1.280 -+			   (*gws)[i].user, (*gws)[i].user_len );
   1.281 -+	if(attr == NULL)
   1.282 -+	    return -1;
   1.283 -+
   1.284 -+	attr = add_mi_attr(node, MI_DUP_VALUE, "REALM", 6,
   1.285 -+			   (*gws)[i].realm, (*gws)[i].realm_len );
   1.286 -+	if(attr == NULL)
   1.287 -+	    return -1;
   1.288 -+
   1.289 -+	attr = add_mi_attr(node, MI_DUP_VALUE, "PASSWD", 6,
   1.290 -+			   (*gws)[i].passwd, (*gws)[i].passwd_len );
   1.291 -+	if(attr == NULL)
   1.292 -+	    return -1;
   1.293 -     }
   1.294 - 
   1.295 -     for (i = 0; i < MAX_NO_OF_LCRS; i++) {
   1.296 -@@ -1184,6 +1350,9 @@
   1.297 -     char ruri[MAX_URI_SIZE];
   1.298 -     unsigned int i, j, k, index, addr, port, strip, gw_index,
   1.299 - 	duplicated_gw, flags, have_rpid_avp;
   1.300 -+    char *user;
   1.301 -+    char *realm;
   1.302 -+    char *passwd;
   1.303 -     uri_type scheme;
   1.304 -     uri_transport transport;
   1.305 -     struct ip_addr address;
   1.306 -@@ -1407,6 +1576,9 @@
   1.307 - 	transport = (*gws)[index].transport;
   1.308 - 	flags = (*gws)[index].flags;
   1.309 - 	strip = (*gws)[index].strip;
   1.310 -+	user = (*gws)[index].user;
   1.311 -+	realm = (*gws)[index].realm;
   1.312 -+	passwd = (*gws)[index].passwd;
   1.313 - 	if (strip > ruri_user.len) {
   1.314 - 	    LM_ERR("Strip count of gw is too large <%u>\n", strip);
   1.315 - 	    goto skip;
   1.316 -@@ -1476,6 +1648,25 @@
   1.317 - 	val.s = value;
   1.318 - 	add_avp(gw_uri_avp_type|AVP_VAL_STR, gw_uri_avp, val);
   1.319 - 	LM_DBG("Added gw_uri_avp <%.*s>\n", value.len, value.s);
   1.320 -+
   1.321 -+	value.s = user;
   1.322 -+	value.len = strlen(value.s);
   1.323 -+	val.s = value;
   1.324 -+	add_avp(user_avp_type|AVP_VAL_STR, user_avp, val);
   1.325 -+	LM_DBG("Added user_avp <%.*s>\n", value.len, value.s);
   1.326 -+
   1.327 -+	value.s = realm;
   1.328 -+	value.len = strlen(value.s);
   1.329 -+	val.s = value;
   1.330 -+	add_avp(realm_avp_type|AVP_VAL_STR, realm_avp, val);
   1.331 -+	LM_DBG("Added realm_avp <%.*s>\n", value.len, value.s);
   1.332 -+
   1.333 -+	value.s = passwd;
   1.334 -+	value.len = strlen(value.s);
   1.335 -+	val.s = value;
   1.336 -+	add_avp(passwd_avp_type|AVP_VAL_STR, passwd_avp, val);
   1.337 -+	LM_DBG("Added passwd_avp <%.*s>\n", value.len, value.s);
   1.338 -+
   1.339 -     skip:
   1.340 - 	continue;
   1.341 -     }
   1.342 -@@ -1558,7 +1749,8 @@
   1.343 - static int next_gw(struct sip_msg* _m, char* _s1, char* _s2)
   1.344 - {
   1.345 -     int_str gw_uri_val, ruri_user_val, val;
   1.346 --    struct usr_avp *gu_avp, *ru_avp;
   1.347 -+    int_str user_val, realm_val, passwd_val;
   1.348 -+    struct usr_avp *gu_avp, *ru_avp, *usr_avp, *rlm_avp, *pwd_avp;
   1.349 -     int rval;
   1.350 -     str new_ruri;
   1.351 -     char *at, *at_char, *strip_char, *endptr;
   1.352 -@@ -1575,6 +1767,35 @@
   1.353 -     gw_uri_val.s.len = gw_uri_val.s.len - (at - gw_uri_val.s.s);
   1.354 -     gw_uri_val.s.s = at;
   1.355 - 
   1.356 -+	/* Save gateway AVPs for use in script */
   1.357 -+	usr_avp = search_first_avp(user_avp_type, user_avp, &user_val, 0);
   1.358 -+	rlm_avp = search_first_avp(realm_avp_type, realm_avp, &realm_val, 0);
   1.359 -+	pwd_avp = search_first_avp(passwd_avp_type, passwd_avp, &passwd_val, 0);
   1.360 -+	if (!usr_avp) {
   1.361 -+		LM_DBG("User AVP no set\n");
   1.362 -+		return -1;
   1.363 -+	}
   1.364 -+	else {
   1.365 -+		add_avp(user_avp_type|AVP_VAL_STR, user_avp, user_val);
   1.366 -+		LM_DBG("Added user_avp <%.*s>\n", user_val.s.len, user_val.s.s);
   1.367 -+	}
   1.368 -+	if (!rlm_avp) {
   1.369 -+		LM_DBG("Realm AVP no set\n");
   1.370 -+		return -1;
   1.371 -+	}
   1.372 -+	else {
   1.373 -+		add_avp(realm_avp_type|AVP_VAL_STR, realm_avp, realm_val);
   1.374 -+		LM_DBG("Added realm_avp <%.*s>\n", realm_val.s.len, realm_val.s.s);
   1.375 -+	}
   1.376 -+	if (!pwd_avp) {
   1.377 -+		LM_DBG("Passwd AVP no set\n");
   1.378 -+		return -1;
   1.379 -+	}
   1.380 -+	else {
   1.381 -+		add_avp(passwd_avp_type|AVP_VAL_STR, passwd_avp, passwd_val);
   1.382 -+		LM_DBG("Added passwd_avp <%.*s>\n", passwd_val.s.len, passwd_val.s.s);
   1.383 -+	}
   1.384 -+
   1.385 - 	/* Create new Request-URI taking URI user from ruri_user AVP
   1.386 - 	   and other parts of from gateway URI AVP. */
   1.387 - 	ru_avp = search_first_avp(ruri_user_avp_type, ruri_user_avp,

mercurial