[Asterisk-cvs] asterisk Makefile, 1.111, 1.112 asterisk.c, 1.120, 1.121 file.c, 1.47, 1.48

markster at lists.digium.com markster at lists.digium.com
Mon Sep 6 21:46:24 CDT 2004


Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv21478

Modified Files:
	Makefile asterisk.c file.c 
Log Message:
Merge anthm's "-t" flag (with minor mods) (bug #2380)


Index: Makefile
===================================================================
RCS file: /usr/cvsroot/asterisk/Makefile,v
retrieving revision 1.111
retrieving revision 1.112
diff -u -d -r1.111 -r1.112
--- Makefile	2 Sep 2004 03:34:12 -0000	1.111
+++ Makefile	7 Sep 2004 01:49:08 -0000	1.112
@@ -371,6 +371,7 @@
 	mkdir -p $(DESTDIR)$(ASTSBINDIR)
 	mkdir -p $(DESTDIR)$(ASTVARRUNDIR)
 	mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail
+	mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/tmp
 	install -m 755 asterisk $(DESTDIR)$(ASTSBINDIR)/
 	install -m 755 contrib/scripts/astgenkey $(DESTDIR)$(ASTSBINDIR)/
 	if [ ! -f $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ]; then \

Index: asterisk.c
===================================================================
RCS file: /usr/cvsroot/asterisk/asterisk.c,v
retrieving revision 1.120
retrieving revision 1.121
diff -u -d -r1.120 -r1.121
--- asterisk.c	2 Sep 2004 20:45:24 -0000	1.120
+++ asterisk.c	7 Sep 2004 01:49:08 -0000	1.121
@@ -76,9 +76,11 @@
 int option_initcrypto=0;
 int option_nocolor;
 int option_dumpcore = 0;
+int option_cache_record_files = 0;
 int option_overrideconfig = 0;
 int option_reconnect = 0;
 int fully_booted = 0;
+char record_cache_dir[AST_CACHE_DIR_LEN] = "/var/spool/asterisk/tmp";
 
 static int ast_socket = -1;		/* UNIX Socket for allowing remote control */
 static int ast_consock = -1;		/* UNIX Socket for controlling another asterisk */
@@ -1473,6 +1475,7 @@
 	printf("   -q              Quiet mode (supress output)\n");
 	printf("   -r              Connect to Asterisk on this machine\n");
 	printf("   -R              Connect to Asterisk, and attempt to reconnect if disconnected\n");
+	printf("   -t              Record soundfiles in /tmp and move them where they belong after they are done.\n");
 	printf("   -v              Increase verbosity (multiple v's = more verbose)\n");
 	printf("   -x <cmd>        Execute command <cmd> (only valid with -r)\n");
 	printf("\n");
@@ -1531,6 +1534,33 @@
 		}
 		v = v->next;
 	}
+	v = ast_variable_browse(cfg, "options");
+	while(v) {
+		if(!strcasecmp(v->name, "verbose")) {
+			option_verbose= atoi(v->value);
+		} else if (!strcasecmp(v->name, "debug")) {
+			option_debug= ast_true(v->value);
+		} else if (!strcasecmp(v->name, "nofork")) {
+            option_nofork = ast_true(v->value);
+		} else if (!strcasecmp(v->name, "quiet")) {
+            option_quiet = ast_true(v->value);
+		} else if (!strcasecmp(v->name, "console")) {
+            option_console = ast_true(v->value);
+		} else if (!strcasecmp(v->name, "highpriority")) {
+            option_highpriority = ast_true(v->value);
+		} else if (!strcasecmp(v->name, "initcrypto")) {
+            option_initcrypto = ast_true(v->value);
+		} else if (!strcasecmp(v->name, "nocolor")) {
+            option_nocolor = ast_true(v->value);
+		} else if (!strcasecmp(v->name, "dumpcore")) {
+            option_dumpcore = ast_true(v->value);
+		} else if (!strcasecmp(v->name, "cache_record_files")) {
+            option_cache_record_files = ast_true(v->value);
+		}  else if (!strcasecmp(v->name, "record_cache_dir")) {
+			strncpy(record_cache_dir,v->value,AST_CACHE_DIR_LEN);
+		}
+		v = v->next;
+	}
 	ast_destroy(cfg);
 }
 
@@ -1580,7 +1610,7 @@
 	}
 	*/
 	/* Check for options */
