Permalink
Browse files

Merge branch 'master' of github.com:klacke/yaws

  • Loading branch information...
2 parents 3cdb645 + 2d74b84 commit 3b521606c7e3813d89bd3a0b1f4898a9f066702e @vinoski vinoski committed Jan 18, 2011
View
@@ -98,10 +98,11 @@
yaws, %% server string
id = "default", %% string identifying this instance of yaws
enable_soap = false, %% start yaws_soap_srv iff true
- soap_srv_mods = [] %% a list of
+ soap_srv_mods = [], %% a list of
%% {{Mod, Func}, WsdlFile, Prefix } |
%% {{Mod, Func}, WsdlFile}
%% automatically setup in yaws_soap_srv init.
+ ysession_mod = yaws_session_server %% storage module for ysession
}).
View
@@ -182,6 +182,14 @@ when we run in normal standalone mode, we typically want the
Erlang errorlog written to a report.log file.
Default value is true.
+.TP
+\fBysession_mod = Module\fR
+Allows to specify a different Yaws session storage mechanism instead of
+an ETS table. One of the drawbacks of the default yaws_session_server
+implementation is that server side cookies are lost when the server
+restarts.
+Specifying a different module here will pass all writes/read
+operations to this module (it must implements appropriate callbacks).
.TP
\fBrunmod = ModuleName\fR
@@ -0,0 +1,106 @@
+%%%----------------------------------------------------------------------
+%%% File : yaws_mnesia_session.erl
+%%% Author : Nicolas Thauvin <nicolas@corporama.com>
+%%% Purpose : mnesia storage callbacks for yaws_session_server
+%%%----------------------------------------------------------------------
+
+%% Warning !!!
+%% This module may init mnesia in a way that is not suitable for your
+%% application !
+
+%% Quick steps:
+%% 1) Compile this module
+%% 2) Drop the .beam in your code path
+%% 3) Run Yaws with the
+
+-module (yaws_mnesia_session).
+
+-export ([init_backend/1, stop_backend/0]).
+-export ([list/0, insert/1, lookup/1, delete/1]).
+-export ([traverse/1, cleanup/0]).
+
+-define(TABLE, ysession).
+
+init_backend(Fields) ->
+ case net_kernel:get_net_ticktime() of
+ ignored ->
+ Message = "mnesia backend needs distribution (a node name)",
+ Error = {?MODULE, Message},
+ error_logger:error_msg("~p~n", [Error]),
+ exit (Error);
+ _ ->
+ ok
+ end,
+ case catch mnesia:table_info(schema, where_to_write) of
+ Nodes when is_list(Nodes) ->
+ case catch mnesia:table_info(?TABLE, where_to_write) of
+ {'EXIT', {aborted, {no_exists, ?TABLE, where_to_write}}} ->
+ Nodes = mnesia:system_info(running_db_nodes),
+ Options = [{disc_copies, Nodes}, {type, set},
+ {attributes, Fields}],
+ {atomic, ok} = mnesia: create_table (?TABLE, Options),
+ ok;
+ List when is_list (List) ->
+ ok = mnesia:wait_for_tables([?TABLE], 60000)
+ end;
+ {'EXIT',{aborted,{no_exists,schema,where_to_write}}} ->
+ application:stop(mnesia),
+ mnesia:create_schema([node()]),
+ ok = application:start(mnesia),
+ init_backend(Fields)
+ end.
+
+stop_backend() ->
+ ok.
+
+insert(Session) ->
+ Fun = fun () -> mnesia:write(Session) end,
+ {atomic, ok} = mnesia:transaction(Fun),
+ true.
+
+lookup(Key) ->
+ Fun = fun () -> mnesia:read(?TABLE, Key) end,
+ {atomic, Result} = mnesia:transaction(Fun),
+ Result.
+
+delete(Key) ->
+ Fun = fun () -> mnesia:delete({?TABLE, Key}) end,
+ {atomic, Result} = mnesia:transaction(Fun),
+ Result.
+
+list() ->
+ Fold = fun (Session, Acc) -> [Session | Acc] end,
+ Fun = fun () -> mnesia:foldl(Fold, [], ?TABLE) end,
+ {atomic, Result} = mnesia:transaction(Fun),
+ Result.
+
+cleanup() ->
+ mnesia:clear_table(?TABLE).
+
+traverse(Gnow) ->
+ Fun = fun() -> tr_traverse(Gnow) end,
+ {atomic, Result} = mnesia:transaction(Fun),
+ Result.
+
+tr_traverse(Gnow) ->
+ tr_traverse(Gnow, mnesia:first(?TABLE)).
+
+tr_traverse(_N, '$end_of_table') ->
+ ok;
+tr_traverse(N, Key) ->
+ case mnesia:read(?TABLE, Key) of
+ [Y] ->
+ case yaws_session_server:has_timedout(Y, N) of
+ false ->
+ tr_traverse(N, mnesia:next(?TABLE, Key));
+ true ->
+ yaws_session_server:report_timedout_sess(Y),
+ Next = mnesia:next(?TABLE, Key),
+ mnesia:delete({?TABLE, Key}),
+ tr_traverse(N, Next)
+ end;
+ [] ->
+ tr_traverse(N, mnesia:next(?MODULE, Key))
+ end.
+
+
View
@@ -782,6 +782,10 @@ fload(FD, globals, GC, C, Cs, Lno, Chars) ->
GC2 = GC#gconf{x_forwarded_for_log_proxy_whitelist = Addrs},
fload(FD, globals, GC2, C, Cs, Lno+1, Next)
end;
+ ["ysession_mod", '=', Mod_str] ->
+ Ysession_mod = list_to_atom(Mod_str),
+ fload(FD, globals, GC#gconf{ysession_mod = Ysession_mod},
+ C, Cs, Lno+1, Next);
['<', "server", Server, '>'] -> %% first server
fload(FD, server, GC, #sconf{servername = Server},
Cs, Lno+1, Next);
Oops, something went wrong.

0 comments on commit 3b52160

Please sign in to comment.