[Devel] Patch - LCR Strip Option
Bayan William Towfiq
william at telepacket.com
Wed Nov 23 16:39:49 CET 2005
Bayan William Towfiq wrote:
> Juha,
> Sorry about that. I'll have a new one out a little later today.
>
> Bayan
>
> Juha Heinanen wrote:
>
>> bayan,
>>
>> sorry, but your diff didn't include patches for the documentation
>> files.
>>
>> -- juha
>>
>>
>
>
> _______________________________________________
> Devel mailing list
> Devel at openser.org
> http://openser.org/cgi-bin/mailman/listinfo/devel
-------------- next part --------------
diff -ru sip-server/modules/lcr/doc/lcr_user.sgml sip-server-strippatch/modules/lcr/doc/lcr_user.sgml
--- sip-server/modules/lcr/doc/lcr_user.sgml 2005-10-27 10:57:25.000000000 -0700
+++ sip-server-strippatch/modules/lcr/doc/lcr_user.sgml 2005-11-23 07:36:12.687015904 -0800
@@ -49,12 +49,13 @@
Gateway and routing information is kept in two tables: gw and lcr.
</para>
<para>
- When a gateway is selected, Request-URI is rewritten with information
- from gw table: URI scheme, prefix, IP address, port, and transport
- protocol. Valid URI scheme values are NULL = sip, 1 = sip and 2 =
- sips. Prefix is appended in front of Request-URI user part.
- Currently valid transport protocol values are NULL = none, 1 = udp, 2
- = tcp, and 3 = tls.
+ When a gateway is selected, the Request-URI user part is stripped by
+ the number of digits specified in the strip parameter. Subsequently,
+ the Request-URI is rewritten with information from gw table:
+ URI scheme, prefix, IP address, port, and transport protocol. Valid
+ URI scheme values are NULL = sip, 1 = sip and 2 = sips. Prefix is
+ appended in front of Request-URI user part. Currently valid transport
+ protocol values are NULL = none, 1 = udp, 2 = tcp, and 3 = tls.
</para>
<para>
Table lcr contains prefix of user part of Request-URI, From URI,
@@ -293,6 +294,26 @@
</section>
<section>
+ <title><varname>strip_column</varname> (string)</title>
+ <para>
+ Name of the column holding the number of digits to strip from the RURI before applying the prefix.
+ </para>
+ <para>
+ <emphasis>
+ Default value is <quote>strip</quote>.
+ </emphasis>
+ </para>
+ <example>
+ <title>Setting <varname>strip_column</varname> module parameter</title>
+ <programlisting format="linespecific">
+...
+modparam("lcr","strip_column","strip")
+...
+</programlisting>
+ </example>
+ </section>
+
+<section>
<title><varname>prefix_column</varname> (string)</title>
<para>
Name of the column holding the RURI(destination) prefix.
diff -ru sip-server/modules/lcr/lcr_mod.c sip-server-strippatch/modules/lcr/lcr_mod.c
--- sip-server/modules/lcr/lcr_mod.c 2005-11-03 07:16:38.000000000 -0800
+++ sip-server-strippatch/modules/lcr/lcr_mod.c 2005-11-22 14:52:22.686883248 -0800
@@ -100,6 +100,9 @@
#define LCR_TABLE "lcr"
#define LCR_TABLE_LEN (sizeof(LCR_TABLE) - 1)
+#define STRIP_COL "strip"
+#define STRIP_COL_LEN (sizeof(STRIP_COL) - 1)
+
#define PREFIX_COL "prefix"
#define PREFIX_COL_LEN (sizeof(PREFIX_COL) - 1)
@@ -133,6 +136,7 @@
unsigned int port;
uri_type scheme;
uri_transport transport;
+ unsigned int strip;
unsigned int prefix_len;
char prefix[16];
};
@@ -155,6 +159,7 @@
str transport_col = {TRANSPORT_COL, TRANSPORT_COL_LEN};
str grp_id_col = {GRP_ID_COL, GRP_ID_COL_LEN};
str lcr_table = {LCR_TABLE, LCR_TABLE_LEN};
+str strip_col = {STRIP_COL, STRIP_COL_LEN};
str prefix_col = {PREFIX_COL, PREFIX_COL_LEN};
str from_uri_col = {FROM_URI_COL, FROM_URI_COL_LEN};
str priority_col = {PRIORITY_COL, PRIORITY_COL_LEN};
@@ -369,6 +374,7 @@
transport_col.len = strlen(transport_col.s);
grp_id_col.len = strlen(grp_id_col.s);
lcr_table.len = strlen(lcr_table.s);
+ strip_col.len = strlen(strip_col.s);
prefix_col.len = strlen(prefix_col.s);
from_uri_col.len = strlen(from_uri_col.s);
priority_col.len = strlen(priority_col.s);
@@ -482,7 +488,7 @@
int reload_gws ( void )
{
int q_len, i;
- unsigned int ip_addr, port, prefix_len;
+ unsigned int ip_addr, port, strip, prefix_len;
uri_type scheme;
uri_transport transport;
db_con_t* dbh;
@@ -490,11 +496,12 @@
db_res_t* res;
db_row_t* row;
- q_len = snprintf(query, MAX_QUERY_SIZE, "SELECT %.*s, %.*s, %.*s, %.*s, %.*s FROM %.*s",
+ q_len = snprintf(query, MAX_QUERY_SIZE, "SELECT %.*s, %.*s, %.*s, %.*s, %.*s, %.*s FROM %.*s",
ip_addr_col.len, ip_addr_col.s,
port_col.len, port_col.s,
uri_scheme_col.len, uri_scheme_col.s,
transport_col.len, transport_col.s,
+ strip_col.len, strip_col.s,
prefix_col.len, prefix_col.s,
gw_table.len, gw_table.s);
@@ -570,10 +577,15 @@
}
}
if (VAL_NULL(ROW_VALUES(row) + 4) == 1) {
+ strip = 0;
+ } else {
+ strip = VAL_INT(ROW_VALUES(row) + 4);
+ }
+ if (VAL_NULL(ROW_VALUES(row) + 5) == 1) {
prefix_len = 0;
prefix = (char *)0;
} else {
- prefix = (char *)VAL_STRING(ROW_VALUES(row) + 4);
+ prefix = (char *)VAL_STRING(ROW_VALUES(row) + 5);
prefix_len = strlen(prefix);
if (prefix_len > MAX_PREFIX_LEN) {
LOG(L_ERR, "reload_gws(): too long prefix\n");
@@ -587,6 +599,7 @@
gws_2[i].port = port;
gws_2[i].scheme = scheme;
gws_2[i].transport = transport;
+ gws_2[i].strip = strip;
gws_2[i].prefix_len = prefix_len;
if (prefix_len)
memcpy(&(gws_2[i].prefix[0]), prefix, prefix_len);
@@ -595,6 +608,7 @@
gws_1[i].port = port;
gws_1[i].scheme = scheme;
gws_1[i].transport = transport;
+ gws_1[i].strip = strip;
gws_1[i].prefix_len = prefix_len;
if (prefix_len)
memcpy(&(gws_1[i].prefix[0]), prefix, prefix_len);
@@ -620,6 +634,7 @@
void print_gws (FILE *reply_file)
{
unsigned int i, prefix_len;
+ unsigned int strip;
uri_transport transport;
for (i = 0; i < MAX_NO_OF_GWS; i++) {
@@ -655,6 +670,8 @@
} else {
fprintf(reply_file, ":");
}
+ strip = (*gws)[i].strip;
+ fprintf(reply_file, "%d", strip);
prefix_len = (*gws)[i].prefix_len;
if (prefix_len) {
fprintf(reply_file, "%.*s\n",
@@ -676,8 +693,9 @@
str ruri_user, from_uri, value;
char query[MAX_QUERY_SIZE];
char ruri[MAX_URI_SIZE];
- unsigned int q_len, i, j, prefix_len;
+ unsigned int q_len, i, j, strip_len, prefix_len;
unsigned int addr, port;
+ unsigned int strip;
uri_type scheme;
uri_transport transport;
struct ip_addr address;
@@ -715,11 +733,12 @@
from_uri = get_from(_m)->uri;
}
- q_len = snprintf(query, MAX_QUERY_SIZE, "SELECT %.*s.%.*s, %.*s.%.*s, %.*s.%.*s, %.*s.%.*s, %.*s.%.*s FROM %.*s, %.*s WHERE '%.*s' LIKE %.*s.%.*s AND '%.*s' LIKE CONCAT(%.*s.%.*s, '%%') AND %.*s.%.*s = %.*s.%.*s ORDER BY CHAR_LENGTH(%.*s.%.*s), %.*s.%.*s DESC, RAND()",
+ q_len = snprintf(query, MAX_QUERY_SIZE, "SELECT %.*s.%.*s, %.*s.%.*s, %.*s.%.*s, %.*s.%.*s, %.*s.%.*s, %.*s.%.*s FROM %.*s, %.*s WHERE '%.*s' LIKE %.*s.%.*s AND '%.*s' LIKE CONCAT(%.*s.%.*s, '%%') AND %.*s.%.*s = %.*s.%.*s ORDER BY CHAR_LENGTH(%.*s.%.*s), %.*s.%.*s DESC, RAND()",
gw_table.len, gw_table.s, ip_addr_col.len, ip_addr_col.s,
gw_table.len, gw_table.s, port_col.len, port_col.s,
gw_table.len, gw_table.s, uri_scheme_col.len, uri_scheme_col.s,
gw_table.len, gw_table.s, transport_col.len, transport_col.s,
+ gw_table.len, gw_table.s, strip_col.len, strip_col.s,
gw_table.len, gw_table.s, prefix_col.len, prefix_col.s,
gw_table.len, gw_table.s, lcr_table.len, lcr_table.s,
from_uri.len, from_uri.s,
@@ -766,13 +785,25 @@
transport = (uri_transport)VAL_INT(ROW_VALUES(row) + 3);
}
if (VAL_NULL(ROW_VALUES(row) + 4) == 1) {
+ strip = 0;
+ strip_len = 1;
+ } else {
+ strip = VAL_INT(ROW_VALUES(row) + 4);
+ if (strip<10) strip_len = 1;
+ else
+ if (strip < 100)
+ strip_len = 2;
+ else
+ strip_len = 3;
+ }
+ if (VAL_NULL(ROW_VALUES(row) + 5) == 1) {
prefix_len = 0;
prefix = (char *)0;
} else {
- prefix = (char *)VAL_STRING(ROW_VALUES(row) + 4);
+ prefix = (char *)VAL_STRING(ROW_VALUES(row) + 5);
prefix_len = strlen(prefix);
}
- if (5 + prefix_len + 1 + 15 + 1 + 5 + 1 + 14 >
+ if (5 + prefix_len + 1 + strip_len + 1 + 15 + 1 + 5 + 1 + 14 >
MAX_URI_SIZE) {
LOG(L_ERR, "load_gws(): Request URI would be too long\n");
goto skip;
@@ -789,6 +820,11 @@
if (prefix_len) {
memcpy(at, prefix, prefix_len); at = at + prefix_len;
}
+ //Add strip in this form |number. For example: |3 means strip first 3 characters
+ *at = '|'; at = at + 1;
+ sprintf(at,"%d", strip);
+ at = at + strip_len;
+
*at = '@'; at = at + 1;
address.af = AF_INET;
address.len = 4;
@@ -853,6 +889,8 @@
struct usr_avp *gw_uri_avp, *ruri_user_avp;
str new_ruri;
char *at, *at_char;
+ char *strip_char;
+ unsigned int strip;
gw_uri_avp = search_first_avp(gw_uri_avp_name_str,
gw_uri_name, &gw_uri_val);
@@ -871,17 +909,21 @@
LOG(L_ERR, "next_gw(): No memory for new R-URI.\n");
return -1;
}
+ strip_char = memchr(gw_uri_val.s->s, '|', gw_uri_val.s->len);
at_char = memchr(gw_uri_val.s->s, '@', gw_uri_val.s->len);
+ if (!strip_char || strip_char > at_char)
+ strip = 0;
if (!at_char) {
pkg_free(new_ruri.s);
LOG(L_ERR, "next_gw(): No @ in gateway URI.\n");
return -1;
}
at = new_ruri.s;
- memcpy(at, gw_uri_val.s->s, at_char - gw_uri_val.s->s);
- at = at + (at_char - gw_uri_val.s->s);
- memcpy(at, _m->parsed_uri.user.s, _m->parsed_uri.user.len);
- at = at + _m->parsed_uri.user.len;
+ memcpy(at, gw_uri_val.s->s, strip_char - gw_uri_val.s->s);
+ sscanf(strip_char+1,"%d",&strip);
+ at = at + (strip_char - gw_uri_val.s->s);
+ memcpy(at, _m->parsed_uri.user.s+strip, _m->parsed_uri.user.len-strip);
+ at = at + _m->parsed_uri.user.len-strip;
memcpy(at, at_char, gw_uri_val.s->len - (at_char - gw_uri_val.s->s));
at = at + gw_uri_val.s->len - (at_char - gw_uri_val.s->s);
*at = '\0';
diff -ru sip-server/scripts/mysqldb.sh sip-server-strippatch/scripts/mysqldb.sh
--- sip-server/scripts/mysqldb.sh 2005-10-27 13:03:33.000000000 -0700
+++ sip-server-strippatch/scripts/mysqldb.sh 2005-11-22 14:52:22.687883096 -0800
@@ -701,6 +701,7 @@
port SMALLINT UNSIGNED,
uri_scheme TINYINT UNSIGNED,
transport TINYINT UNSIGNED,
+ strip TINYINT UNSIGNED,
prefix varchar(16) default NULL,
PRIMARY KEY (gw_name),
KEY (grp_id)
More information about the Devel
mailing list