Module: sip-router Branch: pd/outbound Commit: e3ba8f38f7bd008f72705fb6acd082e65b5a140e URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=e3ba8f38...
Author: Peter Dunkley peter.dunkley@crocodile-rcs.com Committer: Peter Dunkley peter.dunkley@crocodile-rcs.com Date: Thu Mar 14 22:42:16 2013 +0000
core: added ruid to msg and branch structures
---
config.h | 2 ++ dset.c | 19 ++++++++++++++++++- dset.h | 11 ++++++++--- parser/msg_parser.c | 39 +++++++++++++++++++++++++++++++++++++++ parser/msg_parser.h | 5 +++++ 5 files changed, 72 insertions(+), 4 deletions(-)
diff --git a/config.h b/config.h index 2368503..85e6388 100644 --- a/config.h +++ b/config.h @@ -75,6 +75,8 @@
#define MAX_INSTANCE_SIZE 256 /*!< Maximum length of +sip.instance contact header param value buffer */
+#define MAX_RUID_SIZE 65 /*!< Maximum length of ruid 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 536a7ae..d0aef89 100644 --- a/dset.c +++ b/dset.c @@ -297,7 +297,8 @@ void clear_branches(void) 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* instance, unsigned int reg_id, + str* ruid) { str luri;
@@ -381,6 +382,22 @@ int append_branch(struct sip_msg* msg, str* uri, str* dst_uri, str* path, /* copy reg_id */ branches[nr_branches].reg_id = reg_id;
+ /* copy ruid string */ + if (unlikely(ruid && ruid->len && ruid->s)) { + if (unlikely(ruid->len > MAX_RUID_SIZE - 1)) { + LOG(L_ERR, "too long ruid: %.*s\n", + ruid->len, ruid->s); + return -1; + } + memcpy(branches[nr_branches].ruid, ruid->s, + ruid->len); + branches[nr_branches].ruid[ruid->len] = 0; + branches[nr_branches].ruid_len = ruid->len; + } else { + branches[nr_branches].ruid[0] = '\0'; + branches[nr_branches].ruid_len = 0; + } + nr_branches++; return 1; } diff --git a/dset.h b/dset.h index bc131ef..3140f95 100644 --- a/dset.h +++ b/dset.h @@ -66,6 +66,10 @@ struct branch /* reg-id contact header param value */ unsigned int reg_id;
+ /* ruid value from usrloc */ + char ruid[MAX_RUID_SIZE]; + unsigned int ruid_len; + /* Branch flags */ flag_t flags; }; @@ -88,11 +92,12 @@ int drop_sip_branch(int idx); 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* instance, unsigned int reg_id, + str* ruid);
/*! \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) + append_branch(msg, uri, dst_uri, path, q, flags, force_socket, 0, 0, 0)
/*! \brief ser compatible append_branch version. * append_branch version compatible with ser: no path or branch flags support @@ -109,7 +114,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); + return append_branch(msg, &s_uri, &s_dst_uri, 0, q, 0, force_socket, 0, 0, 0); }
diff --git a/parser/msg_parser.c b/parser/msg_parser.c index dfed08d..9e5bd34 100644 --- a/parser/msg_parser.c +++ b/parser/msg_parser.c @@ -859,6 +859,45 @@ void reset_instance(struct sip_msg* const msg) }
+int set_ruid(struct sip_msg* msg, str* ruid) +{ + char* ptr; + + if (unlikely(!msg || !ruid)) { + LM_ERR("invalid ruid parameter value\n"); + return -1; + } + + if (unlikely(ruid->len == 0)) { + reset_ruid(msg); + } else if (msg->ruid.s && (msg->ruid.len >= ruid->len)) { + memcpy(msg->ruid.s, ruid->s, ruid->len); + msg->ruid.len = ruid->len; + } else { + ptr = (char*)pkg_malloc(ruid->len); + if (!ptr) { + LM_ERR("not enough pkg memory for ruid\n"); + return -1; + } + memcpy(ptr, ruid->s, ruid->len); + if (msg->ruid.s) pkg_free(msg->ruid.s); + msg->ruid.s = ptr; + msg->ruid.len = ruid->len; + } + return 0; +} + + +void reset_ruid(struct sip_msg* const msg) +{ + if(msg->ruid.s != 0) { + pkg_free(msg->ruid.s); + } + msg->ruid.s = 0; + msg->ruid.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 79194e3..09a8460 100644 --- a/parser/msg_parser.h +++ b/parser/msg_parser.h @@ -365,6 +365,7 @@ typedef struct sip_msg { str path_vec; str instance; unsigned int reg_id; + str ruid; } sip_msg_t;
/*! \brief pointer to a fakes message which was never received ; @@ -453,6 +454,10 @@ int set_instance(struct sip_msg* msg, str* instance);
void reset_instance(struct sip_msg* const msg);
+int set_ruid(struct sip_msg* msg, str* ruid); + +void reset_ruid(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