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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/ext/libmongocrypt/libmongocrypt/CHANGELOG.md +9 -7
- data/ext/libmongocrypt/libmongocrypt/CMakeLists.txt +17 -23
- data/ext/libmongocrypt/libmongocrypt/Earthfile +374 -0
- data/ext/libmongocrypt/libmongocrypt/README.md +7 -7
- data/ext/libmongocrypt/libmongocrypt/VERSION_CURRENT +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/CryptClient.cs +25 -6
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt/Library.cs +25 -3
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Example/MongoDB.Libmongocrypt.Example.csproj +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/MongoDB.Libmongocrypt.Test/BasicTests.cs +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/Scripts/build.cake +3 -2
- data/ext/libmongocrypt/libmongocrypt/bindings/cs/cs.sln +79 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/build.gradle.kts +2 -2
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/java/com/mongodb/crypt/capi/MongoCryptTest.java +6 -4
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit-v2/int32/encrypted-payload.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/CHANGELOG.md +24 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/README.md +134 -5
- data/ext/libmongocrypt/libmongocrypt/bindings/node/etc/build-static.sh +3 -6
- data/ext/libmongocrypt/libmongocrypt/bindings/node/index.d.ts +203 -77
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/autoEncrypter.js +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/clientEncryption.js +165 -43
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/common.js +12 -14
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/errors.js +75 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/index.js +34 -3
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/aws.js +26 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/azure.js +178 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/gcp.js +24 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/index.js +54 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/providers/utils.js +39 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/stateMachine.js +9 -4
- data/ext/libmongocrypt/libmongocrypt/bindings/node/package-lock.json +4440 -5189
- data/ext/libmongocrypt/libmongocrypt/bindings/node/package.json +27 -8
- data/ext/libmongocrypt/libmongocrypt/bindings/node/src/mongocrypt.cc +65 -38
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/autoEncrypter.test.js +4 -7
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/clientEncryption.test.js +434 -42
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/common.test.js +94 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/cryptoCallbacks.test.js +1 -45
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/index.test.js +45 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/mongocryptdManager.test.js +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/providers/credentialsProvider.test.js +551 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/release.test.js +10 -3
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/requirements.helper.js +23 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/stateMachine.test.js +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/tools/chai-addons.js +8 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/types/index.test-d.ts +63 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/CHANGELOG.rst +26 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/README.rst +2 -2
- data/ext/libmongocrypt/libmongocrypt/bindings/python/build-manylinux-wheel.sh +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/binding.py +128 -238
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/compat.py +0 -27
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/explicit_encrypter.py +1 -1
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/mongocrypt.py +5 -21
- data/ext/libmongocrypt/libmongocrypt/bindings/python/pymongocrypt/version.py +2 -2
- data/ext/libmongocrypt/libmongocrypt/bindings/python/release.sh +5 -5
- data/ext/libmongocrypt/libmongocrypt/bindings/python/setup.py +14 -9
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/__init__.py +1 -10
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit-v2/int32/encrypted-payload.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/test_mongocrypt.py +5 -5
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test-requirements.txt +4 -12
- data/ext/libmongocrypt/libmongocrypt/cmake/ImportBSON.cmake +8 -6
- data/ext/libmongocrypt/libmongocrypt/cmake/IntelDFP.cmake +2 -1
- data/ext/libmongocrypt/libmongocrypt/cmake/Platform.cmake +50 -0
- data/ext/libmongocrypt/libmongocrypt/cmake/mongocrypt-config.cmake +21 -0
- data/ext/libmongocrypt/libmongocrypt/debian/gbp.conf +2 -2
- data/ext/libmongocrypt/libmongocrypt/etc/c6-vault.repo +39 -0
- data/ext/libmongocrypt/libmongocrypt/etc/fle2_aead_generate_tests.py +15 -24
- data/ext/libmongocrypt/libmongocrypt/etc/fle2_crypto.py +66 -54
- data/ext/libmongocrypt/libmongocrypt/etc/fle2_generate_tests.py +14 -23
- data/ext/libmongocrypt/libmongocrypt/etc/fle2v2_aead_generate_tests.py +32 -0
- data/ext/libmongocrypt/libmongocrypt/etc/format-all.sh +12 -0
- data/ext/libmongocrypt/libmongocrypt/etc/format.sh +16 -0
- data/ext/libmongocrypt/libmongocrypt/etc/install-package.sh +48 -0
- data/ext/libmongocrypt/libmongocrypt/etc/mongo-inteldfp-libmongocrypt-pr-625.patch +13 -0
- data/ext/libmongocrypt/libmongocrypt/src/crypto/cng.c +381 -436
- data/ext/libmongocrypt/libmongocrypt/src/crypto/commoncrypto.c +162 -227
- data/ext/libmongocrypt/libmongocrypt/src/crypto/libcrypto.c +180 -248
- data/ext/libmongocrypt/libmongocrypt/src/crypto/none.c +33 -55
- data/ext/libmongocrypt/libmongocrypt/src/csfle-markup.cpp +175 -205
- data/ext/libmongocrypt/libmongocrypt/src/mc-array-private.h +10 -21
- data/ext/libmongocrypt/libmongocrypt/src/mc-array.c +44 -56
- data/ext/libmongocrypt/libmongocrypt/src/mc-check-conversions-private.h +4 -8
- data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.h +351 -463
- data/ext/libmongocrypt/libmongocrypt/src/mc-dec128.test.cpp +59 -66
- data/ext/libmongocrypt/libmongocrypt/src/mc-efc-private.h +7 -11
- data/ext/libmongocrypt/libmongocrypt/src/mc-efc.c +80 -92
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle-blob-subtype-private.h +18 -10
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder-private.h +59 -70
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-encryption-placeholder.c +384 -439
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private-v2.h +41 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-private.h +11 -18
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload-v2.c +135 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-equality-payload.c +109 -126
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private-v2.h +88 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-private.h +24 -27
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload-v2.c +137 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-find-range-payload.c +106 -125
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private-v2.h +117 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-private.h +28 -36
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload-v2.c +294 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-insert-update-payload.c +237 -278
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-private-v2.h +133 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-private.h +67 -56
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev-v2.c +437 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-iev.c +476 -325
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-common-private.h +69 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-common.c +182 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-private.h +23 -31
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-v2-private.h +85 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev-v2.c +142 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-payload-uev.c +104 -231
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-range-operator-private.h +8 -7
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds-private.h +55 -56
- data/ext/libmongocrypt/libmongocrypt/src/mc-fle2-rfds.c +517 -580
- data/ext/libmongocrypt/libmongocrypt/src/mc-optional-private.h +36 -66
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation-private.h +57 -76
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-edge-generation.c +158 -189
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding-private.h +36 -42
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-encoding.c +515 -558
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-generator.template.h +155 -191
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover-private.h +43 -53
- data/ext/libmongocrypt/libmongocrypt/src/mc-range-mincover.c +170 -240
- data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts-private.h +29 -34
- data/ext/libmongocrypt/libmongocrypt/src/mc-rangeopts.c +289 -338
- data/ext/libmongocrypt/libmongocrypt/src/mc-reader-private.h +36 -71
- data/ext/libmongocrypt/libmongocrypt/src/mc-reader.c +111 -164
- data/ext/libmongocrypt/libmongocrypt/src/mc-tokens-private.h +55 -49
- data/ext/libmongocrypt/libmongocrypt/src/mc-tokens.c +109 -125
- data/ext/libmongocrypt/libmongocrypt/src/mc-writer-private.h +66 -0
- data/ext/libmongocrypt/libmongocrypt/src/mc-writer.c +141 -0
- data/ext/libmongocrypt/libmongocrypt/src/mlib/check.hpp +37 -55
- data/ext/libmongocrypt/libmongocrypt/src/mlib/endian.h +11 -11
- data/ext/libmongocrypt/libmongocrypt/src/mlib/error.h +27 -32
- data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.h +444 -499
- data/ext/libmongocrypt/libmongocrypt/src/mlib/int128.test.cpp +251 -334
- data/ext/libmongocrypt/libmongocrypt/src/mlib/macros.h +4 -5
- data/ext/libmongocrypt/libmongocrypt/src/mlib/path.h +196 -231
- data/ext/libmongocrypt/libmongocrypt/src/mlib/path.test.c +56 -79
- data/ext/libmongocrypt/libmongocrypt/src/mlib/str.h +411 -530
- data/ext/libmongocrypt/libmongocrypt/src/mlib/str.test.c +116 -131
- data/ext/libmongocrypt/libmongocrypt/src/mlib/thread.h +17 -26
- data/ext/libmongocrypt/libmongocrypt/src/mlib/user-check.h +2 -2
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary-private.h +3 -6
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-binary.c +31 -48
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer-private.h +55 -131
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-buffer.c +444 -565
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-collinfo-private.h +1 -2
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-collinfo.c +28 -45
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key-private.h +11 -17
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-key.c +103 -132
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth-private.h +8 -14
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-oauth.c +78 -90
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache-private.h +26 -45
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-cache.c +220 -273
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ciphertext-private.h +13 -25
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ciphertext.c +147 -166
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-compat.h +2 -2
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto-private.h +110 -204
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-crypto.c +1137 -1565
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-datakey.c +425 -472
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-decrypt.c +817 -694
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-encrypt.c +2394 -2697
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-private.h +166 -186
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx-rewrap-many-datakey.c +308 -351
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-ctx.c +921 -1138
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-dll-private.h +16 -24
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endian-private.h +44 -58
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endpoint-private.h +21 -25
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-endpoint.c +167 -181
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek-private.h +37 -43
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kek.c +215 -253
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker-private.h +73 -108
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-broker.c +889 -1034
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key-private.h +27 -44
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-key.c +349 -402
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx-private.h +92 -120
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-kms-ctx.c +1397 -1612
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-log-private.h +35 -67
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-log.c +49 -83
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking-private.h +30 -36
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-marking.c +1821 -1470
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-mutex-private.h +7 -12
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts-private.h +80 -108
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-opts.c +354 -424
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-private.h +101 -117
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-status-private.h +3 -8
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-status.c +92 -119
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-traverse-util-private.h +19 -29
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-traverse-util.c +136 -176
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util-private.h +11 -21
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt-util.c +96 -135
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.c +1092 -1320
- data/ext/libmongocrypt/libmongocrypt/src/mongocrypt.h +130 -295
- data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_dll.c +66 -78
- data/ext/libmongocrypt/libmongocrypt/src/os_posix/os_mutex.c +20 -28
- data/ext/libmongocrypt/libmongocrypt/src/os_win/os_dll.c +60 -73
- data/ext/libmongocrypt/libmongocrypt/src/os_win/os_mutex.c +8 -16
- data/ext/libmongocrypt/libmongocrypt/test/crypt_shared-stub.cpp +57 -87
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-delete/empty/encrypted-payload-v2.json +60 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-delete/success/encrypted-payload-v2.json +67 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explain/with-csfle/encrypted-payload.json +2 -2
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/find-indexed-contentionFactor1-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/find-indexed-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-contentionFactor1-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-same-user-and-index-key-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-explicit/insert-indexed-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/cmd.json +6 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/encrypted-field-map.json +22 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/encrypted-payload.json +40 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-equality-v2/mongocryptd-reply.json +19 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/cmd.json +10 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/encrypted-payload.json +41 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/date-v2/mongocryptd-reply.json +49 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/cmd.json +6 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/encrypted-field-map.json +30 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/encrypted-payload.json +50 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-precision-v2/mongocryptd-reply.json +58 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/cmd.json +6 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/encrypted-payload.json +41 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/decimal128-v2/mongocryptd-reply.json +49 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/cmd.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/encrypted-field-map.json +30 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/encrypted-payload.json +44 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-precision-v2/mongocryptd-reply.json +52 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/cmd.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/encrypted-payload.json +41 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/double-v2/mongocryptd-reply.json +49 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/cmd.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/encrypted-payload.json +41 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int32-v2/mongocryptd-reply.json +49 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/cmd.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/encrypted-payload.json +41 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range/int64-v2/mongocryptd-reply.json +49 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/double/encrypted-payload-v2.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/double-precision/encrypted-payload-v2.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32/encrypted-payload-v2.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/encrypted-payload-v2.json +26 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-openinterval/encrypted-payload-v2.json +16 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert/cmd.json +1 -1
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date/RNG_DATA.h +65 -65
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/cmd.json +13 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/encrypted-payload.json +44 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/date-v2/mongocryptd-reply.json +52 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128/RNG_DATA.h +132 -132
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision/RNG_DATA.h +71 -71
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/cmd.json +9 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/encrypted-field-map.json +30 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/encrypted-payload.json +53 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-precision-v2/mongocryptd-reply.json +61 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/cmd.json +9 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/encrypted-payload.json +44 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/decimal128-v2/mongocryptd-reply.json +52 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double/RNG_DATA.h +68 -68
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision/RNG_DATA.h +19 -19
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/cmd.json +11 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/encrypted-field-map.json +30 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/encrypted-payload.json +47 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-precision-v2/mongocryptd-reply.json +55 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/cmd.json +11 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/encrypted-payload.json +44 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/double-v2/mongocryptd-reply.json +52 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32/RNG_DATA.h +25 -25
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/cmd.json +11 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/encrypted-payload.json +44 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int32-v2/mongocryptd-reply.json +52 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64/RNG_DATA.h +65 -65
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/cmd.json +11 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/encrypted-field-map.json +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/encrypted-payload.json +44 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range/int64-v2/mongocryptd-reply.json +52 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double/RNG_DATA.h +68 -68
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double/encrypted-payload-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double-precision/RNG_DATA.h +19 -19
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/double-precision/encrypted-payload-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32/RNG_DATA.h +25 -25
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32/encrypted-payload-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/encrypted-payload-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/sparsity-2/RNG_DATA.h +15 -15
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/sparsity-2/encrypted-payload-v2.json +8 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/cmd.json +9 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/encrypted-field-map.json +18 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/encrypted-payload.json +14 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-unindexed-v2/mongocryptd-reply.json +41 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/cmd.json +9 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/encrypted-field-map.json +22 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/encrypted-payload.json +39 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-v2/mongocryptd-reply.json +49 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/iev-v2/FLECrudTest-insertOneRangeV2.json +10 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/iev-v2/FLECrudTest-insertOneV2.json +10 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/README.md +17 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/aes-ctr.json +29 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2-fixed.json +10 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2-generated.json +38 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-decrypt.json +35 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-fixed.json +29 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2aead-generated.json +122 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2v2-aead-fixed.json +29 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/fle2v2-aead-generated.json +122 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/mcgrew.json +12 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/roundtrip/nist.json +20 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/tokens/README.md +27 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/tokens/mc.json +21 -0
- data/ext/libmongocrypt/libmongocrypt/test/data/tokens/server.json +21 -0
- data/ext/libmongocrypt/libmongocrypt/test/example-no-bson.c +4 -4
- data/ext/libmongocrypt/libmongocrypt/test/example-state-machine.c +278 -323
- data/ext/libmongocrypt/libmongocrypt/test/fuzz_kms.c +8 -7
- data/ext/libmongocrypt/libmongocrypt/test/test-dll.cpp +6 -7
- data/ext/libmongocrypt/libmongocrypt/test/test-gcp-auth.c +221 -283
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-efc.c +58 -73
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-equality-payload-v2.c +78 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-find-range-payload-v2.c +89 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iev-v2.c +248 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iev.c +467 -414
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup-v2.c +172 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-iup.c +141 -159
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-uev-v2.c +338 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-payload-uev.c +238 -176
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-fle2-rfds.c +373 -474
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-edge-generation.c +346 -388
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-encoding.c +708 -825
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-range-mincover.c +417 -481
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-rangeopts.c +110 -144
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-reader.c +124 -207
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-tokens.c +223 -213
- data/ext/libmongocrypt/libmongocrypt/test/test-mc-writer.c +176 -0
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.c +634 -807
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert-match-bson.h +1 -2
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-assert.h +168 -189
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-buffer.c +187 -211
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache-oauth.c +34 -36
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-cache.c +210 -233
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ciphertext.c +185 -220
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-compact.c +331 -445
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-hooks.c +670 -814
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.c +102 -135
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto-std-hooks.h +54 -71
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-crypto.c +394 -846
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-csfle-lib.c +159 -183
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-decrypt.c +867 -1045
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-encrypt.c +4349 -4713
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-rewrap-many-datakey.c +750 -964
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-ctx-setopt.c +991 -1178
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-datakey.c +342 -419
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-dll.c +23 -30
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-endpoint.c +98 -111
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kek.c +49 -52
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key-broker.c +770 -920
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key-cache.c +354 -407
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-key.c +197 -245
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-ctx.c +286 -370
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-kms-responses.c +147 -166
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-local-kms.c +50 -61
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-log.c +85 -100
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-marking.c +656 -692
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-status.c +46 -58
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-traverse-util.c +377 -451
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.c +48 -67
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt-util.h +4 -10
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.c +827 -918
- data/ext/libmongocrypt/libmongocrypt/test/test-mongocrypt.h +111 -172
- data/ext/libmongocrypt/libmongocrypt/test/util/csfle.c +508 -559
- data/ext/libmongocrypt/libmongocrypt/test/util/util.c +735 -881
- data/ext/libmongocrypt/libmongocrypt/test/util/util.h +33 -55
- data/lib/libmongocrypt_helper/version.rb +2 -2
- data.tar.gz.sig +0 -0
- metadata +154 -26
- metadata.gz.sig +0 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit/int32/encrypted-payload.json +0 -26
- data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/fle2-find-range-explicit/int32/key-document.json +0 -0
- data/ext/libmongocrypt/libmongocrypt/bindings/node/lib/credentialsProvider.js +0 -33
- data/ext/libmongocrypt/libmongocrypt/bindings/node/test/credentialsProvider.test.js +0 -163
- data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/fle2-find-range-explicit/int32/encrypted-payload.json +0 -26
- data/ext/libmongocrypt/libmongocrypt/test/data/aes-ctr.cstructs +0 -359
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-aead.cstructs +0 -109
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/encrypted-payload.json +0 -26
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/rangeopts.json +0 -5
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-find-range-explicit/int32-nominmax/value-to-encrypt.json +0 -20
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/RNG_DATA.h +0 -70
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/encrypted-payload.json +0 -8
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/rangeopts.json +0 -5
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2-insert-range-explicit/int32-nominmax/value-to-encrypt.json +0 -5
- data/ext/libmongocrypt/libmongocrypt/test/data/fle2.cstructs +0 -33
- /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
- /data/ext/libmongocrypt/libmongocrypt/bindings/java/mongocrypt/src/test/resources/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/rangeopts.json +0 -0
- /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
- /data/ext/libmongocrypt/libmongocrypt/bindings/python/test/data/{fle2-find-range-explicit → fle2-find-range-explicit-v2}/int32/rangeopts.json +0 -0
- /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
|
-
|
38
|
-
|
39
|
-
|
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)
|
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
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
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
|
-
|
97
|
-
|
98
|
-
|
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
|
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
|
-
|
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
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
118
|
+
for (p = result; *p; p++) {
|
119
|
+
if (*p == '\'') {
|
120
|
+
*p = '"';
|
121
|
+
}
|
122
|
+
}
|
151
123
|
|
152
|
-
|
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
|
175
|
-
|
176
|
-
match_json
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
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
|
-
|
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
|
-
|
257
|
-
|
221
|
+
ctx.strict_numeric_types = true;
|
222
|
+
ctx.is_command = is_command;
|
258
223
|
|
259
|
-
|
224
|
+
return match_bson_with_ctx(doc, pattern, &ctx);
|
260
225
|
}
|
261
226
|
|
227
|
+
MLIB_ANNOTATE_PRINTF(2, 3)
|
262
228
|
|
263
|
-
|
264
|
-
|
265
|
-
|
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
|
-
|
233
|
+
BSON_ASSERT(ctx);
|
271
234
|
|
272
|
-
|
273
|
-
|
274
|
-
|
235
|
+
va_start(args, fmt);
|
236
|
+
formatted = bson_strdupv_printf(fmt, args);
|
237
|
+
va_end(args);
|
275
238
|
|
276
|
-
|
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
|
-
|
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
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
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
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
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
|
-
|
409
|
-
|
410
|
-
|
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
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
379
|
+
next:
|
380
|
+
is_first = false;
|
381
|
+
if (found) {
|
382
|
+
bson_value_destroy(&doc_value);
|
383
|
+
}
|
384
|
+
}
|
436
385
|
|
437
|
-
|
386
|
+
return true;
|
438
387
|
|
439
388
|
fail:
|
440
|
-
|
441
|
-
|
442
|
-
|
389
|
+
if (found) {
|
390
|
+
bson_value_destroy(&doc_value);
|
391
|
+
}
|
443
392
|
|
444
|
-
|
445
|
-
|
446
|
-
|
393
|
+
if (strlen(derived.errmsg) > 0) {
|
394
|
+
memcpy(ctx->errmsg, derived.errmsg, sizeof(derived.errmsg));
|
395
|
+
}
|
447
396
|
|
448
|
-
|
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
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
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
|
-
|
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
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
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
|
-
|
546
|
-
|
547
|
-
|
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
|
-
|
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
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
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
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
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
|
}
|