Module: kamailio Branch: master Commit: 712d593406540f0bda8e8b6fb707d41bb3df8440 URL: https://github.com/kamailio/kamailio/commit/712d593406540f0bda8e8b6fb707d41bb3df8440
Author: Daniel-Constantin Mierla <[email protected]> Committer: Daniel-Constantin Mierla <[email protected]> Date: 2025-12-12T07:28:53+01:00 core: msg translator - function to parse via branch value --- Modified: src/core/msg_translator.c Modified: src/core/msg_translator.h --- Diff: https://github.com/kamailio/kamailio/commit/712d593406540f0bda8e8b6fb707d41bb3df8440.diff Patch: https://github.com/kamailio/kamailio/commit/712d593406540f0bda8e8b6fb707d41bb3df8440.patch --- diff --git a/src/core/msg_translator.c b/src/core/msg_translator.c index d5f7d410372..d01f13c4eef 100644 --- a/src/core/msg_translator.c +++ b/src/core/msg_translator.c @@ -102,6 +102,8 @@ #include "cfg/cfg.h" #include "parser/parse_to.h" #include "parser/parse_param.h" +#include "parser/parser_f.h" +#include "hash_func.h" #include "forward.h" #include "str_list.h" #include "pvapi.h" @@ -2843,6 +2845,71 @@ char *build_res_buf_from_sip_req(unsigned int code, str *text, str *new_tag, } +int via_branch_parser(str *vbranch, viabranch_t *vb) +{ + char *p; + char *n; + int scan_space; + + /* we do RFC 3261 tid matching and want to see first if there is + * magic cookie in branch */ + if(vbranch->len <= MCOOKIE_LEN) + goto nomatch; + if(memcmp(vbranch->s, MCOOKIE, MCOOKIE_LEN) != 0) + goto nomatch; + + vb->cookie.s = vbranch->s; + vb->cookie.len = MCOOKIE_LEN; + + p = vbranch->s + MCOOKIE_LEN; + scan_space = vbranch->len - MCOOKIE_LEN; + + /* hash_id */ + n = eat_token2_end(p, p + scan_space, BRANCH_SEPARATOR); + vb->shashidx.len = n - p; + scan_space -= vb->shashidx.len; + if(!vb->shashidx.len || scan_space < 2 || *n != BRANCH_SEPARATOR) + goto nomatch; + vb->shashidx.s = p; + p = n + 1; + scan_space--; + + /* md5 value */ + n = eat_token2_end(p, p + scan_space, BRANCH_SEPARATOR); + vb->transid.len = n - p; + scan_space -= vb->transid.len; + if(n == p || scan_space < 2 || *n != BRANCH_SEPARATOR) + goto nomatch; + vb->transid.s = p; + p = n + 1; + scan_space--; + + /* branch id - should exceed the scan_space */ + n = eat_token_end(p, p + scan_space); + vb->sbranchidx.len = n - p; + if(!vb->sbranchidx.len) + goto nomatch; + vb->sbranchidx.s = p; + + /* sanity check */ + if(unlikely(reverse_hex2int(vb->shashidx.s, vb->shashidx.len, &vb->vhashidx) + < 0 + || vb->vhashidx >= TABLE_ENTRIES + || reverse_hex2int(vb->sbranchidx.s, vb->sbranchidx.len, + &vb->vbranchidx) + < 0 + || vb->vbranchidx >= sr_dst_max_branches + || vb->transid.len != MD5_LEN)) { + LM_DBG("poor reply ids - hashidx %d branchidx %d transid-len %d/%d\n", + vb->vhashidx, vb->vbranchidx, vb->transid.len, MD5_LEN); + goto nomatch; + } + return 0; + +nomatch: + return -1; +} + /* return number of chars printed or 0 if space exceeded; assumes buffer size of at least MAX_BRANCH_PARAM_LEN */ diff --git a/src/core/msg_translator.h b/src/core/msg_translator.h index 7e83d85c9cb..7a995e2e90d 100644 --- a/src/core/msg_translator.h +++ b/src/core/msg_translator.h @@ -70,6 +70,15 @@ struct hostport str *port; }; +typedef struct viabranch +{ + str cookie; + str shashidx; + unsigned int vhashidx; + str transid; + str sbranchidx; + unsigned int vbranchidx; +} viabranch_t; #define set_hostport(hp, msg) \ do { \ @@ -118,6 +127,8 @@ char *via_builder(unsigned int *len, sip_msg_t *msg, char *create_via_hf(unsigned int *len, struct sip_msg *msg, struct dest_info *send_info /* where to send the reply */, str *branch); +int via_branch_parser(str *vbranch, viabranch_t *vb); + int branch_builder(unsigned int hash_index, /* only either parameter useful */ unsigned int label, char *char_v, str *xval, int branch, _______________________________________________ Kamailio - Development Mailing List -- [email protected] To unsubscribe send an email to [email protected] Important: keep the mailing list in the recipients, do not reply only to the sender!
