Pārlūkot izejas kodu

registrar Add option to the save() function to turn off expires variation when saving a registration

Olle E. Johansson 9 gadi atpakaļ
vecāks
revīzija
55975adcea

+ 2 - 0
modules/registrar/README

@@ -815,6 +815,8 @@ modparam("registrar", "flow_timer", 25)
             other contact addresses for AoR not matching current
             registration, remove them. This mode ensures one contact per
             AoR (user).
+          + 0x08 - Do not apply expires_range or default_expires_range to
+            this registration.
        The flags may be given in decimal or hexa format.
      * uri (optional - flags param has to be set and can be 0 for default
        behavior) - SIP URI to do be used instead of To header URI. It can

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

@@ -973,6 +973,13 @@ modparam("registrar", "flow_timer", 25)
 					AoR not matching current registration, remove them.
 					This mode ensures one contact per AoR (user).</para>
 				</listitem>
+				<listitem>
+					<para><emphasis>0x08</emphasis> - Do not apply
+					<emphasis>expires_range</emphasis> or 
+					<emphasis>default_expires_range</emphasis> to this
+					registration.
+					</para>
+				</listitem>
 			</itemizedlist>
 			<para>The flags may be given in decimal or hexa format.</para>
 		</listitem>

+ 5 - 4
modules/registrar/registrar.h

@@ -49,10 +49,11 @@
 #define PATH_MODE_LAZY		1
 #define PATH_MODE_OFF		0
 
-#define REG_SAVE_MEM_FL     (1<<0)
-#define REG_SAVE_NORPL_FL   (1<<1)
-#define REG_SAVE_REPL_FL    (1<<2)
-#define REG_SAVE_ALL_FL     ((1<<3)-1)
+#define REG_SAVE_MEM_FL     	(1<<0)
+#define REG_SAVE_NORPL_FL   	(1<<1)
+#define REG_SAVE_REPL_FL    	(1<<2)
+#define REG_SAVE_NOVARIATION_FL (1<<3)
+#define REG_SAVE_ALL_FL     ((1<<4)-1)
 
 #define REG_OUTBOUND_NONE	0
 #define REG_OUTBOUND_SUPPORTED	1

+ 13 - 10
modules/registrar/save.c

@@ -70,7 +70,7 @@ static int q_override_msg_id;
 static qvalue_t q_override_value;
 
 /*! \brief
- * Process request that contained a star, in that case,
+ * Process request that contained a star (*) as a contact, in that case,
  * we will remove all bindings with the given username
  * from the usrloc and return 200 OK response
  */
@@ -448,7 +448,7 @@ int reg_get_crt_max_contacts(void)
  * and insert all contacts from the message that have expires
  * > 0
  */
