diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index 0c0862ce5..8a5109f02 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -809,12 +809,10 @@ static const char *call_offer_answer_ng(bencode_item_t *input, if (!ret) ret = sdp_replace(chopper, &parsed, monologue->active_dialogue, &flags); - struct iovec *sdp_iov = &g_array_index(chopper->iov, struct iovec, 0); - struct recording *recording = call->recording; if (recording != NULL) { meta_write_sdp_before(recording, &sdp, monologue, opmode); - meta_write_sdp_after(recording, sdp_iov, chopper->iov_num, chopper->str_len, + meta_write_sdp_after(recording, chopper->output, monologue, opmode); //only add METADATA chunk if value is changed @@ -848,8 +846,7 @@ static const char *call_offer_answer_ng(bencode_item_t *input, if (ret) goto out; - bencode_dictionary_add_iovec(output, "sdp", sdp_iov, - chopper->iov_num, chopper->str_len); + bencode_dictionary_add_string(output, "sdp", chopper->output->str); errstr = NULL; out: diff --git a/daemon/recording.c b/daemon/recording.c index f1047c7af..2b490faa0 100644 --- a/daemon/recording.c +++ b/daemon/recording.c @@ -38,8 +38,7 @@ static char *meta_setup_file(struct recording *recording); // pcap methods static int pcap_create_spool_dir(const char *dirpath); static void pcap_init(struct call *); -static void sdp_after_pcap(struct recording *, struct iovec *sdp_iov, int iovcnt, - unsigned int str_len, struct call_monologue *, enum call_opmode opmode); +static void sdp_after_pcap(struct recording *, GString *str, struct call_monologue *, enum call_opmode opmode); static void dump_packet_pcap(struct recording *recording, struct packet_stream *sink, const str *s); static void finish_pcap(struct call *); static void response_pcap(struct recording *, bencode_item_t *); @@ -47,8 +46,7 @@ static void response_pcap(struct recording *, bencode_item_t *); // proc methods static void proc_init(struct call *); static void sdp_before_proc(struct recording *, const str *, struct call_monologue *, enum call_opmode); -static void sdp_after_proc(struct recording *, struct iovec *sdp_iov, int iovcnt, - unsigned int str_len, struct call_monologue *, enum call_opmode opmode); +static void sdp_after_proc(struct recording *, GString *str, struct call_monologue *, enum call_opmode opmode); static void meta_chunk_proc(struct recording *, const char *, const str *); static void finish_proc(struct call *); static void dump_packet_proc(struct recording *recording, struct packet_stream *sink, const str *s); @@ -337,8 +335,8 @@ static char *meta_setup_file(struct recording *recording) { /** * Write out a block of SDP to the metadata file. */ -static void sdp_after_pcap(struct recording *recording, struct iovec *sdp_iov, int iovcnt, - unsigned int str_len, struct call_monologue *ml, enum call_opmode opmode) +static void sdp_after_pcap(struct recording *recording, GString *str, struct call_monologue *ml, + enum call_opmode opmode) { FILE *meta_fp = recording->u.pcap.meta_fp; if (!meta_fp) @@ -352,7 +350,7 @@ static void sdp_after_pcap(struct recording *recording, struct iovec *sdp_iov, i fprintf(meta_fp, "%s", get_opmode_text(opmode)); fprintf(meta_fp, "\nSDP before RTP packet: %" PRIu64 "\n\n", recording->u.pcap.packet_num); fflush(meta_fp); - if (writev(meta_fd, sdp_iov, iovcnt) <= 0) + if (write(meta_fd, str->str, str->len) <= 0) ilog(LOG_WARN, "Error writing SDP body to metadata file: %s", strerror(errno)); } @@ -602,21 +600,6 @@ static int vappend_meta_chunk_iov(struct recording *recording, struct iovec *in_ return 0; } -static int append_meta_chunk_iov(struct recording *recording, struct iovec *iov, int iovcnt, - unsigned int str_len, const char *label_fmt, ...) - __attribute__((format(printf,5,6))); - -static int append_meta_chunk_iov(struct recording *recording, struct iovec *iov, int iovcnt, - unsigned int str_len, const char *label_fmt, ...) -{ - va_list ap; - va_start(ap, label_fmt); - int ret = vappend_meta_chunk_iov(recording, iov, iovcnt, str_len, label_fmt, ap); - va_end(ap); - - return ret; -} - static int append_meta_chunk(struct recording *recording, const char *buf, unsigned int buflen, const char *label_fmt, ...) __attribute__((format(printf,4,5))); @@ -670,10 +653,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, struct iovec *sdp_iov, int iovcnt, - unsigned int str_len, struct call_monologue *ml, enum call_opmode opmode) +static void sdp_after_proc(struct recording *recording, GString *str, struct call_monologue *ml, + enum call_opmode opmode) { - append_meta_chunk_iov(recording, sdp_iov, iovcnt, str_len, + append_meta_chunk(recording, str->str, str->len, "SDP from %u after %s", ml->unique_id, get_opmode_text(opmode)); } diff --git a/daemon/recording.h b/daemon/recording.h index a0edca1a2..a64cb98a7 100644 --- a/daemon/recording.h +++ b/daemon/recording.h @@ -68,7 +68,7 @@ struct recording_method { void (*init_struct)(struct call *); void (*sdp_before)(struct recording *, const str *, struct call_monologue *, enum call_opmode); - void (*sdp_after)(struct recording *, struct iovec *, int, unsigned int, struct call_monologue *, + void (*sdp_after)(struct recording *, GString *, struct call_monologue *, enum call_opmode); void (*meta_chunk)(struct recording *, const char *, const str *); diff --git a/daemon/sdp.c b/daemon/sdp.c index eaa886436..573afe042 100644 --- a/daemon/sdp.c +++ b/daemon/sdp.c @@ -1357,23 +1357,15 @@ error: return -1; } -// XXX iovec can probably be eliminated now and this moved to a regular string builder struct sdp_chopper *sdp_chopper_new(str *input) { struct sdp_chopper *c = g_slice_alloc0(sizeof(*c)); c->input = input; - c->chunk = g_string_chunk_new(512); - c->iov = g_array_new(0, 0, sizeof(struct iovec)); + c->output = g_string_new(""); return c; } INLINE void chopper_append(struct sdp_chopper *c, const char *s, int len) { - struct iovec *iov; - - g_array_set_size(c->iov, ++c->iov_num); - iov = &g_array_index(c->iov, struct iovec, c->iov_num - 1); - iov->iov_base = (void *) s; - iov->iov_len = len; - c->str_len += len; + g_string_append_len(c->output, s, len); } INLINE void chopper_append_c(struct sdp_chopper *c, const char *s) { chopper_append(c, s, strlen(s)); @@ -1382,22 +1374,7 @@ INLINE void chopper_append_str(struct sdp_chopper *c, const str *s) { chopper_append(c, s->s, s->len); } -static void chopper_append_dup(struct sdp_chopper *c, const char *s, int len) { - return chopper_append(c, g_string_chunk_insert_len(c->chunk, s, len), len); -} - -static void chopper_append_printf(struct sdp_chopper *c, const char *fmt, ...) __attribute__((format(printf,2,3))); - -static void chopper_append_printf(struct sdp_chopper *c, const char *fmt, ...) { - char buf[512]; - int l; - va_list va; - - va_start(va, fmt); - l = vsnprintf(buf, sizeof(buf) - 1, fmt, va); - va_end(va); - chopper_append(c, g_string_chunk_insert_len(c->chunk, buf, l), l); -} +#define chopper_append_printf(c, f...) g_string_append_printf((c)->output, f) static int copy_up_to_ptr(struct sdp_chopper *chop, const char *b) { int offset, len; @@ -1543,7 +1520,7 @@ static int insert_ice_address(struct sdp_chopper *chop, struct stream_fd *sfd) { int len; call_stream_address46(buf, sfd->stream, SAF_ICE, &len, sfd->local_intf, 0); - chopper_append_dup(chop, buf, len); + chopper_append(chop, buf, len); chopper_append_printf(chop, " %u", sfd->socket.local.port); return 0; @@ -1555,7 +1532,7 @@ static int insert_raddr_rport(struct sdp_chopper *chop, struct packet_stream *ps chopper_append_c(chop, " raddr "); call_stream_address46(buf, ps, SAF_ICE, &len, ifa, 0); - chopper_append_dup(chop, buf, len); + chopper_append(chop, buf, len); chopper_append_c(chop, " rport "); chopper_append_printf(chop, "%u", ps->selected_sfd->socket.local.port); @@ -1586,7 +1563,7 @@ static int replace_network_address(struct sdp_chopper *chop, struct network_addr sockaddr_print_buf(&flags->parsed_media_address)); else call_stream_address46(buf, ps, SAF_NG, &len, NULL, keep_unspec); - chopper_append_dup(chop, buf, len); + chopper_append(chop, buf, len); if (skip_over(chop, &address->address)) return -1; @@ -1595,8 +1572,7 @@ static int replace_network_address(struct sdp_chopper *chop, struct network_addr } void sdp_chopper_destroy(struct sdp_chopper *chop) { - g_string_chunk_free(chop->chunk); - g_array_free(chop->iov, 1); + g_string_free(chop->output, TRUE); g_slice_free1(sizeof(*chop), chop); } @@ -1919,7 +1895,7 @@ static void insert_dtls(struct call_media *media, struct sdp_chopper *chop) { chopper_append_c(chop, "\r\na=fingerprint:"); chopper_append_c(chop, hf->name); chopper_append_c(chop, " "); - chopper_append_dup(chop, hexbuf, o - hexbuf); + chopper_append(chop, hexbuf, o - hexbuf); chopper_append_c(chop, "\r\n"); } @@ -1946,7 +1922,7 @@ static void insert_crypto(struct call_media *media, struct sdp_chopper *chop) { chopper_append_printf(chop, "%u ", media->sdes_out.tag); chopper_append_c(chop, cp->crypto_suite->name); chopper_append_c(chop, " inline:"); - chopper_append_dup(chop, b64_buf, p - b64_buf); + chopper_append(chop, b64_buf, p - b64_buf); if (cp->mki_len) { ull = 0; for (i = 0; i < cp->mki_len && i < sizeof(ull); i++) diff --git a/daemon/sdp.h b/daemon/sdp.h index f31bb1e24..3f208b75e 100644 --- a/daemon/sdp.h +++ b/daemon/sdp.h @@ -10,10 +10,11 @@ struct sdp_chopper { str *input; int position; - GStringChunk *chunk; - GArray *iov; - int iov_num; - int str_len; + GString *output; +// GStringChunk *chunk; +// GArray *iov; +// int iov_num; +// int str_len; }; void sdp_init(void);