nghttp3 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f4b42e410c8a60fcd74db0e035c92fdde1942930d6eac27bbc6865cc3db4ea3f
4
+ data.tar.gz: 1fd9eba1cba09eec60fed2a3794ce9d243c0c6be5506f7acea178c92c851c7b3
5
+ SHA512:
6
+ metadata.gz: 5a0c576a7d481aa52e07367521a09fe8a27a108eda6b5d66ba8e9748cd03ab6097c6acc5e78415d8cf7577b0ac0916ce3df1116849da7f004ee7376b5a95d877
7
+ data.tar.gz: ab3d4467fb47e89a77893c1536f5705d42402c1d3bb2767ec1d62f66d0a7cc2727ebaf80ac215b560189cd8390a41f2133962b7ca56e0465ee9d837b29e29ff6
data/.clang-format ADDED
@@ -0,0 +1 @@
1
+ BasedOnStyle: LLVM
@@ -0,0 +1,6 @@
1
+ {
2
+ "recommendations": [
3
+ "ms-vscode.cpptools",
4
+ "shopify.ruby-lsp",
5
+ ]
6
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "[c][cpp]": {
3
+ "editor.formatOnSave": true,
4
+ "editor.defaultFormatter": "ms-vscode.cpptools"
5
+ },
6
+ "[json][jsonc]": {
7
+ "editor.formatOnSave": true,
8
+ "editor.defaultFormatter": "vscode.json-language-features"
9
+ }
10
+ }
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-12-19
4
+
5
+ - Initial release
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Yusuke Nakamura
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # nghttp3-ruby
2
+
3
+ > [!CAUTION]
4
+ > This gem is for experimental purposes only. Do not use it in production environments.
5
+
6
+ > [!WARNING]
7
+ > The code in this repository is almost entirely generated by Claude Code and reviewed by a human.
8
+
9
+ ## Installation
10
+
11
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
12
+
13
+ Install the gem and add to the application's Gemfile by executing:
14
+
15
+ ```bash
16
+ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
17
+ ```
18
+
19
+ If bundler is not being used to manage dependencies, install the gem by executing:
20
+
21
+ ```bash
22
+ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ TODO: Write usage instructions here
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/unasuke/nghttp3. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/unasuke/nghttp3/blob/main/CODE_OF_CONDUCT.md).
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
42
+
43
+ ## Code of Conduct
44
+
45
+ Everyone interacting in the Nghttp3 project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/unasuke/nghttp3/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "standard/rake"
9
+
10
+ require "rake/extensiontask"
11
+
12
+ task build: :compile
13
+
14
+ GEMSPEC = Gem::Specification.load("nghttp3.gemspec")
15
+
16
+ Rake::ExtensionTask.new("nghttp3", GEMSPEC) do |ext|
17
+ ext.lib_dir = "lib/nghttp3"
18
+ end
19
+
20
+ task default: %i[clobber compile test standard]
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mkmf"
4
+
5
+ # Makes all symbols private by default to avoid unintended conflict
6
+ # with other gems. To explicitly export symbols you can use RUBY_FUNC_EXPORTED
7
+ # selectively, or entirely remove this flag.
8
+ append_cflags("-fvisibility=hidden")
9
+
10
+ unless have_library("nghttp3", "nghttp3_version")
11
+ abort "nghttp3 library not found"
12
+ end
13
+
14
+ unless have_header("nghttp3/nghttp3.h")
15
+ abort "nghttp3/nghttp3.h not found"
16
+ end
17
+
18
+ create_makefile("nghttp3/nghttp3")
@@ -0,0 +1,300 @@
1
+ #include "nghttp3.h"
2
+ #include <stdarg.h>
3
+
4
+ VALUE rb_mNghttp3;
5
+ VALUE rb_cNghttp3Info;
6
+ VALUE rb_eNghttp3Error;
7
+
8
+ /* Error classes */
9
+ VALUE rb_eNghttp3InvalidArgumentError;
10
+ VALUE rb_eNghttp3InvalidStateError;
11
+ VALUE rb_eNghttp3WouldBlockError;
12
+ VALUE rb_eNghttp3StreamInUseError;
13
+ VALUE rb_eNghttp3MalformedHTTPHeaderError;
14
+ VALUE rb_eNghttp3MalformedHTTPMessagingError;
15
+ VALUE rb_eNghttp3QPACKFatalError;
16
+ VALUE rb_eNghttp3QPACKHeaderTooLargeError;
17
+ VALUE rb_eNghttp3StreamNotFoundError;
18
+ VALUE rb_eNghttp3ConnClosingError;
19
+ VALUE rb_eNghttp3StreamDataOverflowError;
20
+ VALUE rb_eNghttp3FatalError;
21
+ VALUE rb_eNghttp3NoMemError;
22
+ VALUE rb_eNghttp3CallbackFailureError;
23
+
24
+ /*
25
+ * call-seq:
26
+ * Nghttp3.library_version -> Nghttp3::Info
27
+ * Nghttp3.library_version(least_version) -> Nghttp3::Info or nil
28
+ *
29
+ * Returns version information about the nghttp3 library.
30
+ * If least_version is specified and the library version is less than
31
+ * that value, returns nil.
32
+ */
33
+ static VALUE rb_nghttp3_library_version(int argc, VALUE *argv, VALUE self) {
34
+ VALUE rb_least_version;
35
+ int least_version = 0;
36
+ const nghttp3_info *info;
37
+ VALUE info_obj;
38
+
39
+ rb_scan_args(argc, argv, "01", &rb_least_version);
40
+
41
+ if (!NIL_P(rb_least_version)) {
42
+ least_version = NUM2INT(rb_least_version);
43
+ }
44
+
45
+ info = nghttp3_version(least_version);
46
+
47
+ if (info == NULL) {
48
+ return Qnil;
49
+ }
50
+
51
+ info_obj = rb_obj_alloc(rb_cNghttp3Info);
52
+ rb_iv_set(info_obj, "@age", INT2NUM(info->age));
53
+ rb_iv_set(info_obj, "@version_num", INT2NUM(info->version_num));
54
+ rb_iv_set(info_obj, "@version_str", rb_str_new_cstr(info->version_str));
55
+
56
+ return info_obj;
57
+ }
58
+
59
+ /*
60
+ * Returns the age of the nghttp3 library.
61
+ */
62
+ static VALUE rb_nghttp3_info_age(VALUE self) { return rb_iv_get(self, "@age"); }
63
+
64
+ /*
65
+ * Returns the numerical version of the nghttp3 library.
66
+ */
67
+ static VALUE rb_nghttp3_info_version_num(VALUE self) {
68
+ return rb_iv_get(self, "@version_num");
69
+ }
70
+
71
+ /*
72
+ * Returns the version string of the nghttp3 library.
73
+ */
74
+ static VALUE rb_nghttp3_info_version_str(VALUE self) {
75
+ return rb_iv_get(self, "@version_str");
76
+ }
77
+
78
+ /*
79
+ * Returns the appropriate Ruby error class for the given nghttp3 error code.
80
+ */
81
+ VALUE nghttp3_rb_error_class_for_code(int error_code) {
82
+ switch (error_code) {
83
+ case NGHTTP3_ERR_INVALID_ARGUMENT:
84
+ return rb_eNghttp3InvalidArgumentError;
85
+ case NGHTTP3_ERR_INVALID_STATE:
86
+ return rb_eNghttp3InvalidStateError;
87
+ case NGHTTP3_ERR_WOULDBLOCK:
88
+ return rb_eNghttp3WouldBlockError;
89
+ case NGHTTP3_ERR_STREAM_IN_USE:
90
+ return rb_eNghttp3StreamInUseError;
91
+ case NGHTTP3_ERR_MALFORMED_HTTP_HEADER:
92
+ return rb_eNghttp3MalformedHTTPHeaderError;
93
+ case NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING:
94
+ return rb_eNghttp3MalformedHTTPMessagingError;
95
+ case NGHTTP3_ERR_QPACK_FATAL:
96
+ return rb_eNghttp3QPACKFatalError;
97
+ case NGHTTP3_ERR_QPACK_HEADER_TOO_LARGE:
98
+ return rb_eNghttp3QPACKHeaderTooLargeError;
99
+ case NGHTTP3_ERR_STREAM_NOT_FOUND:
100
+ return rb_eNghttp3StreamNotFoundError;
101
+ case NGHTTP3_ERR_CONN_CLOSING:
102
+ return rb_eNghttp3ConnClosingError;
103
+ case NGHTTP3_ERR_STREAM_DATA_OVERFLOW:
104
+ return rb_eNghttp3StreamDataOverflowError;
105
+ case NGHTTP3_ERR_NOMEM:
106
+ return rb_eNghttp3NoMemError;
107
+ case NGHTTP3_ERR_CALLBACK_FAILURE:
108
+ return rb_eNghttp3CallbackFailureError;
109
+ default:
110
+ if (nghttp3_err_is_fatal(error_code)) {
111
+ return rb_eNghttp3FatalError;
112
+ }
113
+ return rb_eNghttp3Error;
114
+ }
115
+ }
116
+
117
+ /*
118
+ * Raises an appropriate Ruby exception for the given nghttp3 error code.
119
+ */
120
+ void nghttp3_rb_raise(int error_code, const char *fmt, ...) {
121
+ VALUE error_class;
122
+ char buf[256];
123
+ va_list args;
124
+
125
+ error_class = nghttp3_rb_error_class_for_code(error_code);
126
+
127
+ if (fmt != NULL) {
128
+ va_start(args, fmt);
129
+ vsnprintf(buf, sizeof(buf), fmt, args);
130
+ va_end(args);
131
+ rb_raise(error_class, "%s: %s", buf, nghttp3_strerror(error_code));
132
+ } else {
133
+ rb_raise(error_class, "%s", nghttp3_strerror(error_code));
134
+ }
135
+ }
136
+
137
+ /*
138
+ * call-seq:
139
+ * Nghttp3.err_is_fatal?(error_code) -> true or false
140
+ *
141
+ * Returns true if the given error code represents a fatal error.
142
+ */
143
+ static VALUE rb_nghttp3_err_is_fatal(VALUE self, VALUE rb_error_code) {
144
+ int error_code = NUM2INT(rb_error_code);
145
+ return nghttp3_err_is_fatal(error_code) ? Qtrue : Qfalse;
146
+ }
147
+
148
+ /*
149
+ * call-seq:
150
+ * Nghttp3.strerror(error_code) -> String
151
+ *
152
+ * Returns a textual representation of the given error code.
153
+ */
154
+ static VALUE rb_nghttp3_strerror(VALUE self, VALUE rb_error_code) {
155
+ int error_code = NUM2INT(rb_error_code);
156
+ const char *str = nghttp3_strerror(error_code);
157
+ return rb_str_new_cstr(str);
158
+ }
159
+
160
+ RUBY_FUNC_EXPORTED void Init_nghttp3(void) {
161
+ /* Define main module */
162
+ rb_mNghttp3 = rb_define_module("Nghttp3");
163
+
164
+ /* Define compile-time version constants */
165
+ rb_define_const(rb_mNghttp3, "NGHTTP3_VERSION",
166
+ rb_str_new_cstr(NGHTTP3_VERSION));
167
+ rb_define_const(rb_mNghttp3, "NGHTTP3_VERSION_NUM",
168
+ INT2NUM(NGHTTP3_VERSION_NUM));
169
+ rb_define_const(rb_mNghttp3, "NGHTTP3_VERSION_AGE",
170
+ INT2NUM(NGHTTP3_VERSION_AGE));
171
+
172
+ /* Define module method for runtime version */
173
+ rb_define_singleton_method(rb_mNghttp3, "library_version",
174
+ rb_nghttp3_library_version, -1);
175
+
176
+ /* Define Info class */
177
+ rb_cNghttp3Info = rb_define_class_under(rb_mNghttp3, "Info", rb_cObject);
178
+ rb_undef_method(rb_singleton_class(rb_cNghttp3Info), "new");
179
+ rb_define_method(rb_cNghttp3Info, "age", rb_nghttp3_info_age, 0);
180
+ rb_define_method(rb_cNghttp3Info, "version_num", rb_nghttp3_info_version_num,
181
+ 0);
182
+ rb_define_method(rb_cNghttp3Info, "version_str", rb_nghttp3_info_version_str,
183
+ 0);
184
+
185
+ /* Define base error class */
186
+ rb_eNghttp3Error =
187
+ rb_define_class_under(rb_mNghttp3, "Error", rb_eStandardError);
188
+
189
+ /* Define error code constants */
190
+ rb_define_const(rb_mNghttp3, "NGHTTP3_ERR_INVALID_ARGUMENT",
191
+ INT2NUM(NGHTTP3_ERR_INVALID_ARGUMENT));
192
+ rb_define_const(rb_mNghttp3, "NGHTTP3_ERR_INVALID_STATE",
193
+ INT2NUM(NGHTTP3_ERR_INVALID_STATE));
194
+ rb_define_const(rb_mNghttp3, "NGHTTP3_ERR_WOULDBLOCK",
195
+ INT2NUM(NGHTTP3_ERR_WOULDBLOCK));
196
+ rb_define_const(rb_mNghttp3, "NGHTTP3_ERR_STREAM_IN_USE",
197
+ INT2NUM(NGHTTP3_ERR_STREAM_IN_USE));
198
+ rb_define_const(rb_mNghttp3, "NGHTTP3_ERR_MALFORMED_HTTP_HEADER",
199
+ INT2NUM(NGHTTP3_ERR_MALFORMED_HTTP_HEADER));
200
+ rb_define_const(rb_mNghttp3, "NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING",
201
+ INT2NUM(NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING));
202
+ rb_define_const(rb_mNghttp3, "NGHTTP3_ERR_QPACK_FATAL",
203
+ INT2NUM(NGHTTP3_ERR_QPACK_FATAL));
204
+ rb_define_const(rb_mNghttp3, "NGHTTP3_ERR_QPACK_HEADER_TOO_LARGE",
205
+ INT2NUM(NGHTTP3_ERR_QPACK_HEADER_TOO_LARGE));
206
+ rb_define_const(rb_mNghttp3, "NGHTTP3_ERR_STREAM_NOT_FOUND",
207
+ INT2NUM(NGHTTP3_ERR_STREAM_NOT_FOUND));
208
+ rb_define_const(rb_mNghttp3, "NGHTTP3_ERR_CONN_CLOSING",
209
+ INT2NUM(NGHTTP3_ERR_CONN_CLOSING));
210
+ rb_define_const(rb_mNghttp3, "NGHTTP3_ERR_STREAM_DATA_OVERFLOW",
211
+ INT2NUM(NGHTTP3_ERR_STREAM_DATA_OVERFLOW));
212
+ rb_define_const(rb_mNghttp3, "NGHTTP3_ERR_FATAL", INT2NUM(NGHTTP3_ERR_FATAL));
213
+ rb_define_const(rb_mNghttp3, "NGHTTP3_ERR_NOMEM", INT2NUM(NGHTTP3_ERR_NOMEM));
214
+ rb_define_const(rb_mNghttp3, "NGHTTP3_ERR_CALLBACK_FAILURE",
215
+ INT2NUM(NGHTTP3_ERR_CALLBACK_FAILURE));
216
+
217
+ /* Define HTTP/3 application error code constants */
218
+ rb_define_const(rb_mNghttp3, "H3_NO_ERROR", INT2NUM(NGHTTP3_H3_NO_ERROR));
219
+ rb_define_const(rb_mNghttp3, "H3_GENERAL_PROTOCOL_ERROR",
220
+ INT2NUM(NGHTTP3_H3_GENERAL_PROTOCOL_ERROR));
221
+ rb_define_const(rb_mNghttp3, "H3_INTERNAL_ERROR",
222
+ INT2NUM(NGHTTP3_H3_INTERNAL_ERROR));
223
+ rb_define_const(rb_mNghttp3, "H3_STREAM_CREATION_ERROR",
224
+ INT2NUM(NGHTTP3_H3_STREAM_CREATION_ERROR));
225
+ rb_define_const(rb_mNghttp3, "H3_CLOSED_CRITICAL_STREAM",
226
+ INT2NUM(NGHTTP3_H3_CLOSED_CRITICAL_STREAM));
227
+ rb_define_const(rb_mNghttp3, "H3_FRAME_UNEXPECTED",
228
+ INT2NUM(NGHTTP3_H3_FRAME_UNEXPECTED));
229
+ rb_define_const(rb_mNghttp3, "H3_FRAME_ERROR",
230
+ INT2NUM(NGHTTP3_H3_FRAME_ERROR));
231
+ rb_define_const(rb_mNghttp3, "H3_EXCESSIVE_LOAD",
232
+ INT2NUM(NGHTTP3_H3_EXCESSIVE_LOAD));
233
+ rb_define_const(rb_mNghttp3, "H3_ID_ERROR", INT2NUM(NGHTTP3_H3_ID_ERROR));
234
+ rb_define_const(rb_mNghttp3, "H3_SETTINGS_ERROR",
235
+ INT2NUM(NGHTTP3_H3_SETTINGS_ERROR));
236
+ rb_define_const(rb_mNghttp3, "H3_MISSING_SETTINGS",
237
+ INT2NUM(NGHTTP3_H3_MISSING_SETTINGS));
238
+ rb_define_const(rb_mNghttp3, "H3_REQUEST_REJECTED",
239
+ INT2NUM(NGHTTP3_H3_REQUEST_REJECTED));
240
+ rb_define_const(rb_mNghttp3, "H3_REQUEST_CANCELLED",
241
+ INT2NUM(NGHTTP3_H3_REQUEST_CANCELLED));
242
+ rb_define_const(rb_mNghttp3, "H3_REQUEST_INCOMPLETE",
243
+ INT2NUM(NGHTTP3_H3_REQUEST_INCOMPLETE));
244
+ rb_define_const(rb_mNghttp3, "H3_MESSAGE_ERROR",
245
+ INT2NUM(NGHTTP3_H3_MESSAGE_ERROR));
246
+ rb_define_const(rb_mNghttp3, "H3_CONNECT_ERROR",
247
+ INT2NUM(NGHTTP3_H3_CONNECT_ERROR));
248
+ rb_define_const(rb_mNghttp3, "H3_VERSION_FALLBACK",
249
+ INT2NUM(NGHTTP3_H3_VERSION_FALLBACK));
250
+
251
+ /* Define data flag constants */
252
+ rb_define_const(rb_mNghttp3, "DATA_FLAG_NONE",
253
+ UINT2NUM(NGHTTP3_DATA_FLAG_NONE));
254
+ rb_define_const(rb_mNghttp3, "DATA_FLAG_EOF",
255
+ UINT2NUM(NGHTTP3_DATA_FLAG_EOF));
256
+ rb_define_const(rb_mNghttp3, "DATA_FLAG_NO_END_STREAM",
257
+ UINT2NUM(NGHTTP3_DATA_FLAG_NO_END_STREAM));
258
+
259
+ /* Define specific error classes */
260
+ rb_eNghttp3InvalidArgumentError = rb_define_class_under(
261
+ rb_mNghttp3, "InvalidArgumentError", rb_eNghttp3Error);
262
+ rb_eNghttp3InvalidStateError =
263
+ rb_define_class_under(rb_mNghttp3, "InvalidStateError", rb_eNghttp3Error);
264
+ rb_eNghttp3WouldBlockError =
265
+ rb_define_class_under(rb_mNghttp3, "WouldBlockError", rb_eNghttp3Error);
266
+ rb_eNghttp3StreamInUseError =
267
+ rb_define_class_under(rb_mNghttp3, "StreamInUseError", rb_eNghttp3Error);
268
+ rb_eNghttp3MalformedHTTPHeaderError = rb_define_class_under(
269
+ rb_mNghttp3, "MalformedHTTPHeaderError", rb_eNghttp3Error);
270
+ rb_eNghttp3MalformedHTTPMessagingError = rb_define_class_under(
271
+ rb_mNghttp3, "MalformedHTTPMessagingError", rb_eNghttp3Error);
272
+ rb_eNghttp3QPACKFatalError =
273
+ rb_define_class_under(rb_mNghttp3, "QPACKFatalError", rb_eNghttp3Error);
274
+ rb_eNghttp3QPACKHeaderTooLargeError = rb_define_class_under(
275
+ rb_mNghttp3, "QPACKHeaderTooLargeError", rb_eNghttp3Error);
276
+ rb_eNghttp3StreamNotFoundError = rb_define_class_under(
277
+ rb_mNghttp3, "StreamNotFoundError", rb_eNghttp3Error);
278
+ rb_eNghttp3ConnClosingError =
279
+ rb_define_class_under(rb_mNghttp3, "ConnClosingError", rb_eNghttp3Error);
280
+ rb_eNghttp3StreamDataOverflowError = rb_define_class_under(
281
+ rb_mNghttp3, "StreamDataOverflowError", rb_eNghttp3Error);
282
+ rb_eNghttp3FatalError =
283
+ rb_define_class_under(rb_mNghttp3, "FatalError", rb_eNghttp3Error);
284
+ rb_eNghttp3NoMemError =
285
+ rb_define_class_under(rb_mNghttp3, "NoMemError", rb_eNghttp3Error);
286
+ rb_eNghttp3CallbackFailureError = rb_define_class_under(
287
+ rb_mNghttp3, "CallbackFailureError", rb_eNghttp3Error);
288
+
289
+ /* Define error utility methods */
290
+ rb_define_singleton_method(rb_mNghttp3, "err_is_fatal?",
291
+ rb_nghttp3_err_is_fatal, 1);
292
+ rb_define_singleton_method(rb_mNghttp3, "strerror", rb_nghttp3_strerror, 1);
293
+
294
+ /* Initialize other classes */
295
+ Init_nghttp3_settings();
296
+ Init_nghttp3_nv();
297
+ Init_nghttp3_callbacks();
298
+ Init_nghttp3_connection();
299
+ Init_nghttp3_qpack();
300
+ }
@@ -0,0 +1,65 @@
1
+ #ifndef NGHTTP3_RUBY_H
2
+ #define NGHTTP3_RUBY_H 1
3
+
4
+ #include "ruby.h"
5
+ #include <nghttp3/nghttp3.h>
6
+
7
+ extern VALUE rb_mNghttp3;
8
+ extern VALUE rb_cNghttp3Info;
9
+ extern VALUE rb_eNghttp3Error;
10
+
11
+ /* Error classes */
12
+ extern VALUE rb_eNghttp3InvalidArgumentError;
13
+ extern VALUE rb_eNghttp3InvalidStateError;
14
+ extern VALUE rb_eNghttp3WouldBlockError;
15
+ extern VALUE rb_eNghttp3StreamInUseError;
16
+ extern VALUE rb_eNghttp3MalformedHTTPHeaderError;
17
+ extern VALUE rb_eNghttp3MalformedHTTPMessagingError;
18
+ extern VALUE rb_eNghttp3QPACKFatalError;
19
+ extern VALUE rb_eNghttp3QPACKHeaderTooLargeError;
20
+ extern VALUE rb_eNghttp3StreamNotFoundError;
21
+ extern VALUE rb_eNghttp3ConnClosingError;
22
+ extern VALUE rb_eNghttp3StreamDataOverflowError;
23
+ extern VALUE rb_eNghttp3FatalError;
24
+ extern VALUE rb_eNghttp3NoMemError;
25
+ extern VALUE rb_eNghttp3CallbackFailureError;
26
+
27
+ /* Data structure classes */
28
+ extern VALUE rb_cNghttp3Settings;
29
+ extern VALUE rb_cNghttp3NV;
30
+ extern VALUE rb_cNghttp3Connection;
31
+ extern VALUE rb_cNghttp3Callbacks;
32
+
33
+ /* QPACK module and classes */
34
+ extern VALUE rb_mNghttp3QPACK;
35
+ extern VALUE rb_cNghttp3QPACKEncoder;
36
+ extern VALUE rb_cNghttp3QPACKDecoder;
37
+
38
+ /* TypedData type for Settings (used by Connection) */
39
+ extern const rb_data_type_t settings_data_type;
40
+
41
+ /* TypedData type for Callbacks */
42
+ extern const rb_data_type_t callbacks_data_type;
43
+
44
+ /* Helper functions */
45
+ VALUE nghttp3_rb_error_class_for_code(int error_code);
46
+ void nghttp3_rb_raise(int error_code, const char *fmt, ...);
47
+
48
+ /* Settings helper */
49
+ nghttp3_settings *nghttp3_rb_get_settings(VALUE rb_settings);
50
+
51
+ /* NV helper */
52
+ nghttp3_nv nghttp3_rb_nv_to_c(VALUE rb_nv);
53
+
54
+ /* Callbacks helper */
55
+ VALUE nghttp3_rb_get_callbacks(VALUE rb_conn);
56
+ void nghttp3_rb_setup_callbacks(nghttp3_callbacks *callbacks);
57
+
58
+ /* Init functions */
59
+ void Init_nghttp3_settings(void);
60
+ void Init_nghttp3_nv(void);
61
+ void Init_nghttp3_connection(void);
62
+ void Init_nghttp3_callbacks(void);
63
+ void Init_nghttp3_qpack(void);
64
+
65
+ #endif /* NGHTTP3_RUBY_H */