~ubuntu-branches/ubuntu/trusty/erlang/trusty

« back to all changes in this revision

Viewing changes to lib/ssl/src/ssl_session_cache.erl

  • Committer: Bazaar Package Importer
  • Author(s): Clint Byrum
  • Date: 2011-05-05 15:48:43 UTC
  • mfrom: (3.5.13 sid)
  • Revision ID: james.westby@ubuntu.com-20110505154843-0om6ekzg6m7ugj27
Tags: 1:14.b.2-dfsg-3ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Drop libwxgtk2.8-dev build dependency. Wx isn't in main, and not
    supposed to.
  - Drop erlang-wx binary.
  - Drop erlang-wx dependency from -megaco, -common-test, and -reltool, they
    do not really need wx. Also drop it from -debugger; the GUI needs wx,
    but it apparently has CLI bits as well, and is also needed by -megaco,
    so let's keep the package for now.
  - debian/patches/series: Do what I meant, and enable build-options.patch
    instead.
* Additional changes:
  - Drop erlang-wx from -et
* Dropped Changes:
  - patches/pcre-crash.patch: CVE-2008-2371: outer level option with
    alternatives caused crash. (Applied Upstream)
  - fix for ssl certificate verification in newSSL: 
    ssl_cacertfile_fix.patch (Applied Upstream)
  - debian/patches/series: Enable native.patch again, to get stripped beam
    files and reduce the package size again. (build-options is what
    actually accomplished this)
  - Remove build-options.patch on advice from upstream and because it caused
    odd build failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
%%
2
2
%% %CopyrightBegin%
3
 
%% 
4
 
%% Copyright Ericsson AB 2008-2009. All Rights Reserved.
5
 
%% 
 
3
%%
 
4
%% Copyright Ericsson AB 2008-2010. All Rights Reserved.
 
5
%%
6
6
%% The contents of this file are subject to the Erlang Public License,
7
7
%% Version 1.1, (the "License"); you may not use this file except in
8
8
%% compliance with the License. You should have received a copy of the
9
9
%% Erlang Public License along with this software. If not, it can be
10
10
%% retrieved online at http://www.erlang.org/.
11
 
%% 
 
11
%%
12
12
%% Software distributed under the License is distributed on an "AS IS"
13
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
14
%% the License for the specific language governing rights and limitations
15
15
%% under the License.
16
 
%% 
 
16
%%
17
17
%% %CopyrightEnd%
18
18
%%
19
19
 
22
22
 
23
23
-behaviour(ssl_session_cache_api).
24
24
 
25
 
-export([init/0, terminate/1, lookup/2, update/3, delete/2, foldl/3, 
26
 
         select_session/2]).
 
25
-include("ssl_handshake.hrl").
 
26
-include("ssl_internal.hrl").
 
27
 
 
28
-export([init/1, terminate/1, lookup/2, update/3, delete/2, foldl/3, 
 
29
         select_session/2]). 
 
30
 
 
31
-type key() :: {{host(), port_num()}, session_id()} |  {port_num(), session_id()}.
27
32
 
28
33
%%--------------------------------------------------------------------
29
 
%% Function: init() -> Cache  
30
 
%%
31
 
%%      Cache - Reference to the cash (opaque)    
 
34
-spec init(list()) -> cache_ref(). %% Returns reference to the cache (opaque)    
32
35
%%
33
36
%% Description: Return table reference. Called by ssl_manager process. 
34
37
%%--------------------------------------------------------------------
35
 
init() ->
 
38
init(_) ->
36
39
    ets:new(cache_name(), [set, protected]).
37
40
 
38
41
%%--------------------------------------------------------------------
39
 
%% Function: terminate(Cache) -> 
40
 
%%
41
 
%%      Cache - as returned by create/0
 
42
-spec terminate(cache_ref()) -> any(). %%    
42
43
%%
43
44
%% Description: Handles cache table at termination of ssl manager. 
44
45
%%--------------------------------------------------------------------
46
47
    ets:delete(Cache).
47
48
 
48
49
%%--------------------------------------------------------------------
49
 
%% Function: lookup(Cache, Key) -> Session | undefined   
50
 
%%      Cache - as returned by create/0   
51
 
%%      Session = #session{}
 
50
-spec lookup(cache_ref(), key()) -> #session{} | undefined.
52
51
%%
53
52
%% Description: Looks up a cach entry. Should be callable from any
54
53
%% process.
62
61
    end.
63
62
 
64
63
%%--------------------------------------------------------------------
65
 
%% Function: update(Cache, Key, Session) -> _
66
 
%%      Cache - as returned by create/0
67
 
%%      Session = #session{}
 
64
-spec update(cache_ref(), key(), #session{}) -> any().
68
65
%%
69
66
%% Description: Caches a new session or updates a already cached one.
70
67
%% Will only be called from the ssl_manager process.
73
70
    ets:insert(Cache, {Key, Session}).
74
71
 
75
72
%%--------------------------------------------------------------------
76
 
%% Function: delete(Cache, HostIP, Port, Id) -> _
77
 
%%      Cache - as returned by create/0   
78
 
%%      HostIP =  Host = string() | ipadress()
79
 
%%      Port =  integer()
80
 
%%      Id = 
 
73
-spec delete(cache_ref(), key()) -> any().
81
74
%%
82
75
%% Description: Delets a cache entry.
83
76
%% Will only be called from the ssl_manager process.
86
79
    ets:delete(Cache, Key).
87
80
 
88
81
%%--------------------------------------------------------------------
89
 
%% Function: foldl(Fun, Acc0, Cache) -> Acc
90
 
%%   
91
 
%%      Fun  - fun()
92
 
%%      Acc0  - term()
93
 
%%      Cache  - cache_ref()
94
 
%%
 
82
-spec foldl(fun(), term(), cache_ref()) -> term().
95
83
%%
96
84
%% Description: Calls Fun(Elem, AccIn) on successive elements of the
97
85
%% cache, starting with AccIn == Acc0. Fun/2 must return a new
98
86
%% accumulator which is passed to the next call. The function returns
99
 
%% the final value of the accumulator. Acc0 is returned if the cache is
100
 
%% empty. 
101
 
%% Should be callable from any process
 
87
%% the final value of the accumulator. Acc0 is returned if the cache
 
88
%% is empty.Should be callable from any process
102
89
%%--------------------------------------------------------------------
103
90
foldl(Fun, Acc0, Cache) ->
104
91
    ets:foldl(Fun, Acc0, Cache).
105
92
  
106
93
%%--------------------------------------------------------------------
107
 
%% Function: select_session(Cache, PartialKey) -> [Sessions]
108
 
%%
109
 
%%     Cache - as returned by create/0   
110
 
%%     PartialKey - opaque  Key = {PartialKey, SessionId}
 
94
-spec select_session(cache_ref(), {host(), port_num()} | port_num()) -> [#session{}].
111
95
%%
112
96
%% Description: Selects a session that could be reused. Should be callable
113
97
%% from any process.
119
103
%%--------------------------------------------------------------------
120
104
%%% Internal functions
121
105
%%--------------------------------------------------------------------
122
 
 
123
106
cache_name() ->
124
107
    ssl_otp_session_cache.