qr_reader-native 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.
Files changed (95) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE-mruby.txt +22 -0
  3. data/LICENSE-spinel.txt +19 -0
  4. data/LICENSE.txt +21 -0
  5. data/README.md +61 -0
  6. data/ext/qr_reader_native/SPINEL_VERSION +1 -0
  7. data/ext/qr_reader_native/extconf.rb +8 -0
  8. data/ext/qr_reader_native/mruby/error.h +13 -0
  9. data/ext/qr_reader_native/mruby/internal.h +145 -0
  10. data/ext/qr_reader_native/mruby/string.h +22 -0
  11. data/ext/qr_reader_native/mruby.h +93 -0
  12. data/ext/qr_reader_native/mruby_shim.h +118 -0
  13. data/ext/qr_reader_native/qr_reader_native.c +13513 -0
  14. data/ext/qr_reader_native/qr_reader_native.h +29 -0
  15. data/ext/qr_reader_native/qr_reader_native_ext.c +598 -0
  16. data/ext/qr_reader_native/re_cased.h +71 -0
  17. data/ext/qr_reader_native/re_compile.c +5784 -0
  18. data/ext/qr_reader_native/re_ctype.h +3540 -0
  19. data/ext/qr_reader_native/re_exec.c +2190 -0
  20. data/ext/qr_reader_native/re_internal.h +671 -0
  21. data/ext/qr_reader_native/re_prop.h +4629 -0
  22. data/ext/qr_reader_native/re_spinel.c +363 -0
  23. data/ext/qr_reader_native/re_spinel.h +22 -0
  24. data/ext/qr_reader_native/re_spinel_utf8.inc +97 -0
  25. data/ext/qr_reader_native/re_utf8.c +156 -0
  26. data/ext/qr_reader_native/sp_alloc.c +1447 -0
  27. data/ext/qr_reader_native/sp_alloc.h +1196 -0
  28. data/ext/qr_reader_native/sp_argf.h +33 -0
  29. data/ext/qr_reader_native/sp_array.c +1052 -0
  30. data/ext/qr_reader_native/sp_array.h +456 -0
  31. data/ext/qr_reader_native/sp_bigint.c +5826 -0
  32. data/ext/qr_reader_native/sp_bigint.h +117 -0
  33. data/ext/qr_reader_native/sp_cold.c +5259 -0
  34. data/ext/qr_reader_native/sp_compat.h +402 -0
  35. data/ext/qr_reader_native/sp_core.c +818 -0
  36. data/ext/qr_reader_native/sp_core.h +56 -0
  37. data/ext/qr_reader_native/sp_crypto.c +877 -0
  38. data/ext/qr_reader_native/sp_crypto.h +169 -0
  39. data/ext/qr_reader_native/sp_dtoa.c +1533 -0
  40. data/ext/qr_reader_native/sp_dtoa.h +29 -0
  41. data/ext/qr_reader_native/sp_encoding_names.h +172 -0
  42. data/ext/qr_reader_native/sp_enum.h +86 -0
  43. data/ext/qr_reader_native/sp_exc.c +1185 -0
  44. data/ext/qr_reader_native/sp_exc.h +186 -0
  45. data/ext/qr_reader_native/sp_exc_ctx.h +56 -0
  46. data/ext/qr_reader_native/sp_fiber.c +889 -0
  47. data/ext/qr_reader_native/sp_fiber.h +162 -0
  48. data/ext/qr_reader_native/sp_fiber_ctx.h +84 -0
  49. data/ext/qr_reader_native/sp_format.c +695 -0
  50. data/ext/qr_reader_native/sp_format.h +83 -0
  51. data/ext/qr_reader_native/sp_gc.c +1793 -0
  52. data/ext/qr_reader_native/sp_gc.h +762 -0
  53. data/ext/qr_reader_native/sp_hash.c +131 -0
  54. data/ext/qr_reader_native/sp_hash.h +131 -0
  55. data/ext/qr_reader_native/sp_inspect.c +215 -0
  56. data/ext/qr_reader_native/sp_inspect.h +128 -0
  57. data/ext/qr_reader_native/sp_io.c +1676 -0
  58. data/ext/qr_reader_native/sp_io.h +272 -0
  59. data/ext/qr_reader_native/sp_iobuffer.c +1014 -0
  60. data/ext/qr_reader_native/sp_iobuffer.h +167 -0
  61. data/ext/qr_reader_native/sp_marshal.c +487 -0
  62. data/ext/qr_reader_native/sp_marshal.h +60 -0
  63. data/ext/qr_reader_native/sp_net.c +1029 -0
  64. data/ext/qr_reader_native/sp_net.h +205 -0
  65. data/ext/qr_reader_native/sp_pack.c +1254 -0
  66. data/ext/qr_reader_native/sp_poly_cold.c +1220 -0
  67. data/ext/qr_reader_native/sp_proc.c +410 -0
  68. data/ext/qr_reader_native/sp_proc.h +327 -0
  69. data/ext/qr_reader_native/sp_process.c +547 -0
  70. data/ext/qr_reader_native/sp_process_status.c +211 -0
  71. data/ext/qr_reader_native/sp_process_status.h +66 -0
  72. data/ext/qr_reader_native/sp_random.c +287 -0
  73. data/ext/qr_reader_native/sp_random.h +52 -0
  74. data/ext/qr_reader_native/sp_range.h +144 -0
  75. data/ext/qr_reader_native/sp_re.c +1379 -0
  76. data/ext/qr_reader_native/sp_re.h +186 -0
  77. data/ext/qr_reader_native/sp_re_names.h +59 -0
  78. data/ext/qr_reader_native/sp_sched.c +4044 -0
  79. data/ext/qr_reader_native/sp_sched.h +295 -0
  80. data/ext/qr_reader_native/sp_slab.c +1507 -0
  81. data/ext/qr_reader_native/sp_str.c +1462 -0
  82. data/ext/qr_reader_native/sp_str.h +306 -0
  83. data/ext/qr_reader_native/sp_str_crypt.c +23 -0
  84. data/ext/qr_reader_native/sp_string.c +92 -0
  85. data/ext/qr_reader_native/sp_string.h +253 -0
  86. data/ext/qr_reader_native/sp_system.c +78 -0
  87. data/ext/qr_reader_native/sp_system.h +18 -0
  88. data/ext/qr_reader_native/sp_time.c +860 -0
  89. data/ext/qr_reader_native/sp_time.h +100 -0
  90. data/ext/qr_reader_native/sp_types.h +292 -0
  91. data/ext/qr_reader_native/spinel_rt.h +19017 -0
  92. data/ext/qr_reader_native/unicase.c +399 -0
  93. data/ext/qr_reader_native/unicase.h +901 -0
  94. data/lib/qr_reader/native.rb +6 -0
  95. metadata +153 -0
