diff options
Diffstat (limited to 'vendor/luasec/src/options.lua')
-rw-r--r-- | vendor/luasec/src/options.lua | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/vendor/luasec/src/options.lua b/vendor/luasec/src/options.lua new file mode 100644 index 00000000..72428c01 --- /dev/null +++ b/vendor/luasec/src/options.lua | |||
@@ -0,0 +1,93 @@ | |||
1 | local function usage() | ||
2 | print("Usage:") | ||
3 | print("* Generate options of your system:") | ||
4 | print(" lua options.lua -g /path/to/ssl.h [version] > options.c") | ||
5 | print("* Examples:") | ||
6 | print(" lua options.lua -g /usr/include/openssl/ssl.h > options.c\n") | ||
7 | print(" lua options.lua -g /usr/include/openssl/ssl.h \"OpenSSL 1.1.1f\" > options.c\n") | ||
8 | |||
9 | print("* List options of your system:") | ||
10 | print(" lua options.lua -l /path/to/ssl.h\n") | ||
11 | end | ||
12 | |||
13 | -- | ||
14 | local function printf(str, ...) | ||
15 | print(string.format(str, ...)) | ||
16 | end | ||
17 | |||
18 | local function generate(options, version) | ||
19 | print([[ | ||
20 | /*-------------------------------------------------------------------------- | ||
21 | * LuaSec 1.3.2 | ||
22 | * | ||
23 | * Copyright (C) 2006-2023 Bruno Silvestre | ||
24 | * | ||
25 | *--------------------------------------------------------------------------*/ | ||
26 | |||
27 | #include <openssl/ssl.h> | ||
28 | |||
29 | #include "options.h" | ||
30 | |||
31 | /* If you need to generate these options again, see options.lua */ | ||
32 | |||
33 | ]]) | ||
34 | |||
35 | printf([[ | ||
36 | /* | ||
37 | OpenSSL version: %s | ||
38 | */ | ||
39 | ]], version) | ||
40 | |||
41 | print([[static lsec_ssl_option_t ssl_options[] = {]]) | ||
42 | |||
43 | for k, option in ipairs(options) do | ||
44 | local name = string.lower(string.sub(option, 8)) | ||
45 | print(string.format([[#if defined(%s)]], option)) | ||
46 | print(string.format([[ {"%s", %s},]], name, option)) | ||
47 | print([[#endif]]) | ||
48 | end | ||
49 | print([[ {NULL, 0L}]]) | ||
50 | print([[ | ||
51 | }; | ||
52 | |||
53 | LSEC_API lsec_ssl_option_t* lsec_get_ssl_options() { | ||
54 | return ssl_options; | ||
55 | } | ||
56 | ]]) | ||
57 | end | ||
58 | |||
59 | local function loadoptions(file) | ||
60 | local options = {} | ||
61 | local f = assert(io.open(file, "r")) | ||
62 | for line in f:lines() do | ||
63 | local op = string.match(line, "define%s+(SSL_OP_BIT%()") | ||
64 | if not op then | ||
65 | op = string.match(line, "define%s+(SSL_OP_%S+)") | ||
66 | if op then | ||
67 | table.insert(options, op) | ||
68 | end | ||
69 | end | ||
70 | end | ||
71 | table.sort(options, function(a,b) return a<b end) | ||
72 | return options | ||
73 | end | ||
74 | -- | ||
75 | |||
76 | local options | ||
77 | local flag, file, version = ... | ||
78 | |||
79 | version = version or "Unknown" | ||
80 | |||
81 | if not file then | ||
82 | usage() | ||
83 | elseif flag == "-g" then | ||
84 | options = loadoptions(file) | ||
85 | generate(options, version) | ||
86 | elseif flag == "-l" then | ||
87 | options = loadoptions(file) | ||
88 | for k, option in ipairs(options) do | ||
89 | print(option) | ||
90 | end | ||
91 | else | ||
92 | usage() | ||
93 | end | ||