Module: kamailio Branch: master Commit: a8162b513443fd688ab66e470748cc948c811a6a URL: https://github.com/kamailio/kamailio/commit/a8162b513443fd688ab66e470748cc94...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2024-08-27T12:38:25+02:00
core: relocated function for stateless forwarding uac style
---
Modified: src/core/forward.c Modified: src/core/forward.h
---
Diff: https://github.com/kamailio/kamailio/commit/a8162b513443fd688ab66e470748cc94... Patch: https://github.com/kamailio/kamailio/commit/a8162b513443fd688ab66e470748cc94...
---
diff --git a/src/core/forward.c b/src/core/forward.c index 1d2b1d5d650..3d2e743cdbd 100644 --- a/src/core/forward.c +++ b/src/core/forward.c @@ -40,6 +40,7 @@ #include "hash_func.h" #include "config.h" #include "parser/msg_parser.h" +#include "parser/parse_uri.h" #include "char_msg_val.h" #include "route.h" #include "events.h" @@ -694,6 +695,70 @@ int forward_request(struct sip_msg *msg, str *dst, unsigned short port, }
+/** + * forward request like initial uac sender, with only one via + */ +int forward_uac_uri(sip_msg_t *msg, str *vuri) +{ + int ret; + dest_info_t dst; + sip_uri_t *u; + sip_uri_t next_hop; + sr_lump_t *anchor; + hdr_field_t *hf; + msg_flags_t msg_flags_bk; + + if(msg == NULL) { + LM_WARN("invalid msg parameter\n"); + return -1; + } + + if(parse_headers(msg, HDR_EOH_F, 0) == -1) { + LM_ERR("error while parsing message\n"); + return -1; + } + /* remove incoming Via headers */ + for(hf = msg->headers; hf; hf = hf->next) { + if(hf->type != HDR_VIA_T) { + continue; + } + anchor = del_lump(msg, hf->name.s - msg->buf, hf->len, 0); + if(anchor == 0) { + LM_ERR("cannot remove Via header\n"); + return -1; + } + } + + init_dest_info(&dst); + if(vuri == NULL || vuri->s == NULL || vuri->len <= 0) { + if(msg->dst_uri.len) { + ret = parse_uri(msg->dst_uri.s, msg->dst_uri.len, &next_hop); + u = &next_hop; + } else { + ret = parse_sip_msg_uri(msg); + u = &msg->parsed_uri; + } + } else { + ret = parse_uri(vuri->s, vuri->len, &next_hop); + u = &next_hop; + } + if(ret < 0) { + LM_ERR("forward - bad uri dropping packet\n"); + return -1; + } + dst.proto = u->proto; + msg_flags_bk = msg->msg_flags; + msg->msg_flags |= FL_VIA_NORECEIVED; + ret = forward_request_mode( + msg, &u->host, u->port_no, &dst, BUILD_NO_VIA1_UPDATE); + msg->msg_flags = msg_flags_bk; + if(ret >= 0) { + return 1; + } + + return -1; +} + int update_sock_struct_from_via( union sockaddr_union *to, struct sip_msg *msg, struct via_body *via) { diff --git a/src/core/forward.h b/src/core/forward.h index a90ce3446ce..5b414a7a64b 100644 --- a/src/core/forward.h +++ b/src/core/forward.h @@ -82,6 +82,7 @@ int forward_request(struct sip_msg *msg, str *dst, unsigned short port, struct dest_info *send_info); int forward_request_mode(struct sip_msg *msg, str *dst, unsigned short port, struct dest_info *send_info, unsigned int mbmode); +int forward_uac_uri(sip_msg_t *msg, str *vuri); int update_sock_struct_from_via( union sockaddr_union *to, struct sip_msg *msg, struct via_body *via);