Module: sip-router
Branch: master
Commit: 542eb50fa3f30265488a5fa1ea6871b3bc101891
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=542eb50…
Author: Carsten Bock <carsten(a)ng-voice.com>
Committer: Carsten Bock <carsten(a)ng-voice.com>
Date: Wed May 30 12:53:03 2012 +0200
- improved URI while publishing user location
- extended user-record-data in the XML
Credits go to Gnaneshwar Gatla, InTouch Health
---
modules_k/pua_reginfo/notify.c | 40 ++++++++++++++++++++++++++--------
modules_k/pua_reginfo/pua_reginfo.c | 3 ++
modules_k/pua_reginfo/pua_reginfo.h | 4 +-
modules_k/pua_reginfo/usrloc_cb.c | 36 +++++++++++++++++++++++++++++-
4 files changed, 69 insertions(+), 14 deletions(-)
diff --git a/modules_k/pua_reginfo/notify.c b/modules_k/pua_reginfo/notify.c
index b006633..3b20e4e 100644
--- a/modules_k/pua_reginfo/notify.c
+++ b/modules_k/pua_reginfo/notify.c
@@ -1,7 +1,7 @@
/*
* pua_reginfo module - Presence-User-Agent Handling of reg events
*
- * Copyright (C) 2011 Carsten Bock, carsten(a)ng-voice.com
+ * Copyright (C) 2011-2012 Carsten Bock, carsten(a)ng-voice.com
*
http://www.ng-voice.com
*
* This file is part of Kamailio, a free SIP server.
@@ -104,8 +104,8 @@ int process_contact(udomain_t * domain, urecord_t ** ul_record, str
aor, str cal
/* Now we start looking for the contact: */
if (((*ul_record)->contacts == 0)
- || (ul.get_ucontact(*ul_record, &aor, &callid, &no_str, cseq+1,
&ul_contact) != 0)) {
- if (ul.insert_ucontact(*ul_record, &aor, &ci, &ul_contact) < 0) {
+ || (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;
}
@@ -200,6 +200,9 @@ int process_body(str notify_body, udomain_t * domain) {
str aor = {0, 0};
str callid = {0, 0};
str contact_uri = {0, 0};
+ str received = {0,0};
+ str path = {0,0};
+ str user_agent = {0, 0};
int state, event, expires, result, final_result = RESULT_ERROR;
char * expires_char, * cseq_char;
int cseq = 0;
@@ -247,13 +250,13 @@ int process_body(str notify_body, udomain_t * domain) {
}
/* Now let's lock that domain for this AOR: */
- ul.lock_udomain(domain, &parsed_aor.user);
+ ul.lock_udomain(domain, &aor);
/* and retrieve the user-record for this user: */
- result = ul.get_urecord(domain, &parsed_aor.user, &ul_record);
+ result = ul.get_urecord(domain, &aor, &ul_record);
if (result < 0) {
- ul.unlock_udomain(domain, &parsed_aor.user);
- LM_ERR("failed to query usrloc (User %.*s)\n",
- parsed_aor.user.len, parsed_aor.user.s);
+ ul.unlock_udomain(domain, &aor);
+ LM_ERR("failed to query usrloc (AOR %.*s)\n",
+ aor.len, aor.s);
goto next_registration;
}
/* If no contacts found, then set the ul_record to NULL */
@@ -271,7 +274,7 @@ int process_body(str notify_body, udomain_t * domain) {
}
ul_contact = ul_contact->next;
}
- if (ul.delete_urecord(domain, &parsed_aor.user, ul_record) < 0) {
+ if (ul.delete_urecord(domain, &aor, ul_record) < 0) {
LM_ERR("failed to remove record from usrloc\n");
}
/* If already a registration with contacts was found, then keep that result.
@@ -291,6 +294,23 @@ int process_body(str notify_body, udomain_t * domain) {
goto next_contact;
}
callid.len = strlen(callid.s);
+ received.s = xmlGetAttrContentByName(contacts, "received");
+ if (received.s == NULL) {
+ LM_DBG("No received for this
contact!\n");
+ }
+ received.len - strlen(received.s);
+
+ path.s = xmlGetAttrContentByName(contacts, "path");
+ if (received.s == NULL) {
+ LM_DBG("No path for this contact!\n");
+ }
+ path.len = strlen(path.s);
+
+ user_agent.s = xmlGetAttrContentByName(contacts, "user_agent");
+ if (received.s == NULL) {
+ LM_DBG("No user_agent for this
contact!\n");
+ }
+ user_agent.len = strlen(user_agent.s);
event = reginfo_parse_event(xmlGetAttrContentByName(contacts, "event"));
if (event == EVENT_UNKNOWN) {
@@ -349,7 +369,7 @@ next_contact:
next_registration:
// if (ul_record) ul.release_urecord(ul_record);
/* Unlock the domain for this AOR: */
- ul.unlock_udomain(domain, &parsed_aor.user);
+ ul.unlock_udomain(domain, &aor);
registrations = registrations->next;
}
diff --git a/modules_k/pua_reginfo/pua_reginfo.c b/modules_k/pua_reginfo/pua_reginfo.c
index d5e4328..a9ffe76 100644
--- a/modules_k/pua_reginfo/pua_reginfo.c
+++ b/modules_k/pua_reginfo/pua_reginfo.c
@@ -33,6 +33,9 @@
MODULE_VERSION
+usrloc_api_t ul; /*!< Structure containing pointers to usrloc functions*/
+pua_api_t pua; /*!< Structure containing pointers to PUA functions*/
+
/* Default domain to be added, if none provided. */
str default_domain = {NULL, 0};
str outbound_proxy = {NULL, 0};
diff --git a/modules_k/pua_reginfo/pua_reginfo.h b/modules_k/pua_reginfo/pua_reginfo.h
index f5b14c8..2ff8e54 100644
--- a/modules_k/pua_reginfo/pua_reginfo.h
+++ b/modules_k/pua_reginfo/pua_reginfo.h
@@ -31,7 +31,7 @@ str default_domain;
str outbound_proxy;
str server_address;
-usrloc_api_t ul; /*!< Structure containing pointers to usrloc functions*/
-pua_api_t pua; /*!< Structure containing pointers to PUA functions*/
+extern usrloc_api_t ul; /*!< Structure containing pointers to usrloc functions*/
+extern pua_api_t pua; /*!< Structure containing pointers to PUA functions*/
#endif
diff --git a/modules_k/pua_reginfo/usrloc_cb.c b/modules_k/pua_reginfo/usrloc_cb.c
index 725c21b..1833034 100644
--- a/modules_k/pua_reginfo/usrloc_cb.c
+++ b/modules_k/pua_reginfo/usrloc_cb.c
@@ -142,10 +142,32 @@ str* build_reginfo_full(urecord_t * record, str uri, ucontact_t* c,
int type) {
memset(buf, 0, sizeof(buf));
buf_len = snprintf(buf, sizeof(buf), "%.*s", ptr->callid.len,
ptr->callid.s);
xmlNewProp(contact_node, BAD_CAST "callid", BAD_CAST buf);
+
/* CSeq Attribute */
memset(buf, 0, sizeof(buf));
buf_len = snprintf(buf, sizeof(buf), "%d", ptr->cseq);
xmlNewProp(contact_node, BAD_CAST "cseq", BAD_CAST buf);
+
+ /* received Attribute */
+ memset(buf, 0, sizeof(buf));
+ buf_len = snprintf(buf, sizeof(buf), "%.*s",
ptr->received.len, ptr->received.s);
+ xmlNewProp(contact_node, BAD_CAST "received", BAD_CAST buf);
+
+ /* path Attribute */
+ memset(buf, 0, sizeof(buf));
+ buf_len = snprintf(buf, sizeof(buf), "%.*s", ptr->path.len,
ptr->path.s);
+ xmlNewProp(contact_node, BAD_CAST "path", BAD_CAST buf);
+
+ /* user_agent Attribute */
+ memset(buf, 0, sizeof(buf));
+ buf_len = snprintf(buf, sizeof(buf), "%.*s", ptr->user_agent.len,
ptr->user_agent.s);
+ xmlNewProp(contact_node, BAD_CAST "user_agent", BAD_CAST buf);
+
+ /* CSeq Attribute */
+ memset(buf, 0, sizeof(buf));
+ buf_len = snprintf(buf, sizeof(buf), "%d", ptr->cseq);
+ xmlNewProp(contact_node, BAD_CAST "cseq", BAD_CAST buf);
+
/* URI-Node */
memset(buf, 0, sizeof(buf));
buf_len = snprintf(buf, sizeof(buf), "%.*s", ptr->c.len, ptr->c.s);
@@ -198,6 +220,8 @@ void reginfo_usrloc_cb(ucontact_t* c, int type, void* param) {
urecord_t * record;
int res;
str uri = {NULL, 0};
+ str user = {NULL, 0};
+
char* at = NULL;
char id_buf[512];
int id_buf_len;
@@ -215,11 +239,19 @@ void reginfo_usrloc_cb(ucontact_t* c, int type, void* param) {
LM_ERR("Unknown Type %i\n", type);
return;
}
+ /* make a local copy of the AOR */
+ user.len = c->aor->len;
+ user.s = c->aor->s;
/* Get the UDomain for this account */
- ul.get_udomain(c->domain->s, &domain);
+ res = ul.get_udomain(c->domain->s, &domain);
+ if(res < 0) {
+ LM_ERR("no domain found\n");
+ return;
+ }
+
/* Get the URecord for this AOR */
- res = ul.get_urecord(domain, c->aor, &record);
+ res = ul.get_urecord(domain, &user, &record);
if (res > 0) {
LM_ERR("' %.*s (%.*s)' Not found in usrloc\n", c->aor->len,
c->aor->s, c->domain->len, c->domain->s);
return;