|
@@ -237,6 +237,10 @@ ht_t* ht_get_table(str *name)
|
|
unsigned int htid;
|
|
unsigned int htid;
|
|
ht_t *ht;
|
|
ht_t *ht;
|
|
|
|
|
|
|
|
+ if(name==NULL || name->s==NULL) {
|
|
|
|
+ LM_WARN("invalid name parameter\n");
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
|
htid = ht_compute_hash(name);
|
|
htid = ht_compute_hash(name);
|
|
|
|
|
|
/* does it exist */
|
|
/* does it exist */
|
|
@@ -263,6 +267,10 @@ int ht_add_table(str *name, int autoexp, str *dbtable, str *dbcols, int size,
|
|
int c;
|
|
int c;
|
|
int i;
|
|
int i;
|
|
|
|
|
|
|
|
+ if(name==NULL || name->s==NULL) {
|
|
|
|
+ LM_WARN("invalid name parameter\n");
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
htid = ht_compute_hash(name);
|
|
htid = ht_compute_hash(name);
|
|
|
|
|
|
/* does it exist */
|
|
/* does it exist */
|
|
@@ -463,8 +471,14 @@ int ht_set_cell_ex(ht_t *ht, str *name, int type, int_str *val, int mode,
|
|
ht_cell_t *it, *prev, *cell;
|
|
ht_cell_t *it, *prev, *cell;
|
|
time_t now;
|
|
time_t now;
|
|
|
|
|
|
- if(ht==NULL || ht->entries==NULL)
|
|
|
|
|
|
+ if(ht==NULL || ht->entries==NULL) {
|
|
|
|
+ LM_WARN("invalid ht parameter\n");
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+ if(name==NULL || name->s==NULL) {
|
|
|
|
+ LM_WARN("invalid name parameter\n");
|
|
return -1;
|
|
return -1;
|
|
|
|
+ }
|
|
|
|
|
|
hid = ht_compute_hash(name);
|
|
hid = ht_compute_hash(name);
|
|
|
|
|
|
@@ -639,6 +653,10 @@ int ht_del_cell(ht_t *ht, str *name)
|
|
if(ht==NULL || ht->entries==NULL)
|
|
if(ht==NULL || ht->entries==NULL)
|
|
return -1;
|
|
return -1;
|
|
|
|
|
|
|
|
+ if(name==NULL || name->s==NULL) {
|
|
|
|
+ LM_WARN("invalid name parameter\n");
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
hid = ht_compute_hash(name);
|
|
hid = ht_compute_hash(name);
|
|
|
|
|
|
idx = ht_get_entry(hid, ht->htsize);
|
|
idx = ht_get_entry(hid, ht->htsize);
|
|
@@ -685,6 +703,10 @@ ht_cell_t* ht_cell_value_add(ht_t *ht, str *name, int val, ht_cell_t *old)
|
|
if(ht==NULL || ht->entries==NULL)
|
|
if(ht==NULL || ht->entries==NULL)
|
|
return NULL;
|
|
return NULL;
|
|
|
|
|
|
|
|
+ if(name==NULL || name->s==NULL) {
|
|
|
|
+ LM_WARN("invalid name parameter\n");
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
|
hid = ht_compute_hash(name);
|
|
hid = ht_compute_hash(name);
|
|
|
|
|
|
idx = ht_get_entry(hid, ht->htsize);
|
|
idx = ht_get_entry(hid, ht->htsize);
|
|
@@ -807,6 +829,10 @@ ht_cell_t* ht_cell_pkg_copy(ht_t *ht, str *name, ht_cell_t *old)
|
|
if(ht==NULL || ht->entries==NULL)
|
|
if(ht==NULL || ht->entries==NULL)
|
|
return NULL;
|
|
return NULL;
|
|
|
|
|
|
|
|
+ if(name==NULL || name->s==NULL) {
|
|
|
|
+ LM_WARN("invalid name parameter\n");
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
|
hid = ht_compute_hash(name);
|
|
hid = ht_compute_hash(name);
|
|
|
|
|
|
idx = ht_get_entry(hid, ht->htsize);
|
|
idx = ht_get_entry(hid, ht->htsize);
|
|
@@ -851,6 +877,50 @@ ht_cell_t* ht_cell_pkg_copy(ht_t *ht, str *name, ht_cell_t *old)
|
|
return NULL;
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+int ht_cell_exists(ht_t *ht, str *name)
|
|
|
|
+{
|
|
|
|
+ unsigned int idx;
|
|
|
|
+ unsigned int hid;
|
|
|
|
+ ht_cell_t *it;
|
|
|
|
+
|
|
|
|
+ if(ht==NULL || ht->entries==NULL)
|
|
|
|
+ return 0;
|
|
|
|
+
|
|
|
|
+ if(name==NULL || name->s==NULL) {
|
|
|
|
+ LM_WARN("invalid name parameter\n");
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+ hid = ht_compute_hash(name);
|
|
|
|
+
|
|
|
|
+ idx = ht_get_entry(hid, ht->htsize);
|
|
|
|
+
|
|
|
|
+ /* head test and return */
|
|
|
|
+ if(ht->entries[idx].first==NULL)
|
|
|
|
+ return 0;
|
|
|
|
+
|
|
|
|
+ ht_slot_lock(ht, idx);
|
|
|
|
+ it = ht->entries[idx].first;
|
|
|
|
+ while(it!=NULL && it->cellid < hid)
|
|
|
|
+ it = it->next;
|
|
|
|
+ while(it!=NULL && it->cellid == hid) {
|
|
|
|
+ if(name->len==it->name.len
|
|
|
|
+ && strncmp(name->s, it->name.s, name->len)==0) {
|
|
|
|
+ /* found */
|
|
|
|
+ if(ht->htexpire>0 && it->expire!=0 && it->expire<time(NULL)) {
|
|
|
|
+ /* entry has expired */
|
|
|
|
+ ht_slot_unlock(ht, idx);
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+ ht_slot_unlock(ht, idx);
|
|
|
|
+ return 1;
|
|
|
|
+ }
|
|
|
|
+ it = it->next;
|
|
|
|
+ }
|
|
|
|
+ ht_slot_unlock(ht, idx);
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
int ht_dbg(void)
|
|
int ht_dbg(void)
|
|
{
|
|
{
|
|
int i;
|
|
int i;
|
|
@@ -1157,6 +1227,10 @@ int ht_set_cell_expire(ht_t *ht, str *name, int type, int_str *val)
|
|
if(ht->htexpire==0)
|
|
if(ht->htexpire==0)
|
|
return 0;
|
|
return 0;
|
|
|
|
|
|
|
|
+ if(name==NULL || name->s==NULL) {
|
|
|
|
+ LM_WARN("invalid name parameter\n");
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
hid = ht_compute_hash(name);
|
|
hid = ht_compute_hash(name);
|
|
|
|
|
|
idx = ht_get_entry(hid, ht->htsize);
|
|
idx = ht_get_entry(hid, ht->htsize);
|
|
@@ -1202,6 +1276,10 @@ int ht_get_cell_expire(ht_t *ht, str *name, unsigned int *val)
|
|
if(ht->htexpire==0)
|
|
if(ht->htexpire==0)
|
|
return 0;
|
|
return 0;
|
|
|
|
|
|
|
|
+ if(name==NULL || name->s==NULL) {
|
|
|
|
+ LM_WARN("invalid name parameter\n");
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
hid = ht_compute_hash(name);
|
|
hid = ht_compute_hash(name);
|
|
|
|
|
|
idx = ht_get_entry(hid, ht->htsize);
|
|
idx = ht_get_entry(hid, ht->htsize);
|