Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

yaws_session_server ttl patch from Rob.Schmersel

git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk/yaws@707 9fbdc01b-0d2c-0410-bfb7-fb27d70d8b52
  • Loading branch information...
commit 13b21a993644e06efa2ba6f3f1905648f9f9fd4e 1 parent df96b15
@klacke authored
Showing with 21 additions and 9 deletions.
  1. +5 −0 man/yaws_api.5
  2. +4 −1 src/yaws_api.erl
  3. +12 −8 src/yaws_session_server.erl
View
5 man/yaws_api.5
@@ -276,6 +276,11 @@ cookie. The new randomgenerated cookie is returned from this
function. The Opaque argument will typically contain user data
such as username and password
+.TP
+\fBnew_cookie_session(Opaque, TTL)\fR
+As above, but allows to set a session specific time-out value,
+overriding teh system specified time-out value.
+
.TP
\fBcookieval_to_opaque(CookieVal)\fR
View
5 src/yaws_api.erl
@@ -34,7 +34,7 @@
-export([get_line/1, mime_type/1]).
-export([stream_chunk_deliver/2, stream_chunk_deliver_blocking/2,
stream_chunk_end/1]).
--export([new_cookie_session/1,
+-export([new_cookie_session/1, new_cookie_session/2,
cookieval_to_opaque/1, request_url/1,
print_cookie_sessions/0,
replace_cookie_session/2, delete_cookie_session/1]).
@@ -843,6 +843,9 @@ stream_chunk_end(YawsPid) ->
new_cookie_session(Opaque) ->
yaws_session_server:new_session(Opaque).
+new_cookie_session(Opaque, TTL) ->
+ yaws_session_server:new_session(Opaque, TTL).
+
%% as returned in #ysession.cookie
cookieval_to_opaque(CookieVal) ->
yaws_session_server:cookieval_to_opaque(CookieVal).
View
20 src/yaws_session_server.erl
@@ -26,6 +26,7 @@
-record(ysession,
{cookie, %% the cookie assigned to the session
to, %% greg secs untill timeout death
+ ttl, %% default time to live
starttime, %% When calendar:local_time() did sess start
opaque %% any data the user supplies
}).
@@ -50,12 +51,15 @@ stop() ->
%% will return a new cookie as a string
new_session(Opaque) ->
- gen_server:call(?MODULE, {new_session, Opaque}).
+ gen_server:call(?MODULE, {new_session, Opaque, ?TTL}).
+
+new_session(Opaque, TTL) ->
+ gen_server:call(?MODULE, {new_session, Opaque, TTL}).
cookieval_to_opaque(CookieString) ->
case ets:lookup(?MODULE, CookieString) of
[Y] ->
- Y2 = Y#ysession{to = gnow() + ?TTL},
+ Y2 = Y#ysession{to = gnow() + Y#ysession.ttl},
ets:insert(?MODULE, Y2),
{ok, Y#ysession.opaque};
[] ->
@@ -79,9 +83,9 @@ print_sessions() ->
replace_session(Cookie, NewOpaque) ->
case ets:lookup(?MODULE, Cookie) of
[Y] ->
- Y2 = Y#ysession{to = gnow() + ?TTL},
- ets:insert(?MODULE, Y2),
- ets:insert(?MODULE, Y#ysession{opaque = NewOpaque});
+ Y2 = Y#ysession{to = gnow() + Y#ysession.ttl,
+ opaque = NewOpaque},
+ ets:insert(?MODULE, Y2);
[] ->
error
end.
@@ -136,8 +140,7 @@ seed() ->
%%----------------------------------------------------------------------
-
-handle_call({new_session, Opaque}, _From, _State) ->
+handle_call({new_session, Opaque, TTL}, _From, _State) ->
Now = gnow(),
N = random:uniform(16#ffffffffffffffff), %% 64 bits
TS = calendar:local_time(),
@@ -145,7 +148,8 @@ handle_call({new_session, Opaque}, _From, _State) ->
NS = #ysession{cookie = C,
starttime = TS,
opaque = Opaque,
- to = Now + ?TTL},
+ to = Now + TTL,
+ ttl = TTL},
ets:insert(?MODULE, NS),
{reply, C, undefined, to()};
Please sign in to comment.
Something went wrong with that request. Please try again.