grpc 1.26.0 → 1.27.0.pre1

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 (209) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1654 -1519
  3. data/etc/roots.pem +44 -0
  4. data/include/grpc/grpc_security.h +37 -15
  5. data/include/grpc/grpc_security_constants.h +27 -0
  6. data/include/grpc/impl/codegen/grpc_types.h +14 -0
  7. data/include/grpc/impl/codegen/port_platform.h +1 -1
  8. data/src/core/ext/filters/client_channel/client_channel.cc +0 -20
  9. data/src/core/ext/filters/client_channel/http_proxy.cc +4 -4
  10. data/src/core/ext/filters/client_channel/lb_policy.cc +4 -3
  11. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +191 -201
  12. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.cc +89 -0
  13. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h +40 -0
  14. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +3 -2
  15. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +88 -121
  16. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +28 -57
  17. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +0 -7
  18. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +8 -9
  19. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +53 -34
  20. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +18 -5
  21. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +24 -19
  22. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +2 -1
  23. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +4 -2
  24. data/src/core/ext/filters/client_channel/server_address.cc +6 -9
  25. data/src/core/ext/filters/client_channel/server_address.h +3 -10
  26. data/src/core/ext/filters/client_channel/xds/xds_api.cc +394 -150
  27. data/src/core/ext/filters/client_channel/xds/xds_api.h +75 -35
  28. data/src/core/ext/filters/client_channel/xds/xds_bootstrap.cc +59 -22
  29. data/src/core/ext/filters/client_channel/xds/xds_bootstrap.h +13 -9
  30. data/src/core/ext/filters/client_channel/xds/xds_channel_secure.cc +8 -6
  31. data/src/core/ext/filters/client_channel/xds/xds_client.cc +456 -175
  32. data/src/core/ext/filters/client_channel/xds/xds_client.h +33 -21
  33. data/src/core/ext/filters/client_channel/xds/xds_client_stats.cc +5 -8
  34. data/src/core/ext/filters/client_channel/xds/xds_client_stats.h +18 -24
  35. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +2 -2
  36. data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c +13 -5
  37. data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h +34 -0
  38. data/src/core/lib/channel/channelz.h +11 -1
  39. data/src/core/lib/gpr/time_precise.cc +1 -1
  40. data/src/core/lib/gprpp/optional.h +26 -0
  41. data/src/core/lib/gprpp/string_view.h +14 -10
  42. data/src/core/lib/iomgr/executor.cc +1 -1
  43. data/src/core/lib/iomgr/fork_posix.cc +4 -0
  44. data/src/core/lib/iomgr/poller/eventmanager_libuv.cc +87 -0
  45. data/src/core/lib/iomgr/poller/eventmanager_libuv.h +88 -0
  46. data/src/core/lib/iomgr/socket_utils_common_posix.cc +14 -0
  47. data/src/core/lib/iomgr/socket_utils_posix.h +12 -0
  48. data/src/core/lib/iomgr/tcp_custom.h +3 -0
  49. data/src/core/lib/iomgr/tcp_posix.cc +607 -56
  50. data/src/core/lib/iomgr/tcp_server_custom.cc +15 -2
  51. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +8 -0
  52. data/src/core/lib/json/json.h +11 -1
  53. data/src/core/lib/json/json_reader.cc +206 -28
  54. data/src/core/lib/json/json_writer.cc +111 -24
  55. data/src/core/lib/security/credentials/composite/composite_credentials.cc +7 -0
  56. data/src/core/lib/security/credentials/composite/composite_credentials.h +5 -1
  57. data/src/core/lib/security/credentials/credentials.h +10 -1
  58. data/src/core/lib/security/credentials/fake/fake_credentials.h +2 -1
  59. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +1 -1
  60. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +6 -4
  61. data/src/core/lib/security/credentials/plugin/plugin_credentials.h +2 -1
  62. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +20 -0
  63. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +8 -0
  64. data/src/core/lib/security/credentials/tls/{spiffe_credentials.cc → tls_credentials.cc} +23 -24
  65. data/src/core/lib/security/credentials/tls/{spiffe_credentials.h → tls_credentials.h} +9 -9
  66. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +13 -0
  67. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +22 -2
  68. data/src/core/lib/security/security_connector/load_system_roots_fallback.cc +2 -2
  69. data/src/core/lib/security/security_connector/load_system_roots_linux.cc +2 -2
  70. data/src/core/lib/security/security_connector/local/local_security_connector.cc +30 -3
  71. data/src/core/lib/security/security_connector/ssl_utils.cc +45 -3
  72. data/src/core/lib/security/security_connector/ssl_utils.h +12 -0
  73. data/src/core/lib/security/security_connector/tls/{spiffe_security_connector.cc → tls_security_connector.cc} +82 -69
  74. data/src/core/lib/security/security_connector/tls/{spiffe_security_connector.h → tls_security_connector.h} +17 -18
  75. data/src/core/lib/security/transport/client_auth_filter.cc +33 -0
  76. data/src/core/lib/surface/completion_queue.cc +22 -1
  77. data/src/core/lib/surface/version.cc +1 -1
  78. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +11 -1
  79. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h +1 -1
  80. data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +3 -3
  81. data/src/core/tsi/fake_transport_security.cc +7 -3
  82. data/src/core/tsi/fake_transport_security.h +2 -0
  83. data/src/core/tsi/ssl_transport_security.cc +144 -8
  84. data/src/core/tsi/ssl_transport_security.h +15 -1
  85. data/src/core/tsi/transport_security.cc +13 -0
  86. data/src/core/tsi/transport_security_grpc.cc +2 -2
  87. data/src/core/tsi/transport_security_grpc.h +2 -2
  88. data/src/core/tsi/transport_security_interface.h +12 -0
  89. data/src/ruby/bin/math_pb.rb +5 -5
  90. data/src/ruby/ext/grpc/rb_call_credentials.c +4 -1
  91. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
  92. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +4 -1
  93. data/src/ruby/lib/grpc/version.rb +1 -1
  94. data/src/ruby/pb/grpc/health/v1/health_pb.rb +3 -3
  95. data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +1 -1
  96. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +23 -13
  97. data/third_party/abseil-cpp/absl/algorithm/algorithm.h +159 -0
  98. data/third_party/abseil-cpp/absl/base/attributes.h +609 -0
  99. data/third_party/abseil-cpp/absl/base/call_once.h +226 -0
  100. data/third_party/abseil-cpp/absl/base/casts.h +184 -0
  101. data/third_party/abseil-cpp/absl/base/config.h +622 -0
  102. data/third_party/abseil-cpp/absl/base/const_init.h +76 -0
  103. data/third_party/abseil-cpp/absl/base/dynamic_annotations.cc +129 -0
  104. data/third_party/abseil-cpp/absl/base/dynamic_annotations.h +389 -0
  105. data/third_party/abseil-cpp/absl/base/internal/atomic_hook.h +179 -0
  106. data/third_party/abseil-cpp/absl/base/internal/bits.h +218 -0
  107. data/third_party/abseil-cpp/absl/base/internal/cycleclock.cc +107 -0
  108. data/third_party/abseil-cpp/absl/base/internal/cycleclock.h +94 -0
  109. data/third_party/abseil-cpp/absl/base/internal/endian.h +266 -0
  110. data/third_party/abseil-cpp/absl/base/internal/hide_ptr.h +51 -0
  111. data/third_party/abseil-cpp/absl/base/internal/identity.h +37 -0
  112. data/third_party/abseil-cpp/absl/base/internal/inline_variable.h +107 -0
  113. data/third_party/abseil-cpp/absl/base/internal/invoke.h +187 -0
  114. data/third_party/abseil-cpp/absl/base/internal/low_level_scheduling.h +107 -0
  115. data/third_party/abseil-cpp/absl/base/internal/per_thread_tls.h +52 -0
  116. data/third_party/abseil-cpp/absl/base/internal/raw_logging.cc +237 -0
  117. data/third_party/abseil-cpp/absl/base/internal/raw_logging.h +179 -0
  118. data/third_party/abseil-cpp/absl/base/internal/scheduling_mode.h +58 -0
  119. data/third_party/abseil-cpp/absl/base/internal/spinlock.cc +233 -0
  120. data/third_party/abseil-cpp/absl/base/internal/spinlock.h +243 -0
  121. data/third_party/abseil-cpp/absl/base/internal/spinlock_akaros.inc +35 -0
  122. data/third_party/abseil-cpp/absl/base/internal/spinlock_linux.inc +67 -0
  123. data/third_party/abseil-cpp/absl/base/internal/spinlock_posix.inc +46 -0
  124. data/third_party/abseil-cpp/absl/base/internal/spinlock_wait.cc +81 -0
  125. data/third_party/abseil-cpp/absl/base/internal/spinlock_wait.h +93 -0
  126. data/third_party/abseil-cpp/absl/base/internal/spinlock_win32.inc +37 -0
  127. data/third_party/abseil-cpp/absl/base/internal/sysinfo.cc +414 -0
  128. data/third_party/abseil-cpp/absl/base/internal/sysinfo.h +66 -0
  129. data/third_party/abseil-cpp/absl/base/internal/thread_annotations.h +271 -0
  130. data/third_party/abseil-cpp/absl/base/internal/thread_identity.cc +140 -0
  131. data/third_party/abseil-cpp/absl/base/internal/thread_identity.h +250 -0
  132. data/third_party/abseil-cpp/absl/base/internal/throw_delegate.cc +108 -0
  133. data/third_party/abseil-cpp/absl/base/internal/throw_delegate.h +75 -0
  134. data/third_party/abseil-cpp/absl/base/internal/tsan_mutex_interface.h +66 -0
  135. data/third_party/abseil-cpp/absl/base/internal/unaligned_access.h +158 -0
  136. data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.cc +103 -0
  137. data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.h +124 -0
  138. data/third_party/abseil-cpp/absl/base/log_severity.cc +27 -0
  139. data/third_party/abseil-cpp/absl/base/log_severity.h +121 -0
  140. data/third_party/abseil-cpp/absl/base/macros.h +220 -0
  141. data/third_party/abseil-cpp/absl/base/optimization.h +181 -0
  142. data/third_party/abseil-cpp/absl/base/options.h +214 -0
  143. data/third_party/abseil-cpp/absl/base/policy_checks.h +111 -0
  144. data/third_party/abseil-cpp/absl/base/port.h +26 -0
  145. data/third_party/abseil-cpp/absl/base/thread_annotations.h +280 -0
  146. data/third_party/abseil-cpp/absl/container/inlined_vector.h +848 -0
  147. data/third_party/abseil-cpp/absl/container/internal/compressed_tuple.h +265 -0
  148. data/third_party/abseil-cpp/absl/container/internal/inlined_vector.h +892 -0
  149. data/third_party/abseil-cpp/absl/memory/memory.h +695 -0
  150. data/third_party/abseil-cpp/absl/meta/type_traits.h +759 -0
  151. data/third_party/abseil-cpp/absl/numeric/int128.cc +404 -0
  152. data/third_party/abseil-cpp/absl/numeric/int128.h +1091 -0
  153. data/third_party/abseil-cpp/absl/numeric/int128_have_intrinsic.inc +302 -0
  154. data/third_party/abseil-cpp/absl/numeric/int128_no_intrinsic.inc +308 -0
  155. data/third_party/abseil-cpp/absl/strings/ascii.cc +200 -0
  156. data/third_party/abseil-cpp/absl/strings/ascii.h +241 -0
  157. data/third_party/abseil-cpp/absl/strings/charconv.cc +985 -0
  158. data/third_party/abseil-cpp/absl/strings/charconv.h +119 -0
  159. data/third_party/abseil-cpp/absl/strings/escaping.cc +949 -0
  160. data/third_party/abseil-cpp/absl/strings/escaping.h +164 -0
  161. data/third_party/abseil-cpp/absl/strings/internal/char_map.h +156 -0
  162. data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.cc +359 -0
  163. data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.h +421 -0
  164. data/third_party/abseil-cpp/absl/strings/internal/charconv_parse.cc +504 -0
  165. data/third_party/abseil-cpp/absl/strings/internal/charconv_parse.h +99 -0
  166. data/third_party/abseil-cpp/absl/strings/internal/escaping.cc +180 -0
  167. data/third_party/abseil-cpp/absl/strings/internal/escaping.h +58 -0
  168. data/third_party/abseil-cpp/absl/strings/internal/memutil.cc +112 -0
  169. data/third_party/abseil-cpp/absl/strings/internal/memutil.h +148 -0
  170. data/third_party/abseil-cpp/absl/strings/internal/ostringstream.cc +36 -0
  171. data/third_party/abseil-cpp/absl/strings/internal/ostringstream.h +89 -0
  172. data/third_party/abseil-cpp/absl/strings/internal/resize_uninitialized.h +73 -0
  173. data/third_party/abseil-cpp/absl/strings/internal/stl_type_traits.h +248 -0
  174. data/third_party/abseil-cpp/absl/strings/internal/str_join_internal.h +314 -0
  175. data/third_party/abseil-cpp/absl/strings/internal/str_split_internal.h +455 -0
  176. data/third_party/abseil-cpp/absl/strings/internal/utf8.cc +53 -0
  177. data/third_party/abseil-cpp/absl/strings/internal/utf8.h +50 -0
  178. data/third_party/abseil-cpp/absl/strings/match.cc +40 -0
  179. data/third_party/abseil-cpp/absl/strings/match.h +90 -0
  180. data/third_party/abseil-cpp/absl/strings/numbers.cc +916 -0
  181. data/third_party/abseil-cpp/absl/strings/numbers.h +263 -0
  182. data/third_party/abseil-cpp/absl/strings/str_cat.cc +246 -0
  183. data/third_party/abseil-cpp/absl/strings/str_cat.h +408 -0
  184. data/third_party/abseil-cpp/absl/strings/str_join.h +293 -0
  185. data/third_party/abseil-cpp/absl/strings/str_replace.cc +82 -0
  186. data/third_party/abseil-cpp/absl/strings/str_replace.h +219 -0
  187. data/third_party/abseil-cpp/absl/strings/str_split.cc +139 -0
  188. data/third_party/abseil-cpp/absl/strings/str_split.h +513 -0
  189. data/third_party/abseil-cpp/absl/strings/string_view.cc +235 -0
  190. data/third_party/abseil-cpp/absl/strings/string_view.h +615 -0
  191. data/third_party/abseil-cpp/absl/strings/strip.h +91 -0
  192. data/third_party/abseil-cpp/absl/strings/substitute.cc +171 -0
  193. data/third_party/abseil-cpp/absl/strings/substitute.h +693 -0
  194. data/third_party/abseil-cpp/absl/types/bad_optional_access.cc +48 -0
  195. data/third_party/abseil-cpp/absl/types/bad_optional_access.h +78 -0
  196. data/third_party/abseil-cpp/absl/types/internal/optional.h +396 -0
  197. data/third_party/abseil-cpp/absl/types/internal/span.h +128 -0
  198. data/third_party/abseil-cpp/absl/types/optional.h +776 -0
  199. data/third_party/abseil-cpp/absl/types/span.h +713 -0
  200. data/third_party/abseil-cpp/absl/utility/utility.h +350 -0
  201. data/third_party/upb/upb/decode.c +4 -0
  202. data/third_party/upb/upb/port.c +0 -1
  203. data/third_party/upb/upb/port_def.inc +1 -3
  204. data/third_party/upb/upb/table.c +2 -1
  205. metadata +147 -43
  206. data/src/core/lib/json/json_common.h +0 -34
  207. data/src/core/lib/json/json_reader.h +0 -146
  208. data/src/core/lib/json/json_string.cc +0 -367
  209. data/src/core/lib/json/json_writer.h +0 -84
