[sr-dev] git:master: htable(k): Added 'updateexpire' parameter to the definition of an

Alex Balashov abalashov at evaristesys.com
Wed Apr 4 17:00:29 CEST 2012


Module: sip-router
Branch: master
Commit: aa5a8463c835c94d1c8cba348791e13c64bcf4f2
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=aa5a8463c835c94d1c8cba348791e13c64bcf4f2

Author: Alex Balashov <abalashov at evaristesys.com>
Committer: Alex Balashov <abalashov at evaristesys.com>
Date:   Wed Apr  4 10:48:03 2012 -0400

htable(k): Added 'updateexpire' parameter to the definition of an
htable.  It permits one to change whether updating a value stored
in the htable resets its time until expiration.

Its default value is 1, to preserve existing behaviour.  However, if
set to 0, updating a value will have no effect on how soon it will
expire.

---

 modules_k/htable/README               |   10 ++++++++++
 modules_k/htable/doc/htable.xml       |    5 +++++
 modules_k/htable/doc/htable_admin.xml |    5 +++++
 modules_k/htable/ht_api.c             |   23 ++++++++++++++++++-----
 modules_k/htable/ht_api.h             |    3 ++-
 5 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/modules_k/htable/README b/modules_k/htable/README
index 45f2684..aa98300 100644
--- a/modules_k/htable/README
+++ b/modules_k/htable/README
@@ -11,6 +11,12 @@ Elena-Ramona Modroiu
 
    <ramona at rosdev.ro>
 
+Edited by
+
+Alex Balashov
+
+   <abalashov at evaristesys.com>
+
    Copyright © 2008-2011 http://www.asipto.com
      __________________________________________________________________
 
@@ -278,6 +284,10 @@ if(is_present_hf("Authorization"))
        table).
      * initval - the integer value to be returned instead of $null when a
        requested key is not set.
+     * updateexpire - if set to 1 (default), the time until expiration of
+       an item is reset when that item is updated. Certain uses of htable
+       may dictate that updates should not reset the expiration timeout,
+       however, in which case this attribute can be set to 0.
 
    Default value is NULL.
 
diff --git a/modules_k/htable/doc/htable.xml b/modules_k/htable/doc/htable.xml
index 8081252..9404084 100644
--- a/modules_k/htable/doc/htable.xml
+++ b/modules_k/htable/doc/htable.xml
@@ -29,6 +29,11 @@
 		<surname>Modroiu</surname>
 		<email>ramona at rosdev.ro</email>
 	    </editor>
+	    <editor>
+		<firstname>Alex</firstname>
+		<surname>Balashov</surname>
+		<email>abalashov at evaristesys.com</email>
+	    </editor>
 	</authorgroup>
 	<copyright>
 	    <year>2008-2011</year>
diff --git a/modules_k/htable/doc/htable_admin.xml b/modules_k/htable/doc/htable_admin.xml
index a9ff4ba..09ee23c 100644
--- a/modules_k/htable/doc/htable_admin.xml
+++ b/modules_k/htable/doc/htable_admin.xml
@@ -267,6 +267,11 @@ if(is_present_hf("Authorization"))
 			instead of $null when a requested key is not set.
 		</para>
 		</listitem>
+		<listitem>
+		<para>
+			<emphasis>updateexpire</emphasis> - if set to 1 (default), the time until expiration of an item is reset when that item is updated.  Certain uses of htable may dictate that updates should not reset the expiration timeout, however, in which case this attribute can be set to 0.
+		</para>
+		</listitem>
 		</itemizedlist>
 		<para>
 		<emphasis>
