grpc 0.14.1 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (277) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1398 -817
  3. data/include/grpc/compression.h +2 -1
  4. data/include/grpc/grpc.h +10 -1
  5. data/include/grpc/grpc_cronet.h +51 -0
  6. data/include/grpc/grpc_posix.h +70 -0
  7. data/include/grpc/impl/codegen/atm.h +2 -2
  8. data/include/grpc/impl/codegen/{atm_win32.h → atm_windows.h} +3 -3
  9. data/include/grpc/impl/codegen/compression_types.h +39 -5
  10. data/include/grpc/impl/codegen/connectivity_state.h +1 -1
  11. data/include/grpc/impl/codegen/grpc_types.h +10 -0
  12. data/include/grpc/impl/codegen/log.h +2 -1
  13. data/include/grpc/impl/codegen/port_platform.h +30 -12
  14. data/include/grpc/impl/codegen/slice_buffer.h +2 -3
  15. data/include/grpc/impl/codegen/sync.h +2 -2
  16. data/include/grpc/impl/codegen/{sync_win32.h → sync_windows.h} +3 -3
  17. data/include/grpc/support/{sync_win32.h → atm_windows.h} +4 -4
  18. data/include/grpc/support/avl.h +5 -0
  19. data/include/grpc/support/{log_win32.h → log_windows.h} +3 -3
  20. data/include/grpc/support/string_util.h +2 -1
  21. data/include/grpc/support/{atm_win32.h → sync_windows.h} +4 -4
  22. data/src/core/ext/census/gen/census.pb.c +179 -0
  23. data/src/core/ext/census/gen/census.pb.h +294 -0
  24. data/src/core/ext/census/grpc_filter.c +11 -7
  25. data/src/core/ext/client_config/channel_connectivity.c +28 -14
  26. data/src/core/ext/client_config/client_channel.c +77 -53
  27. data/src/core/ext/client_config/connector.h +1 -1
  28. data/src/core/ext/client_config/lb_policy.c +9 -6
  29. data/src/core/ext/client_config/lb_policy.h +9 -5
  30. data/src/core/ext/client_config/subchannel.c +58 -39
  31. data/src/core/ext/client_config/subchannel.h +3 -2
  32. data/src/core/ext/client_config/subchannel_call_holder.c +34 -19
  33. data/src/core/ext/client_config/subchannel_call_holder.h +2 -1
  34. data/src/core/ext/client_config/subchannel_index.c +20 -9
  35. data/src/core/ext/lb_policy/grpclb/load_balancer_api.c +7 -7
  36. data/src/core/ext/lb_policy/grpclb/load_balancer_api.h +5 -5
  37. data/src/core/ext/lb_policy/grpclb/proto/grpc/lb/{v0 → v1}/load_balancer.pb.c +29 -30
  38. data/src/core/ext/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +178 -0
  39. data/src/core/ext/lb_policy/pick_first/pick_first.c +65 -45
  40. data/src/core/ext/lb_policy/round_robin/round_robin.c +84 -43
  41. data/src/core/ext/load_reporting/load_reporting.c +133 -0
  42. data/src/core/ext/load_reporting/load_reporting.h +75 -0
  43. data/src/core/ext/load_reporting/load_reporting_filter.c +151 -0
  44. data/src/core/ext/load_reporting/load_reporting_filter.h +41 -0
  45. data/src/core/ext/resolver/dns/native/dns_resolver.c +22 -8
  46. data/src/core/ext/resolver/sockaddr/sockaddr_resolver.c +2 -2
  47. data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +4 -4
  48. data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.c +95 -0
  49. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +14 -18
  50. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c +49 -24
  51. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c +82 -0
  52. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +104 -60
  53. data/src/core/ext/transport/chttp2/transport/bin_decoder.c +232 -0
  54. data/src/{ruby/ext/grpc/rb_signal.c → core/ext/transport/chttp2/transport/bin_decoder.h} +27 -31
  55. data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +481 -260
  56. data/src/core/ext/transport/chttp2/transport/frame.h +1 -7
  57. data/src/core/ext/transport/chttp2/transport/frame_data.c +44 -27
  58. data/src/core/ext/transport/chttp2/transport/frame_data.h +6 -5
  59. data/src/core/ext/transport/chttp2/transport/frame_goaway.c +23 -17
  60. data/src/core/ext/transport/chttp2/transport/frame_goaway.h +2 -2
  61. data/src/core/ext/transport/chttp2/transport/frame_ping.c +12 -7
  62. data/src/core/ext/transport/chttp2/transport/frame_ping.h +3 -3
  63. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +25 -12
  64. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +2 -2
  65. data/src/core/ext/transport/chttp2/transport/frame_settings.c +23 -21
  66. data/src/core/ext/transport/chttp2/transport/frame_settings.h +2 -2
  67. data/src/core/ext/transport/chttp2/transport/frame_window_update.c +17 -9
  68. data/src/core/ext/transport/chttp2/transport/frame_window_update.h +2 -2
  69. data/src/core/ext/transport/chttp2/transport/hpack_parser.c +365 -287
  70. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +8 -6
  71. data/src/core/ext/transport/chttp2/transport/hpack_table.c +24 -20
  72. data/src/core/ext/transport/chttp2/transport/hpack_table.h +5 -4
  73. data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +1 -0
  74. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +1 -0
  75. data/src/core/ext/transport/chttp2/transport/internal.h +34 -32
  76. data/src/core/ext/transport/chttp2/transport/parsing.c +296 -212
  77. data/src/core/ext/transport/chttp2/transport/writing.c +12 -9
  78. data/src/core/lib/channel/channel_args.c +26 -12
  79. data/src/core/lib/channel/channel_args.h +1 -1
  80. data/src/core/lib/channel/channel_stack.c +12 -8
  81. data/src/core/lib/channel/channel_stack.h +27 -11
  82. data/src/core/lib/channel/channel_stack_builder.c +2 -2
  83. data/src/core/lib/channel/compress_filter.c +26 -31
  84. data/src/core/lib/channel/compress_filter.h +4 -4
  85. data/src/core/lib/channel/connected_channel.c +7 -5
  86. data/src/core/lib/channel/http_client_filter.c +34 -8
  87. data/src/core/lib/channel/http_client_filter.h +1 -1
  88. data/src/core/lib/channel/http_server_filter.c +21 -12
  89. data/src/core/lib/compression/{compression_algorithm.c → compression.c} +22 -21
  90. data/src/core/lib/http/httpcli.c +81 -59
  91. data/src/core/lib/http/httpcli.h +11 -15
  92. data/src/core/lib/http/httpcli_security_connector.c +5 -3
  93. data/src/core/lib/http/parser.c +127 -118
  94. data/src/core/lib/http/parser.h +11 -6
  95. data/src/core/lib/iomgr/closure.c +20 -16
  96. data/src/core/lib/iomgr/closure.h +19 -15
  97. data/src/core/lib/iomgr/endpoint.h +1 -1
  98. data/src/core/lib/iomgr/endpoint_pair_posix.c +2 -2
  99. data/src/core/lib/iomgr/error.c +535 -0
  100. data/src/core/lib/iomgr/error.h +192 -0
  101. data/src/core/lib/iomgr/ev_poll_and_epoll_posix.c +190 -83
  102. data/src/core/lib/iomgr/ev_poll_posix.c +1267 -0
  103. data/src/{ruby/ext/grpc/rb_signal.h → core/lib/iomgr/ev_poll_posix.h} +7 -5
  104. data/src/core/lib/iomgr/ev_posix.c +104 -14
  105. data/src/core/lib/iomgr/ev_posix.h +17 -7
  106. data/src/core/lib/iomgr/exec_ctx.c +25 -7
  107. data/src/core/lib/iomgr/exec_ctx.h +27 -8
  108. data/src/core/lib/iomgr/executor.c +2 -2
  109. data/src/core/lib/iomgr/executor.h +1 -1
  110. data/src/core/lib/iomgr/iocp_windows.c +2 -41
  111. data/src/core/lib/iomgr/iocp_windows.h +0 -8
  112. data/src/core/lib/iomgr/iomgr.c +5 -4
  113. data/src/core/lib/iomgr/iomgr_posix.c +5 -1
  114. data/src/core/lib/iomgr/iomgr_windows.c +1 -1
  115. data/src/core/lib/{support → iomgr}/load_file.c +15 -17
  116. data/src/core/lib/{support → iomgr}/load_file.h +8 -7
  117. data/src/core/lib/iomgr/polling_entity.c +104 -0
  118. data/src/core/lib/iomgr/polling_entity.h +81 -0
  119. data/src/core/lib/iomgr/pollset.h +6 -5
  120. data/src/core/lib/iomgr/pollset_set_windows.c +4 -1
  121. data/src/core/lib/iomgr/pollset_windows.c +10 -6
  122. data/src/core/lib/iomgr/resolve_address.h +5 -9
  123. data/src/core/lib/iomgr/resolve_address_posix.c +55 -38
  124. data/src/core/lib/iomgr/resolve_address_windows.c +51 -37
  125. data/src/core/lib/iomgr/sockaddr.h +2 -2
  126. data/src/core/lib/iomgr/{sockaddr_win32.h → sockaddr_windows.h} +3 -3
  127. data/src/core/lib/iomgr/socket_utils_common_posix.c +92 -45
  128. data/src/core/lib/iomgr/socket_utils_posix.h +19 -12
  129. data/src/core/lib/iomgr/socket_windows.c +61 -2
  130. data/src/core/lib/iomgr/socket_windows.h +13 -0
  131. data/src/core/lib/iomgr/tcp_client_posix.c +54 -39
  132. data/src/core/lib/iomgr/tcp_client_windows.c +34 -34
  133. data/src/core/lib/iomgr/tcp_posix.c +43 -39
  134. data/src/core/lib/iomgr/tcp_server.h +5 -3
  135. data/src/core/lib/iomgr/tcp_server_posix.c +103 -64
  136. data/src/core/lib/iomgr/tcp_server_windows.c +114 -101
  137. data/src/core/lib/iomgr/tcp_windows.c +45 -50
  138. data/src/core/lib/iomgr/tcp_windows.h +1 -1
  139. data/src/core/lib/iomgr/timer.c +26 -13
  140. data/src/core/lib/iomgr/udp_server.c +28 -4
  141. data/src/core/lib/iomgr/udp_server.h +5 -1
  142. data/src/core/lib/iomgr/unix_sockets_posix.c +8 -7
  143. data/src/core/lib/iomgr/unix_sockets_posix.h +2 -1
  144. data/src/core/lib/iomgr/unix_sockets_posix_noop.c +4 -2
  145. data/src/core/lib/iomgr/wakeup_fd_eventfd.c +15 -5
  146. data/src/core/lib/iomgr/wakeup_fd_pipe.c +13 -9
  147. data/src/core/lib/iomgr/wakeup_fd_posix.c +6 -6
  148. data/src/core/lib/iomgr/wakeup_fd_posix.h +9 -6
  149. data/src/core/lib/iomgr/workqueue.h +5 -4
  150. data/src/core/lib/iomgr/workqueue_posix.c +40 -26
  151. data/src/core/lib/iomgr/workqueue_windows.c +2 -2
  152. data/src/core/lib/profiling/basic_timers.c +2 -2
  153. data/src/core/lib/security/{security_context.c → context/security_context.c} +1 -1
  154. data/src/core/lib/security/{security_context.h → context/security_context.h} +4 -4
  155. data/src/core/lib/security/credentials/composite/composite_credentials.c +263 -0
  156. data/src/core/lib/security/credentials/composite/composite_credentials.h +72 -0
  157. data/src/core/lib/security/credentials/credentials.c +233 -0
  158. data/src/core/lib/security/{credentials.h → credentials/credentials.h} +19 -157
  159. data/src/core/lib/security/{credentials_metadata.c → credentials/credentials_metadata.c} +1 -1
  160. data/src/core/lib/security/credentials/fake/fake_credentials.c +139 -0
  161. data/src/core/lib/security/credentials/fake/fake_credentials.h +56 -0
  162. data/src/core/lib/security/{credentials_posix.c → credentials/google_default/credentials_posix.c} +1 -1
  163. data/src/core/lib/security/{credentials_win32.c → credentials/google_default/credentials_windows.c} +3 -3
  164. data/src/core/lib/security/{google_default_credentials.c → credentials/google_default/google_default_credentials.c} +93 -35
  165. data/src/core/lib/security/credentials/google_default/google_default_credentials.h +46 -0
  166. data/src/core/lib/security/credentials/iam/iam_credentials.c +85 -0
  167. data/src/core/lib/security/credentials/iam/iam_credentials.h +44 -0
  168. data/src/core/lib/security/{json_token.c → credentials/jwt/json_token.c} +10 -101
  169. data/src/core/lib/security/{json_token.h → credentials/jwt/json_token.h} +3 -33
  170. data/src/core/lib/security/credentials/jwt/jwt_credentials.c +160 -0
  171. data/src/core/lib/security/credentials/jwt/jwt_credentials.h +62 -0
  172. data/src/core/lib/security/{jwt_verifier.c → credentials/jwt/jwt_verifier.c} +35 -15
  173. data/src/core/lib/security/{jwt_verifier.h → credentials/jwt/jwt_verifier.h} +3 -3
  174. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +433 -0
  175. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +109 -0
  176. data/src/core/lib/security/credentials/plugin/plugin_credentials.c +129 -0
  177. data/src/core/lib/security/credentials/plugin/plugin_credentials.h +45 -0
  178. data/src/core/lib/security/credentials/ssl/ssl_credentials.c +240 -0
  179. data/src/core/lib/security/credentials/ssl/ssl_credentials.h +48 -0
  180. data/src/core/lib/security/{auth_filters.h → transport/auth_filters.h} +3 -3
  181. data/src/core/lib/security/{client_auth_filter.c → transport/client_auth_filter.c} +27 -20
  182. data/src/core/lib/security/{handshake.c → transport/handshake.c} +77 -45
  183. data/src/core/lib/security/{handshake.h → transport/handshake.h} +9 -11
  184. data/src/core/lib/security/{secure_endpoint.c → transport/secure_endpoint.c} +19 -12
  185. data/src/core/lib/security/{secure_endpoint.h → transport/secure_endpoint.h} +3 -3
  186. data/src/core/lib/security/{security_connector.c → transport/security_connector.c} +26 -17
  187. data/src/core/lib/security/{security_connector.h → transport/security_connector.h} +8 -8
  188. data/src/core/lib/security/{server_auth_filter.c → transport/server_auth_filter.c} +24 -16
  189. data/src/core/lib/security/transport/tsi_error.c +40 -0
  190. data/src/core/lib/security/transport/tsi_error.h +42 -0
  191. data/src/core/lib/security/{b64.c → util/b64.c} +1 -1
  192. data/src/core/lib/security/{b64.h → util/b64.h} +3 -3
  193. data/src/core/lib/security/util/json_util.c +61 -0
  194. data/src/core/lib/security/util/json_util.h +55 -0
  195. data/src/core/lib/support/avl.c +11 -0
  196. data/src/core/lib/support/cpu_windows.c +2 -2
  197. data/src/core/lib/support/{env_win32.c → env_windows.c} +3 -3
  198. data/src/core/lib/support/log.c +3 -1
  199. data/src/core/lib/support/log_linux.c +2 -2
  200. data/src/core/lib/support/{log_win32.c → log_windows.c} +4 -4
  201. data/src/core/lib/support/murmur_hash.c +3 -5
  202. data/src/core/lib/support/string.c +10 -0
  203. data/src/core/lib/support/string.h +4 -0
  204. data/src/core/lib/support/{string_util_win32.c → string_util_windows.c} +3 -3
  205. data/src/core/lib/support/{string_win32.c → string_windows.c} +2 -2
  206. data/src/core/lib/support/{string_win32.h → string_windows.h} +5 -5
  207. data/src/core/lib/support/subprocess_windows.c +1 -1
  208. data/src/core/lib/support/{sync_win32.c → sync_windows.c} +2 -2
  209. data/src/core/lib/support/{thd_win32.c → thd_windows.c} +2 -2
  210. data/src/core/lib/support/{time_win32.c → time_windows.c} +2 -2
  211. data/src/core/lib/support/tmpfile_msys.c +1 -1
  212. data/src/core/lib/support/{tmpfile_win32.c → tmpfile_windows.c} +3 -3
  213. data/src/core/lib/surface/alarm.c +2 -2
  214. data/src/core/lib/surface/byte_buffer_reader.c +13 -6
  215. data/src/core/lib/surface/call.c +323 -123
  216. data/src/core/lib/surface/call.h +2 -0
  217. data/src/core/lib/surface/call_log_batch.c +1 -1
  218. data/src/core/lib/surface/channel.c +64 -15
  219. data/src/core/lib/surface/channel.h +9 -0
  220. data/src/core/lib/surface/channel_ping.c +3 -3
  221. data/src/core/lib/surface/completion_queue.c +75 -19
  222. data/src/core/lib/surface/completion_queue.h +7 -2
  223. data/src/core/lib/surface/init.c +2 -1
  224. data/src/core/lib/surface/init_secure.c +4 -4
  225. data/src/core/lib/surface/lame_client.c +12 -8
  226. data/src/core/lib/surface/server.c +213 -120
  227. data/src/core/lib/surface/server.h +1 -0
  228. data/src/core/lib/surface/version.c +1 -1
  229. data/src/core/lib/transport/connectivity_state.c +40 -18
  230. data/src/core/lib/transport/connectivity_state.h +4 -1
  231. data/src/core/lib/transport/metadata.c +23 -23
  232. data/src/core/lib/transport/metadata.h +4 -0
  233. data/src/core/lib/transport/metadata_batch.c +9 -0
  234. data/src/core/lib/transport/metadata_batch.h +3 -0
  235. data/src/core/lib/transport/static_metadata.c +6 -5
  236. data/src/core/lib/transport/static_metadata.h +64 -60
  237. data/src/core/lib/transport/transport.c +24 -12
  238. data/src/core/lib/transport/transport.h +6 -5
  239. data/src/core/lib/transport/transport_impl.h +4 -0
  240. data/src/core/lib/transport/transport_op_string.c +2 -2
  241. data/src/core/plugin_registry/grpc_plugin_registry.c +4 -0
  242. data/src/ruby/bin/math_services.rb +41 -2
  243. data/src/ruby/ext/grpc/rb_call.c +42 -40
  244. data/src/ruby/ext/grpc/rb_channel.c +1 -1
  245. data/src/ruby/ext/grpc/rb_completion_queue.c +59 -6
  246. data/src/ruby/ext/grpc/rb_completion_queue.h +1 -1
  247. data/src/ruby/ext/grpc/rb_grpc.c +1 -3
  248. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +12 -2
  249. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +21 -5
  250. data/src/ruby/ext/grpc/rb_loader.c +1 -1
  251. data/src/ruby/ext/grpc/rb_server.c +5 -3
  252. data/src/ruby/lib/grpc.rb +0 -3
  253. data/src/ruby/lib/grpc/errors.rb +3 -2
  254. data/src/ruby/lib/grpc/generic/active_call.rb +32 -42
  255. data/src/ruby/lib/grpc/generic/bidi_call.rb +20 -0
  256. data/src/ruby/lib/grpc/generic/client_stub.rb +31 -54
  257. data/src/ruby/lib/grpc/generic/rpc_desc.rb +4 -4
  258. data/src/ruby/lib/grpc/generic/rpc_server.rb +12 -23
  259. data/src/ruby/lib/grpc/generic/service.rb +8 -8
  260. data/src/ruby/lib/grpc/version.rb +1 -1
  261. data/src/ruby/pb/grpc/health/v1/health_services.rb +30 -2
  262. data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services.rb +34 -4
  263. data/src/ruby/pb/grpc/testing/metrics_services.rb +39 -2
  264. data/src/ruby/pb/src/proto/grpc/testing/empty.rb +15 -0
  265. data/src/ruby/pb/src/proto/grpc/testing/messages.rb +84 -0
  266. data/src/ruby/pb/src/proto/grpc/testing/test.rb +14 -0
  267. data/src/ruby/pb/src/proto/grpc/testing/test_services.rb +110 -0
  268. data/src/ruby/pb/test/client.rb +5 -2
  269. data/src/ruby/spec/generic/active_call_spec.rb +3 -2
  270. data/src/ruby/spec/generic/client_stub_spec.rb +27 -24
  271. data/src/ruby/spec/generic/rpc_desc_spec.rb +11 -11
  272. data/src/ruby/spec/generic/rpc_server_spec.rb +42 -61
  273. data/src/ruby/spec/pb/health/checker_spec.rb +3 -5
  274. metadata +86 -48
  275. data/src/core/ext/lb_policy/grpclb/proto/grpc/lb/v0/load_balancer.pb.h +0 -182
  276. data/src/core/lib/security/credentials.c +0 -1296
  277. data/src/ruby/lib/grpc/signals.rb +0 -69