@@ -1,34 +0,0 @@
1
- /*
2
- *
3
- * Copyright 2015 gRPC authors.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
- #ifndef GRPC_CORE_LIB_JSON_JSON_COMMON_H
20
- #define GRPC_CORE_LIB_JSON_JSON_COMMON_H
21
-
22
- /* The various json types. */
23
- typedef enum {
24
- GRPC_JSON_OBJECT,
25
- GRPC_JSON_ARRAY,
26
- GRPC_JSON_STRING,
27
- GRPC_JSON_NUMBER,
28
- GRPC_JSON_TRUE,
29
- GRPC_JSON_FALSE,
30
- GRPC_JSON_NULL,
31
- GRPC_JSON_TOP_LEVEL
32
- } grpc_json_type;
33
-
34
- #endif /* GRPC_CORE_LIB_JSON_JSON_COMMON_H */
@@ -1,146 +0,0 @@
1
- /*
2
- *
3
- * Copyright 2015 gRPC authors.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
- #ifndef GRPC_CORE_LIB_JSON_JSON_READER_H
20
- #define GRPC_CORE_LIB_JSON_JSON_READER_H
21
-
22
- #include <grpc/support/port_platform.h>
23
-
24
- #include "src/core/lib/json/json_common.h"
25
-
26
- typedef enum {
27
- GRPC_JSON_STATE_OBJECT_KEY_BEGIN,
28
- GRPC_JSON_STATE_OBJECT_KEY_STRING,
29
- GRPC_JSON_STATE_OBJECT_KEY_END,
30
- GRPC_JSON_STATE_VALUE_BEGIN,
31
- GRPC_JSON_STATE_VALUE_STRING,
32
- GRPC_JSON_STATE_STRING_ESCAPE,
33
- GRPC_JSON_STATE_STRING_ESCAPE_U1,
34
- GRPC_JSON_STATE_STRING_ESCAPE_U2,
35
- GRPC_JSON_STATE_STRING_ESCAPE_U3,
36
- GRPC_JSON_STATE_STRING_ESCAPE_U4,
37
- GRPC_JSON_STATE_VALUE_NUMBER,
38
- GRPC_JSON_STATE_VALUE_NUMBER_WITH_DECIMAL,
39
- GRPC_JSON_STATE_VALUE_NUMBER_ZERO,
40
- GRPC_JSON_STATE_VALUE_NUMBER_DOT,
41
- GRPC_JSON_STATE_VALUE_NUMBER_E,
42
- GRPC_JSON_STATE_VALUE_NUMBER_EPM,
43
- GRPC_JSON_STATE_VALUE_TRUE_R,
44
- GRPC_JSON_STATE_VALUE_TRUE_U,
45
- GRPC_JSON_STATE_VALUE_TRUE_E,
46
- GRPC_JSON_STATE_VALUE_FALSE_A,
47
- GRPC_JSON_STATE_VALUE_FALSE_L,
48
- GRPC_JSON_STATE_VALUE_FALSE_S,
49
- GRPC_JSON_STATE_VALUE_FALSE_E,
50
- GRPC_JSON_STATE_VALUE_NULL_U,
51
- GRPC_JSON_STATE_VALUE_NULL_L1,
52
- GRPC_JSON_STATE_VALUE_NULL_L2,
53
- GRPC_JSON_STATE_VALUE_END,
54
- GRPC_JSON_STATE_END
55
- } grpc_json_reader_state;
56
-
57
- enum {
58
- /* The first non-unicode value is 0x110000. But let's pick
59
- * a value high enough to start our error codes from. These
60
- * values are safe to return from the read_char function.
61
- */
62
- GRPC_JSON_READ_CHAR_EOF = 0x7ffffff0,
63
- GRPC_JSON_READ_CHAR_EAGAIN,
64
- GRPC_JSON_READ_CHAR_ERROR
65
- };
66
-
67
- struct grpc_json_reader;
68
-
69
- typedef struct grpc_json_reader_vtable {
70
- /* Clears your internal string scratchpad. */
71
- void (*string_clear)(void* userdata);
72
- /* Adds a char to the string scratchpad. */
73
- void (*string_add_char)(void* userdata, uint32_t c);
74
- /* Adds a utf32 char to the string scratchpad. */
75
- void (*string_add_utf32)(void* userdata, uint32_t c);
76
- /* Reads a character from your input. May be utf-8, 16 or 32. */
77
- uint32_t (*read_char)(void* userdata);
78
- /* Starts a container of type GRPC_JSON_ARRAY or GRPC_JSON_OBJECT. */
79
- void (*container_begins)(void* userdata, grpc_json_type type);
80
- /* Ends the current container. Must return the type of its parent. */
81
- grpc_json_type (*container_ends)(void* userdata);
82
- /* Your internal string scratchpad is an object's key. */
83
- void (*set_key)(void* userdata);
84
- /* Your internal string scratchpad is a string value. */
85
- void (*set_string)(void* userdata);
86
- /* Your internal string scratchpad is a numerical value. Return 1 if valid. */
87
- int (*set_number)(void* userdata);
88
- /* Sets the values true, false or null. */
89
- void (*set_true)(void* userdata);
90
- void (*set_false)(void* userdata);
91
- void (*set_null)(void* userdata);
92
- } grpc_json_reader_vtable;
93
-
94
- typedef struct grpc_json_reader {
95
- /* That structure is fully private, and initialized by grpc_json_reader_init.
96
- * The definition is public so you can put it on your stack.
97
- */
98
-
99
- void* userdata;
100
- grpc_json_reader_vtable* vtable;
101
- int depth;
102
- int in_object;
103
- int in_array;
104
- int escaped_string_was_key;
105
- int container_just_begun;
106
- uint16_t unicode_char, unicode_high_surrogate;
107
- grpc_json_reader_state state;
108
- } grpc_json_reader;
109
-
110
- /* The return type of the parser. */
111
- typedef enum {
112
- GRPC_JSON_DONE, /* The parser finished successfully. */
113
- GRPC_JSON_EAGAIN, /* The parser yields to get more data. */
114
- GRPC_JSON_READ_ERROR, /* The parser passes through a read error. */
115
- GRPC_JSON_PARSE_ERROR, /* The parser found an error in the json stream. */
116
- GRPC_JSON_INTERNAL_ERROR /* The parser got an internal error. */
117
- } grpc_json_reader_status;
118
-
119
- /* Call this function to start parsing the input. It will return the following:
120
- * . GRPC_JSON_DONE if the input got eof, and the parsing finished
121
- * successfully.
122
- * . GRPC_JSON_EAGAIN if the read_char function returned again. Call the
123
- * parser again as needed. It is okay to call the parser in polling mode,
124
- * although a bit dull.
125
- * . GRPC_JSON_READ_ERROR if the read_char function returned an error. The
126
- * state isn't broken however, and the function can be called again if the
127
- * error has been corrected. But please use the EAGAIN feature instead for
128
- * consistency.
129
- * . GRPC_JSON_PARSE_ERROR if the input was somehow invalid.
130
- * . GRPC_JSON_INTERNAL_ERROR if the parser somehow ended into an invalid
131
- * internal state.
132
- */
133
- grpc_json_reader_status grpc_json_reader_run(grpc_json_reader* reader);
134
-
135
- /* Call this function to initialize the reader structure. */
136
- void grpc_json_reader_init(grpc_json_reader* reader,
137
- grpc_json_reader_vtable* vtable, void* userdata);
138
-
139
- /* You may call this from the read_char callback if you don't know where is the
140
- * end of your input stream, and you'd like the json reader to hint you that it
141
- * has completed reading its input, so you can return an EOF to it. Note that
142
- * there might still be trailing whitespaces after that point.
143
- */
144
- int grpc_json_reader_is_complete(grpc_json_reader* reader);
145
-
146
- #endif /* GRPC_CORE_LIB_JSON_JSON_READER_H */
@@ -1,367 +0,0 @@
1
- /*
2
- *
3
- * Copyright 2015 gRPC authors.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- *
17
- */
18
-
19
- #include <grpc/support/port_platform.h>
20
-
21
- #include <stdlib.h>
22
- #include <string.h>
23
-
24
- #include <grpc/support/alloc.h>
25
- #include <grpc/support/log.h>
26
-
27
- #include "src/core/lib/json/json.h"
28
- #include "src/core/lib/json/json_reader.h"
29
- #include "src/core/lib/json/json_writer.h"
30
-
31
- /* The json reader will construct a bunch of grpc_json objects and
32
- * link them all up together in a tree-like structure that will represent
33
- * the json data in memory.
34
- *
35
- * It also uses its own input as a scratchpad to store all of the decoded,
36
- * unescaped strings. So we need to keep track of all these pointers in
37
- * that opaque structure the reader will carry for us.
38
- *
39
- * Note that this works because the act of parsing json always reduces its
40
- * input size, and never expands it.
41
- */
42
- typedef struct {
43
- grpc_json* top;
44
- grpc_json* current_container;
45
- grpc_json* current_value;
46
- uint8_t* input;
47
- uint8_t* key;
48
- uint8_t* string;
49
- uint8_t* string_ptr;
50
- size_t remaining_input;
51
- } json_reader_userdata;
52
-
53
- /* This json writer will put everything in a big string.
54
- * The point is that we allocate that string in chunks of 256 bytes.
55
- */
56
- typedef struct {
57
- char* output;
58
- size_t free_space;
59
- size_t string_len;
60
- size_t allocated;
61
- } json_writer_userdata;
62
-
63
- /* This function checks if there's enough space left in the output buffer,
64
- * and will enlarge it if necessary. We're only allocating chunks of 256
65
- * bytes at a time (or multiples thereof).
66
- */
67
- static void json_writer_output_check(void* userdata, size_t needed) {
68
- json_writer_userdata* state = static_cast<json_writer_userdata*>(userdata);
69
- if (state->free_space >= needed) return;
70
- needed -= state->free_space;
71
- /* Round up by 256 bytes. */
72
- needed = (needed + 0xff) & ~0xffU;
73
- state->output =
74
- static_cast<char*>(gpr_realloc(state->output, state->allocated + needed));
75
- state->free_space += needed;
76
- state->allocated += needed;
77
- }
78
-
79
- /* These are needed by the writer's implementation. */
80
- static void json_writer_output_char(void* userdata, char c) {
81
- json_writer_userdata* state = static_cast<json_writer_userdata*>(userdata);
82
- json_writer_output_check(userdata, 1);
83
- state->output[state->string_len++] = c;
84
- state->free_space--;
85
- }
86
-
87
- static void json_writer_output_string_with_len(void* userdata, const char* str,
88
- size_t len) {
89
- json_writer_userdata* state = static_cast<json_writer_userdata*>(userdata);
90
- json_writer_output_check(userdata, len);
91
- memcpy(state->output + state->string_len, str, len);
92
- state->string_len += len;
93
- state->free_space -= len;
94
- }
95
-
96
- static void json_writer_output_string(void* userdata, const char* str) {
97
- size_t len = strlen(str);
98
- json_writer_output_string_with_len(userdata, str, len);
99
- }
100
-
101
- /* The reader asks us to clear our scratchpad. In our case, we'll simply mark
102
- * the end of the current string, and advance our output pointer.
103
- */
104
- static void json_reader_string_clear(void* userdata) {
105
- json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata);
106
- if (state->string) {
107
- GPR_ASSERT(state->string_ptr < state->input);
108
- *state->string_ptr++ = 0;
109
- }
110
- state->string = state->string_ptr;
111
- }
112
-
113
- static void json_reader_string_add_char(void* userdata, uint32_t c) {
114
- json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata);
115
- GPR_ASSERT(state->string_ptr < state->input);
116
- GPR_ASSERT(c <= 0xff);
117
- *state->string_ptr++ = static_cast<uint8_t>(c);
118
- }
119
-
120
- /* We are converting a UTF-32 character into UTF-8 here,
121
- * as described by RFC3629.
122
- */
123
- static void json_reader_string_add_utf32(void* userdata, uint32_t c) {
124
- if (c <= 0x7f) {
125
- json_reader_string_add_char(userdata, c);
126
- } else if (c <= 0x7ff) {
127
- uint32_t b1 = 0xc0 | ((c >> 6) & 0x1f);
128
- uint32_t b2 = 0x80 | (c & 0x3f);
129
- json_reader_string_add_char(userdata, b1);
130
- json_reader_string_add_char(userdata, b2);
131
- } else if (c <= 0xffff) {
132
- uint32_t b1 = 0xe0 | ((c >> 12) & 0x0f);
133
- uint32_t b2 = 0x80 | ((c >> 6) & 0x3f);
134
- uint32_t b3 = 0x80 | (c & 0x3f);
135
- json_reader_string_add_char(userdata, b1);
136
- json_reader_string_add_char(userdata, b2);
137
- json_reader_string_add_char(userdata, b3);
138
- } else if (c <= 0x1fffff) {
139
- uint32_t b1 = 0xf0 | ((c >> 18) & 0x07);
140
- uint32_t b2 = 0x80 | ((c >> 12) & 0x3f);
141
- uint32_t b3 = 0x80 | ((c >> 6) & 0x3f);
142
- uint32_t b4 = 0x80 | (c & 0x3f);
143
- json_reader_string_add_char(userdata, b1);
144
- json_reader_string_add_char(userdata, b2);
145
- json_reader_string_add_char(userdata, b3);
146
- json_reader_string_add_char(userdata, b4);
147
- }
148
- }
149
-
150
- /* We consider that the input may be a zero-terminated string. So we
151
- * can end up hitting eof before the end of the alleged string length.
152
- */
153
- static uint32_t json_reader_read_char(void* userdata) {
154
- uint32_t r;
155
- json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata);
156
-
157
- if (state->remaining_input == 0) return GRPC_JSON_READ_CHAR_EOF;
158
-
159
- r = *state->input++;
160
- state->remaining_input--;
161
-
162
- if (r == 0) {
163
- state->remaining_input = 0;
164
- return GRPC_JSON_READ_CHAR_EOF;
165
- }
166
-
167
- return r;
168
- }
169
-
170
- /* Helper function to create a new grpc_json object and link it into
171
- * our tree-in-progress inside our opaque structure.
172
- */
173
- static grpc_json* json_create_and_link(void* userdata, grpc_json_type type) {
174
- json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata);
175
- grpc_json* json = grpc_json_create(type);
176
-
177
- json->parent = state->current_container;
178
- json->prev = state->current_value;
179
- state->current_value = json;
180
-
181
- if (json->prev) {
182
- json->prev->next = json;
183
- }
184
- if (json->parent) {
185
- if (!json->parent->child) {
186
- json->parent->child = json;
187
- }
188
- if (json->parent->type == GRPC_JSON_OBJECT) {
189
- json->key = reinterpret_cast<char*>(state->key);
190
- }
191
- }
192
- if (!state->top) {
193
- state->top = json;
194
- }
195
-
196
- return json;
197
- }
198
-
199
- static void json_reader_container_begins(void* userdata, grpc_json_type type) {
200
- json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata);
201
- grpc_json* container;
202
-
203
- GPR_ASSERT(type == GRPC_JSON_ARRAY || type == GRPC_JSON_OBJECT);
204
-
205
- container = json_create_and_link(userdata, type);
206
- state->current_container = container;
207
- state->current_value = nullptr;
208
- }
209
-
210
- /* It's important to remember that the reader is mostly stateless, so it
211
- * isn't trying to remember what the container was prior the one that just
212
- * ends. Since we're keeping track of these for our own purpose, we are
213
- * able to return that information back, which is useful for it to validate
214
- * the input json stream.
215
- *
216
- * Also note that if we're at the top of the tree, and the last container
217
- * ends, we have to return GRPC_JSON_TOP_LEVEL.
218
- */
219
- static grpc_json_type json_reader_container_ends(void* userdata) {
220
- grpc_json_type container_type = GRPC_JSON_TOP_LEVEL;
221
- json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata);
222
-
223
- GPR_ASSERT(state->current_container);
224
-
225
- state->current_value = state->current_container;
226
- state->current_container = state->current_container->parent;
227
-
228
- if (state->current_container) {
229
- container_type = state->current_container->type;
230
- }
231
-
232
- return container_type;
233
- }
234
-
235
- /* The next 3 functions basically are the reader asking us to use our string
236
- * scratchpad for one of these 3 purposes.
237
- *
238
- * Note that in the set_number case, we're not going to try interpreting it.
239
- * We'll keep it as a string, and leave it to the caller to evaluate it.
240
- */
241
- static void json_reader_set_key(void* userdata) {
242
- json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata);
243
- state->key = state->string;
244
- }
245
-
246
- static void json_reader_set_string(void* userdata) {
247
- json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata);
248
- grpc_json* json = json_create_and_link(userdata, GRPC_JSON_STRING);
249
- json->value = reinterpret_cast<char*>(state->string);
250
- }
251
-
252
- static int json_reader_set_number(void* userdata) {
253
- json_reader_userdata* state = static_cast<json_reader_userdata*>(userdata);
254
- grpc_json* json = json_create_and_link(userdata, GRPC_JSON_NUMBER);
255
- json->value = reinterpret_cast<char*>(state->string);
256
- return 1;
257
- }
258
-
259
- /* The object types true, false and null are self-sufficient, and don't need
260
- * any more information beside their type.
261
- */
262
- static void json_reader_set_true(void* userdata) {
263
- json_create_and_link(userdata, GRPC_JSON_TRUE);
264
- }
265
-
266
- static void json_reader_set_false(void* userdata) {
267
- json_create_and_link(userdata, GRPC_JSON_FALSE);
268
- }
269
-
270
- static void json_reader_set_null(void* userdata) {
271
- json_create_and_link(userdata, GRPC_JSON_NULL);
272
- }
273
-
274
- static grpc_json_reader_vtable reader_vtable = {
275
- json_reader_string_clear, json_reader_string_add_char,
276
- json_reader_string_add_utf32, json_reader_read_char,
277
- json_reader_container_begins, json_reader_container_ends,
278
- json_reader_set_key, json_reader_set_string,
279
- json_reader_set_number, json_reader_set_true,
280
- json_reader_set_false, json_reader_set_null};
281
-
282
- /* And finally, let's define our public API. */
283
- grpc_json* grpc_json_parse_string_with_len(char* input, size_t size) {
284
- grpc_json_reader reader;
285
- json_reader_userdata state;
286
- grpc_json* json = nullptr;
287
- grpc_json_reader_status status;
288
-
289
- if (!input) return nullptr;
290
-
291
- state.top = state.current_container = state.current_value = nullptr;
292
- state.string = state.key = nullptr;
293
- state.string_ptr = state.input = reinterpret_cast<uint8_t*>(input);
294
- state.remaining_input = size;
295
- grpc_json_reader_init(&reader, &reader_vtable, &state);
296
-
297
- status = grpc_json_reader_run(&reader);
298
- json = state.top;
299
-
300
- if ((status != GRPC_JSON_DONE) && json) {
301
- grpc_json_destroy(json);
302
- json = nullptr;
303
- }
304
-
305
- return json;
306
- }
307
-
308
- #define UNBOUND_JSON_STRING_LENGTH 0x7fffffff
309
-
310
- grpc_json* grpc_json_parse_string(char* input) {
311
- return grpc_json_parse_string_with_len(input, UNBOUND_JSON_STRING_LENGTH);
312
- }
313
-
314
- static void json_dump_recursive(grpc_json_writer* writer, const grpc_json* json,
315
- int in_object) {
316
- while (json) {
317
- if (in_object) grpc_json_writer_object_key(writer, json->key);
318
-
319
- switch (json->type) {
320
- case GRPC_JSON_OBJECT:
321
- case GRPC_JSON_ARRAY:
322
- grpc_json_writer_container_begins(writer, json->type);
323
- if (json->child)
324
- json_dump_recursive(writer, json->child,
325
- json->type == GRPC_JSON_OBJECT);
326
- grpc_json_writer_container_ends(writer, json->type);
327
- break;
328
- case GRPC_JSON_STRING:
329
- grpc_json_writer_value_string(writer, json->value);
330
- break;
331
- case GRPC_JSON_NUMBER:
332
- grpc_json_writer_value_raw(writer, json->value);
333
- break;
334
- case GRPC_JSON_TRUE:
335
- grpc_json_writer_value_raw_with_len(writer, "true", 4);
336
- break;
337
- case GRPC_JSON_FALSE:
338
- grpc_json_writer_value_raw_with_len(writer, "false", 5);
339
- break;
340
- case GRPC_JSON_NULL:
341
- grpc_json_writer_value_raw_with_len(writer, "null", 4);
342
- break;
343
- default:
344
- GPR_UNREACHABLE_CODE(abort());
345
- }
346
- json = json->next;
347
- }
348
- }
349
-
350
- static grpc_json_writer_vtable writer_vtable = {
351
- json_writer_output_char, json_writer_output_string,
352
- json_writer_output_string_with_len};
353
-
354
- char* grpc_json_dump_to_string(const grpc_json* json, int indent) {
355
- grpc_json_writer writer;
356
- json_writer_userdata state;
357
-
358
- state.output = nullptr;
359
- state.free_space = state.string_len = state.allocated = 0;
360
- grpc_json_writer_init(&writer, indent, &writer_vtable, &state);
361
-
362
- json_dump_recursive(&writer, json, 0);
363
-
364
- json_writer_output_char(&state, 0);
365
-
366
- return state.output;
367
- }