Module: sip-router
Branch: master
Commit: 8ca114df0fad44e4819cf80840f90e526ff655b4
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=8ca114d…
Author: Peter Dunkley <peter.dunkley(a)crocodile-rcs.com>
Committer: Peter Dunkley <peter.dunkley(a)crocodile-rcs.com>
Date: Sat May 18 00:13:11 2013 +0100
core: added fields to message structure and branch structure to hold user-agent string
retrieved from usrloc
---
action.c | 2 +-
config.h | 2 ++
dset.c | 36 ++++++++++++++++++++++++++++++------
dset.h | 13 ++++++++-----
parser/msg_parser.c | 39 +++++++++++++++++++++++++++++++++++++++
parser/msg_parser.h | 5 +++++
select_core.c | 6 +++---
7 files changed, 88 insertions(+), 15 deletions(-)
diff --git a/action.c b/action.c
index e2d9550..6fa85da 100644
--- a/action.c
+++ b/action.c
@@ -509,7 +509,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg*
msg)
ret=append_branch(msg, &a->val[0].u.str, &msg->dst_uri,
&msg->path_vec, a->val[1].u.number,
(flag_t)flags, msg->force_send_socket,
- 0, 0, 0);
+ 0, 0, 0, 0);
/* if the uri is the ruri and q was also not changed, mark
ruri as consumed, to avoid having an identical branch */
if ((a->val[0].u.str.s == 0 || a->val[0].u.str.len == 0) &&
diff --git a/config.h b/config.h
index 1465f1e..32cd55c 100644
--- a/config.h
+++ b/config.h
@@ -77,6 +77,8 @@
#define MAX_RUID_SIZE 65 /*!< Maximum length of ruid for location records */
+#define MAX_UA_SIZE 255 /*!< Maximum length of user-agent for location records */
+
#define MY_VIA "Via: SIP/2.0/UDP "
#define MY_VIA_LEN (sizeof(MY_VIA) - 1)
diff --git a/dset.c b/dset.c
index 296f7c4..98be023 100644
--- a/dset.c
+++ b/dset.c
@@ -216,7 +216,7 @@ void set_branch_iterator(int n)
char* get_branch(unsigned int i, int* len, qvalue_t* q, str* dst_uri,
str* path, unsigned int *flags,
struct socket_info** force_socket,
- str *ruid, str *instance)
+ str *ruid, str *instance, str *location_ua)
{
if (i < nr_branches) {
*len = branches[i].len;
@@ -241,6 +241,11 @@ char* get_branch(unsigned int i, int* len, qvalue_t* q, str*
dst_uri,
instance->len = branches[i].instance_len;
instance->s = (instance->len)?branches[i].instance:0;
}
+ if (location_ua) {
+ location_ua->len = branches[i].location_ua_len;
+ location_ua->s
+ = (location_ua->len)?branches[i].location_ua:0;
+ }
return branches[i].uri;
} else {
*len = 0;
@@ -265,6 +270,10 @@ char* get_branch(unsigned int i, int* len, qvalue_t* q, str*
dst_uri,
instance->s = 0;
instance->len = 0;
}
+ if (location_ua) {
+ location_ua->s = 0;
+ location_ua->len = 0;
+ }
return 0;
}
}
@@ -276,12 +285,12 @@ char* get_branch(unsigned int i, int* len, qvalue_t* q, str*
dst_uri,
*/
char* next_branch(int* len, qvalue_t* q, str* dst_uri, str* path,
unsigned int* flags, struct socket_info** force_socket,
- str* ruid, str *instance)
+ str* ruid, str *instance, str *location_ua)
{
char* ret;
ret=get_branch(branch_iterator, len, q, dst_uri, path, flags,
- force_socket, ruid, instance);
+ force_socket, ruid, instance, location_ua);
if (likely(ret))
branch_iterator++;
return ret;
@@ -316,7 +325,7 @@ int append_branch(struct sip_msg* msg, str* uri, str* dst_uri, str*
path,
qvalue_t q, unsigned int flags,
struct socket_info* force_socket,
str* instance, unsigned int reg_id,
- str* ruid)
+ str* ruid, str* location_ua)
{
str luri;
@@ -416,6 +425,21 @@ int append_branch(struct sip_msg* msg, str* uri, str* dst_uri, str*
path,
branches[nr_branches].ruid_len = 0;
}
+ if (unlikely(location_ua && location_ua->len && location_ua->s))
{
+ if (unlikely(location_ua->len > MAX_UA_SIZE)) {
+ LOG(L_ERR, "too long location_ua: %.*s\n",
+ location_ua->len, location_ua->s);
+ return -1;
+ }
+ memcpy(branches[nr_branches].location_ua, location_ua->s,
+ location_ua->len);
+ branches[nr_branches].location_ua[location_ua->len] = 0;
+ branches[nr_branches].location_ua_len = location_ua->len;
+ } else {
+ branches[nr_branches].location_ua[0] = '\0';
+ branches[nr_branches].location_ua_len = 0;
+ }
+
nr_branches++;
return 1;
}
@@ -450,7 +474,7 @@ char* print_dset(struct sip_msg* msg, int* len)
crt_branch = get_branch_iterator();
init_branch_iterator();
- while ((uri.s = next_branch(&uri.len, &q, 0, 0, 0, 0, 0, 0))) {
+ while ((uri.s = next_branch(&uri.len, &q, 0, 0, 0, 0, 0, 0, 0))) {
cnt++;
*len += uri.len;
if (q != Q_UNSPECIFIED) {
@@ -491,7 +515,7 @@ char* print_dset(struct sip_msg* msg, int* len)
}
init_branch_iterator();
- while ((uri.s = next_branch(&uri.len, &q, 0, 0, 0, 0, 0, 0))) {
+ while ((uri.s = next_branch(&uri.len, &q, 0, 0, 0, 0, 0, 0, 0))) {
if (i) {
memcpy(p, CONTACT_DELIM, CONTACT_DELIM_LEN);
p += CONTACT_DELIM_LEN;
diff --git a/dset.h b/dset.h
index 3741fcb..dc15eba 100644
--- a/dset.h
+++ b/dset.h
@@ -70,6 +70,9 @@ struct branch
char ruid[MAX_RUID_SIZE];
unsigned int ruid_len;
+ char location_ua[MAX_UA_SIZE + 1];
+ unsigned int location_ua_len;
+
/* Branch flags */
flag_t flags;
};
@@ -93,11 +96,11 @@ int append_branch(struct sip_msg* msg, str* uri, str* dst_uri, str*
path,
qvalue_t q, unsigned int flags,
struct socket_info* force_socket,
str* instance, unsigned int reg_id,
- str* ruid);
+ str* ruid, str* location_ua);
/*! \brief kamailio compatible version */
#define km_append_branch(msg, uri, dst_uri, path, q, flags, force_socket) \
- append_branch(msg, uri, dst_uri, path, q, flags, force_socket, 0, 0, 0)
+ append_branch(msg, uri, dst_uri, path, q, flags, force_socket, 0, 0, 0, 0)
/*! \brief ser compatible append_branch version.
* append_branch version compatible with ser: no path or branch flags support
@@ -114,7 +117,7 @@ static inline int ser_append_branch(struct sip_msg* msg,
s_uri.len=uri_len;
s_dst_uri.s=dst_uri;
s_dst_uri.len=dst_uri_len;
- return append_branch(msg, &s_uri, &s_dst_uri, 0, q, 0, force_socket, 0, 0,
0);
+ return append_branch(msg, &s_uri, &s_dst_uri, 0, q, 0, force_socket, 0, 0, 0,
0);
}
@@ -140,12 +143,12 @@ void set_branch_iterator(int n);
*/
char* next_branch(int* len, qvalue_t* q, str* dst_uri, str* path,
unsigned int* flags, struct socket_info** force_socket,
- str *ruid, str *instance);
+ str *ruid, str *instance, str *location_ua);
char* get_branch( unsigned int i, int* len, qvalue_t* q, str* dst_uri,
str* path, unsigned int *flags,
struct socket_info** force_socket,
- str* ruid, str *instance);
+ str* ruid, str *instance, str *location_ua);
/*! \brief
* Empty the array of branches
diff --git a/parser/msg_parser.c b/parser/msg_parser.c
index 9e5bd34..d8709e4 100644
--- a/parser/msg_parser.c
+++ b/parser/msg_parser.c
@@ -898,6 +898,45 @@ void reset_ruid(struct sip_msg* const msg)
}
+int set_ua(struct sip_msg* msg, str* location_ua)
+{
+ char* ptr;
+
+ if (unlikely(!msg || !location_ua)) {
+ LM_ERR("invalid location_ua parameter value\n");
+ return -1;
+ }
+
+ if (unlikely(location_ua->len == 0)) {
+ reset_ua(msg);
+ } else if (msg->location_ua.s && (msg->location_ua.len >=
location_ua->len)) {
+ memcpy(msg->location_ua.s, location_ua->s, location_ua->len);
+ msg->location_ua.len = location_ua->len;
+ } else {
+ ptr = (char*)pkg_malloc(location_ua->len);
+ if (!ptr) {
+ LM_ERR("not enough pkg memory for location_ua\n");
+ return -1;
+ }
+ memcpy(ptr, location_ua->s, location_ua->len);
+ if (msg->location_ua.s) pkg_free(msg->location_ua.s);
+ msg->location_ua.s = ptr;
+ msg->location_ua.len = location_ua->len;
+ }
+ return 0;
+}
+
+
+void reset_ua(struct sip_msg* const msg)
+{
+ if(msg->location_ua.s != 0) {
+ pkg_free(msg->location_ua.s);
+ }
+ msg->location_ua.s = 0;
+ msg->location_ua.len = 0;
+}
+
+
hdr_field_t* get_hdr(const sip_msg_t* const msg, const enum _hdr_types_t ht)
{
hdr_field_t *hdr;
diff --git a/parser/msg_parser.h b/parser/msg_parser.h
index 37d1ecb..d58ea5e 100644
--- a/parser/msg_parser.h
+++ b/parser/msg_parser.h
@@ -366,6 +366,7 @@ typedef struct sip_msg {
str instance;
unsigned int reg_id;
str ruid;
+ str location_ua;
struct {
int decoded;
@@ -463,6 +464,10 @@ int set_ruid(struct sip_msg* msg, str* ruid);
void reset_ruid(struct sip_msg* const msg);
+int set_ua(struct sip_msg* msg, str *location_ua);
+
+void reset_ua(struct sip_msg* const msg);
+
/** force a specific send socket for forwarding a request.
* @param msg - sip msg.
* @param fsocket - forced socket, pointer to struct socket_info, can be 0 (in
diff --git a/select_core.c b/select_core.c
index 130a9fd..4d8fe06 100644
--- a/select_core.c
+++ b/select_core.c
@@ -1621,7 +1621,7 @@ int select_branch_uri(str* res, select_t* s, struct sip_msg* msg) {
char *c;
init_branch_iterator();
len = 0;
- while ((c = next_branch(&l, &q, &dst_uri, 0, 0, 0, 0, 0))) {
+ while ((c = next_branch(&l, &q, &dst_uri, 0, 0, 0, 0, 0, 0))) {
if (s->params[SEL_POS].v.i & SEL_BRANCH_DST_URI) {
l = dst_uri.len;
@@ -1645,7 +1645,7 @@ int select_branch_uri(str* res, select_t* s, struct sip_msg* msg) {
init_branch_iterator();
res->len = 0;
n = 0;
- while ((c = next_branch(&l, &q, &dst_uri, 0, 0, 0, 0, 0))) {
+ while ((c = next_branch(&l, &q, &dst_uri, 0, 0, 0, 0, 0, 0))) {
if (s->params[SEL_POS].v.i & SEL_BRANCH_DST_URI) {
l = dst_uri.len;
c = dst_uri.s;
@@ -1687,7 +1687,7 @@ int select_branch_uri(str* res, select_t* s, struct sip_msg* msg) {
if (n < 0 || n >= nr_branches)
return -1;
init_branch_iterator();
- for (; (c = next_branch(&l, &q, &dst_uri, 0, 0, 0, 0, 0)) && n;
n--);
+ for (; (c = next_branch(&l, &q, &dst_uri, 0, 0, 0, 0, 0, 0)) && n;
n--);
if (!c) return 1;
if (s->params[SEL_POS].v.i & SEL_BRANCH_DST_URI) {