Permalink
Browse files

added a dir_listing function in yaws_api

git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk/yaws@1117 9fbdc01b-0d2c-0410-bfb7-fb27d70d8b52
  • Loading branch information...
1 parent 2c05455 commit f3deff2ace66c01a74051a97a53742376a0ac39e @klacke committed May 24, 2007
Showing with 30 additions and 1 deletion.
  1. +5 −0 man/yaws_api.5
  2. +25 −1 src/yaws_api.erl
View
@@ -363,6 +363,11 @@ Like before, but
calls \fIExefilename\fR to handle the script. The file name of the
script is handed to the executable via a CGI meta variable.
+.TP
+\fBdir_listing(Arg)\fR
+Perform a directory listing. Can be used in special directories
+when we don't want to turn on dir listings for the entire server.
+Always returns ok.
.SH RETURN VALUES from out/1
.PP
View
@@ -56,7 +56,7 @@
-export([parse_set_cookie/1, format_set_cookie/1,
postvar/2, queryvar/2, getvar/2]).
--export([binding/1]).
+-export([binding/1,dir_listing/1, dir_listing/2]).
-import(lists, [map/2, flatten/1, reverse/1]).
@@ -1756,3 +1756,27 @@ setconf(GC0, Groups0) ->
getconf() ->
gen_server:call(yaws_server, getconf, infinity).
+
+%% Function which invokeable typically from an index.yaws file
+dir_listing(Arg) ->
+ dir_listing(Arg, ".").
+dir_listing(Arg, RelDir) ->
+ %% .yaws.auth
+ Dir0 = filename:dirname(Arg#arg.fullpath),
+ Dir = case RelDir of
+ "." -> Dir0;
+ _ -> filename:join([Dir0, RelDir])
+ end,
+ Req = Arg#arg.req,
+ case file:list_dir(Dir) of
+ {ok, Data0} ->
+ Data = Data0 -- [".yaws.auth", "index.yaws"],
+ yaws_ls:list_directory(Arg, Arg#arg.clisock, Data,
+ Dir,
+ Req, false),
+ ok;
+ _Err ->
+ %% Just ignore errors ??, the programmer has to
+ %% make sure it's a valid path here
+ ok
+ end.

0 comments on commit f3deff2

Please sign in to comment.