Index: app_read.c =================================================================== RCS file: /usr/cvsroot/asterisk/apps/app_read.c,v retrieving revision 1.7 diff -u -r1.7 app_read.c --- app_read.c 22 Jun 2004 19:32:52 -0000 1.7 +++ app_read.c 29 Jun 2004 15:32:18 -0000 @@ -31,13 +31,14 @@ static char *synopsis = "Read a variable"; static char *descrip = -" Read(variable[|filename][|maxdigits]): Reads a #-terminated string of digits from\n" +" Read(variable[|filename][|maxdigits][|option]): Reads a #-terminated string of digits from\n" "the user, optionally playing a given filename first. Returns -1 on hangup or\n" "error and 0 otherwise.\n" " maxdigits -- maximum acceptable number of digits. Stops reading after maxdigits\n" " have been entered (without requiring the user press the '#' key).\n" " Defaults to 0 - no limit - wait for the user press the '#' key.\n" -" Any value below 0 means the same. Max accepted value is 255.\n"; +" Any value below 0 means the same. Max accepted value is 255.\n" +" option -- if 'noanswer', don't answer the line if it isn't up"; STANDARD_LOCAL_USER; @@ -48,21 +49,26 @@ int res = 0; struct localuser *u; char tmp[256]; + char argdata[256] = ""; char *varname; char *filename; char *stringp; char *maxdigitstr; + char *options; + int option_noanswer = 0; int maxdigits=255; if (!data || ast_strlen_zero((char *)data)) { ast_log(LOG_WARNING, "Read requires an argument (variable)\n"); return -1; } - strncpy(tmp, (char *)data, sizeof(tmp)-1); - stringp=(char *)calloc(1,strlen(tmp)+1); - snprintf(stringp,strlen(tmp)+1,"%s",tmp); + strncpy(argdata, (char *)data, sizeof(argdata)-1); + stringp=argdata; varname = strsep(&stringp, "|"); filename = strsep(&stringp, "|"); maxdigitstr = strsep(&stringp,"|"); + options = strsep(&stringp, "|"); + if (options && !strcasecmp(options, "noanswer")) + option_noanswer = 1; if (!(filename) || ast_strlen_zero(filename)) filename = NULL; if (maxdigitstr) { @@ -77,11 +83,10 @@ return -1; } LOCAL_USER_ADD(u); - if (chan->_state != AST_STATE_UP) { - /* Answer if the line isn't up. */ + if (chan->_state != AST_STATE_UP && !option_noanswer) { + /* Answer if the line isn't up (and noaswer option not specified). */ res = ast_answer(chan); } - strncpy(tmp, (char *)varname, sizeof(tmp)-1); if (!res) { ast_stopstream(chan); res = ast_app_getdata(chan, filename, tmp, maxdigits, 0); Index: app_record.c =================================================================== RCS file: /usr/cvsroot/asterisk/apps/app_record.c,v retrieving revision 1.18 diff -u -r1.18 app_record.c --- app_record.c 22 Jun 2004 19:32:52 -0000 1.18 +++ app_record.c 29 Jun 2004 15:32:18 -0000 @@ -29,10 +29,11 @@ static char *synopsis = "Record to a file"; static char *descrip = -" Record(filename:format|silence): Records from the channel into a given\n" +" Record(filename:format|silence[|option]): Records from the channel into a given\n" "filename. If the file exists it will be overwritten. \n" "- 'format' is the format of the file type to be recorded (wav, gsm, etc).\n" "- 'silence' is the number of seconds of silence to allow before returning.\n\n" +"- 'option' if 'noanswer', don't answer the line if it is not up." "If filename contains '%d', these characters will be replaced with a number\n" "incremented by one each time the file is recorded. \n\n" "Formats: g723, g729, gsm, h263, ulaw, alaw, vox, wav, WAV\n\n" @@ -65,7 +66,8 @@ int silence = 0; /* amount of silence to allow */ int gotsilence = 0; /* did we timeout for silence? */ char silencestr[5]; - int k = 0; + char option[16]; + int option_noanswer = 0; int rfmt = 0; vdata = data; /* explained above */ @@ -80,30 +82,50 @@ if ((vdata[i] == '%') && (vdata[i+1] == 'd')) { percentflag = 1; /* the wildcard is used */ } - - if (i == strlen(vdata) ) { - ast_log(LOG_WARNING, "No extension found\n"); - return -1; - } - fil[i] = vdata[i]; + if (j < sizeof(fil) - 1) + fil[j++] = vdata[i]; + } + fil[j] = '\0'; + + if (vdata[i] != ':') { + ast_log(LOG_WARNING, "No extension found\n"); + return -1; } - fil[i++] = '\0'; + i++; - for (; j < 10 && i < strlen(data) && (vdata[i] != '|'); i++, j++) - ext[j] = vdata[i]; + j = 0; + for (; vdata[i] && (vdata[i] != '|'); i++) + if (j < sizeof(ext) - 1) + ext[j++] = vdata[i]; ext[j] = '\0'; - if (vdata[i] && (vdata[i] == '|')) i++; - for (; vdata[i] && (vdata[i] != '|') && (k < 3) && i < strlen(data); i++, k++) - silencestr[k] = vdata[i]; - silencestr[k] = '\0'; + if (vdata[i] == '|') + i++; - if (silencestr) { + j = 0; + for (; vdata[i] && (vdata[i] != '|'); i++) + if (j < sizeof(silencestr) - 1) + silencestr[j++] = vdata[i]; + silencestr[j] = '\0'; + + if (j > 0) { silence = atoi(silencestr); if (silence > 0) silence *= 1000; } + if (vdata[i] == '|') + i++; + + j = 0; + for (; vdata[i] && (vdata[i] != '|'); i++) + if (j < sizeof(option) - 1) + option[j++] = vdata[i]; + option[j] = '\0'; + + if (!strcasecmp(option, "noanswer")) + option_noanswer = 1; + /* done parsing */ @@ -111,17 +133,17 @@ create a new file with the inputed name scheme */ if (percentflag) { do { - snprintf(tmp, 256, fil, count); + snprintf(tmp, sizeof(tmp)-1, fil, count); count++; } while ( ast_fileexists(tmp, ext, chan->language) != -1 ); pbx_builtin_setvar_helper(chan, "RECORDED_FILE", tmp); } else - strncpy(tmp, fil, 256-1); + strncpy(tmp, fil, sizeof(tmp)-1); /* end of routine mentioned */ LOCAL_USER_ADD(u); - if (chan->_state != AST_STATE_UP) { + if (chan->_state != AST_STATE_UP && !option_noanswer) { res = ast_answer(chan); /* Shouldn't need this, but checking to see if channel is already answered * Theoretically asterisk should already have answered before running the app */ }