Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use source address of request as SDP session and media address #168

Closed
wants to merge 9 commits into from

Conversation

juha-h
Copy link
Contributor

@juha-h juha-h commented Oct 19, 2021

This PR always keep SDP session and media addresses up to date with request source address.

@cspiel1
Copy link
Collaborator

cspiel1 commented Oct 19, 2021

I think that src/sip should make no assumptions about the structure of the SIP body. So I suppose that SDP has to be built, encoded outside and then passed to function sip_request(), or similar as buffer.

@juha-h
Copy link
Contributor Author

juha-h commented Oct 19, 2021

I think that src/sip should make no assumptions about the structure of the SIP body. So I suppose that SDP has to be built, encoded outside and then passed to function sip_request(), or similar as buffer.

I don't think that src/sip makes any assumptions about structure of SIP body. It just checks if message body is SDP and if so, updates its laddr using API function. Body is SDP if req->sdp is set.

Edit: In my tests all requests that baresip/re knows about had valid message body when they were sent out.

@juha-h
Copy link
Contributor Author

juha-h commented Oct 19, 2021

Just a summary. This PR is functionally backwards compatible with current behavior. The only API change is in sipsess_connect() function that now takes one more argument (SDP session). Current (buggy) behavior can be preserved by setting value of that argument to NULL.

src/sip/request.c Outdated Show resolved Hide resolved
src/sip/request.c Outdated Show resolved Hide resolved
- Added sdp_encode() call to err chain
@juha-h
Copy link
Contributor Author

juha-h commented Oct 20, 2021 via email

@juha-h
Copy link
Contributor Author

juha-h commented Oct 21, 2021

In this PR, sip/request.c request() function has this piece of code:

	/* add request line and Via header */
	err  = mbuf_printf(mb, "%s %s SIP/2.0\r\n", req->met, req->uri);
	err |= mbuf_printf(mb, "Via: SIP/2.0/%s %J;branch=%s;rport\r\n",
			   sip_transp_name(tp), &laddr, branch);

	/* add Contact header */
	err |= req->sendh ? req->sendh(tp, &laddr, dst, mb, req->arg) : 0;
	err |= mbuf_write_mem(mb, mbuf_buf(req->mb), mbuf_get_left(req->mb));

The name of the called handler is sendh, but actually it is defined in reg/reg.c and only adds contact header, nothing else.

It would seem logical that sendh would handle also the body of the request or there could be more than one handler, for example, message header handler and message body handler. The latter would be set based on what kind of body type is in question, for example, sdp handler and another one just adds Content-Length header and copies the body text to mb.

I don't propose any changes now, since I would not like to delay the fix. The bug was opened against my Android app more than two years ago on Oct 11, 2019 and I would like to finally close it.

@cspiel1
Copy link
Collaborator

cspiel1 commented Oct 21, 2021

It would seem logical that sendh would handle also the body of the request or there could be more than one handler, for example, message header handler and message body handler. The latter would be set based on what kind of body type is in question, for example, sdp handler and another one just adds Content-Length header and copies the body text to mb.

This is a good idea. Will have a look on it soon.

@juha-h
Copy link
Contributor Author

juha-h commented Oct 22, 2021

I was thinking that perhaps sipsess_connect() struct mbuf *desc argument could be replaced with

sip_body_h *bodyh, void *barg

arguments. Then in call.c send_invite, they could have values

body_handler, call->sdp

where body_handler is defined like this:

static int body_handler(const struct sa *laddr, struct mbuf *mb, void *arg)
{
	struct sdp_session *sess;
	struct mbuf *bb = NULL;
	int err = 0;

	sess = (struct sdp_session *)arg;
	if (sess) {
		sdp_session_set_laddr(sess, laddr);
		err = sdp_encode(&bb, sess, true);
		bb->pos = 0;
		err |= mbuf_printf(mb, "Content-Length: %zu\r\n",
				   mbuf_get_left(bb));
		if (mbuf_get_left(bb) > 0) {
			err |= mbuf_write_str(mb, "\r\n");
			err |= mbuf_write_mem(mb, mbuf_buf(bb),
					      mbuf_get_left(bb));
		}
		mem_deref(bb);
	}

	return err;
}

@cspiel1
Copy link
Collaborator

cspiel1 commented Oct 22, 2021

I am currently working on a similar approach.

@juha-h
Copy link
Contributor Author

juha-h commented Oct 22, 2021

I am currently working on a similar approach.

Good, so I don't need to double the work.

@cspiel1
Copy link
Collaborator

cspiel1 commented Oct 22, 2021

re PR: #172
retest PR: baresip/retest#34
baresip PR: baresip/baresip#1645

It works already. But have to fix a shortly added unit test in baresip.

@juha-h
Copy link
Contributor Author

juha-h commented Oct 22, 2021 via email

@cspiel1
Copy link
Collaborator

cspiel1 commented Oct 22, 2021

Christian Spielberger writes:
re PR: #172 retest PR: baresip/retest#34 baresip PR: baresip/baresip#1645 It works already. But have to fix a shortly added unit test in baresip.
Thanks, I'll test tomorrow.

Ok, thanks! I tested only with IP address so far and checked if the SIP Header + Content looks ok.

@juha-h
Copy link
Contributor Author

juha-h commented Oct 23, 2021

Now the test described in baresip/baresip#1631 (comment) worked!

One comment: is the concept of "best effort laddr" still needed?

               [email protected]
[email protected]: selected for request
call uri: sip:[email protected]
ua: using best effort laddr 192.168.213.45

@juha-h
Copy link
Contributor Author

juha-h commented Oct 24, 2021

I'll close this in favor of #172.

@juha-h juha-h closed this Oct 24, 2021
@cspiel1
Copy link
Collaborator

cspiel1 commented Oct 24, 2021

Now the test described in baresip/baresip#1631 (comment) worked!

One comment: is the concept of "best effort laddr" still needed?

               [email protected]
[email protected]: selected for request
call uri: sip:[email protected]
ua: using best effort laddr 192.168.213.45

This is a good question.

@sreimers sreimers deleted the sdp_laddr_fix branch December 10, 2021 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants