@ -133,7 +133,7 @@ static void __monologue_destroy(struct call_monologue *monologue);
static int monologue_destroy ( struct call_monologue * ml ) ;
/* Generate a random PCAP filepath to write recorded RTP stream. */
void setup_recording_files ( struct call * call , struct call_monologue * monologue ) ;
str * setup_recording_file ( struct call * call , struct call_monologue * monologue ) ;
/* Generates a random string sandwiched between affixes. */
char * rand_affixed_str ( int num_bytes , char * prefix , char * suffix ) ;
/* Generates a hex string representing n random bytes. len(rand_str) = 2*num_bytes + 1 */
@ -1532,7 +1532,10 @@ int monologue_offer_answer(struct call_monologue *other_ml, GQueue *streams,
ml_media = other_ml_media = NULL ;
setup_recording_files ( call , monologue ) ;
str * pcap_path = setup_recording_file ( call , monologue ) ;
if ( pcap_path ! = NULL ) {
fprintf ( call - > meta_fp , " %s \n " , pcap_path - > s ) ;
}
for ( media_iter = streams - > head ; media_iter ; media_iter = media_iter - > next ) {
sp = media_iter - > data ;
@ -2225,12 +2228,51 @@ void call_destroy(struct call *c) {
c - > recording_pcaps = g_slist_delete_link ( c - > recording_pcaps , c - > recording_pcaps ) ;
}
/ / TODO - here is where we write out metadata for IPC communication
meta_file_finish ( c ) ;
free ( c - > metadata ) ;
rwlock_unlock_w ( & c - > master_lock ) ;
}
/**
* Writes metadata to metafile , closes file , and renames it to finished location .
* Returns non - zero for failure .
*/
int meta_file_finish ( struct call * call ) {
int return_code = 0 ;
if ( call - > meta_fp ! = NULL ) {
fprintf ( call - > meta_fp , " \n %s \n " , call - > metadata - > s ) ;
fclose ( call - > meta_fp ) ;
/ / Get the filename ( in between its directory and the file extension )
/ / and move it to the finished file location .
/ / Rename extension to " .txt " .
int fn_len ;
char * meta_filename = strrchr ( call - > meta_filepath - > s , ' / ' ) ;
char * meta_ext = NULL ;
if ( meta_filename = = NULL )
meta_filename = call - > meta_filepath - > s ;
else
meta_filename = meta_filename + 1 ;
/ / We can always expect a file extension
meta_ext = strrchr ( meta_filename , ' . ' ) ;
fn_len = meta_ext - meta_filename ;
int prefix_len = 30 ; / / for " /var/spool/rtpengine/metadata/ "
int ext_len = 4 ; / / for " .txt "
char new_metapath [ prefix_len + fn_len + ext_len + 1 ] ;
snprintf ( new_metapath , prefix_len + fn_len + 1 , " /var/spool/rtpengine/metadata/%s " , meta_filename ) ;
snprintf ( new_metapath + prefix_len + fn_len , ext_len + 1 , " .txt " ) ;
return_code = return_code | rename ( call - > meta_filepath - > s , new_metapath ) ;
}
if ( call - > meta_filepath ! = NULL ) {
free ( call - > meta_filepath - > s ) ;
free ( call - > meta_filepath ) ;
}
return return_code ;
}
/* XXX move these */
@ -2334,6 +2376,22 @@ static struct call *call_create(const str *callid, struct callmaster *m) {
c - > created = poller_now ;
c - > dtls_cert = dtls_cert ( ) ;
c - > tos = m - > conf . default_tos ;
int rand_bytes = 16 ;
str * meta_filepath = malloc ( sizeof ( str ) ) ;
/ / Initially file extension is " .tmp " . When call is over , it changes to " .txt " .
char * path_chars = rand_affixed_str ( rand_bytes , " /tmp/rtpengine-meta- " , " .tmp " ) ;
meta_filepath = str_init ( meta_filepath , path_chars ) ;
c - > meta_filepath = meta_filepath ;
FILE * mfp = fopen ( meta_filepath - > s , " w " ) ;
if ( mfp = = NULL ) {
ilog ( LOG_ERROR , " Could not open metadata file: %s " , meta_filepath - > s ) ;
free ( c - > meta_filepath - > s ) ;
free ( c - > meta_filepath ) ;
c - > meta_filepath = NULL ;
}
c - > meta_fp = mfp ;
return c ;
}
@ -2867,12 +2925,13 @@ out:
/**
* Generate a random PCAP filepath to write recorded RTP stream .
*/
void setup_recording_files ( struct call * call , struct call_monologue * monologue ) {
str * setup_recording_file ( struct call * call , struct call_monologue * monologue ) {
str * recording_path = NULL ;
if ( call - > record_call
& & monologue - > recording_pd = = NULL & & monologue - > recording_pdumper = = NULL ) {
int rand_bytes = 16 ;
str * recording_path = malloc ( sizeof ( str ) ) ;
char * path_chars = rand_affixed_str ( rand_bytes , " /tm p/ " , " .pcap " ) ;
recording_path = malloc ( sizeof ( str ) ) ;
char * path_chars = rand_affixed_str ( rand_bytes , " /var/spool/r tpengine/recordings / " , " .pcap " ) ;
recording_path = str_init ( recording_path , path_chars ) ;
monologue - > recording_path = recording_path ;
@ -2882,9 +2941,12 @@ void setup_recording_files(struct call *call, struct call_monologue *monologue)
monologue - > recording_pd = pcap_open_dead ( DLT_RAW , 65535 ) ;
monologue - > recording_pdumper = pcap_dump_open ( monologue - > recording_pd , recording_path ) ;
} else {
monologue - > recording_path = NULL ;
monologue - > recording_pd = NULL ;
monologue - > recording_pdumper = NULL ;
}
return recording_path ;
}
/**