Module: kamailio
Branch: 4.4
Commit: d782f0d052f7092576b4935987b9ee25beb0f771
URL: 
https://github.com/kamailio/kamailio/commit/d782f0d052f7092576b4935987b9ee25beb0f771

Author: Carsten Bock <cars...@ng-voice.com>
Committer: Julien Chavanton <jchavan...@gmail.com>
Date: 2017-03-10T13:47:31-08:00

dmq_usrloc: Use ruid for saving/updating contacts

---

Modified: modules/dmq_usrloc/usrloc_sync.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/d782f0d052f7092576b4935987b9ee25beb0f771.diff
Patch: 
https://github.com/kamailio/kamailio/commit/d782f0d052f7092576b4935987b9ee25beb0f771.patch

---

diff --git a/modules/dmq_usrloc/usrloc_sync.c b/modules/dmq_usrloc/usrloc_sync.c
index 1c78e71..63e664b 100644
--- a/modules/dmq_usrloc/usrloc_sync.c
+++ b/modules/dmq_usrloc/usrloc_sync.c
@@ -50,9 +50,9 @@ extern int _dmq_usrloc_batch_usleep;
 
 static int add_contact(str aor, ucontact_info_t* ci)
 {
-       urecord_t* r;
+       urecord_t* r = NULL;
        udomain_t* _d;
-       ucontact_t* c;
+       ucontact_t* c = NULL;
        str contact;
        int res;
 
@@ -63,35 +63,52 @@ static int add_contact(str aor, ucontact_info_t* ci)
 
        dmq_ul.lock_udomain(_d, &aor);
 
-       res = dmq_ul.get_urecord(_d, &aor, &r);
-       if (res < 0) {
-               LM_ERR("failed to retrieve record from usrloc\n");
-               goto error;
-       } else if ( res == 0) {
-               LM_DBG("'%.*s' found in usrloc\n", aor.len, ZSW(aor.s));
-               res = dmq_ul.get_ucontact(r, ci->c, ci->callid, ci->path, 
ci->cseq, &c);
-               LM_DBG("get_ucontact = %d\n", res);
-               if (res==-1) {
-                       LM_ERR("Invalid cseq\n");
+       LM_DBG("aor: %.*s\n", aor.len, aor.s);
+       LM_DBG("ci->ruid: %.*s\n", ci->ruid.len, ci->ruid.s);
+       LM_DBG("aorhash: %i\n", dmq_ul.get_aorhash(&aor));
+
+       if (ci->ruid.len > 0) {
+               // Search by ruid, if possible
+               res = dmq_ul.get_urecord_by_ruid(_d, dmq_ul.get_aorhash(&aor), 
&ci->ruid, &r, &c);
+               if (res == 0) {
+                       LM_DBG("Found contact\n");
+                       dmq_ul.update_ucontact(r, c, ci);
+                       LM_DBG("Release record\n");
+                       dmq_ul.release_urecord(r);
+                       LM_DBG("Unlock udomain\n");
+                       dmq_ul.unlock_udomain(_d, &aor);
+                       return 0;
+               }
+       }
+               res = dmq_ul.get_urecord(_d, &aor, &r);
+               if (res < 0) {
+                       LM_ERR("failed to retrieve record from usrloc\n");
                        goto error;
-               } else if (res > 0 ) {
-                       LM_DBG("Not found contact\n");
+               } else if ( res == 0) {
+                       LM_DBG("'%.*s' found in usrloc\n", aor.len, ZSW(aor.s));
+                       res = dmq_ul.get_ucontact(r, ci->c, ci->callid, 
ci->path, ci->cseq, &c);
+                       LM_DBG("get_ucontact = %d\n", res);
+                       if (res==-1) {
+                               LM_ERR("Invalid cseq\n");
+                               goto error;
+                       } else if (res > 0 ) {
+                               LM_DBG("Not found contact\n");
+                               contact.s = ci->c->s;
+                               contact.len = ci->c->len;
+                               dmq_ul.insert_ucontact(r, &contact, ci, &c);
+                       } else if (res == 0) {
+                               LM_DBG("Found contact\n");
+                               dmq_ul.update_ucontact(r, c, ci);
+                       }
+               } else {
+                       LM_DBG("'%.*s' Not found in usrloc\n", aor.len, 
ZSW(aor.s));
+                       dmq_ul.insert_urecord(_d, &aor, &r);
+                       LM_DBG("Insert record\n");
                        contact.s = ci->c->s;
                        contact.len = ci->c->len;
                        dmq_ul.insert_ucontact(r, &contact, ci, &c);
-               } else if (res == 0) {
-                       LM_DBG("Found contact\n");
-                       dmq_ul.update_ucontact(r, c, ci);
+                       LM_DBG("Insert ucontact\n");
                }
-       } else {
-               LM_DBG("'%.*s' Not found in usrloc\n", aor.len, ZSW(aor.s));
-               dmq_ul.insert_urecord(_d, &aor, &r);
-               LM_DBG("Insert record\n");
-               contact.s = ci->c->s;
-               contact.len = ci->c->len;
-               dmq_ul.insert_ucontact(r, &contact, ci, &c);
-               LM_DBG("Insert ucontact\n");
-       }
 
                LM_DBG("Release record\n");
                dmq_ul.release_urecord(r);


_______________________________________________
sr-dev mailing list
sr-dev@lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to