@@ -41,6 +41,7 @@
41
41
  #include "src/core/lib/http/parser.h"
42
42
  #include "src/core/lib/iomgr/endpoint.h"
43
43
  #include "src/core/lib/iomgr/iomgr_internal.h"
44
+ #include "src/core/lib/iomgr/polling_entity.h"
44
45
  #include "src/core/lib/iomgr/pollset_set.h"
45
46
 
46
47
  /* User agent this library reports */
@@ -56,7 +57,7 @@ typedef struct grpc_httpcli_context {
56
57
  typedef struct {
57
58
  const char *default_port;
58
59
  void (*handshake)(grpc_exec_ctx *exec_ctx, void *arg, grpc_endpoint *endpoint,
59
- const char *host,
60
+ const char *host, gpr_timespec deadline,
60
61
  void (*on_done)(grpc_exec_ctx *exec_ctx, void *arg,
61
62
  grpc_endpoint *endpoint));
62
63
  } grpc_httpcli_handshaker;
@@ -81,11 +82,6 @@ typedef struct grpc_httpcli_request {
81
82
  /* Expose the parser response type as a httpcli response too */
82
83
  typedef struct grpc_http_response grpc_httpcli_response;
83
84
 
84
- /* Callback for grpc_httpcli_get and grpc_httpcli_post. */
85
- typedef void (*grpc_httpcli_response_cb)(grpc_exec_ctx *exec_ctx,
86
- void *user_data,
87
- const grpc_http_response *response);
88
-
89
85
  void grpc_httpcli_context_init(grpc_httpcli_context *context);
90
86
  void grpc_httpcli_context_destroy(grpc_httpcli_context *context);
91
87
 
@@ -100,10 +96,10 @@ void grpc_httpcli_context_destroy(grpc_httpcli_context *context);
100
96
  'on_response' is a callback to report results to (and 'user_data' is a user
101
97
  supplied pointer to pass to said call) */
102
98
  void grpc_httpcli_get(grpc_exec_ctx *exec_ctx, grpc_httpcli_context *context,
103
- grpc_pollset *pollset,
99
+ grpc_polling_entity *pollent,
104
100
  const grpc_httpcli_request *request,
105
- gpr_timespec deadline,
106
- grpc_httpcli_response_cb on_response, void *user_data);
101
+ gpr_timespec deadline, grpc_closure *on_complete,
102
+ grpc_httpcli_response *response);
107
103
 
108
104
  /* Asynchronously perform a HTTP POST.
109
105
  'context' specifies the http context under which to do the post
@@ -121,22 +117,22 @@ void grpc_httpcli_get(grpc_exec_ctx *exec_ctx, grpc_httpcli_context *context,
121
117
  supplied pointer to pass to said call)
122
118
  Does not support ?var1=val1&var2=val2 in the path. */
123
119
  void grpc_httpcli_post(grpc_exec_ctx *exec_ctx, grpc_httpcli_context *context,
124
- grpc_pollset *pollset,
120
+ grpc_polling_entity *pollent,
125
121
  const grpc_httpcli_request *request,
126
122
  const char *body_bytes, size_t body_size,
127
- gpr_timespec deadline,
128
- grpc_httpcli_response_cb on_response, void *user_data);
123
+ gpr_timespec deadline, grpc_closure *on_complete,
124
+ grpc_httpcli_response *response);
129
125
 
