usrloc: delete contact attributes in db-only mode
authorDaniel-Constantin Mierla <miconda@gmail.com>
Mon, 29 Jul 2019 08:54:41 +0000 (10:54 +0200)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Mon, 29 Jul 2019 08:54:41 +0000 (10:54 +0200)
src/modules/usrloc/ucontact.h
src/modules/usrloc/udomain.c

index abe7353..321bd95 100644 (file)
@@ -176,4 +176,6 @@ int uldb_insert_attrs(str *_dname, str *_user, str *_domain,
  */
 void ul_set_xavp_contact_clone(int v);
 
+int uldb_delete_attrs_ruid(str* _dname, str *_ruid);
+
 #endif
index c29e6fc..6160cd9 100644 (file)
@@ -909,6 +909,9 @@ int udomain_contact_expired_cb(db1_con_t* _c, udomain_t* _d)
        int n;
        urecord_t* r;
        ucontact_t* c;
+#define RUIDBUF_SIZE 128
+       char ruidbuf[RUIDBUF_SIZE];
+       str ruid;
 
        if (db_mode!=DB_ONLY) {
                return 0;
@@ -1028,8 +1031,24 @@ int udomain_contact_expired_cb(db1_con_t* _c, udomain_t* _d)
                                run_ul_callbacks( UL_CONTACT_EXPIRE, c);
                        }
                        c->state = CS_SYNC;
+                       ruid.len = 0;
+                       if(c->ruid.len > 0 && ul_xavp_contact_name.s != NULL) {
+                               /* clone ruid to delete attributes out of lock */
+                               if(c->ruid.len < RUIDBUF_SIZE - 2) {
+                                       memcpy(ruidbuf, c->ruid.s, c->ruid.len);
+                                       ruidbuf[c->ruid.len] = '\0';
+                                       ruid.s = ruidbuf;
+                                       ruid.len = c->ruid.len;
+                               } else {
+                                       LM_ERR("ruid is too long: %d\n", c->ruid.len);
+                               }
+                       }
                        release_urecord(r);
                        unlock_udomain(_d, &user);
+                       if(ruid.len > 0 && ul_xavp_contact_name.s != NULL) {
+                               /* delete attributes by ruid */
+                               uldb_delete_attrs_ruid(_d->name, &ruid);
+                       }
                }
 
                if (DB_CAPABILITY(ul_dbf, DB_CAP_FETCH)) {