Pārlūkot izejas kodu

registrar: Add module parameter "contact_max_size" to make max contact size configurable

The new module parameter "contact_max_size" allows changing the max size of contact URIs
that are accepted in REGISTER requests.
The default value of this parameter is 255 which was the value of the compile time constant
that is replaced by this module parameter.
If configured one must make sure that the DB actually supports the configured size in the
column "contact".
AndreasHuber-CH 9 gadi atpakaļ
vecāks
revīzija
eb6b9c6bbd

+ 30 - 0
modules/registrar/doc/registrar_admin.xml

@@ -929,6 +929,36 @@ modparam("registrar", "flow_timer", 25)
 		</example>
 	</section>
 
+	<section id="registrar.p.contact_max_size">
+		<title><varname>contact_max_size</varname> (integer)</title>
+		<para>
+		Max size of URIs in <quote>Contact:</quote> header.
+		</para>
+		<para>
+		The size of URIs in <quote>Contact:</quote> headers are checked to be
+		lower or equal to this value.
+		A warning is logged and a 400 Bad Request is sent in response to REGISTER
+		requests with contact URIs that are longer than this value.
+		</para>
+		<para>
+		If a database is used then you must make sure that your database model supports
+		strings of the configured size in the column <quote>contact</quote> of the table
+		specified in <quote>save()</quote> function.
+		</para>
+		<para>
+		<emphasis>
+			Default value is 255.
+		</emphasis>
+		</para>
+		<example>
+		<title>Set <varname>contact_max_size</varname> parameter</title>
+		<programlisting format="linespecific">
+...
+modparam("registrar", "contact_max_size", 500)
+...
+		</programlisting>
+		</example>
+	</section>
 
 	</section>
 

+ 3 - 0
modules/registrar/registrar.c

@@ -106,6 +106,8 @@ int reg_outbound_mode = 0;
 int reg_regid_mode = 0;
 int reg_flow_timer = 0;
 
+int contact_max_size = 255; /* max size of contact URIs */
+
 str match_callid_name = str_init("match_callid");
 str match_received_name = str_init("match_received");
 str match_contact_name = str_init("match_contact");
@@ -225,6 +227,7 @@ static param_export_t params[] = {
 	{"outbound_mode",      INT_PARAM, &reg_outbound_mode					},
 	{"regid_mode",         INT_PARAM, &reg_regid_mode					},
 	{"flow_timer",         INT_PARAM, &reg_flow_timer					},
+	{"contact_max_size",   INT_PARAM, &contact_max_size					},
 	{0, 0, 0}
 };
 

+ 1 - 1
modules/registrar/registrar.h

@@ -39,7 +39,7 @@
 
 /* if DB support is used, this values must not exceed the
  * storage capacity of the DB columns! See db/schema/entities.xml */
-#define CONTACT_MAX_SIZE       255
+extern int contact_max_size; /* configurable using module parameter "contact_max_size" instead of compile time constant */
 #define RECEIVED_MAX_SIZE      255
 #define USERNAME_MAX_SIZE      64
 #define DOMAIN_MAX_SIZE        128

+ 1 - 1
modules/registrar/sip_msg.c

@@ -190,7 +190,7 @@ int check_contacts(struct sip_msg* _m, int* _s)
 				}
 				/* check also the length of all contacts */
 				for(c=((contact_body_t*)p->parsed)->contacts ; c ; c=c->next) {
-					if (c->uri.len > CONTACT_MAX_SIZE) {
+					if (c->uri.len > contact_max_size) {
 						LM_WARN("contact uri is too long: [%.*s]\n", c->uri.len, c->uri.s);
 						rerrno = R_CONTACT_LEN;
 						return 1;