130
126
  /* override functions return 1 if they handled the request, 0 otherwise */
131
127
  typedef int (*grpc_httpcli_get_override)(grpc_exec_ctx *exec_ctx,
132
128
  const grpc_httpcli_request *request,
133
129
  gpr_timespec deadline,
134
- grpc_httpcli_response_cb on_response,
135
- void *user_data);
130
+ grpc_closure *on_complete,
131
+ grpc_httpcli_response *response);
136
132
  typedef int (*grpc_httpcli_post_override)(
137
133
  grpc_exec_ctx *exec_ctx, const grpc_httpcli_request *request,
138
134
  const char *body_bytes, size_t body_size, gpr_timespec deadline,
139
- grpc_httpcli_response_cb on_response, void *user_data);
135
+ grpc_closure *on_complete, grpc_httpcli_response *response);
140
136
 
141
137
  void grpc_httpcli_set_override(grpc_httpcli_get_override get,
142
138
  grpc_httpcli_post_override post);
@@ -38,7 +38,7 @@
38
38
  #include <grpc/support/alloc.h>
39
39
  #include <grpc/support/log.h>
40
40
  #include <grpc/support/string_util.h>
41
- #include "src/core/lib/security/handshake.h"
41
+ #include "src/core/lib/security/transport/handshake.h"
42
42
  #include "src/core/lib/support/string.h"
