libmongocrypt-helper 1.7.4.0.1002 → 1.8.0.0.1001

Sign up to get free protection for your applications and to get access to all the features.
Files changed (396) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/ext/libmongocrypt/libmongocrypt/CHANGELOG.md +9 -7
  4. data/ext/libmongocrypt/libmongocrypt/CMakeLists.txt +17 -23
  5. data/ext/libmongocrypt/libmongocrypt/Earthfile +374 -0
  6. data/ext/libmongocrypt/libmongocrypt/README.md +7 -7
  7. data/ext/libmongocrypt/libmongocrypt/VERSION_CURRENT +1 -1
  8. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/CryptClient.cs +25 -6
  9. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/Library.cs +25 -3
  10. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Example/MongoDB.Libmongocrypt.Example.csproj +1 -1
  11. data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Test/BasicTests.cs +1 -1
  12. data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.cake +3 -2
  13. data/ext/libmongocrypt/libmongocrypt/bindings/cs/cs.sln +79 -0
  14. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/build.gradle.kts +2 -2
  15. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/java/com/mongodb/crypt/capi/MongoCryptTest.java +6 -4
  16. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit-v2/int32/encrypted-payload.json +26 -0
  17. data/ext/libmongocrypt/libmongocrypt/bindings/node/CHANGELOG.md +24 -0
  18. data/ext/libmongocrypt/libmongocrypt/bindings/node/README.md +134 -5
  19. data/ext/libmongocrypt/libmongocrypt/bindings/node/etc/build-static.sh +3 -6
  20. data/ext/libmongocrypt/libmongocrypt/bindings/node/index.d.ts +203 -77
  21. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/autoEncrypter.js +1 -1
  22. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/clientEncryption.js +165 -43
  23. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/common.js +12 -14
  24. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/errors.js +75 -0
  25. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/index.js +34 -3
  26. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/aws.js +26 -0
  27. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/azure.js +178 -0
  28. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/gcp.js +24 -0
  29. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/index.js +54 -0
  30. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/utils.js +39 -0
  31. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/stateMachine.js +9 -4
  32. data/ext/libmongocrypt/libmongocrypt/bindings/node/package-lock.json +4440 -5189
  33. data/ext/libmongocrypt/libmongocrypt/bindings/node/package.json +27 -8
  34. data/ext/libmongocrypt/libmongocrypt/bindings/node/src/mongocrypt.cc +65 -38
  35. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/autoEncrypter.test.js +4 -7
  36. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/clientEncryption.test.js +434 -42
  37. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/common.test.js +94 -0
  38. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/cryptoCallbacks.test.js +1 -45
  39. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/index.test.js +45 -0
  40. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/mongocryptdManager.test.js +1 -1
  41. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/providers/credentialsProvider.test.js +551 -0
  42. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/release.test.js +10 -3
  43. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/requirements.helper.js +23 -1
  44. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/stateMachine.test.js +1 -1
  45. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/tools/chai-addons.js +8 -0
  46. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/types/index.test-d.ts +63 -0
  47. data/ext/libmongocrypt/libmongocrypt/bindings/python/CHANGELOG.rst +26 -0
  48. data/ext/libmongocrypt/libmongocrypt/bindings/python/README.rst +2 -2
  49. data/ext/libmongocrypt/libmongocrypt/bindings/python/build-manylinux-wheel.sh +1 -1
  50. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/binding.py +128 -238
  51. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/compat.py +0 -27
  52. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/explicit_encrypter.py +1 -1
  53. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/mongocrypt.py +5 -21
  54. data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/version.py +2 -2
  55. data/ext/libmongocrypt/libmongocrypt/bindings/python/release.sh +5 -5
  56. data/ext/libmongocrypt/libmongocrypt/bindings/python/setup.py +14 -9
  57. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/__init__.py +1 -10
  58. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit-v2/int32/encrypted-payload.json +26 -0
  59. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_mongocrypt.py +5 -5
  60. data/ext/libmongocrypt/libmongocrypt/bindings/python/test-requirements.txt +4 -12
  61. data/ext/libmongocrypt/libmongocrypt/cmake/ImportBSON.cmake +8 -6
  62. data/ext/libmongocrypt/libmongocrypt/cmake/IntelDFP.cmake +2 -1
  63. data/ext/libmongocrypt/libmongocrypt/cmake/Platform.cmake +50 -0
  64. data/ext/libmongocrypt/libmongocrypt/cmake/mongocrypt-config.cmake +21 -0
  65. data/ext/libmongocrypt/libmongocrypt/debian/gbp.conf +2 -2
  66. data/ext/libmongocrypt/libmongocrypt/etc/c6-vault.repo +39 -0
  67. data/ext/libmongocrypt/libmongocrypt/etc/fle2_aead_generate_tests.py +15 -24
  68. data/ext/libmongocrypt/libmongocrypt/etc/fle2_crypto.py +66 -54
  69. data/ext/libmongocrypt/libmongocrypt/etc/fle2_generate_tests.py +14 -23
  70. data/ext/libmongocrypt/libmongocrypt/etc/fle2v2_aead_generate_tests.py +32 -0
  71. data/ext/libmongocrypt/libmongocrypt/etc/format-all.sh +12 -0
  72. data/ext/libmongocrypt/libmongocrypt/etc/format.sh +16 -0
  73. data/ext/libmongocrypt/libmongocrypt/etc/install-package.sh +48 -0
  74. data/ext/libmongocrypt/libmongocrypt/etc/mongo-inteldfp-libmongocrypt-pr-625.patch +13 -0
  75. data/ext/libmongocrypt/libmongocrypt/src/crypto/cng.c +381 -436
  76. data/ext/libmongocrypt/libmongocrypt/src/crypto/commoncrypto.c +162 -227
  77. data/ext/libmongocrypt/libmongocrypt/src/crypto/libcrypto.c +180 -248
  78. data/ext/libmongocrypt/libmongocrypt/src/crypto/none.c +33 -55
  79. data/ext/libmongocrypt/libmongocrypt/src/csfle-markup.cpp +175 -205
  80. data/ext/libmongocrypt/libmongocrypt/src/mc-array-private.h +10 -21
  81. data/ext/libmongocrypt/libmongocrypt/src/mc-array.c +44 -56
  82. data/ext/libmongocrypt/libmongocrypt/src/mc-check-conversions-private.h +4 -8
  83. data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.h +351 -463
  84. data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.test.cpp +59 -66
  85. data/ext/libmongocrypt/libmongocrypt/src/mc-efc-private.h +7 -11
  86. data/ext/libmongocrypt/libmongocrypt/src/mc-efc.c +80 -92
  87. data/ext/libmongocrypt/libmongocrypt/src/mc-fle-blob-subtype-private.h +18 -10
  88. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder-private.h +59 -70
  89. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder.c +384 -439
  90. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private-v2.h +41 -0
  91. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private.h +11 -18
  92. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-v2.c +135 -0
  93. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload.c +109 -126
  94. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private-v2.h +88 -0
  95. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private.h +24 -27
  96. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-v2.c +137 -0
  97. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload.c +106 -125
  98. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private-v2.h +117 -0
  99. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private.h +28 -36
  100. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-v2.c +294 -0
  101. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload.c +237 -278
  102. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-private-v2.h +133 -0
  103. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-private.h +67 -56
  104. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-v2.c +437 -0
  105. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev.c +476 -325
  106. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-common-private.h +69 -0
  107. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-common.c +182 -0
  108. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-private.h +23 -31
  109. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-v2-private.h +85 -0
  110. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-v2.c +142 -0
  111. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev.c +104 -231
  112. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-range-operator-private.h +8 -7
  113. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds-private.h +55 -56
  114. data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds.c +517 -580
  115. data/ext/libmongocrypt/libmongocrypt/src/mc-optional-private.h +36 -66
  116. data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation-private.h +57 -76
  117. data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation.c +158 -189
  118. data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding-private.h +36 -42
  119. data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding.c +515 -558
  120. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-generator.template.h +155 -191
  121. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-private.h +43 -53
  122. data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover.c +170 -240
  123. data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts-private.h +29 -34
  124. data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts.c +289 -338
  125. data/ext/libmongocrypt/libmongocrypt/src/mc-reader-private.h +36 -71
  126. data/ext/libmongocrypt/libmongocrypt/src/mc-reader.c +111 -164
  127. data/ext/libmongocrypt/libmongocrypt/src/mc-tokens-private.h +55 -49
  128. data/ext/libmongocrypt/libmongocrypt/src/mc-tokens.c +109 -125
  129. data/ext/libmongocrypt/libmongocrypt/src/mc-writer-private.h +66 -0
  130. data/ext/libmongocrypt/libmongocrypt/src/mc-writer.c +141 -0
  131. data/ext/libmongocrypt/libmongocrypt/src/mlib/check.hpp +37 -55
  132. data/ext/libmongocrypt/libmongocrypt/src/mlib/endian.h +11 -11
  133. data/ext/libmongocrypt/libmongocrypt/src/mlib/error.h +27 -32
  134. data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.h +444 -499
  135. data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.test.cpp +251 -334
  136. data/ext/libmongocrypt/libmongocrypt/src/mlib/macros.h +4 -5
  137. data/ext/libmongocrypt/libmongocrypt/src/mlib/path.h +196 -231
  138. data/ext/libmongocrypt/libmongocrypt/src/mlib/path.test.c +56 -79
  139. data/ext/libmongocrypt/libmongocrypt/src/mlib/str.h +411 -530
  140. data/ext/libmongocrypt/libmongocrypt/src/mlib/str.test.c +116 -131
  141. data/ext/libmongocrypt/libmongocrypt/src/mlib/thread.h +17 -26
  142. data/ext/libmongocrypt/libmongocrypt/src/mlib/user-check.h +2 -2
  143. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary-private.h +3 -6
  144. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary.c +31 -48
  145. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer-private.h +55 -131
  146. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer.c +444 -565
  147. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-collinfo-private.h +1 -2
  148. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-collinfo.c +28 -45
  149. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key-private.h +11 -17
  150. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key.c +103 -132
  151. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth-private.h +8 -14
  152. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth.c +78 -90
  153. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-private.h +26 -45
  154. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache.c +220 -273
  155. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ciphertext-private.h +13 -25
  156. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ciphertext.c +147 -166
  157. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-compat.h +2 -2
  158. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto-private.h +110 -204
  159. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto.c +1137 -1565
  160. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-datakey.c +425 -472
  161. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-decrypt.c +817 -694
  162. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-encrypt.c +2394 -2697
  163. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-private.h +166 -186
  164. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-rewrap-many-datakey.c +308 -351
  165. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx.c +921 -1138
  166. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-dll-private.h +16 -24
  167. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endian-private.h +44 -58
  168. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endpoint-private.h +21 -25
  169. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endpoint.c +167 -181
  170. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek-private.h +37 -43
  171. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek.c +215 -253
  172. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker-private.h +73 -108
  173. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker.c +889 -1034
  174. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-private.h +27 -44
  175. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key.c +349 -402
  176. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx-private.h +92 -120
  177. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx.c +1397 -1612
  178. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-log-private.h +35 -67
  179. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-log.c +49 -83
  180. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking-private.h +30 -36
  181. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking.c +1821 -1470
  182. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-mutex-private.h +7 -12
  183. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts-private.h +80 -108
  184. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts.c +354 -424
  185. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-private.h +101 -117
  186. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-status-private.h +3 -8
  187. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-status.c +92 -119
  188. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-traverse-util-private.h +19 -29
  189. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-traverse-util.c +136 -176
  190. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util-private.h +11 -21
  191. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util.c +96 -135
  192. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.c +1092 -1320
  193. data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.h +130 -295
  194. data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_dll.c +66 -78
  195. data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_mutex.c +20 -28
  196. data/ext/libmongocrypt/libmongocrypt/src/os_win/os_dll.c +60 -73
  197. data/ext/libmongocrypt/libmongocrypt/src/os_win/os_mutex.c +8 -16
  198. data/ext/libmongocrypt/libmongocrypt/test/crypt_shared-stub.cpp +57 -87
  199. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-delete/empty/encrypted-payload-v2.json +60 -0
  200. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-delete/success/encrypted-payload-v2.json +67 -0
  201. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explain/with-csfle/encrypted-payload.json +2 -2
  202. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/find-indexed-contentionFactor1-v2.json +8 -0
  203. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/find-indexed-v2.json +8 -0
  204. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-contentionFactor1-v2.json +8 -0
  205. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-same-user-and-index-key-v2.json +8 -0
  206. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-v2.json +8 -0
  207. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/cmd.json +6 -0
  208. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/encrypted-field-map.json +22 -0
  209. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/encrypted-payload.json +40 -0
  210. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/mongocryptd-reply.json +19 -0
  211. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/cmd.json +10 -0
  212. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/encrypted-field-map.json +27 -0
  213. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/encrypted-payload.json +41 -0
  214. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/mongocryptd-reply.json +49 -0
  215. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/cmd.json +6 -0
  216. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/encrypted-field-map.json +30 -0
  217. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/encrypted-payload.json +50 -0
  218. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/mongocryptd-reply.json +58 -0
  219. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/cmd.json +6 -0
  220. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/encrypted-field-map.json +27 -0
  221. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/encrypted-payload.json +41 -0
  222. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/mongocryptd-reply.json +49 -0
  223. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/cmd.json +8 -0
  224. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/encrypted-field-map.json +30 -0
  225. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/encrypted-payload.json +44 -0
  226. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/mongocryptd-reply.json +52 -0
  227. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/cmd.json +8 -0
  228. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/encrypted-field-map.json +27 -0
  229. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/encrypted-payload.json +41 -0
  230. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/mongocryptd-reply.json +49 -0
  231. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/cmd.json +8 -0
  232. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/encrypted-field-map.json +27 -0
  233. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/encrypted-payload.json +41 -0
  234. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/mongocryptd-reply.json +49 -0
  235. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/cmd.json +8 -0
  236. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/encrypted-field-map.json +27 -0
  237. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/encrypted-payload.json +41 -0
  238. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/mongocryptd-reply.json +49 -0
  239. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/double/encrypted-payload-v2.json +26 -0
  240. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/double-precision/encrypted-payload-v2.json +26 -0
  241. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32/encrypted-payload-v2.json +26 -0
  242. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/encrypted-payload-v2.json +26 -0
  243. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-openinterval/encrypted-payload-v2.json +16 -0
  244. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert/cmd.json +1 -1
  245. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date/RNG_DATA.h +65 -65
  246. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/cmd.json +13 -0
  247. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/encrypted-field-map.json +27 -0
  248. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/encrypted-payload.json +44 -0
  249. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/mongocryptd-reply.json +52 -0
  250. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128/RNG_DATA.h +132 -132
  251. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision/RNG_DATA.h +71 -71
  252. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/cmd.json +9 -0
  253. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/encrypted-field-map.json +30 -0
  254. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/encrypted-payload.json +53 -0
  255. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/mongocryptd-reply.json +61 -0
  256. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/cmd.json +9 -0
  257. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/encrypted-field-map.json +27 -0
  258. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/encrypted-payload.json +44 -0
  259. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/mongocryptd-reply.json +52 -0
  260. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double/RNG_DATA.h +68 -68
  261. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision/RNG_DATA.h +19 -19
  262. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/cmd.json +11 -0
  263. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/encrypted-field-map.json +30 -0
  264. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/encrypted-payload.json +47 -0
  265. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/mongocryptd-reply.json +55 -0
  266. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/cmd.json +11 -0
  267. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/encrypted-field-map.json +27 -0
  268. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/encrypted-payload.json +44 -0
  269. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/mongocryptd-reply.json +52 -0
  270. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32/RNG_DATA.h +25 -25
  271. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/cmd.json +11 -0
  272. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/encrypted-field-map.json +27 -0
  273. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/encrypted-payload.json +44 -0
  274. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/mongocryptd-reply.json +52 -0
  275. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64/RNG_DATA.h +65 -65
  276. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/cmd.json +11 -0
  277. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/encrypted-field-map.json +27 -0
  278. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/encrypted-payload.json +44 -0
  279. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/mongocryptd-reply.json +52 -0
  280. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double/RNG_DATA.h +68 -68
  281. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double/encrypted-payload-v2.json +8 -0
  282. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double-precision/RNG_DATA.h +19 -19
  283. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double-precision/encrypted-payload-v2.json +8 -0
  284. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32/RNG_DATA.h +25 -25
  285. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32/encrypted-payload-v2.json +8 -0
  286. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/encrypted-payload-v2.json +8 -0
  287. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/sparsity-2/RNG_DATA.h +15 -15
  288. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/sparsity-2/encrypted-payload-v2.json +8 -0
  289. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/cmd.json +9 -0
  290. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/encrypted-field-map.json +18 -0
  291. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/encrypted-payload.json +14 -0
  292. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/mongocryptd-reply.json +41 -0
  293. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/cmd.json +9 -0
  294. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/encrypted-field-map.json +22 -0
  295. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/encrypted-payload.json +39 -0
  296. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/mongocryptd-reply.json +49 -0
  297. data/ext/libmongocrypt/libmongocrypt/test/data/iev-v2/FLECrudTest-insertOneRangeV2.json +10 -0
  298. data/ext/libmongocrypt/libmongocrypt/test/data/iev-v2/FLECrudTest-insertOneV2.json +10 -0
  299. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/README.md +17 -0
  300. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/aes-ctr.json +29 -0
  301. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2-fixed.json +10 -0
  302. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2-generated.json +38 -0
  303. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-decrypt.json +35 -0
  304. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-fixed.json +29 -0
  305. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-generated.json +122 -0
  306. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2v2-aead-fixed.json +29 -0
  307. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2v2-aead-generated.json +122 -0
  308. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/mcgrew.json +12 -0
  309. data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/nist.json +20 -0
  310. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/README.md +27 -0
  311. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/mc.json +21 -0
  312. data/ext/libmongocrypt/libmongocrypt/test/data/tokens/server.json +21 -0
  313. data/ext/libmongocrypt/libmongocrypt/test/example-no-bson.c +4 -4
  314. data/ext/libmongocrypt/libmongocrypt/test/example-state-machine.c +278 -323
  315. data/ext/libmongocrypt/libmongocrypt/test/fuzz_kms.c +8 -7
  316. data/ext/libmongocrypt/libmongocrypt/test/test-dll.cpp +6 -7
  317. data/ext/libmongocrypt/libmongocrypt/test/test-gcp-auth.c +221 -283
  318. data/ext/libmongocrypt/libmongocrypt/test/test-mc-efc.c +58 -73
  319. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-equality-payload-v2.c +78 -0
  320. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-range-payload-v2.c +89 -0
  321. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iev-v2.c +248 -0
  322. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iev.c +467 -414
  323. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup-v2.c +172 -0
  324. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup.c +141 -159
  325. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-uev-v2.c +338 -0
  326. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-uev.c +238 -176
  327. data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-rfds.c +373 -474
  328. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-edge-generation.c +346 -388
  329. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-encoding.c +708 -825
  330. data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-mincover.c +417 -481
  331. data/ext/libmongocrypt/libmongocrypt/test/test-mc-rangeopts.c +110 -144
  332. data/ext/libmongocrypt/libmongocrypt/test/test-mc-reader.c +124 -207
  333. data/ext/libmongocrypt/libmongocrypt/test/test-mc-tokens.c +223 -213
  334. data/ext/libmongocrypt/libmongocrypt/test/test-mc-writer.c +176 -0
  335. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.c +634 -807
  336. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.h +1 -2
  337. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert.h +168 -189
  338. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-buffer.c +187 -211
  339. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache-oauth.c +34 -36
  340. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache.c +210 -233
  341. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ciphertext.c +185 -220
  342. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-compact.c +331 -445
  343. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-hooks.c +670 -814
  344. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.c +102 -135
  345. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.h +54 -71
  346. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto.c +394 -846
  347. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-csfle-lib.c +159 -183
  348. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-decrypt.c +867 -1045
  349. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-encrypt.c +4349 -4713
  350. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-rewrap-many-datakey.c +750 -964
  351. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-setopt.c +991 -1178
  352. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-datakey.c +342 -419
  353. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-dll.c +23 -30
  354. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-endpoint.c +98 -111
  355. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kek.c +49 -52
  356. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key-broker.c +770 -920
  357. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key-cache.c +354 -407
  358. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key.c +197 -245
  359. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-ctx.c +286 -370
  360. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-responses.c +147 -166
  361. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-local-kms.c +50 -61
  362. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-log.c +85 -100
  363. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-marking.c +656 -692
  364. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-status.c +46 -58
  365. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-traverse-util.c +377 -451
  366. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.c +48 -67
  367. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.h +4 -10
  368. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.c +827 -918
  369. data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.h +111 -172
  370. data/ext/libmongocrypt/libmongocrypt/test/util/csfle.c +508 -559
  371. data/ext/libmongocrypt/libmongocrypt/test/util/util.c +735 -881
  372. data/ext/libmongocrypt/libmongocrypt/test/util/util.h +33 -55
  373. data/lib/libmongocrypt_helper/version.rb +2 -2
  374. data.tar.gz.sig +0 -0
  375. metadata +154 -26
  376. metadata.gz.sig +0 -0
  377. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit/int32/encrypted-payload.json +0 -26
  378. data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit/int32/key-document.json +0 -0
  379. data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/credentialsProvider.js +0 -33
  380. data/ext/libmongocrypt/libmongocrypt/bindings/node/test/credentialsProvider.test.js +0 -163
  381. data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit/int32/encrypted-payload.json +0 -26
  382. data/ext/libmongocrypt/libmongocrypt/test/data/aes-ctr.cstructs +0 -359
  383. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-aead.cstructs +0 -109
  384. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/encrypted-payload.json +0 -26
  385. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/rangeopts.json +0 -5
  386. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/value-to-encrypt.json +0 -20
  387. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/RNG_DATA.h +0 -70
  388. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/encrypted-payload.json +0 -8
  389. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/rangeopts.json +0 -5
  390. data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/value-to-encrypt.json +0 -5
  391. data/ext/libmongocrypt/libmongocrypt/test/data/fle2.cstructs +0 -33
  392. /data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/key-filter.json +0 -0
  393. /data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/rangeopts.json +0 -0
  394. /data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/value-to-encrypt.json +0 -0
  395. /data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/rangeopts.json +0 -0
  396. /data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/value-to-encrypt.json +0 -0
