awesome-grpc-that-works 0.12.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (453) hide show
  1. checksums.yaml +7 -0
  2. data/Makefile +29456 -0
  3. data/Rakefile +63 -0
  4. data/etc/roots.pem +5114 -0
  5. data/include/grpc/byte_buffer.h +120 -0
  6. data/include/grpc/byte_buffer_reader.h +58 -0
  7. data/include/grpc/census.h +488 -0
  8. data/include/grpc/compression.h +106 -0
  9. data/include/grpc/grpc.h +732 -0
  10. data/include/grpc/grpc_security.h +374 -0
  11. data/include/grpc/grpc_zookeeper.h +59 -0
  12. data/include/grpc/status.h +163 -0
  13. data/include/grpc/support/alloc.h +72 -0
  14. data/include/grpc/support/atm.h +92 -0
  15. data/include/grpc/support/atm_gcc_atomic.h +72 -0
  16. data/include/grpc/support/atm_gcc_sync.h +87 -0
  17. data/include/grpc/support/atm_win32.h +125 -0
  18. data/include/grpc/support/avl.h +91 -0
  19. data/include/grpc/support/cmdline.h +101 -0
  20. data/include/grpc/support/cpu.h +57 -0
  21. data/include/grpc/support/histogram.h +76 -0
  22. data/include/grpc/support/host_port.h +64 -0
  23. data/include/grpc/support/log.h +108 -0
  24. data/include/grpc/support/log_win32.h +51 -0
  25. data/include/grpc/support/port_platform.h +356 -0
  26. data/include/grpc/support/slice.h +182 -0
  27. data/include/grpc/support/slice_buffer.h +102 -0
  28. data/include/grpc/support/string_util.h +61 -0
  29. data/include/grpc/support/subprocess.h +57 -0
  30. data/include/grpc/support/sync.h +315 -0
  31. data/include/grpc/support/sync_generic.h +55 -0
  32. data/include/grpc/support/sync_posix.h +47 -0
  33. data/include/grpc/support/sync_win32.h +49 -0
  34. data/include/grpc/support/thd.h +91 -0
  35. data/include/grpc/support/time.h +128 -0
  36. data/include/grpc/support/tls.h +77 -0
  37. data/include/grpc/support/tls_gcc.h +56 -0
  38. data/include/grpc/support/tls_msvc.h +56 -0
  39. data/include/grpc/support/tls_pthread.h +60 -0
  40. data/include/grpc/support/useful.h +75 -0
  41. data/src/core/census/aggregation.h +66 -0
  42. data/src/core/census/context.c +46 -0
  43. data/src/core/census/context.h +47 -0
  44. data/src/core/census/grpc_context.c +53 -0
  45. data/src/core/census/grpc_filter.c +184 -0
  46. data/src/core/census/grpc_filter.h +44 -0
  47. data/src/core/census/initialize.c +57 -0
  48. data/src/core/census/operation.c +63 -0
  49. data/src/core/census/rpc_metric_id.h +51 -0
  50. data/src/core/census/tracing.c +45 -0
  51. data/src/core/channel/channel_args.c +209 -0
  52. data/src/core/channel/channel_args.h +88 -0
  53. data/src/core/channel/channel_stack.c +262 -0
  54. data/src/core/channel/channel_stack.h +260 -0
  55. data/src/core/channel/client_channel.c +524 -0
  56. data/src/core/channel/client_channel.h +63 -0
  57. data/src/core/channel/client_uchannel.c +243 -0
  58. data/src/core/channel/client_uchannel.h +60 -0
  59. data/src/core/channel/compress_filter.c +297 -0
  60. data/src/core/channel/compress_filter.h +65 -0
  61. data/src/core/channel/connected_channel.c +167 -0
  62. data/src/core/channel/connected_channel.h +51 -0
  63. data/src/core/channel/context.h +49 -0
  64. data/src/core/channel/http_client_filter.c +248 -0
  65. data/src/core/channel/http_client_filter.h +44 -0
  66. data/src/core/channel/http_server_filter.c +233 -0
  67. data/src/core/channel/http_server_filter.h +42 -0
  68. data/src/core/channel/subchannel_call_holder.c +259 -0
  69. data/src/core/channel/subchannel_call_holder.h +98 -0
  70. data/src/core/client_config/client_config.c +72 -0
  71. data/src/core/client_config/client_config.h +53 -0
  72. data/src/core/client_config/connector.c +54 -0
  73. data/src/core/client_config/connector.h +95 -0
  74. data/src/core/client_config/default_initial_connect_string.c +39 -0
  75. data/src/core/client_config/initial_connect_string.c +53 -0
  76. data/src/core/client_config/initial_connect_string.h +50 -0
  77. data/src/core/client_config/lb_policies/pick_first.c +398 -0
  78. data/src/core/client_config/lb_policies/pick_first.h +43 -0
  79. data/src/core/client_config/lb_policies/round_robin.c +537 -0
  80. data/src/core/client_config/lb_policies/round_robin.h +46 -0
  81. data/src/core/client_config/lb_policy.c +134 -0
  82. data/src/core/client_config/lb_policy.h +143 -0
  83. data/src/core/client_config/lb_policy_factory.c +48 -0
  84. data/src/core/client_config/lb_policy_factory.h +73 -0
  85. data/src/core/client_config/lb_policy_registry.c +88 -0
  86. data/src/core/client_config/lb_policy_registry.h +54 -0
  87. data/src/core/client_config/resolver.c +82 -0
  88. data/src/core/client_config/resolver.h +94 -0
  89. data/src/core/client_config/resolver_factory.c +55 -0
  90. data/src/core/client_config/resolver_factory.h +82 -0
  91. data/src/core/client_config/resolver_registry.c +137 -0
  92. data/src/core/client_config/resolver_registry.h +65 -0
  93. data/src/core/client_config/resolvers/dns_resolver.c +257 -0
  94. data/src/core/client_config/resolvers/dns_resolver.h +42 -0
  95. data/src/core/client_config/resolvers/sockaddr_resolver.c +391 -0
  96. data/src/core/client_config/resolvers/sockaddr_resolver.h +50 -0
  97. data/src/core/client_config/subchannel.c +697 -0
  98. data/src/core/client_config/subchannel.h +165 -0
  99. data/src/core/client_config/subchannel_factory.c +49 -0
  100. data/src/core/client_config/subchannel_factory.h +66 -0
  101. data/src/core/client_config/uri_parser.c +242 -0
  102. data/src/core/client_config/uri_parser.h +51 -0
  103. data/src/core/compression/algorithm.c +166 -0
  104. data/src/core/compression/algorithm_metadata.h +53 -0
  105. data/src/core/compression/message_compress.c +198 -0
  106. data/src/core/compression/message_compress.h +52 -0
  107. data/src/core/debug/trace.c +136 -0
  108. data/src/core/debug/trace.h +43 -0
  109. data/src/core/httpcli/format_request.c +120 -0
  110. data/src/core/httpcli/format_request.h +45 -0
  111. data/src/core/httpcli/httpcli.c +286 -0
  112. data/src/core/httpcli/httpcli.h +162 -0
  113. data/src/core/httpcli/httpcli_security_connector.c +189 -0
  114. data/src/core/httpcli/parser.c +211 -0
  115. data/src/core/httpcli/parser.h +64 -0
  116. data/src/core/iomgr/closure.c +98 -0
  117. data/src/core/iomgr/closure.h +97 -0
  118. data/src/core/iomgr/endpoint.c +67 -0
  119. data/src/core/iomgr/endpoint.h +102 -0
  120. data/src/core/iomgr/endpoint_pair.h +47 -0
  121. data/src/core/iomgr/endpoint_pair_posix.c +82 -0
  122. data/src/core/iomgr/endpoint_pair_windows.c +97 -0
  123. data/src/core/iomgr/exec_ctx.c +72 -0
  124. data/src/core/iomgr/exec_ctx.h +78 -0
  125. data/src/core/iomgr/executor.c +143 -0
  126. data/src/core/iomgr/executor.h +53 -0
  127. data/src/core/iomgr/fd_posix.c +438 -0
  128. data/src/core/iomgr/fd_posix.h +189 -0
  129. data/src/core/iomgr/iocp_windows.c +206 -0
  130. data/src/core/iomgr/iocp_windows.h +56 -0
  131. data/src/core/iomgr/iomgr.c +156 -0
  132. data/src/core/iomgr/iomgr.h +43 -0
  133. data/src/core/iomgr/iomgr_internal.h +58 -0
  134. data/src/core/iomgr/iomgr_posix.c +52 -0
  135. data/src/core/iomgr/iomgr_posix.h +39 -0
  136. data/src/core/iomgr/iomgr_windows.c +73 -0
  137. data/src/core/iomgr/pollset.h +95 -0
  138. data/src/core/iomgr/pollset_multipoller_with_epoll.c +258 -0
  139. data/src/core/iomgr/pollset_multipoller_with_poll_posix.c +227 -0
  140. data/src/core/iomgr/pollset_posix.c +638 -0
  141. data/src/core/iomgr/pollset_posix.h +147 -0
  142. data/src/core/iomgr/pollset_set.h +67 -0
  143. data/src/core/iomgr/pollset_set_posix.c +182 -0
  144. data/src/core/iomgr/pollset_set_posix.h +61 -0
  145. data/src/core/iomgr/pollset_set_windows.c +60 -0
  146. data/src/core/iomgr/pollset_set_windows.h +39 -0
  147. data/src/core/iomgr/pollset_windows.c +248 -0
  148. data/src/core/iomgr/pollset_windows.h +79 -0
  149. data/src/core/iomgr/resolve_address.h +72 -0
  150. data/src/core/iomgr/resolve_address_posix.c +183 -0
  151. data/src/core/iomgr/resolve_address_windows.c +166 -0
  152. data/src/core/iomgr/sockaddr.h +47 -0
  153. data/src/core/iomgr/sockaddr_posix.h +44 -0
  154. data/src/core/iomgr/sockaddr_utils.c +234 -0
  155. data/src/core/iomgr/sockaddr_utils.h +89 -0
  156. data/src/core/iomgr/sockaddr_win32.h +46 -0
  157. data/src/core/iomgr/socket_utils_common_posix.c +208 -0
  158. data/src/core/iomgr/socket_utils_linux.c +51 -0
  159. data/src/core/iomgr/socket_utils_posix.c +70 -0
  160. data/src/core/iomgr/socket_utils_posix.h +113 -0
  161. data/src/core/iomgr/socket_windows.c +98 -0
  162. data/src/core/iomgr/socket_windows.h +111 -0
  163. data/src/core/iomgr/tcp_client.h +53 -0
  164. data/src/core/iomgr/tcp_client_posix.c +304 -0
  165. data/src/core/iomgr/tcp_client_windows.c +221 -0
  166. data/src/core/iomgr/tcp_posix.c +485 -0
  167. data/src/core/iomgr/tcp_posix.h +65 -0
  168. data/src/core/iomgr/tcp_server.h +83 -0
  169. data/src/core/iomgr/tcp_server_posix.c +562 -0
  170. data/src/core/iomgr/tcp_server_windows.c +509 -0
  171. data/src/core/iomgr/tcp_windows.c +406 -0
  172. data/src/core/iomgr/tcp_windows.h +57 -0
  173. data/src/core/iomgr/time_averaged_stats.c +77 -0
  174. data/src/core/iomgr/time_averaged_stats.h +88 -0
  175. data/src/core/iomgr/timer.c +345 -0
  176. data/src/core/iomgr/timer.h +89 -0
  177. data/src/core/iomgr/timer_heap.c +148 -0
  178. data/src/core/iomgr/timer_heap.h +57 -0
  179. data/src/core/iomgr/timer_internal.h +61 -0
  180. data/src/core/iomgr/udp_server.c +439 -0
  181. data/src/core/iomgr/udp_server.h +83 -0
  182. data/src/core/iomgr/wakeup_fd_eventfd.c +85 -0
  183. data/src/core/iomgr/wakeup_fd_nospecial.c +51 -0
  184. data/src/core/iomgr/wakeup_fd_pipe.c +97 -0
  185. data/src/core/iomgr/wakeup_fd_pipe.h +41 -0
  186. data/src/core/iomgr/wakeup_fd_posix.c +72 -0
  187. data/src/core/iomgr/wakeup_fd_posix.h +101 -0
  188. data/src/core/iomgr/workqueue.h +85 -0
  189. data/src/core/iomgr/workqueue_posix.c +143 -0
  190. data/src/core/iomgr/workqueue_posix.h +51 -0
  191. data/src/core/iomgr/workqueue_windows.c +40 -0
  192. data/src/core/iomgr/workqueue_windows.h +37 -0
  193. data/src/core/json/json.c +64 -0
  194. data/src/core/json/json.h +88 -0
  195. data/src/core/json/json_common.h +49 -0
  196. data/src/core/json/json_reader.c +660 -0
  197. data/src/core/json/json_reader.h +160 -0
  198. data/src/core/json/json_string.c +379 -0
  199. data/src/core/json/json_writer.c +260 -0
  200. data/src/core/json/json_writer.h +97 -0
  201. data/src/core/profiling/basic_timers.c +274 -0
  202. data/src/core/profiling/stap_timers.c +65 -0
  203. data/src/core/profiling/timers.h +119 -0
  204. data/src/core/security/auth_filters.h +42 -0
  205. data/src/core/security/base64.c +233 -0
  206. data/src/core/security/base64.h +52 -0
  207. data/src/core/security/client_auth_filter.c +337 -0
  208. data/src/core/security/credentials.c +1273 -0
  209. data/src/core/security/credentials.h +376 -0
  210. data/src/core/security/credentials_metadata.c +101 -0
  211. data/src/core/security/credentials_posix.c +61 -0
  212. data/src/core/security/credentials_win32.c +61 -0
  213. data/src/core/security/google_default_credentials.c +260 -0
  214. data/src/core/security/handshake.c +327 -0
  215. data/src/core/security/handshake.h +50 -0
  216. data/src/core/security/json_token.c +405 -0
  217. data/src/core/security/json_token.h +118 -0
  218. data/src/core/security/jwt_verifier.c +842 -0
  219. data/src/core/security/jwt_verifier.h +136 -0
  220. data/src/core/security/secure_endpoint.c +383 -0
  221. data/src/core/security/secure_endpoint.h +49 -0
  222. data/src/core/security/security_connector.c +756 -0
  223. data/src/core/security/security_connector.h +246 -0
  224. data/src/core/security/security_context.c +342 -0
  225. data/src/core/security/security_context.h +114 -0
  226. data/src/core/security/server_auth_filter.c +264 -0
  227. data/src/core/security/server_secure_chttp2.c +268 -0
  228. data/src/core/statistics/census_interface.h +76 -0
  229. data/src/core/statistics/census_rpc_stats.h +101 -0
  230. data/src/core/support/alloc.c +90 -0
  231. data/src/core/support/avl.c +288 -0
  232. data/src/core/support/block_annotate.h +48 -0
  233. data/src/core/support/cmdline.c +347 -0
  234. data/src/core/support/cpu_iphone.c +49 -0
  235. data/src/core/support/cpu_linux.c +78 -0
  236. data/src/core/support/cpu_posix.c +77 -0
  237. data/src/core/support/cpu_windows.c +47 -0
  238. data/src/core/support/env.h +60 -0
  239. data/src/core/support/env_linux.c +62 -0
  240. data/src/core/support/env_posix.c +57 -0
  241. data/src/core/support/env_win32.c +65 -0
  242. data/src/core/support/file.c +91 -0
  243. data/src/core/support/file.h +63 -0
  244. data/src/core/support/file_posix.c +85 -0
  245. data/src/core/support/file_win32.c +84 -0
  246. data/src/core/support/histogram.c +244 -0
  247. data/src/core/support/host_port.c +110 -0
  248. data/src/core/support/log.c +66 -0
  249. data/src/core/support/log_android.c +87 -0
  250. data/src/core/support/log_linux.c +105 -0
  251. data/src/core/support/log_posix.c +102 -0
  252. data/src/core/support/log_win32.c +125 -0
  253. data/src/core/support/murmur_hash.c +96 -0
  254. data/src/core/support/murmur_hash.h +44 -0
  255. data/src/core/support/slice.c +343 -0
  256. data/src/core/support/slice_buffer.c +282 -0
  257. data/src/core/support/stack_lockfree.c +175 -0
  258. data/src/core/support/stack_lockfree.h +53 -0
  259. data/src/core/support/string.c +296 -0
  260. data/src/core/support/string.h +121 -0
  261. data/src/core/support/string_posix.c +86 -0
  262. data/src/core/support/string_win32.c +109 -0
  263. data/src/core/support/string_win32.h +47 -0
  264. data/src/core/support/subprocess_posix.c +112 -0
  265. data/src/core/support/sync.c +122 -0
  266. data/src/core/support/sync_posix.c +104 -0
  267. data/src/core/support/sync_win32.c +128 -0
  268. data/src/core/support/thd.c +64 -0
  269. data/src/core/support/thd_internal.h +39 -0
  270. data/src/core/support/thd_posix.c +94 -0
  271. data/src/core/support/thd_win32.c +117 -0
  272. data/src/core/support/time.c +304 -0
  273. data/src/core/support/time_posix.c +161 -0
  274. data/src/core/support/time_precise.c +89 -0
  275. data/src/core/support/time_precise.h +42 -0
  276. data/src/core/support/time_win32.c +101 -0
  277. data/src/core/support/tls_pthread.c +45 -0
  278. data/src/core/surface/api_trace.c +36 -0
  279. data/src/core/surface/api_trace.h +65 -0
  280. data/src/core/surface/byte_buffer.c +97 -0
  281. data/src/core/surface/byte_buffer_reader.c +123 -0
  282. data/src/core/surface/call.c +1424 -0
  283. data/src/core/surface/call.h +109 -0
  284. data/src/core/surface/call_details.c +50 -0
  285. data/src/core/surface/call_log_batch.c +118 -0
  286. data/src/core/surface/call_test_only.h +64 -0
  287. data/src/core/surface/channel.c +327 -0
  288. data/src/core/surface/channel.h +74 -0
  289. data/src/core/surface/channel_connectivity.c +220 -0
  290. data/src/core/surface/channel_create.c +235 -0
  291. data/src/core/surface/channel_ping.c +79 -0
  292. data/src/core/surface/completion_queue.c +481 -0
  293. data/src/core/surface/completion_queue.h +91 -0
  294. data/src/core/surface/event_string.c +81 -0
  295. data/src/core/surface/event_string.h +42 -0
  296. data/src/core/surface/init.c +168 -0
  297. data/src/core/surface/init.h +40 -0
  298. data/src/core/surface/init_secure.c +42 -0
  299. data/src/core/surface/lame_client.c +149 -0
  300. data/src/core/surface/metadata_array.c +49 -0
  301. data/src/core/surface/secure_channel_create.c +336 -0
  302. data/src/core/surface/server.c +1343 -0
  303. data/src/core/surface/server.h +67 -0
  304. data/src/core/surface/server_chttp2.c +149 -0
  305. data/src/core/surface/server_create.c +51 -0
  306. data/src/core/surface/surface_trace.h +48 -0
  307. data/src/core/surface/validate_metadata.c +73 -0
  308. data/src/core/surface/version.c +39 -0
  309. data/src/core/transport/byte_stream.c +76 -0
  310. data/src/core/transport/byte_stream.h +88 -0
  311. data/src/core/transport/chttp2/alpn.c +56 -0
  312. data/src/core/transport/chttp2/alpn.h +49 -0
  313. data/src/core/transport/chttp2/bin_encoder.c +285 -0
  314. data/src/core/transport/chttp2/bin_encoder.h +54 -0
  315. data/src/core/transport/chttp2/frame.h +69 -0
  316. data/src/core/transport/chttp2/frame_data.c +245 -0
  317. data/src/core/transport/chttp2/frame_data.h +101 -0
  318. data/src/core/transport/chttp2/frame_goaway.c +193 -0
  319. data/src/core/transport/chttp2/frame_goaway.h +77 -0
  320. data/src/core/transport/chttp2/frame_ping.c +97 -0
  321. data/src/core/transport/chttp2/frame_ping.h +56 -0
  322. data/src/core/transport/chttp2/frame_rst_stream.c +100 -0
  323. data/src/core/transport/chttp2/frame_rst_stream.h +55 -0
  324. data/src/core/transport/chttp2/frame_settings.c +259 -0
  325. data/src/core/transport/chttp2/frame_settings.h +103 -0
  326. data/src/core/transport/chttp2/frame_window_update.c +114 -0
  327. data/src/core/transport/chttp2/frame_window_update.h +58 -0
  328. data/src/core/transport/chttp2/hpack_encoder.c +572 -0
  329. data/src/core/transport/chttp2/hpack_encoder.h +95 -0
  330. data/src/core/transport/chttp2/hpack_parser.c +1449 -0
  331. data/src/core/transport/chttp2/hpack_parser.h +116 -0
  332. data/src/core/transport/chttp2/hpack_table.c +361 -0
  333. data/src/core/transport/chttp2/hpack_table.h +108 -0
  334. data/src/core/transport/chttp2/http2_errors.h +56 -0
  335. data/src/core/transport/chttp2/huffsyms.c +297 -0
  336. data/src/core/transport/chttp2/huffsyms.h +48 -0
  337. data/src/core/transport/chttp2/incoming_metadata.c +96 -0
  338. data/src/core/transport/chttp2/incoming_metadata.h +60 -0
  339. data/src/core/transport/chttp2/internal.h +757 -0
  340. data/src/core/transport/chttp2/parsing.c +866 -0
  341. data/src/core/transport/chttp2/status_conversion.c +109 -0
  342. data/src/core/transport/chttp2/status_conversion.h +50 -0
  343. data/src/core/transport/chttp2/stream_lists.c +401 -0
  344. data/src/core/transport/chttp2/stream_map.c +198 -0
  345. data/src/core/transport/chttp2/stream_map.h +85 -0
  346. data/src/core/transport/chttp2/timeout_encoding.c +185 -0
  347. data/src/core/transport/chttp2/timeout_encoding.h +47 -0
  348. data/src/core/transport/chttp2/varint.c +66 -0
  349. data/src/core/transport/chttp2/varint.h +76 -0
  350. data/src/core/transport/chttp2/writing.c +356 -0
  351. data/src/core/transport/chttp2_transport.c +1692 -0
  352. data/src/core/transport/chttp2_transport.h +51 -0
  353. data/src/core/transport/connectivity_state.c +164 -0
  354. data/src/core/transport/connectivity_state.h +85 -0
  355. data/src/core/transport/metadata.c +690 -0
  356. data/src/core/transport/metadata.h +156 -0
  357. data/src/core/transport/metadata_batch.c +194 -0
  358. data/src/core/transport/metadata_batch.h +125 -0
  359. data/src/core/transport/static_metadata.c +90 -0
  360. data/src/core/transport/static_metadata.h +408 -0
  361. data/src/core/transport/transport.c +183 -0
  362. data/src/core/transport/transport.h +222 -0
  363. data/src/core/transport/transport_impl.h +78 -0
  364. data/src/core/transport/transport_op_string.c +140 -0
  365. data/src/core/tsi/fake_transport_security.c +525 -0
  366. data/src/core/tsi/fake_transport_security.h +61 -0
  367. data/src/core/tsi/ssl_transport_security.c +1467 -0
  368. data/src/core/tsi/ssl_transport_security.h +173 -0
  369. data/src/core/tsi/transport_security.c +284 -0
  370. data/src/core/tsi/transport_security.h +111 -0
  371. data/src/core/tsi/transport_security_interface.h +344 -0
  372. data/src/ruby/bin/apis/google/protobuf/empty.rb +44 -0
  373. data/src/ruby/bin/apis/pubsub_demo.rb +256 -0
  374. data/src/ruby/bin/apis/tech/pubsub/proto/pubsub.rb +174 -0
  375. data/src/ruby/bin/apis/tech/pubsub/proto/pubsub_services.rb +103 -0
  376. data/src/ruby/bin/grpc_ruby_interop_client +33 -0
  377. data/src/ruby/bin/grpc_ruby_interop_server +33 -0
  378. data/src/ruby/bin/interop/interop_client.rb +51 -0
  379. data/src/ruby/bin/interop/interop_server.rb +50 -0
  380. data/src/ruby/bin/math.rb +32 -0
  381. data/src/ruby/bin/math_client.rb +147 -0
  382. data/src/ruby/bin/math_server.rb +206 -0
  383. data/src/ruby/bin/math_services.rb +27 -0
  384. data/src/ruby/bin/noproto_client.rb +108 -0
  385. data/src/ruby/bin/noproto_server.rb +112 -0
  386. data/src/ruby/ext/grpc/extconf.rb +92 -0
  387. data/src/ruby/ext/grpc/rb_byte_buffer.c +75 -0
  388. data/src/ruby/ext/grpc/rb_byte_buffer.h +47 -0
  389. data/src/ruby/ext/grpc/rb_call.c +915 -0
  390. data/src/ruby/ext/grpc/rb_call.h +66 -0
  391. data/src/ruby/ext/grpc/rb_call_credentials.c +315 -0
  392. data/src/ruby/ext/grpc/rb_call_credentials.h +46 -0
  393. data/src/ruby/ext/grpc/rb_channel.c +430 -0
  394. data/src/ruby/ext/grpc/rb_channel.h +47 -0
  395. data/src/ruby/ext/grpc/rb_channel_args.c +167 -0
  396. data/src/ruby/ext/grpc/rb_channel_args.h +53 -0
  397. data/src/ruby/ext/grpc/rb_channel_credentials.c +266 -0
  398. data/src/ruby/ext/grpc/rb_channel_credentials.h +47 -0
  399. data/src/ruby/ext/grpc/rb_completion_queue.c +181 -0
  400. data/src/ruby/ext/grpc/rb_completion_queue.h +55 -0
  401. data/src/ruby/ext/grpc/rb_event_thread.c +153 -0
  402. data/src/ruby/ext/grpc/rb_event_thread.h +37 -0
  403. data/src/ruby/ext/grpc/rb_grpc.c +328 -0
  404. data/src/ruby/ext/grpc/rb_grpc.h +85 -0
  405. data/src/ruby/ext/grpc/rb_server.c +398 -0
  406. data/src/ruby/ext/grpc/rb_server.h +47 -0
  407. data/src/ruby/ext/grpc/rb_server_credentials.c +282 -0
  408. data/src/ruby/ext/grpc/rb_server_credentials.h +47 -0
  409. data/src/ruby/lib/grpc/core/time_consts.rb +71 -0
  410. data/src/ruby/lib/grpc/errors.rb +62 -0
  411. data/src/ruby/lib/grpc/generic/active_call.rb +488 -0
  412. data/src/ruby/lib/grpc/generic/bidi_call.rb +218 -0
  413. data/src/ruby/lib/grpc/generic/client_stub.rb +471 -0
  414. data/src/ruby/lib/grpc/generic/rpc_desc.rb +147 -0
  415. data/src/ruby/lib/grpc/generic/rpc_server.rb +504 -0
  416. data/src/ruby/lib/grpc/generic/service.rb +234 -0
  417. data/src/ruby/lib/grpc/logconfig.rb +59 -0
  418. data/src/ruby/lib/grpc/notifier.rb +60 -0
  419. data/src/ruby/lib/grpc/version.rb +33 -0
  420. data/src/ruby/lib/grpc.rb +44 -0
  421. data/src/ruby/pb/README.md +42 -0
  422. data/src/ruby/pb/generate_proto_ruby.sh +51 -0
  423. data/src/ruby/pb/grpc/health/checker.rb +75 -0
  424. data/src/ruby/pb/grpc/health/v1alpha/health.rb +29 -0
  425. data/src/ruby/pb/grpc/health/v1alpha/health_services.rb +28 -0
  426. data/src/ruby/pb/test/client.rb +469 -0
  427. data/src/ruby/pb/test/proto/empty.rb +15 -0
  428. data/src/ruby/pb/test/proto/messages.rb +80 -0
  429. data/src/ruby/pb/test/proto/test.rb +14 -0
  430. data/src/ruby/pb/test/proto/test_services.rb +64 -0
  431. data/src/ruby/pb/test/server.rb +253 -0
  432. data/src/ruby/spec/call_credentials_spec.rb +57 -0
  433. data/src/ruby/spec/call_spec.rb +163 -0
  434. data/src/ruby/spec/channel_credentials_spec.rb +97 -0
  435. data/src/ruby/spec/channel_spec.rb +177 -0
  436. data/src/ruby/spec/client_server_spec.rb +475 -0
  437. data/src/ruby/spec/completion_queue_spec.rb +42 -0
  438. data/src/ruby/spec/generic/active_call_spec.rb +373 -0
  439. data/src/ruby/spec/generic/client_stub_spec.rb +476 -0
  440. data/src/ruby/spec/generic/rpc_desc_spec.rb +331 -0
  441. data/src/ruby/spec/generic/rpc_server_pool_spec.rb +138 -0
  442. data/src/ruby/spec/generic/rpc_server_spec.rb +576 -0
  443. data/src/ruby/spec/generic/service_spec.rb +345 -0
  444. data/src/ruby/spec/pb/health/checker_spec.rb +232 -0
  445. data/src/ruby/spec/server_credentials_spec.rb +94 -0
  446. data/src/ruby/spec/server_spec.rb +209 -0
  447. data/src/ruby/spec/spec_helper.rb +69 -0
  448. data/src/ruby/spec/testdata/README +1 -0
  449. data/src/ruby/spec/testdata/ca.pem +15 -0
  450. data/src/ruby/spec/testdata/server1.key +16 -0
  451. data/src/ruby/spec/testdata/server1.pem +16 -0
  452. data/src/ruby/spec/time_consts_spec.rb +89 -0
  453. metadata +665 -0