43
43
  #include "src/core/lib/tsi/ssl_transport_security.h"
44
44
 
@@ -61,6 +61,7 @@ static void httpcli_ssl_destroy(grpc_security_connector *sc) {
61
61
  static void httpcli_ssl_do_handshake(grpc_exec_ctx *exec_ctx,
62
62
  grpc_channel_security_connector *sc,
63
63
  grpc_endpoint *nonsecure_endpoint,
64
+ gpr_timespec deadline,
64
65
  grpc_security_handshake_done_cb cb,
65
66
  void *user_data) {
66
67
  grpc_httpcli_ssl_channel_security_connector *c =
@@ -79,7 +80,7 @@ static void httpcli_ssl_do_handshake(grpc_exec_ctx *exec_ctx,
79
80
  cb(exec_ctx, user_data, GRPC_SECURITY_ERROR, NULL, NULL);
80
81
  } else {
81
82
  grpc_do_security_handshake(exec_ctx, handshaker, &sc->base, true,
82
- nonsecure_endpoint, cb, user_data);
83
+ nonsecure_endpoint, deadline, cb, user_data);
83
84
  }
84
85
  }
85
86
 
@@ -163,6 +164,7 @@ static void on_secure_transport_setup_done(grpc_exec_ctx *exec_ctx, void *rp,
163
164
 
164
165
  static void ssl_handshake(grpc_exec_ctx *exec_ctx, void *arg,
165
166
  grpc_endpoint *tcp, const char *host,
167
+ gpr_timespec deadline,
166
168
  void (*on_done)(grpc_exec_ctx *exec_ctx, void *arg,
167
169
  grpc_endpoint *endpoint)) {
168
170
  grpc_channel_security_connector *sc = NULL;
@@ -181,7 +183,7 @@ static void ssl_handshake(grpc_exec_ctx *exec_ctx, void *arg,
181
183
  pem_root_certs, pem_root_certs_size, host, &sc) ==
182
184
  GRPC_SECURITY_OK);
183
185
  grpc_channel_security_connector_do_handshake(
184
- exec_ctx, sc, tcp, on_secure_transport_setup_done, c);
186
+ exec_ctx, sc, tcp, deadline, on_secure_transport_setup_done, c);
185
187
  GRPC_SECURITY_CONNECTOR_UNREF(&sc->base, "httpcli");
