Skip to content

Commit

Permalink
pua_reginfo: avoid sending notify when processing location record act…
Browse files Browse the repository at this point in the history
…ion triggered by itself

(cherry picked from commit e070257)
  • Loading branch information
miconda committed Nov 11, 2014
1 parent 2965000 commit 39d6a77
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
21 changes: 15 additions & 6 deletions modules/pua_reginfo/notify.c
Expand Up @@ -28,6 +28,7 @@
#include "../../modules/usrloc/usrloc.h"
#include "../../lib/srutils/sruid.h"
#include <libxml/parser.h>
#include "usrloc_cb.h"
#include "pua_reginfo.h"

/*<?xml version="1.0"?>
Expand Down Expand Up @@ -71,7 +72,9 @@ int process_contact(udomain_t * domain, urecord_t ** ul_record, str aor, str cal
static str no_ua = str_init("n/a");
static ucontact_info_t ci;
ucontact_t * ul_contact;
int ret;

pua_reginfo_update_self_op(1);
if (*ul_record == NULL) {
switch(event) {
case EVENT_REGISTERED:
Expand All @@ -81,14 +84,15 @@ int process_contact(udomain_t * domain, urecord_t ** ul_record, str aor, str cal
create a new entry for this user in the usrloc-DB */
if (ul.insert_urecord(domain, &aor, ul_record) < 0) {
LM_ERR("failed to insert new user-record\n");
return RESULT_ERROR;
ret = RESULT_ERROR;
goto done;
}
break;
default:
/* No entry in usrloc and the contact is expired, deleted, unregistered, whatever:
We do not need to do anything. */
return RESULT_NO_CONTACTS;
break;
ret = RESULT_NO_CONTACTS;
goto done;
}
}

Expand Down Expand Up @@ -118,12 +122,14 @@ int process_contact(udomain_t * domain, urecord_t ** ul_record, str aor, str cal
|| (ul.get_ucontact(*ul_record, &contact_uri, &callid, &no_str, cseq+1, &ul_contact) != 0)) {
if (ul.insert_ucontact(*ul_record, &contact_uri, &ci, &ul_contact) < 0) {
LM_ERR("failed to insert new contact\n");
return RESULT_ERROR;
ret = RESULT_ERROR;
goto done;
}
} else {
if (ul.update_ucontact(*ul_record, ul_contact, &ci) < 0) {
LM_ERR("failed to update contact\n");
return RESULT_ERROR;
ret = RESULT_ERROR;
goto done;
}
}
ul_contact = (*ul_record)->contacts;
Expand All @@ -132,7 +138,10 @@ int process_contact(udomain_t * domain, urecord_t ** ul_record, str aor, str cal
ul_contact = ul_contact->next;
}

return RESULT_NO_CONTACTS;
ret = RESULT_NO_CONTACTS;
done:
pua_reginfo_update_self_op(0);
return ret;
}

xmlNodePtr xmlGetNodeByName(xmlNodePtr parent, const char *name) {
Expand Down
12 changes: 12 additions & 0 deletions modules/pua_reginfo/usrloc_cb.c
Expand Up @@ -49,6 +49,12 @@ Call-ID: 9ad9f89f-164d-bb86-1072-52e7e9eb5025.
.</registration>
</reginfo> */

static int _pua_reginfo_self_op = 0;

void pua_reginfo_update_self_op(int v)
{
_pua_reginfo_self_op = v;
}

str* build_reginfo_full(urecord_t * record, str uri, ucontact_t* c, int type) {
xmlDocPtr doc = NULL;
Expand Down Expand Up @@ -221,6 +227,12 @@ void reginfo_usrloc_cb(ucontact_t* c, int type, void* param) {
char id_buf[512];
int id_buf_len;

if(_pua_reginfo_self_op == 1) {
LM_DBG("operation triggered by own action for aor: %.*s (%d)\n",
c->aor->len, c->aor->s, type);
return;
}

content_type.s = "application/reginfo+xml";
content_type.len = 23;

Expand Down
6 changes: 6 additions & 0 deletions modules/pua_reginfo/usrloc_cb.h
Expand Up @@ -21,6 +21,12 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef __PUA_REGINFO_USRLOC_CB__
#define __PUA_REGINFO_USRLOC_CB__

#include "../usrloc/usrloc.h"

void reginfo_usrloc_cb(ucontact_t* c, int type, void* param);
void pua_reginfo_update_self_op(int v);

#endif

0 comments on commit 39d6a77

Please sign in to comment.