Skip to content

Commit

Permalink
Added facility for specifying an #auth record when starting embedded
Browse files Browse the repository at this point in the history
When giving a proplist for SC, the option {auth, Opts} can be
given. Opts is a {Key,Value} list where Key shall match the fields
in the #auth{} record. All other options ignored.
  • Loading branch information
uwiger authored and vinoski committed Mar 17, 2012
1 parent cf60207 commit a2c17ec
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/yaws.erl
Expand Up @@ -275,8 +275,8 @@ setup_sconf(DocRoot, D, SL) ->
ets = lkup(ets, SL,
D#sconf.ets),
ssl = setup_sconf_ssl(SL, D#sconf.ssl),
authdirs = lkup(authdirs, SL,
D#sconf.authdirs),
authdirs = lkup(authdirs, expand_auth(SL),
D#sconf.authdirs),
partial_post_size = lkup(partial_post_size, SL,
D#sconf.partial_post_size),
appmods = lkup(appmods, SL,
Expand Down Expand Up @@ -308,6 +308,22 @@ setup_sconf(DocRoot, D, SL) ->
D#sconf.fcgi_app_server),
php_handler = lkup(php_handler, SL, D#sconf.php_handler)}.

expand_auth(SL) ->
case [A || {auth, A} <- SL] of
[] ->
SL;
As ->
[{authdirs, [opts_to_auth(O) || O <- As]}|SL]
end.

opts_to_auth(Opts) ->
{_, Auth} =
lists:foldl(
fun(F, {P,A}) ->
{P+1,setelement(P, A, proplists:get_value(F, Opts, element(P,A)))}
end, {2, #auth{}}, record_info(fields, auth)),
Auth.

setup_sconf_ssl(SL, DefaultSSL) ->
case lkup(ssl, SL, undefined) of
undefined ->
Expand Down

0 comments on commit a2c17ec

Please sign in to comment.