[asterisk-bugs] [JIRA] (ASTERISK-24033) Extend STAT to check relative paths (for audio files)

Matt Jordan (JIRA) noreply at issues.asterisk.org
Sat Jul 12 12:34:56 CDT 2014


     [ https://issues.asterisk.org/jira/browse/ASTERISK-24033?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Matt Jordan updated ASTERISK-24033:
-----------------------------------

    Description: 
When playing sound files, I'd like to check existance *before* playing the file (i.e. not by checking Background() result or similar). I found STAT() to check file existance, but it only checks full paths. I think it would have "some extremely obvious (to many people) benefit" if STAT() would also understand relative paths like most sound/file-related functions do.

The way I solved it, with a minimum of files/lines changed, was to add this to funcs/func_env.c in stat_read(), line 286:
*\[EDIT: Inline code removed - mjordan\]*

        if ( data[0] != '/' && *action == 'e' )
        {
                int res = ast_fileexists(data,NULL,NULL);
                if ( res ) strcpy(buf,"1");
                return 0;
        }

(see diff below)

This is only a quick fix that only works for the e(xistance) check, and clearly doesn't recognize either "fmt" or "preflang" arguments to ast_fileexists().

The distinction between relative and absolute paths is very clear so I don't see a risk of breaking existing installations. To be on the extreme safe side, the return statement can also be conditional on the positive result of ast_fileexists().

I read the reasoning behind not allowing globbing in STAT (it was along the lines of "STAT() wraps the underlying stat() system call and should not do more"), which could also hold in this case, but I think most users would expect STAT to behave like other parts of Asterisk and allow relative filenames as well as absolute ones.

Diff against latest svn:

*\[EDIT: Inline code removed - mjordan\]*



  was:
When playing sound files, I'd like to check existance *before* playing the file (i.e. not by checking Background() result or similar). I found STAT() to check file existance, but it only checks full paths. I think it would have "some extremely obvious (to many people) benefit" if STAT() would also understand relative paths like most sound/file-related functions do.

The way I solved it, with a minimum of files/lines changed, was to add this to funcs/func_env.c in stat_read(), line 286:

        if ( data[0] != '/' && *action == 'e' )
        {
                int res = ast_fileexists(data,NULL,NULL);
                if ( res ) strcpy(buf,"1");
                return 0;
        }

(see diff below)

This is only a quick fix that only works for the e(xistance) check, and clearly doesn't recognize either "fmt" or "preflang" arguments to ast_fileexists().

The distinction between relative and absolute paths is very clear so I don't see a risk of breaking existing installations. To be on the extreme safe side, the return statement can also be conditional on the positive result of ast_fileexists().

I read the reasoning behind not allowing globbing in STAT (it was along the lines of "STAT() wraps the underlying stat() system call and should not do more"), which could also hold in this case, but I think most users would expect STAT to behave like other parts of Asterisk and allow relative filenames as well as absolute ones.

Diff against latest svn:

Index: funcs/func_env.c
===================================================================
--- funcs/func_env.c	(revision 418438)
+++ funcs/func_env.c	(working copy)
@@ -283,6 +283,12 @@
 	ast_copy_string(buf, "0", len);
 
 	action = strsep(&data, ",");
+        if ( data[0] != '/' && *action == 'e' )
+        {
+                int res = ast_fileexists(data,NULL,NULL);
+                if ( res ) strcpy(buf,"1");
+                return 0;
+        }
 	if (stat(data, &s)) {
 		return 0;
 	} else {



> Extend STAT to check relative paths (for audio files)
> -----------------------------------------------------
>
>                 Key: ASTERISK-24033
>                 URL: https://issues.asterisk.org/jira/browse/ASTERISK-24033
>             Project: Asterisk
>          Issue Type: Improvement
>      Security Level: None
>          Components: Functions/func_env
>         Environment: any
>            Reporter: M vd S
>            Severity: Trivial
>
> When playing sound files, I'd like to check existance *before* playing the file (i.e. not by checking Background() result or similar). I found STAT() to check file existance, but it only checks full paths. I think it would have "some extremely obvious (to many people) benefit" if STAT() would also understand relative paths like most sound/file-related functions do.
> The way I solved it, with a minimum of files/lines changed, was to add this to funcs/func_env.c in stat_read(), line 286:
> *\[EDIT: Inline code removed - mjordan\]*
>         if ( data[0] != '/' && *action == 'e' )
>         {
>                 int res = ast_fileexists(data,NULL,NULL);
>                 if ( res ) strcpy(buf,"1");
>                 return 0;
>         }
> (see diff below)
> This is only a quick fix that only works for the e(xistance) check, and clearly doesn't recognize either "fmt" or "preflang" arguments to ast_fileexists().
> The distinction between relative and absolute paths is very clear so I don't see a risk of breaking existing installations. To be on the extreme safe side, the return statement can also be conditional on the positive result of ast_fileexists().
> I read the reasoning behind not allowing globbing in STAT (it was along the lines of "STAT() wraps the underlying stat() system call and should not do more"), which could also hold in this case, but I think most users would expect STAT to behave like other parts of Asterisk and allow relative filenames as well as absolute ones.
> Diff against latest svn:
> *\[EDIT: Inline code removed - mjordan\]*



--
This message was sent by Atlassian JIRA
(v6.2#6252)



More information about the asterisk-bugs mailing list