MT#56759 split up meta_filepath

These are two different file paths and each belongs to its respective
recording method. Move them into the appropriate struct. Also use
g_clear_pointer() for memory bookkeeping.

Change-Id: I25a897636d4f6e8fea3c533f9ca39c90f81390f8
pull/1642/head
Richard Fuchs 3 years ago
parent 61ad463031
commit 4fde86f981

@ -467,14 +467,13 @@ static char *meta_setup_file(struct recording *recording) {
} }
char *meta_filepath = file_path_str(recording->meta_prefix, "/tmp/rtpengine-meta-", ".tmp"); char *meta_filepath = file_path_str(recording->meta_prefix, "/tmp/rtpengine-meta-", ".tmp");
recording->meta_filepath_pcap = meta_filepath; recording->u.pcap.meta_filepath = meta_filepath;
FILE *mfp = fopen(meta_filepath, "w"); FILE *mfp = fopen(meta_filepath, "w");
// coverity[check_return : FALSE] // coverity[check_return : FALSE]
chmod(meta_filepath, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); chmod(meta_filepath, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
if (mfp == NULL) { if (mfp == NULL) {
ilog(LOG_ERROR, "Could not open metadata file: %s%s%s", FMT_M(meta_filepath)); ilog(LOG_ERROR, "Could not open metadata file: %s%s%s", FMT_M(meta_filepath));
free(meta_filepath); g_clear_pointer(&recording->u.pcap.meta_filepath, free);
recording->meta_filepath_pcap = NULL;
return NULL; return NULL;
} }
recording->u.pcap.meta_fp = mfp; recording->u.pcap.meta_fp = mfp;
@ -553,10 +552,10 @@ static void rec_pcap_meta_finish_file(struct call *call) {
// and move it to the finished file location. // and move it to the finished file location.
// Rename extension to ".txt". // Rename extension to ".txt".
int fn_len; int fn_len;
char *meta_filename = strrchr(recording->meta_filepath_pcap, '/'); char *meta_filename = strrchr(recording->u.pcap.meta_filepath, '/');
char *meta_ext = NULL; char *meta_ext = NULL;
if (meta_filename == NULL) { if (meta_filename == NULL) {
meta_filename = recording->meta_filepath_pcap; meta_filename = recording->u.pcap.meta_filepath;
} }
else { else {
meta_filename = meta_filename + 1; meta_filename = meta_filename + 1;
@ -569,16 +568,17 @@ static void rec_pcap_meta_finish_file(struct call *call) {
char new_metapath[prefix_len + fn_len + ext_len + 1]; char new_metapath[prefix_len + fn_len + ext_len + 1];
snprintf(new_metapath, prefix_len+fn_len+1, "%s/metadata/%s", spooldir, meta_filename); snprintf(new_metapath, prefix_len+fn_len+1, "%s/metadata/%s", spooldir, meta_filename);
snprintf(new_metapath + prefix_len+fn_len, ext_len+1, ".txt"); snprintf(new_metapath + prefix_len+fn_len, ext_len+1, ".txt");
int return_code = rename(recording->meta_filepath_pcap, new_metapath); int return_code = rename(recording->u.pcap.meta_filepath, new_metapath);
if (return_code != 0) { if (return_code != 0) {
ilog(LOG_ERROR, "Could not move metadata file \"%s\" to \"%s/metadata/\"", ilog(LOG_ERROR, "Could not move metadata file \"%s\" to \"%s/metadata/\"",
recording->meta_filepath_pcap, spooldir); recording->u.pcap.meta_filepath, spooldir);
} else { } else {
ilog(LOG_INFO, "Moved metadata file \"%s\" to \"%s/metadata\"", ilog(LOG_INFO, "Moved metadata file \"%s\" to \"%s/metadata\"",
recording->meta_filepath_pcap, spooldir); recording->u.pcap.meta_filepath, spooldir);
} }
mutex_destroy(&recording->u.pcap.recording_lock); mutex_destroy(&recording->u.pcap.recording_lock);
g_clear_pointer(&recording->u.pcap.meta_filepath, free);
} }
@ -711,8 +711,6 @@ void recording_finish(struct call *call) {
free(recording->meta_prefix); free(recording->meta_prefix);
free(recording->escaped_callid); free(recording->escaped_callid);
free(recording->meta_filepath_pcap);
free(recording->meta_filepath_proc);
g_slice_free1(sizeof(*(recording)), recording); g_slice_free1(sizeof(*(recording)), recording);
call->recording = NULL; call->recording = NULL;
@ -727,10 +725,10 @@ void recording_finish(struct call *call) {
static int open_proc_meta_file(struct recording *recording) { static int open_proc_meta_file(struct recording *recording) {
int fd; int fd;
fd = open(recording->meta_filepath_proc, O_WRONLY | O_APPEND | O_CREAT, 0666); fd = open(recording->u.proc.meta_filepath, O_WRONLY | O_APPEND | O_CREAT, 0666);
if (fd == -1) { if (fd == -1) {
ilog(LOG_ERR, "Failed to open recording metadata file '%s' for writing: %s", ilog(LOG_ERR, "Failed to open recording metadata file '%s' for writing: %s",
recording->meta_filepath_proc, strerror(errno)); recording->u.proc.meta_filepath, strerror(errno));
return -1; return -1;
} }
return fd; return fd;
@ -796,8 +794,8 @@ static void proc_init(struct call *call) {
} }
ilog(LOG_DEBUG, "kernel call idx is %u", recording->u.proc.call_idx); ilog(LOG_DEBUG, "kernel call idx is %u", recording->u.proc.call_idx);
recording->meta_filepath_proc = file_path_str(recording->meta_prefix, "/", ".meta"); recording->u.proc.meta_filepath = file_path_str(recording->meta_prefix, "/", ".meta");
unlink(recording->meta_filepath_proc); // start fresh XXX good idea? unlink(recording->u.proc.meta_filepath); // start fresh XXX good idea?
append_meta_chunk_str(recording, &call->callid, "CALL-ID"); append_meta_chunk_str(recording, &call->callid, "CALL-ID");
append_meta_chunk_s(recording, recording->meta_prefix, "PARENT"); append_meta_chunk_s(recording, recording->meta_prefix, "PARENT");
@ -831,7 +829,8 @@ static void finish_proc(struct call *call) {
struct packet_stream *ps = l->data; struct packet_stream *ps = l->data;
ps->recording.u.proc.stream_idx = UNINIT_IDX; ps->recording.u.proc.stream_idx = UNINIT_IDX;
} }
unlink(recording->meta_filepath_proc); unlink(recording->u.proc.meta_filepath);
g_clear_pointer(&recording->u.proc.meta_filepath, free);
} }
static void init_stream_proc(struct packet_stream *stream) { static void init_stream_proc(struct packet_stream *stream) {

@ -28,6 +28,7 @@ struct sdp_ng_flags;
struct recording_pcap { struct recording_pcap {
char *meta_filepath; // full file path
FILE *meta_fp; FILE *meta_fp;
pcap_t *recording_pd; pcap_t *recording_pd;
pcap_dumper_t *recording_pdumper; pcap_dumper_t *recording_pdumper;
@ -39,6 +40,7 @@ struct recording_pcap {
struct recording_proc { struct recording_proc {
unsigned int call_idx; unsigned int call_idx;
char *meta_filepath; // full file path
}; };
struct recording_stream_proc { struct recording_stream_proc {
unsigned int stream_idx; unsigned int stream_idx;
@ -52,8 +54,6 @@ struct recording {
char *escaped_callid; // call-id with dangerous characters escaped char *escaped_callid; // call-id with dangerous characters escaped
char *meta_prefix; // escaped call-id plus random suffix char *meta_prefix; // escaped call-id plus random suffix
char *meta_filepath_proc; // full file path
char *meta_filepath_pcap; // full file path
}; };
struct recording_stream { struct recording_stream {

Loading…
Cancel
Save