@@ -0,0 +1,1449 @@
1
+ /*
2
+ *
3
+ * Copyright 2015-2016, Google Inc.
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions are
8
+ * met:
9
+ *
10
+ * * Redistributions of source code must retain the above copyright
11
+ * notice, this list of conditions and the following disclaimer.
12
+ * * Redistributions in binary form must reproduce the above
13
+ * copyright notice, this list of conditions and the following disclaimer
14
+ * in the documentation and/or other materials provided with the
15
+ * distribution.
16
+ * * Neither the name of Google Inc. nor the names of its
17
+ * contributors may be used to endorse or promote products derived from
18
+ * this software without specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ *
32
+ */
33
+
34
+ #include "src/core/transport/chttp2/hpack_parser.h"
35
+ #include "src/core/transport/chttp2/internal.h"
36
+
37
+ #include <stddef.h>
38
+ #include <string.h>
39
+ #include <assert.h>
40
+
41
+ /* This is here for grpc_is_binary_header
42
+ * TODO(murgatroid99): Remove this
43
+ */
44
+ #include <grpc/grpc.h>
45
+
46
+ #include <grpc/support/alloc.h>
47
+ #include <grpc/support/log.h>
48
+ #include <grpc/support/port_platform.h>
49
+ #include <grpc/support/useful.h>
50
+
51
+ #include "src/core/profiling/timers.h"
52
+ #include "src/core/support/string.h"
53
+ #include "src/core/transport/chttp2/bin_encoder.h"
54
+
55
+ typedef enum {
56
+ NOT_BINARY,
57
+ B64_BYTE0,
58
+ B64_BYTE1,
59
+ B64_BYTE2,
60
+ B64_BYTE3
61
+ } binary_state;
62
+
63
+ /* How parsing works:
64
+
65
+ The parser object keeps track of a function pointer which represents the
66
+ current parse state.
67
+
68
+ Each time new bytes are presented, we call into the current state, which
69
+ recursively parses until all bytes in the given chunk are exhausted.
70
+
71
+ The parse state that terminates then saves its function pointer to be the
72
+ current state so that it can resume when more bytes are available.
73
+
74
+ It's expected that most optimizing compilers will turn this code into
75
+ a set of indirect jumps, and so not waste stack space. */
76
+
77
+ /* forward declarations for parsing states */
78
+ static int parse_begin(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
79
+ const gpr_uint8 *end);
80
+ static int parse_error(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
81
+ const gpr_uint8 *end);
82
+ static int parse_illegal_op(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
83
+ const gpr_uint8 *end);
84
+
85
+ static int parse_string_prefix(grpc_chttp2_hpack_parser *p,
86
+ const gpr_uint8 *cur, const gpr_uint8 *end);
87
+ static int parse_key_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
88
+ const gpr_uint8 *end);
89
+ static int parse_value_string_with_indexed_key(grpc_chttp2_hpack_parser *p,
90
+ const gpr_uint8 *cur,
91
+ const gpr_uint8 *end);
92
+ static int parse_value_string_with_literal_key(grpc_chttp2_hpack_parser *p,
93
+ const gpr_uint8 *cur,
94
+ const gpr_uint8 *end);
95
+
96
+ static int parse_value0(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
97
+ const gpr_uint8 *end);
98
+ static int parse_value1(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
99
+ const gpr_uint8 *end);
100
+ static int parse_value2(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
101
+ const gpr_uint8 *end);
102
+ static int parse_value3(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
103
+ const gpr_uint8 *end);
104
+ static int parse_value4(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
105
+ const gpr_uint8 *end);
106
+ static int parse_value5up(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
107
+ const gpr_uint8 *end);
108
+
109
+ static int parse_indexed_field(grpc_chttp2_hpack_parser *p,
110
+ const gpr_uint8 *cur, const gpr_uint8 *end);
111
+ static int parse_indexed_field_x(grpc_chttp2_hpack_parser *p,
112
+ const gpr_uint8 *cur, const gpr_uint8 *end);
113
+ static int parse_lithdr_incidx(grpc_chttp2_hpack_parser *p,
114
+ const gpr_uint8 *cur, const gpr_uint8 *end);
115
+ static int parse_lithdr_incidx_x(grpc_chttp2_hpack_parser *p,
116
+ const gpr_uint8 *cur, const gpr_uint8 *end);
117
+ static int parse_lithdr_incidx_v(grpc_chttp2_hpack_parser *p,
118
+ const gpr_uint8 *cur, const gpr_uint8 *end);
119
+ static int parse_lithdr_notidx(grpc_chttp2_hpack_parser *p,
120
+ const gpr_uint8 *cur, const gpr_uint8 *end);
121
+ static int parse_lithdr_notidx_x(grpc_chttp2_hpack_parser *p,
122
+ const gpr_uint8 *cur, const gpr_uint8 *end);
123
+ static int parse_lithdr_notidx_v(grpc_chttp2_hpack_parser *p,
124
+ const gpr_uint8 *cur, const gpr_uint8 *end);
125
+ static int parse_lithdr_nvridx(grpc_chttp2_hpack_parser *p,
126
+ const gpr_uint8 *cur, const gpr_uint8 *end);
127
+ static int parse_lithdr_nvridx_x(grpc_chttp2_hpack_parser *p,
128
+ const gpr_uint8 *cur, const gpr_uint8 *end);
129
+ static int parse_lithdr_nvridx_v(grpc_chttp2_hpack_parser *p,
130
+ const gpr_uint8 *cur, const gpr_uint8 *end);
131
+ static int parse_max_tbl_size(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
132
+ const gpr_uint8 *end);
133
+ static int parse_max_tbl_size_x(grpc_chttp2_hpack_parser *p,
134
+ const gpr_uint8 *cur, const gpr_uint8 *end);
135
+
136
+ /* we translate the first byte of a hpack field into one of these decoding
137
+ cases, then use a lookup table to jump directly to the appropriate parser.
138
+
139
+ _X => the integer index is all ones, meaning we need to do varint decoding
140
+ _V => the integer index is all zeros, meaning we need to decode an additional
141
+ string value */
142
+ typedef enum {
143
+ INDEXED_FIELD,
144
+ INDEXED_FIELD_X,
145
+ LITHDR_INCIDX,
146
+ LITHDR_INCIDX_X,
147
+ LITHDR_INCIDX_V,
148
+ LITHDR_NOTIDX,
149
+ LITHDR_NOTIDX_X,
150
+ LITHDR_NOTIDX_V,
151
+ LITHDR_NVRIDX,
152
+ LITHDR_NVRIDX_X,
153
+ LITHDR_NVRIDX_V,
154
+ MAX_TBL_SIZE,
155
+ MAX_TBL_SIZE_X,
156
+ ILLEGAL
157
+ } first_byte_type;
158
+
159
+ /* jump table of parse state functions -- order must match first_byte_type
160
+ above */
161
+ static const grpc_chttp2_hpack_parser_state first_byte_action[] = {
162
+ parse_indexed_field, parse_indexed_field_x, parse_lithdr_incidx,
163
+ parse_lithdr_incidx_x, parse_lithdr_incidx_v, parse_lithdr_notidx,
164
+ parse_lithdr_notidx_x, parse_lithdr_notidx_v, parse_lithdr_nvridx,
165
+ parse_lithdr_nvridx_x, parse_lithdr_nvridx_v, parse_max_tbl_size,
166
+ parse_max_tbl_size_x, parse_illegal_op};
167
+
168
+ /* indexes the first byte to a parse state function - generated by
169
+ gen_hpack_tables.c */
170
+ static const gpr_uint8 first_byte_lut[256] = {
171
+ LITHDR_NOTIDX_V, LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX,
172
+ LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX,
173
+ LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX,
174
+ LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX_X,
175
+ LITHDR_NVRIDX_V, LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX,
176
+ LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX,
177
+ LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX,
178
+ LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX_X,
179
+ MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE,
180
+ MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE,
181
+ MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE,
182
+ MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE,
183
+ MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE,
184
+ MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE,
185
+ MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE,
186
+ MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE_X,
187
+ LITHDR_INCIDX_V, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
188
+ LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
189
+ LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
190
+ LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
191
+ LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
192
+ LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
193
+ LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
194
+ LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
195
+ LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
196
+ LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
197
+ LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
198
+ LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
199
+ LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
200
+ LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
201
+ LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
202
+ LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX_X,
203
+ ILLEGAL, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
204
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
205
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
206
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
207
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
208
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
209
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
210
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
211
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
212
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
213
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
214
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
215
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
216
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
217
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
218
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
219
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
220
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
221
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
222
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
223
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
224
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
225
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
226
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
227
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
228
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
229
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
230
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
231
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
232
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
233
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
234
+ INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD_X,
235
+ };
236
+
237
+ /* state table for huffman decoding: given a state, gives an index/16 into
238
+ next_sub_tbl. Taking that index and adding the value of the nibble being
239
+ considered returns the next state.
240
+
241
+ generated by gen_hpack_tables.c */
242
+ static const gpr_uint8 next_tbl[256] = {
243
+ 0, 1, 2, 3, 4, 1, 2, 5, 6, 1, 7, 8, 1, 3, 3, 9, 10, 11, 1, 1,
244
+ 1, 12, 1, 2, 13, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,
245
+ 14, 1, 15, 16, 1, 17, 1, 15, 2, 7, 3, 18, 19, 1, 1, 1, 1, 20, 1, 1,
246
+ 1, 1, 1, 1, 1, 1, 1, 1, 15, 2, 2, 7, 21, 1, 22, 1, 1, 1, 1, 1,
247
+ 1, 1, 1, 15, 2, 2, 2, 2, 2, 2, 23, 24, 25, 1, 1, 1, 1, 2, 2, 2,
248
+ 26, 3, 3, 27, 10, 28, 1, 1, 1, 1, 1, 1, 2, 3, 29, 10, 30, 1, 1, 1,
249
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 31, 1, 1, 1, 1, 1, 1, 1, 2,
250
+ 2, 2, 2, 2, 2, 2, 2, 32, 1, 1, 15, 33, 1, 34, 35, 9, 36, 1, 1, 1,
251
+ 1, 1, 1, 1, 37, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 26, 9,
252
+ 38, 1, 1, 1, 1, 1, 1, 1, 15, 2, 2, 2, 2, 26, 3, 3, 39, 1, 1, 1,
253
+ 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 7, 3, 3, 3, 40, 2,
254
+ 41, 1, 1, 1, 42, 43, 1, 1, 44, 1, 1, 1, 1, 15, 2, 2, 2, 2, 2, 2,
255
+ 3, 3, 3, 45, 46, 1, 1, 2, 2, 2, 35, 3, 3, 18, 47, 2,
256
+ };
257
+
258
+ /* next state, based upon current state and the current nibble: see above.
259
+ generated by gen_hpack_tables.c */
260
+ static const gpr_int16 next_sub_tbl[48 * 16] = {
261
+ 1, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217,
262
+ 218, 2, 6, 10, 13, 14, 15, 16, 17, 2, 6, 10, 13, 14, 15,
263
+ 16, 17, 3, 7, 11, 24, 3, 7, 11, 24, 3, 7, 11, 24, 3,
264
+ 7, 11, 24, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8,
265
+ 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
266
+ 199, 200, 201, 202, 203, 4, 8, 4, 8, 0, 0, 0, 0, 0, 0,
267
+ 0, 0, 0, 0, 0, 0, 9, 133, 134, 135, 136, 137, 138, 139, 140,
268
+ 141, 142, 143, 144, 145, 146, 147, 3, 7, 11, 24, 3, 7, 11, 24,
269
+ 4, 8, 4, 8, 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0,
270
+ 0, 0, 0, 0, 0, 0, 0, 12, 132, 4, 8, 4, 8, 4, 8,
271
+ 4, 8, 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
272
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
273
+ 0, 0, 0, 0, 0, 0, 0, 0, 18, 19, 20, 21, 4, 8, 4,
274
+ 8, 4, 8, 4, 8, 4, 8, 0, 0, 0, 22, 23, 91, 25, 26,
275
+ 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 3,
276
+ 7, 11, 24, 3, 7, 11, 24, 0, 0, 0, 0, 0, 41, 42, 43,
277
+ 2, 6, 10, 13, 14, 15, 16, 17, 3, 7, 11, 24, 3, 7, 11,
278
+ 24, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 0, 0,
279
+ 44, 45, 2, 6, 10, 13, 14, 15, 16, 17, 46, 47, 48, 49, 50,
280
+ 51, 52, 57, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
281
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
282
+ 0, 53, 54, 55, 56, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
283
+ 68, 69, 70, 71, 72, 74, 0, 0, 0, 0, 0, 0, 0, 0, 0,
284
+ 0, 0, 0, 0, 0, 0, 73, 75, 76, 77, 78, 79, 80, 81, 82,
285
+ 83, 84, 85, 86, 87, 88, 89, 90, 3, 7, 11, 24, 3, 7, 11,
286
+ 24, 3, 7, 11, 24, 0, 0, 0, 0, 3, 7, 11, 24, 3, 7,
287
+ 11, 24, 4, 8, 4, 8, 0, 0, 0, 92, 0, 0, 0, 93, 94,
288
+ 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 3, 7, 11, 24,
289
+ 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4,
290
+ 8, 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
291
+ 0, 0, 0, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 4,
292
+ 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 0, 0,
293
+ 0, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130,
294
+ 131, 2, 6, 10, 13, 14, 15, 16, 17, 4, 8, 4, 8, 4, 8,
295
+ 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 148,
296
+ 149, 150, 151, 3, 7, 11, 24, 4, 8, 4, 8, 0, 0, 0, 0,
297
+ 0, 0, 152, 153, 3, 7, 11, 24, 3, 7, 11, 24, 3, 7, 11,
298
+ 24, 154, 155, 156, 164, 3, 7, 11, 24, 3, 7, 11, 24, 3, 7,
299
+ 11, 24, 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
300
+ 157, 158, 159, 160, 161, 162, 163, 165, 166, 167, 168, 169, 170, 171, 172,
301
+ 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187,
302
+ 188, 189, 190, 191, 192, 193, 194, 195, 196, 4, 8, 4, 8, 4, 8,
303
+ 4, 8, 4, 8, 4, 8, 4, 8, 197, 198, 4, 8, 4, 8, 4,
304
+ 8, 4, 8, 0, 0, 0, 0, 0, 0, 219, 220, 3, 7, 11, 24,
305
+ 4, 8, 4, 8, 4, 8, 0, 0, 221, 222, 223, 224, 3, 7, 11,
306
+ 24, 3, 7, 11, 24, 4, 8, 4, 8, 4, 8, 225, 228, 4, 8,
307
+ 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 226, 227, 229,
308
+ 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244,
309
+ 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 0, 0, 0, 0, 0,
310
+ 0, 0, 0, 0, 0, 0, 0, 245, 246, 247, 248, 249, 250, 251, 252,
311
+ 253, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
312
+ 0, 0, 255,
313
+ };
314
+
315
+ /* emission table: indexed like next_tbl, ultimately gives the byte to be
316
+ emitted, or -1 for no byte, or 256 for end of stream
317
+
318
+ generated by gen_hpack_tables.c */
319
+ static const gpr_uint16 emit_tbl[256] = {
320
+ 0, 1, 2, 3, 4, 5, 6, 7, 0, 8, 9, 10, 11, 12, 13,
321
+ 14, 15, 16, 17, 18, 19, 20, 21, 22, 0, 23, 24, 25, 26, 27,
322
+ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
323
+ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 0, 55, 56,
324
+ 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 0,
325
+ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85,
326
+ 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
327
+ 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115,
328
+ 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130,
329
+ 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145,
330
+ 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 0,
331
+ 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174,
332
+ 0, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188,
333
+ 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203,
334
+ 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218,
335
+ 219, 220, 221, 0, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232,
336
+ 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247,
337
+ 248,
338
+ };
339
+
340
+ /* generated by gen_hpack_tables.c */
341
+ static const gpr_int16 emit_sub_tbl[249 * 16] = {
342
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
343
+ -1, 48, 48, 48, 48, 48, 48, 48, 48, 49, 49, 49, 49, 49, 49,
344
+ 49, 49, 48, 48, 48, 48, 49, 49, 49, 49, 50, 50, 50, 50, 97,
345
+ 97, 97, 97, 48, 48, 49, 49, 50, 50, 97, 97, 99, 99, 101, 101,
346
+ 105, 105, 111, 111, 48, 49, 50, 97, 99, 101, 105, 111, 115, 116, -1,
347
+ -1, -1, -1, -1, -1, 32, 32, 32, 32, 32, 32, 32, 32, 37, 37,
348
+ 37, 37, 37, 37, 37, 37, 99, 99, 99, 99, 101, 101, 101, 101, 105,
349
+ 105, 105, 105, 111, 111, 111, 111, 115, 115, 116, 116, 32, 37, 45, 46,
350
+ 47, 51, 52, 53, 54, 55, 56, 57, 61, 61, 61, 61, 61, 61, 61,
351
+ 61, 65, 65, 65, 65, 65, 65, 65, 65, 115, 115, 115, 115, 116, 116,
352
+ 116, 116, 32, 32, 37, 37, 45, 45, 46, 46, 61, 65, 95, 98, 100,
353
+ 102, 103, 104, 108, 109, 110, 112, 114, 117, -1, -1, 58, 58, 58, 58,
354
+ 58, 58, 58, 58, 66, 66, 66, 66, 66, 66, 66, 66, 47, 47, 51,
355
+ 51, 52, 52, 53, 53, 54, 54, 55, 55, 56, 56, 57, 57, 61, 61,
356
+ 65, 65, 95, 95, 98, 98, 100, 100, 102, 102, 103, 103, 104, 104, 108,
357
+ 108, 109, 109, 110, 110, 112, 112, 114, 114, 117, 117, 58, 66, 67, 68,
358
+ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
359
+ 84, 85, 86, 87, 89, 106, 107, 113, 118, 119, 120, 121, 122, -1, -1,
360
+ -1, -1, 38, 38, 38, 38, 38, 38, 38, 38, 42, 42, 42, 42, 42,
361
+ 42, 42, 42, 44, 44, 44, 44, 44, 44, 44, 44, 59, 59, 59, 59,
362
+ 59, 59, 59, 59, 88, 88, 88, 88, 88, 88, 88, 88, 90, 90, 90,
363
+ 90, 90, 90, 90, 90, 33, 33, 34, 34, 40, 40, 41, 41, 63, 63,
364
+ 39, 43, 124, -1, -1, -1, 35, 35, 35, 35, 35, 35, 35, 35, 62,
365
+ 62, 62, 62, 62, 62, 62, 62, 0, 0, 0, 0, 36, 36, 36, 36,
366
+ 64, 64, 64, 64, 91, 91, 91, 91, 69, 69, 69, 69, 69, 69, 69,
367
+ 69, 70, 70, 70, 70, 70, 70, 70, 70, 71, 71, 71, 71, 71, 71,
368
+ 71, 71, 72, 72, 72, 72, 72, 72, 72, 72, 73, 73, 73, 73, 73,
369
+ 73, 73, 73, 74, 74, 74, 74, 74, 74, 74, 74, 75, 75, 75, 75,
370
+ 75, 75, 75, 75, 76, 76, 76, 76, 76, 76, 76, 76, 77, 77, 77,
371
+ 77, 77, 77, 77, 77, 78, 78, 78, 78, 78, 78, 78, 78, 79, 79,
372
+ 79, 79, 79, 79, 79, 79, 80, 80, 80, 80, 80, 80, 80, 80, 81,
373
+ 81, 81, 81, 81, 81, 81, 81, 82, 82, 82, 82, 82, 82, 82, 82,
374
+ 83, 83, 83, 83, 83, 83, 83, 83, 84, 84, 84, 84, 84, 84, 84,
375
+ 84, 85, 85, 85, 85, 85, 85, 85, 85, 86, 86, 86, 86, 86, 86,
376
+ 86, 86, 87, 87, 87, 87, 87, 87, 87, 87, 89, 89, 89, 89, 89,
377
+ 89, 89, 89, 106, 106, 106, 106, 106, 106, 106, 106, 107, 107, 107, 107,
378
+ 107, 107, 107, 107, 113, 113, 113, 113, 113, 113, 113, 113, 118, 118, 118,
379
+ 118, 118, 118, 118, 118, 119, 119, 119, 119, 119, 119, 119, 119, 120, 120,
380
+ 120, 120, 120, 120, 120, 120, 121, 121, 121, 121, 121, 121, 121, 121, 122,
381
+ 122, 122, 122, 122, 122, 122, 122, 38, 38, 38, 38, 42, 42, 42, 42,
382
+ 44, 44, 44, 44, 59, 59, 59, 59, 88, 88, 88, 88, 90, 90, 90,
383
+ 90, 33, 34, 40, 41, 63, -1, -1, -1, 39, 39, 39, 39, 39, 39,
384
+ 39, 39, 43, 43, 43, 43, 43, 43, 43, 43, 124, 124, 124, 124, 124,
385
+ 124, 124, 124, 35, 35, 35, 35, 62, 62, 62, 62, 0, 0, 36, 36,
386
+ 64, 64, 91, 91, 93, 93, 126, 126, 94, 125, -1, -1, 60, 60, 60,
387
+ 60, 60, 60, 60, 60, 96, 96, 96, 96, 96, 96, 96, 96, 123, 123,
388
+ 123, 123, 123, 123, 123, 123, -1, -1, -1, -1, -1, -1, -1, -1, 92,
389
+ 92, 92, 92, 92, 92, 92, 92, 195, 195, 195, 195, 195, 195, 195, 195,
390
+ 208, 208, 208, 208, 208, 208, 208, 208, 128, 128, 128, 128, 130, 130, 130,
391
+ 130, 131, 131, 131, 131, 162, 162, 162, 162, 184, 184, 184, 184, 194, 194,
392
+ 194, 194, 224, 224, 224, 224, 226, 226, 226, 226, 153, 153, 161, 161, 167,
393
+ 167, 172, 172, 176, 176, 177, 177, 179, 179, 209, 209, 216, 216, 217, 217,
394
+ 227, 227, 229, 229, 230, 230, 129, 132, 133, 134, 136, 146, 154, 156, 160,
395
+ 163, 164, 169, 170, 173, 178, 181, 185, 186, 187, 189, 190, 196, 198, 228,
396
+ 232, 233, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 135,
397
+ 135, 135, 135, 135, 135, 135, 135, 137, 137, 137, 137, 137, 137, 137, 137,
398
+ 138, 138, 138, 138, 138, 138, 138, 138, 139, 139, 139, 139, 139, 139, 139,
399
+ 139, 140, 140, 140, 140, 140, 140, 140, 140, 141, 141, 141, 141, 141, 141,
400
+ 141, 141, 143, 143, 143, 143, 143, 143, 143, 143, 147, 147, 147, 147, 147,
401
+ 147, 147, 147, 149, 149, 149, 149, 149, 149, 149, 149, 150, 150, 150, 150,
402
+ 150, 150, 150, 150, 151, 151, 151, 151, 151, 151, 151, 151, 152, 152, 152,
403
+ 152, 152, 152, 152, 152, 155, 155, 155, 155, 155, 155, 155, 155, 157, 157,
404
+ 157, 157, 157, 157, 157, 157, 158, 158, 158, 158, 158, 158, 158, 158, 165,
405
+ 165, 165, 165, 165, 165, 165, 165, 166, 166, 166, 166, 166, 166, 166, 166,
406
+ 168, 168, 168, 168, 168, 168, 168, 168, 174, 174, 174, 174, 174, 174, 174,
407
+ 174, 175, 175, 175, 175, 175, 175, 175, 175, 180, 180, 180, 180, 180, 180,
408
+ 180, 180, 182, 182, 182, 182, 182, 182, 182, 182, 183, 183, 183, 183, 183,
409
+ 183, 183, 183, 188, 188, 188, 188, 188, 188, 188, 188, 191, 191, 191, 191,
410
+ 191, 191, 191, 191, 197, 197, 197, 197, 197, 197, 197, 197, 231, 231, 231,
411
+ 231, 231, 231, 231, 231, 239, 239, 239, 239, 239, 239, 239, 239, 9, 9,
412
+ 9, 9, 142, 142, 142, 142, 144, 144, 144, 144, 145, 145, 145, 145, 148,
413
+ 148, 148, 148, 159, 159, 159, 159, 171, 171, 171, 171, 206, 206, 206, 206,
414
+ 215, 215, 215, 215, 225, 225, 225, 225, 236, 236, 236, 236, 237, 237, 237,
415
+ 237, 199, 199, 207, 207, 234, 234, 235, 235, 192, 193, 200, 201, 202, 205,
416
+ 210, 213, 218, 219, 238, 240, 242, 243, 255, -1, 203, 203, 203, 203, 203,
417
+ 203, 203, 203, 204, 204, 204, 204, 204, 204, 204, 204, 211, 211, 211, 211,
418
+ 211, 211, 211, 211, 212, 212, 212, 212, 212, 212, 212, 212, 214, 214, 214,
419
+ 214, 214, 214, 214, 214, 221, 221, 221, 221, 221, 221, 221, 221, 222, 222,
420
+ 222, 222, 222, 222, 222, 222, 223, 223, 223, 223, 223, 223, 223, 223, 241,
421
+ 241, 241, 241, 241, 241, 241, 241, 244, 244, 244, 244, 244, 244, 244, 244,
422
+ 245, 245, 245, 245, 245, 245, 245, 245, 246, 246, 246, 246, 246, 246, 246,
423
+ 246, 247, 247, 247, 247, 247, 247, 247, 247, 248, 248, 248, 248, 248, 248,
424
+ 248, 248, 250, 250, 250, 250, 250, 250, 250, 250, 251, 251, 251, 251, 251,
425
+ 251, 251, 251, 252, 252, 252, 252, 252, 252, 252, 252, 253, 253, 253, 253,
426
+ 253, 253, 253, 253, 254, 254, 254, 254, 254, 254, 254, 254, 2, 2, 2,
427
+ 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6,
428
+ 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 11, 11, 11, 11, 12,
429
+ 12, 12, 12, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16,
430
+ 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20,
431
+ 20, 21, 21, 21, 21, 23, 23, 23, 23, 24, 24, 24, 24, 25, 25,
432
+ 25, 25, 26, 26, 26, 26, 27, 27, 27, 27, 28, 28, 28, 28, 29,
433
+ 29, 29, 29, 30, 30, 30, 30, 31, 31, 31, 31, 127, 127, 127, 127,
434
+ 220, 220, 220, 220, 249, 249, 249, 249, 10, 13, 22, 256, 93, 93, 93,
435
+ 93, 126, 126, 126, 126, 94, 94, 125, 125, 60, 96, 123, -1, 92, 195,
436
+ 208, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 128,
437
+ 128, 128, 128, 128, 128, 128, 128, 130, 130, 130, 130, 130, 130, 130, 130,
438
+ 131, 131, 131, 131, 131, 131, 131, 131, 162, 162, 162, 162, 162, 162, 162,
439
+ 162, 184, 184, 184, 184, 184, 184, 184, 184, 194, 194, 194, 194, 194, 194,
440
+ 194, 194, 224, 224, 224, 224, 224, 224, 224, 224, 226, 226, 226, 226, 226,
441
+ 226, 226, 226, 153, 153, 153, 153, 161, 161, 161, 161, 167, 167, 167, 167,
442
+ 172, 172, 172, 172, 176, 176, 176, 176, 177, 177, 177, 177, 179, 179, 179,
443
+ 179, 209, 209, 209, 209, 216, 216, 216, 216, 217, 217, 217, 217, 227, 227,
444
+ 227, 227, 229, 229, 229, 229, 230, 230, 230, 230, 129, 129, 132, 132, 133,
445
+ 133, 134, 134, 136, 136, 146, 146, 154, 154, 156, 156, 160, 160, 163, 163,
446
+ 164, 164, 169, 169, 170, 170, 173, 173, 178, 178, 181, 181, 185, 185, 186,
447
+ 186, 187, 187, 189, 189, 190, 190, 196, 196, 198, 198, 228, 228, 232, 232,
448
+ 233, 233, 1, 135, 137, 138, 139, 140, 141, 143, 147, 149, 150, 151, 152,
449
+ 155, 157, 158, 165, 166, 168, 174, 175, 180, 182, 183, 188, 191, 197, 231,
450
+ 239, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 9, 9, 9,
451
+ 9, 9, 9, 9, 9, 142, 142, 142, 142, 142, 142, 142, 142, 144, 144,
452
+ 144, 144, 144, 144, 144, 144, 145, 145, 145, 145, 145, 145, 145, 145, 148,
453
+ 148, 148, 148, 148, 148, 148, 148, 159, 159, 159, 159, 159, 159, 159, 159,
454
+ 171, 171, 171, 171, 171, 171, 171, 171, 206, 206, 206, 206, 206, 206, 206,
455
+ 206, 215, 215, 215, 215, 215, 215, 215, 215, 225, 225, 225, 225, 225, 225,
456
+ 225, 225, 236, 236, 236, 236, 236, 236, 236, 236, 237, 237, 237, 237, 237,
457
+ 237, 237, 237, 199, 199, 199, 199, 207, 207, 207, 207, 234, 234, 234, 234,
458
+ 235, 235, 235, 235, 192, 192, 193, 193, 200, 200, 201, 201, 202, 202, 205,
459
+ 205, 210, 210, 213, 213, 218, 218, 219, 219, 238, 238, 240, 240, 242, 242,
460
+ 243, 243, 255, 255, 203, 204, 211, 212, 214, 221, 222, 223, 241, 244, 245,
461
+ 246, 247, 248, 250, 251, 252, 253, 254, -1, -1, -1, -1, -1, -1, -1,
462
+ -1, -1, -1, -1, -1, -1, -1, -1, 2, 2, 2, 2, 2, 2, 2,
463
+ 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4,
464
+ 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6,
465
+ 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
466
+ 8, 8, 8, 8, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12,
467
+ 12, 12, 12, 12, 12, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15,
468
+ 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 17,
469
+ 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18,
470
+ 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20,
471
+ 20, 21, 21, 21, 21, 21, 21, 21, 21, 23, 23, 23, 23, 23, 23,
472
+ 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25,
473
+ 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27,
474
+ 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29,
475
+ 29, 29, 29, 29, 29, 30, 30, 30, 30, 30, 30, 30, 30, 31, 31,
476
+ 31, 31, 31, 31, 31, 31, 127, 127, 127, 127, 127, 127, 127, 127, 220,
477
+ 220, 220, 220, 220, 220, 220, 220, 249, 249, 249, 249, 249, 249, 249, 249,
478
+ 10, 10, 13, 13, 22, 22, 256, 256, 67, 67, 67, 67, 67, 67, 67,
479
+ 67, 68, 68, 68, 68, 68, 68, 68, 68, 95, 95, 95, 95, 95, 95,
480
+ 95, 95, 98, 98, 98, 98, 98, 98, 98, 98, 100, 100, 100, 100, 100,
481
+ 100, 100, 100, 102, 102, 102, 102, 102, 102, 102, 102, 103, 103, 103, 103,
482
+ 103, 103, 103, 103, 104, 104, 104, 104, 104, 104, 104, 104, 108, 108, 108,
483
+ 108, 108, 108, 108, 108, 109, 109, 109, 109, 109, 109, 109, 109, 110, 110,
484
+ 110, 110, 110, 110, 110, 110, 112, 112, 112, 112, 112, 112, 112, 112, 114,
485
+ 114, 114, 114, 114, 114, 114, 114, 117, 117, 117, 117, 117, 117, 117, 117,
486
+ 58, 58, 58, 58, 66, 66, 66, 66, 67, 67, 67, 67, 68, 68, 68,
487
+ 68, 69, 69, 69, 69, 70, 70, 70, 70, 71, 71, 71, 71, 72, 72,
488
+ 72, 72, 73, 73, 73, 73, 74, 74, 74, 74, 75, 75, 75, 75, 76,
489
+ 76, 76, 76, 77, 77, 77, 77, 78, 78, 78, 78, 79, 79, 79, 79,
490
+ 80, 80, 80, 80, 81, 81, 81, 81, 82, 82, 82, 82, 83, 83, 83,
491
+ 83, 84, 84, 84, 84, 85, 85, 85, 85, 86, 86, 86, 86, 87, 87,
492
+ 87, 87, 89, 89, 89, 89, 106, 106, 106, 106, 107, 107, 107, 107, 113,
493
+ 113, 113, 113, 118, 118, 118, 118, 119, 119, 119, 119, 120, 120, 120, 120,
494
+ 121, 121, 121, 121, 122, 122, 122, 122, 38, 38, 42, 42, 44, 44, 59,
495
+ 59, 88, 88, 90, 90, -1, -1, -1, -1, 33, 33, 33, 33, 33, 33,
496
+ 33, 33, 34, 34, 34, 34, 34, 34, 34, 34, 40, 40, 40, 40, 40,
497
+ 40, 40, 40, 41, 41, 41, 41, 41, 41, 41, 41, 63, 63, 63, 63,
498
+ 63, 63, 63, 63, 39, 39, 39, 39, 43, 43, 43, 43, 124, 124, 124,
499
+ 124, 35, 35, 62, 62, 0, 36, 64, 91, 93, 126, -1, -1, 94, 94,
500
+ 94, 94, 94, 94, 94, 94, 125, 125, 125, 125, 125, 125, 125, 125, 60,
501
+ 60, 60, 60, 96, 96, 96, 96, 123, 123, 123, 123, -1, -1, -1, -1,
502
+ 92, 92, 92, 92, 195, 195, 195, 195, 208, 208, 208, 208, 128, 128, 130,
503
+ 130, 131, 131, 162, 162, 184, 184, 194, 194, 224, 224, 226, 226, 153, 161,
504
+ 167, 172, 176, 177, 179, 209, 216, 217, 227, 229, 230, -1, -1, -1, -1,
505
+ -1, -1, -1, 129, 129, 129, 129, 129, 129, 129, 129, 132, 132, 132, 132,
506
+ 132, 132, 132, 132, 133, 133, 133, 133, 133, 133, 133, 133, 134, 134, 134,
507
+ 134, 134, 134, 134, 134, 136, 136, 136, 136, 136, 136, 136, 136, 146, 146,
508
+ 146, 146, 146, 146, 146, 146, 154, 154, 154, 154, 154, 154, 154, 154, 156,
509
+ 156, 156, 156, 156, 156, 156, 156, 160, 160, 160, 160, 160, 160, 160, 160,
510
+ 163, 163, 163, 163, 163, 163, 163, 163, 164, 164, 164, 164, 164, 164, 164,
511
+ 164, 169, 169, 169, 169, 169, 169, 169, 169, 170, 170, 170, 170, 170, 170,
512
+ 170, 170, 173, 173, 173, 173, 173, 173, 173, 173, 178, 178, 178, 178, 178,
513
+ 178, 178, 178, 181, 181, 181, 181, 181, 181, 181, 181, 185, 185, 185, 185,
514
+ 185, 185, 185, 185, 186, 186, 186, 186, 186, 186, 186, 186, 187, 187, 187,
515
+ 187, 187, 187, 187, 187, 189, 189, 189, 189, 189, 189, 189, 189, 190, 190,
516
+ 190, 190, 190, 190, 190, 190, 196, 196, 196, 196, 196, 196, 196, 196, 198,
517
+ 198, 198, 198, 198, 198, 198, 198, 228, 228, 228, 228, 228, 228, 228, 228,
518
+ 232, 232, 232, 232, 232, 232, 232, 232, 233, 233, 233, 233, 233, 233, 233,
519
+ 233, 1, 1, 1, 1, 135, 135, 135, 135, 137, 137, 137, 137, 138, 138,
520
+ 138, 138, 139, 139, 139, 139, 140, 140, 140, 140, 141, 141, 141, 141, 143,
521
+ 143, 143, 143, 147, 147, 147, 147, 149, 149, 149, 149, 150, 150, 150, 150,
522
+ 151, 151, 151, 151, 152, 152, 152, 152, 155, 155, 155, 155, 157, 157, 157,
523
+ 157, 158, 158, 158, 158, 165, 165, 165, 165, 166, 166, 166, 166, 168, 168,
524
+ 168, 168, 174, 174, 174, 174, 175, 175, 175, 175, 180, 180, 180, 180, 182,
525
+ 182, 182, 182, 183, 183, 183, 183, 188, 188, 188, 188, 191, 191, 191, 191,
526
+ 197, 197, 197, 197, 231, 231, 231, 231, 239, 239, 239, 239, 9, 9, 142,
527
+ 142, 144, 144, 145, 145, 148, 148, 159, 159, 171, 171, 206, 206, 215, 215,
528
+ 225, 225, 236, 236, 237, 237, 199, 207, 234, 235, 192, 192, 192, 192, 192,
529
+ 192, 192, 192, 193, 193, 193, 193, 193, 193, 193, 193, 200, 200, 200, 200,
530
+ 200, 200, 200, 200, 201, 201, 201, 201, 201, 201, 201, 201, 202, 202, 202,
531
+ 202, 202, 202, 202, 202, 205, 205, 205, 205, 205, 205, 205, 205, 210, 210,
532
+ 210, 210, 210, 210, 210, 210, 213, 213, 213, 213, 213, 213, 213, 213, 218,
533
+ 218, 218, 218, 218, 218, 218, 218, 219, 219, 219, 219, 219, 219, 219, 219,
534
+ 238, 238, 238, 238, 238, 238, 238, 238, 240, 240, 240, 240, 240, 240, 240,
535
+ 240, 242, 242, 242, 242, 242, 242, 242, 242, 243, 243, 243, 243, 243, 243,
536
+ 243, 243, 255, 255, 255, 255, 255, 255, 255, 255, 203, 203, 203, 203, 204,
537
+ 204, 204, 204, 211, 211, 211, 211, 212, 212, 212, 212, 214, 214, 214, 214,
538
+ 221, 221, 221, 221, 222, 222, 222, 222, 223, 223, 223, 223, 241, 241, 241,
539
+ 241, 244, 244, 244, 244, 245, 245, 245, 245, 246, 246, 246, 246, 247, 247,
540
+ 247, 247, 248, 248, 248, 248, 250, 250, 250, 250, 251, 251, 251, 251, 252,
541
+ 252, 252, 252, 253, 253, 253, 253, 254, 254, 254, 254, 2, 2, 3, 3,
542
+ 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 11, 11, 12, 12, 14,
543
+ 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21,
544
+ 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 30,
545
+ 30, 31, 31, 127, 127, 220, 220, 249, 249, -1, -1, 10, 10, 10, 10,
546
+ 10, 10, 10, 10, 13, 13, 13, 13, 13, 13, 13, 13, 22, 22, 22,
547
+ 22, 22, 22, 22, 22, 256, 256, 256, 256, 256, 256, 256, 256, 45, 45,
548
+ 45, 45, 45, 45, 45, 45, 46, 46, 46, 46, 46, 46, 46, 46, 47,
549
+ 47, 47, 47, 47, 47, 47, 47, 51, 51, 51, 51, 51, 51, 51, 51,
550
+ 52, 52, 52, 52, 52, 52, 52, 52, 53, 53, 53, 53, 53, 53, 53,
551
+ 53, 54, 54, 54, 54, 54, 54, 54, 54, 55, 55, 55, 55, 55, 55,
552
+ 55, 55, 56, 56, 56, 56, 56, 56, 56, 56, 57, 57, 57, 57, 57,
553
+ 57, 57, 57, 50, 50, 50, 50, 50, 50, 50, 50, 97, 97, 97, 97,
554
+ 97, 97, 97, 97, 99, 99, 99, 99, 99, 99, 99, 99, 101, 101, 101,
555
+ 101, 101, 101, 101, 101, 105, 105, 105, 105, 105, 105, 105, 105, 111, 111,
556
+ 111, 111, 111, 111, 111, 111, 115, 115, 115, 115, 115, 115, 115, 115, 116,
557
+ 116, 116, 116, 116, 116, 116, 116, 32, 32, 32, 32, 37, 37, 37, 37,
558
+ 45, 45, 45, 45, 46, 46, 46, 46, 47, 47, 47, 47, 51, 51, 51,
559
+ 51, 52, 52, 52, 52, 53, 53, 53, 53, 54, 54, 54, 54, 55, 55,
560
+ 55, 55, 56, 56, 56, 56, 57, 57, 57, 57, 61, 61, 61, 61, 65,
561
+ 65, 65, 65, 95, 95, 95, 95, 98, 98, 98, 98, 100, 100, 100, 100,
562
+ 102, 102, 102, 102, 103, 103, 103, 103, 104, 104, 104, 104, 108, 108, 108,
563
+ 108, 109, 109, 109, 109, 110, 110, 110, 110, 112, 112, 112, 112, 114, 114,
564
+ 114, 114, 117, 117, 117, 117, 58, 58, 66, 66, 67, 67, 68, 68, 69,
565
+ 69, 70, 70, 71, 71, 72, 72, 73, 73, 74, 74, 75, 75, 76, 76,
566
+ 77, 77, 78, 78, 79, 79, 80, 80, 81, 81, 82, 82, 83, 83, 84,
567
+ 84, 85, 85, 86, 86, 87, 87, 89, 89, 106, 106, 107, 107, 113, 113,
568
+ 118, 118, 119, 119, 120, 120, 121, 121, 122, 122, 38, 42, 44, 59, 88,
569
+ 90, -1, -1, 33, 33, 33, 33, 34, 34, 34, 34, 40, 40, 40, 40,
570
+ 41, 41, 41, 41, 63, 63, 63, 63, 39, 39, 43, 43, 124, 124, 35,
571
+ 62, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 36, 36,
572
+ 36, 36, 36, 36, 36, 36, 64, 64, 64, 64, 64, 64, 64, 64, 91,
573
+ 91, 91, 91, 91, 91, 91, 91, 93, 93, 93, 93, 93, 93, 93, 93,
574
+ 126, 126, 126, 126, 126, 126, 126, 126, 94, 94, 94, 94, 125, 125, 125,
575
+ 125, 60, 60, 96, 96, 123, 123, -1, -1, 92, 92, 195, 195, 208, 208,
576
+ 128, 130, 131, 162, 184, 194, 224, 226, -1, -1, 153, 153, 153, 153, 153,
577
+ 153, 153, 153, 161, 161, 161, 161, 161, 161, 161, 161, 167, 167, 167, 167,
578
+ 167, 167, 167, 167, 172, 172, 172, 172, 172, 172, 172, 172, 176, 176, 176,
579
+ 176, 176, 176, 176, 176, 177, 177, 177, 177, 177, 177, 177, 177, 179, 179,
580
+ 179, 179, 179, 179, 179, 179, 209, 209, 209, 209, 209, 209, 209, 209, 216,
581
+ 216, 216, 216, 216, 216, 216, 216, 217, 217, 217, 217, 217, 217, 217, 217,
582
+ 227, 227, 227, 227, 227, 227, 227, 227, 229, 229, 229, 229, 229, 229, 229,
583
+ 229, 230, 230, 230, 230, 230, 230, 230, 230, 129, 129, 129, 129, 132, 132,
584
+ 132, 132, 133, 133, 133, 133, 134, 134, 134, 134, 136, 136, 136, 136, 146,
585
+ 146, 146, 146, 154, 154, 154, 154, 156, 156, 156, 156, 160, 160, 160, 160,
586
+ 163, 163, 163, 163, 164, 164, 164, 164, 169, 169, 169, 169, 170, 170, 170,
587
+ 170, 173, 173, 173, 173, 178, 178, 178, 178, 181, 181, 181, 181, 185, 185,
588
+ 185, 185, 186, 186, 186, 186, 187, 187, 187, 187, 189, 189, 189, 189, 190,
589
+ 190, 190, 190, 196, 196, 196, 196, 198, 198, 198, 198, 228, 228, 228, 228,
590
+ 232, 232, 232, 232, 233, 233, 233, 233, 1, 1, 135, 135, 137, 137, 138,
591
+ 138, 139, 139, 140, 140, 141, 141, 143, 143, 147, 147, 149, 149, 150, 150,
592
+ 151, 151, 152, 152, 155, 155, 157, 157, 158, 158, 165, 165, 166, 166, 168,
593
+ 168, 174, 174, 175, 175, 180, 180, 182, 182, 183, 183, 188, 188, 191, 191,
594
+ 197, 197, 231, 231, 239, 239, 9, 142, 144, 145, 148, 159, 171, 206, 215,
595
+ 225, 236, 237, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 199, 199,
596
+ 199, 199, 199, 199, 199, 199, 207, 207, 207, 207, 207, 207, 207, 207, 234,
597
+ 234, 234, 234, 234, 234, 234, 234, 235, 235, 235, 235, 235, 235, 235, 235,
598
+ 192, 192, 192, 192, 193, 193, 193, 193, 200, 200, 200, 200, 201, 201, 201,
599
+ 201, 202, 202, 202, 202, 205, 205, 205, 205, 210, 210, 210, 210, 213, 213,
600
+ 213, 213, 218, 218, 218, 218, 219, 219, 219, 219, 238, 238, 238, 238, 240,
601
+ 240, 240, 240, 242, 242, 242, 242, 243, 243, 243, 243, 255, 255, 255, 255,
602
+ 203, 203, 204, 204, 211, 211, 212, 212, 214, 214, 221, 221, 222, 222, 223,
603
+ 223, 241, 241, 244, 244, 245, 245, 246, 246, 247, 247, 248, 248, 250, 250,
604
+ 251, 251, 252, 252, 253, 253, 254, 254, 2, 3, 4, 5, 6, 7, 8,
605
+ 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27,
606
+ 28, 29, 30, 31, 127, 220, 249, -1, 10, 10, 10, 10, 13, 13, 13,
607
+ 13, 22, 22, 22, 22, 256, 256, 256, 256,
608
+ };
609
+
610
+ static const gpr_uint8 inverse_base64[256] = {
611
+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
612
+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
613
+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 62, 255,
614
+ 255, 255, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255,
615
+ 255, 64, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
616
+ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
617
+ 25, 255, 255, 255, 255, 255, 255, 26, 27, 28, 29, 30, 31, 32, 33,
618
+ 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
619
+ 49, 50, 51, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
620
+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
621
+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
622
+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
623
+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
624
+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
625
+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
626
+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
627
+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
628
+ 255,
629
+ };
630
+
631
+ /* emission helpers */
632
+ static int on_hdr(grpc_chttp2_hpack_parser *p, grpc_mdelem *md,
633
+ int add_to_table) {
634
+ if (add_to_table) {
635
+ if (!grpc_chttp2_hptbl_add(&p->table, md)) {
636
+ return 0;
637
+ }
638
+ }
639
+ p->on_header(p->on_header_user_data, md);
640
+ return 1;
641
+ }
642
+
643
+ static grpc_mdstr *take_string(grpc_chttp2_hpack_parser *p,
644
+ grpc_chttp2_hpack_parser_string *str) {
645
+ grpc_mdstr *s = grpc_mdstr_from_buffer((gpr_uint8 *)str->str, str->length);
646
+ str->length = 0;
647
+ return s;
648
+ }
649
+
650
+ /* jump to the next state */
651
+ static int parse_next(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
652
+ const gpr_uint8 *end) {
653
+ p->state = *p->next_state++;
654
+ return p->state(p, cur, end);
655
+ }
656
+
657
+ /* begin parsing a header: all functionality is encoded into lookup tables
658
+ above */
659
+ static int parse_begin(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
660
+ const gpr_uint8 *end) {
661
+ if (cur == end) {
662
+ p->state = parse_begin;
663
+ return 1;
664
+ }
665
+
666
+ return first_byte_action[first_byte_lut[*cur]](p, cur, end);
667
+ }
668
+
669
+ /* stream dependency and prioritization data: we just skip it */
670
+ static int parse_stream_weight(grpc_chttp2_hpack_parser *p,
671
+ const gpr_uint8 *cur, const gpr_uint8 *end) {
672
+ if (cur == end) {
673
+ p->state = parse_stream_weight;
674
+ return 1;
675
+ }
676
+
677
+ return p->after_prioritization(p, cur + 1, end);
678
+ }
679
+
680
+ static int parse_stream_dep3(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
681
+ const gpr_uint8 *end) {
682
+ if (cur == end) {
683
+ p->state = parse_stream_dep3;
684
+ return 1;
685
+ }
686
+
687
+ return parse_stream_weight(p, cur + 1, end);
688
+ }
689
+
690
+ static int parse_stream_dep2(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
691
+ const gpr_uint8 *end) {
692
+ if (cur == end) {
693
+ p->state = parse_stream_dep2;
694
+ return 1;
695
+ }
696
+
697
+ return parse_stream_dep3(p, cur + 1, end);
698
+ }
699
+
700
+ static int parse_stream_dep1(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
701
+ const gpr_uint8 *end) {
702
+ if (cur == end) {
703
+ p->state = parse_stream_dep1;
704
+ return 1;
705
+ }
706
+
707
+ return parse_stream_dep2(p, cur + 1, end);
708
+ }
709
+
710
+ static int parse_stream_dep0(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
711
+ const gpr_uint8 *end) {
712
+ if (cur == end) {
713
+ p->state = parse_stream_dep0;
714
+ return 1;
715
+ }
716
+
717
+ return parse_stream_dep1(p, cur + 1, end);
718
+ }
719
+
720
+ /* emit an indexed field; for now just logs it to console; jumps to
721
+ begin the next field on completion */
722
+ static int finish_indexed_field(grpc_chttp2_hpack_parser *p,
723
+ const gpr_uint8 *cur, const gpr_uint8 *end) {
724
+ grpc_mdelem *md = grpc_chttp2_hptbl_lookup(&p->table, p->index);
725
+ if (md == NULL) {
726
+ gpr_log(GPR_ERROR, "Invalid HPACK index received: %d", p->index);
727
+ return 0;
728
+ }
729
+ GRPC_MDELEM_REF(md);
730
+ return on_hdr(p, md, 0) && parse_begin(p, cur, end);
731
+ }
732
+
733
+ /* parse an indexed field with index < 127 */
734
+ static int parse_indexed_field(grpc_chttp2_hpack_parser *p,
735
+ const gpr_uint8 *cur, const gpr_uint8 *end) {
736
+ p->dynamic_table_update_allowed = 0;
737
+ p->index = (*cur) & 0x7f;
738
+ return finish_indexed_field(p, cur + 1, end);
739
+ }
740
+
741
+ /* parse an indexed field with index >= 127 */
742
+ static int parse_indexed_field_x(grpc_chttp2_hpack_parser *p,
743
+ const gpr_uint8 *cur, const gpr_uint8 *end) {
744
+ static const grpc_chttp2_hpack_parser_state and_then[] = {
745
+ finish_indexed_field};
746
+ p->dynamic_table_update_allowed = 0;
747
+ p->next_state = and_then;
748
+ p->index = 0x7f;
749
+ p->parsing.value = &p->index;
750
+ return parse_value0(p, cur + 1, end);
751
+ }
752
+
753
+ /* finish a literal header with incremental indexing: just log, and jump to '
754
+ begin */
755
+ static int finish_lithdr_incidx(grpc_chttp2_hpack_parser *p,
756
+ const gpr_uint8 *cur, const gpr_uint8 *end) {
757
+ grpc_mdelem *md = grpc_chttp2_hptbl_lookup(&p->table, p->index);
758
+ GPR_ASSERT(md != NULL); /* handled in string parsing */
759
+ return on_hdr(p, grpc_mdelem_from_metadata_strings(GRPC_MDSTR_REF(md->key),
760
+ take_string(p, &p->value)),
761
+ 1) &&
762
+ parse_begin(p, cur, end);
763
+ }
764
+
765
+ /* finish a literal header with incremental indexing with no index */
766
+ static int finish_lithdr_incidx_v(grpc_chttp2_hpack_parser *p,
767
+ const gpr_uint8 *cur, const gpr_uint8 *end) {
768
+ return on_hdr(p, grpc_mdelem_from_metadata_strings(take_string(p, &p->key),
769
+ take_string(p, &p->value)),
770
+ 1) &&
771
+ parse_begin(p, cur, end);
772
+ }
773
+
774
+ /* parse a literal header with incremental indexing; index < 63 */
775
+ static int parse_lithdr_incidx(grpc_chttp2_hpack_parser *p,
776
+ const gpr_uint8 *cur, const gpr_uint8 *end) {
777
+ static const grpc_chttp2_hpack_parser_state and_then[] = {
778
+ parse_value_string_with_indexed_key, finish_lithdr_incidx};
779
+ p->dynamic_table_update_allowed = 0;
780
+ p->next_state = and_then;
781
+ p->index = (*cur) & 0x3f;
782
+ return parse_string_prefix(p, cur + 1, end);
783
+ }
784
+
785
+ /* parse a literal header with incremental indexing; index >= 63 */
786
+ static int parse_lithdr_incidx_x(grpc_chttp2_hpack_parser *p,
787
+ const gpr_uint8 *cur, const gpr_uint8 *end) {
788
+ static const grpc_chttp2_hpack_parser_state and_then[] = {
789
+ parse_string_prefix, parse_value_string_with_indexed_key,
790
+ finish_lithdr_incidx};
791
+ p->dynamic_table_update_allowed = 0;
792
+ p->next_state = and_then;
793
+ p->index = 0x3f;
794
+ p->parsing.value = &p->index;
795
+ return parse_value0(p, cur + 1, end);
796
+ }
797
+
798
+ /* parse a literal header with incremental indexing; index = 0 */
799
+ static int parse_lithdr_incidx_v(grpc_chttp2_hpack_parser *p,
800
+ const gpr_uint8 *cur, const gpr_uint8 *end) {
801
+ static const grpc_chttp2_hpack_parser_state and_then[] = {
802
+ parse_key_string, parse_string_prefix,
803
+ parse_value_string_with_literal_key, finish_lithdr_incidx_v};
804
+ p->dynamic_table_update_allowed = 0;
805
+ p->next_state = and_then;
806
+ return parse_string_prefix(p, cur + 1, end);
807
+ }
808
+
809
+ /* finish a literal header without incremental indexing */
810
+ static int finish_lithdr_notidx(grpc_chttp2_hpack_parser *p,
811
+ const gpr_uint8 *cur, const gpr_uint8 *end) {
812
+ grpc_mdelem *md = grpc_chttp2_hptbl_lookup(&p->table, p->index);
813
+ GPR_ASSERT(md != NULL); /* handled in string parsing */
814
+ return on_hdr(p, grpc_mdelem_from_metadata_strings(GRPC_MDSTR_REF(md->key),
815
+ take_string(p, &p->value)),
816
+ 0) &&
817
+ parse_begin(p, cur, end);
818
+ }
819
+
820
+ /* finish a literal header without incremental indexing with index = 0 */
821
+ static int finish_lithdr_notidx_v(grpc_chttp2_hpack_parser *p,
822
+ const gpr_uint8 *cur, const gpr_uint8 *end) {
823
+ return on_hdr(p, grpc_mdelem_from_metadata_strings(take_string(p, &p->key),
824
+ take_string(p, &p->value)),
825
+ 0) &&
826
+ parse_begin(p, cur, end);
827
+ }
828
+
829
+ /* parse a literal header without incremental indexing; index < 15 */
830
+ static int parse_lithdr_notidx(grpc_chttp2_hpack_parser *p,
831
+ const gpr_uint8 *cur, const gpr_uint8 *end) {
832
+ static const grpc_chttp2_hpack_parser_state and_then[] = {
833
+ parse_value_string_with_indexed_key, finish_lithdr_notidx};
834
+ p->dynamic_table_update_allowed = 0;
835
+ p->next_state = and_then;
836
+ p->index = (*cur) & 0xf;
837
+ return parse_string_prefix(p, cur + 1, end);
838
+ }
839
+
840
+ /* parse a literal header without incremental indexing; index >= 15 */
841
+ static int parse_lithdr_notidx_x(grpc_chttp2_hpack_parser *p,
842
+ const gpr_uint8 *cur, const gpr_uint8 *end) {
843
+ static const grpc_chttp2_hpack_parser_state and_then[] = {
844
+ parse_string_prefix, parse_value_string_with_indexed_key,
845
+ finish_lithdr_notidx};
846
+ p->dynamic_table_update_allowed = 0;
847
+ p->next_state = and_then;
848
+ p->index = 0xf;
849
+ p->parsing.value = &p->index;
850
+ return parse_value0(p, cur + 1, end);
851
+ }
852
+
853
+ /* parse a literal header without incremental indexing; index == 0 */
854
+ static int parse_lithdr_notidx_v(grpc_chttp2_hpack_parser *p,
855
+ const gpr_uint8 *cur, const gpr_uint8 *end) {
856
+ static const grpc_chttp2_hpack_parser_state and_then[] = {
857
+ parse_key_string, parse_string_prefix,
858
+ parse_value_string_with_literal_key, finish_lithdr_notidx_v};
859
+ p->dynamic_table_update_allowed = 0;
860
+ p->next_state = and_then;
861
+ return parse_string_prefix(p, cur + 1, end);
862
+ }
863
+
864
+ /* finish a literal header that is never indexed */
865
+ static int finish_lithdr_nvridx(grpc_chttp2_hpack_parser *p,
866
+ const gpr_uint8 *cur, const gpr_uint8 *end) {
867
+ grpc_mdelem *md = grpc_chttp2_hptbl_lookup(&p->table, p->index);
868
+ GPR_ASSERT(md != NULL); /* handled in string parsing */
869
+ return on_hdr(p, grpc_mdelem_from_metadata_strings(GRPC_MDSTR_REF(md->key),
870
+ take_string(p, &p->value)),
871
+ 0) &&
872
+ parse_begin(p, cur, end);
873
+ }
874
+
875
+ /* finish a literal header that is never indexed with an extra value */
876
+ static int finish_lithdr_nvridx_v(grpc_chttp2_hpack_parser *p,
877
+ const gpr_uint8 *cur, const gpr_uint8 *end) {
878
+ return on_hdr(p, grpc_mdelem_from_metadata_strings(take_string(p, &p->key),
879
+ take_string(p, &p->value)),
880
+ 0) &&
881
+ parse_begin(p, cur, end);
882
+ }
883
+
884
+ /* parse a literal header that is never indexed; index < 15 */
885
+ static int parse_lithdr_nvridx(grpc_chttp2_hpack_parser *p,
886
+ const gpr_uint8 *cur, const gpr_uint8 *end) {
887
+ static const grpc_chttp2_hpack_parser_state and_then[] = {
888
+ parse_value_string_with_indexed_key, finish_lithdr_nvridx};
889
+ p->dynamic_table_update_allowed = 0;
890
+ p->next_state = and_then;
891
+ p->index = (*cur) & 0xf;
892
+ return parse_string_prefix(p, cur + 1, end);
893
+ }
894
+
895
+ /* parse a literal header that is never indexed; index >= 15 */
896
+ static int parse_lithdr_nvridx_x(grpc_chttp2_hpack_parser *p,
897
+ const gpr_uint8 *cur, const gpr_uint8 *end) {
898
+ static const grpc_chttp2_hpack_parser_state and_then[] = {
899
+ parse_string_prefix, parse_value_string_with_indexed_key,
900
+ finish_lithdr_nvridx};
901
+ p->dynamic_table_update_allowed = 0;
902
+ p->next_state = and_then;
903
+ p->index = 0xf;
904
+ p->parsing.value = &p->index;
905
+ return parse_value0(p, cur + 1, end);
906
+ }
907
+
908
+ /* parse a literal header that is never indexed; index == 0 */
909
+ static int parse_lithdr_nvridx_v(grpc_chttp2_hpack_parser *p,
910
+ const gpr_uint8 *cur, const gpr_uint8 *end) {
911
+ static const grpc_chttp2_hpack_parser_state and_then[] = {
912
+ parse_key_string, parse_string_prefix,
913
+ parse_value_string_with_literal_key, finish_lithdr_nvridx_v};
914
+ p->dynamic_table_update_allowed = 0;
915
+ p->next_state = and_then;
916
+ return parse_string_prefix(p, cur + 1, end);
917
+ }
918
+
919
+ /* finish parsing a max table size change */
920
+ static int finish_max_tbl_size(grpc_chttp2_hpack_parser *p,
921
+ const gpr_uint8 *cur, const gpr_uint8 *end) {
922
+ gpr_log(GPR_INFO, "MAX TABLE SIZE: %d", p->index);
923
+ return grpc_chttp2_hptbl_set_current_table_size(&p->table, p->index) &&
924
+ parse_begin(p, cur, end);
925
+ }
926
+
927
+ /* parse a max table size change, max size < 15 */
928
+ static int parse_max_tbl_size(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
929
+ const gpr_uint8 *end) {
930
+ if (p->dynamic_table_update_allowed == 0) {
931
+ return 0;
932
+ }
933
+ p->dynamic_table_update_allowed--;
934
+ p->index = (*cur) & 0x1f;
935
+ return finish_max_tbl_size(p, cur + 1, end);
936
+ }
937
+
938
+ /* parse a max table size change, max size >= 15 */
939
+ static int parse_max_tbl_size_x(grpc_chttp2_hpack_parser *p,
940
+ const gpr_uint8 *cur, const gpr_uint8 *end) {
941
+ static const grpc_chttp2_hpack_parser_state and_then[] = {
942
+ finish_max_tbl_size};
943
+ if (p->dynamic_table_update_allowed == 0) {
944
+ return 0;
945
+ }
946
+ p->dynamic_table_update_allowed--;
947
+ p->next_state = and_then;
948
+ p->index = 0x1f;
949
+ p->parsing.value = &p->index;
950
+ return parse_value0(p, cur + 1, end);
951
+ }
952
+
953
+ /* a parse error: jam the parse state into parse_error, and return error */
954
+ static int parse_error(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
955
+ const gpr_uint8 *end) {
956
+ p->state = parse_error;
957
+ return 0;
958
+ }
959
+
960
+ static int parse_illegal_op(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
961
+ const gpr_uint8 *end) {
962
+ GPR_ASSERT(cur != end);
963
+ gpr_log(GPR_DEBUG, "Illegal hpack op code %d", *cur);
964
+ return parse_error(p, cur, end);
965
+ }
966
+
967
+ /* parse the 1st byte of a varint into p->parsing.value
968
+ no overflow is possible */
969
+ static int parse_value0(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
970
+ const gpr_uint8 *end) {
971
+ if (cur == end) {
972
+ p->state = parse_value0;
973
+ return 1;
974
+ }
975
+
976
+ *p->parsing.value += (*cur) & 0x7f;
977
+
978
+ if ((*cur) & 0x80) {
979
+ return parse_value1(p, cur + 1, end);
980
+ } else {
981
+ return parse_next(p, cur + 1, end);
982
+ }
983
+ }
984
+
985
+ /* parse the 2nd byte of a varint into p->parsing.value
986
+ no overflow is possible */
987
+ static int parse_value1(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
988
+ const gpr_uint8 *end) {
989
+ if (cur == end) {
990
+ p->state = parse_value1;
991
+ return 1;
992
+ }
993
+
994
+ *p->parsing.value += (((gpr_uint32)*cur) & 0x7f) << 7;
995
+
996
+ if ((*cur) & 0x80) {
997
+ return parse_value2(p, cur + 1, end);
998
+ } else {
999
+ return parse_next(p, cur + 1, end);
1000
+ }
1001
+ }
1002
+
1003
+ /* parse the 3rd byte of a varint into p->parsing.value
1004
+ no overflow is possible */
1005
+ static int parse_value2(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
1006
+ const gpr_uint8 *end) {
1007
+ if (cur == end) {
1008
+ p->state = parse_value2;
1009
+ return 1;
1010
+ }
1011
+
1012
+ *p->parsing.value += (((gpr_uint32)*cur) & 0x7f) << 14;
1013
+
1014
+ if ((*cur) & 0x80) {
1015
+ return parse_value3(p, cur + 1, end);
1016
+ } else {
1017
+ return parse_next(p, cur + 1, end);
1018
+ }
1019
+ }
1020
+
1021
+ /* parse the 4th byte of a varint into p->parsing.value
1022
+ no overflow is possible */
1023
+ static int parse_value3(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
1024
+ const gpr_uint8 *end) {
1025
+ if (cur == end) {
1026
+ p->state = parse_value3;
1027
+ return 1;
1028
+ }
1029
+
1030
+ *p->parsing.value += (((gpr_uint32)*cur) & 0x7f) << 21;
1031
+
1032
+ if ((*cur) & 0x80) {
1033
+ return parse_value4(p, cur + 1, end);
1034
+ } else {
1035
+ return parse_next(p, cur + 1, end);
1036
+ }
1037
+ }
1038
+
1039
+ /* parse the 5th byte of a varint into p->parsing.value
1040
+ depending on the byte, we may overflow, and care must be taken */
1041
+ static int parse_value4(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
1042
+ const gpr_uint8 *end) {
1043
+ gpr_uint8 c;
1044
+ gpr_uint32 cur_value;
1045
+ gpr_uint32 add_value;
1046
+
1047
+ if (cur == end) {
1048
+ p->state = parse_value4;
1049
+ return 1;
1050
+ }
1051
+
1052
+ c = (*cur) & 0x7f;
1053
+ if (c > 0xf) {
1054
+ goto error;
1055
+ }
1056
+
1057
+ cur_value = *p->parsing.value;
1058
+ add_value = ((gpr_uint32)c) << 28;
1059
+ if (add_value > 0xffffffffu - cur_value) {
1060
+ goto error;
1061
+ }
1062
+
1063
+ *p->parsing.value = cur_value + add_value;
1064
+
1065
+ if ((*cur) & 0x80) {
1066
+ return parse_value5up(p, cur + 1, end);
1067
+ } else {
1068
+ return parse_next(p, cur + 1, end);
1069
+ }
1070
+
1071
+ error:
1072
+ gpr_log(GPR_ERROR,
1073
+ "integer overflow in hpack integer decoding: have 0x%08x, "
1074
+ "got byte 0x%02x on byte 5",
1075
+ *p->parsing.value, *cur);
1076
+ return parse_error(p, cur, end);
1077
+ }
1078
+
1079
+ /* parse any trailing bytes in a varint: it's possible to append an arbitrary
1080
+ number of 0x80's and not affect the value - a zero will terminate - and
1081
+ anything else will overflow */
1082
+ static int parse_value5up(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
1083
+ const gpr_uint8 *end) {
1084
+ while (cur != end && *cur == 0x80) {
1085
+ ++cur;
1086
+ }
1087
+
1088
+ if (cur == end) {
1089
+ p->state = parse_value5up;
1090
+ return 1;
1091
+ }
1092
+
1093
+ if (*cur == 0) {
1094
+ return parse_next(p, cur + 1, end);
1095
+ }
1096
+
1097
+ gpr_log(GPR_ERROR,
1098
+ "integer overflow in hpack integer decoding: have 0x%08x, "
1099
+ "got byte 0x%02x sometime after byte 5",
1100
+ *p->parsing.value, *cur);
1101
+ return parse_error(p, cur, end);
1102
+ }
1103
+
1104
+ /* parse a string prefix */
1105
+ static int parse_string_prefix(grpc_chttp2_hpack_parser *p,
1106
+ const gpr_uint8 *cur, const gpr_uint8 *end) {
1107
+ if (cur == end) {
1108
+ p->state = parse_string_prefix;
1109
+ return 1;
1110
+ }
1111
+
1112
+ p->strlen = (*cur) & 0x7f;
1113
+ p->huff = (*cur) >> 7;
1114
+ if (p->strlen == 0x7f) {
1115
+ p->parsing.value = &p->strlen;
1116
+ return parse_value0(p, cur + 1, end);
1117
+ } else {
1118
+ return parse_next(p, cur + 1, end);
1119
+ }
1120
+ }
1121
+
1122
+ /* append some bytes to a string */
1123
+ static void append_bytes(grpc_chttp2_hpack_parser_string *str,
1124
+ const gpr_uint8 *data, size_t length) {
1125
+ if (length + str->length > str->capacity) {
1126
+ GPR_ASSERT(str->length + length <= GPR_UINT32_MAX);
1127
+ str->capacity = (gpr_uint32)(str->length + length);
1128
+ str->str = gpr_realloc(str->str, str->capacity);
1129
+ }
1130
+ memcpy(str->str + str->length, data, length);
1131
+ GPR_ASSERT(length <= GPR_UINT32_MAX - str->length);
1132
+ str->length += (gpr_uint32)length;
1133
+ }
1134
+
1135
+ static int append_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
1136
+ const gpr_uint8 *end) {
1137
+ grpc_chttp2_hpack_parser_string *str = p->parsing.str;
1138
+ gpr_uint32 bits;
1139
+ gpr_uint8 decoded[3];
1140
+ switch ((binary_state)p->binary) {
1141
+ case NOT_BINARY:
1142
+ append_bytes(str, cur, (size_t)(end - cur));
1143
+ return 1;
1144
+ b64_byte0:
1145
+ case B64_BYTE0:
1146
+ if (cur == end) {
1147
+ p->binary = B64_BYTE0;
1148
+ return 1;
1149
+ }
1150
+ bits = inverse_base64[*cur];
1151
+ ++cur;
1152
+ if (bits == 255)
1153
+ return 0;
1154
+ else if (bits == 64)
1155
+ goto b64_byte0;
1156
+ p->base64_buffer = bits << 18;
1157
+ /* fallthrough */
1158
+ b64_byte1:
1159
+ case B64_BYTE1:
1160
+ if (cur == end) {
1161
+ p->binary = B64_BYTE1;
1162
+ return 1;
1163
+ }
1164
+ bits = inverse_base64[*cur];
1165
+ ++cur;
1166
+ if (bits == 255)
1167
+ return 0;
1168
+ else if (bits == 64)
1169
+ goto b64_byte1;
1170
+ p->base64_buffer |= bits << 12;
1171
+ /* fallthrough */
1172
+ b64_byte2:
1173
+ case B64_BYTE2:
1174
+ if (cur == end) {
1175
+ p->binary = B64_BYTE2;
1176
+ return 1;
1177
+ }
1178
+ bits = inverse_base64[*cur];
1179
+ ++cur;
1180
+ if (bits == 255)
1181
+ return 0;
1182
+ else if (bits == 64)
1183
+ goto b64_byte2;
1184
+ p->base64_buffer |= bits << 6;
1185
+ /* fallthrough */
1186
+ b64_byte3:
1187
+ case B64_BYTE3:
1188
+ if (cur == end) {
1189
+ p->binary = B64_BYTE3;
1190
+ return 1;
1191
+ }
1192
+ bits = inverse_base64[*cur];
1193
+ ++cur;
1194
+ if (bits == 255)
1195
+ return 0;
1196
+ else if (bits == 64)
1197
+ goto b64_byte3;
1198
+ p->base64_buffer |= bits;
1199
+ bits = p->base64_buffer;
1200
+ decoded[0] = (gpr_uint8)(bits >> 16);
1201
+ decoded[1] = (gpr_uint8)(bits >> 8);
1202
+ decoded[2] = (gpr_uint8)(bits);
1203
+ append_bytes(str, decoded, 3);
1204
+ goto b64_byte0;
1205
+ }
1206
+ GPR_UNREACHABLE_CODE(return 1);
1207
+ }
1208
+
1209
+ /* append a null terminator to a string */
1210
+ static int finish_str(grpc_chttp2_hpack_parser *p) {
1211
+ gpr_uint8 terminator = 0;
1212
+ gpr_uint8 decoded[2];
1213
+ gpr_uint32 bits;
1214
+ grpc_chttp2_hpack_parser_string *str = p->parsing.str;
1215
+ switch ((binary_state)p->binary) {
1216
+ case NOT_BINARY:
1217
+ break;
1218
+ case B64_BYTE0:
1219
+ break;
1220
+ case B64_BYTE1:
1221
+ gpr_log(GPR_ERROR, "illegal base64 encoding");
1222
+ return 0; /* illegal encoding */
1223
+ case B64_BYTE2:
1224
+ bits = p->base64_buffer;
1225
+ if (bits & 0xffff) {
1226
+ gpr_log(GPR_ERROR, "trailing bits in base64 encoding: 0x%04x",
1227
+ bits & 0xffff);
1228
+ return 0;
1229
+ }
1230
+ decoded[0] = (gpr_uint8)(bits >> 16);
1231
+ append_bytes(str, decoded, 1);
1232
+ break;
1233
+ case B64_BYTE3:
1234
+ bits = p->base64_buffer;
1235
+ if (bits & 0xff) {
1236
+ gpr_log(GPR_ERROR, "trailing bits in base64 encoding: 0x%02x",
1237
+ bits & 0xff);
1238
+ return 0;
1239
+ }
1240
+ decoded[0] = (gpr_uint8)(bits >> 16);
1241
+ decoded[1] = (gpr_uint8)(bits >> 8);
1242
+ append_bytes(str, decoded, 2);
1243
+ break;
1244
+ }
1245
+ append_bytes(str, &terminator, 1);
1246
+ p->parsing.str->length--; /* don't actually count the null terminator */
1247
+ return 1;
1248
+ }
1249
+
1250
+ /* decode a nibble from a huffman encoded stream */
1251
+ static int huff_nibble(grpc_chttp2_hpack_parser *p, gpr_uint8 nibble) {
1252
+ gpr_int16 emit = emit_sub_tbl[16 * emit_tbl[p->huff_state] + nibble];
1253
+ gpr_int16 next = next_sub_tbl[16 * next_tbl[p->huff_state] + nibble];
1254
+ if (emit != -1) {
1255
+ if (emit >= 0 && emit < 256) {
1256
+ gpr_uint8 c = (gpr_uint8)emit;
1257
+ if (!append_string(p, &c, (&c) + 1)) return 0;
1258
+ } else {
1259
+ assert(emit == 256);
1260
+ }
1261
+ }
1262
+ p->huff_state = next;
1263
+ return 1;
1264
+ }
1265
+
1266
+ /* decode full bytes from a huffman encoded stream */
1267
+ static int add_huff_bytes(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
1268
+ const gpr_uint8 *end) {
1269
+ for (; cur != end; ++cur) {
1270
+ if (!huff_nibble(p, *cur >> 4) || !huff_nibble(p, *cur & 0xf)) return 0;
1271
+ }
1272
+ return 1;
1273
+ }
1274
+
1275
+ /* decode some string bytes based on the current decoding mode
1276
+ (huffman or not) */
1277
+ static int add_str_bytes(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
1278
+ const gpr_uint8 *end) {
1279
+ if (p->huff) {
1280
+ return add_huff_bytes(p, cur, end);
1281
+ } else {
1282
+ return append_string(p, cur, end);
1283
+ }
1284
+ }
1285
+
1286
+ /* parse a string - tries to do large chunks at a time */
1287
+ static int parse_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
1288
+ const gpr_uint8 *end) {
1289
+ size_t remaining = p->strlen - p->strgot;
1290
+ size_t given = (size_t)(end - cur);
1291
+ if (remaining <= given) {
1292
+ return add_str_bytes(p, cur, cur + remaining) && finish_str(p) &&
1293
+ parse_next(p, cur + remaining, end);
1294
+ } else {
1295
+ if (!add_str_bytes(p, cur, cur + given)) return 0;
1296
+ GPR_ASSERT(given <= GPR_UINT32_MAX - p->strgot);
1297
+ p->strgot += (gpr_uint32)given;
1298
+ p->state = parse_string;
1299
+ return 1;
1300
+ }
1301
+ }
1302
+
1303
+ /* begin parsing a string - performs setup, calls parse_string */
1304
+ static int begin_parse_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
1305
+ const gpr_uint8 *end, gpr_uint8 binary,
1306
+ grpc_chttp2_hpack_parser_string *str) {
1307
+ p->strgot = 0;
1308
+ str->length = 0;
1309
+ p->parsing.str = str;
1310
+ p->huff_state = 0;
1311
+ p->binary = binary;
1312
+ return parse_string(p, cur, end);
1313
+ }
1314
+
1315
+ /* parse the key string */
1316
+ static int parse_key_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
1317
+ const gpr_uint8 *end) {
1318
+ return begin_parse_string(p, cur, end, NOT_BINARY, &p->key);
1319
+ }
1320
+
1321
+ /* check if a key represents a binary header or not */
1322
+ typedef enum { BINARY_HEADER, PLAINTEXT_HEADER, ERROR_HEADER } is_binary_header;
1323
+
1324
+ static is_binary_header is_binary_literal_header(grpc_chttp2_hpack_parser *p) {
1325
+ return grpc_is_binary_header(p->key.str, p->key.length) ? BINARY_HEADER
1326
+ : PLAINTEXT_HEADER;
1327
+ }
1328
+
1329
+ static is_binary_header is_binary_indexed_header(grpc_chttp2_hpack_parser *p) {
1330
+ grpc_mdelem *elem = grpc_chttp2_hptbl_lookup(&p->table, p->index);
1331
+ if (!elem) {
1332
+ gpr_log(GPR_ERROR, "Invalid HPACK index received: %d", p->index);
1333
+ return ERROR_HEADER;
1334
+ }
1335
+ return grpc_is_binary_header(
1336
+ (const char *)GPR_SLICE_START_PTR(elem->key->slice),
1337
+ GPR_SLICE_LENGTH(elem->key->slice))
1338
+ ? BINARY_HEADER
1339
+ : PLAINTEXT_HEADER;
1340
+ }
1341
+
1342
+ /* parse the value string */
1343
+ static int parse_value_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
1344
+ const gpr_uint8 *end, is_binary_header type) {
1345
+ switch (type) {
1346
+ case BINARY_HEADER:
1347
+ return begin_parse_string(p, cur, end, B64_BYTE0, &p->value);
1348
+ case PLAINTEXT_HEADER:
1349
+ return begin_parse_string(p, cur, end, NOT_BINARY, &p->value);
1350
+ case ERROR_HEADER:
1351
+ return 0;
1352
+ }
1353
+ /* Add code to prevent return without value error */
1354
+ GPR_UNREACHABLE_CODE(return 0);
1355
+ }
1356
+
1357
+ static int parse_value_string_with_indexed_key(grpc_chttp2_hpack_parser *p,
1358
+ const gpr_uint8 *cur,
1359
+ const gpr_uint8 *end) {
1360
+ return parse_value_string(p, cur, end, is_binary_indexed_header(p));
1361
+ }
1362
+
1363
+ static int parse_value_string_with_literal_key(grpc_chttp2_hpack_parser *p,
1364
+ const gpr_uint8 *cur,
1365
+ const gpr_uint8 *end) {
1366
+ return parse_value_string(p, cur, end, is_binary_literal_header(p));
1367
+ }
1368
+
1369
+ /* PUBLIC INTERFACE */
1370
+
1371
+ static void on_header_not_set(void *user_data, grpc_mdelem *md) {
1372
+ GPR_UNREACHABLE_CODE(return );
1373
+ }
1374
+
1375
+ void grpc_chttp2_hpack_parser_init(grpc_chttp2_hpack_parser *p) {
1376
+ p->on_header = on_header_not_set;
1377
+ p->on_header_user_data = NULL;
1378
+ p->state = parse_begin;
1379
+ p->key.str = NULL;
1380
+ p->key.capacity = 0;
1381
+ p->key.length = 0;
1382
+ p->value.str = NULL;
1383
+ p->value.capacity = 0;
1384
+ p->value.length = 0;
1385
+ p->dynamic_table_update_allowed = 2;
1386
+ grpc_chttp2_hptbl_init(&p->table);
1387
+ }
1388
+
1389
+ void grpc_chttp2_hpack_parser_set_has_priority(grpc_chttp2_hpack_parser *p) {
1390
+ p->after_prioritization = p->state;
1391
+ p->state = parse_stream_dep0;
1392
+ }
1393
+
1394
+ void grpc_chttp2_hpack_parser_destroy(grpc_chttp2_hpack_parser *p) {
1395
+ grpc_chttp2_hptbl_destroy(&p->table);
1396
+ gpr_free(p->key.str);
1397
+ gpr_free(p->value.str);
1398
+ }
1399
+
1400
+ int grpc_chttp2_hpack_parser_parse(grpc_chttp2_hpack_parser *p,
1401
+ const gpr_uint8 *beg, const gpr_uint8 *end) {
1402
+ /* TODO(ctiller): limit the distance of end from beg, and perform multiple
1403
+ steps in the event of a large chunk of data to limit
1404
+ stack space usage when no tail call optimization is
1405
+ available */
1406
+ return p->state(p, beg, end);
1407
+ }
1408
+
1409
+ grpc_chttp2_parse_error grpc_chttp2_header_parser_parse(
1410
+ grpc_exec_ctx *exec_ctx, void *hpack_parser,
1411
+ grpc_chttp2_transport_parsing *transport_parsing,
1412
+ grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last) {
1413
+ grpc_chttp2_hpack_parser *parser = hpack_parser;
1414
+ GPR_TIMER_BEGIN("grpc_chttp2_hpack_parser_parse", 0);
1415
+ if (!grpc_chttp2_hpack_parser_parse(parser, GPR_SLICE_START_PTR(slice),
1416
+ GPR_SLICE_END_PTR(slice))) {
1417
+ GPR_TIMER_END("grpc_chttp2_hpack_parser_parse", 0);
1418
+ return GRPC_CHTTP2_CONNECTION_ERROR;
1419
+ }
1420
+ if (is_last) {
1421
+ if (parser->is_boundary && parser->state != parse_begin) {
1422
+ gpr_log(GPR_ERROR,
1423
+ "end of header frame not aligned with a hpack record boundary");
1424
+ GPR_TIMER_END("grpc_chttp2_hpack_parser_parse", 0);
1425
+ return GRPC_CHTTP2_CONNECTION_ERROR;
1426
+ }
1427
+ /* need to check for null stream: this can occur if we receive an invalid
1428
+ stream id on a header */
1429
+ if (stream_parsing != NULL) {
1430
+ if (parser->is_boundary) {
1431
+ stream_parsing
1432
+ ->got_metadata_on_parse[stream_parsing->header_frames_received] = 1;
1433
+ stream_parsing->header_frames_received++;
1434
+ grpc_chttp2_list_add_parsing_seen_stream(transport_parsing,
1435
+ stream_parsing);
1436
+ }
1437
+ if (parser->is_eof) {
1438
+ stream_parsing->received_close = 1;
1439
+ }
1440
+ }
1441
+ parser->on_header = on_header_not_set;
1442
+ parser->on_header_user_data = NULL;
1443
+ parser->is_boundary = 0xde;
1444
+ parser->is_eof = 0xde;
1445
+ parser->dynamic_table_update_allowed = 2;
1446
+ }
1447
+ GPR_TIMER_END("grpc_chttp2_hpack_parser_parse", 0);
1448
+ return GRPC_CHTTP2_PARSE_OK;
1449
+ }