Browse files

add the soap_srv_mods support, which can setup soap serve modules whi…

…le yaws start.
  • Loading branch information...
1 parent ded4870 commit d8df08cf3a0fb3e686103deaf584b1258f69880e @ericliang ericliang committed with Nov 19, 2009
Showing with 56 additions and 10 deletions.
  1. +5 −1 include/yaws.hrl
  2. +34 −2 src/yaws_config.erl
  3. +1 −1 src/yaws_server.erl
  4. +16 −6 src/yaws_soap_srv.erl
View
6 include/yaws.hrl
@@ -86,7 +86,11 @@
phpexe = "/usr/bin/php-cgi", %% cgi capable php executable
yaws, %% server string
id = "default", %% string identifying this instance of yaws
- enable_soap = false %% start yaws_soap_srv iff true
+ enable_soap = false, %% start yaws_soap_srv iff true
+ soap_srv_mods = [] %% a list of
+ %% {{Mod, Func}, WsdlFile, Prefix } | {{Mod, Func}, WsdlFile}
+ %% which will be automatically setuped
+ %% while yaws_soap_srv init.
}).
View
36 src/yaws_config.erl
@@ -83,7 +83,7 @@ load(E) ->
add_yaws_soap_srv(GC) when GC#gconf.enable_soap == true ->
SoapStarted = (whereis(yaws_soap_srv) /= undefined),
if (SoapStarted == false) ->
- Spec = {yaws_soap_srv, {yaws_soap_srv, start_link, []},
+ Spec = {yaws_soap_srv, {yaws_soap_srv, start_link, [GC#gconf.soap_srv_mods] },
permanent, 5000, worker, [yaws_soap_srv]},
spawn(fun() -> supervisor:start_child(yaws_sup, Spec) end);
true ->
@@ -550,8 +550,17 @@ fload(FD, globals, GC, C, Cs, Lno, Chars) ->
true ->
fload(FD, globals, GC#gconf{enable_soap = false},
C, Cs, Lno+1, Next)
+ end;
+
+ ["soap_srv_mods", '=' | SoapSrvMods] ->
+ case parse_soap_srv_mods(SoapSrvMods, []) of
+ {ok, L} ->
+ fload(FD, globals, GC#gconf{soap_srv_mods = L},
+ C, Cs, Lno+1, Next);
+ {error, Str} ->
+ {error, ?F("~s at line ~w", [Str, Lno])}
end;
-
+
["max_connections", '=', Int] ->
case (catch list_to_integer(Int)) of
I when is_integer(I) ->
@@ -1414,6 +1423,29 @@ is_special(C) ->
lists:member(C, [$=, $<, $>, $,]).
+parse_soap_srv_mods(['<', Module, ',' , Handler, ',', WsdlFile, '>' | Tail], Ack) ->
+ case is_file(WsdlFile) of
+ true ->
+ S = { {list_to_atom(Module), list_to_atom(Handler)}, WsdlFile},
+ parse_soap_srv_mods(Tail, [S |Ack]);
+ false ->
+ {error, ?F("Bad wsdl file ~p", [WsdlFile])}
+ end;
+
+parse_soap_srv_mods(['<', Module, ',' , Handler, ',', WsdlFile, ',', Prefix, '>' | Tail], Ack) ->
+ case is_file(WsdlFile) of
+ true ->
+ S = { {list_to_atom(Module), list_to_atom(Handler)}, WsdlFile, Prefix},
+ parse_soap_srv_mods(Tail, [S |Ack]);
+ false ->
+ {error, ?F("Bad wsdl file ~p", [WsdlFile])}
+ end;
+
+parse_soap_srv_mods([ SoapSrvMod | _Tail], _Ack) ->
+ {error, ?F("Bad soap_srv_mods syntax: ~p", [SoapSrvMod])};
+
+parse_soap_srv_mods([], Ack) ->
+ {ok, Ack}.
parse_appmods(['<', PathElem, ',' , AppMod, '>' | Tail], Ack) ->
S = {PathElem , list_to_atom(AppMod)},
View
2 src/yaws_server.erl
@@ -113,7 +113,7 @@ l2a(A) when is_atom(A) -> A.
init(Env) -> %% #env{Trace, TraceOut, Conf, RunMod, Embedded, Id}) ->
process_flag(trap_exit, true),
- put(start_time, calendar:local_time()), %% for uptime
+ put(start_time, calendar:local_time ()), %% for uptime
case Env#env.embedded of
false ->
Config = (catch yaws_config:load(Env)),
View
22 src/yaws_soap_srv.erl
@@ -8,7 +8,7 @@
-behaviour(gen_server).
%% API
--export([start_link/0,
+-export([start_link/1,
setup/1, setup/2, setup/3,
handler/4
]).
@@ -40,7 +40,7 @@
%% Function: start_link() -> {ok,Pid} | ignore | {error,Error}
%% Description: Starts the server
%%--------------------------------------------------------------------
-start_link() ->
+start_link(L) ->
%% We are dependent on erlsom
case code:ensure_loaded(erlsom) of
{error, _} ->
@@ -49,7 +49,7 @@ start_link() ->
[?MODULE, Emsg]),
{error, Emsg};
{module, erlsom} ->
- gen_server:start_link({local, ?SERVER}, ?MODULE, [], [])
+ gen_server:start_link({local, ?SERVER}, ?MODULE, L, [])
end.
%%% To be called from yaws_rpc.erl
@@ -95,9 +95,19 @@ setup(Id, WsdlFile, Prefix) when is_tuple(Id),size(Id)==2 ->
%% {stop, Reason}
%% Description: Initiates the server
%%--------------------------------------------------------------------
-init([]) ->
- {ok, #s{}}.
-
+init(L) -> %% [ {{Mod,Handler}, WsdlFile} ]
+ WsdlList = lists:foldl( fun( SoapSrvMod, OldList) ->
+ setup_on_init( SoapSrvMod, OldList )
+ end,[],L),
+ {ok, #s{wsdl_list = WsdlList}}.
+
+setup_on_init( {Id, WsdlFile}, OldList ) when is_tuple(Id),size(Id)==2 ->
+ Wsdl = yaws_soap_lib:initModel(WsdlFile),
+ uinsert({Id, Wsdl}, OldList);
+setup_on_init( {Id, WsdlFile, Prefix}, OldList ) when is_tuple(Id),size(Id)==2 ->
+ Wsdl = yaws_soap_lib:initModel(WsdlFile, Prefix),
+ uinsert({Id, Wsdl}, OldList).
+
%%--------------------------------------------------------------------
%% Function: %% handle_call(Request, From, State) -> {reply, Reply, State} |
%% {reply, Reply, State, Timeout} |

0 comments on commit d8df08c

Please sign in to comment.