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.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -1
  3. data/CHANGELOG.md +17 -3
  4. data/Rakefile +1 -9
  5. data/examples/etag.ru +16 -0
  6. data/ext/{iodine → iodine_ext}/extconf.rb +1 -1
  7. data/ext/{iodine → iodine_ext}/fio.c +0 -0
  8. data/ext/{iodine → iodine_ext}/fio.h +0 -0
  9. data/ext/{iodine → iodine_ext}/fio_cli.c +0 -0
  10. data/ext/{iodine → iodine_ext}/fio_cli.h +189 -189
  11. data/ext/{iodine → iodine_ext}/fio_json_parser.h +687 -687
  12. data/ext/{iodine → iodine_ext}/fio_siphash.c +157 -157
  13. data/ext/{iodine → iodine_ext}/fio_siphash.h +37 -37
  14. data/ext/{iodine → iodine_ext}/fio_tls.h +129 -129
  15. data/ext/{iodine → iodine_ext}/fio_tls_missing.c +0 -0
  16. data/ext/{iodine → iodine_ext}/fio_tls_openssl.c +0 -0
  17. data/ext/{iodine → iodine_ext}/fio_tmpfile.h +0 -0
  18. data/ext/{iodine → iodine_ext}/fiobj.h +44 -44
  19. data/ext/{iodine → iodine_ext}/fiobj4fio.h +21 -21
  20. data/ext/{iodine → iodine_ext}/fiobj_ary.c +333 -333
  21. data/ext/{iodine → iodine_ext}/fiobj_ary.h +139 -139
  22. data/ext/{iodine → iodine_ext}/fiobj_data.c +0 -0
  23. data/ext/{iodine → iodine_ext}/fiobj_data.h +0 -0
  24. data/ext/{iodine → iodine_ext}/fiobj_hash.c +0 -0
  25. data/ext/{iodine → iodine_ext}/fiobj_hash.h +176 -176
  26. data/ext/{iodine → iodine_ext}/fiobj_json.c +622 -622
  27. data/ext/{iodine → iodine_ext}/fiobj_json.h +68 -68
  28. data/ext/{iodine → iodine_ext}/fiobj_mem.h +71 -71
  29. data/ext/{iodine → iodine_ext}/fiobj_mustache.c +0 -0
  30. data/ext/{iodine → iodine_ext}/fiobj_mustache.h +62 -62
  31. data/ext/{iodine → iodine_ext}/fiobj_numbers.c +0 -0
  32. data/ext/{iodine → iodine_ext}/fiobj_numbers.h +127 -127
  33. data/ext/{iodine → iodine_ext}/fiobj_str.c +0 -0
  34. data/ext/{iodine → iodine_ext}/fiobj_str.h +172 -172
  35. data/ext/{iodine → iodine_ext}/fiobject.c +0 -0
  36. data/ext/{iodine → iodine_ext}/fiobject.h +0 -0
  37. data/ext/{iodine → iodine_ext}/hpack.h +1923 -1923
  38. data/ext/{iodine → iodine_ext}/http.c +14 -27
  39. data/ext/{iodine → iodine_ext}/http.h +1002 -1002
  40. data/ext/{iodine → iodine_ext}/http1.c +0 -0
  41. data/ext/{iodine → iodine_ext}/http1.h +29 -29
  42. data/ext/{iodine → iodine_ext}/http1_parser.h +0 -0
  43. data/ext/{iodine → iodine_ext}/http_internal.c +0 -0
  44. data/ext/{iodine → iodine_ext}/http_internal.h +0 -0
  45. data/ext/{iodine → iodine_ext}/http_mime_parser.h +350 -350
  46. data/ext/{iodine → iodine_ext}/iodine.c +1 -1
  47. data/ext/{iodine → iodine_ext}/iodine.h +0 -0
  48. data/ext/{iodine → iodine_ext}/iodine_caller.c +0 -0
  49. data/ext/{iodine → iodine_ext}/iodine_caller.h +0 -0
  50. data/ext/{iodine → iodine_ext}/iodine_connection.c +0 -0
  51. data/ext/{iodine → iodine_ext}/iodine_connection.h +55 -55
  52. data/ext/{iodine → iodine_ext}/iodine_defer.c +0 -0
  53. data/ext/{iodine → iodine_ext}/iodine_defer.h +6 -6
  54. data/ext/{iodine → iodine_ext}/iodine_fiobj2rb.h +120 -120
  55. data/ext/{iodine → iodine_ext}/iodine_helpers.c +0 -0
  56. data/ext/{iodine → iodine_ext}/iodine_helpers.h +12 -12
  57. data/ext/{iodine → iodine_ext}/iodine_http.c +0 -2
  58. data/ext/{iodine → iodine_ext}/iodine_http.h +23 -23
  59. data/ext/{iodine → iodine_ext}/iodine_json.c +302 -302
  60. data/ext/{iodine → iodine_ext}/iodine_json.h +6 -6
  61. data/ext/{iodine → iodine_ext}/iodine_mustache.c +0 -0
  62. data/ext/{iodine → iodine_ext}/iodine_mustache.h +6 -6
  63. data/ext/{iodine → iodine_ext}/iodine_pubsub.c +0 -0
  64. data/ext/{iodine → iodine_ext}/iodine_pubsub.h +26 -26
  65. data/ext/{iodine → iodine_ext}/iodine_rack_io.c +0 -0
  66. data/ext/{iodine → iodine_ext}/iodine_rack_io.h +20 -20
  67. data/ext/{iodine → iodine_ext}/iodine_store.c +0 -0
  68. data/ext/{iodine → iodine_ext}/iodine_store.h +20 -20
  69. data/ext/{iodine → iodine_ext}/iodine_tcp.c +0 -0
  70. data/ext/{iodine → iodine_ext}/iodine_tcp.h +0 -0
  71. data/ext/{iodine → iodine_ext}/iodine_tls.c +0 -0
  72. data/ext/{iodine → iodine_ext}/iodine_tls.h +13 -13
  73. data/ext/{iodine → iodine_ext}/mustache_parser.h +0 -0
  74. data/ext/{iodine → iodine_ext}/redis_engine.c +0 -0
  75. data/ext/{iodine → iodine_ext}/redis_engine.h +0 -0
  76. data/ext/{iodine → iodine_ext}/resp_parser.h +0 -0
  77. data/ext/{iodine → iodine_ext}/websocket_parser.h +505 -505
  78. data/ext/{iodine → iodine_ext}/websockets.c +0 -0
  79. data/ext/{iodine → iodine_ext}/websockets.h +185 -185
  80. data/isomorfeus-iodine.gemspec +1 -2
  81. data/lib/iodine/version.rb +1 -1
  82. data/lib/iodine.rb +1 -1
  83. metadata +79 -78
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d738c4e12837e4701e07b9a23b5339ec81f9bca7576432394405ac425fedb9d
4
- data.tar.gz: 34051db83348db0ad3fd5bcf92fa4efda7f662afabf322b74f66896dc850d0c5
3
+ metadata.gz: 3f6d52427fb6c73c781981a09b9217b557e2da7c676578d7c726c375f8f49919
4
+ data.tar.gz: 24b2b507bb66405986b947085fcc6ac65d921fb3e7775ffb00ea82909cfc74fb
5
5
  SHA512:
