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

« back to all changes in this revision

Viewing changes to lib/ssl/pkix/mk_ssl_pkix_oid.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
 
-module(mk_ssl_pkix_oid).
2
 
 
3
 
-export([make/0]).
4
 
 
5
 
-define(PKIX_MODULES, ['OTP-PKIX']).
6
 
 
7
 
make() ->
8
 
    {ok, Fd} = file:open("ssl_pkix_oid.erl", [write]),
9
 
    io:fwrite(Fd, "%%% File: ssl_pkix_oid.erl\n"
10
 
              "%%% NB This file has been automatically generated by "
11
 
              "mk_ssl_pkix_oid.\n"
12
 
              "%%% Do not edit it.\n\n", []),
13
 
    io:fwrite(Fd, "-module(ssl_pkix_oid).\n", []),
14
 
    io:fwrite(Fd, "-export([id2atom/1, atom2id/1, all_atoms/0, "
15
 
              "all_ids/0]).\n\n", []),
16
 
 
17
 
 
18
 
    AIds0 = get_atom_ids(?PKIX_MODULES),
19
 
 
20
 
    AIds1 = modify_atoms(AIds0),
21
 
    gen_id2atom(Fd, AIds1),
22
 
    gen_atom2id(Fd, AIds1),
23
 
    gen_all(Fd, AIds1),
24
 
    file:close(Fd).
25
 
 
26
 
get_atom_ids(Ms) ->
27
 
    get_atom_ids(Ms, []).
28
 
 
29
 
get_atom_ids([], AIdss) ->
30
 
    lists:flatten(AIdss);
31
 
get_atom_ids([M| Ms], AIdss) ->
32
 
    {value, {exports, Exports}} = 
33
 
        lists:keysearch(exports, 1, M:module_info()),
34
 
    As = lists:zf(
35
 
           fun ({info, 0}) -> false;
36
 
               ({module_info, 0}) -> false;
37
 
               ({encoding_rule, 0}) -> false;
38
 
               ({F, 0}) -> 
39
 
                   case atom_to_list(F) of
40
 
                   %% Remove upper-bound (ub-) functions
41
 
                       "ub-" ++ _Rest ->
42
 
                           false;
43
 
                       _ ->
44
 
                           {true, F}
45
 
                   end;
46
 
               (_) -> false 
47
 
           end, Exports),
48
 
    AIds = lists:map(fun(F) -> {F, M:F()} end, As),
49
 
    get_atom_ids(Ms, [AIds| AIdss]).
50
 
 
51
 
modify_atoms(AIds) ->
52
 
    F = fun({A, I}) ->
53
 
                NAS = case atom_to_list(A) of
54
 
                          "id-" ++ Rest ->
55
 
                              Rest;
56
 
                          Any ->
57
 
                              Any
58
 
                      end,
59
 
                {list_to_atom(NAS), I} end,
60
 
    lists:map(F, AIds). 
61
 
 
62
 
gen_id2atom(Fd, AIds0) ->
63
 
    AIds1 = lists:keysort(2, AIds0),
64
 
    Txt = join(";\n", 
65
 
               lists:map(
66
 
                 fun({Atom, Id}) ->
67
 
                         io_lib:fwrite("id2atom(~p) ->\n    ~p", [Id, Atom]) 
68
 
                 end, AIds1)),
69
 
    io:fwrite(Fd, "~s;\nid2atom(Any)->\n    Any.\n\n", [Txt]).
70
 
 
71
 
gen_atom2id(Fd, AIds0) ->
72
 
    AIds1 = lists:keysort(1, AIds0),
73
 
    Txt = join(";\n", 
74
 
               lists:map(
75
 
                 fun({Atom, Id}) ->
76
 
                         io_lib:fwrite("atom2id(~p) ->\n    ~p", [Atom, Id]) 
77
 
                 end, AIds1)),
78
 
    io:fwrite(Fd, "~s;\natom2id(Any)->\n    Any.\n\n", [Txt]).
79
 
 
80
 
gen_all(Fd, AIds) ->
81
 
    Atoms = lists:sort([A || {A, _} <- AIds]),
82
 
    Ids = lists:sort([I || {_, I} <- AIds]),
83
 
    F = fun(X) -> io_lib:fwrite("    ~w", [X]) end,
84
 
    ATxt = "all_atoms() ->\n" ++ join(",\n", lists:map(F, Atoms)),
85
 
    io:fwrite(Fd, "~s.\n\n", [ATxt]),
86
 
    ITxt = "all_ids() ->\n" ++  join(",\n", lists:map(F, Ids)),
87
 
    io:fwrite(Fd, "~s.\n\n", [ITxt]).
88
 
 
89
 
join(Sep, [H1, H2| T]) ->
90
 
    [H1, Sep| join(Sep, [H2| T])]; 
91
 
join(_Sep, [H1]) ->
92
 
    H1;
93
 
join(_, []) ->
94
 
    [].