186
188
  }
187
189
 
@@ -48,37 +48,38 @@ static char *buf2str(void *buffer, size_t length) {
48
48
  return out;
49
49
  }
50
50
 
51
- static int handle_response_line(grpc_http_parser *parser) {
51
+ static grpc_error *handle_response_line(grpc_http_parser *parser) {
52
52
  uint8_t *beg = parser->cur_line;
53
53
  uint8_t *cur = beg;
54
54
  uint8_t *end = beg + parser->cur_line_length;
55
55
 
56
- if (cur == end || *cur++ != 'H') goto error;
57
- if (cur == end || *cur++ != 'T') goto error;
58
- if (cur == end || *cur++ != 'T') goto error;
59
- if (cur == end || *cur++ != 'P') goto error;
60
- if (cur == end || *cur++ != '/') goto error;
61
- if (cur == end || *cur++ != '1') goto error;
62
- if (cur == end || *cur++ != '.') goto error;
63
- if (cur == end || *cur < '0' || *cur++ > '1') goto error;
64
- if (cur == end || *cur++ != ' ') goto error;
65
- if (cur == end || *cur < '1' || *cur++ > '9') goto error;
66
- if (cur == end || *cur < '0' || *cur++ > '9') goto error;
67
- if (cur == end || *cur < '0' || *cur++ > '9') goto error;
68
- parser->http.response.status =
56
+ if (cur == end || *cur++ != 'H') return GRPC_ERROR_CREATE("Expected 'H'");
57
+ if (cur == end || *cur++ != 'T') return GRPC_ERROR_CREATE("Expected 'T'");
58
+ if (cur == end || *cur++ != 'T') return GRPC_ERROR_CREATE("Expected 'T'");
59
+ if (cur == end || *cur++ != 'P') return GRPC_ERROR_CREATE("Expected 'P'");
60
+ if (cur == end || *cur++ != '/') return GRPC_ERROR_CREATE("Expected '/'");
61
+ if (cur == end || *cur++ != '1') return GRPC_ERROR_CREATE("Expected '1'");
62
+ if (cur == end || *cur++ != '.') return GRPC_ERROR_CREATE("Expected '.'");
63
+ if (cur == end || *cur < '0' || *cur++ > '1') {
64
+ return GRPC_ERROR_CREATE("Expected HTTP/1.0 or HTTP/1.1");
65
+ }
66
+ if (cur == end || *cur++ != ' ') return GRPC_ERROR_CREATE("Expected ' '");
67
+ if (cur == end || *cur < '1' || *cur++ > '9')
68
+ return GRPC_ERROR_CREATE("Expected status code");
69
+ if (cur == end || *cur < '0' || *cur++ > '9')
70
+ return GRPC_ERROR_CREATE("Expected status code");
71
+ if (cur == end || *cur < '0' || *cur++ > '9')
72
+ return GRPC_ERROR_CREATE("Expected status code");
73
+ parser->http.response->status =
69
74
  (cur[-3] - '0') * 100 + (cur[-2] - '0') * 10 + (cur[-1] - '0');
70
- if (cur == end || *cur++ != ' ') goto error;
75
+ if (cur == end || *cur++ != ' ') return GRPC_ERROR_CREATE("Expected ' '");
71
76
 
72
77
  /* we don't really care about the status code message */
73
78
 
74
- return 1;
75
-
76
- error:
77
- if (grpc_http1_trace) gpr_log(GPR_ERROR, "Failed parsing response line");
78
- return 0;
79
+ return GRPC_ERROR_NONE;
79
80
  }
80
81
 
81
- static int handle_request_line(grpc_http_parser *parser) {
82
+ static grpc_error *handle_request_line(grpc_http_parser *parser) {
82
83
  uint8_t *beg = parser->cur_line;
83
84
  uint8_t *cur = beg;
84
85
  uint8_t *end = beg + parser->cur_line_length;
@@ -87,83 +88,81 @@ static int handle_request_line(grpc_http_parser *parser) {
87
88
 
88
89
  while (cur != end && *cur++ != ' ')
89
90
  ;
90
- if (cur == end) goto error;
91
- parser->http.request.method = buf2str(beg, (size_t)(cur - beg - 1));
91
+ if (cur == end) return GRPC_ERROR_CREATE("No method on HTTP request line");
92
+ parser->http.request->method = buf2str(beg, (size_t)(cur - beg - 1));
92
93
 
93
94
  beg = cur;
94
95
  while (cur != end && *cur++ != ' ')
95
96
  ;
96
- if (cur == end) goto error;
97
- parser->http.request.path = buf2str(beg, (size_t)(cur - beg - 1));
98
-
99
- if (cur == end || *cur++ != 'H') goto error;
100
- if (cur == end || *cur++ != 'T') goto error;
101
- if (cur == end || *cur++ != 'T') goto error;
102
- if (cur == end || *cur++ != 'P') goto error;
103
- if (cur == end || *cur++ != '/') goto error;
97
+ if (cur == end) return GRPC_ERROR_CREATE("No path on HTTP request line");
98
+ parser->http.request->path = buf2str(beg, (size_t)(cur - beg - 1));
99
+
100
+ if (cur == end || *cur++ != 'H') return GRPC_ERROR_CREATE("Expected 'H'");
101
+ if (cur == end || *cur++ != 'T') return GRPC_ERROR_CREATE("Expected 'T'");
102
+ if (cur == end || *cur++ != 'T') return GRPC_ERROR_CREATE("Expected 'T'");
103
+ if (cur == end || *cur++ != 'P') return GRPC_ERROR_CREATE("Expected 'P'");
104
+ if (cur == end || *cur++ != '/') return GRPC_ERROR_CREATE("Expected '/'");
104
105
  vers_major = (uint8_t)(*cur++ - '1' + 1);
105
106
  ++cur;
106
- if (cur == end) goto error;
107
+ if (cur == end)
108
+ return GRPC_ERROR_CREATE("End of line in HTTP version string");
107
109
  vers_minor = (uint8_t)(*cur++ - '1' + 1);
108
110
 
109
111
  if (vers_major == 1) {
110
112
  if (vers_minor == 0) {
111
- parser->http.request.version = GRPC_HTTP_HTTP10;
113
+ parser->http.request->version = GRPC_HTTP_HTTP10;
112
114
  } else if (vers_minor == 1) {
113
- parser->http.request.version = GRPC_HTTP_HTTP11;
115
+ parser->http.request->version = GRPC_HTTP_HTTP11;
114
116
  } else {
115
- goto error;
117
+ return GRPC_ERROR_CREATE(
118
+ "Expected one of HTTP/1.0, HTTP/1.1, or HTTP/2.0");
116
119
  }
117
120
  } else if (vers_major == 2) {
118
121
  if (vers_minor == 0) {
119
- parser->http.request.version = GRPC_HTTP_HTTP20;
122
+ parser->http.request->version = GRPC_HTTP_HTTP20;
120
123
  } else {
121
- goto error;
124
+ return GRPC_ERROR_CREATE(
125
+ "Expected one of HTTP/1.0, HTTP/1.1, or HTTP/2.0");
122
126
  }
123
127
  } else {
124
- goto error;
128
+ return GRPC_ERROR_CREATE("Expected one of HTTP/1.0, HTTP/1.1, or HTTP/2.0");
125
129
  }
126
130
 
127
- return 1;
128
-
129
- error:
130
- if (grpc_http1_trace) gpr_log(GPR_ERROR, "Failed parsing request line");
131
- return 0;
131
+ return GRPC_ERROR_NONE;
132
132
  }
133
133
 
134
- static int handle_first_line(grpc_http_parser *parser) {
135
- if (parser->cur_line[0] == 'H') {
136
- parser->type = GRPC_HTTP_RESPONSE;
137
- return handle_response_line(parser);
138
- } else {
139
- parser->type = GRPC_HTTP_REQUEST;
140
- return handle_request_line(parser);
134
+ static grpc_error *handle_first_line(grpc_http_parser *parser) {
135
+ switch (parser->type) {
136
+ case GRPC_HTTP_REQUEST:
137
+ return handle_request_line(parser);
138
+ case GRPC_HTTP_RESPONSE:
139
+ return handle_response_line(parser);
141
140
  }
141
+ GPR_UNREACHABLE_CODE(return GRPC_ERROR_CREATE("Should never reach here"));
142
142
  }
143
143
 
144
- static int add_header(grpc_http_parser *parser) {
144
+ static grpc_error *add_header(grpc_http_parser *parser) {
145
145
  uint8_t *beg = parser->cur_line;
146
146
  uint8_t *cur = beg;
147
147
  uint8_t *end = beg + parser->cur_line_length;
148
148
  size_t *hdr_count = NULL;
149
149
  grpc_http_header **hdrs = NULL;
150
150
  grpc_http_header hdr = {NULL, NULL};
151
+ grpc_error *error = GRPC_ERROR_NONE;
151
152
 
152
153
  GPR_ASSERT(cur != end);
153
154
 
154
155
  if (*cur == ' ' || *cur == '\t') {
155
- if (grpc_http1_trace)
156
- gpr_log(GPR_ERROR, "Continued header lines not supported yet");
157
- goto error;
156
+ error = GRPC_ERROR_CREATE("Continued header lines not supported yet");
157
+ goto done;
158
158
  }
159
159
 
160
160
  while (cur != end && *cur != ':') {
161
161
  cur++;
162
162
  }
163
163
  if (cur == end) {
164
- if (grpc_http1_trace)
165
- gpr_log(GPR_ERROR, "Didn't find ':' in header string");
166
- goto error;
164
+ error = GRPC_ERROR_CREATE("Didn't find ':' in header string");
165
+ goto done;
167
166
  }
168
167
  GPR_ASSERT(cur >= beg);
169
168
  hdr.key = buf2str(beg, (size_t)(cur - beg));
@@ -175,14 +174,15 @@ static int add_header(grpc_http_parser *parser) {
175
174
  GPR_ASSERT((size_t)(end - cur) >= parser->cur_line_end_length);
176
175
  hdr.value = buf2str(cur, (size_t)(end - cur) - parser->cur_line_end_length);
177
176
 
178
- if (parser->type == GRPC_HTTP_RESPONSE) {
179
- hdr_count = &parser->http.response.hdr_count;
180
- hdrs = &parser->http.response.hdrs;
181
- } else if (parser->type == GRPC_HTTP_REQUEST) {
182
- hdr_count = &parser->http.request.hdr_count;
183
- hdrs = &parser->http.request.hdrs;
184
- } else {
185
- return 0;
177
+ switch (parser->type) {
178
+ case GRPC_HTTP_RESPONSE:
179
+ hdr_count = &parser->http.response->hdr_count;
180
+ hdrs = &parser->http.response->hdrs;
181
+ break;
182
+ case GRPC_HTTP_REQUEST:
183
+ hdr_count = &parser->http.request->hdr_count;
184
+ hdrs = &parser->http.request->hdrs;
185
+ break;
186
186
  }
187
187
 
188
188
  if (*hdr_count == parser->hdr_capacity) {
@@ -191,20 +191,21 @@ static int add_header(grpc_http_parser *parser) {
191
191
  *hdrs = gpr_realloc(*hdrs, parser->hdr_capacity * sizeof(**hdrs));
192
192
  }
193
193
  (*hdrs)[(*hdr_count)++] = hdr;
194
- return 1;
195
194
 
196
- error:
197
- gpr_free(hdr.key);
198
- gpr_free(hdr.value);
199
- return 0;
195
+ done:
196
+ if (error != GRPC_ERROR_NONE) {
197
+ gpr_free(hdr.key);
198
+ gpr_free(hdr.value);
199
+ }
200
+ return error;
200
201
  }
201
202
 
202
- static int finish_line(grpc_http_parser *parser) {
203
+ static grpc_error *finish_line(grpc_http_parser *parser) {
204
+ grpc_error *err;
203
205
  switch (parser->state) {
204
206
  case GRPC_HTTP_FIRST_LINE:
205
- if (!handle_first_line(parser)) {
206
- return 0;
207
- }
207
+ err = handle_first_line(parser);
208
+ if (err != GRPC_ERROR_NONE) return err;
208
209
  parser->state = GRPC_HTTP_HEADERS;
209
210
  break;
210
211
  case GRPC_HTTP_HEADERS:
@@ -212,30 +213,31 @@ static int finish_line(grpc_http_parser *parser) {
212
213
  parser->state = GRPC_HTTP_BODY;
213
214
  break;
214
215
  }
215
- if (!add_header(parser)) {
216
- return 0;
216
+ err = add_header(parser);
217
+ if (err != GRPC_ERROR_NONE) {
218
+ return err;
217
219
  }
218
220
  break;
219
221
  case GRPC_HTTP_BODY:
220
- GPR_UNREACHABLE_CODE(return 0);
222
+ GPR_UNREACHABLE_CODE(return GRPC_ERROR_CREATE("Should never reach here"));
221
223
  }
222
224
 
223
225
  parser->cur_line_length = 0;
224
- return 1;
226
+ return GRPC_ERROR_NONE;
225
227
  }
226
228
 
227
- static int addbyte_body(grpc_http_parser *parser, uint8_t byte) {
229
+ static grpc_error *addbyte_body(grpc_http_parser *parser, uint8_t byte) {
228
230
  size_t *body_length = NULL;
229
231
  char **body = NULL;
230
232
 
231
233
  if (parser->type == GRPC_HTTP_RESPONSE) {
232
- body_length = &parser->http.response.body_length;
233
- body = &parser->http.response.body;
234
+ body_length = &parser->http.response->body_length;
235
+ body = &parser->http.response->body;
234
236
  } else if (parser->type == GRPC_HTTP_REQUEST) {
235
- body_length = &parser->http.request.body_length;
236
- body = &parser->http.request.body;
237
+ body_length = &parser->http.request->body_length;
238
+ body = &parser->http.request->body;
237
239
  } else {
238
- return 0;
240
+ GPR_UNREACHABLE_CODE(return GRPC_ERROR_CREATE("Should never reach here"));
239
241
  }
240
242
 
241
243
  if (*body_length == parser->body_capacity) {
@@ -245,34 +247,34 @@ static int addbyte_body(grpc_http_parser *parser, uint8_t byte) {
245
247
  (*body)[*body_length] = (char)byte;
246
248
  (*body_length)++;
247
249
 
248
- return 1;
250
+ return GRPC_ERROR_NONE;
249
251
  }
250
252
 
251
- static int check_line(grpc_http_parser *parser) {
253
+ static bool check_line(grpc_http_parser *parser) {
252
254
  if (parser->cur_line_length >= 2 &&
253
255
  parser->cur_line[parser->cur_line_length - 2] == '\r' &&
254
256
  parser->cur_line[parser->cur_line_length - 1] == '\n') {
255
- return 1;
257
+ return true;
256
258
  }
257
259
 
258
260
  // HTTP request with \n\r line termiantors.
259
261
  else if (parser->cur_line_length >= 2 &&
260
262
  parser->cur_line[parser->cur_line_length - 2] == '\n' &&
261
263
  parser->cur_line[parser->cur_line_length - 1] == '\r') {
262
- return 1;
264
+ return true;
263
265
  }
264
266
 
265
267
  // HTTP request with only \n line terminators.
266
268
  else if (parser->cur_line_length >= 1 &&
267
269
  parser->cur_line[parser->cur_line_length - 1] == '\n') {
268
270
  parser->cur_line_end_length = 1;
269
- return 1;
271
+ return true;
270
272
  }
271
273
 
272
- return 0;
274
+ return false;
273
275
  }
274
276
 
275
- static int addbyte(grpc_http_parser *parser, uint8_t byte) {
277
+ static grpc_error *addbyte(grpc_http_parser *parser, uint8_t byte) {
276
278
  switch (parser->state) {
277
279
  case GRPC_HTTP_FIRST_LINE:
278
280
  case GRPC_HTTP_HEADERS:
@@ -287,7 +289,7 @@ static int addbyte(grpc_http_parser *parser, uint8_t byte) {
287
289
  if (check_line(parser)) {
288
290
  return finish_line(parser);
289
291
  } else {
290
- return 1;
292
+ return GRPC_ERROR_NONE;
291
293
  }
292
294
  GPR_UNREACHABLE_CODE(return 0);
293
295
  case GRPC_HTTP_BODY:
@@ -296,46 +298,53 @@ static int addbyte(grpc_http_parser *parser, uint8_t byte) {
296
298
  GPR_UNREACHABLE_CODE(return 0);
297
299
  }
298
300
 
299
- void grpc_http_parser_init(grpc_http_parser *parser) {
301
+ void grpc_http_parser_init(grpc_http_parser *parser, grpc_http_type type,
302
+ void *request_or_response) {
300
303
  memset(parser, 0, sizeof(*parser));
301
304
  parser->state = GRPC_HTTP_FIRST_LINE;
302
- parser->type = GRPC_HTTP_UNKNOWN;
305
+ parser->type = type;
306
+ parser->http.request_or_response = request_or_response;
303
307
  parser->cur_line_end_length = 2;
304
308
  }
305
309
 
306
- void grpc_http_parser_destroy(grpc_http_parser *parser) {
310
+ void grpc_http_parser_destroy(grpc_http_parser *parser) {}
311
+
312
+ void grpc_http_request_destroy(grpc_http_request *request) {
307
313
  size_t i;
308
- if (parser->type == GRPC_HTTP_RESPONSE) {
309
- gpr_free(parser->http.response.body);
310
- for (i = 0; i < parser->http.response.hdr_count; i++) {
311
- gpr_free(parser->http.response.hdrs[i].key);
312
- gpr_free(parser->http.response.hdrs[i].value);
313
- }
314
- gpr_free(parser->http.response.hdrs);
315
- } else if (parser->type == GRPC_HTTP_REQUEST) {
316
- gpr_free(parser->http.request.body);
317
- for (i = 0; i < parser->http.request.hdr_count; i++) {
318
- gpr_free(parser->http.request.hdrs[i].key);
319
- gpr_free(parser->http.request.hdrs[i].value);
320
- }
321
- gpr_free(parser->http.request.hdrs);
322
- gpr_free(parser->http.request.method);
323
- gpr_free(parser->http.request.path);
314
+ gpr_free(request->body);
315
+ for (i = 0; i < request->hdr_count; i++) {
316
+ gpr_free(request->hdrs[i].key);
317
+ gpr_free(request->hdrs[i].value);
324
318
  }
319
+ gpr_free(request->hdrs);
320
+ gpr_free(request->method);
321
+ gpr_free(request->path);
325
322
  }
326
323
 
327
- int grpc_http_parser_parse(grpc_http_parser *parser, gpr_slice slice) {
324
+ void grpc_http_response_destroy(grpc_http_response *response) {
325
+ size_t i;
326
+ gpr_free(response->body);
327
+ for (i = 0; i < response->hdr_count; i++) {
328
+ gpr_free(response->hdrs[i].key);
329
+ gpr_free(response->hdrs[i].value);
330
+ }
331
+ gpr_free(response->hdrs);
332
+ }
333
+
334
+ grpc_error *grpc_http_parser_parse(grpc_http_parser *parser, gpr_slice slice) {
328
335
  size_t i;
329
336
 
330
337
  for (i = 0; i < GPR_SLICE_LENGTH(slice); i++) {
331
- if (!addbyte(parser, GPR_SLICE_START_PTR(slice)[i])) {
332
- return 0;
333
- }
338
+ grpc_error *err = addbyte(parser, GPR_SLICE_START_PTR(slice)[i]);
339
+ if (err != GRPC_ERROR_NONE) return err;
334
340
  }
335
341
 
336
- return 1;
342
+ return GRPC_ERROR_NONE;
337
343
  }
338
344
 
339
- int grpc_http_parser_eof(grpc_http_parser *parser) {
340
- return parser->state == GRPC_HTTP_BODY;
345
+ grpc_error *grpc_http_parser_eof(grpc_http_parser *parser) {
346
+ if (parser->state != GRPC_HTTP_BODY) {
347
+ return GRPC_ERROR_CREATE("Did not finish headers");
348
+ }
349
+ return GRPC_ERROR_NONE;
341
350
  }