diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index 74b490d00..547016e9c 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -2144,6 +2144,7 @@ static const char *call_offer_answer_ng(ng_command_ctx_t *ctx, enum call_opmode g_auto(sdp_ng_flags) flags; parser_arg output = ctx->resp; const ng_parser_t *parser = ctx->parser_ctx.parser; + g_auto(str) sdp_out = STR_NULL; call_ng_process_flags(&flags, ctx, opmode); @@ -2230,8 +2231,6 @@ static const char *call_offer_answer_ng(ng_command_ctx_t *ctx, enum call_opmode from_ml->tagtype = TO_TAG; } - struct sdp_chopper *chopper = ctx->ngbuf->chopper = sdp_chopper_new(&sdp); - if (flags.drop_traffic_start) { CALL_SET(call, DROP_TRAFFIC); } @@ -2245,9 +2244,17 @@ static const char *call_offer_answer_ng(ng_command_ctx_t *ctx, enum call_opmode /* offer/answer model processing */ if ((ret = monologue_offer_answer(monologues, &streams, &flags)) == 0) { /* if all fine, prepare an outer sdp and save it */ - if ((ret = sdp_replace(chopper, &parsed, to_ml, &flags)) == 0) { + if ((ret = sdp_create(&sdp_out, to_ml, &flags)) == 0) { + /* TODO: should we save sdp_out? */ save_last_sdp(from_ml, &sdp, &parsed, &streams); } + + /* place return output SDP */ + if (sdp_out.len) { + ctx->ngbuf->sdp_out = sdp_out.s; + ctx->parser_ctx.parser->dict_add_str(output, "sdp", &sdp_out); + sdp_out = STR_NULL; /* ownership passed to output */ + } } update_metadata_monologue(from_ml, &flags); @@ -2256,8 +2263,7 @@ static const char *call_offer_answer_ng(ng_command_ctx_t *ctx, enum call_opmode struct recording *recording = call->recording; if (recording != NULL) { meta_write_sdp_before(recording, &sdp, from_ml, opmode); - meta_write_sdp_after(recording, chopper->output, - from_ml, opmode); + meta_write_sdp_after(recording, &sdp_out, from_ml, opmode); recording_response(recording, ctx->parser_ctx.parser, output); } @@ -2286,9 +2292,6 @@ static const char *call_offer_answer_ng(ng_command_ctx_t *ctx, enum call_opmode if (ret) goto out; - if (chopper->output->len) - ctx->parser_ctx.parser->dict_add_str(output, "sdp", &STR_LEN(chopper->output->str, chopper->output->len)); - errstr = NULL; out: return errstr; diff --git a/daemon/recording.c b/daemon/recording.c index e9a46818a..ce3c20551 100644 --- a/daemon/recording.c +++ b/daemon/recording.c @@ -45,7 +45,7 @@ static int vappend_meta_chunk(struct recording *recording, const char *buf, unsi // all methods static int create_spool_dir_all(const char *spoolpath); static void init_all(call_t *call); -static void sdp_after_all(struct recording *recording, GString *str, struct call_monologue *ml, +static void sdp_after_all(struct recording *recording, const str *str, struct call_monologue *ml, enum call_opmode opmode); static void dump_packet_all(struct media_packet *mp, const str *s); static void finish_all(call_t *call, bool discard); @@ -53,7 +53,7 @@ static void finish_all(call_t *call, bool discard); // pcap methods static int rec_pcap_create_spool_dir(const char *dirpath); static void rec_pcap_init(call_t *); -static void sdp_after_pcap(struct recording *, GString *str, struct call_monologue *, enum call_opmode opmode); +static void sdp_after_pcap(struct recording *, const str *str, struct call_monologue *, enum call_opmode opmode); static void dump_packet_pcap(struct media_packet *mp, const str *s); static void finish_pcap(call_t *, bool discard); static void response_pcap(struct recording *, const ng_parser_t *, parser_arg); @@ -61,7 +61,7 @@ static void response_pcap(struct recording *, const ng_parser_t *, parser_arg); // proc methods static void proc_init(call_t *); static void sdp_before_proc(struct recording *, const str *, struct call_monologue *, enum call_opmode); -static void sdp_after_proc(struct recording *, GString *str, struct call_monologue *, enum call_opmode opmode); +static void sdp_after_proc(struct recording *, const str *sdp, struct call_monologue *, enum call_opmode opmode); static void meta_chunk_proc(struct recording *, const char *, const str *); static void update_flags_proc(call_t *call, bool streams); static void finish_proc(call_t *, bool discard); @@ -525,7 +525,7 @@ static char *meta_setup_file(struct recording *recording, const str *meta_prefix /** * Write out a block of SDP to the metadata file. */ -static void sdp_after_pcap(struct recording *recording, GString *s, struct call_monologue *ml, +static void sdp_after_pcap(struct recording *recording, const str *s, struct call_monologue *ml, enum call_opmode opmode) { FILE *meta_fp = recording->pcap.meta_fp; @@ -545,7 +545,7 @@ static void sdp_after_pcap(struct recording *recording, GString *s, struct call_ fprintf(meta_fp, "%s", get_opmode_text(opmode)); fprintf(meta_fp, "\nSDP before RTP packet: %" PRIu64 "\n\n", recording->pcap.packet_num); fflush(meta_fp); - if (write(meta_fd, s->str, s->len) <= 0) + if (write(meta_fd, s->s, s->len) <= 0) ilog(LOG_WARN, "Error writing SDP body to metadata file: %s", strerror(errno)); } @@ -883,10 +883,10 @@ static void sdp_before_proc(struct recording *recording, const str *sdp, struct "SDP from %u before %s", ml->unique_id, get_opmode_text(opmode)); } -static void sdp_after_proc(struct recording *recording, GString *s, struct call_monologue *ml, +static void sdp_after_proc(struct recording *recording, const str *sdp, struct call_monologue *ml, enum call_opmode opmode) { - append_meta_chunk(recording, s->str, s->len, + append_meta_chunk_str(recording, sdp, "SDP from %u after %s", ml->unique_id, get_opmode_text(opmode)); } @@ -1073,7 +1073,7 @@ static void init_all(call_t *call) { proc_init(call); } -static void sdp_after_all(struct recording *recording, GString *s, struct call_monologue *ml, +static void sdp_after_all(struct recording *recording, const str *s, struct call_monologue *ml, enum call_opmode opmode) { sdp_after_pcap(recording, s, ml, opmode); diff --git a/include/recording.h b/include/recording.h index ad6a234e6..a352047d2 100644 --- a/include/recording.h +++ b/include/recording.h @@ -63,7 +63,7 @@ struct recording_method { void (*init_struct)(call_t *); void (*sdp_before)(struct recording *, const str *, struct call_monologue *, enum call_opmode); - void (*sdp_after)(struct recording *, GString *, struct call_monologue *, + void (*sdp_after)(struct recording *, const str *, struct call_monologue *, enum call_opmode); void (*meta_chunk)(struct recording *, const char *, const str *); void (*update_flags)(call_t *call, bool streams); diff --git a/t/auto-daemon-tests-intfs.pl b/t/auto-daemon-tests-intfs.pl index f747d82b8..e8e7018c6 100644 --- a/t/auto-daemon-tests-intfs.pl +++ b/t/auto-daemon-tests-intfs.pl @@ -169,7 +169,7 @@ a=rtcp:PORT SDP - +new_call; offer('intfs selection alias', { direction => [qw(blah baz)] }, < ['SDP version'] }, < ['SDP version'] }, < ['SDP version'] }, < ['SDP version'] }, < ['SDP version'] }, < ['SDP version'] }, < ['SDP version'] }, < ['SDP version'] }, < ['username'] }, < 'remove', "transport-protocol" => "RTP/AVP"}, <