/*! * \brief Insert a new Record-Route header field with lr parameter * * Insert a new Record-Route header field and also 2nd one if it is enabled * and the realm changed so the 2nd record-route header will be necessary. * \param _m SIP message * \param params RR parameter * \return 0 on success, negative on failure */ int record_route(struct sip_msg* _m, str *params) { struct lump* l, *l2; str user = {NULL, 0}; str* tag; int use_ob = rr_obb.use_outbound ? rr_obb.use_outbound(_m) : 0; int sips; int ret = 0; user.len = 0; if (add_username) { /* check if there is a custom user set */ if (get_custom_user(_m, &user) < 0) { if (get_username(_m, &user) < 0) { LM_ERR("failed to extract username\n"); return -1; } } } else if (use_ob == 1) { if (rr_obb.encode_flow_token(&user, _m->rcv) != 0) { LM_ERR("encoding outbound flow-token\n"); return -1; } } else if (use_ob == 2) { if (copy_flow_token(&user, _m) != 0) { LM_ERR("copying outbound flow-token\n"); return -1; } } if (append_fromtag) { if (is_direction(_m, RR_FLOW_UPSTREAM) == 0) { if (parse_to_header(_m) < 0) { LM_ERR("To parsing failed\n"); ret = -2; goto error; } tag = &((struct to_body*)_m->to->parsed)->tag_value; } else { if (parse_from_header(_m) < 0) { LM_ERR("From parsing failed\n"); ret = -2; goto error; } tag = &((struct to_body*)_m->from->parsed)->tag_value; } } else { tag = 0; } if (rr_param_buf.len && rr_param_msg!=_m->id) { /* rr_params were set for a different message -> reset buffer */ rr_param_buf.len = 0; } sips = rr_is_sips(_m); if (enable_double_rr) { l = anchor_lump(_m, _m->headers->name.s - _m->buf,0,HDR_RECORDROUTE_T); l2 = anchor_lump(_m, _m->headers->name.s - _m->buf, 0, 0); if (!l || !l2) { LM_ERR("failed to create an anchor\n"); ret = -5; goto error; } l = insert_cond_lump_after(l, (enable_double_rr == 2) ? COND_TRUE : COND_IF_DIFF_REALMS, 0); l2 = insert_cond_lump_before(l2, (enable_double_rr == 2) ? COND_TRUE : COND_IF_DIFF_REALMS, 0); if (!l || !l2) { LM_ERR("failed to insert conditional lump\n"); ret = -6; goto error; } if (build_rr(l, l2, &user, tag, params, OUTBOUND, sips) < 0) { LM_ERR("failed to insert outbound Record-Route\n"); ret = -7; goto error; } } l = anchor_lump(_m, _m->headers->name.s - _m->buf, 0, HDR_RECORDROUTE_T); l2 = anchor_lump(_m, _m->headers->name.s - _m->buf, 0, 0); if (!l || !l2) { LM_ERR("failed to create an anchor\n"); ret = -3; goto error; } if (build_rr(l, l2, &user, tag, params, INBOUND, sips) < 0) { LM_ERR("failed to insert inbound Record-Route\n"); ret = -4; goto error; } /* reset the rr_param buffer */ rr_param_buf.len = 0; ret = 0; error: if ((use_ob == 1) || (use_ob == 2)) if (user.s != NULL) pkg_free(user.s); return ret; }
/*! * \brief Insert a new Record-Route header field with lr parameter * * Insert a new Record-Route header field and also 2nd one if it is enabled * and the realm changed so the 2nd record-route header will be necessary. * \param _m SIP message * \param params RR parameter * \return 0 on success, negative on failure */ int record_route(struct sip_msg* _m, str *params) { struct lump* l, *l2; str user; struct to_body* from = NULL; str* tag; int use_ob = rr_obb.use_outbound ? rr_obb.use_outbound(_m) : 0; int sips; user.len = 0; if (add_username) { /* check if there is a custom user set */ if (get_custom_user(_m, &user) < 0) { if (get_username(_m, &user) < 0) { LM_ERR("failed to extract username\n"); return -1; } } } else if (use_ob == 1) { if (rr_obb.encode_flow_token(&user, _m->rcv) != 0) { LM_ERR("encoding outbound flow-token\n"); return -1; } } else if (use_ob == 2) { if (copy_flow_token(&user, _m) != 0) { LM_ERR("copying outbound flow-token\n"); return -1; } } if (append_fromtag) { if (parse_from_header(_m) < 0) { LM_ERR("From parsing failed\n"); return -2; } from = (struct to_body*)_m->from->parsed; tag = &from->tag_value; } else { tag = 0; } if (rr_param_buf.len && rr_param_msg!=_m->id) { /* rr_params were set for a different message -> reset buffer */ rr_param_buf.len = 0; } sips = rr_is_sips(_m); if (enable_double_rr) { l = anchor_lump(_m, _m->headers->name.s - _m->buf,0,HDR_RECORDROUTE_T); l2 = anchor_lump(_m, _m->headers->name.s - _m->buf, 0, 0); if (!l || !l2) { LM_ERR("failed to create an anchor\n"); return -5; } l = insert_cond_lump_after(l, COND_IF_DIFF_REALMS, 0); l2 = insert_cond_lump_before(l2, COND_IF_DIFF_REALMS, 0); if (!l || !l2) { LM_ERR("failed to insert conditional lump\n"); return -6; } if (build_rr(l, l2, &user, tag, params, OUTBOUND, sips) < 0) { LM_ERR("failed to insert outbound Record-Route\n"); return -7; } } l = anchor_lump(_m, _m->headers->name.s - _m->buf, 0, HDR_RECORDROUTE_T); l2 = anchor_lump(_m, _m->headers->name.s - _m->buf, 0, 0); if (!l || !l2) { LM_ERR("failed to create an anchor\n"); return -3; } if (build_rr(l, l2, &user, tag, params, INBOUND, sips) < 0) { LM_ERR("failed to insert inbound Record-Route\n"); return -4; } /* reset the rr_param buffer */ rr_param_buf.len = 0; return 0; }