[Asterisk-cvs] asterisk/res res_monitor.c,1.6,1.7 res_parking.c,1.15,1.16
martinp at lists.digium.com
martinp at lists.digium.com
Tue Feb 3 10:48:19 CST 2004
Update of /usr/cvsroot/asterisk/res
In directory mongoose.digium.com:/tmp/cvs-serv26567/res
Modified Files:
res_monitor.c res_parking.c
Log Message:
Add recording agent's calls patch. Basically the call starts recording when the agent picks up and the file is stamped with the agent's id and the timestamp. Also optionally a URL link to that file may be inserted in the userfield of the CDR record. By default the recorded file will be mixed if soxmix is available.
Index: res_monitor.c
===================================================================
RCS file: /usr/cvsroot/asterisk/res/res_monitor.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- res_monitor.c 11 Jan 2004 05:58:10 -0000 1.6
+++ res_monitor.c 3 Feb 2004 16:57:00 -0000 1.7
@@ -4,6 +4,7 @@
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <libgen.h> //dirname()
#include <asterisk/lock.h>
#include <asterisk/channel.h>
@@ -48,6 +49,7 @@
const char *fname_base, int need_lock )
{
int res = 0;
+ char tmp[256];
if( need_lock ) {
if (ast_mutex_lock(&chan->lock)) {
@@ -73,11 +75,19 @@
/* Determine file names */
if( fname_base && strlen( fname_base ) ) {
+ int directory = strchr(fname_base, '/') ? 1 : 0;
+ /* try creating the directory just in case it doesn't exist */
+ if (directory) {
+ char *name = strdup(fname_base);
+ snprintf(tmp, sizeof(tmp), "mkdir -p %s",dirname(name));
+ free(name);
+ system(tmp);
+ }
snprintf( monitor->read_filename, FILENAME_MAX, "%s/%s-in",
- AST_MONITOR_DIR, fname_base );
+ directory ? "" : AST_MONITOR_DIR, fname_base );
snprintf( monitor->write_filename, FILENAME_MAX, "%s/%s-out",
- AST_MONITOR_DIR, fname_base );
- *monitor->filename_base = 0;
+ directory ? "" : AST_MONITOR_DIR, fname_base );
+ strncpy(monitor->filename_base, fname_base, sizeof(monitor->filename_base) - 1);
} else {
ast_mutex_lock( &monitorlock );
snprintf( monitor->read_filename, FILENAME_MAX, "%s/audio-in-%ld",
@@ -93,6 +103,7 @@
}
snprintf( monitor->filename_base, FILENAME_MAX, "%s/%s",
AST_MONITOR_DIR, channel_name );
+ monitor->filename_changed = 1;
free( channel_name );
}
@@ -164,7 +175,7 @@
ast_closestream( chan->monitor->write_stream );
}
- if(chan->monitor->filename_base&&strlen(chan->monitor->filename_base)) {
+ if(chan->monitor->filename_changed&&strlen(chan->monitor->filename_base)) {
if( ast_fileexists(chan->monitor->read_filename,NULL,NULL) > 0 ) {
snprintf( filename, FILENAME_MAX, "%s-in",
chan->monitor->filename_base );
@@ -191,7 +202,19 @@
chan->monitor->write_filename );
}
}
-
+ if (chan->monitor->joinfiles && strlen(chan->monitor->filename_base)) {
+ char tmp[255];
+ char *format = !strcasecmp(chan->monitor->format,"wav49") ? "WAV" : chan->monitor->format;
+ char *name = chan->monitor->filename_base;
+ int directory = strchr(name, '/') ? 1 : 0;
+ char *dir = directory ? "" : AST_MONITOR_DIR;
+ snprintf(tmp, sizeof(tmp), "nice -n 19 soxmix %s/%s-in.%s %s/%s-out.%s %s/%s.%s && rm -rf %s/%s-* &", dir, name, format, dir, name, format, dir, name, format, dir, name);
+#if 0
+ ast_verbose("executing %s\n",tmp);
+#endif
+ if (system(tmp) == -1)
+ ast_log(LOG_WARNING, "You might not have the soxmix installed and available in the path, please check.\n");
+ }
free( chan->monitor->format );
free( chan->monitor );
chan->monitor = NULL;
@@ -207,6 +230,7 @@
int ast_monitor_change_fname( struct ast_channel *chan,
const char *fname_base, int need_lock )
{
+ char tmp[256];
if( (!fname_base) || (!strlen(fname_base)) ) {
ast_log( LOG_WARNING,
"Cannot change monitor filename of channel %s to null",
@@ -222,8 +246,17 @@
}
if( chan->monitor ) {
+ int directory = strchr(fname_base, '/') ? 1 : 0;
+ /* try creating the directory just in case it doesn't exist */
+ if (directory) {
+ char *name = strdup(fname_base);
+ snprintf(tmp, sizeof(tmp), "mkdir -p %s",dirname(name));
+ free(name);
+ system(tmp);
+ }
+
snprintf( chan->monitor->filename_base, FILENAME_MAX, "%s/%s",
- AST_MONITOR_DIR, fname_base );
+ directory ? "" : AST_MONITOR_DIR, fname_base );
} else {
ast_log( LOG_WARNING,
"Cannot change monitor filename of channel %s to %s, monitoring not started",
@@ -377,6 +410,12 @@
}
astman_send_ack(s, m, "Stopped monitoring channel");
return 0;
+}
+
+void ast_monitor_setjoinfiles(struct ast_channel *chan, int turnon)
+{
+ if (chan->monitor)
+ chan->monitor->joinfiles = turnon;
}
int load_module(void)
Index: res_parking.c
===================================================================
RCS file: /usr/cvsroot/asterisk/res/res_parking.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- res_parking.c 30 Jan 2004 06:31:25 -0000 1.15
+++ res_parking.c 3 Feb 2004 16:57:00 -0000 1.16
@@ -234,6 +234,18 @@
return -1;
peer->appl = "Bridged Call";
peer->data = chan->name;
+ /* copy the userfield from the B-leg to A-leg if applicable */
+ if (chan->cdr && peer->cdr && strlen(peer->cdr->userfield)) {
+ char tmp[256];
+ if (strlen(chan->cdr->userfield)) {
+ snprintf(tmp, sizeof(tmp), "%s;%s",chan->cdr->userfield, peer->cdr->userfield);
+ ast_cdr_appenduserfield(chan, tmp);
+ } else
+ ast_cdr_setuserfield(chan, peer->cdr->userfield);
+ /* free the peer's cdr without ast_cdr_free complaining */
+ free(peer->cdr);
+ peer->cdr = NULL;
+ }
for (;;) {
res = ast_channel_bridge(chan, peer, (allowdisconnect||allowredirect_out ? AST_BRIDGE_DTMF_CHANNEL_0 : 0) + (allowredirect_in ? AST_BRIDGE_DTMF_CHANNEL_1 : 0), &f, &who);
if (res < 0) {
More information about the svn-commits
mailing list