Skip to content

Commit

Permalink
refactor network address formatting to a standalone function so it ca…
Browse files Browse the repository at this point in the history
…n be reused
  • Loading branch information
guss77 committed Dec 10, 2019
1 parent 8e207e0 commit 3adf514
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
10 changes: 10 additions & 0 deletions daemon/call_interfaces.c
Original file line number Diff line number Diff line change
Expand Up @@ -1945,3 +1945,13 @@ int call_interfaces_init() {

return 0;
}


void format_network_address(str* o, struct packet_stream *ps, struct sdp_ng_flags *flags, int keep_unspec) {
if (!is_addr_unspecified(&flags->parsed_media_address))
o->len = sprintf(o->s, "%s %s",
flags->parsed_media_address.family->rfc_name,
sockaddr_print_buf(&flags->parsed_media_address));
else
call_stream_address46(o->s, ps, SAF_NG, &o->len, NULL, keep_unspec);
}
13 changes: 4 additions & 9 deletions daemon/sdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,7 @@ static int replace_network_address(struct sdp_chopper *chop, struct network_addr
struct packet_stream *ps, struct sdp_ng_flags *flags, int keep_unspec)
{
char buf[64];
int len;
str res = { buf, 0 };
struct packet_stream *sink = packet_stream_sink(ps);

if (is_addr_unspecified(&address->parsed)
Expand All @@ -1583,14 +1583,9 @@ static int replace_network_address(struct sdp_chopper *chop, struct network_addr

if (flags->media_address.s && is_addr_unspecified(&flags->parsed_media_address))
__parse_address(&flags->parsed_media_address, NULL, NULL, &flags->media_address);

if (!is_addr_unspecified(&flags->parsed_media_address))
len = sprintf(buf, "%s %s",
flags->parsed_media_address.family->rfc_name,
sockaddr_print_buf(&flags->parsed_media_address));
else
call_stream_address46(buf, ps, SAF_NG, &len, NULL, keep_unspec);
chopper_append(chop, buf, len);

format_network_address(&res, ps, flags, keep_unspec);
chopper_append(chop, res.s, res.len);

if (skip_over(chop, &address->address))
return -1;
Expand Down
1 change: 1 addition & 0 deletions include/call_interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,6 @@ void ng_call_stats(struct call *call, const str *fromtag, const str *totag, benc

int call_interfaces_init(void);

void format_network_address(str* o, struct packet_stream *ps, struct sdp_ng_flags *flags, int keep_unspec);

#endif

0 comments on commit 3adf514

Please sign in to comment.