1
%% ``The contents of this file are subject to the Erlang Public License,
2
%% Version 1.1, (the "License"); you may not use this file except in
3
%% compliance with the License. You should have received a copy of the
4
%% Erlang Public License along with this software. If not, it can be
5
%% retrieved via the world wide web at http://www.erlang.org/.
7
%% Software distributed under the License is distributed on an "AS IS"
8
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
9
%% the License for the specific language governing rights and limitations
12
%% The Initial Developer of the Original Code is Ericsson Utvecklings AB.
13
%% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings
14
%% AB. All Rights Reserved.''
16
%% $Id: mod_actions.erl,v 1.1 2008/12/17 09:53:34 mikpe Exp $
19
-export([do/1,load/2]).
21
-include("httpd.hrl").
26
case httpd_util:key1search(Info#mod.data,status) of
27
%% A status code has been generated!
28
{StatusCode,PhraseArgs,Reason} ->
29
{proceed,Info#mod.data};
30
%% No status code has been generated!
32
case httpd_util:key1search(Info#mod.data,response) of
33
%% No response has been generated!
35
Path=mod_alias:path(Info#mod.data,Info#mod.config_db,
36
Info#mod.request_uri),
37
Suffix=httpd_util:suffix(Path),
38
MimeType=httpd_util:lookup_mime(Info#mod.config_db,Suffix,
40
Actions=httpd_util:multi_lookup(Info#mod.config_db,action),
41
case action(Info#mod.request_uri,MimeType,Actions) of
43
{proceed,[{new_request_uri,RequestURI}|Info#mod.data]};
45
Scripts=httpd_util:multi_lookup(Info#mod.config_db,script),
46
case script(Info#mod.request_uri,Info#mod.method,Scripts) of
48
{proceed,[{new_request_uri,RequestURI}|Info#mod.data]};
50
{proceed,Info#mod.data}
53
%% A response has been generated or sent!
55
{proceed,Info#mod.data}
59
action(RequestURI,MimeType,[]) ->
61
action(RequestURI,MimeType,[{MimeType,CGIScript}|Rest]) ->
62
{yes,CGIScript++RequestURI};
63
action(RequestURI,MimeType,[_|Rest]) ->
64
action(RequestURI,MimeType,Rest).
66
script(RequestURI,Method,[]) ->
68
script(RequestURI,Method,[{Method,CGIScript}|Rest]) ->
69
{yes,CGIScript++RequestURI};
70
script(RequestURI,Method,[_|Rest]) ->
71
script(RequestURI,Method,Rest).
79
load([$A,$c,$t,$i,$o,$n,$ |Action],[]) ->
80
case regexp:split(Action," ") of
81
{ok,[MimeType,CGIScript]} ->
82
{ok,[],{action,{MimeType,CGIScript}}};
84
{error,?NICE(httpd_conf:clean(Action)++" is an invalid Action")}
86
load([$S,$c,$r,$i,$p,$t,$ |Script],[]) ->
87
case regexp:split(Script," ") of
88
{ok,[Method,CGIScript]} ->
89
{ok,[],{script,{Method,CGIScript}}};
91
{error,?NICE(httpd_conf:clean(Script)++" is an invalid Script")}