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
/*!
 * \brief Insert manually created Record-Route header
 *
 * Insert manually created Record-Route header, no checks, no restrictions,
 * always adds lr parameter, only fromtag is added automatically when requested.
 * Allocates new private memory for this.
 * \param _m SIP message
 * \param _data manually created RR header
 * \return 1 on success, negative on failure
 */
int record_route_preset(struct sip_msg* _m, str* _data)
{
    str user = {NULL, 0};
    struct to_body* from = NULL;
    struct lump* l;
    char* hdr, *p;
    int hdr_len;
    int use_ob = rr_obb.use_outbound ? rr_obb.use_outbound(_m) : 0;
    char *rr_prefix;
    int rr_prefix_len;
    int sips;
    int ret = 0;

    sips = rr_is_sips(_m);
    if(sips==0) {
        rr_prefix = RR_PREFIX_SIP;
        rr_prefix_len = RR_PREFIX_SIP_LEN;
    } else {
        rr_prefix = RR_PREFIX_SIPS;
        rr_prefix_len = RR_PREFIX_SIPS_LEN;
    }

    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");
            ret = -2;
            goto error;
        }
        from = (struct to_body*)_m->from->parsed;
    }

    l = anchor_lump(_m, _m->headers->name.s - _m->buf, 0, HDR_RECORDROUTE_T);
    if (!l) {
        LM_ERR("failed to create lump anchor\n");
        ret = -3;
        goto error;
    }

    hdr_len = rr_prefix_len;
    if (user.len)
        hdr_len += user.len + 1; /* @ */
    hdr_len += _data->len;

    if (append_fromtag && from->tag_value.len) {
        hdr_len += RR_FROMTAG_LEN + from->tag_value.len;
    }

    if (enable_full_lr) {
        hdr_len += RR_LR_FULL_LEN;
    } else {
        hdr_len += RR_LR_LEN;
    }

    hdr_len += RR_TERM_LEN;

    hdr = pkg_malloc(hdr_len);
    if (!hdr) {
        LM_ERR("no pkg memory left\n");
        ret = -4;
        goto error;
    }

    p = hdr;
    memcpy(p, rr_prefix, rr_prefix_len);
    p += rr_prefix_len;

    if (user.len) {
        memcpy(p, user.s, user.len);
        p += user.len;
        *p = '@';
        p++;
    }

    memcpy(p, _data->s, _data->len);
    p += _data->len;

    if (append_fromtag && from->tag_value.len) {
        memcpy(p, RR_FROMTAG, RR_FROMTAG_LEN);
        p += RR_FROMTAG_LEN;
        memcpy(p, from->tag_value.s, from->tag_value.len);
        p += from->tag_value.len;
    }

    if (enable_full_lr) {
        memcpy(p, RR_LR_FULL, RR_LR_FULL_LEN);
        p += RR_LR_FULL_LEN;
    } else {
        memcpy(p, RR_LR, RR_LR_LEN);
        p += RR_LR_LEN;
    }

    memcpy(p, RR_TERM, RR_TERM_LEN);

    if (!insert_new_lump_after(l, hdr, hdr_len, 0)) {
        LM_ERR("failed to insert new lump\n");
        pkg_free(hdr);
        ret = -5;
        goto error;
    }
    ret = 1;
error:
    if ((use_ob == 1) || (use_ob == 2))
        if (user.s != NULL)
            pkg_free(user.s);
    return ret;
}
Example #3
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;
}
Example #4
0
/*!
 * \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;
}
Example #5
0
/*!
 * \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;
}