~ubuntu-branches/debian/squeeze/erlang/squeeze

« back to all changes in this revision

Viewing changes to lib/inets/src/http_server/mod_actions.erl

  • Committer: Bazaar Package Importer
  • Author(s): Erlang Packagers, Sergei Golovan
  • Date: 2006-12-03 17:07:44 UTC
  • mfrom: (2.1.11 feisty)
  • Revision ID: james.westby@ubuntu.com-20061203170744-rghjwupacqlzs6kv
Tags: 1:11.b.2-4
[ Sergei Golovan ]
Fixed erlang-base and erlang-base-hipe prerm scripts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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/.
 
6
%% 
 
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
 
10
%% under the License.
 
11
%% 
 
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.''
 
15
%% 
 
16
%%     $Id$
 
17
%%
 
18
-module(mod_actions).
 
19
-export([do/1,load/2]).
 
20
 
 
21
-include("httpd.hrl").
 
22
 
 
23
%% do
 
24
 
 
25
do(Info) ->
 
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!
 
31
    undefined ->
 
32
      case httpd_util:key1search(Info#mod.data,response) of
 
33
        %% No response has been generated!
 
34
        undefined ->
 
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,
 
39
                                          "text/plain"),
 
40
          Actions = httpd_util:multi_lookup(Info#mod.config_db,action),
 
41
          case action(Info#mod.request_uri,MimeType,Actions) of
 
42
            {yes, RequestURI} ->
 
43
              {proceed, [{new_request_uri, RequestURI} | Info#mod.data]};
 
44
            no ->
 
45
              Scripts = httpd_util:multi_lookup(Info#mod.config_db, script),
 
46
              case script(Info#mod.request_uri, Info#mod.method, Scripts) of
 
47
                {yes, RequestURI} ->
 
48
                  {proceed,[{new_request_uri, RequestURI} | Info#mod.data]};
 
49
                no ->
 
50
                  {proceed, Info#mod.data} 
 
51
              end
 
52
          end;
 
53
        %% A response has been generated or sent!
 
54
        _Response ->
 
55
          {proceed, Info#mod.data}
 
56
      end
 
57
  end.
 
58
 
 
59
action(_RequestURI, _MimeType, []) ->
 
60
  no;
 
61
action(RequestURI, MimeType, [{MimeType, CGIScript} | _Rest]) ->
 
62
  {yes, CGIScript ++ RequestURI};
 
63
action(RequestURI, MimeType, [_ | Rest]) ->
 
64
  action(RequestURI, MimeType, Rest).
 
65
 
 
66
script(_RequestURI, _Method, []) ->
 
67
  no;
 
68
script(RequestURI, Method, [{Method, CGIScript} | _Rest]) ->
 
69
  {yes, CGIScript ++ RequestURI};
 
70
script(RequestURI, Method, [_ | Rest]) ->
 
71
  script(RequestURI, Method, Rest).
 
72
 
 
73
%%
 
74
%% Configuration
 
75
%%
 
76
 
 
77
%% load
 
78
 
 
79
load("Action "++  Action, []) ->
 
80
  case regexp:split(Action, " ") of
 
81
    {ok,[MimeType, CGIScript]} ->
 
82
      {ok,[],{action, {MimeType, CGIScript}}};
 
83
    {ok,_} ->
 
84
      {error,?NICE(httpd_conf:clean(Action)++" is an invalid Action")}
 
85
  end;
 
86
load("Script " ++ Script,[]) ->
 
87
  case regexp:split(Script, " ") of
 
88
    {ok,[Method, CGIScript]} ->
 
89
      {ok,[],{script, {Method, CGIScript}}};
 
90
    {ok,_} ->
 
91
      {error,?NICE(httpd_conf:clean(Script)++" is an invalid Script")}
 
92
  end.