MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / insert_path_as_route

Function insert_path_as_route

msg_translator.c:2066–2117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2064#define ROUTE_STR "Route: "
2065#define ROUTE_LEN (sizeof(ROUTE_STR)-1)
2066static inline int insert_path_as_route(struct sip_msg* msg, str* path)
2067{
2068 struct lump *anchor;
2069 char *route;
2070 struct hdr_field *hf, *last_via=0;
2071
2072 for (hf = msg->headers; hf; hf = hf->next) {
2073 if (hf->type == HDR_ROUTE_T) {
2074 break;
2075 } else if (hf->type == HDR_VIA_T) {
2076 last_via = hf;
2077 }
2078 }
2079 if (hf) {
2080 /* Route HF found, insert before it */
2081 anchor = anchor_lump(msg, hf->name.s - msg->buf, 0);
2082 } else if(last_via) {
2083 if (last_via->next) {
2084 /* Via HF in between, insert after it */
2085 anchor = anchor_lump(msg, last_via->next->name.s - msg->buf, 0);
2086 } else {
2087 /* Via HF is last, so append */
2088 anchor = anchor_lump(msg, msg->unparsed - msg->buf, 0);
2089 }
2090 } else {
2091 /* None of the above, insert as first */
2092 anchor = anchor_lump(msg, msg->headers->name.s - msg->buf, 0);
2093 }
2094
2095 if (anchor == 0) {
2096 LM_ERR("failed to get anchor\n");
2097 return -1;
2098 }
2099
2100 route = pkg_malloc(ROUTE_LEN + path->len + CRLF_LEN);
2101 if (!route) {
2102 LM_ERR("out of pkg memory\n");
2103 return -1;
2104 }
2105 memcpy(route, ROUTE_STR, ROUTE_LEN);
2106 memcpy(route + ROUTE_LEN, path->s, path->len);
2107 memcpy(route + ROUTE_LEN + path->len, CRLF, CRLF_LEN);
2108
2109 if (insert_new_lump_before(anchor, route, ROUTE_LEN + path->len + CRLF_LEN, 0) == 0) {
2110 LM_ERR("failed to insert lump\n");
2111 return -1;
2112 }
2113
2114 msg->msg_flags |= FL_HAS_ROUTE_LUMP;
2115
2116 return 0;
2117}
2118
2119int is_del_via1_lump(struct sip_msg* msg)
2120{

Callers 1

Calls 2

anchor_lumpFunction · 0.85
insert_new_lump_beforeFunction · 0.85

Tested by

no test coverage detected