isomorfeus-iodine 0.7.49 → 0.7.50
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +1 -1
- data/CHANGELOG.md +17 -3
- data/Rakefile +1 -9
- data/examples/etag.ru +16 -0
- data/ext/{iodine → iodine_ext}/extconf.rb +1 -1
- data/ext/{iodine → iodine_ext}/fio.c +0 -0
- data/ext/{iodine → iodine_ext}/fio.h +0 -0
- data/ext/{iodine → iodine_ext}/fio_cli.c +0 -0
- data/ext/{iodine → iodine_ext}/fio_cli.h +189 -189
- data/ext/{iodine → iodine_ext}/fio_json_parser.h +687 -687
- data/ext/{iodine → iodine_ext}/fio_siphash.c +157 -157
- data/ext/{iodine → iodine_ext}/fio_siphash.h +37 -37
- data/ext/{iodine → iodine_ext}/fio_tls.h +129 -129
- data/ext/{iodine → iodine_ext}/fio_tls_missing.c +0 -0
- data/ext/{iodine → iodine_ext}/fio_tls_openssl.c +0 -0
- data/ext/{iodine → iodine_ext}/fio_tmpfile.h +0 -0
- data/ext/{iodine → iodine_ext}/fiobj.h +44 -44
- data/ext/{iodine → iodine_ext}/fiobj4fio.h +21 -21
- data/ext/{iodine → iodine_ext}/fiobj_ary.c +333 -333
- data/ext/{iodine → iodine_ext}/fiobj_ary.h +139 -139
- data/ext/{iodine → iodine_ext}/fiobj_data.c +0 -0
- data/ext/{iodine → iodine_ext}/fiobj_data.h +0 -0
- data/ext/{iodine → iodine_ext}/fiobj_hash.c +0 -0
- data/ext/{iodine → iodine_ext}/fiobj_hash.h +176 -176
- data/ext/{iodine → iodine_ext}/fiobj_json.c +622 -622
- data/ext/{iodine → iodine_ext}/fiobj_json.h +68 -68
- data/ext/{iodine → iodine_ext}/fiobj_mem.h +71 -71
- data/ext/{iodine → iodine_ext}/fiobj_mustache.c +0 -0
- data/ext/{iodine → iodine_ext}/fiobj_mustache.h +62 -62
- data/ext/{iodine → iodine_ext}/fiobj_numbers.c +0 -0
- data/ext/{iodine → iodine_ext}/fiobj_numbers.h +127 -127
- data/ext/{iodine → iodine_ext}/fiobj_str.c +0 -0
- data/ext/{iodine → iodine_ext}/fiobj_str.h +172 -172
- data/ext/{iodine → iodine_ext}/fiobject.c +0 -0
- data/ext/{iodine → iodine_ext}/fiobject.h +0 -0
- data/ext/{iodine → iodine_ext}/hpack.h +1923 -1923
- data/ext/{iodine → iodine_ext}/http.c +14 -27
- data/ext/{iodine → iodine_ext}/http.h +1002 -1002
- data/ext/{iodine → iodine_ext}/http1.c +0 -0
- data/ext/{iodine → iodine_ext}/http1.h +29 -29
- data/ext/{iodine → iodine_ext}/http1_parser.h +0 -0
- data/ext/{iodine → iodine_ext}/http_internal.c +0 -0
- data/ext/{iodine → iodine_ext}/http_internal.h +0 -0
- data/ext/{iodine → iodine_ext}/http_mime_parser.h +350 -350
- data/ext/{iodine → iodine_ext}/iodine.c +1 -1
- data/ext/{iodine → iodine_ext}/iodine.h +0 -0
- data/ext/{iodine → iodine_ext}/iodine_caller.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_caller.h +0 -0
- data/ext/{iodine → iodine_ext}/iodine_connection.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_connection.h +55 -55
- data/ext/{iodine → iodine_ext}/iodine_defer.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_defer.h +6 -6
- data/ext/{iodine → iodine_ext}/iodine_fiobj2rb.h +120 -120
- data/ext/{iodine → iodine_ext}/iodine_helpers.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_helpers.h +12 -12
- data/ext/{iodine → iodine_ext}/iodine_http.c +0 -2
- data/ext/{iodine → iodine_ext}/iodine_http.h +23 -23
- data/ext/{iodine → iodine_ext}/iodine_json.c +302 -302
- data/ext/{iodine → iodine_ext}/iodine_json.h +6 -6
- data/ext/{iodine → iodine_ext}/iodine_mustache.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_mustache.h +6 -6
- data/ext/{iodine → iodine_ext}/iodine_pubsub.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_pubsub.h +26 -26
- data/ext/{iodine → iodine_ext}/iodine_rack_io.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_rack_io.h +20 -20
- data/ext/{iodine → iodine_ext}/iodine_store.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_store.h +20 -20
- data/ext/{iodine → iodine_ext}/iodine_tcp.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_tcp.h +0 -0
- data/ext/{iodine → iodine_ext}/iodine_tls.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_tls.h +13 -13
- data/ext/{iodine → iodine_ext}/mustache_parser.h +0 -0
- data/ext/{iodine → iodine_ext}/redis_engine.c +0 -0
- data/ext/{iodine → iodine_ext}/redis_engine.h +0 -0
- data/ext/{iodine → iodine_ext}/resp_parser.h +0 -0
- data/ext/{iodine → iodine_ext}/websocket_parser.h +505 -505
- data/ext/{iodine → iodine_ext}/websockets.c +0 -0
- data/ext/{iodine → iodine_ext}/websockets.h +185 -185
- data/isomorfeus-iodine.gemspec +1 -2
- data/lib/iodine/version.rb +1 -1
- data/lib/iodine.rb +1 -1
- metadata +79 -78
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f6d52427fb6c73c781981a09b9217b557e2da7c676578d7c726c375f8f49919
|
4
|
+
data.tar.gz: 24b2b507bb66405986b947085fcc6ac65d921fb3e7775ffb00ea82909cfc74fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '059aafd0ed382cc2b7446532d83a19121e19e61c8c9590bf372d074149aee2765426452c488020a2b55720fc63fbf050cc4314e26398495945957d55b9328a8c'
|
7
|
+
data.tar.gz: e0e74b28d8f2c193271aa8a610298f003913e0214870ca2dd20d4c87a7358da04bd63015204788eabbe84215f4c89582f85f2d1bb4504773e8b46776d744ae3b
|
data/.github/workflows/ruby.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,20 @@ Please notice that this change log contains changes for upcoming releases as wel
|
|
6
6
|
|
7
7
|
## Changes:
|
8
8
|
|
9
|
+
#### Change log v.0.7.47 (2022-05-11)
|
10
|
+
|
11
|
+
**Fix**: Fixes an issue that causes `Rack::Lint` to complain about `SERVER_PORT` being an empty string. Credit to @adam12 (Adam Daniels) for PR #108 and issue #107.
|
12
|
+
|
13
|
+
#### Change log v.0.7.46 (2022-05-06)
|
14
|
+
|
15
|
+
**Fix**: Fixes the (erroneous) default insertion of the `last-modified` header in order to both better express the intent of RFC 2616 and prevent conflict with the `Rack::ETag` middleware. Credit to @raxoft (Patrik Rak) for opening issue #122.
|
16
|
+
|
17
|
+
#### Change log v.0.7.45 (2021-11-26)
|
18
|
+
|
19
|
+
**Security**: Fixes a number of issues with the HTTP parser that could have been leveraged in potential exploit attempts such as request smuggling. Credit to @dcepelik (David Čepelík).
|
20
|
+
|
21
|
+
**Compatibility**: This release adds experimental Windows support (I don't have Windows, nor Intel, I cannot test this). Credit for a lot of work by @janbiedermann (Jan Biedermann).
|
22
|
+
|
9
23
|
#### Change log v.0.7.44 (2021-02-28)
|
10
24
|
|
11
25
|
**Fix**: Fixes issue #103 where an empty String response would result in the word "null" being returned (no String object was created, which routed the NULL object to facil.io's JSON interpreter). Credit to @waghanza (Marwan Rabbâa) for exposing the issue.
|
@@ -82,7 +96,7 @@ Please notice that this change log contains changes for upcoming releases as wel
|
|
82
96
|
|
83
97
|
#### Change log v.0.7.31
|
84
98
|
|
85
|
-
**Security**: a heap-overflow vulnerability was fixed in the WebSocket parser. This attack could have been triggered remotely by a maliciously crafted message-header. Credit to Dane (4cad@silvertoque) for exposing this issue and providing a Python script demonstrating the attack.
|
99
|
+
**Security**: a heap-overflow vulnerability was fixed in the WebSocket parser. This attack could have been triggered remotely by a maliciously crafted message-header. Credit to Dane (4cad@silvertoque) for exposing this issue and providing a Python script demonstrating the attack.
|
86
100
|
|
87
101
|
It's recommended that all iodine users update to the latest version.
|
88
102
|
|
@@ -148,7 +162,7 @@ It's recommended that all iodine users update to the latest version.
|
|
148
162
|
|
149
163
|
#### Change log v.0.7.20
|
150
164
|
|
151
|
-
**Security**: (`fio`) lower and smarter Slowloris detection limits (backlog limit is now 1,024 responses / messages per client).
|
165
|
+
**Security**: (`fio`) lower and smarter Slowloris detection limits (backlog limit is now 1,024 responses / messages per client).
|
152
166
|
|
153
167
|
**Security**: (`http`) HTTP/1.1 slow client throttling - new requests will not be consumed until pending responses were sent. Since HTTP/1.1 is a response-request protocol, this protocol specific approach should protect the HTTP application against slow clients.
|
154
168
|
|
@@ -332,7 +346,7 @@ It's recommended that all iodine users update to the latest version.
|
|
332
346
|
|
333
347
|
#### Change log v.0.7.0
|
334
348
|
|
335
|
-
This version bump is performed because the internal engine changed significantly and might be considered less mature. The public API remains unbroken.
|
349
|
+
This version bump is performed because the internal engine changed significantly and might be considered less mature. The public API remains unbroken.
|
336
350
|
|
337
351
|
**Fix**: Fixed a documentation error. Credit to @Fonsan (Erik Fonselius) for PR #41.
|
338
352
|
|
data/Rakefile
CHANGED
@@ -32,13 +32,5 @@ end
|
|
32
32
|
|
33
33
|
task :default => [:compile, :spec]
|
34
34
|
|
35
|
-
Rake::ExtensionTask.new
|
36
|
-
ext.lib_dir = "lib/iodine"
|
37
|
-
end
|
35
|
+
Rake::ExtensionTask.new :iodine_ext
|
38
36
|
|
39
|
-
# Rake::ExtensionTask.new "iodine_http" do |ext|
|
40
|
-
# ext.name = 'iodine_http'
|
41
|
-
# ext.lib_dir = "lib/iodine"
|
42
|
-
# ext.ext_dir = 'ext/iodine'
|
43
|
-
# ext.config_script = 'extconf-http.rb'
|
44
|
-
# end
|
data/examples/etag.ru
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# This example uses Rack::ETag to allow for response caching.
|
2
|
+
|
3
|
+
require 'rack'
|
4
|
+
require 'iodine'
|
5
|
+
|
6
|
+
App = Proc.new do |env|
|
7
|
+
[200,
|
8
|
+
{ "Content-Type" => "text/html".freeze,
|
9
|
+
"Content-Length" => "16".freeze },
|
10
|
+
['Hello from Rack!'.freeze] ]
|
11
|
+
end
|
12
|
+
|
13
|
+
use Rack::ConditionalGet
|
14
|
+
use Rack::ETag, 'public'
|
15
|
+
|
16
|
+
run App
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,189 +1,189 @@
|
|
1
|
-
/*
|
2
|
-
Copyright: Boaz segev, 2017
|
3
|
-
License: MIT
|
4
|
-
|
5
|
-
Feel free to copy, use and enjoy according to the license provided.
|
6
|
-
*/
|
7
|
-
#ifndef H_FIO_CLI_HELPER_H
|
8
|
-
#define H_FIO_CLI_HELPER_H
|
9
|
-
|
10
|
-
/* support C++ */
|
11
|
-
#ifdef __cplusplus
|
12
|
-
extern "C" {
|
13
|
-
#endif
|
14
|
-
|
15
|
-
/* *****************************************************************************
|
16
|
-
CLI API
|
17
|
-
***************************************************************************** */
|
18
|
-
|
19
|
-
/** Indicates the CLI argument should be a String (default). */
|
20
|
-
#define FIO_CLI_STRING(line)
|
21
|
-
/** Indicates the CLI argument is a Boolean value. */
|
22
|
-
#define FIO_CLI_BOOL(line)
|
23
|
-
/** Indicates the CLI argument should be an Integer (numerical). */
|
24
|
-
#define FIO_CLI_INT(line)
|
25
|
-
/** Indicates the CLI string should be printed as is. */
|
26
|
-
#define FIO_CLI_PRINT(line)
|
27
|
-
/** Indicates the CLI string should be printed as a header. */
|
28
|
-
#define FIO_CLI_PRINT_HEADER(line)
|
29
|
-
|
30
|
-
/**
|
31
|
-
* This function parses the Command Line Interface (CLI), creating a temporary
|
32
|
-
* "dictionary" that allows easy access to the CLI using their names or aliases.
|
33
|
-
*
|
34
|
-
* Command line arguments may be typed. If an optional type requirement is
|
35
|
-
* provided and the provided arument fails to match the required type, execution
|
36
|
-
* will end and an error message will be printed along with a short "help".
|
37
|
-
*
|
38
|
-
* The function / macro accepts the following arguments:
|
39
|
-
* - `argc`: command line argument count.
|
40
|
-
* - `argv`: command line argument list (array).
|
41
|
-
* - `unnamed_min`: the required minimum of un-named arguments.
|
42
|
-
* - `unnamed_max`: the maximum limit of un-named arguments.
|
43
|
-
* - `description`: a C string containing the program's description.
|
44
|
-
* - named arguments list: a list of C strings describing named arguments.
|
45
|
-
*
|
46
|
-
* The following optional type requirements are:
|
47
|
-
*
|
48
|
-
* * FIO_CLI_STRING(desc_line) - (default) string argument.
|
49
|
-
* * FIO_CLI_BOOL(desc_line) - boolean argument (no value).
|
50
|
-
* * FIO_CLI_INT(desc_line) - integer argument.
|
51
|
-
* * FIO_CLI_PRINT_HEADER(desc_line) - extra header for output.
|
52
|
-
* * FIO_CLI_PRINT(desc_line) - extra information for output.
|
53
|
-
*
|
54
|
-
* Argument names MUST start with the '-' character. The first word starting
|
55
|
-
* without the '-' character will begin the description for the CLI argument.
|
56
|
-
*
|
57
|
-
* The arguments "-?", "-h", "-help" and "--help" are automatically handled
|
58
|
-
* unless overridden.
|
59
|
-
*
|
60
|
-
* Un-named arguments shouldn't be listed in the named arguments list.
|
61
|
-
*
|
62
|
-
* Example use:
|
63
|
-
*
|
64
|
-
* fio_cli_start(argc, argv, 0, 0, "this example accepts the following:",
|
65
|
-
* FIO_CLI_PRINT_HREADER("Concurrency:"),
|
66
|
-
* FIO_CLI_INT("-t -thread number of threads to run."),
|
67
|
-
* FIO_CLI_INT("-w -workers number of workers to run."),
|
68
|
-
* FIO_CLI_PRINT_HREADER("Address Binding:"),
|
69
|
-
* "-b, -address the address to bind to.",
|
70
|
-
* FIO_CLI_INT("-p,-port the port to bind to."),
|
71
|
-
* FIO_CLI_PRINT("\t\tset port to zero (0) for Unix s."),
|
72
|
-
* FIO_CLI_PRINT_HREADER("Logging:"),
|
73
|
-
* FIO_CLI_BOOL("-v -log enable logging."));
|
74
|
-
*
|
75
|
-
*
|
76
|
-
* This would allow access to the named arguments:
|
77
|
-
*
|
78
|
-
* fio_cli_get("-b") == fio_cli_get("-address");
|
79
|
-
*
|
80
|
-
*
|
81
|
-
* Once all the data was accessed, free the parsed data dictionary using:
|
82
|
-
*
|
83
|
-
* fio_cli_end();
|
84
|
-
*
|
85
|
-
* It should be noted, arguments will be recognized in a number of forms, i.e.:
|
86
|
-
*
|
87
|
-
* app -t=1 -p3000 -a localhost
|
88
|
-
*
|
89
|
-
* This function is NOT thread safe.
|
90
|
-
*/
|
91
|
-
#define fio_cli_start(argc, argv, unnamed_min, unnamed_max, description, ...) \
|
92
|
-
fio_cli_start((argc), (argv), (unnamed_min), (unnamed_max), (description), \
|
93
|
-
(char const *[]){__VA_ARGS__, NULL})
|
94
|
-
#define FIO_CLI_IGNORE
|
95
|
-
/**
|
96
|
-
* Never use the function directly, always use the MACRO, because the macro
|
97
|
-
* attaches a NULL marker at the end of the `names` argument collection.
|
98
|
-
*/
|
99
|
-
void fio_cli_start FIO_CLI_IGNORE(int argc, char const *argv[], int unnamed_min,
|
100
|
-
int unnamed_max, char const *description,
|
101
|
-
char const **names);
|
102
|
-
/**
|
103
|
-
* Clears the memory used by the CLI dictionary, removing all parsed data.
|
104
|
-
*
|
105
|
-
* This function is NOT thread safe.
|
106
|
-
*/
|
107
|
-
void fio_cli_end(void);
|
108
|
-
|
109
|
-
/** Returns the argument's value as a NUL terminated C String. */
|
110
|
-
char const *fio_cli_get(char const *name);
|
111
|
-
|
112
|
-
/** Returns the argument's value as an integer. */
|
113
|
-
int fio_cli_get_i(char const *name);
|
114
|
-
|
115
|
-
/** This MACRO returns the argument's value as a boolean. */
|
116
|
-
#define fio_cli_get_bool(name) (fio_cli_get((name)) != NULL)
|
117
|
-
|
118
|
-
/** Returns the number of unnamed argument. */
|
119
|
-
unsigned int fio_cli_unnamed_count(void);
|
120
|
-
|
121
|
-
/** Returns the unnamed argument using a 0 based `index`. */
|
122
|
-
char const *fio_cli_unnamed(unsigned int index);
|
123
|
-
|
124
|
-
/**
|
125
|
-
* Sets the argument's value as a NUL terminated C String (no copy!).
|
126
|
-
*
|
127
|
-
* CAREFUL: This does not automatically detect aliases or type violations! it
|
128
|
-
* will only effect the specific name given, even if invalid. i.e.:
|
129
|
-
*
|
130
|
-
* fio_cli_start(argc, argv,
|
131
|
-
* "this is example accepts the following options:",
|
132
|
-
* "-p -port the port to bind to", FIO_CLI_INT;
|
133
|
-
*
|
134
|
-
* fio_cli_set("-p", "hello"); // fio_cli_get("-p") != fio_cli_get("-port");
|
135
|
-
*
|
136
|
-
* Note: this does NOT copy the C strings to memory. Memory should be kept alive
|
137
|
-
* until `fio_cli_end` is called.
|
138
|
-
*
|
139
|
-
* This function is NOT thread safe.
|
140
|
-
*/
|
141
|
-
void fio_cli_set(char const *name, char const *value);
|
142
|
-
|
143
|
-
/**
|
144
|
-
* This MACRO is the same as:
|
145
|
-
*
|
146
|
-
* if(!fio_cli_get(name)) {
|
147
|
-
* fio_cli_set(name, value)
|
148
|
-
* }
|
149
|
-
*
|
150
|
-
* See fio_cli_set for notes and restrictions.
|
151
|
-
*/
|
152
|
-
#define fio_cli_set_default(name, value) \
|
153
|
-
if (!fio_cli_get((name))) \
|
154
|
-
fio_cli_set(name, value);
|
155
|
-
|
156
|
-
#ifdef __cplusplus
|
157
|
-
} /* extern "C" */
|
158
|
-
#endif
|
159
|
-
|
160
|
-
/* *****************************************************************************
|
161
|
-
Internal Macro Implementation
|
162
|
-
***************************************************************************** */
|
163
|
-
|
164
|
-
/** Used internally. */
|
165
|
-
#define FIO_CLI_STRING__TYPE_I 0x1
|
166
|
-
#define FIO_CLI_BOOL__TYPE_I 0x2
|
167
|
-
#define FIO_CLI_INT__TYPE_I 0x3
|
168
|
-
#define FIO_CLI_PRINT__TYPE_I 0x4
|
169
|
-
#define FIO_CLI_PRINT_HEADER__TYPE_I 0x5
|
170
|
-
|
171
|
-
#undef FIO_CLI_STRING
|
172
|
-
#undef FIO_CLI_BOOL
|
173
|
-
#undef FIO_CLI_INT
|
174
|
-
#undef FIO_CLI_PRINT
|
175
|
-
#undef FIO_CLI_PRINT_HEADER
|
176
|
-
|
177
|
-
/** Indicates the CLI argument should be a String (default). */
|
178
|
-
#define FIO_CLI_STRING(line) (line), ((char *)FIO_CLI_STRING__TYPE_I)
|
179
|
-
/** Indicates the CLI argument is a Boolean value. */
|
180
|
-
#define FIO_CLI_BOOL(line) (line), ((char *)FIO_CLI_BOOL__TYPE_I)
|
181
|
-
/** Indicates the CLI argument should be an Integer (numerical). */
|
182
|
-
#define FIO_CLI_INT(line) (line), ((char *)FIO_CLI_INT__TYPE_I)
|
183
|
-
/** Indicates the CLI string should be printed as is. */
|
184
|
-
#define FIO_CLI_PRINT(line) (line), ((char *)FIO_CLI_PRINT__TYPE_I)
|
185
|
-
/** Indicates the CLI string should be printed as a header. */
|
186
|
-
#define FIO_CLI_PRINT_HEADER(line) \
|
187
|
-
(line), ((char *)FIO_CLI_PRINT_HEADER__TYPE_I)
|
188
|
-
|
189
|
-
#endif
|
1
|
+
/*
|
2
|
+
Copyright: Boaz segev, 2017
|
3
|
+
License: MIT
|
4
|
+
|
5
|
+
Feel free to copy, use and enjoy according to the license provided.
|
6
|
+
*/
|
7
|
+
#ifndef H_FIO_CLI_HELPER_H
|
8
|
+
#define H_FIO_CLI_HELPER_H
|
9
|
+
|
10
|
+
/* support C++ */
|
11
|
+
#ifdef __cplusplus
|
12
|
+
extern "C" {
|
13
|
+
#endif
|
14
|
+
|
15
|
+
/* *****************************************************************************
|
16
|
+
CLI API
|
17
|
+
***************************************************************************** */
|
18
|
+
|
19
|
+
/** Indicates the CLI argument should be a String (default). */
|
20
|
+
#define FIO_CLI_STRING(line)
|
21
|
+
/** Indicates the CLI argument is a Boolean value. */
|
22
|
+
#define FIO_CLI_BOOL(line)
|
23
|
+
/** Indicates the CLI argument should be an Integer (numerical). */
|
24
|
+
#define FIO_CLI_INT(line)
|
25
|
+
/** Indicates the CLI string should be printed as is. */
|
26
|
+
#define FIO_CLI_PRINT(line)
|
27
|
+
/** Indicates the CLI string should be printed as a header. */
|
28
|
+
#define FIO_CLI_PRINT_HEADER(line)
|
29
|
+
|
30
|
+
/**
|
31
|
+
* This function parses the Command Line Interface (CLI), creating a temporary
|
32
|
+
* "dictionary" that allows easy access to the CLI using their names or aliases.
|
33
|
+
*
|
34
|
+
* Command line arguments may be typed. If an optional type requirement is
|
35
|
+
* provided and the provided arument fails to match the required type, execution
|
36
|
+
* will end and an error message will be printed along with a short "help".
|
37
|
+
*
|
38
|
+
* The function / macro accepts the following arguments:
|
39
|
+
* - `argc`: command line argument count.
|
40
|
+
* - `argv`: command line argument list (array).
|
41
|
+
* - `unnamed_min`: the required minimum of un-named arguments.
|
42
|
+
* - `unnamed_max`: the maximum limit of un-named arguments.
|
43
|
+
* - `description`: a C string containing the program's description.
|
44
|
+
* - named arguments list: a list of C strings describing named arguments.
|
45
|
+
*
|
46
|
+
* The following optional type requirements are:
|
47
|
+
*
|
48
|
+
* * FIO_CLI_STRING(desc_line) - (default) string argument.
|
49
|
+
* * FIO_CLI_BOOL(desc_line) - boolean argument (no value).
|
50
|
+
* * FIO_CLI_INT(desc_line) - integer argument.
|
51
|
+
* * FIO_CLI_PRINT_HEADER(desc_line) - extra header for output.
|
52
|
+
* * FIO_CLI_PRINT(desc_line) - extra information for output.
|
53
|
+
*
|
54
|
+
* Argument names MUST start with the '-' character. The first word starting
|
55
|
+
* without the '-' character will begin the description for the CLI argument.
|
56
|
+
*
|
57
|
+
* The arguments "-?", "-h", "-help" and "--help" are automatically handled
|
58
|
+
* unless overridden.
|
59
|
+
*
|
60
|
+
* Un-named arguments shouldn't be listed in the named arguments list.
|
61
|
+
*
|
62
|
+
* Example use:
|
63
|
+
*
|
64
|
+
* fio_cli_start(argc, argv, 0, 0, "this example accepts the following:",
|
65
|
+
* FIO_CLI_PRINT_HREADER("Concurrency:"),
|
66
|
+
* FIO_CLI_INT("-t -thread number of threads to run."),
|
67
|
+
* FIO_CLI_INT("-w -workers number of workers to run."),
|
68
|
+
* FIO_CLI_PRINT_HREADER("Address Binding:"),
|
69
|
+
* "-b, -address the address to bind to.",
|
70
|
+
* FIO_CLI_INT("-p,-port the port to bind to."),
|
71
|
+
* FIO_CLI_PRINT("\t\tset port to zero (0) for Unix s."),
|
72
|
+
* FIO_CLI_PRINT_HREADER("Logging:"),
|
73
|
+
* FIO_CLI_BOOL("-v -log enable logging."));
|
74
|
+
*
|
75
|
+
*
|
76
|
+
* This would allow access to the named arguments:
|
77
|
+
*
|
78
|
+
* fio_cli_get("-b") == fio_cli_get("-address");
|
79
|
+
*
|
80
|
+
*
|
81
|
+
* Once all the data was accessed, free the parsed data dictionary using:
|
82
|
+
*
|
83
|
+
* fio_cli_end();
|
84
|
+
*
|
85
|
+
* It should be noted, arguments will be recognized in a number of forms, i.e.:
|
86
|
+
*
|
87
|
+
* app -t=1 -p3000 -a localhost
|
88
|
+
*
|
89
|
+
* This function is NOT thread safe.
|
90
|
+
*/
|
91
|
+
#define fio_cli_start(argc, argv, unnamed_min, unnamed_max, description, ...) \
|
92
|
+
fio_cli_start((argc), (argv), (unnamed_min), (unnamed_max), (description), \
|
93
|
+
(char const *[]){__VA_ARGS__, NULL})
|
94
|
+
#define FIO_CLI_IGNORE
|
95
|
+
/**
|
96
|
+
* Never use the function directly, always use the MACRO, because the macro
|
97
|
+
* attaches a NULL marker at the end of the `names` argument collection.
|
98
|
+
*/
|
99
|
+
void fio_cli_start FIO_CLI_IGNORE(int argc, char const *argv[], int unnamed_min,
|
100
|
+
int unnamed_max, char const *description,
|
101
|
+
char const **names);
|
102
|
+
/**
|
103
|
+
* Clears the memory used by the CLI dictionary, removing all parsed data.
|
104
|
+
*
|
105
|
+
* This function is NOT thread safe.
|
106
|
+
*/
|
107
|
+
void fio_cli_end(void);
|
108
|
+
|
109
|
+
/** Returns the argument's value as a NUL terminated C String. */
|
110
|
+
char const *fio_cli_get(char const *name);
|
111
|
+
|
112
|
+
/** Returns the argument's value as an integer. */
|
113
|
+
int fio_cli_get_i(char const *name);
|
114
|
+
|
115
|
+
/** This MACRO returns the argument's value as a boolean. */
|
116
|
+
#define fio_cli_get_bool(name) (fio_cli_get((name)) != NULL)
|
117
|
+
|
118
|
+
/** Returns the number of unnamed argument. */
|
119
|
+
unsigned int fio_cli_unnamed_count(void);
|
120
|
+
|
121
|
+
/** Returns the unnamed argument using a 0 based `index`. */
|
122
|
+
char const *fio_cli_unnamed(unsigned int index);
|
123
|
+
|
124
|
+
/**
|
125
|
+
* Sets the argument's value as a NUL terminated C String (no copy!).
|
126
|
+
*
|
127
|
+
* CAREFUL: This does not automatically detect aliases or type violations! it
|
128
|
+
* will only effect the specific name given, even if invalid. i.e.:
|
129
|
+
*
|
130
|
+
* fio_cli_start(argc, argv,
|
131
|
+
* "this is example accepts the following options:",
|
132
|
+
* "-p -port the port to bind to", FIO_CLI_INT;
|
133
|
+
*
|
134
|
+
* fio_cli_set("-p", "hello"); // fio_cli_get("-p") != fio_cli_get("-port");
|
135
|
+
*
|
136
|
+
* Note: this does NOT copy the C strings to memory. Memory should be kept alive
|
137
|
+
* until `fio_cli_end` is called.
|
138
|
+
*
|
139
|
+
* This function is NOT thread safe.
|
140
|
+
*/
|
141
|
+
void fio_cli_set(char const *name, char const *value);
|
142
|
+
|
143
|
+
/**
|
144
|
+
* This MACRO is the same as:
|
145
|
+
*
|
146
|
+
* if(!fio_cli_get(name)) {
|
147
|
+
* fio_cli_set(name, value)
|
148
|
+
* }
|
149
|
+
*
|
150
|
+
* See fio_cli_set for notes and restrictions.
|
151
|
+
*/
|
152
|
+
#define fio_cli_set_default(name, value) \
|
153
|
+
if (!fio_cli_get((name))) \
|
154
|
+
fio_cli_set(name, value);
|
155
|
+
|
156
|
+
#ifdef __cplusplus
|
157
|
+
} /* extern "C" */
|
158
|
+
#endif
|
159
|
+
|
160
|
+
/* *****************************************************************************
|
161
|
+
Internal Macro Implementation
|
162
|
+
***************************************************************************** */
|
163
|
+
|
164
|
+
/** Used internally. */
|
165
|
+
#define FIO_CLI_STRING__TYPE_I 0x1
|
166
|
+
#define FIO_CLI_BOOL__TYPE_I 0x2
|
167
|
+
#define FIO_CLI_INT__TYPE_I 0x3
|
168
|
+
#define FIO_CLI_PRINT__TYPE_I 0x4
|
169
|
+
#define FIO_CLI_PRINT_HEADER__TYPE_I 0x5
|
170
|
+
|
171
|
+
#undef FIO_CLI_STRING
|
172
|
+
#undef FIO_CLI_BOOL
|
173
|
+
#undef FIO_CLI_INT
|
174
|
+
#undef FIO_CLI_PRINT
|
175
|
+
#undef FIO_CLI_PRINT_HEADER
|
176
|
+
|
177
|
+
/** Indicates the CLI argument should be a String (default). */
|
178
|
+
#define FIO_CLI_STRING(line) (line), ((char *)FIO_CLI_STRING__TYPE_I)
|
179
|
+
/** Indicates the CLI argument is a Boolean value. */
|
180
|
+
#define FIO_CLI_BOOL(line) (line), ((char *)FIO_CLI_BOOL__TYPE_I)
|
181
|
+
/** Indicates the CLI argument should be an Integer (numerical). */
|
182
|
+
#define FIO_CLI_INT(line) (line), ((char *)FIO_CLI_INT__TYPE_I)
|
183
|
+
/** Indicates the CLI string should be printed as is. */
|
184
|
+
#define FIO_CLI_PRINT(line) (line), ((char *)FIO_CLI_PRINT__TYPE_I)
|
185
|
+
/** Indicates the CLI string should be printed as a header. */
|
186
|
+
#define FIO_CLI_PRINT_HEADER(line) \
|
187
|
+
(line), ((char *)FIO_CLI_PRINT_HEADER__TYPE_I)
|
188
|
+
|
189
|
+
#endif
|