Example #1
0
int record_route_advertised_address(struct sip_msg* _m, str* _data)
{
    str user = {NULL, 0};
    str *tag = NULL;
    struct lump* l;
    struct lump* l2;
    int use_ob = rr_obb.use_outbound ? rr_obb.use_outbound(_m) : 0;
    int sips;
    int ret = 0;

    user.len = 0;
    user.s = 0;

    if (add_username) {
        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;
    }

    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 = -3;
            goto error;
        }
        l = insert_cond_lump_after(l,
                                   (enable_double_rr == 2) ? COND_TRUE : COND_IF_DIFF_PROTO, 0);
        l2 = insert_cond_lump_before(l2,
                                     (enable_double_rr == 2) ? COND_TRUE : COND_IF_DIFF_PROTO, 0);
        if (!l || !l2) {
            LM_ERR("failed to insert conditional lump\n");
            ret = -4;
            goto error;
        }
        if (build_advertised_rr(l, l2, _data, &user, tag, OUTBOUND,
                                sips) < 0) {
            LM_ERR("failed to insert outbound Record-Route\n");
            ret = -5;
            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 = -6;
        goto error;
    }

    if (build_advertised_rr(l, l2, _data, &user, tag, INBOUND, sips) < 0) {
        LM_ERR("failed to insert outbound Record-Route\n");
        ret = -7;
        goto error;
    }
    ret = 1;
error:
    if ((use_ob == 1) || (use_ob == 2))
        if (user.s != NULL)
            pkg_free(user.s);
    return ret;
}
Example #2
0
int record_route_advertised_address(struct sip_msg* _m, str* _data)
{
	str user;
	str *tag = NULL;
	struct lump* l;
	struct lump* l2;
	int use_ob = rr_obb.use_outbound ? rr_obb.use_outbound(_m) : 0;
	int sips;
	
	user.len = 0;
	user.s = 0;

	if (add_username) {
		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;
		}
		tag = &((struct to_body*)_m->from->parsed)->tag_value;
	}

	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 -3;
		}
		l = insert_cond_lump_after(l, COND_IF_DIFF_PROTO, 0);
		l2 = insert_cond_lump_before(l2, COND_IF_DIFF_PROTO, 0);
		if (!l || !l2) {
			LM_ERR("failed to insert conditional lump\n");
			return -4;
		}
		if (build_advertised_rr(l, l2, _data, &user, tag, OUTBOUND,
					sips) < 0) {
			LM_ERR("failed to insert outbound Record-Route\n");
			return -5;
		}
	}
	
	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 -6;
	}
	
	if (build_advertised_rr(l, l2, _data, &user, tag, INBOUND, sips) < 0) {
		LM_ERR("failed to insert outbound Record-Route\n");
		return -7;
	}
	return 1;
}