From 2a896e5d3c708078d821d8481ba1247cdbf96a23 Mon Sep 17 00:00:00 2001
From: Anthony Minessale II <anthmct@yahoo.com>
Date: Thu, 23 Sep 2004 16:39:33 +0000
Subject: [PATCH] tweak prior commit

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3826 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 app.c             | 15 +++++++++------
 apps/app_record.c | 30 +++++++++++++++++++++++++-----
 2 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/app.c b/app.c
index d602de058b..b273f4c3c6 100755
--- a/app.c
+++ b/app.c
@@ -437,13 +437,16 @@ int ast_control_streamfile(struct ast_channel *chan, char *file, char *fwd, char
 	if (chan)
 		ast_stopstream(chan);
 
-	if (file) {
-		end = strchr(file,':');
-		if (!strcasecmp(end,":end")) {
-			*end = '\0';
-			end++;
+
+	if(file) {
+        if((end = strchr(file,':'))) {
+			if(!strcasecmp(end,":end")) {
+				*end = '\0';
+				end++;
+			}
 		}
-	}
+    }
+
 	for (;;) {
 		gettimeofday(&started,NULL);
 
diff --git a/apps/app_record.c b/apps/app_record.c
index cd46d3e434..c1f06780a2 100755
--- a/apps/app_record.c
+++ b/apps/app_record.c
@@ -56,7 +56,7 @@ static int record_exec(struct ast_channel *chan, void *data)
 	char fil[256];
 	char tmp[256];
 	char ext[10];
-	char * vdata;  /* Used so I don't have to typecast every use of *data */
+	char *vdata;
 	int i = 0;
 	int j = 0;
 
@@ -78,15 +78,32 @@ static int record_exec(struct ast_channel *chan, void *data)
 	int option_skip = 0;
 	int option_noanswer = 0;
 	int rfmt = 0;
+	int flags;
+	char *end=NULL;
+	char *p=NULL;
+
 
-	vdata = data; /* explained above */
 
 	/* The next few lines of code parse out the filename and header from the input string */
-	if (!vdata) { /* no data implies no filename or anything is present */
+	if (!data) { /* no data implies no filename or anything is present */
 		ast_log(LOG_WARNING, "Record requires an argument (filename)\n");
 		return -1;
 	}
+	vdata = ast_strdupa(data);
 	
+	p = vdata;
+	while(p && (p=strchr(p,':'))) {
+		end=p;
+		if(!strcasecmp(end,":end")) {
+			*end='\0';
+			end++;
+			break;
+		}
+		p++;
+		end=NULL;
+	}
+	
+
 	for (; vdata[i] && (vdata[i] != ':') && (vdata[i] != '|'); i++ ) {
 		if ((vdata[i] == '%') && (vdata[i+1] == 'd')) {
 			percentflag = 1;                      /* the wildcard is used */
@@ -205,8 +222,11 @@ static int record_exec(struct ast_channel *chan, void *data)
 			ast_dsp_set_threshold(sildet, 256);
 		}
 
-		s = ast_writefile( tmp, ext, NULL, O_CREAT|O_TRUNC|O_WRONLY , 0, 0644);
-	
+
+		flags = end ? O_CREAT|O_APPEND|O_WRONLY : O_CREAT|O_TRUNC|O_WRONLY;
+		s = ast_writefile( tmp, ext, NULL, flags , 0, 0644);
+
+
 		if (s) {
 			if (maxduration > 0)
 				timeout = time(NULL) + (time_t)maxduration;
-- 
GitLab