Skip to content
This repository
Newer
Older
100644 92 lines (66 sloc) 1.879 kb
d69e4d84 »
2002-02-25 ""
1
2 <erl>
aed77d62 »
2007-02-04 preparing for 1.67
3 -export([pserv/0]).
d69e4d84 »
2002-02-25 ""
4
5 ensure_pcookie_server() ->
6 case whereis(pcookie_server) of
0be3c7e8 »
2008-02-14 untabified all of yaws
7 undefined ->
8 proc_lib:start(?MODULE, pserv,[]);
9 _ ->
10 ok
d69e4d84 »
2002-02-25 ""
11 end.
12
13 pserv() ->
14 catch begin
0be3c7e8 »
2008-02-14 untabified all of yaws
15 register(pcookie_server, self()),
78112471 »
2011-10-31 whitespace cleanup
16 T = ets:new(pcookies, [set, public,
0be3c7e8 »
2008-02-14 untabified all of yaws
17 named_table]),
18 ets:insert(T, {counter, 0})
19 end,
d69e4d84 »
2002-02-25 ""
20 proc_lib:init_ack(ok),
21 pserv_loop().
22
23 pserv_loop() ->
24 receive
0be3c7e8 »
2008-02-14 untabified all of yaws
25 X ->
26 pserv_loop()
d69e4d84 »
2002-02-25 ""
27 end.
28
29 setcookie(A) ->
30 Num = ets:update_counter(pcookies, counter, 1),
78112471 »
2011-10-31 whitespace cleanup
31 Data = {(A#arg.headers)#headers.user_agent,
0be3c7e8 »
2008-02-14 untabified all of yaws
32 calendar:local_time(),
33 inet:peername(A#arg.clisock)},
d69e4d84 »
2002-02-25 ""
34 ets:insert(pcookies, {{cookie, Num}, Data}),
a5e3fa4a »
2002-06-18 ""
35 yaws_api:setcookie("pfoobar",integer_to_list(Num), "/").
d69e4d84 »
2002-02-25 ""
36
37
38
3b9e4a1c »
2002-06-12 new ret vals from out/1
39 out(A) ->
d69e4d84 »
2002-02-25 ""
40 ensure_pcookie_server(),
41 H = A#arg.headers,
42 C = H#headers.cookie,
43 case C of
0be3c7e8 »
2008-02-14 untabified all of yaws
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)
d69e4d84 »
2002-02-25 ""
60 end.
961926f2 »
2002-03-04 ""
61 </erl>
62
63
64 <erl>
65
66
bea82617 »
2004-11-19 added log_wrap_size, configurable wrap size for all logs, fixed a bug…
67 out(A) -> {ssi, "TAB.inc", [],[]}.
68 </erl>
69
70 <div id="entry">
961926f2 »
2002-03-04 ""
71
d69e4d84 »
2002-02-25 ""
72
73
74
75
d02b9655 »
2004-02-13 qnx port + docs overhaul by cschatz@networkadvantage.biz
76 <h2> Set persistent cookie </h2>
d69e4d84 »
2002-02-25 ""
77
78112471 »
2011-10-31 whitespace cleanup
78 <p>This is the page that set a persistent cookie in
79 the browser.
80 <a href="readpcookie.yaws">readpcookie.yaws</a> will
d02b9655 »
2004-02-13 qnx port + docs overhaul by cschatz@networkadvantage.biz
81 read the cookie and report persistent information.
d69e4d84 »
2002-02-25 ""
82
78112471 »
2011-10-31 whitespace cleanup
83
d69e4d84 »
2002-02-25 ""
84
bea82617 »
2004-11-19 added log_wrap_size, configurable wrap size for all logs, fixed a bug…
85 </div>
86
87
88 <erl>
89 out(A) -> {ssi, "END2",[],[]}.
90 </erl>
d69e4d84 »
2002-02-25 ""
91
Something went wrong with that request. Please try again.