@@ -26,101 +26,75 @@
26
26
  #endif
27
27
 
28
28
  /* The following matching logic is copied from libmongoc. */
29
- bool
30
- bson_init_from_value (bson_t *b, const bson_value_t *v);
29
+ bool bson_init_from_value(bson_t *b, const bson_value_t *v);
31
30
 
32
- char *
33
- single_quotes_to_double (const char *str);
31
+ char *single_quotes_to_double(const char *str);
34
32
 
35
33
  /* match_action_t determines if default check for a field is overridden. */
36
34
  typedef enum {
37
- MATCH_ACTION_SKIP, /* do not use the default check. */
38
- MATCH_ACTION_ABORT, /* an error occurred, stop checking. */
39
- MATCH_ACTION_CONTINUE /* use the default check. */
35
+ MATCH_ACTION_SKIP, /* do not use the default check. */
36
+ MATCH_ACTION_ABORT, /* an error occurred, stop checking. */
37
+ MATCH_ACTION_CONTINUE /* use the default check. */
40
38
  } match_action_t;
41
39
 
42
40
  struct _match_ctx_t;
43
41
  /* doc_iter may be null if the pattern field is not found. */
44
- typedef match_action_t (*match_visitor_fn) (struct _match_ctx_t *ctx,
45
- bson_iter_t *pattern_iter,
46
- bson_iter_t *doc_iter);
42
+ typedef match_action_t (*match_visitor_fn)(struct _match_ctx_t *ctx, bson_iter_t *pattern_iter, bson_iter_t *doc_iter);
47
43
 