diff --git a/modules_k/htable/ht_api.c b/modules_k/htable/ht_api.c
index ed4da81..24ae0b0 100644
--- a/modules_k/htable/ht_api.c
+++ b/modules_k/htable/ht_api.c
@@ -217,7 +217,7 @@ ht_t* ht_get_table(str *name)
 }
 
 int ht_add_table(str *name, int autoexp, str *dbtable, int size, int dbmode,
-		int itype, int_str *ival)
+		int itype, int_str *ival, int updateexpire)
 {
 	unsigned int htid;
 	ht_t *ht;
@@ -252,6 +252,7 @@ int ht_add_table(str *name, int autoexp, str *dbtable, int size, int dbmode,
 	else ht->htsize = 1<<size;
 	ht->htid = htid;
 	ht->htexpire = autoexp;
+	ht->updateexpire = updateexpire;
 	ht->name = *name;
 	if(dbtable!=NULL && dbtable->len>0)
 		ht->dbtable = *dbtable;
@@ -387,7 +388,9 @@ int ht_set_cell(ht_t *ht, str *name, int type, int_str *val, int mode)
 						it->value.s.len = val->s.len;
 						memcpy(it->value.s.s, val->s.s, val->s.len);
 						it->value.s.s[it->value.s.len] = '\0';
-						it->expire = now + ht->htexpire;
+						
+						if(ht->updateexpire)
+							it->expire = now + ht->htexpire;
 					} else {
 						/* new */
 						cell = ht_cell_new(name, type, val, hid);
@@ -411,7 +414,9 @@ int ht_set_cell(ht_t *ht, str *name, int type, int_str *val, int mode)
 				} else {
 					it->flags &= ~AVP_VAL_STR;
 					it->value.n = val->n;
-					it->expire = now + ht->htexpire;
+
+					if(ht->updateexpire)
+						it->expire = now + ht->htexpire;
 				}
 				if(mode) lock_release(&ht->entries[idx].lock);
 				return 0;
@@ -438,7 +443,9 @@ int ht_set_cell(ht_t *ht, str *name, int type, int_str *val, int mode)
 					ht_cell_free(it);
 				} else {
 					it->value.n = val->n;
-					it->expire = now + ht->htexpire;
+
+					if(ht->updateexpire)
+						it->expire = now + ht->htexpire;
 				}
 				if(mode) lock_release(&ht->entries[idx].lock);
 				return 0;
@@ -717,6 +724,7 @@ int ht_table_spec(char *spec)
 	unsigned int autoexpire = 0;
 	unsigned int size = 4;
 	unsigned int dbmode = 0;
+	unsigned int updateexpire = 1;
 	str in;
 	str tok;
 	param_t *pit=NULL;
@@ -768,11 +776,16 @@ int ht_table_spec(char *spec)
 			itype = PV_VAL_INT;
 			LM_DBG("htable [%.*s] - initval [%d]\n", name.len, name.s,
 					ival.n);
+		} else if(pit->name.len == 12 && strncmp(pit->name.s, "updateexpire", 12) == 0) {
+			if(str2int(&tok, &updateexpire) != 0)
+				goto error;
+
+			LM_DBG("htable [%.*s] - updateexpire [%u]\n", name.len, name.s, updateexpire); 
 		} else { goto error; }
 	}
 
 	return ht_add_table(&name, autoexpire, &dbtable, size, dbmode,
-			itype, &ival);
+			itype, &ival, updateexpire);
 
 error:
 	LM_ERR("invalid htable parameter [%.*s]\n", in.len, in.s);
diff --git a/modules_k/htable/ht_api.h b/modules_k/htable/ht_api.h
index 831267e..9a039be 100644
--- a/modules_k/htable/ht_api.h
+++ b/modules_k/htable/ht_api.h
@@ -57,6 +57,7 @@ typedef struct _ht
 	int dbmode;
 	int flags;
 	int_str initval;
+	int updateexpire;
 	unsigned int htsize;
 	ht_entry_t *entries;
 	struct _ht *next;
@@ -69,7 +70,7 @@ typedef struct _ht_pv {
 } ht_pv_t, *ht_pv_p;
 
 int ht_add_table(str *name, int autoexp, str *dbtable, int size, int dbmode,
-		int itype, int_str *ival);
+		int itype, int_str *ival, int updateexpire);
 int ht_init_tables(void);
 int ht_destroy(void);
 int ht_set_cell(ht_t *ht, str *name, int type, int_str *val, int mode);




More information about the sr-dev mailing list