-	while((c=getopt(argc, argv, "hfdvVqprRgcinx:U:G:C:")) != -1) {
+	while((c=getopt(argc, argv, "thfdvVqprRgcinx:U:G:C:")) != -1) {
 		switch(c) {
 		case 'd':
 			option_debug++;
@@ -1615,6 +1645,9 @@
 		case 'q':
 			option_quiet++;
 			break;
+		case 't':
+			option_cache_record_files++;
+			break;
 		case 'x':
 			option_exec++;
 			xarg = optarg;
@@ -1822,8 +1855,13 @@
 		printf(term_quit());
 		exit(1);
 	}
-	/* reload logger in case a custom config handler binded to logger.conf*/
+	/* sync cust config and reload some internals in case a custom config handler binded to them */
+	read_ast_cust_config();
 	reload_logger(0);
+    reload_manager();
+    ast_enum_reload();
+    ast_rtp_reload();
+
 
 	/* We might have the option of showing a console, but for now just
 	   do nothing... */

Index: file.c
===================================================================
RCS file: /usr/cvsroot/asterisk/file.c,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -d -r1.47 -r1.48
--- file.c	15 Jul 2004 14:37:09 -0000	1.47
+++ file.c	7 Sep 2004 01:49:08 -0000	1.48
@@ -22,6 +22,7 @@
 #include <asterisk/translate.h>
 #include <asterisk/utils.h>
 #include <asterisk/lock.h>
+#include <asterisk/app.h>
 #include <errno.h>
 #include <unistd.h>
 #include <stdlib.h>
@@ -71,6 +72,7 @@
 	int flags;
 	mode_t mode;
 	char *filename;
+	char *realfilename;
 	/* Video file stream */
 	struct ast_filestream *vfs;
 	/* Transparently translate from another format -- just once */
@@ -649,6 +651,8 @@
 
 int ast_closestream(struct ast_filestream *f)
 {
+	char *cmd = NULL;
+	size_t size = 0;
 	/* Stop a running stream if there is one */
 	if (f->owner) {
 		if (f->fmt->format < AST_FORMAT_MAX_AUDIO) {
@@ -671,10 +675,24 @@
 		ast_translator_free_path(f->trans);
 		f->trans = NULL;
 	}
-	if (f->filename)
-		free(f->filename);
-	f->filename = NULL;
+
+	if (f->realfilename && f->filename) {
+			size = strlen(f->filename) + strlen(f->realfilename) + 15;
+			cmd = alloca(size);
+			memset(cmd,0,size);
+			snprintf(cmd,size,"/bin/mv -f %s %s",f->filename,f->realfilename);
+			ast_safe_system(cmd);
+	}
 	f->fmt->close(f);
+	if (f->filename) {
+		free(f->filename);
+		f->filename = NULL;
+	}
+	if (f->realfilename) {
+		free(f->realfilename);
+		f->realfilename = NULL;
+	}
+
 	return 0;
 }
 
@@ -816,8 +834,11 @@
 	int fd,myflags = 0;
 	struct ast_format *f;
 	struct ast_filestream *fs=NULL;
-	char *fn;
+	char *fn,*orig_fn=NULL;
 	char *ext;
+	char *buf=NULL;
+	size_t size = 0;
+
 	if (ast_mutex_lock(&formatlock)) {
 		ast_log(LOG_WARNING, "Unable to lock format list\n");
 		return NULL;
@@ -833,11 +854,31 @@
 		if (exts_compare(f->exts, type)) {
 			char *stringp=NULL;
 			/* XXX Implement check XXX */
-			ext = strdup(f->exts);
+			ext = ast_strdupa(f->exts);
 			stringp=ext;
 			ext = strsep(&stringp, "|");
 			fn = build_filename(filename, ext);
 			fd = open(fn, flags | myflags, mode);
+
+			if (option_cache_record_files && fd >= 0) {
+				close(fd);
+				/*
+				   We touch orig_fn just as a place-holder so other things (like vmail) see the file is there.
+				   What we are really doing is writing to record_cache_dir until we are done then we will mv the file into place.
+				*/
+				orig_fn = ast_strdupa(fn); 
+				for (size=0;size<strlen(fn);size++)
+					if (fn[size] == '/')
+						fn[size] = '_';
+
+				size += (strlen(record_cache_dir) + 10);
+				buf = alloca(size);
+				memset(buf,0,size);
+				snprintf(buf,size,"%s/%s",record_cache_dir,fn);
+				free(fn);
+				fn=buf;
+				fd = open(fn, flags | myflags, mode);
+			}
 			if (fd >= 0) {
 				errno = 0;
 				if ((fs = f->rewrite(fd, comment))) {
@@ -845,17 +886,30 @@
 					fs->fmt = f;
 					fs->flags = flags;
 					fs->mode = mode;
-					fs->filename = strdup(filename);
+					if (option_cache_record_files) {
+						fs->realfilename = build_filename(filename, ext);
+						fs->filename = strdup(fn);
+					}
+					else {
+						fs->realfilename = NULL;
+						fs->filename = strdup(filename);
+					}
 					fs->vfs = NULL;
 				} else {
 					ast_log(LOG_WARNING, "Unable to rewrite %s\n", fn);
 					close(fd);
 					unlink(fn);
+					if (orig_fn)
+						unlink(orig_fn);
 				}
-			} else if (errno != EEXIST)
+			} else if (errno != EEXIST) {
 				ast_log(LOG_WARNING, "Unable to open file %s: %s\n", fn, strerror(errno));
-			free(fn);
-			free(ext);
+				if(orig_fn)
+					unlink(orig_fn);
+			}
+			if (!buf) /* if buf != NULL then fn is already free and pointing to it */
+				free(fn);
+
 			break;
 		}
 		f = f->next;




More information about the svn-commits mailing list