48
44
  typedef struct _match_ctx_t {
49
- char errmsg[1000];
50
- bool strict_numeric_types;
51
- /* if retain_dots_in_keys is true, then don't consider a path with dots to
52
- * indicate recursing into a sub document. */
53
- bool retain_dots_in_keys;
54
- /* if allow_placeholders is true, treats 42 and "42" as placeholders. I.e.
55
- * comparing 42 to anything is ok. */
56
- bool allow_placeholders;
57
- /* path is the dot separated breadcrumb trail of keys. */
58
- char path[1000];
59
- /* if visitor_fn is not NULL, this is called on for every key in the pattern.
60
- * The returned match_action_t can override the default match behavior. */
61
- match_visitor_fn visitor_fn;
62
- void *visitor_ctx;
63
- /* if is_command is true, then compare the first key case insensitively. */
64
- bool is_command;
45
+ char errmsg[1000];
46
+ bool strict_numeric_types;
47
+ /* if retain_dots_in_keys is true, then don't consider a path with dots to
48
+ * indicate recursing into a sub document. */
49
+ bool retain_dots_in_keys;
50
+ /* if allow_placeholders is true, treats 42 and "42" as placeholders. I.e.
51
+ * comparing 42 to anything is ok. */
52
+ bool allow_placeholders;
53
+ /* path is the dot separated breadcrumb trail of keys. */
54
+ char path[1000];
55
+ /* if visitor_fn is not NULL, this is called on for every key in the pattern.
56
+ * The returned match_action_t can override the default match behavior. */
57
+ match_visitor_fn visitor_fn;
58
+ void *visitor_ctx;
59
+ /* if is_command is true, then compare the first key case insensitively. */
60
+ bool is_command;
65
61
  } match_ctx_t;
66
62
 
67
- void
68
- assert_match_bson (const bson_t *doc, const bson_t *pattern, bool is_command);
63
+ void assert_match_bson(const bson_t *doc, const bson_t *pattern, bool is_command);
69
64
 
70
- bool
71
- match_bson (const bson_t *doc, const bson_t *pattern, bool is_command);
65
+ bool match_bson(const bson_t *doc, const bson_t *pattern, bool is_command);
72
66
 
73
- int64_t
74
- bson_value_as_int64 (const bson_value_t *value);
67
+ int64_t bson_value_as_int64(const bson_value_t *value);
75
68
 
76
- bool
77
- match_bson_value (const bson_value_t *doc,
78
- const bson_value_t *pattern,
79
- match_ctx_t *ctx);
69
+ bool match_bson_value(const bson_value_t *doc, const bson_value_t *pattern, match_ctx_t *ctx);
80
70
 
81
- bool
82
- match_bson_with_ctx (const bson_t *doc,
83
- const bson_t *pattern,
84
- match_ctx_t *ctx);
71
+ bool match_bson_with_ctx(const bson_t *doc, const bson_t *pattern, match_ctx_t *ctx);
85
72
 
86
- bool
87
- match_json (const bson_t *doc,
88
- bool is_command,
89
- const char *filename,
90
- int lineno,
91
- const char *funcname,
92
- const char *json_pattern,
93
- ...);
73
+ bool match_json(const bson_t *doc,
74
+ bool is_command,
75
+ const char *filename,
76
+ int lineno,
77
+ const char *funcname,
78
+ const char *json_pattern,
79
+ ...);
94
80
 
95
- #define ASSERT_MATCH(doc, ...) \
96
- do { \
97
- BSON_ASSERT ( \
98
- match_json (doc, false, __FILE__, __LINE__, BSON_FUNC, __VA_ARGS__)); \
99
- } while (0)
81
+ #define ASSERT_MATCH(doc, ...) \
82
+ do { \
83
+ BSON_ASSERT(match_json(doc, false, __FILE__, __LINE__, BSON_FUNC, __VA_ARGS__)); \
84
+ } while (0)
100
85
 
101
- const char *
102
- _mongoc_bson_type_to_str (bson_type_t t);
86
+ const char *_mongoc_bson_type_to_str(bson_type_t t);
103
87
 
104
- static bool
105
- get_exists_operator (const bson_value_t *value, bool *exists);
88
+ static bool get_exists_operator(const bson_value_t *value, bool *exists);
106
89
 
107
- static bool
108
- get_empty_operator (const bson_value_t *value, bool *exists);
90
+ static bool get_empty_operator(const bson_value_t *value, bool *exists);
109
91
 
110
- static bool
111
- get_type_operator (const bson_value_t *value, bson_type_t *out);
92
+ static bool get_type_operator(const bson_value_t *value, bson_type_t *out);
112
93
 
113
- static bool
114
- is_empty_doc_or_array (const bson_value_t *value);
94
+ static bool is_empty_doc_or_array(const bson_value_t *value);
115
95
 
116
96
  static bool
117
- find (bson_iter_t *iter,
118
- const bson_t *doc,
119
- const char *key,
120
- bool is_command,
121
- bool is_first,
122
- bool retain_dots_in_keys);
123
-
97
+ find(bson_iter_t *iter, const bson_t *doc, const char *key, bool is_command, bool is_first, bool retain_dots_in_keys);
124
98
 
125
99
  /*--------------------------------------------------------------------------
126
100
  *
@@ -137,22 +111,19 @@ find (bson_iter_t *iter,
137
111
  *--------------------------------------------------------------------------
138
112
  */
139
113
 
