? patch ? apps/app_readfile.c Index: app.c =================================================================== RCS file: /usr/cvsroot/asterisk/app.c,v retrieving revision 1.48 diff -r1.48 app.c 1395a1396,1428 > > char * ast_read_file(char *filename, char *mode) > { > FILE *file; > char line[2048]; > char *output=NULL; > file = fopen(filename, mode); > int count=0; > > if (!file) { > ast_log(LOG_ERROR, "Cannot open file\n"); > return NULL; > } > > while (fgets(line, sizeof(line), file)) { > if (count == 0) { > output=(char *)malloc((strlen(line)+1)*sizeof(char)); > count+=1; > strcpy(output, line); > > } else if (output) { > output=(char *) realloc(output, (strlen(output)+strlen(line)+1)*sizeof(char)); > strcat(output, line); > } else { > ast_log(LOG_ERROR, "Out of memory\n"); > } > > } > > fclose(file); > return output; > } > Index: apps/app_system.c =================================================================== RCS file: /usr/cvsroot/asterisk/apps/app_system.c,v retrieving revision 1.13 diff -r1.13 app_system.c 1c1 < /* --- > /* 20a21 > #include 33c34 < static char *synopsis = "Execute a system command"; --- > static char *synopsis = "System(varname=command,lines)"; 38c39 < " System(command): Executes a command by using system(). Returns -1 on\n" --- > " System(varname=command,lines): Executes a command by using system(). Returns -1 on\n" 42c43,47 < "continue at that priority level. Otherwise, System returns 0.\n"; --- > "continue at that priority level. Otherwise, System returns 0.\n" > " Varname - Result stored here.\n" > " Command - The name of the command to run, optionally enclosed in quotes.\n" > " Lines - Maximum lines to capture. Defaults to infinite.\n"; > 58a64,69 > char *s, *varname=NULL, *program=NULL, *length=NULL, *tempvar, *returnvar=NULL; > char *path=NULL; > char *tail="|tail -n"; > char *cat=" > "; > char *remove=NULL; > int len=0; 62a74 > 64,65c76,138 < /* Do our thing here */ < res = ast_safe_system((char *)data); --- > > s = ast_strdupa(data); > if (!s) { > ast_log(LOG_ERROR, "Out of memory\n"); > return -1; > } > > varname = strsep(&s, "="); > if (s && *s == '"') { > s++; > program = strsep(&s, "\""); > if (s && *s == '|') { > s++; > } > } else { > program = strsep(&s, "|"); > } > length = s; > > if (!program) { > tempvar=varname; > } > > else { > sscanf(length, "%d", &len); > path = (char *)malloc((strlen("/var/spool/asterisk/system/")+strlen(chan->uniqueid)+1)*sizeof(char)); > strcpy(path,"/var/spool/asterisk/system/"); > strcat(path,chan->uniqueid); > > if (len ==0) { > tempvar=(char *)malloc((strlen(program)+strlen(cat)+strlen(path)+1)*sizeof(char)); > strcpy(tempvar,program); > strcat(tempvar,cat); > strcat(tempvar,path); > } > else{ > tempvar=(char *)malloc((strlen(program)+strlen(tail)+strlen(length)+strlen(cat)+strlen(path)+1)*sizeof(char)); > strcpy(tempvar,program); > strcat(tempvar,tail); > strcat(tempvar,length); > strcat(tempvar,cat); > strcat(tempvar,path); > } > } > res = ast_safe_system(tempvar); > > if(!program){ > free(returnvar); > free(path); > } > else{ > > returnvar = ast_read_file(path,"r"); > > remove = (char *)malloc((strlen("rm -f /var/spool/asterisk/system/")+strlen(chan->uniqueid)+1)*sizeof(char)); > strcpy(remove,"rm -f /var/spool/asterisk/system/"); > strcat(remove,chan->uniqueid); > ast_safe_system(remove); > pbx_builtin_setvar_helper(chan, varname, returnvar); > free(returnvar); > free(remove); > free(path); > } 67c140 < ast_log(LOG_WARNING, "Unable to execute '%s'\n", (char *)data); --- > ast_log(LOG_WARNING, "Unable to execute1 '%s'\n", tempvar); 70c143 < ast_log(LOG_WARNING, "Unable to execute '%s'\n", (char *)data); --- > ast_log(LOG_WARNING, "Unable to execute2 '%s'\n", tempvar); 78a152,155 > > if(program) > free(tempvar); > 81a159,160 > > Index: include/asterisk/app.h =================================================================== RCS file: /usr/cvsroot/asterisk/include/asterisk/app.h,v retrieving revision 1.30 diff -r1.30 app.h 129a130,132 > /*Read a file into asterisk*/ > char * ast_read_file(char *file, char* mode); >