6
- metadata.gz: b0a04ba4c6ccdcd506866b575240a62e625285118d200fc54171b120d19df27a7f974b9bce6f3168f589a689276766b336c4935e5fe07d81595e4b2b74f2132f
7
- data.tar.gz: 65b915942797680025c0441dbd46205a330254ab18bb8d4a3ca161889ac88b74b6d02ca3867d558f7b2665772ee0846a41edc46d019b7d7648b8c560c2d6ef08
6
+ metadata.gz: '059aafd0ed382cc2b7446532d83a19121e19e61c8c9590bf372d074149aee2765426452c488020a2b55720fc63fbf050cc4314e26398495945957d55b9328a8c'
7
+ data.tar.gz: e0e74b28d8f2c193271aa8a610298f003913e0214870ca2dd20d4c87a7358da04bd63015204788eabbe84215f4c89582f85f2d1bb4504773e8b46776d744ae3b
@@ -1,4 +1,4 @@
1
- name: Isomorfeus Project
1
+ name: isomorfeus-iodine
2
2
 
3
3
  on:
4
4
  push:
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 "iodine" do |ext|
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
@@ -120,4 +120,4 @@ EOS
120
120
  end
121
121
  end
122
122
 
123
- create_makefile 'iodine/iodine'
123
+ create_makefile 'iodine_ext'
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