Module: sip-router Branch: alexh/master Commit: 74af2df4b37cae1b72c964eed0d1d80cc499f64e URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=74af2df4...
Author: Alex Hermann alex@speakup.nl Committer: Alex Hermann alex@speakup.nl Date: Tue Jul 26 10:32:18 2011 +0200
core/dset: Create contacts with flags as header parameter
---
dset.c | 34 +++++++++++++++++++++++----------- 1 files changed, 23 insertions(+), 11 deletions(-)
diff --git a/dset.c b/dset.c index 2a42d43..a876119 100644 --- a/dset.c +++ b/dset.c @@ -51,9 +51,12 @@ #define CONTACT_DELIM ", " #define CONTACT_DELIM_LEN (sizeof(CONTACT_DELIM) - 1)
-#define Q_PARAM ">;q=" +#define Q_PARAM ";q=" #define Q_PARAM_LEN (sizeof(Q_PARAM) - 1)
+#define FLAGS_PARAM ";flags=" +#define FLAGS_PARAM_LEN (sizeof(FLAGS_PARAM) - 1) + #define PATH_PARAM "?Route=" #define PATH_PARAM_LEN (sizeof(PATH_PARAM) - 1)
@@ -291,6 +294,7 @@ int append_branch(struct sip_msg* msg, str* uri, str* dst_uri, str* path, { str luri;
+ LM_DBG("uri=%.*s q=%d flags=%d\n", uri->len, uri->s, q, flags); /* if we have already set up the maximum number * of branches, don't try new ones */ @@ -422,17 +426,13 @@ static int escape_param(str *sin, str *sout) * end = end of target buffer * Returns pointer to final position in target buffer or 0 on failure */ -char* print_contact_str(char *p, str uri, qvalue_t q, str path, char *end) +char* print_contact_str(char *p, str uri, qvalue_t q, str path, unsigned int flags, char *end) { str buf;
- if (q != Q_UNSPECIFIED) { - if (p + 1 > end) return 0; - *p++ = '<'; - } - /* uri */ - if (p + uri.len > end) return 0; + if (p + uri.len + 1 > end) return 0; + *p++ = '<'; memcpy(p, uri.s, uri.len); p += uri.len;
@@ -450,6 +450,9 @@ char* print_contact_str(char *p, str uri, qvalue_t q, str path, char *end) p += buf.len; }
+ if (p + 1 > end) return 0; + *p++ = '>'; + /* q value (header parameter) */ if (q != Q_UNSPECIFIED) { buf.s = q2str(q, (unsigned int*)&buf.len); @@ -460,6 +463,14 @@ char* print_contact_str(char *p, str uri, qvalue_t q, str path, char *end) p += buf.len; }
+ /* branch flags (header parameter) */ + buf.s = int2str(flags, &buf.len); + if (p + FLAGS_PARAM_LEN + buf.len > end) return 0; + memcpy(p, FLAGS_PARAM, FLAGS_PARAM_LEN); + p += FLAGS_PARAM_LEN; + memcpy(p, buf.s, buf.len); + p += buf.len; + return p; }
@@ -472,6 +483,7 @@ char* print_dset(struct sip_msg* msg, int* len) int i; qvalue_t q; str uri, path; + unsigned int flags; char *p; static char dset[MAX_REDIRECTION_LEN]; char *end = dset + MAX_REDIRECTION_LEN; @@ -480,7 +492,7 @@ char* print_dset(struct sip_msg* msg, int* len) memcpy(dset, CONTACT, CONTACT_LEN); p = dset + CONTACT_LEN; if (msg->new_uri.s) { - p = print_contact_str(p, msg->new_uri, ruri_q, msg->path_vec, end); + p = print_contact_str(p, msg->new_uri, ruri_q, msg->path_vec, ruri_bflags, end); if (!p) goto memfail; i = 1; @@ -489,13 +501,13 @@ char* print_dset(struct sip_msg* msg, int* len) }
init_branch_iterator(); - while ((uri.s = next_branch(&uri.len, &q, 0, &path, 0, 0))) { + while ((uri.s = next_branch(&uri.len, &q, 0, &path, &flags, 0))) { if (i) { if (p + CONTACT_DELIM_LEN > end) goto memfail; memcpy(p, CONTACT_DELIM, CONTACT_DELIM_LEN); p += CONTACT_DELIM_LEN; } - p = print_contact_str(p, uri, q, path, end); + p = print_contact_str(p, uri, q, path, flags, end); if (!p) goto memfail; i++;