-static inline int insert_contacts(struct sip_msg* _m, udomain_t* _d, str* _a, int _use_regid)
+static inline int insert_contacts(struct sip_msg* _m, udomain_t* _d, str* _a, int _use_regid, int novariation)
 {
 	ucontact_info_t* ci;
 	urecord_t* r = NULL;
@@ -482,7 +482,7 @@ static inline int insert_contacts(struct sip_msg* _m, udomain_t* _d, str* _a, in
 	maxc = reg_get_crt_max_contacts();
 	for( num=0,r=0,ci=0 ; _c ; _c = get_next_contact(_c) ) {
 		/* calculate expires */
-		calc_contact_expires(_m, _c->expires, &expires);
+		calc_contact_expires(_m, _c->expires, &expires, novariation);
 		/* Skip contacts with zero expires */
 		if (expires == 0)
 			continue;
@@ -592,7 +592,7 @@ static int test_max_contacts(struct sip_msg* _m, urecord_t* _r, contact_t* _c,
 
 	for( ; _c ; _c = get_next_contact(_c) ) {
 		/* calculate expires */
-		calc_contact_expires(_m, _c->expires, &e);
+		calc_contact_expires(_m, _c->expires, &e, 0);
 
 		ret = ul.get_ucontact_by_instance( _r, &_c->uri, ci, &cont);
 		if (ret==-1) {
@@ -632,7 +632,7 @@ static int test_max_contacts(struct sip_msg* _m, urecord_t* _r, contact_t* _c,
  * 3) If contact in usrloc exists and expires
  *    == 0, delete contact
  */
-static inline int update_contacts(struct sip_msg* _m, urecord_t* _r, int _mode, int _use_regid)
+static inline int update_contacts(struct sip_msg* _m, urecord_t* _r, int _mode, int _use_regid, int novariation)
 {
 	ucontact_info_t *ci;
 	ucontact_t *c, *ptr, *ptr0;
@@ -679,7 +679,7 @@ static inline int update_contacts(struct sip_msg* _m, urecord_t* _r, int _mode,
 	updated=0;
 	for( ; _c ; _c = get_next_contact(_c) ) {
 		/* calculate expires */
-		calc_contact_expires(_m, _c->expires, &expires);
+		calc_contact_expires(_m, _c->expires, &expires, novariation);
 
 		/* pack the contact info */
 		if ( (ci=pack_ci( 0, _c, expires, 0, _use_regid))==0 ) {
@@ -817,7 +817,7 @@ error:
  * contained some contact header fields
  */
 static inline int add_contacts(struct sip_msg* _m, udomain_t* _d,
-		str* _a, int _mode, int _use_regid)
+		str* _a, int _mode, int _use_regid, int novariation)
 {
 	int res;
 	int ret;
@@ -839,7 +839,7 @@ static inline int add_contacts(struct sip_msg* _m, udomain_t* _d,
 	}
 
 	if (res == 0) { /* Contacts found */
-		if ((ret=update_contacts(_m, r, _mode, _use_regid)) < 0) {
+		if ((ret=update_contacts(_m, r, _mode, _use_regid, novariation)) < 0) {
 			build_contact(_m, r->contacts, &u->host);
 			ul.release_urecord(r);
 			ul.unlock_udomain(_d, _a);
@@ -848,7 +848,7 @@ static inline int add_contacts(struct sip_msg* _m, udomain_t* _d,
 		build_contact(_m, r->contacts, &u->host);
 		ul.release_urecord(r);
 	} else {
-		if (insert_contacts(_m, _d, _a, _use_regid) < 0) {
+		if (insert_contacts(_m, _d, _a, _use_regid, novariation) < 0) {
 			ul.unlock_udomain(_d, _a);
 			return -4;
 		}
@@ -876,6 +876,8 @@ int save(struct sip_msg* _m, udomain_t* _d, int _cflags, str *_uri)
 	param_t *params;
 	contact_t *contact;
 	int use_ob = 1, use_regid = 1;
+	int novariation = 0;
+
 
 	u = parse_to_uri(_m);
 	if(u==NULL)
@@ -973,6 +975,7 @@ int save(struct sip_msg* _m, udomain_t* _d, int _cflags, str *_uri)
 	}
 
 	mem_only = is_cflag_set(REG_SAVE_MEM_FL)?FL_MEM:FL_NONE;
+	novariation = is_cflag_set(REG_SAVE_NOVARIATION_FL)? 1:0;
 
 	if (c == 0) {
 		if (st) {
@@ -984,7 +987,7 @@ int save(struct sip_msg* _m, udomain_t* _d, int _cflags, str *_uri)
 		}
 	} else {
 		mode = is_cflag_set(REG_SAVE_REPL_FL)?1:0;
-		if ((ret=add_contacts(_m, (udomain_t*)_d, &aor, mode, use_regid)) < 0)
+		if ((ret=add_contacts(_m, (udomain_t*)_d, &aor, mode, use_regid, novariation)) < 0)
 			goto error;
 		ret = (ret==0)?1:ret;
 	}

+ 10 - 4
modules/registrar/sip_msg.c

@@ -48,10 +48,13 @@ static struct hdr_field* act_contact;
  */
 static inline int randomize_expires( int expires, int range )
 {
+	int range_min;
+
 	/* if no range is given just return expires */
-	if(range == 0) return expires;
+	if(range == 0)
+		return expires;
 
-	int range_min = expires - (float)range/100 * expires;
+	range_min = expires - (float)range/100 * expires;
 
 	return range_min + (float)(rand()%100)/100 * ( expires - range_min );
 }
@@ -240,9 +243,10 @@ contact_t* get_next_contact(contact_t* _c)
  * 3) If the message contained no expires header field, use
  *    the default value
  */
-void calc_contact_expires(struct sip_msg* _m, param_t* _ep, int* _e)
+void calc_contact_expires(struct sip_msg* _m, param_t* _ep, int* _e, int novariation)
 {
 	int range = 0;
+
 	if (!_ep || !_ep->body.len) {
 		*_e = get_expires_hf(_m);
 
@@ -263,7 +267,9 @@ void calc_contact_expires(struct sip_msg* _m, param_t* _ep, int* _e)
 
 	if ( *_e != 0 )
 	{
-		*_e = randomize_expires( *_e, range );
+		if (!novariation) {
+			*_e = randomize_expires( *_e, range );
+		}
 
 		if (*_e < cfg_get(registrar, registrar_cfg, min_expires)) {
 			*_e = cfg_get(registrar, registrar_cfg, min_expires);

+ 2 - 1
modules/registrar/sip_msg.h

@@ -69,8 +69,9 @@ contact_t* get_next_contact(contact_t* _c);
  *    header field in the same way
  * 3) If the message contained no expires header field, use
  *    the default value
+ * If novariation is not set, the expires range will not be applied (variation in accepted expiry)
  */
-void calc_contact_expires(struct sip_msg* _m, param_t* _ep, int* _e);
+void calc_contact_expires(struct sip_msg* _m, param_t* _ep, int* _e, int novariation);
 
 
 /*! \brief