140
- char *
141
- single_quotes_to_double (const char *str)
142
- {
143
- char *result = bson_strdup (str);
144
- char *p;
114
+ char *single_quotes_to_double(const char *str) {
115
+ char *result = bson_strdup(str);
116
+ char *p;
145
117
 
146
- for (p = result; *p; p++) {
147
- if (*p == '\'') {
148
- *p = '"';
149
- }
150
- }
118
+ for (p = result; *p; p++) {
119
+ if (*p == '\'') {
120
+ *p = '"';
121
+ }
122
+ }
151
123
 
152
- return result;
124
+ return result;
153
125
  }
154
126
 
155
-
156
127
  /*--------------------------------------------------------------------------
157
128
  *
158
129
  * match_json --
@@ -171,66 +142,62 @@ single_quotes_to_double (const char *str)
171
142
  *--------------------------------------------------------------------------
172
143
  */
173
144
 
174
- MLIB_ANNOTATE_PRINTF (6, 7)
175
- bool
176
- match_json (const bson_t *doc,
177
- bool is_command,
178
- const char *filename,
179
- int lineno,
180
- const char *funcname,
181
- const char *json_pattern,
182
- ...)
183
- {
184
- va_list args;
185
- char *json_pattern_formatted;
186
- char *double_quoted;
187
- bson_error_t error;
188
- bson_t *pattern;
189
- match_ctx_t ctx = {{0}};
190
- bool matches;
191
-
192
- va_start (args, json_pattern);
193
- json_pattern_formatted =
194
- bson_strdupv_printf (json_pattern ? json_pattern : "{}", args);
195
- va_end (args);
196
-
197
- double_quoted = single_quotes_to_double (json_pattern_formatted);
198
- pattern = bson_new_from_json ((const uint8_t *) double_quoted, -1, &error);
199
-
200
- if (!pattern) {
201
- fprintf (stderr, "couldn't parse JSON: %s\n", error.message);
202
- abort ();
203
- }
204
-
205
- ctx.is_command = is_command;
206
- matches = match_bson_with_ctx (doc, pattern, &ctx);
207
-
208
- if (!matches) {
209
- char *as_string =
210
- doc ? bson_as_canonical_extended_json (doc, NULL) : NULL;
211
- fprintf (stderr,
212
- "ASSERT_MATCH failed with document:\n\n"
213
- "%s\n"
214
- "pattern:\n%s\n"
215
- "%s\n"
216
- "%s:%d %s()\n",
217
- as_string ? as_string : "{}",
218
- double_quoted,
219
- ctx.errmsg,
220
- filename,
221
- lineno,
222
- funcname);
223
- bson_free (as_string);
224
- }
225
-
226
- bson_destroy (pattern);
227
- bson_free (json_pattern_formatted);
228
- bson_free (double_quoted);
229
-
230
- return matches;
145
+ MLIB_ANNOTATE_PRINTF(6, 7)
146
+
147
+ bool match_json(const bson_t *doc,
148
+ bool is_command,
149
+ const char *filename,
150
+ int lineno,
151
+ const char *funcname,
152
+ const char *json_pattern,
153
+ ...) {
154
+ va_list args;
155
+ char *json_pattern_formatted;
156
+ char *double_quoted;
157
+ bson_error_t error;
158
+ bson_t *pattern;
159
+ match_ctx_t ctx = {{0}};
160
+ bool matches;
161
+
162
+ va_start(args, json_pattern);
163
+ json_pattern_formatted = bson_strdupv_printf(json_pattern ? json_pattern : "{}", args);
164
+ va_end(args);
165
+
166
+ double_quoted = single_quotes_to_double(json_pattern_formatted);
167
+ pattern = bson_new_from_json((const uint8_t *)double_quoted, -1, &error);
168
+
169
+ if (!pattern) {
170
+ fprintf(stderr, "couldn't parse JSON: %s\n", error.message);
171
+ abort();
172
+ }
173
+
174
+ ctx.is_command = is_command;
175
+ matches = match_bson_with_ctx(doc, pattern, &ctx);
176
+
177
+ if (!matches) {
178
+ char *as_string = doc ? bson_as_canonical_extended_json(doc, NULL) : NULL;
179
+ fprintf(stderr,
180
+ "ASSERT_MATCH failed with document:\n\n"
181
+ "%s\n"
182
+ "pattern:\n%s\n"
183
+ "%s\n"
184
+ "%s:%d %s()\n",
185
+ as_string ? as_string : "{}",
186
+ double_quoted,
187
+ ctx.errmsg,
188
+ filename,
189
+ lineno,
190
+ funcname);
191
+ bson_free(as_string);
192
+ }
193
+
194
+ bson_destroy(pattern);
195
+ bson_free(json_pattern_formatted);
196
+ bson_free(double_quoted);
197
+
198
+ return matches;
231
199
  }
232
200
 
233
-
234
201
  /*--------------------------------------------------------------------------
235
202
  *
236
203
  * match_bson --
@@ -248,64 +215,54 @@ match_json (const bson_t *doc,
248
215
  *--------------------------------------------------------------------------
249
216
  */
250
217
 
251
- bool
252
- match_bson (const bson_t *doc, const bson_t *pattern, bool is_command)
253
- {
254
- match_ctx_t ctx = {{0}};
218
+ bool match_bson(const bson_t *doc, const bson_t *pattern, bool is_command) {
219
+ match_ctx_t ctx = {{0}};
255
220
 
256
- ctx.strict_numeric_types = true;
257
- ctx.is_command = is_command;
221
+ ctx.strict_numeric_types = true;
222
+ ctx.is_command = is_command;
258
223
 
259
- return match_bson_with_ctx (doc, pattern, &ctx);
224
+ return match_bson_with_ctx(doc, pattern, &ctx);
260
225
  }
261
226
 
227
+ MLIB_ANNOTATE_PRINTF(2, 3)
262
228
 
263
- MLIB_ANNOTATE_PRINTF (2, 3)
264
- void
265
- match_err (match_ctx_t *ctx, const char *fmt, ...)
266
- {
267
- va_list args;
268
- char *formatted;
229
+ void match_err(match_ctx_t *ctx, const char *fmt, ...) {
230
+ va_list args;
231
+ char *formatted;
269
232
 
270
- BSON_ASSERT (ctx);
233
+ BSON_ASSERT(ctx);
271
234
 
272
- va_start (args, fmt);
273
- formatted = bson_strdupv_printf (fmt, args);
274
- va_end (args);
235
+ va_start(args, fmt);
236
+ formatted = bson_strdupv_printf(fmt, args);
237
+ va_end(args);
275
238
 
276
- bson_snprintf (
277
- ctx->errmsg, sizeof ctx->errmsg, "%s: %s", ctx->path, formatted);
239
+ bson_snprintf(ctx->errmsg, sizeof ctx->errmsg, "%s: %s", ctx->path, formatted);
278
240
 
279
- bson_free (formatted);
241
+ bson_free(formatted);
280
242
  }
281
243
 
282
-
283
244
  /* When matching two docs, and preparing to recurse to match two subdocs with
284
245
  * the given key, derive context for matching them from the current context. */
285
- static void
286
- derive (match_ctx_t *ctx, match_ctx_t *derived, const char *key)
287
- {
288
- BSON_ASSERT (ctx);
289
- BSON_ASSERT (derived);
290
- BSON_ASSERT (key);
291
-
292
- derived->strict_numeric_types = ctx->strict_numeric_types;
293
-
294
- if (strlen (ctx->path) > 0) {
295
- bson_snprintf (
296
- derived->path, sizeof derived->path, "%s.%s", ctx->path, key);
297
- } else {
298
- bson_snprintf (derived->path, sizeof derived->path, "%s", key);
299
- }
300
- derived->retain_dots_in_keys = ctx->retain_dots_in_keys;
301
- derived->allow_placeholders = ctx->allow_placeholders;
302
- derived->visitor_ctx = ctx->visitor_ctx;
303
- derived->visitor_fn = ctx->visitor_fn;
304
- derived->is_command = false;
305
- derived->errmsg[0] = 0;
246
+ static void derive(match_ctx_t *ctx, match_ctx_t *derived, const char *key) {
247
+ BSON_ASSERT(ctx);
248
+ BSON_ASSERT(derived);
249
+ BSON_ASSERT(key);
250
+
251
+ derived->strict_numeric_types = ctx->strict_numeric_types;
252
+
253
+ if (strlen(ctx->path) > 0) {
254
+ bson_snprintf(derived->path, sizeof derived->path, "%s.%s", ctx->path, key);
255
+ } else {
256
+ bson_snprintf(derived->path, sizeof derived->path, "%s", key);
257
+ }
258
+ derived->retain_dots_in_keys = ctx->retain_dots_in_keys;
259
+ derived->allow_placeholders = ctx->allow_placeholders;
260
+ derived->visitor_ctx = ctx->visitor_ctx;
261
+ derived->visitor_fn = ctx->visitor_fn;
262
+ derived->is_command = false;
263
+ derived->errmsg[0] = 0;
306
264
  }
307
265
 
308
-
309
266
  /*--------------------------------------------------------------------------
310
267
  *
311
268
  * match_bson_with_ctx --
@@ -339,116 +296,107 @@ derive (match_ctx_t *ctx, match_ctx_t *derived, const char *key)
339
296
  *--------------------------------------------------------------------------
340
297
  */
341
298
 
342
- bool
343
- match_bson_with_ctx (const bson_t *doc, const bson_t *pattern, match_ctx_t *ctx)
344
- {
345
- bson_iter_t pattern_iter;
346
- const char *key;
347
- const bson_value_t *value;
348
- bool is_first = true;
349
- bool is_exists_operator;
350
- bool is_empty_operator;
351
- bool is_type_operator;
352
- bool exists;
353
- bool empty = false;
354
- bson_type_t bson_type = (bson_type_t) 0;
355
- bool found;
356
- bson_iter_t doc_iter;
357
- bson_value_t doc_value;
358
- match_ctx_t derived;
359
-
360
- if (bson_empty0 (pattern)) {
361
- /* matches anything */
362
- return true;
363
- }
364
-
365
- BSON_ASSERT (bson_iter_init (&pattern_iter, pattern));
366
-
367
- while (bson_iter_next (&pattern_iter)) {
368
- key = bson_iter_key (&pattern_iter);
369
- value = bson_iter_value (&pattern_iter);
370
-
371
- found = find (&doc_iter,
372
- doc,
373
- key,
374
- ctx->is_command,
375
- is_first,
376
- ctx->retain_dots_in_keys);
377
- if (found) {
378
- bson_value_copy (bson_iter_value (&doc_iter), &doc_value);
379
- }
380
-
381
- /* is value {"$exists": true} or {"$exists": false} ? */
382
- is_exists_operator = get_exists_operator (value, &exists);
383
-
384
- /* is value {"$empty": true} or {"$empty": false} ? */
385
- is_empty_operator = get_empty_operator (value, &empty);
386
-
387
- /* is value {"$$type": "string" } ? */
388
- is_type_operator = get_type_operator (value, &bson_type);
389
-
390
- derive (ctx, &derived, key);
391
-
392
- if (ctx->visitor_fn) {
393
- match_action_t action =
394
- ctx->visitor_fn (ctx, &pattern_iter, found ? &doc_iter : NULL);
395
- if (action == MATCH_ACTION_ABORT) {
396
- goto fail;
397
- } else if (action == MATCH_ACTION_SKIP) {
398
- goto next;
399
- }
400
- }
401
-
402
- if (value->value_type == BSON_TYPE_NULL && found) {
403
- /* pattern has "key": null, and "key" is in doc */
404
- if (doc_value.value_type != BSON_TYPE_NULL) {
405
- match_err (&derived, "%s should be null or absent", key);
299
+ bool match_bson_with_ctx(const bson_t *doc, const bson_t *pattern, match_ctx_t *ctx) {
300
+ bson_iter_t pattern_iter;
301
+ const char *key;
302
+ const bson_value_t *value;
303
+ bool is_first = true;
304
+ bool is_exists_operator;
305
+ bool is_empty_operator;
306
+ bool is_type_operator;
307
+ bool exists;
308
+ bool empty = false;
309
+ bson_type_t bson_type = (bson_type_t)0;
310
+ bool found;
311
+ bson_iter_t doc_iter;
312
+ bson_value_t doc_value;
313
+ match_ctx_t derived;
314
+
315
+ if (bson_empty0(pattern)) {
316
+ /* matches anything */
317
+ return true;
318
+ }
319
+
320
+ BSON_ASSERT(bson_iter_init(&pattern_iter, pattern));
321
+
322
+ while (bson_iter_next(&pattern_iter)) {
323
+ key = bson_iter_key(&pattern_iter);
324
+ value = bson_iter_value(&pattern_iter);
325
+
326
+ found = find(&doc_iter, doc, key, ctx->is_command, is_first, ctx->retain_dots_in_keys);
327
+ if (found) {
328
+ bson_value_copy(bson_iter_value(&doc_iter), &doc_value);
329
+ }
330
+
331
+ /* is value {"$exists": true} or {"$exists": false} ? */
332
+ is_exists_operator = get_exists_operator(value, &exists);
333
+
334
+ /* is value {"$empty": true} or {"$empty": false} ? */
335
+ is_empty_operator = get_empty_operator(value, &empty);
336
+
337
+ /* is value {"$$type": "string" } ? */
338
+ is_type_operator = get_type_operator(value, &bson_type);
339
+
340
+ derive(ctx, &derived, key);
341
+
342
+ if (ctx->visitor_fn) {
343
+ match_action_t action = ctx->visitor_fn(ctx, &pattern_iter, found ? &doc_iter : NULL);
344
+ if (action == MATCH_ACTION_ABORT) {
345
+ goto fail;
346
+ } else if (action == MATCH_ACTION_SKIP) {
347
+ goto next;
348
+ }
349
+ }
350
+
351
+ if (value->value_type == BSON_TYPE_NULL && found) {
352
+ /* pattern has "key": null, and "key" is in doc */
353
+ if (doc_value.value_type != BSON_TYPE_NULL) {
354
+ match_err(&derived, "%s should be null or absent", key);
355
+ goto fail;
356
+ }
357
+ } else if (is_exists_operator) {
358
+ if (exists != found) {
359
+ match_err(&derived, "%s found", found ? "" : "not");
360
+ goto fail;
361
+ }
362
+ } else if (!found) {
363
+ match_err(&derived, "not found");
406
364
  goto fail;
407
- }
408
- } else if (is_exists_operator) {
409
- if (exists != found) {
410
- match_err (&derived, "%s found", found ? "" : "not");
365
+ } else if (is_empty_operator) {
366
+ if (empty != is_empty_doc_or_array(&doc_value)) {
367
+ match_err(&derived, "%s found", empty ? "" : " not");
368
+ goto fail;
369
+ }
370
+ } else if (is_type_operator) {
371
+ if (doc_value.value_type != bson_type) {
372
+ match_err(&derived, "incorrect type");
373
+ goto fail;
374
+ }
375
+ } else if (!match_bson_value(&doc_value, value, &derived)) {
411
376
  goto fail;
412
- }
413
- } else if (!found) {
414
- match_err (&derived, "not found");
415
- goto fail;
416
- } else if (is_empty_operator) {
417
- if (empty != is_empty_doc_or_array (&doc_value)) {
418
- match_err (&derived, "%s found", empty ? "" : " not");
419
- goto fail;
420
- }
421
- } else if (is_type_operator) {
422
- if (doc_value.value_type != bson_type) {
423
- match_err (&derived, "incorrect type");
424
- goto fail;
425
- }
426
- } else if (!match_bson_value (&doc_value, value, &derived)) {
427
- goto fail;
428
- }
377
+ }
429
378
 
430
- next:
431
- is_first = false;
432
- if (found) {
433
- bson_value_destroy (&doc_value);
434
- }
435
- }
379
+ next:
380
+ is_first = false;
381
+ if (found) {
382
+ bson_value_destroy(&doc_value);
383
+ }
384
+ }
436
385
 
437
- return true;
386
+ return true;
438
387
 
439
388
  fail:
440
- if (found) {
441
- bson_value_destroy (&doc_value);
442
- }
389
+ if (found) {
390
+ bson_value_destroy(&doc_value);
391
+ }
443
392
 
444
- if (strlen (derived.errmsg) > 0) {
445
- memcpy (ctx->errmsg, derived.errmsg, sizeof (derived.errmsg));
446
- }
393
+ if (strlen(derived.errmsg) > 0) {
394
+ memcpy(ctx->errmsg, derived.errmsg, sizeof(derived.errmsg));
395
+ }
447
396
 
448
- return false;
397
+ return false;
449
398
  }
450
399
 
451
-
452
400
  /*--------------------------------------------------------------------------
453
401
  *
454
402
  * find --
@@ -464,65 +412,54 @@ fail:
464
412
  *--------------------------------------------------------------------------
465
413
  */
466
414
 
467
- static bool
468
- find (bson_iter_t *iter_out,
469
- const bson_t *doc,
470
- const char *key,
471
- bool is_command,
472
- bool is_first,
473
- bool retain_dots_in_keys)
474
- {
475
- bson_iter_t iter;
476
- bson_iter_t descendent;
477
-
478
- bson_iter_init (&iter, doc);
479
-
480
- if (!retain_dots_in_keys && strchr (key, '.')) {
481
- if (!bson_iter_find_descendant (&iter, key, &descendent)) {
482
- return false;
483
- }
484
-
485
- memcpy (iter_out, &descendent, sizeof (bson_iter_t));
486
- return true;
487
- } else if (is_command && is_first) {
488
- if (!bson_iter_find_case (&iter, key)) {
489
- return false;
490
- }
491
- } else if (!bson_iter_find (&iter, key)) {
492
- return false;
493
- }
494
-
495
- memcpy (iter_out, &iter, sizeof (bson_iter_t));
496
- return true;
415
+ static bool find(bson_iter_t *iter_out,
416
+ const bson_t *doc,
417
+ const char *key,
418
+ bool is_command,
419
+ bool is_first,
420
+ bool retain_dots_in_keys) {
421
+ bson_iter_t iter;
422
+ bson_iter_t descendent;
423
+
424
+ bson_iter_init(&iter, doc);
425
+
426
+ if (!retain_dots_in_keys && strchr(key, '.')) {
427
+ if (!bson_iter_find_descendant(&iter, key, &descendent)) {
428
+ return false;
429
+ }
430
+
431
+ memcpy(iter_out, &descendent, sizeof(bson_iter_t));
432
+ return true;
433
+ } else if (is_command && is_first) {
434
+ if (!bson_iter_find_case(&iter, key)) {
435
+ return false;
436
+ }
437
+ } else if (!bson_iter_find(&iter, key)) {
438
+ return false;
439
+ }
440
+
441
+ memcpy(iter_out, &iter, sizeof(bson_iter_t));
442
+ return true;
497
443
  }
498
444
 
445
+ bool bson_init_from_value(bson_t *b, const bson_value_t *v) {
446
+ BSON_ASSERT(v->value_type == BSON_TYPE_ARRAY || v->value_type == BSON_TYPE_DOCUMENT);
499
447
 
500
- bool
501
- bson_init_from_value (bson_t *b, const bson_value_t *v)
502
- {
503
- BSON_ASSERT (v->value_type == BSON_TYPE_ARRAY ||
504
- v->value_type == BSON_TYPE_DOCUMENT);
505
-
506
- return bson_init_static (b, v->value.v_doc.data, v->value.v_doc.data_len);
448
+ return bson_init_static(b, v->value.v_doc.data, v->value.v_doc.data_len);
507
449
  }
508
450
 
451
+ static bool _is_operator(const char *op_name, const bson_value_t *value, bool *op_val) {
452
+ bson_t bson;
453
+ bson_iter_t iter;
509
454
 
510
- static bool
511
- _is_operator (const char *op_name, const bson_value_t *value, bool *op_val)
512
- {
513
- bson_t bson;
514
- bson_iter_t iter;
515
-
516
- if (value->value_type == BSON_TYPE_DOCUMENT &&
517
- bson_init_from_value (&bson, value) &&
518
- bson_iter_init_find (&iter, &bson, op_name)) {
519
- *op_val = bson_iter_as_bool (&iter);
520
- return true;
521
- }
522
-
523
- return false;
524
- }
455
+ if (value->value_type == BSON_TYPE_DOCUMENT && bson_init_from_value(&bson, value)
456
+ && bson_iter_init_find(&iter, &bson, op_name)) {
457
+ *op_val = bson_iter_as_bool(&iter);
458
+ return true;
459
+ }
525
460
 
461
+ return false;
462
+ }
526
463
 
527
464
  /*--------------------------------------------------------------------------
528
465
  *
@@ -541,21 +478,18 @@ _is_operator (const char *op_name, const bson_value_t *value, bool *op_val)
541
478
  *--------------------------------------------------------------------------
542
479
  */
543
480
 
544
- static bool
545
- get_exists_operator (const bson_value_t *value, bool *exists)
546
- {
547
- if (_is_operator ("$exists", value, exists)) {
548
- return true;
549
- }
550
-
551
- if (value->value_type == BSON_TYPE_NULL) {
552
- *exists = false;
553
- return true;
554
- }
555
-
556
- return false;
557
- }
481
+ static bool get_exists_operator(const bson_value_t *value, bool *exists) {
482
+ if (_is_operator("$exists", value, exists)) {
483
+ return true;
484
+ }
558
485
 
486
+ if (value->value_type == BSON_TYPE_NULL) {
487
+ *exists = false;
488
+ return true;
489
+ }
490
+
491
+ return false;
492
+ }
559
493
 
560
494
  /*--------------------------------------------------------------------------
561
495
  *
@@ -573,13 +507,10 @@ get_exists_operator (const bson_value_t *value, bool *exists)
573
507
  *--------------------------------------------------------------------------
574
508
  */
575
509
 
576
- bool
577
- get_empty_operator (const bson_value_t *value, bool *empty)
578
- {
579
- return _is_operator ("$empty", value, empty);
510
+ bool get_empty_operator(const bson_value_t *value, bool *empty) {
511
+ return _is_operator("$empty", value, empty);
580
512
  }
581
513
 
582
-
583
514
  /*--------------------------------------------------------------------------
584
515
  *
585
516
  * get_type_operator --
@@ -596,72 +527,68 @@ get_empty_operator (const bson_value_t *value, bool *empty)
596
527
  *--------------------------------------------------------------------------
597
528
  */
598
529
 
599
- static bool
600
- get_type_operator (const bson_value_t *value, bson_type_t *out)
601
- {
602
- bson_t bson;
603
- bson_iter_t iter;
604
- const char *value_string;
605
-
606
- /* See list of aliases on this page:
607
- * https://docs.mongodb.com/manual/reference/bson-types/ */
608
- if (value->value_type == BSON_TYPE_DOCUMENT &&
609
- bson_init_from_value (&bson, value) &&
610
- bson_iter_init_find (&iter, &bson, "$$type")) {
611
- value_string = bson_iter_utf8 (&iter, NULL);
612
- if (0 == strcasecmp ("double", value_string)) {
613
- *out = BSON_TYPE_DOUBLE;
614
- } else if (0 == strcasecmp ("string", value_string)) {
615
- *out = BSON_TYPE_UTF8;
616
- } else if (0 == strcasecmp ("object", value_string)) {
617
- *out = BSON_TYPE_DOCUMENT;
618
- } else if (0 == strcasecmp ("array", value_string)) {
619
- *out = BSON_TYPE_ARRAY;
620
- } else if (0 == strcasecmp ("binData", value_string)) {
621
- *out = BSON_TYPE_BINARY;
622
- } else if (0 == strcasecmp ("undefined", value_string)) {
623
- *out = BSON_TYPE_UNDEFINED;
624
- } else if (0 == strcasecmp ("objectId", value_string)) {
625
- *out = BSON_TYPE_OID;
626
- } else if (0 == strcasecmp ("bool", value_string)) {
627
- *out = BSON_TYPE_BOOL;
628
- } else if (0 == strcasecmp ("date", value_string)) {
629
- *out = BSON_TYPE_DATE_TIME;
630
- } else if (0 == strcasecmp ("null", value_string)) {
631
- *out = BSON_TYPE_NULL;
632
- } else if (0 == strcasecmp ("regex", value_string)) {
633
- *out = BSON_TYPE_REGEX;
634
- } else if (0 == strcasecmp ("dbPointer", value_string)) {
635
- *out = BSON_TYPE_DBPOINTER;
636
- } else if (0 == strcasecmp ("javascript", value_string)) {
637
- *out = BSON_TYPE_CODE;
638
- } else if (0 == strcasecmp ("symbol", value_string)) {
639
- *out = BSON_TYPE_SYMBOL;
640
- } else if (0 == strcasecmp ("javascriptWithScope", value_string)) {
641
- *out = BSON_TYPE_CODEWSCOPE;
642
- } else if (0 == strcasecmp ("int", value_string)) {
643
- *out = BSON_TYPE_INT32;
644
- } else if (0 == strcasecmp ("timestamp", value_string)) {
645
- *out = BSON_TYPE_TIMESTAMP;
646
- } else if (0 == strcasecmp ("long", value_string)) {
647
- *out = BSON_TYPE_INT64;
648
- } else if (0 == strcasecmp ("decimal", value_string)) {
649
- *out = BSON_TYPE_DECIMAL128;
650
- } else if (0 == strcasecmp ("minKey", value_string)) {
651
- *out = BSON_TYPE_MINKEY;
652
- } else if (0 == strcasecmp ("maxKey", value_string)) {
653
- *out = BSON_TYPE_MAXKEY;
654
- } else {
655
- fprintf (stderr, "unrecognized $$type value: %s\n", value_string);
656
- abort ();
657
- }
658
- return true;
659
- }
660
-
661
- return false;
530
+ static bool get_type_operator(const bson_value_t *value, bson_type_t *out) {
531
+ bson_t bson;
532
+ bson_iter_t iter;
533
+ const char *value_string;
534
+
535
+ /* See list of aliases on this page:
536
+ * https://docs.mongodb.com/manual/reference/bson-types/ */
537
+ if (value->value_type == BSON_TYPE_DOCUMENT && bson_init_from_value(&bson, value)
538
+ && bson_iter_init_find(&iter, &bson, "$$type")) {
539
+ value_string = bson_iter_utf8(&iter, NULL);
540
+ if (0 == strcasecmp("double", value_string)) {
541
+ *out = BSON_TYPE_DOUBLE;
542
+ } else if (0 == strcasecmp("string", value_string)) {
543
+ *out = BSON_TYPE_UTF8;
544
+ } else if (0 == strcasecmp("object", value_string)) {
545
+ *out = BSON_TYPE_DOCUMENT;
546
+ } else if (0 == strcasecmp("array", value_string)) {
547
+ *out = BSON_TYPE_ARRAY;
548
+ } else if (0 == strcasecmp("binData", value_string)) {
549
+ *out = BSON_TYPE_BINARY;
550
+ } else if (0 == strcasecmp("undefined", value_string)) {
551
+ *out = BSON_TYPE_UNDEFINED;
552
+ } else if (0 == strcasecmp("objectId", value_string)) {
553
+ *out = BSON_TYPE_OID;
554
+ } else if (0 == strcasecmp("bool", value_string)) {
555
+ *out = BSON_TYPE_BOOL;
556
+ } else if (0 == strcasecmp("date", value_string)) {
557
+ *out = BSON_TYPE_DATE_TIME;
558
+ } else if (0 == strcasecmp("null", value_string)) {
559
+ *out = BSON_TYPE_NULL;
560
+ } else if (0 == strcasecmp("regex", value_string)) {
561
+ *out = BSON_TYPE_REGEX;
562
+ } else if (0 == strcasecmp("dbPointer", value_string)) {
563
+ *out = BSON_TYPE_DBPOINTER;
564
+ } else if (0 == strcasecmp("javascript", value_string)) {
565
+ *out = BSON_TYPE_CODE;
566
+ } else if (0 == strcasecmp("symbol", value_string)) {
567
+ *out = BSON_TYPE_SYMBOL;
568
+ } else if (0 == strcasecmp("javascriptWithScope", value_string)) {
569
+ *out = BSON_TYPE_CODEWSCOPE;
570
+ } else if (0 == strcasecmp("int", value_string)) {
571
+ *out = BSON_TYPE_INT32;
572
+ } else if (0 == strcasecmp("timestamp", value_string)) {
573
+ *out = BSON_TYPE_TIMESTAMP;
574
+ } else if (0 == strcasecmp("long", value_string)) {
575
+ *out = BSON_TYPE_INT64;
576
+ } else if (0 == strcasecmp("decimal", value_string)) {
577
+ *out = BSON_TYPE_DECIMAL128;
578
+ } else if (0 == strcasecmp("minKey", value_string)) {
579
+ *out = BSON_TYPE_MINKEY;
580
+ } else if (0 == strcasecmp("maxKey", value_string)) {
581
+ *out = BSON_TYPE_MAXKEY;
582
+ } else {
583
+ fprintf(stderr, "unrecognized $$type value: %s\n", value_string);
584
+ abort();
585
+ }
586
+ return true;
587
+ }
588
+
589
+ return false;
662
590
  }
663
591
 
664
-
665
592
  /*--------------------------------------------------------------------------
666
593
  *
667
594
  * is_empty_doc_or_array --
@@ -671,409 +598,309 @@ get_type_operator (const bson_value_t *value, bson_type_t *out)
671
598
  *--------------------------------------------------------------------------
672
599
  */
673
600
 
674
- static bool
675
- is_empty_doc_or_array (const bson_value_t *value)
676
- {
677
- bson_t doc;
678
-
679
- if (!(value->value_type == BSON_TYPE_ARRAY ||
680
- value->value_type == BSON_TYPE_DOCUMENT)) {
681
- return false;
682
- }
683
- BSON_ASSERT (bson_init_static (
684
- &doc, value->value.v_doc.data, value->value.v_doc.data_len));
685
-
686
- return bson_count_keys (&doc) == 0;
687
- }
601
+ static bool is_empty_doc_or_array(const bson_value_t *value) {
602
+ bson_t doc;
688
603
 
604
+ if (!(value->value_type == BSON_TYPE_ARRAY || value->value_type == BSON_TYPE_DOCUMENT)) {
605
+ return false;
606
+ }
607
+ BSON_ASSERT(bson_init_static(&doc, value->value.v_doc.data, value->value.v_doc.data_len));
689
608
 
690
- static bool
691
- match_bson_arrays (const bson_t *array, const bson_t *pattern, match_ctx_t *ctx)
692
- {
693
- uint32_t array_count;
694
- uint32_t pattern_count;
695
- bson_iter_t array_iter;
696
- bson_iter_t pattern_iter;
697
- const bson_value_t *array_value;
698
- const bson_value_t *pattern_value;
699
- match_ctx_t derived;
700
-
701
- array_count = bson_count_keys (array);
702
- pattern_count = bson_count_keys (pattern);
703
-
704
- if (array_count != pattern_count) {
705
- match_err (ctx,
706
- "expected %" PRIu32 " keys, not %" PRIu32,
707
- pattern_count,
708
- array_count);
709
- return false;
710
- }
711
-
712
- BSON_ASSERT (bson_iter_init (&array_iter, array));
713
- BSON_ASSERT (bson_iter_init (&pattern_iter, pattern));
714
-
715
- while (bson_iter_next (&array_iter)) {
716
- BSON_ASSERT (bson_iter_next (&pattern_iter));
717
- array_value = bson_iter_value (&array_iter);
718
- pattern_value = bson_iter_value (&pattern_iter);
719
-
720
- derive (ctx, &derived, bson_iter_key (&array_iter));
721
-
722
- if (!match_bson_value (array_value, pattern_value, &derived)) {
723
- return false;
724
- }
725
- }
726
-
727
- return true;
609
+ return bson_count_keys(&doc) == 0;
728
610
  }
729
611
 
612
+ static bool match_bson_arrays(const bson_t *array, const bson_t *pattern, match_ctx_t *ctx) {
613
+ uint32_t array_count;
614
+ uint32_t pattern_count;
615
+ bson_iter_t array_iter;
616
+ bson_iter_t pattern_iter;
617
+ const bson_value_t *array_value;
618
+ const bson_value_t *pattern_value;
619
+ match_ctx_t derived;
730
620
 
731
- static bool
732
- is_number_type (bson_type_t t)
733
- {
734
- if (t == BSON_TYPE_DOUBLE || t == BSON_TYPE_INT32 || t == BSON_TYPE_INT64) {
735
- return true;
736
- }
621
+ array_count = bson_count_keys(array);
622
+ pattern_count = bson_count_keys(pattern);
623
+
624
+ if (array_count != pattern_count) {
625
+ match_err(ctx, "expected %" PRIu32 " keys, not %" PRIu32, pattern_count, array_count);
626
+ return false;
627
+ }
737
628
 
738
- return false;
629
+ BSON_ASSERT(bson_iter_init(&array_iter, array));
630
+ BSON_ASSERT(bson_iter_init(&pattern_iter, pattern));
631
+
632
+ while (bson_iter_next(&array_iter)) {
633
+ BSON_ASSERT(bson_iter_next(&pattern_iter));
634
+ array_value = bson_iter_value(&array_iter);
635
+ pattern_value = bson_iter_value(&pattern_iter);
636
+
637
+ derive(ctx, &derived, bson_iter_key(&array_iter));
638
+
639
+ if (!match_bson_value(array_value, pattern_value, &derived)) {
640
+ return false;
641
+ }
642
+ }
643
+
644
+ return true;
739
645
  }
740
646
 
647
+ static bool is_number_type(bson_type_t t) {
648
+ if (t == BSON_TYPE_DOUBLE || t == BSON_TYPE_INT32 || t == BSON_TYPE_INT64) {
649
+ return true;
650
+ }
741
651
 
742
- int64_t
743
- bson_value_as_int64 (const bson_value_t *value)
744
- {
745
- if (value->value_type == BSON_TYPE_DOUBLE) {
746
- return (int64_t) value->value.v_double;
747
- } else if (value->value_type == BSON_TYPE_INT32) {
748
- return (int64_t) value->value.v_int32;
749
- } else if (value->value_type == BSON_TYPE_INT64) {
750
- return value->value.v_int64;
751
- } else {
752
- return -123;
753
- }
652
+ return false;
754
653
  }
755
654
 
655
+ int64_t bson_value_as_int64(const bson_value_t *value) {
656
+ if (value->value_type == BSON_TYPE_DOUBLE) {
657
+ return (int64_t)value->value.v_double;
658
+ } else if (value->value_type == BSON_TYPE_INT32) {
659
+ return (int64_t)value->value.v_int32;
660
+ } else if (value->value_type == BSON_TYPE_INT64) {
661
+ return value->value.v_int64;
662
+ } else {
663
+ return -123;
664
+ }
665
+ }
666
+
667
+ bool match_bson_value(const bson_value_t *doc, const bson_value_t *pattern, match_ctx_t *ctx) {
668
+ bson_t subdoc;
669
+ bson_t pattern_subdoc;
670
+ int64_t doc_int64;
671
+ int64_t pattern_int64;
672
+ bool ret = false;
673
+
674
+ if (ctx && ctx->allow_placeholders) {
675
+ /* The change streams spec tests use the value 42 as a placeholder. */
676
+ bool is_placeholder = false;
677
+ if (is_number_type(pattern->value_type) && bson_value_as_int64(pattern) == 42) {
678
+ is_placeholder = true;
679
+ }
680
+ if (pattern->value_type == BSON_TYPE_UTF8 && !strcmp(pattern->value.v_utf8.str, "42")) {
681
+ is_placeholder = true;
682
+ }
683
+ if (is_placeholder) {
684
+ return true;
685
+ }
686
+ }
687
+
688
+ if (is_number_type(doc->value_type) && is_number_type(pattern->value_type) && ctx && !ctx->strict_numeric_types) {
689
+ doc_int64 = bson_value_as_int64(doc);
690
+ pattern_int64 = bson_value_as_int64(pattern);
691
+
692
+ if (doc_int64 != pattern_int64) {
693
+ match_err(ctx, "expected %" PRId64 ", got %" PRId64, pattern_int64, doc_int64);
694
+ return false;
695
+ }
696
+
697
+ return true;
698
+ }
699
+
700
+ if (doc->value_type != pattern->value_type) {
701
+ match_err(ctx,
702
+ "expected type %s, got %s",
703
+ _mongoc_bson_type_to_str(pattern->value_type),
704
+ _mongoc_bson_type_to_str(doc->value_type));
705
+ return false;
706
+ }
707
+
708
+ switch (doc->value_type) {
709
+ case BSON_TYPE_ARRAY:
710
+ case BSON_TYPE_DOCUMENT:
711
+
712
+ if (!bson_init_from_value(&subdoc, doc)) {
713
+ return false;
714
+ }
715
+
716
+ if (!bson_init_from_value(&pattern_subdoc, pattern)) {
717
+ bson_destroy(&subdoc);
718
+ return false;
719
+ }
720
+
721
+ if (doc->value_type == BSON_TYPE_ARRAY) {
722
+ ret = match_bson_arrays(&subdoc, &pattern_subdoc, ctx);
723
+ } else {
724
+ ret = match_bson_with_ctx(&subdoc, &pattern_subdoc, ctx);
725
+ }
726
+
727
+ bson_destroy(&subdoc);
728
+ bson_destroy(&pattern_subdoc);
729
+
730
+ return ret;
731
+
732
+ case BSON_TYPE_BINARY:
733
+ ret = doc->value.v_binary.data_len == pattern->value.v_binary.data_len
734
+ && !memcmp(doc->value.v_binary.data, pattern->value.v_binary.data, doc->value.v_binary.data_len);
735
+ break;
736
+
737
+ case BSON_TYPE_BOOL:
738
+ ret = doc->value.v_bool == pattern->value.v_bool;
739
+
740
+ if (!ret) {
741
+ match_err(ctx, "expected %d, got %d", pattern->value.v_bool, doc->value.v_bool);
742
+ }
743
+
744
+ return ret;
745
+
746
+ case BSON_TYPE_CODE:
747
+ ret = doc->value.v_code.code_len == pattern->value.v_code.code_len
748
+ && !memcmp(doc->value.v_code.code, pattern->value.v_code.code, doc->value.v_code.code_len);
749
+
750
+ break;
751
+
752
+ case BSON_TYPE_CODEWSCOPE:
753
+ ret = doc->value.v_codewscope.code_len == pattern->value.v_codewscope.code_len
754
+ && !memcmp(doc->value.v_codewscope.code, pattern->value.v_codewscope.code, doc->value.v_codewscope.code_len)
755
+ && doc->value.v_codewscope.scope_len == pattern->value.v_codewscope.scope_len
756
+ && !memcmp(doc->value.v_codewscope.scope_data,
757
+ pattern->value.v_codewscope.scope_data,
758
+ doc->value.v_codewscope.scope_len);
759
+
760
+ break;
761
+
762
+ case BSON_TYPE_DATE_TIME:
763
+ ret = doc->value.v_datetime == pattern->value.v_datetime;
764
+
765
+ if (!ret) {
766
+ match_err(ctx, "expected %" PRId64 ", got %" PRId64, pattern->value.v_datetime, doc->value.v_datetime);
767
+ }
768
+
769
+ return ret;
770
+
771
+ case BSON_TYPE_DOUBLE:
772
+ ret = doc->value.v_double == pattern->value.v_double;
773
+
774
+ if (!ret) {
775
+ match_err(ctx, "expected %f, got %f", pattern->value.v_double, doc->value.v_double);
776
+ }
777
+
778
+ return ret;
779
+
780
+ case BSON_TYPE_INT32:
781
+ ret = doc->value.v_int32 == pattern->value.v_int32;
782
+
783
+ if (!ret) {
784
+ match_err(ctx, "expected %" PRId32 ", got %" PRId32, pattern->value.v_int32, doc->value.v_int32);
785
+ }
786
+
787
+ return ret;
788
+
789
+ case BSON_TYPE_INT64:
790
+ ret = doc->value.v_int64 == pattern->value.v_int64;
791
+
792
+ if (!ret) {
793
+ match_err(ctx, "expected %" PRId64 ", got %" PRId64, pattern->value.v_int64, doc->value.v_int64);
794
+ }
795
+
796
+ return ret;
797
+
798
+ case BSON_TYPE_OID: ret = bson_oid_equal(&doc->value.v_oid, &pattern->value.v_oid); break;
799
+
800
+ case BSON_TYPE_REGEX:
801
+ ret = !strcmp(doc->value.v_regex.regex, pattern->value.v_regex.regex)
802
+ && !strcmp(doc->value.v_regex.options, pattern->value.v_regex.options);
803
+
804
+ break;
805
+
806
+ case BSON_TYPE_SYMBOL:
807
+ ret = doc->value.v_symbol.len == pattern->value.v_symbol.len
808
+ && !strncmp(doc->value.v_symbol.symbol, pattern->value.v_symbol.symbol, doc->value.v_symbol.len);
809
+
810
+ break;
811
+
812
+ case BSON_TYPE_TIMESTAMP:
813
+ ret = doc->value.v_timestamp.timestamp == pattern->value.v_timestamp.timestamp
814
+ && doc->value.v_timestamp.increment == pattern->value.v_timestamp.increment;
815
+
816
+ break;
817
+
818
+ case BSON_TYPE_UTF8:
819
+ ret = doc->value.v_utf8.len == pattern->value.v_utf8.len
820
+ && !strncmp(doc->value.v_utf8.str, pattern->value.v_utf8.str, doc->value.v_utf8.len);
821
+
822
+ if (!ret) {
823
+ match_err(ctx, "expected \"%s\", got \"%s\"", pattern->value.v_utf8.str, doc->value.v_utf8.str);
824
+ }
825
+
826
+ return ret;
827
+
828
+ /* these are empty types, if "a" and "b" are the same type they're equal */
829
+ case BSON_TYPE_EOD:
830
+ case BSON_TYPE_MAXKEY:
831
+ case BSON_TYPE_MINKEY:
832
+ case BSON_TYPE_NULL:
833
+ case BSON_TYPE_UNDEFINED: return true;
834
+
835
+ case BSON_TYPE_DBPOINTER:
836
+ ret = (0 == strcmp(doc->value.v_dbpointer.collection, pattern->value.v_dbpointer.collection)
837
+ && bson_oid_equal(&doc->value.v_dbpointer.oid, &pattern->value.v_dbpointer.oid));
838
+ break;
839
+
840
+ case BSON_TYPE_DECIMAL128:
841
+ ret = (doc->value.v_decimal128.low == pattern->value.v_decimal128.low
842
+ && doc->value.v_decimal128.high == pattern->value.v_decimal128.high);
843
+ if (!ret) {
844
+ match_err(ctx,
845
+ "Decimal128 is not an exact binary match (though "
846
+ "numeric values may be equal)");
847
+ }
848
+ break;
849
+ default: match_err(ctx, "unexpected value type %d: %s", doc->value_type, _mongoc_bson_type_to_str(doc->value_type));
850
+ }
851
+
852
+ if (!ret) {
853
+ match_err(ctx, "%s values mismatch", _mongoc_bson_type_to_str(pattern->value_type));
854
+ }
756
855
 
757
- bool
758
- match_bson_value (const bson_value_t *doc,
759
- const bson_value_t *pattern,
760
- match_ctx_t *ctx)
761
- {
762
- bson_t subdoc;
763
- bson_t pattern_subdoc;
764
- int64_t doc_int64;
765
- int64_t pattern_int64;
766
- bool ret = false;
767
-
768
- if (ctx && ctx->allow_placeholders) {
769
- /* The change streams spec tests use the value 42 as a placeholder. */
770
- bool is_placeholder = false;
771
- if (is_number_type (pattern->value_type) &&
772
- bson_value_as_int64 (pattern) == 42) {
773
- is_placeholder = true;
774
- }
775
- if (pattern->value_type == BSON_TYPE_UTF8 &&
776
- !strcmp (pattern->value.v_utf8.str, "42")) {
777
- is_placeholder = true;
778
- }
779
- if (is_placeholder) {
780
- return true;
781
- }
782
- }
783
-
784
- if (is_number_type (doc->value_type) &&
785
- is_number_type (pattern->value_type) && ctx &&
786
- !ctx->strict_numeric_types) {
787
- doc_int64 = bson_value_as_int64 (doc);
788
- pattern_int64 = bson_value_as_int64 (pattern);
789
-
790
- if (doc_int64 != pattern_int64) {
791
- match_err (ctx,
792
- "expected %" PRId64 ", got %" PRId64,
793
- pattern_int64,
794
- doc_int64);
795
- return false;
796
- }
797
-
798
- return true;
799
- }
800
-
801
- if (doc->value_type != pattern->value_type) {
802
- match_err (ctx,
803
- "expected type %s, got %s",
804
- _mongoc_bson_type_to_str (pattern->value_type),
805
- _mongoc_bson_type_to_str (doc->value_type));
806
- return false;
807
- }
808
-
809
- switch (doc->value_type) {
810
- case BSON_TYPE_ARRAY:
811
- case BSON_TYPE_DOCUMENT:
812
-
813
- if (!bson_init_from_value (&subdoc, doc)) {
814
- return false;
815
- }
816
-
817
- if (!bson_init_from_value (&pattern_subdoc, pattern)) {
818
- bson_destroy (&subdoc);
819
- return false;
820
- }
821
-
822
- if (doc->value_type == BSON_TYPE_ARRAY) {
823
- ret = match_bson_arrays (&subdoc, &pattern_subdoc, ctx);
824
- } else {
825
- ret = match_bson_with_ctx (&subdoc, &pattern_subdoc, ctx);
826
- }
827
-
828
- bson_destroy (&subdoc);
829
- bson_destroy (&pattern_subdoc);
830
-
831
- return ret;
832
-
833
- case BSON_TYPE_BINARY:
834
- ret = doc->value.v_binary.data_len == pattern->value.v_binary.data_len &&
835
- !memcmp (doc->value.v_binary.data,
836
- pattern->value.v_binary.data,
837
- doc->value.v_binary.data_len);
838
- break;
839
-
840
- case BSON_TYPE_BOOL:
841
- ret = doc->value.v_bool == pattern->value.v_bool;
842
-
843
- if (!ret) {
844
- match_err (ctx,
845
- "expected %d, got %d",
846
- pattern->value.v_bool,
847
- doc->value.v_bool);
848
- }
849
-
850
- return ret;
851
-
852
- case BSON_TYPE_CODE:
853
- ret = doc->value.v_code.code_len == pattern->value.v_code.code_len &&
854
- !memcmp (doc->value.v_code.code,
855
- pattern->value.v_code.code,
856
- doc->value.v_code.code_len);
857
-
858
- break;
859
-
860
- case BSON_TYPE_CODEWSCOPE:
861
- ret = doc->value.v_codewscope.code_len ==
862
- pattern->value.v_codewscope.code_len &&
863
- !memcmp (doc->value.v_codewscope.code,
864
- pattern->value.v_codewscope.code,
865
- doc->value.v_codewscope.code_len) &&
866
- doc->value.v_codewscope.scope_len ==
867
- pattern->value.v_codewscope.scope_len &&
868
- !memcmp (doc->value.v_codewscope.scope_data,
869
- pattern->value.v_codewscope.scope_data,
870
- doc->value.v_codewscope.scope_len);
871
-
872
- break;
873
-
874
- case BSON_TYPE_DATE_TIME:
875
- ret = doc->value.v_datetime == pattern->value.v_datetime;
876
-
877
- if (!ret) {
878
- match_err (ctx,
879
- "expected %" PRId64 ", got %" PRId64,
880
- pattern->value.v_datetime,
881
- doc->value.v_datetime);
882
- }
883
-
884
- return ret;
885
-
886
- case BSON_TYPE_DOUBLE:
887
- ret = doc->value.v_double == pattern->value.v_double;
888
-
889
- if (!ret) {
890
- match_err (ctx,
891
- "expected %f, got %f",
892
- pattern->value.v_double,
893
- doc->value.v_double);
894
- }
895
-
896
- return ret;
897
-
898
- case BSON_TYPE_INT32:
899
- ret = doc->value.v_int32 == pattern->value.v_int32;
900
-
901
- if (!ret) {
902
- match_err (ctx,
903
- "expected %" PRId32 ", got %" PRId32,
904
- pattern->value.v_int32,
905
- doc->value.v_int32);
906
- }
907
-
908
- return ret;
909
-
910
- case BSON_TYPE_INT64:
911
- ret = doc->value.v_int64 == pattern->value.v_int64;
912
-
913
- if (!ret) {
914
- match_err (ctx,
915
- "expected %" PRId64 ", got %" PRId64,
916
- pattern->value.v_int64,
917
- doc->value.v_int64);
918
- }
919
-
920
- return ret;
921
-
922
- case BSON_TYPE_OID:
923
- ret = bson_oid_equal (&doc->value.v_oid, &pattern->value.v_oid);
924
- break;
925
-
926
- case BSON_TYPE_REGEX:
927
- ret =
928
- !strcmp (doc->value.v_regex.regex, pattern->value.v_regex.regex) &&
929
- !strcmp (doc->value.v_regex.options, pattern->value.v_regex.options);
930
-
931
- break;
932
-
933
- case BSON_TYPE_SYMBOL:
934
- ret = doc->value.v_symbol.len == pattern->value.v_symbol.len &&
935
- !strncmp (doc->value.v_symbol.symbol,
936
- pattern->value.v_symbol.symbol,
937
- doc->value.v_symbol.len);
938
-
939
- break;
940
-
941
- case BSON_TYPE_TIMESTAMP:
942
- ret = doc->value.v_timestamp.timestamp ==
943
- pattern->value.v_timestamp.timestamp &&
944
- doc->value.v_timestamp.increment ==
945
- pattern->value.v_timestamp.increment;
946
-
947
- break;
948
-
949
- case BSON_TYPE_UTF8:
950
- ret = doc->value.v_utf8.len == pattern->value.v_utf8.len &&
951
- !strncmp (doc->value.v_utf8.str,
952
- pattern->value.v_utf8.str,
953
- doc->value.v_utf8.len);
954
-
955
- if (!ret) {
956
- match_err (ctx,
957
- "expected \"%s\", got \"%s\"",
958
- pattern->value.v_utf8.str,
959
- doc->value.v_utf8.str);
960
- }
961
-
962
- return ret;
963
-
964
-
965
- /* these are empty types, if "a" and "b" are the same type they're equal */
966
- case BSON_TYPE_EOD:
967
- case BSON_TYPE_MAXKEY:
968
- case BSON_TYPE_MINKEY:
969
- case BSON_TYPE_NULL:
970
- case BSON_TYPE_UNDEFINED:
971
- return true;
972
-
973
- case BSON_TYPE_DBPOINTER:
974
- ret = (0 == strcmp (doc->value.v_dbpointer.collection,
975
- pattern->value.v_dbpointer.collection) &&
976
- bson_oid_equal (&doc->value.v_dbpointer.oid,
977
- &pattern->value.v_dbpointer.oid));
978
- break;
979
-
980
- case BSON_TYPE_DECIMAL128:
981
- ret = (doc->value.v_decimal128.low == pattern->value.v_decimal128.low &&
982
- doc->value.v_decimal128.high == pattern->value.v_decimal128.high);
983
- if (!ret) {
984
- match_err (ctx,
985
- "Decimal128 is not an exact binary match (though "
986
- "numeric values may be equal)");
987
- }
988
- break;
989
- default:
990
- match_err (ctx,
991
- "unexpected value type %d: %s",
992
- doc->value_type,
993
- _mongoc_bson_type_to_str (doc->value_type));
994
- }
995
-
996
- if (!ret) {
997
- match_err (ctx,
998
- "%s values mismatch",
999
- _mongoc_bson_type_to_str (pattern->value_type));
1000
- }
1001
-
1002
- return ret;
856
+ return ret;
1003
857
  }
1004
858
 
1005
- const char *
1006
- _mongoc_bson_type_to_str (bson_type_t t)
1007
- {
1008
- switch (t) {
1009
- case BSON_TYPE_EOD:
1010
- return "EOD";
1011
- case BSON_TYPE_DOUBLE:
1012
- return "DOUBLE";
1013
- case BSON_TYPE_UTF8:
1014
- return "UTF8";
1015
- case BSON_TYPE_DOCUMENT:
1016
- return "DOCUMENT";
1017
- case BSON_TYPE_ARRAY:
1018
- return "ARRAY";
1019
- case BSON_TYPE_BINARY:
1020
- return "BINARY";
1021
- case BSON_TYPE_UNDEFINED:
1022
- return "UNDEFINED";
1023
- case BSON_TYPE_OID:
1024
- return "OID";
1025
- case BSON_TYPE_BOOL:
1026
- return "BOOL";
1027
- case BSON_TYPE_DATE_TIME:
1028
- return "DATE_TIME";
1029
- case BSON_TYPE_NULL:
1030
- return "NULL";
1031
- case BSON_TYPE_REGEX:
1032
- return "REGEX";
1033
- case BSON_TYPE_DBPOINTER:
1034
- return "DBPOINTER";
1035
- case BSON_TYPE_CODE:
1036
- return "CODE";
1037
- case BSON_TYPE_SYMBOL:
1038
- return "SYMBOL";
1039
- case BSON_TYPE_CODEWSCOPE:
1040
- return "CODEWSCOPE";
1041
- case BSON_TYPE_INT32:
1042
- return "INT32";
1043
- case BSON_TYPE_TIMESTAMP:
1044
- return "TIMESTAMP";
1045
- case BSON_TYPE_INT64:
1046
- return "INT64";
1047
- case BSON_TYPE_MAXKEY:
1048
- return "MAXKEY";
1049
- case BSON_TYPE_MINKEY:
1050
- return "MINKEY";
1051
- case BSON_TYPE_DECIMAL128:
1052
- return "DECIMAL128";
1053
- default:
1054
- return "Unknown";
1055
- }
859
+ const char *_mongoc_bson_type_to_str(bson_type_t t) {
860
+ switch (t) {
861
+ case BSON_TYPE_EOD: return "EOD";
862
+ case BSON_TYPE_DOUBLE: return "DOUBLE";
863
+ case BSON_TYPE_UTF8: return "UTF8";
864
+ case BSON_TYPE_DOCUMENT: return "DOCUMENT";
865
+ case BSON_TYPE_ARRAY: return "ARRAY";
866
+ case BSON_TYPE_BINARY: return "BINARY";
867
+ case BSON_TYPE_UNDEFINED: return "UNDEFINED";
868
+ case BSON_TYPE_OID: return "OID";
869
+ case BSON_TYPE_BOOL: return "BOOL";
870
+ case BSON_TYPE_DATE_TIME: return "DATE_TIME";
871
+ case BSON_TYPE_NULL: return "NULL";
872
+ case BSON_TYPE_REGEX: return "REGEX";
873
+ case BSON_TYPE_DBPOINTER: return "DBPOINTER";
874
+ case BSON_TYPE_CODE: return "CODE";
875
+ case BSON_TYPE_SYMBOL: return "SYMBOL";
876
+ case BSON_TYPE_CODEWSCOPE: return "CODEWSCOPE";
877
+ case BSON_TYPE_INT32: return "INT32";
878
+ case BSON_TYPE_TIMESTAMP: return "TIMESTAMP";
879
+ case BSON_TYPE_INT64: return "INT64";
880
+ case BSON_TYPE_MAXKEY: return "MAXKEY";
881
+ case BSON_TYPE_MINKEY: return "MINKEY";
882
+ case BSON_TYPE_DECIMAL128: return "DECIMAL128";
883
+ default: return "Unknown";
884
+ }
1056
885
  }
1057
886
 
1058
- void
1059
- _assert_match_bson (const bson_t *doc, const bson_t *pattern)
1060
- {
1061
- match_ctx_t ctx;
1062
-
1063
- memset (&ctx, 0, sizeof (match_ctx_t));
1064
- if (!match_bson_with_ctx (doc, pattern, &ctx)) {
1065
- char *doc_str = doc ? bson_as_json (doc, NULL) : NULL;
1066
- char *pattern_str = bson_as_json (pattern, NULL);
1067
-
1068
- TEST_ERROR ("ASSERT_MATCH failed with document:\n\n"
1069
- "%s\n"
1070
- "pattern:\n%s\n"
1071
- "%s\n",
1072
- doc_str ? doc_str : "{}",
1073
- pattern_str,
1074
- ctx.errmsg);
1075
-
1076
- bson_free (doc_str);
1077
- bson_free (pattern_str);
1078
- }
887
+ void _assert_match_bson(const bson_t *doc, const bson_t *pattern) {
888
+ match_ctx_t ctx;
889
+
890
+ memset(&ctx, 0, sizeof(match_ctx_t));
891
+ if (!match_bson_with_ctx(doc, pattern, &ctx)) {
892
+ char *doc_str = doc ? bson_as_json(doc, NULL) : NULL;
893
+ char *pattern_str = bson_as_json(pattern, NULL);
894
+
895
+ TEST_ERROR("ASSERT_MATCH failed with document:\n\n"
896
+ "%s\n"
897
+ "pattern:\n%s\n"
898
+ "%s\n",
899
+ doc_str ? doc_str : "{}",
900
+ pattern_str,
901
+ ctx.errmsg);
902
+
903
+ bson_free(doc_str);
904
+ bson_free(pattern_str);
905
+ }
1079
906
  }