Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 92 lines (66 sloc) 1.879 kb
d69e4d8 @klacke ""
authored
1
2 <erl>
aed77d6 @klacke preparing for 1.67
authored
3 -export([pserv/0]).
d69e4d8 @klacke ""
authored
4
5 ensure_pcookie_server() ->
6 case whereis(pcookie_server) of
0be3c7e @klacke untabified all of yaws
authored
7 undefined ->
8 proc_lib:start(?MODULE, pserv,[]);
9 _ ->
10 ok
d69e4d8 @klacke ""
authored
11 end.
12
13 pserv() ->
14 catch begin
0be3c7e @klacke untabified all of yaws
authored
15 register(pcookie_server, self()),
7811247 @vinoski whitespace cleanup
vinoski authored
16 T = ets:new(pcookies, [set, public,
0be3c7e @klacke untabified all of yaws
authored
17 named_table]),
18 ets:insert(T, {counter, 0})
19 end,
d69e4d8 @klacke ""
authored
20 proc_lib:init_ack(ok),
21 pserv_loop().
22
23 pserv_loop() ->
24 receive
0be3c7e @klacke untabified all of yaws
authored
25 X ->
26 pserv_loop()
d69e4d8 @klacke ""
authored
27 end.
28
29 setcookie(A) ->
30 Num = ets:update_counter(pcookies, counter, 1),
7811247 @vinoski whitespace cleanup
vinoski authored
31 Data = {(A#arg.headers)#headers.user_agent,
0be3c7e @klacke untabified all of yaws
authored
32 calendar:local_time(),
33 inet:peername(A#arg.clisock)},
d69e4d8 @klacke ""
authored
34 ets:insert(pcookies, {{cookie, Num}, Data}),
a5e3fa4 @klacke ""
authored
35 yaws_api:setcookie("pfoobar",integer_to_list(Num), "/").
d69e4d8 @klacke ""
authored
36
37
38
3b9e4a1 @klacke new ret vals from out/1
authored
39 out(A) ->
d69e4d8 @klacke ""
authored
40 ensure_pcookie_server(),
41 H = A#arg.headers,
42 C = H#headers.cookie,
43 case C of
0be3c7e @klacke untabified all of yaws
authored
44 [Cookie|_] ->
45 case string:tokens(Cookie, [$=]) of
46 ["pfoobar", NumStr] ->
47 Num = list_to_integer(NumStr),
48 %% cookie allready set
49 case ets:lookup(pcookies, {c, Num}) of
50 [{cookie, Data}] ->
51 ok; %% cookie already set
52 [] ->
53 setcookie(A)
54 end;
55 _ ->
56 setcookie(A)
57 end;
58 _ ->
59 setcookie(A)
d69e4d8 @klacke ""
authored
60 end.
961926f @klacke ""
authored
61 </erl>
62
63
64 <erl>
65
66
bea8261 @klacke added log_wrap_size, configurable wrap size for all logs, fixed a bug…
authored
67 out(A) -> {ssi, "TAB.inc", [],[]}.
68 </erl>
69
70 <div id="entry">
961926f @klacke ""
authored
71
d69e4d8 @klacke ""
authored
72
73
74
75
d02b965 @klacke qnx port + docs overhaul by cschatz@networkadvantage.biz
authored
76 <h2> Set persistent cookie </h2>
d69e4d8 @klacke ""
authored
77
7811247 @vinoski whitespace cleanup
vinoski authored
78 <p>This is the page that set a persistent cookie in
79 the browser.
80 <a href="readpcookie.yaws">readpcookie.yaws</a> will
d02b965 @klacke qnx port + docs overhaul by cschatz@networkadvantage.biz
authored
81 read the cookie and report persistent information.
d69e4d8 @klacke ""
authored
82
7811247 @vinoski whitespace cleanup
vinoski authored
83
d69e4d8 @klacke ""
authored
84
bea8261 @klacke added log_wrap_size, configurable wrap size for all logs, fixed a bug…
authored
85 </div>
86
87
88 <erl>
89 out(A) -> {ssi, "END2",[],[]}.
90 </erl>
d69e4d8 @klacke ""
authored
91
Something went wrong with that request. Please try again.