Module: kamailio
Branch: master
Commit: 4b6d4fc2d733032391dc8575b594c3e29d06b93e
URL:
https://github.com/kamailio/kamailio/commit/4b6d4fc2d733032391dc8575b594c3e…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2020-04-20T09:12:24+02:00
presence: in-memory presentity update function
- more functions exposed in the header file
---
Modified: src/modules/presence/hash.c
Modified: src/modules/presence/hash.h
---
Diff:
https://github.com/kamailio/kamailio/commit/4b6d4fc2d733032391dc8575b594c3e…
Patch:
https://github.com/kamailio/kamailio/commit/4b6d4fc2d733032391dc8575b594c3e…
---
diff --git a/src/modules/presence/hash.c b/src/modules/presence/hash.c
index 01313a002e..43fcf05eee 100644
--- a/src/modules/presence/hash.c
+++ b/src/modules/presence/hash.c
@@ -1001,6 +1001,56 @@ int ps_ptable_insert(ps_presentity_t *pt)
*/
int ps_ptable_update(ps_presentity_t *pt)
{
+ ps_presentity_t ptc;
+ ps_presentity_t *ptn = NULL;
+ int idx = 0;
+
+ /* copy struct to fill in missing fields */
+ memcpy(&ptc, pt, sizeof(ps_presentity_t));
+
+ ptc.hashid = core_case_hash(&pt->user, &pt->domain, 0);
+
+ if(ptc.ruid.s == NULL) {
+ if(sruid_next(&pres_sruid) < 0) {
+ return -1;
+ }
+ ptc.ruid = pres_sruid.uid;
+ }
+
+ idx = ptn->hashid % _ps_ptable->ssize;
+
+ lock_get(&_ps_ptable->slots[idx].lock);
+ ptn = _ps_ptable->slots[idx].plist;
+ while(ptn!=NULL) {
+ if(ps_presentity_match(ptn, &ptc, 0)==1) {
+ if(ptn->next) {
+ ptn->next->prev = ptn->prev;
+ }
+ if(ptn->prev) {
+ ptn->prev->next = ptn->next;
+ } else {
+ _ps_ptable->slots[idx].plist = ptn->next;
+ }
+ break;
+ }
+ ptn = ptn->next;
+ }
+
+ ptn = ps_presentity_new(&ptc, 0);
+ if(ptn==NULL) {
+ lock_release(&_ps_ptable->slots[idx].lock);
+ return -1;
+ }
+
+ if(_ps_ptable->slots[idx].plist == NULL) {
+ _ps_ptable->slots[idx].plist = ptn;
+ } else {
+ _ps_ptable->slots[idx].plist->prev = ptn;
+ ptn->next = _ps_ptable->slots[idx].plist;
+ _ps_ptable->slots[idx].plist = ptn;
+ }
+ lock_release(&_ps_ptable->slots[idx].lock);
+
return 0;
}
diff --git a/src/modules/presence/hash.h b/src/modules/presence/hash.h
index 26514af276..29753e6228 100644
--- a/src/modules/presence/hash.h
+++ b/src/modules/presence/hash.h
@@ -167,6 +167,10 @@ typedef struct ps_ptable {
ps_pslot_t *slots;
} ps_ptable_t;
+ps_presentity_t *ps_presentity_new(ps_presentity_t *pt, int mtype);
+void ps_presentity_free(ps_presentity_t *pt, int mtype);
+void ps_presentity_list_free(ps_presentity_t *pt, int mtype);
+int ps_presentity_match(ps_presentity_t *pta, ps_presentity_t *ptb, int mmode);
int ps_ptable_init(int ssize);
void ps_ptable_destroy(void);
int ps_ptable_insert(ps_presentity_t *pt);