Commits

Anonymous committed dfcc534

Got hgweb.cgi to work with inets.

  • Participants
  • Parent commits 03889f3

Comments (0)

Files changed (5)

 { './src/*', [
 	{ i, "./include" },
+	{ i, "/home/tobbe/Kreditor/OTP/install/R13B03/lib/erlang/lib/inets-5.2/src"},
 	{ outdir, "./ebin" },
 	debug_info
 ]}.
 
 { './src/*/*', [
 	{ i, "./include" },
+	{ i, "/home/tobbe/Kreditor/OTP/install/R13B03/lib/erlang/lib/inets-5.2/src"},
 	{ outdir, "./ebin" },
 	debug_info
 ]}.
+INETS_SRC=/home/tobbe/Kreditor/OTP/install/R13B03/lib/erlang/lib/inets-5.2/src

File src/ehttp.erl

 %%% @end
 %%%-------------------------------------------------------------------
 -module(ehttp).
--export([start/0]).
+-export([start/0, stop/0, do/1]).
+-include("httpd.hrl").
 
-start() -> ok.
+-define(DEFAULT_PORT, 8081).
+
+start() ->
+    inets_start().
+
+stop() ->
+    RegName = list_to_atom("httpd_instance_sup_"++
+                           integer_to_list(?DEFAULT_PORT)),
+    inets_stop(whereis(RegName)).
    
+inets_start() ->
+    inets:start(),
+    {ok, CWD} = file:get_cwd(),
+    io:format("CWD=~p~n",[CWD]),
+    {ok, Pid} = 
+        inets:start(httpd, 
+                    [{port, ?DEFAULT_PORT},
+                     {server_name, "ehttp"},
+                     {server_root, CWD},
+                     {document_root, CWD},
+%                     {script, {"GET", "hgwebdir.cgi"}},
+                     {script_alias, {"/hgweb.cgi", CWD++"/hgweb.cgi"}},
+                     {modules, [?MODULE, mod_cgi, mod_dir, mod_get, mod_head]}
+%                     {modules, [?MODULE,mod_get,mod_head]}
+%                     {modules, [mod_get, mod_head, mod_log]]},
+%                     {mime_types, [{"css", "text/css"}, 
+%                                   {"js", "text/javascript"}, 
+%                                   {"html", "text/html"}]}
+                    ]),
+    link(Pid),
+    {ok, Pid}.
+
+inets_stop(Pid) ->
+    inets:stop(httpd, Pid).
+
+do(Info) ->
+    case proplists:get_value(status, Info#mod.data) of
+        %% A status code has been generated!
+        {_StatusCode, _PhraseArgs, _Reason} ->
+            {proceed,Info#mod.data};
+        %% No status code has been generated!
+        undefined ->
+            case proplists:get_value(response, Info#mod.data) of
+                %% No response has been generated!
+                undefined ->
+                    Path = Info#mod.request_uri,
+                    case re:run(Path, "hgweb.cgi", []) of
+                        {match,_} -> 
+                            NewPath = re:replace(Path, 
+                                                 "(.*hgweb.cgi)(.*)(/static.*)", 
+                                                 "\\1\\3", 
+                                                 [{return, list}, global]),
+                            {proceed, [{new_request_uri, NewPath}
+                                       | Info#mod.data]};
+                        _ ->
+                            {proceed, Info#mod.data} 
+                    end
+            end;
+	%% A response has been generated or sent!
+	_Response ->
+            {proceed, Info#mod.data}
+    end.
+	
+

File src/ehttp_app.erl

 -behavior(application).
 
 start(_, _) -> 
+    application:start(inets),
     case ehttp_sup:start_link() of
 	{ok, Pid} -> 
 	    {ok, Pid};

File start.sh

File contents unchanged.