@@ -0,0 +1,205 @@
1
+ /* sp_net.h -- POSIX TCP / poll / process / shell primitives for
2
+ * single-host, HTTP-shaped Spinel runtimes.
3
+ *
4
+ * Pure C, no spinel-runtime dependency. Archived into libspinel_rt.a
5
+ * alongside sp_crypto / sp_bigint -- a vendored, audit-sized helper
6
+ * that ships with spinel so frameworks (tep, roundhouse, ...) build
7
+ * their HTTP layer on top instead of fork-and-modifying. Same
8
+ * precedent + spirit as sp_crypto (#514): small enough to read in one
9
+ * sitting, no OpenSSL / libsodium. (TLS is deliberately NOT here --
10
+ * an optional sp_net_tls unit will layer over these fds so the core
11
+ * stays dependency-light; see matz/spinel#1054.)
12
+ *
13
+ * Conventions
14
+ * -----------
15
+ * - fd-based: every call takes/returns a raw socket fd; the framework
16
+ * owns lifetime.
17
+ * - Static return buffers (per-function) -- copy on the caller side if a
18
+ * value must outlive the next call, same as sp_crypto. The buffers are
19
+ * per-worker in the threaded build, so two green threads on two OS
20
+ * workers do not share one; each still holds only its own last result.
21
+ * - String inputs are NUL-terminated.
22
+ *
23
+ * Naming: all exported symbols use the `sp_net_` prefix.
24
+ */
25
+ #ifndef SP_NET_H
26
+ #define SP_NET_H
27
+
28
+ #ifdef __cplusplus
29
+ extern "C" {
30
+ #endif
31
+
32
+ /* ---- graceful shutdown (prefork servers) ----
33
+ * install_term_handlers arms SIGTERM/SIGINT to set a flag (SA_RESETHAND
34
+ * so a second signal kills immediately); shutdown_requested reads it.
35
+ * sp_net_accept honors the flag so a blocking accept loop can break
36
+ * cleanly. */
37
+ int sp_net_install_term_handlers(void);
38
+ int sp_net_shutdown_requested(void);
39
+
40
+ /* ---- TCP socket lifecycle ----
41
+ * listen: bind+listen on `port` (INADDR_ANY); reuseport!=0 sets
42
+ * SO_REUSEPORT for kernel accept load-balancing across prefork
43
+ * workers. Disables Nagle + ignores SIGPIPE. Returns the listen fd.
44
+ * accept: blocking accept; returns -1 if a term signal arrived
45
+ * (checked before blocking and on EINTR), else the connection fd.
46
+ * accept_nb: non-blocking accept; -1 with errno EAGAIN/EWOULDBLOCK if
47
+ * nothing pending (listen fd must be sp_net_set_nonblock'd first).
48
+ * accept / accept_nb set TCP_NODELAY on the returned connection fd.
49
+ * connect: outbound TCP to host:port via getaddrinfo (IP or DNS),
50
+ * Nagle off. Returns the connected fd or -1.
51
+ * close: close(fd). set_nonblock: flip O_NONBLOCK on.
52
+ * set_nodelay: disable Nagle on a connection fd (called for you by
53
+ * accept/accept_nb/connect; exposed for fds obtained elsewhere). */
54
+ int sp_net_listen(int port, int reuseport);
55
+ int sp_net_listen_host(const char *host, int port, int backlog);
56
+ int sp_net_local_port(int fd);
57
+ int sp_net_sock_ip(int fd, int peer, char *ipbuf, int cap);
58
+ int sp_net_sock_host(int fd, int peer, char *hostbuf, int cap);
59
+ int sp_net_accept(int sfd);
60
+ int sp_net_accept_nb(int sfd);
61
+ int sp_net_connect(const char *host, int port);
62
+
63
+ /* ---- UDP ----
64
+ * udp_open: an unbound SOCK_DGRAM fd. bind/connect attach it to a local /
65
+ * remote address. send_to with a NULL host uses the connected peer.
66
+ * recv_from reads one datagram and reports the sender. */
67
+ int sp_net_udp_open(int family);
68
+ int sp_net_fd_family(int fd);
69
+ int sp_net_udp_bind(int fd, const char *host, int port);
70
+ int sp_net_udp_connect(int fd, const char *host, int port);
71
+ int sp_net_udp_send_to(int fd, const char *data, int len, const char *host, int port);
72
+ int sp_net_udp_recv_from(int fd, char *buf, int cap, char *ipbuf, int ipcap, int *port_out);
73
+
74
+ /* ---- UNIX-domain stream sockets ---- */
75
+ int sp_net_unix_listen(const char *path, int backlog);
76
+ int sp_net_unix_connect(const char *path);
77
+ int sp_net_unix_path(int fd, int peer, char *buf, int cap);
78
+
79
+ /* ---- Socket class methods ---- */
80
+ int sp_net_gethostname(char *buf, int cap);
81
+ int sp_net_socketpair(int domain, int type, int protocol, int fds[2]);
82
+ int sp_net_socket(int domain, int type, int protocol);
83
+ int sp_net_getaddrinfo_at(const char *host, int port, int want_family, int socktype, int idx,
84
+ int *family, int *stype, int *proto,
85
+ char *ipbuf, int ipcap, int *port_out);
86
+
87
+ /* ---- socket options ----
88
+ * The integer-valued options, which is what Ruby programs reach for
89
+ * (SO_REUSEADDR, SO_KEEPALIVE, TCP_NODELAY, SO_RCVBUF, ...). */
90
+ int sp_net_setsockopt_int(int fd, int level, int optname, int value);
91
+ int sp_net_getsockopt_int(int fd, int level, int optname);
92
+ int sp_net_shutdown(int fd, int how);
93
+ int sp_net_close(int fd);
94
+ int sp_net_set_nonblock(int fd);
95
+ void sp_net_set_nodelay(int fd);
96
+
97
+ /* ---- TCP I/O ----
98
+ * recv_some: up to maxlen bytes from one read. recv_all: read until
99
+ * EOF or max_bytes. Both return a static, NUL-terminated buffer
100
+ * (empty on error/EOF). write_str: write the full NUL-terminated
101
+ * string; write_bytes: binary variant (explicit length, NUL-safe).
102
+ * Return 0 on success, -1 on failure.
103
+ *
104
+ * Binary-safe recv: a NUL-terminated buffer can't carry an embedded
105
+ * 0x00 (WebSocket frames do). Declaring recv_some/recv_all with the
106
+ * FFI `:binstr` return mode builds the result String from the exact
107
+ * byte count published in sp_ffi_bin_len instead of strlen, so binary
108
+ * payloads survive. The same C functions serve both `:str` and
109
+ * `:binstr` callers; sp_ffi_bin_len (declared in sp_alloc.h) holds the
110
+ * last recv's byte count. */
111
+ const char *sp_net_recv_some(int fd, int maxlen);
112
+ const char *sp_net_recv_all(int fd, int max_bytes);
113
+ int sp_net_write_str(int fd, const char *s);
114
+ int sp_net_write_bytes(int fd, const char *data, int n);
115
+
116
+ /* Non-blocking write: takes what the socket will accept now and answers how
117
+ * much that was, so the caller keeps the backpressure policy. write_str /
118
+ * write_bytes above block until everything is written, which for fan-out
119
+ * means one slow peer delays every other. Returns >0 bytes accepted, 0 when
120
+ * the peer is alive but its buffer is full (wait for WRITE readiness and call
121
+ * again with the remainder), -1 when the connection is gone. */
122
+ int sp_net_write_partial(int fd, const char *data, int n);
123
+
124
+ /* ---- poll(2) ----
125
+ * reset clears the slot table; add registers (fd, mode_bits) where
126
+ * 1=READ, 2=WRITE and returns the slot index; run blocks up to
127
+ * timeout_ms (-1 = forever, 0 = peek) and returns the ready count;
128
+ * ready(slot) returns the mode bits that fired (POLLHUP/POLLERR fold
129
+ * into READ).
130
+ *
131
+ * The set has no fixed ceiling -- it grows with the number of fds added
132
+ * between resets. add() answers -1 only when the allocator refuses, which
133
+ * it also reports on stderr, since a caller cannot tell that apart from
134
+ * "not registered this round" by the return value alone.
135
+ *
136
+ * The set is rebuilt every tick (reset/add/.../run), which costs the caller
137
+ * O(fds) per tick whatever the backend underneath. The persistent-registration
138
+ * calls below cost O(events) instead; prefer them for a connection-holding
139
+ * server. */
140
+ int sp_net_poll_reset(void);
141
+ int sp_net_poll_add(int fd, int mode_bits);
142
+ int sp_net_poll_run(int timeout_ms);
143
+ int sp_net_poll_ready(int slot);
144
+
145
+ /* ---- poll(2), persistent registration ----
146
+ * The four above rebuild the set every tick, so a caller with N parked fds
147
+ * does O(N) work per tick however few of them are ready. These register once
148
+ * per connection instead: wait() answers how many fds fired, and
149
+ * event_fd/event_mode(i) read the i'th of those, so the caller's work is
150
+ * proportional to EVENTS rather than to connections.
151
+ *
152
+ * register(fd, mode_bits) adds or, if fd is already registered, updates it;
153
+ * modify changes the interest (e.g. adding WRITE while a send is pending);
154
+ * unregister drops it. mode_bits are 1=READ, 2=WRITE as above, and
155
+ * event_mode folds POLLHUP/POLLERR into READ as ready() does. register /
156
+ * modify / unregister answer 0, or -1 for an unregistered fd or an allocator
157
+ * refusal (which is also reported on stderr). wait returns the ready count,
158
+ * or -1 if shutdown was requested. registered() is the current set size.
159
+ *
160
+ * The events wait() reports are a snapshot, so unregistering an fd while
161
+ * walking them -- what a server does on every EOF -- does not disturb the
162
+ * walk. Both sets are per-worker, like the recv buffers: a green thread is
163
+ * pinned to its worker, so it always polls the fds it registered, and two
164
+ * threads running their own loops do not share one set.
165
+ *
166
+ * The backend is still poll(2). A caller written to this contract does not
167
+ * change again if epoll/kqueue is put underneath -- which is the point of
168
+ * the shape rather than of the syscall. Use these OR the four above, not
169
+ * both: they keep separate sets. (matz/spinel#4103) */
170
+ int sp_net_poll_register(int fd, int mode_bits);
171
+ int sp_net_poll_modify(int fd, int mode_bits);
172
+ int sp_net_poll_unregister(int fd);
173
+ int sp_net_poll_registered(void);
174
+ int sp_net_poll_wait(int timeout_ms);
175
+ int sp_net_poll_event_fd(int i);
176
+ int sp_net_poll_event_mode(int i);
177
+
178
+ /* ---- process (prefork) ----
179
+ * fork: 0 in child, pid>0 in parent, -1 on failure. exit: _exit(status)
180
+ * (never returns; int for FFI symmetry). getpid. wait_any: reap one
181
+ * child, returns its pid or -1 when none remain. */
182
+ int sp_net_fork(void);
183
+ int sp_net_exit(int status);
184
+ int sp_net_getpid(void);
185
+ int sp_net_wait_any(void);
186
+
187
+ /* ---- shell ----
188
+ * Run `cmd` via popen("r"), capture stdout up to max_bytes (capped at
189
+ * the internal buffer). Returns a static NUL-terminated buffer. */
190
+ const char *sp_net_shell_capture(const char *cmd, int max_bytes);
191
+
192
+ /* ---- packed sockaddr ----
193
+ * The byte form Socket.sockaddr_in / Addrinfo#to_sockaddr produce and
194
+ * connect_nonblock(sockaddr) consumes. Each writes into the caller's buffer
195
+ * and returns the packed length, or -1. sp_net_unpack_sockaddr_in reads one
196
+ * back, returning the port and writing the numeric address into ipbuf. */
197
+ int sp_net_pack_sockaddr_in(const char *host, int port, void *out, int cap);
198
+ int sp_net_pack_sockaddr_un(const char *path, void *out, int cap);
199
+ int sp_net_unpack_sockaddr_in(const void *sa, int salen, char *ipbuf, int cap);
200
+
201
+ #ifdef __cplusplus
202
+ }
203
+ #endif
204
+
205
+ #endif /* SP_NET_H */