Browse Source

Refactored recording setup to streamline it

We had initialization code for recording scattered through
"call_interfaces.c", "call.c", and "recording.c". I moved more of the
actual code into functions within recording.c under the parent function
`detect_setup_recording`. We call this function from "call_interfaces.c".
I moved the disjointed bit of PCAP initialization to occur right below
where we toggle recording on or off.
pull/245/head
Dylan Mikus 10 years ago
committed by Eric Green
parent
commit
466c52c18e
4 changed files with 84 additions and 54 deletions
  1. +0
    -9
      daemon/call.c
  2. +14
    -45
      daemon/call_interfaces.c
  3. +58
    -0
      daemon/recording.c
  4. +12
    -0
      daemon/recording.h

+ 0
- 9
daemon/call.c View File

@ -1523,15 +1523,6 @@ int monologue_offer_answer(struct call_monologue *other_ml, GQueue *streams,
ml_media = other_ml_media = NULL;
if (call->recording != NULL && call->recording->recording_pdumper == NULL) {
str *pcap_path = recording_setup_file(call->recording, call->callid);
if (pcap_path != NULL && call->recording->recording_pdumper != NULL
&& call->recording->meta_fp) {
// Write the location of the PCAP file to the metadata file
fprintf(call->recording->meta_fp, "%s\n", pcap_path->s);
}
}
for (media_iter = streams->head; media_iter; media_iter = media_iter->next) {
sp = media_iter->data;
__C_DBG("processing media stream #%u", sp->index);


+ 14
- 45
daemon/call_interfaces.c View File

@ -25,8 +25,6 @@
int trust_address_def;
int dtls_passive_def;
int set_record_call(struct call *call, str recordcall);
static int call_stream_address_gstring(GString *o, struct packet_stream *ps, enum stream_address_format format) {
int len, ret;
@ -671,7 +669,6 @@ static const char *call_offer_answer_ng(bencode_item_t *input, struct callmaster
str_swap(&totag, &fromtag);
}
bencode_dictionary_get_str(input, "via-branch", &viabranch);
bencode_dictionary_get_str(input, "record-call", &recordcall);
if (sdp_parse(&sdp, &parsed))
return "Failed to parse SDP";
@ -689,24 +686,6 @@ static const char *call_offer_answer_ng(bencode_item_t *input, struct callmaster
if (!call)
goto out;
if (opmode == OP_ANSWER) {
if (recordcall.s) {
set_record_call(call, recordcall);
}
struct recording *recording = call->recording;
if (call->record_call && recording != NULL && recording->meta_fp != NULL) {
fprintf(recording->meta_fp, "\n%s\n", sdp.s);
}
}
bencode_dictionary_get_str(input, "metadata", &metadata);
if (metadata.len > 0 && call->recording != NULL) {
if (call->recording->metadata != NULL) {
free(call->recording->metadata);
}
call->recording->metadata = str_dup(&metadata);
}
if (!call->created_from && addr) {
call->created_from = call_strdup(call, addr);
call->created_from_addr = sin->address;
@ -731,6 +710,12 @@ static const char *call_offer_answer_ng(bencode_item_t *input, struct callmaster
chopper = sdp_chopper_new(&sdp);
bencode_buffer_destroy_add(output->buffer, (free_func_t) sdp_chopper_destroy, chopper);
bencode_dictionary_get_str(input, "record-call", &recordcall);
if (opmode == OP_ANSWER && recordcall.s) {
detect_setup_recording(call, recordcall);
}
ret = monologue_offer_answer(monologue, &streams, &flags);
if (!ret)
ret = sdp_replace(chopper, &parsed, monologue->active_dialogue, &flags);
@ -754,6 +739,14 @@ static const char *call_offer_answer_ng(bencode_item_t *input, struct callmaster
bencode_dictionary_add_iovec(output, "sdp", &g_array_index(chopper->iov, struct iovec, 0),
chopper->iov_num, chopper->str_len);
bencode_dictionary_add_string(output, "result", "ok");
bencode_dictionary_get_str(input, "metadata", &metadata);
if (metadata.len > 0 && call->recording != NULL) {
if (call->recording->metadata != NULL) {
free(call->recording->metadata);
}
call->recording->metadata = str_dup(&metadata);
}
bencode_item_t *recordings = bencode_dictionary_add_list(output, "recordings");
if (call->recording != NULL && call->recording->recording_path != NULL) {
char *recording_path = call->recording->recording_path->s;
@ -1078,27 +1071,3 @@ const char *call_list_ng(bencode_item_t *input, struct callmaster *m, bencode_it
return NULL;
}
/**
* Controls the setting of recording variables on a `struct call *`.
* Sets the `record_call` value on the `struct call`, initializing the
* recording struct if necessary.
*
* Returns a boolean for whether or not the call is being recorded.
*/
int set_record_call(struct call *call, str recordcall) {
if (!str_cmp(&recordcall, "yes")) {
call->record_call = TRUE;
if (call->recording == NULL) {
call->recording = g_slice_alloc0(sizeof(struct recording));
call->recording->recording_pd = NULL;
call->recording->recording_pdumper = NULL;
meta_setup_file(call->recording, call->callid);
}
} else if (!str_cmp(&recordcall, "no")) {
call->record_call = FALSE;
} else {
ilog(LOG_INFO, "\"record-call\" flag %s is invalid flag.", recordcall.s);
}
return call->record_call;
}

+ 58
- 0
daemon/recording.c View File

@ -12,6 +12,8 @@
int maybe_create_spool_dir(char *dirpath);
int set_record_call(struct call *call, str recordcall);
str *init_write_pcap_file(struct call *call);
// Global file reference to the spool directory.
static char *spooldir = NULL;
@ -93,6 +95,62 @@ int maybe_create_spool_dir(char *spoolpath) {
return spool_good;
}
/**
*
* Controls the setting of recording variables on a `struct call *`.
* Sets the `record_call` value on the `struct call`, initializing the
* recording struct if necessary.
* If we do not yet have a PCAP file associated with the call, create it
* and write its file URL to the metadata file.
*
* Returns a boolean for whether or not the call is being recorded.
*/
int detect_setup_recording(struct call *call, str recordcall) {
int is_recording = set_record_call(call, recordcall);
struct recording *recording = call->recording;
if (is_recording && recording != NULL && recording->recording_pdumper == NULL) {
// We haven't set up the PCAP file, so set it up and write the URL to metadata
init_write_pcap_file(call);
}
}
/**
* Controls the setting of recording variables on a `struct call *`.
* Sets the `record_call` value on the `struct call`, initializing the
* recording struct if necessary.
*
* Returns a boolean for whether or not the call is being recorded.
*/
int set_record_call(struct call *call, str recordcall) {
if (!str_cmp(&recordcall, "yes")) {
call->record_call = TRUE;
if (call->recording == NULL) {
call->recording = g_slice_alloc0(sizeof(struct recording));
call->recording->recording_pd = NULL;
call->recording->recording_pdumper = NULL;
meta_setup_file(call->recording, call->callid);
}
} else if (!str_cmp(&recordcall, "no")) {
call->record_call = FALSE;
} else {
ilog(LOG_INFO, "\"record-call\" flag %s is invalid flag.", recordcall.s);
}
return call->record_call;
}
/**
* Checks if we have a PCAP file for the call yet.
* If not, create it and write its location to the metadata file.
*/
str *init_write_pcap_file(struct call *call) {
str *pcap_path = recording_setup_file(call->recording, call->callid);
if (pcap_path != NULL && call->recording->recording_pdumper != NULL
&& call->recording->meta_fp) {
// Write the location of the PCAP file to the metadata file
fprintf(call->recording->meta_fp, "%s\n", pcap_path->s);
}
}
/**
* Create a call metadata file in a temporary location.
* Attaches the filepath and the file pointer to the call struct.


+ 12
- 0
daemon/recording.h View File

@ -30,6 +30,18 @@ struct recording {
*/
void recording_fs_init(char *spooldir);
/**
*
* Controls the setting of recording variables on a `struct call *`.
* Sets the `record_call` value on the `struct call`, initializing the
* recording struct if necessary.
* If we do not yet have a PCAP file associated with the call, create it
* and write its file URL to the metadata file.
*
* Returns a boolean for whether or not the call is being recorded.
*/
int detect_setup_recording(struct call *call, str recordcall);
/**
* Create a call metadata file in a temporary location.
* Attaches the filepath and the file pointer to the call struct.


Loading…
Cancel
Save