--- apps/app_record.c (svn) +++ apps/app_record.c (working copy) @@ -70,6 +70,34 @@ "If the user should hangup during a recording, all data will be lost and the\n" "application will teminate. \n"; +static char *filename_add_count(const char *fn, int count) +{ + char *realname; + char *tmp; + char cnt[32]; + size_t i; + int can_subst = 1; + + snprintf(cnt, sizeof(cnt), "%d", count); + tmp = realname = malloc(strlen(fn) + strlen(cnt) + 1); + + while( *fn ) + { + if (*fn == '%' && can_subst && fn[1] == 'd') { + strcpy(tmp, cnt); + tmp+=strlen(tmp); + can_subst = 0; + fn++; + } else { + *tmp = *fn; + tmp++; + } + fn++; + } + return realname; +} + + STANDARD_LOCAL_USER; LOCAL_USER_DECL; @@ -82,7 +110,7 @@ char *filename, *ext = NULL, *silstr, *maxstr, *options; char *vdata, *p; int i = 0; - char tmp[256]; + char *realfilename = NULL; struct ast_filestream *s = '\0'; struct localuser *u; @@ -177,23 +205,24 @@ option_quiet = 1; } } - /* done parsing */ /* these are to allow the use of the %d in the config file for a wild card of sort to create a new file with the inputed name scheme */ if (percentflag) { - do { - snprintf(tmp, sizeof(tmp), filename, count); + realfilename = filename_add_count(filename, count); + count++; + while ( ast_fileexists(realfilename, ext, chan->language) != -1 ) + { + free(realfilename); + realfilename = filename_add_count(filename, count); count++; - } while ( ast_fileexists(tmp, ext, chan->language) != -1 ); - pbx_builtin_setvar_helper(chan, "RECORDED_FILE", tmp); + } + pbx_builtin_setvar_helper(chan, "RECORDED_FILE", realfilename); } else - strncpy(tmp, filename, sizeof(tmp)-1); + realfilename = strdup(filename); /* end of routine mentioned */ - - if (chan->_state != AST_STATE_UP) { if (option_skip) { /* At the user's option, skip if the line is not up */ @@ -242,7 +271,7 @@ flags = option_append ? O_CREAT|O_APPEND|O_WRONLY : O_CREAT|O_TRUNC|O_WRONLY; - s = ast_writefile( tmp, ext, NULL, flags , 0, 0644); + s = ast_writefile( realfilename, ext, NULL, flags , 0, 0644); if (!s) { ast_log(LOG_WARNING, "Could not create file %s\n", filename); @@ -337,6 +366,7 @@ if (sildet) ast_dsp_free(sildet); } + free(realfilename); LOCAL_USER_REMOVE(u);