├── .github └── workflows │ └── ci.yml ├── .gitignore ├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── ROADMAP.md ├── docs ├── bson.md └── mongo.md ├── examples ├── count-example.v ├── find-example.v ├── find-lean-example.v └── insert-example.v └── src ├── bson.v ├── bson_append.v ├── bson_fn.c.v ├── bson_oid.v ├── bson_structs.c.v ├── bson_test.v ├── bson_types.v ├── c_enums.c.v ├── client.v ├── client_pool.v ├── collection.v ├── collection_test.v ├── cursor.v ├── database.v ├── mongo.v ├── mongo_fn.c.v ├── mongo_structs.c.v ├── mongo_utils.v ├── stream.v ├── test_mongo.v ├── thirdparty ├── libbson-1.0 │ ├── bson.h │ └── bson │ │ ├── bcon.h │ │ ├── bson-atomic.h │ │ ├── bson-clock.h │ │ ├── bson-compat.h │ │ ├── bson-config.h │ │ ├── bson-context.h │ │ ├── bson-decimal128.h │ │ ├── bson-endian.h │ │ ├── bson-error.h │ │ ├── bson-iter.h │ │ ├── bson-json.h │ │ ├── bson-keys.h │ │ ├── bson-macros.h │ │ ├── bson-md5.h │ │ ├── bson-memory.h │ │ ├── bson-oid.h │ │ ├── bson-prelude.h │ │ ├── bson-reader.h │ │ ├── bson-string.h │ │ ├── bson-types.h │ │ ├── bson-utf8.h │ │ ├── bson-value.h │ │ ├── bson-version-functions.h │ │ ├── bson-version.h │ │ ├── bson-writer.h │ │ └── bson.h └── libmongoc-1.0 │ ├── mongoc.h │ └── mongoc │ ├── mongoc-apm.h │ ├── mongoc-bulk-operation.h │ ├── mongoc-change-stream.h │ ├── mongoc-client-pool.h │ ├── mongoc-client-session.h │ ├── mongoc-client-side-encryption.h │ ├── mongoc-client.h │ ├── mongoc-collection.h │ ├── mongoc-config.h │ ├── mongoc-cursor.h │ ├── mongoc-database.h │ ├── mongoc-error.h │ ├── mongoc-find-and-modify.h │ ├── mongoc-flags.h │ ├── mongoc-gridfs-bucket.h │ ├── mongoc-gridfs-file-list.h │ ├── mongoc-gridfs-file-page.h │ ├── mongoc-gridfs-file.h │ ├── mongoc-gridfs.h │ ├── mongoc-handshake.h │ ├── mongoc-host-list.h │ ├── mongoc-index.h │ ├── mongoc-init.h │ ├── mongoc-iovec.h │ ├── mongoc-log.h │ ├── mongoc-macros.h │ ├── mongoc-matcher.h │ ├── mongoc-opcode.h │ ├── mongoc-optional.h │ ├── mongoc-prelude.h │ ├── mongoc-rand.h │ ├── mongoc-read-concern.h │ ├── mongoc-read-prefs.h │ ├── mongoc-server-api.h │ ├── mongoc-server-description.h │ ├── mongoc-socket.h │ ├── mongoc-ssl.h │ ├── mongoc-stream-buffered.h │ ├── mongoc-stream-file.h │ ├── mongoc-stream-gridfs.h │ ├── mongoc-stream-socket.h │ ├── mongoc-stream-tls-libressl.h │ ├── mongoc-stream-tls-openssl.h │ ├── mongoc-stream-tls.h │ ├── mongoc-stream.h │ ├── mongoc-topology-description.h │ ├── mongoc-uri.h │ ├── mongoc-version-functions.h │ ├── mongoc-version.h │ ├── mongoc-write-concern.h │ └── mongoc.h ├── uri.v └── v.mod /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | paths-ignore: 6 | - "**.md" 7 | pull_request: 8 | paths-ignore: 9 | - "**.md" 10 | 11 | jobs: 12 | tests: 13 | runs-on: ubuntu-latest 14 | continue-on-error: true 15 | timeout-minutes: 5 16 | strategy: 17 | matrix: 18 | mongodb-version: ["4.2", "4.4", "5.0", "6.0", "7.0"] 19 | steps: 20 | - name: Checkout V 21 | uses: actions/checkout@v2 22 | with: 23 | repository: vlang/v 24 | - name: Install V dependencies 25 | run: | 26 | sudo apt-get update 27 | sudo apt-get install --quiet -y libglfw3-dev libxi-dev libxcursor-dev 28 | - name: Build V 29 | run: | 30 | make 31 | sudo ./v symlink 32 | - name: Checkout Mongo 33 | uses: actions/checkout@v2 34 | with: 35 | path: vlib/mongo 36 | - name: Install Mongo dependencies 37 | run: | 38 | cd ./vlib/mongo/ 39 | sudo apt update 40 | sudo make install 41 | - name: Start MongoDB 42 | uses: supercharge/mongodb-github-action@1.10.0 43 | with: 44 | mongodb-version: ${{ matrix.mongodb-version }} 45 | - name: Test 46 | run: | 47 | cd ./vlib/mongo/ 48 | make test 49 | - name: Build Mongo example 50 | run: | 51 | cd ./vlib/mongo/examples/ 52 | v -prod count-example.v 53 | 54 | build: 55 | runs-on: ubuntu-latest 56 | container: thevlang/vlang:debian-dev 57 | steps: 58 | - name: Checkout Mongo 59 | uses: actions/checkout@v2 60 | with: 61 | path: vlib/mongo 62 | - name: Install Mongo dependencies 63 | run: | 64 | cd ./vlib/mongo/ 65 | apt update 66 | make install 67 | - name: Build Mongo shared lib 68 | run: | 69 | cd ./vlib/mongo/ 70 | make build 71 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.so 2 | mongo-c-driver* 3 | mongo.so 4 | v 5 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM thevlang/vlang:debian-dev AS builder 2 | 3 | WORKDIR /app 4 | RUN v up 5 | RUN apt update 6 | COPY . . 7 | RUN make install 8 | RUN make build 9 | RUN make test 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 The V Programming Language 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .DEFAULT_GOAL := install 2 | build_mongo_c_driver: 3 | apt install cmake libssl-dev libsasl2-dev 4 | wget -O mongo-c-driver.tar.gz https://github.com/mongodb/mongo-c-driver/releases/download/1.16.2/mongo-c-driver-1.16.2.tar.gz # Check for the latest version 5 | tar xzf mongo-c-driver.tar.gz 6 | mkdir -p mongo-c-driver-1.16.2/cmake-build 7 | cd mongo-c-driver-1.16.2/cmake-build && \ 8 | cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF .. && \ 9 | make && \ 10 | make install 11 | 12 | install: 13 | apt install -y libbson-dev libmongoc-dev 14 | 15 | dev: 16 | v -cg -shared watch . 17 | 18 | build: 19 | v -shared -prod . 20 | 21 | test: 22 | v -stats test . 23 | 24 | test_watch: 25 | v -stats -keepc -cg watch test . --only-watch=*.v,*.h 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Mongo 2 | 3 | _MongoDB driver for vlang_ 4 | 5 | ### Getting start: 6 | 7 | #### Installing dependeces 8 | 9 | [libmongoc](http://mongoc.org/libmongoc/current/installing.html#install-libmongoc-with-a-package-manager)(MongoDB C Driver) 10 | [libbson](http://mongoc.org/libmongoc/current/installing.html#install-libbson-with-a-package-manager)(BSON library) 11 | 12 | ```bash 13 | # Debian and Ubuntu 14 | sudo apt-get install libmongoc-dev 15 | sudo apt-get install libbson-1.0-0 16 | ``` 17 | 18 | ```bash 19 | # Fedora 20 | dnf install mongo-c-driver 21 | dnf install libbson 22 | ``` 23 | 24 | ```bash 25 | # CentOS and RHEL 7 26 | yum install mongo-c-driver 27 | yum install libbson 28 | ``` 29 | 30 | ```bash 31 | # macOS 32 | brew install mongo-c-driver 33 | ``` 34 | 35 | #### Starting MongoDB 36 | 37 | ```bash 38 | mongo --host localhost --port 27017 39 | ``` 40 | 41 | #### Installing mongo package from `vpm` 42 | 43 | ```bash 44 | v install mongo 45 | ``` 46 | 47 | **Examples** 48 | 49 | 50 | ```v 51 | // connect to mongo 52 | mongo_uri := mongo.uri_new('mongodb://127.0.0.1:27017') 53 | client := mongo_uri.new_client() 54 | 55 | // select database 56 | database := client.get_database('db_name') 57 | 58 | // select collection 59 | collection := client.get_collection('db_name', 'collection_name') 60 | 61 | // insert collection 62 | collection.insert_one({ 63 | 'str': 'string' 64 | 'number': 2 65 | 'float': 2.1 66 | 'boolean': true 67 | }) 68 | 69 | // find collection 70 | response := collection.find({ 71 | 'str': 'string' 72 | }).lean() 73 | 74 | assert response[0].as_map()['str'] or { 0 }.str() == 'string' 75 | 76 | ``` 77 | -------------------------------------------------------------------------------- /ROADMAP.md: -------------------------------------------------------------------------------- 1 | ### Roadmap: 2 | 3 | #### v0.0.1 4 | - [x] `define required tasks to get a complete use of mongo with V` 5 | - [x] `add basic fn to wrap mongo and bson` 6 | #### v1.0.0 7 | 8 | - insert_one 9 | - [x] `collection.insert_one(document map[string]json2.Any) bool` 10 | - [x] `collection.insert_one_from(t T) bool` 11 | - [x] `collection.insert_one_from_bson_t(document &C.bson_t) bool` 12 | - find 13 | - [x] `collection.find(document map[string]json2.Any) &C.mongoc_cursor_t` 14 | - [x] `collection.find_from(t T) &C.mongoc_cursor_t` 15 | - [x] `collection.find_from_bson_t(document &C.bson_t) &C.mongoc_cursor_t` 16 | - count 17 | - [x] `collection.count(document map[string]json2.Any) i64` 18 | - [x] `collection.count_from(t T) i64` 19 | - [x] `collection.count_from_bson_t(document &C.bson_t) i64` 20 | - update_one 21 | - [ ] `collection.update_one(document map[string]json2.Any) bool` 22 | - [ ] `collection.update_one_from(t T) bool` 23 | - [ ] `collection.update_one_from_bson_t(document &C.bson_t) bool` 24 | - delete_one 25 | - [ ] `collection.delete_one(document map[string]json2.Any) bool` 26 | - [ ] `collection.delete_one_from(t T) bool` 27 | - [ ] `collection.delete_one_from_bson_t(document &C.bson_t) bool` 28 | - insert_may 29 | - [ ] `add bulk query support` (Ex: insert_many) 30 | - others 31 | - [ ] `separate bson into a submodule of mongo` 32 | 33 | #### v1.0.1 34 | - aggregate 35 | - [ ] `mongoc_collection_aggregate` 36 | - [ ] `mongoc_database_aggregate` 37 | 38 | #### v2.0.0 39 | 40 | - [ ] `Build a native bson vlang library` 41 | - [ ] `Build a native mongo vlang library` 42 | -------------------------------------------------------------------------------- /docs/bson.md: -------------------------------------------------------------------------------- 1 | # bson module docs 2 | 3 | mongo.bson module is a wrapper for Clang [libbson](http://mongoc.org/libbson/current/api.html) 4 | 5 | ## C definitions 6 | ### [Structures](../bson.c_structs.v) 7 | ### [Methods](../bson.c_fn.v) 8 | 9 | ## V functions 10 | ### [bson_t](../bson.v) ([official](http://mongoc.org/libbson/current/bson_t.html)) 11 | ### [bson_t append funcs](../bson_append.v) ([official](http://mongoc.org/libbson/current/bson_t.html)) 12 | ### [bson_oid_t](../bson_oid.v) ([official](http://mongoc.org/libbson/current/bson_oid_t.html)) -------------------------------------------------------------------------------- /docs/mongo.md: -------------------------------------------------------------------------------- 1 | # mongo module docs 2 | 3 | mongo module is a wrapper for Clang [libmongoc](http://mongoc.org/libmongoc/current/api.html) 4 | 5 | ## C definitions 6 | ### [Structures](../c_structs.v) 7 | ### [Methods](../c_fn.v) 8 | 9 | ## V functions 10 | ### [mongoc_client_t](../mongo.v) ([official](http://mongoc.org/libmongoc/1.16.2/mongoc_client_t.html)) 11 | ### [mongoc_collection_t](../collection.v) ([official](http://mongoc.org/libmongoc/1.16.2/mongoc_collection_t.html)) 12 | ### [mongoc_cursor_t](../cursor.v) ([official](http://mongoc.org/libmongoc/1.16.2/mongoc_cursor_t.html)) 13 | ### [mongoc_uri_t](../uri.v) ([official](http://mongoc.org/libmongoc/1.16.2/mongoc_uri_t.html)) -------------------------------------------------------------------------------- /examples/count-example.v: -------------------------------------------------------------------------------- 1 | import mongo 2 | 3 | fn main() { 4 | url := 'mongodb://127.0.0.1:27017/' 5 | 6 | client := mongo.new_client(url) 7 | 8 | collection := client.get_collection('test', 'mongo-test') 9 | 10 | collection.insert_one({ 11 | 'version': '0.2.2' 12 | }) 13 | 14 | count := collection.count({ 15 | 'version': '0.2.2' 16 | }) 17 | 18 | println(count) 19 | client.get_database('test').drop() 20 | } 21 | -------------------------------------------------------------------------------- /examples/find-example.v: -------------------------------------------------------------------------------- 1 | import mongo 2 | 3 | struct App { 4 | pub: 5 | version string 6 | } 7 | 8 | fn main() { 9 | url := 'mongodb://127.0.0.1:27017' 10 | 11 | client := mongo.new_client(url) 12 | 13 | collection := client.get_collection('teste', 'agreements') 14 | 15 | collection.insert_one({ 16 | 'version': '0.2.2' 17 | }) 18 | 19 | cursor := collection.find({ 20 | 'version': '0.2.2' 21 | }) 22 | 23 | document := mongo.new_bson() 24 | 25 | for cursor.next_doc(&document) { 26 | // declare str to avoid v errors 27 | str := document.str() 28 | println(str) 29 | } 30 | 31 | if !cursor.next_doc(&document) { 32 | println(false) 33 | } 34 | 35 | client.get_database('teste').drop() 36 | } 37 | -------------------------------------------------------------------------------- /examples/find-lean-example.v: -------------------------------------------------------------------------------- 1 | import mongo 2 | import time 3 | 4 | fn main() { 5 | url := 'mongodb://127.0.0.1:27017/' 6 | 7 | sw := time.new_stopwatch() 8 | 9 | client := mongo.new_client(url) 10 | 11 | mut dt := sw.elapsed().microseconds() 12 | println('Elapsed time (new_client): ${dt} uS') // Elapsed time (new_client): 38 uS 13 | 14 | collection := client.get_collection('test', 'mongo-test') 15 | 16 | collection.insert_one({ 17 | 'str': 'string' 18 | 'number': int(2) 19 | 'float': f64(2.1) 20 | 'boolean': true 21 | }) 22 | 23 | dt = sw.elapsed().microseconds() 24 | println('Elapsed time (insert_one): ${f64(dt) * 0.001} ms') // Elapsed time (insert_one): 16.808 ms 25 | 26 | response := collection.find({ 27 | 'str': 'different' 28 | }).lean() 29 | 30 | dt = sw.elapsed().microseconds() 31 | println('Elapsed time (find): ${f64(dt) * 0.001} ms') // Elapsed time (find): 17.173000000000002 ms 32 | 33 | println(response) 34 | client.get_database('test').drop() 35 | } 36 | -------------------------------------------------------------------------------- /examples/insert-example.v: -------------------------------------------------------------------------------- 1 | import mongo 2 | import x.json2 3 | 4 | struct Test { 5 | str string 6 | number int 7 | float f64 8 | boolean bool 9 | } 10 | 11 | fn main() { 12 | url := 'mongodb://127.0.0.1:27017/' 13 | 14 | client := mongo.new_client(url) 15 | 16 | collection := client.get_collection('test', 'mongo-test') 17 | 18 | test := Test{ 19 | str: 'string' 20 | number: int(2) 21 | float: f64(2.1) 22 | boolean: true 23 | } 24 | 25 | struct_bson := mongo.new_bson_from[Test](test) 26 | json_bson := mongo.new_from_json('{"str":"string","number":2,"float":2.1,"boolean":true}') 27 | 28 | child := json2.Any({ 29 | 'bar': json2.Any(10) 30 | }) 31 | 32 | collection.insert_one({ 33 | 'str': 'string' 34 | 'number': 2 35 | 'float': 2.1 36 | 'boolean': true 37 | 'foo': child 38 | }) 39 | 40 | collection.insert_one_from(test) 41 | collection.insert_one_from_bson_t(struct_bson) 42 | collection.insert_one_from_bson_t(json_bson) 43 | 44 | struct_bson.destroy() 45 | json_bson.destroy() 46 | client.get_database('test').drop() 47 | } 48 | -------------------------------------------------------------------------------- /src/bson.v: -------------------------------------------------------------------------------- 1 | module mongo 2 | 3 | import json 4 | 5 | // TODO rename to new() when move it to submodule bson 6 | pub fn new_bson() &C.bson_t { 7 | return C.bson_new() 8 | } 9 | 10 | @[inline] 11 | pub fn new_bson_oid_filter(_oid string) &C.bson_t { 12 | return new_from_json('{"_id": {"\$oid": "${_oid}"}}') 13 | } 14 | 15 | @[inline] 16 | pub fn new_bson_from[T](t T) &C.bson_t { 17 | json_data := json.encode(t) 18 | error := C.bson_error_t{} 19 | bson := C.bson_new_from_json(json_data.str, json_data.len, &error) 20 | if unsafe { error.message.vstring() != '' } { 21 | panic(error) 22 | } 23 | return bson 24 | } 25 | 26 | @[inline] 27 | pub fn new_from_json(json_data string) &C.bson_t { 28 | error := C.bson_error_t{} 29 | bson := C.bson_new_from_json(json_data.str, json_data.len, &error) 30 | if unsafe { error.message.vstring() != '' } { 31 | panic(error) 32 | } 33 | return bson 34 | } 35 | 36 | pub fn (document &C.bson_t) reinit() { 37 | C.bson_reinit(document) 38 | } 39 | 40 | @[unsafe] 41 | pub fn (document &C.bson_t) destroy() { 42 | C.bson_destroy(document) 43 | } 44 | 45 | @[unsafe] 46 | pub fn free(mem voidptr) { 47 | C.bson_free(mem) 48 | } 49 | 50 | pub fn (document &C.bson_t) as_canonical_extended_json() string { 51 | return unsafe { 52 | C.bson_as_canonical_extended_json(document, 0).vstring() 53 | } 54 | } 55 | 56 | pub fn (document &C.bson_t) str() string { 57 | return unsafe { 58 | C.bson_as_json(document, 0).vstring() 59 | } 60 | } 61 | 62 | pub fn (document &C.bson_t) as_json() string { 63 | return unsafe { 64 | C.bson_as_json(document, 0).vstring() 65 | } 66 | } 67 | 68 | pub fn (document &C.bson_t) as_relaxed_extended_json() string { 69 | return unsafe { 70 | C.bson_as_relaxed_extended_json(document, 0).vstring() 71 | } 72 | } 73 | 74 | pub fn (document &C.bson_t) init_from_json(json_data string) bool { 75 | return C.bson_init_from_json(document, json_data.str, -1, 0) 76 | } 77 | 78 | pub fn (document &C.bson_t) compare(other &C.bson_t) int { 79 | return C.bson_compare(document, other) 80 | } 81 | 82 | pub fn (destination &C.bson_t) concat(source &C.bson_t) bool { 83 | return C.bson_concat(destination, source) 84 | } 85 | 86 | pub fn (document &C.bson_t) copy() &C.bson_t { 87 | return C.bson_copy(document) 88 | } 89 | 90 | pub fn (source &C.bson_t) copy_to(destination &C.bson_t) { 91 | C.bson_copy_to(source, destination) 92 | } 93 | 94 | pub fn (source &C.bson_t) copy_to_excluding(destination &C.bson_t, exclude string) { 95 | C.bson_copy_to_excluding(source, destination, exclude.str) 96 | } 97 | 98 | pub fn (document &C.bson_t) count_keys() int { 99 | return int(C.bson_count_keys(document)) 100 | } 101 | 102 | pub fn (document &C.bson_t) get_data() u8 { 103 | return C.bson_get_data(document) 104 | } 105 | 106 | pub fn (document &C.bson_t) has_field(field string) bool { 107 | return C.bson_has_field(document, field.str) 108 | } 109 | 110 | pub fn (document &C.bson_t) equal(b &C.bson_t) bool { 111 | return C.bson_equal(document, b) 112 | } 113 | 114 | pub fn (document &C.bson_t) to[T]() ?T { 115 | doc := document.str() 116 | println('tp: ${doc}') 117 | return json.decode(T, doc) 118 | } 119 | -------------------------------------------------------------------------------- /src/bson_append.v: -------------------------------------------------------------------------------- 1 | module mongo 2 | 3 | pub fn (document &C.bson_t) append_array(key string, array &C.bson_t) bool { 4 | return C.bson_append_array(document, key.str, key.len, array) 5 | } 6 | 7 | pub fn (document &C.bson_t) append_array_begin(key string, array_begin &C.bson_t) bool { 8 | return C.bson_append_array_begin(document, key.str, key.len, array_begin) 9 | } 10 | 11 | pub fn (document &C.bson_t) append_array_end(array_begin &C.bson_t) bool { 12 | return C.bson_append_array_end(document, array_begin) 13 | } 14 | 15 | // TODO fix 16 | // pub fn (document &C.bson_t) append_binary(key string, subtype C.bson_subtype_t, binary &byte, length u32) bool { 17 | // return C.bson_append_binary(document, key.str, key.len, subtype, binary, length) 18 | // } 19 | 20 | pub fn (document &C.bson_t) append_bool(key string, value bool) bool { 21 | return C.bson_append_bool(document, key.str, key.len, value) 22 | } 23 | 24 | pub fn (document &C.bson_t) append_code(key string, code string) bool { 25 | return C.bson_append_code(document, key.str, key.len, code.str) 26 | } 27 | 28 | pub fn (document &C.bson_t) append_code_with_scope(key string, value string, context &C.bson_t) bool { 29 | return C.bson_append_code_with_scope(document, key.str, key.len, value.str, context) 30 | } 31 | 32 | pub fn (document &C.bson_t) append_date_time(key string, timestamp i64) bool { 33 | return C.bson_append_date_time(document, key.str, key.len, timestamp) 34 | } 35 | 36 | // pub fn (document &C.bson_t) append_decimal128(key string, decimal128 &C.bson_decimal128_t) bool { 37 | // return C.bson_append_decimal128(document, key.str, key.len, decimal128) 38 | // } 39 | 40 | pub fn (document &C.bson_t) append_document(key string, adocument &C.bson_t) bool { 41 | return C.bson_append_document(document, key.str, key.len, adocument) 42 | } 43 | 44 | pub fn (document &C.bson_t) append_document_begin(key string, adocument &C.bson_t) bool { 45 | return C.bson_append_document_begin(document, key.str, key.len, adocument) 46 | } 47 | 48 | pub fn (document &C.bson_t) append_document_end(adocument &C.bson_t) bool { 49 | return C.bson_append_document_end(document, adocument) 50 | } 51 | 52 | pub fn (document &C.bson_t) append_double(key string, value f64) bool { 53 | return C.bson_append_double(document, key.str, key.len, value) 54 | } 55 | 56 | pub fn (document &C.bson_t) append_int32(key string, value int) bool { 57 | return C.bson_append_int32(document, key.str, key.len, value) 58 | } 59 | 60 | pub fn (document &C.bson_t) append_int64(key string, value i64) bool { 61 | return C.bson_append_int64(document, key.str, key.len, value) 62 | } 63 | 64 | pub fn (document &C.bson_t) append_maxkey(key string) bool { 65 | return C.bson_append_maxkey(document, key.str, key.len) 66 | } 67 | 68 | pub fn (document &C.bson_t) append_minkey(key string) bool { 69 | return C.bson_append_minkey(document, key.str, key.len) 70 | } 71 | 72 | pub fn (document &C.bson_t) append_now_utc(key string) bool { 73 | return C.bson_append_now_utc(document, key.str, key.len) 74 | } 75 | 76 | pub fn (document &C.bson_t) append_null(key string) bool { 77 | return C.bson_append_null(document, key.str, key.len) 78 | } 79 | 80 | pub fn (document &C.bson_t) append_oid(key string, oid &C.bson_oid_t) bool { 81 | return C.bson_append_oid(document, key.str, key.len, oid) 82 | } 83 | 84 | pub fn (document &C.bson_t) append_regex(key string, regex string, options string) bool { 85 | return C.bson_append_regex(document, key.str, key.len, regex.str, options.str) 86 | } 87 | 88 | pub fn (document &C.bson_t) append_symbol(key string, symbol string) bool { 89 | return C.bson_append_symbol(document, key.str, key.len, symbol.str, -1) 90 | } 91 | 92 | pub fn (document &C.bson_t) append_time_t(key string, time_t u32) bool { 93 | return C.bson_append_time_t(document, key.str, key.len, time_t) 94 | } 95 | 96 | pub fn (document &C.bson_t) append_timestamp(key string, timestamp u32, increment u32) bool { 97 | return C.bson_append_timestamp(document, key.str, key.len, timestamp, increment) 98 | } 99 | 100 | pub fn (document &C.bson_t) append_undefined(key string) bool { 101 | return C.bson_append_undefined(document, key.str, key.len) 102 | } 103 | 104 | pub fn (document &C.bson_t) append_utf8(key string, value string) bool { 105 | return C.bson_append_utf8(document, key.str, key.len, value.str, -1) 106 | } 107 | 108 | // pub fn (document &C.bson_t) append_value(key string, value &C.bson_value_t) bool { 109 | // return C.bson_append_value(document, key.str, key.len, value) 110 | // } 111 | -------------------------------------------------------------------------------- /src/bson_fn.c.v: -------------------------------------------------------------------------------- 1 | module mongo 2 | 3 | #flag -I @VMODROOT/thirdparty/libbson-1.0 4 | #flag -I @VMODROOT/thirdparty/libmongoc-1.0 5 | #flag -l mongoc-1.0 6 | #flag -l bson-1.0 7 | 8 | #include "mongoc/mongoc.h" 9 | #include "bson/bson.h" 10 | 11 | fn C.bson_new() &C.bson_t 12 | fn C.bson_new_from_json(byteptr, int, &C.bson_error_t) &C.bson_t 13 | fn C.bson_init_from_json(&C.bson_t, byteptr, int, &C.bson_error_t) bool 14 | fn C.bson_reinit(&C.bson_t) 15 | fn C.bson_as_json(&C.bson_t, int) byteptr 16 | fn C.bson_as_relaxed_extended_json(&C.bson_t, int) byteptr 17 | fn C.bson_compare(&C.bson_t, &C.bson_t) int 18 | fn C.bson_concat(&C.bson_t, &C.bson_t) bool 19 | fn C.bson_copy(&C.bson_t) &C.bson_t 20 | fn C.bson_copy_to(&C.bson_t, &C.bson_t) 21 | fn C.bson_copy_to_excluding(&C.bson_t, &C.bson_t, byteptr) 22 | fn C.bson_count_keys(&C.bson_t) u32 23 | fn C.bson_equal(&C.bson_t, &C.bson_t) bool 24 | fn C.bson_get_data(&C.bson_t) u8 25 | fn C.bson_has_field(&C.bson_t, byteptr) bool 26 | fn C.bson_free(voidptr) 27 | fn C.bson_as_canonical_extended_json(&C.bson_t, int) byteptr 28 | fn C.bson_destroy(&C.bson_t) 29 | 30 | // appends 31 | // http://mongoc.org/libbson/current/bson_append_array.html 32 | fn C.bson_append_array(&C.bson_t, byteptr, int, &C.bson_t) bool 33 | 34 | // http://mongoc.org/libbson/current/bson_append_array_begin.html 35 | fn C.bson_append_array_begin(&C.bson_t, byteptr, int, &C.bson_t) bool 36 | 37 | // http://mongoc.org/libbson/current/bson_append_array_end.html 38 | fn C.bson_append_array_end(&C.bson_t, &C.bson_t) bool 39 | 40 | // http://mongoc.org/libbson/current/bson_append_binary.html 41 | fn C.bson_append_binary(&C.bson_t, byteptr, int, &C.bson_subtype_t, &u8, u32) bool 42 | 43 | // http://mongoc.org/libbson/current/bson_append_bool.html 44 | fn C.bson_append_bool(&C.bson_t, byteptr, int, bool) bool 45 | 46 | // http://mongoc.org/libbson/current/bson_append_code.html 47 | fn C.bson_append_code(&C.bson_t, byteptr, int, byteptr) bool 48 | 49 | // http://mongoc.org/libbson/current/bson_append_code_with_scope.html 50 | fn C.bson_append_code_with_scope(&C.bson_t, byteptr, int, byteptr, &C.bson_t) bool 51 | 52 | // http://mongoc.org/libbson/current/bson_append_date_time.html 53 | fn C.bson_append_date_time(&C.bson_t, byteptr, int, i64) bool 54 | 55 | // http://mongoc.org/libbson/current/bson_append_decimal128.html 56 | fn C.bson_append_decimal128(&C.bson_t, byteptr, int, &C.bson_decimal128_t) bool 57 | 58 | // http://mongoc.org/libbson/current/bson_append_document.html 59 | fn C.bson_append_document(&C.bson_t, byteptr, int, &C.bson_t) bool 60 | 61 | // http://mongoc.org/libbson/current/bson_append_document_begin.html 62 | fn C.bson_append_document_begin(&C.bson_t, byteptr, int, &C.bson_t) bool 63 | 64 | // http://mongoc.org/libbson/current/bson_append_document_end.html 65 | fn C.bson_append_document_end(&C.bson_t, &C.bson_t) bool 66 | 67 | // http://mongoc.org/libbson/current/bson_append_double.html 68 | fn C.bson_append_double(&C.bson_t, byteptr, int, f64) bool 69 | 70 | // http://mongoc.org/libbson/current/bson_append_int32.html 71 | fn C.bson_append_int32(&C.bson_t, byteptr, int, int) bool 72 | 73 | // http://mongoc.org/libbson/current/bson_append_int64.html 74 | fn C.bson_append_int64(&C.bson_t, byteptr, int, i64) bool 75 | 76 | // http://mongoc.org/libbson/current/bson_append_maxkey.html 77 | fn C.bson_append_maxkey(&C.bson_t, byteptr, int) bool 78 | 79 | // http://mongoc.org/libbson/current/bson_append_minkey.html 80 | fn C.bson_append_minkey(&C.bson_t, byteptr, int) bool 81 | 82 | // http://mongoc.org/libbson/current/bson_append_now_utc.html 83 | fn C.bson_append_now_utc(&C.bson_t, byteptr, int) bool 84 | 85 | // http://mongoc.org/libbson/current/bson_append_null.html 86 | fn C.bson_append_null(&C.bson_t, byteptr, int) bool 87 | 88 | // http://mongoc.org/libbson/current/bson_append_oid.html 89 | fn C.bson_append_oid(&C.bson_t, byteptr, int, &C.bson_oid_t) bool 90 | 91 | // http://mongoc.org/libbson/current/bson_append_regex.html 92 | fn C.bson_append_regex(&C.bson_t, byteptr, int, byteptr, byteptr) bool 93 | 94 | // http://mongoc.org/libbson/current/bson_append_regex_w_len.html 95 | fn C.bson_append_regex_w_len(&C.bson_t, byteptr, int, byteptr, int, byteptr) bool 96 | 97 | // http://mongoc.org/libbson/current/bson_append_symbol.html 98 | fn C.bson_append_symbol(&C.bson_t, byteptr, int, byteptr, int) bool 99 | 100 | // http://mongoc.org/libbson/current/bson_append_time_t.html 101 | fn C.bson_append_time_t(&C.bson_t, byteptr, int, u32) bool 102 | 103 | // http://mongoc.org/libbson/current/bson_append_timestamp.html 104 | fn C.bson_append_timestamp(&C.bson_t, byteptr, int, u32, u32) bool 105 | 106 | // http://mongoc.org/libbson/current/bson_append_undefined.html 107 | fn C.bson_append_undefined(&C.bson_t, byteptr, int) bool 108 | 109 | // http://mongoc.org/libbson/current/bson_append_utf8.html 110 | fn C.bson_append_utf8(&C.bson_t, byteptr, int, byteptr, int) bool 111 | 112 | // http://mongoc.org/libbson/current/bson_append_value.html 113 | fn C.bson_append_value(&C.bson_t, byteptr, int, &C.bson_value_t) bool 114 | 115 | // bson_oid_t http://mongoc.org/libbson/current/bson_oid_t.html 116 | fn C.bson_oid_compare(&C.bson_oid_t, &C.bson_oid_t) int 117 | fn C.bson_oid_copy(&C.bson_oid_t, &C.bson_oid_t) 118 | fn C.bson_oid_equal(&C.bson_oid_t, &C.bson_oid_t) bool 119 | fn C.bson_oid_get_time_t(&C.bson_oid_t) int 120 | fn C.bson_oid_hash(&C.bson_oid_t) u32 121 | fn C.bson_oid_init_from_data(&C.bson_oid_t, u8) 122 | fn C.bson_oid_init_from_string(&C.bson_oid_t, byteptr) 123 | fn C.bson_iter_find_descendant(&&C.bson_iter_t, &&char, &&bson_iter_t) 124 | 125 | // DEPRECATED: bson_oid_init_sequence 126 | fn C.bson_oid_is_valid(charptr, int) bool 127 | fn C.bson_oid_to_string(&C.bson_oid_t, charptr) 128 | 129 | fn C.bson_oid_init(&C.bson_oid_t, &C.bson_context_t) 130 | 131 | // TODO: not implemented 132 | // fn bson_append_timeval 133 | // fn bson_validate_with_error 134 | // fn bson_steal 135 | // fn bson_sized_new 136 | // fn bson_new_from_data 137 | // fn bson_new_from_buffer 138 | // fn bson_init_static 139 | // fn bson_destroy_with_steal 140 | // fn bson_copy_to_excluding_noinit 141 | // fn bson_copy_to_excluding_noinit_va 142 | // fn bson_reinit 143 | // fn bson_reserve_buffer 144 | // fn bson_append_dbpointer 145 | // fn bson_array_as_json 146 | // fn bson_append_iter 147 | -------------------------------------------------------------------------------- /src/bson_oid.v: -------------------------------------------------------------------------------- 1 | module mongo 2 | 3 | // TODO; bson_context_t as second arg 4 | /* 5 | pub fn new_oid() &C.bson_oid_t { 6 | oid := &C.bson_oid_t{} 7 | C.bson_oid_init(oid, 0) 8 | return oid 9 | } 10 | */ 11 | 12 | pub fn (oid &C.bson_oid_t) init() { 13 | C.bson_oid_init(oid, 0) 14 | } 15 | 16 | pub fn (oid &C.bson_oid_t) init_from_data(data u8) { 17 | C.bson_oid_init_from_data(oid, data) 18 | } 19 | 20 | pub fn (oid &C.bson_oid_t) compare(other &C.bson_oid_t) int { 21 | return C.bson_oid_compare(oid, other) 22 | } 23 | 24 | pub fn (destination &C.bson_oid_t) copy(source &C.bson_oid_t) { 25 | C.bson_oid_copy(source, destination) 26 | } 27 | 28 | pub fn (oid1 &C.bson_oid_t) equal(oid2 &C.bson_oid_t) bool { 29 | return C.bson_oid_equal(oid1, oid2) 30 | } 31 | 32 | pub fn (oid &C.bson_oid_t) get_time_t() int { 33 | return C.bson_oid_get_time_t(oid) 34 | } 35 | 36 | pub fn (oid &C.bson_oid_t) hash() u32 { 37 | return C.bson_oid_hash(oid) 38 | } 39 | 40 | pub fn oid_is_valid(str string) bool { 41 | return C.bson_oid_is_valid(str.str, str.len) 42 | } 43 | 44 | pub fn (oid &C.bson_oid_t) str() string { 45 | str := '' 46 | C.bson_oid_to_string(oid, str.str) 47 | return str 48 | } 49 | -------------------------------------------------------------------------------- /src/bson_structs.c.v: -------------------------------------------------------------------------------- 1 | module mongo 2 | 3 | #flag -I @VMODROOT/thirdparty/libbson-1.0 4 | #flag -I @VMODROOT/thirdparty/libmongoc-1.0 5 | #flag -l mongoc-1.0 6 | #flag -l bson-1.0 7 | 8 | #include "mongoc/mongoc.h" 9 | #include "bson/bson.h" 10 | 11 | // http://mongoc.org/libbson/current/bson_t.html 12 | @[typedef] 13 | pub struct C.bson_t { 14 | flags u32 // Internal flags for the bson_t. 15 | len u32 // Length of BSON data. 16 | padding u8 // Padding for stack allocation. 17 | } 18 | 19 | // http://mongoc.org/libbson/current/bson_oid_t.html 20 | @[typedef] 21 | pub struct C.bson_oid_t { 22 | bytes u8 // ObjectId is a 12-byte BSON type 23 | } 24 | 25 | // http://mongoc.org/libbson/current/bson_subtype_t.html 26 | @[typedef] 27 | pub struct C.bson_subtype_t {} 28 | 29 | // http://mongoc.org/libbson/current/bson_context_t.html 30 | @[typedef] 31 | pub struct C.bson_context_t {} 32 | 33 | // http://mongoc.org/libbson/current/bson_type_t.html 34 | @[typedef] 35 | pub struct C.bson_type_t {} 36 | 37 | // http://mongoc.org/libbson/current/bson_decimal128_t.html 38 | @[typedef] 39 | pub struct C.bson_decimal128_t {} 40 | 41 | // http://mongoc.org/libbson/current/bson_iter_t.html 42 | @[typedef] 43 | pub struct C.bson_iter_t {} 44 | 45 | // http://mongoc.org/libbson/current/bson_value_t.html 46 | @[typedef] 47 | pub struct C.bson_value_t {} 48 | 49 | // http://mongoc.org/libbson/current/bson_error_t.html 50 | @[typedef] 51 | pub struct C.bson_error_t { 52 | domain u32 53 | code u32 54 | message charptr 55 | } 56 | -------------------------------------------------------------------------------- /src/bson_test.v: -------------------------------------------------------------------------------- 1 | module mongo 2 | 3 | struct Test { 4 | str string 5 | number int 6 | float f64 7 | boolean bool 8 | } 9 | 10 | fn test_new_bson_from() { 11 | test := Test{ 12 | str: 'test' 13 | number: 1 14 | float: 0.5 15 | boolean: true 16 | } 17 | text := new_bson_from[Test](test) 18 | assert text.as_json() == '{ "str" : "test", "number" : 1, "float" : 0.5, "boolean" : true }' 19 | } 20 | 21 | fn test_as_json() { 22 | doc := new_from_json('{"insert":"test"}') 23 | assert doc.as_json() == '{ "insert" : "test" }' 24 | } 25 | 26 | fn test_compare() { 27 | doc1 := new_from_json('{"insert":"test"}') 28 | doc2 := new_from_json('{"insert":"test"}') 29 | assert doc1.compare(doc2) == 0 30 | 31 | doc3 := new_from_json('{"insert":"test"}') 32 | doc4 := new_from_json('{"insert":"test1"}') 33 | assert doc3.compare(doc4) != 0 34 | } 35 | 36 | fn test_concat() { 37 | doc1 := new_from_json('{"key":"value"}') 38 | doc2 := new_from_json('{"key1":"value1"}') 39 | doc1.concat(doc2) 40 | assert doc1.as_json() == '{ "key" : "value", "key1" : "value1" }' 41 | } 42 | 43 | fn test_count_keys() { 44 | doc1 := new_from_json('{"1":"value","2":"value1","3":"value3"}') 45 | assert doc1.count_keys() == 3 46 | } 47 | 48 | fn test_equal() { 49 | doc1 := new_from_json('{"insert":"test"}') 50 | doc2 := new_from_json('{"insert":"test"}') 51 | assert doc1.equal(doc2) 52 | 53 | doc3 := new_from_json('{"insert":"test"}') 54 | doc4 := new_from_json('{"insert":"test1"}') 55 | assert !doc3.equal(doc4) 56 | } 57 | 58 | fn test_has_field() { 59 | doc := new_from_json('{"insert":"test"}') 60 | assert doc.has_field('insert') 61 | 62 | doc1 := new_from_json('{"insert":"test"}') 63 | assert !doc1.has_field('doc2') 64 | } 65 | -------------------------------------------------------------------------------- /src/bson_types.v: -------------------------------------------------------------------------------- 1 | 2 | module mongo 3 | /* 4 | 5 | pub fn (value string) bson_type() voidptr 6 | { 7 | return C.BCON_UTF8(value.str) 8 | } 9 | 10 | pub fn (value int) bson_type() voidptr 11 | { 12 | return C.BSON_APPEND_INT32(value) 13 | } 14 | 15 | pub fn (value byte) bson_type() voidptr 16 | { 17 | return C.BCON_BOOL(value.str) 18 | } 19 | 20 | pub fn (value bool) bson_type() voidptr 21 | { 22 | return C.BCON_BOOL(value.str) 23 | } 24 | 25 | pub fn (value Oid) bson_type() voidptr 26 | { 27 | return C.BCON_OID(values) 28 | } 29 | */ 30 | -------------------------------------------------------------------------------- /src/c_enums.c.v: -------------------------------------------------------------------------------- 1 | module mongo 2 | 3 | // http://mongoc.org/libmongoc/1.17.0/mongoc_query_flags_t.html 4 | pub enum QueryFlags { 5 | @none = 0 // Specify no query flags. 6 | tailable_cursor = 1 // Cursor will not be closed when the last data is retrieved. You can resume this cursor later. 7 | slave_ok = 2 // Allow query of replica set secondaries. 8 | oplog_replay = 3 // Used internally by MongoDB. 9 | no_cursor_timeout = 4 // The server normally times out an idle cursor after an inactivity period (10 minutes). This prevents that. 10 | await_data = 5 // Use with MONGOC_QUERY_TAILABLE_CURSOR. Block rather than returning no data. After a period, time out. 11 | exhaust = 6 // Stream the data down full blast in multiple “reply” packets. Faster when you are pulling down a lot of data and you know you want to retrieve it all. Only applies to cursors created from a find operation (i.e. mongoc_collection_find()). 12 | partial = 7 // Get partial results from mongos if some shards are down (instead of throwing an error). 13 | } 14 | -------------------------------------------------------------------------------- /src/client.v: -------------------------------------------------------------------------------- 1 | module mongo 2 | 3 | pub fn new_client(uri string) &C.mongoc_client_t { 4 | mongoc_uri := C.mongoc_uri_new(uri.str) 5 | return C.mongoc_client_new_from_uri(mongoc_uri) 6 | } 7 | 8 | /* 9 | pub fn new_client_(uri string) &C.mongoc_client_t { 10 | mongoc_uri := C.mongoc_uri_new(uri.str) 11 | mut error := C.bson_error_t{} 12 | return C.mongoc_client_new_from_uri_with_error(mongoc_uri, &error) 13 | } 14 | */ 15 | 16 | pub fn (client &C.mongoc_client_t) set_appname(name string) bool { 17 | return C.mongoc_client_set_appname(client, name.str) 18 | } 19 | 20 | pub fn (client &C.mongoc_client_t) get_database(db_name string) &C.mongoc_database_t { 21 | return C.mongoc_client_get_database(client, &char(db_name.str)) 22 | } 23 | 24 | pub fn (client &C.mongoc_client_t) get_collection(db_name string, collection_name string) &C.mongoc_collection_t { 25 | return C.mongoc_client_get_collection(client, db_name.str, collection_name.str) 26 | } 27 | 28 | pub fn (client &C.mongoc_client_t) set_error_api() bool { 29 | return C.mongoc_client_set_error_api(client, 2) 30 | } 31 | 32 | pub fn (client &C.mongoc_client_t) destroy() { 33 | C.mongoc_client_destroy(client) 34 | } 35 | -------------------------------------------------------------------------------- /src/client_pool.v: -------------------------------------------------------------------------------- 1 | module mongo 2 | 3 | // [inline] 4 | // pub fn (uri &C.mongoc_uri_t) new_client_pool() &C.mongoc_client_pool_t { 5 | // return C.mongoc_client_pool_new(uri) 6 | // } 7 | 8 | // [inline] 9 | // pub fn (pool &C.mongoc_client_pool_t) pop_client() &C.mongoc_client_t { 10 | // return C.mongoc_client_pool_pop(pool) 11 | // } 12 | 13 | // [inline] 14 | // pub fn (pool &C.mongoc_client_pool_t) push_client(client &C.mongoc_client_t) { 15 | // C.mongoc_client_pool_push(pool, client) 16 | // } 17 | 18 | // [inline] 19 | // pub fn (pool &C.mongoc_client_pool_t) destroy() { 20 | // C.mongoc_client_pool_destroy(pool) 21 | // } 22 | -------------------------------------------------------------------------------- /src/collection.v: -------------------------------------------------------------------------------- 1 | module mongo 2 | 3 | import x.json2 4 | // import time 5 | 6 | pub fn (collection &C.mongoc_collection_t) count(filter map[string]json2.Any) i64 { 7 | json_data := filter.str() 8 | filter_bson_t := new_from_json(json_data) 9 | 10 | defer { 11 | unsafe { 12 | filter_bson_t.destroy() 13 | } 14 | } 15 | 16 | return C.mongoc_collection_count_documents(collection, filter_bson_t, 0, 0, 0, 0) 17 | } 18 | 19 | pub fn (collection &C.mongoc_collection_t) count_from[T](t T) i64 { 20 | filter_bson_t := new_bson_from[T](t) 21 | return C.mongoc_collection_count_documents(collection, filter_bson_t, 0, 0, 0, 0) 22 | } 23 | 24 | pub fn (collection &C.mongoc_collection_t) count_from_bson_t(filter &C.bson_t) i64 { 25 | return C.mongoc_collection_count_documents(collection, filter, 0, 0, 0, 0) 26 | } 27 | 28 | pub fn (collection &C.mongoc_collection_t) insert_one(document map[string]json2.Any) bool { 29 | json_data := document.str() 30 | document_bson_t := new_from_json(json_data) 31 | 32 | defer { 33 | unsafe { 34 | document_bson_t.destroy() 35 | } 36 | } 37 | error := C.bson_error_t{} 38 | reply := new_bson() 39 | 40 | result := C.mongoc_collection_insert_one(collection, document_bson_t, 0, reply, &error) 41 | // unsafe { println(C.bson_as_json(&reply, 0).vstring()) } 42 | if unsafe { error.message.vstring() != '' } { 43 | panic(error) 44 | } 45 | return result 46 | } 47 | 48 | pub fn (collection &C.mongoc_collection_t) insert_one_from[T](t T) bool { 49 | document_bson_t := new_bson_from(t) 50 | defer { 51 | unsafe { 52 | document_bson_t.destroy() 53 | } 54 | } 55 | error := C.bson_error_t{} 56 | reply := new_bson() 57 | 58 | result := C.mongoc_collection_insert_one(collection, document_bson_t, 0, reply, &error) 59 | // unsafe { println(C.bson_as_json(&reply, 0).vstring()) } 60 | if unsafe { error.message.vstring() != '' } { 61 | panic(error) 62 | } 63 | return result 64 | } 65 | 66 | pub fn (collection &C.mongoc_collection_t) insert_one_from_bson_t(document &C.bson_t) bool { 67 | error := C.bson_error_t{} 68 | reply := new_bson() 69 | 70 | result := C.mongoc_collection_insert_one(collection, document, 0, reply, &error) 71 | // unsafe { println(C.bson_as_json(&reply, 0).vstring()) } 72 | if unsafe { error.message.vstring() != '' } { 73 | panic(error) 74 | } 75 | return result 76 | } 77 | 78 | // TODO fix it 79 | /* 80 | pub fn (collection &C.mongoc_collection_t) insert_many(documents []&C.bson_t) bool { 81 | return C.mongoc_collection_insert_many(collection, documents.data, documents.len, 0, 0) 82 | } 83 | */ 84 | 85 | pub fn (collection &C.mongoc_collection_t) find(query map[string]json2.Any) &C.mongoc_cursor_t { 86 | // sw := time.new_stopwatch() 87 | json_data := query.str() 88 | // mut dt := sw.elapsed().microseconds() 89 | // println('Elapsed time (query.str()): $dt uS') // Elapsed time (query.str()): 14 uS 90 | 91 | query_bson_t := new_from_json(json_data) 92 | 93 | defer { 94 | unsafe { 95 | query_bson_t.destroy() 96 | } 97 | } 98 | 99 | // dt = sw.elapsed().microseconds() 100 | // println('Elapsed time (C.bson_new_from_json): $dt uS') // Elapsed time (C.bson_new_from_json): 27 uS 101 | return C.mongoc_collection_find(collection, 0, 0, 0, 0, query_bson_t, unsafe { nil }, unsafe { nil }) 102 | } 103 | 104 | pub fn (collection &C.mongoc_collection_t) find_from[T](t T) &C.mongoc_cursor_t { 105 | query_bson_t := new_bson_from(t) 106 | defer { 107 | unsafe { 108 | query_bson_t.destroy() 109 | } 110 | } 111 | return C.mongoc_collection_find(collection, 0, 0, 0, 0, query_bson_t, unsafe { nil }, 112 | unsafe { nil }) 113 | } 114 | 115 | pub fn (collection &C.mongoc_collection_t) find_from_bson_t(query_bson_t &C.bson_t) &C.mongoc_cursor_t { 116 | return C.mongoc_collection_find(collection, 0, 0, 0, 0, query_bson_t, unsafe { nil }, 117 | unsafe { nil }) 118 | } 119 | 120 | pub fn (collection &C.mongoc_collection_t) find_oid(oid string) &C.mongoc_cursor_t { 121 | query := new_bson_oid_filter(oid) 122 | return C.mongoc_collection_find(collection, .no_cursor_timeout, 0, 0, 0, query, 0, 123 | 0) 124 | } 125 | 126 | pub fn (collection &C.mongoc_collection_t) find_with_opts(filter &C.bson_t, opts &C.bson_t) &C.mongoc_cursor_t { 127 | return C.mongoc_collection_find_with_opts(collection, filter, opts, 0) 128 | } 129 | 130 | pub fn (collection &C.mongoc_collection_t) replace_one(selector &C.bson_t, update &C.bson_t) bool { 131 | return C.mongoc_collection_replace_one(collection, selector, update, 0, 0, 0) 132 | } 133 | 134 | pub fn (collection &C.mongoc_collection_t) replace_one_opts(selector &C.bson_t, update &C.bson_t, opts &C.bson_t) bool { 135 | return C.mongoc_collection_replace_one(collection, selector, update, opts, 0, 0) 136 | } 137 | 138 | pub fn (collection &C.mongoc_collection_t) update_one(selector &C.bson_t, update &C.bson_t) bool { 139 | return C.mongoc_collection_update_one(collection, selector, update, 0, 0, 0) 140 | } 141 | 142 | pub fn (collection &C.mongoc_collection_t) delete_one(selector &C.bson_t) bool { 143 | return C.mongoc_collection_delete_one(collection, selector, 0, 0, 0) 144 | } 145 | 146 | pub fn (collection &C.mongoc_collection_t) create_bulk_operation() &C.mongoc_bulk_operation_t { 147 | return C.mongoc_collection_create_bulk_operation_with_opts(collection, 0) 148 | } 149 | 150 | pub fn (collection &C.mongoc_collection_t) destroy() { 151 | unsafe { C.mongoc_collection_destroy(collection) } 152 | } 153 | 154 | //* sugar fn * 155 | pub fn (collection &C.mongoc_collection_t) insert[T](t T) bool { 156 | document := new_bson_from(t) 157 | 158 | return C.mongoc_collection_insert_one(collection, document, 0, 0, 0) 159 | } 160 | 161 | pub fn (collection &C.mongoc_collection_t) replaceone[T](oid string, t T) bool { 162 | selector := new_bson_oid_filter(oid) 163 | return collection.replace[T](selector, t) 164 | } 165 | 166 | pub fn (collection &C.mongoc_collection_t) replace[T](selector &C.bson_t, t T) bool { 167 | document := new_bson_from(t) 168 | return C.mongoc_collection_replace_one(collection, selector, document, 0, 0, 0) 169 | } 170 | 171 | pub fn (collection &C.mongoc_collection_t) replace_opts[T](selector &C.bson_t, opts &C.bson_t, t T) bool { 172 | document := new_bson_from(t) 173 | return C.mongoc_collection_replace_one(collection, selector, document, opts, 0, 0) 174 | } 175 | 176 | pub fn (collection &C.mongoc_collection_t) update[T](selector &C.bson_t, t T) bool { 177 | document := new_bson_from(t) 178 | return C.mongoc_collection_update_one(collection, selector, document, 0, 0, 0) 179 | } 180 | 181 | pub fn (collection &C.mongoc_collection_t) update_opts[T](selector &C.bson_t, opts &C.bson_t, t T) bool { 182 | document := new_bson_from(t) 183 | return C.mongoc_collection_update_one(collection, selector, document, opts, 0, 0) 184 | } 185 | 186 | pub fn (collection &C.mongoc_collection_t) delete(selector &C.bson_t) bool { 187 | return C.mongoc_collection_delete_one(collection, selector, 0, 0, 0) 188 | } 189 | -------------------------------------------------------------------------------- /src/collection_test.v: -------------------------------------------------------------------------------- 1 | module mongo 2 | 3 | import x.json2 4 | 5 | struct Test { 6 | str string 7 | number int 8 | float f64 9 | boolean bool 10 | } 11 | 12 | fn test_collection() { 13 | client := mongo.new_client('mongodb://127.0.0.1:27017/') 14 | client.get_database('vlang').drop() 15 | 16 | collection := client.get_collection('vlang', 'mongo-test') 17 | 18 | test := Test{ 19 | str: 'string' 20 | number: 2 21 | float: 2.1 22 | boolean: true 23 | } 24 | 25 | test_filter := Test{ 26 | str: 'string' 27 | number: 2 28 | float: 2.1 29 | boolean: true 30 | } 31 | 32 | other_test := Test{ 33 | str: 'random' 34 | number: 77 35 | float: 985.36 36 | boolean: false 37 | } 38 | 39 | 40 | child := json2.Any({ 41 | 'bar': json2.Any(10) 42 | }) 43 | 44 | assert collection.insert_one({ 45 | 'number': 2 46 | 'float': 2.1 47 | 'boolean': true 48 | 'foo': child 49 | }) 50 | assert collection.insert_one_from(test) 51 | 52 | json_bson := mongo.new_from_json('{"str":"string","number":2,"float":2.1,"boolean":true}') 53 | assert collection.insert_one_from_bson_t(json_bson) 54 | 55 | for i in 0 .. 3 { 56 | collection.insert_one_from(test) 57 | collection.insert_one_from(other_test) 58 | } 59 | 60 | assert collection.count({}) == 9 61 | assert collection.count({'str': 'string'}) == 5 62 | 63 | lean_response_find := collection.find({'str': 'string'}).lean() 64 | lean_response_find_from := collection.find_from(test_filter).lean() 65 | 66 | bson_json_filter := mongo.new_from_json('{"str":"string"}') 67 | lean_response_find_from_bson_t := collection.find_from_bson_t(bson_json_filter).lean() 68 | 69 | // // TODO - when https://github.com/vlang/v/issues/15923 be fixed 70 | // assert response == [{"_id":{"\$oid":"633587f719a6f14926055715"},"str":"string","number":2,"float":2.1,"boolean":true},{"_id":{"$oid":"633587f719a6f14926055716"},"str":"string","number":2,"float":2.1,"boolean":true},{"_id":{"\$oid":"633587f719a6f14926055717"},"str":"string","number":2,"float":2.1,"boolean":true}] 71 | 72 | // // TODO - when x.json2.Any.str() can convert symbols like $ 73 | // assert response.str() == '[{"_id":{"\$oid":"633587f719a6f14926055715"},"str":"string","number":2,"float":2.1,"boolean":true},{"_id":{"$oid":"633587f719a6f14926055716"},"str":"string","number":2,"float":2.1,"boolean":true},{"_id":{"\$oid":"633587f719a6f14926055717"},"str":"string","number":2,"float":2.1,"boolean":true}]' 74 | 75 | assert lean_response_find.len == 5 76 | assert lean_response_find_from.len == 5 77 | assert lean_response_find_from_bson_t.len == 5 78 | 79 | for obj in lean_response_find { 80 | assert obj.as_map()['str'] or { 0 }.str() == 'string' 81 | assert obj.as_map()['number'] or { 0 }.int() == 2 82 | assert obj.as_map()['float'] or { 0 }.f64() == 2.1 83 | assert obj.as_map()['boolean'] or { 0 }.bool() == true 84 | } 85 | 86 | for obj in lean_response_find_from { 87 | assert obj.as_map()['str'] or { 0 }.str() == 'string' 88 | assert obj.as_map()['number'] or { 0 }.int() == 2 89 | assert obj.as_map()['float'] or { 0 }.f64() == 2.1 90 | assert obj.as_map()['boolean'] or { 0 }.bool() == true 91 | } 92 | 93 | for obj in lean_response_find_from_bson_t { 94 | assert obj.as_map()['str'] or { 0 }.str() == 'string' 95 | assert obj.as_map()['number'] or { 0 }.int() == 2 96 | assert obj.as_map()['float'] or { 0 }.f64() == 2.1 97 | assert obj.as_map()['boolean'] or { 0 }.bool() == true 98 | } 99 | 100 | mut find_cursor_to_be_paginate_filter := map[string]json2.Any{} 101 | find_cursor_to_be_paginate_filter = { 102 | 'str': 'string' 103 | } 104 | 105 | find_cursor_to_be_paginate := collection.find(find_cursor_to_be_paginate_filter) 106 | find_cursor_to_be_paginate1 := collection.find(find_cursor_to_be_paginate_filter) 107 | //find_cursor_to_be_paginate2 := collection.find(find_cursor_to_be_paginate_filter) 108 | find_cursor_to_be_paginate3 := collection.find(find_cursor_to_be_paginate_filter) 109 | find_cursor_to_be_paginate4 := collection.find(find_cursor_to_be_paginate_filter) 110 | 111 | find_cursor_to_be_paginate.limit(2) 112 | find_cursor_to_be_paginate1.skip(2) 113 | //find_cursor_to_be_paginate2.skip(2).limit(1) // FIXME - It is not possible use skip and limit together 114 | find_cursor_to_be_paginate3.skip(0) 115 | find_cursor_to_be_paginate4.limit(0) 116 | 117 | response_with_paginate := find_cursor_to_be_paginate.lean() 118 | response_with_paginate1 := find_cursor_to_be_paginate1.lean() 119 | // response_with_paginate2 := find_cursor_to_be_paginate2.lean() 120 | response_with_paginate3 := find_cursor_to_be_paginate3.lean() 121 | response_with_paginate4 := find_cursor_to_be_paginate4.lean() 122 | 123 | assert response_with_paginate.len == 2 124 | assert response_with_paginate1.len == 3 125 | // assert response_with_paginate2.len == 1 126 | assert response_with_paginate3.len == 5 127 | assert response_with_paginate4.len == 5 128 | } 129 | 130 | fn test_drop() { 131 | client := mongo.new_client('mongodb://127.0.0.1:27017/') 132 | client.get_database('vlang').drop() 133 | assert true 134 | } -------------------------------------------------------------------------------- /src/cursor.v: -------------------------------------------------------------------------------- 1 | module mongo 2 | 3 | import json 4 | import x.json2 5 | 6 | @[inline] 7 | pub fn (cursor &C.mongoc_cursor_t) next_doc(document &&C.bson_t) bool { 8 | return C.mongoc_cursor_next(cursor, document) 9 | } 10 | 11 | pub fn (cursor &C.mongoc_cursor_t) limit(limit int) &C.mongoc_cursor_t { 12 | C.mongoc_cursor_set_limit(cursor, limit) 13 | return unsafe { cursor } 14 | } 15 | 16 | // Get the next document parsing it with the arg struct type and setting it 17 | pub fn (cursor &C.mongoc_cursor_t) next[T](mut t T) ?bool { 18 | document := new_bson() 19 | if !cursor.next_doc(&document) { 20 | return false 21 | } 22 | // declare str to avoid v errors 23 | str := document.str() 24 | t = json.decode(T, str)? 25 | return true 26 | } 27 | 28 | pub fn (cursor &C.mongoc_cursor_t) destroy() { 29 | C.mongoc_cursor_destroy(cursor) 30 | } 31 | 32 | pub fn (cursor &C.mongoc_cursor_t) lean() []json2.Any { 33 | if !C.mongoc_cursor_more(cursor) { 34 | return [] 35 | } 36 | mut response := []json2.Any{} 37 | 38 | document := new_bson() 39 | reply := new_bson() 40 | 41 | mut error := &C.bson_error_t{} 42 | 43 | for C.mongoc_cursor_next(cursor, &document) { 44 | json_doc := document.str() 45 | raw_mp := json2.raw_decode(json_doc) or { continue } 46 | response << raw_mp.as_map() 47 | } 48 | 49 | if C.mongoc_cursor_error_document(cursor, error, &reply) { 50 | unsafe { println(C.bson_as_json(reply, 0).vstring()) } 51 | panic(error) 52 | } 53 | 54 | return response 55 | } 56 | 57 | pub fn (cursor &C.mongoc_cursor_t) skip(skip int) &C.mongoc_cursor_t { 58 | if skip == 0 || !C.mongoc_cursor_more(cursor) { 59 | return unsafe { cursor } 60 | } 61 | 62 | // Do not free this document, it's used with whe cursor and used with the pointer of the current document of the cursor 63 | mut document := &C.bson_t{} 64 | 65 | mut count := skip 66 | for C.mongoc_cursor_next(cursor, document) { 67 | count-- 68 | if count == 0 { 69 | break 70 | } 71 | } 72 | // // FIXME - it not possible set limit after .skip() 73 | // unsafe{println("Set try >>>>>>>>>>> ${C.mongoc_cursor_set_limit(cursor, 1)}")} 74 | 75 | return unsafe { cursor } 76 | } 77 | -------------------------------------------------------------------------------- /src/database.v: -------------------------------------------------------------------------------- 1 | module mongo 2 | 3 | @[inline] 4 | pub fn (database &C.mongoc_database_t) write_command_with_opts(command &C.bson_t, opts &C.bson_t, result &C.bson_t) bool { 5 | return C.mongoc_database_write_command_with_opts(database, command, opts, result, unsafe { nil }) 6 | } 7 | 8 | @[inline] 9 | pub fn (database &C.mongoc_database_t) create_collection(collection string) &C.mongoc_collection_t { 10 | return C.mongoc_database_create_collection(database, collection.str, unsafe { nil }, unsafe { nil }) 11 | } 12 | 13 | @[inline] 14 | pub fn (database &C.mongoc_database_t) get_collections() &C.mongoc_cursor_t { 15 | return C.mongoc_database_find_collections_with_opts(database, unsafe { nil }) 16 | } 17 | 18 | @[inline] 19 | pub fn (database &C.mongoc_database_t) add_user(user string, pass string, roles &C.bson_t) bool { 20 | return C.mongoc_database_add_user(database, user.str, pass.str, unsafe { nil }, unsafe { nil }, unsafe { nil }) 21 | } 22 | 23 | @[inline] 24 | pub fn (database &C.mongoc_database_t) add_user_opts(user string, pass string, roles &C.bson_t, custom_data &C.bson_t) bool { 25 | return C.mongoc_database_add_user(database, user.str, pass.str, roles, custom_data, unsafe { nil }) 26 | } 27 | 28 | @[inline] 29 | pub fn (database &C.mongoc_database_t) drop() bool { 30 | return C.mongoc_database_drop(database, unsafe { nil }) 31 | } 32 | 33 | @[inline] 34 | pub fn (database &C.mongoc_database_t) destroy() { 35 | C.mongoc_database_destroy(database) 36 | } 37 | -------------------------------------------------------------------------------- /src/mongo.v: -------------------------------------------------------------------------------- 1 | module mongo 2 | 3 | fn init() { 4 | C.mongoc_init() 5 | } 6 | 7 | pub fn collection_keys_to_index_string(bson &C.bson_t) string { 8 | return unsafe { 9 | C.mongoc_collection_keys_to_index_string(bson).vstring() 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/mongo_fn.c.v: -------------------------------------------------------------------------------- 1 | module mongo 2 | 3 | #flag -I @VMODROOT/thirdparty/libbson-1.0 4 | #flag -I @VMODROOT/thirdparty/libmongoc-1.0 5 | #flag -l mongoc-1.0 6 | #flag -l bson-1.0 7 | 8 | #include "mongoc/mongoc.h" 9 | #include "bson/bson.h" 10 | 11 | @[trusted] 12 | fn C.mongoc_init() 13 | 14 | @[trusted] 15 | fn C.mongoc_uri_new(byteptr) &C.mongoc_uri_t 16 | @[trusted] 17 | fn C.mongoc_uri_destroy(&C.mongoc_uri_t) 18 | 19 | @[trusted] 20 | fn C.mongoc_client_new(byteptr) &C.mongoc_client_t 21 | @[trusted] 22 | fn C.mongoc_client_new_from_uri(&C.mongoc_uri_t) &C.mongoc_client_t 23 | @[trusted] 24 | fn C.mongoc_client_new_from_uri_with_error(&C.mongoc_uri_t, &C.bson_error_t) &C.mongoc_client_t 25 | @[trusted] 26 | fn C.mongoc_client_destroy(&C.mongoc_client_t) 27 | @[trusted] 28 | fn C.mongoc_client_set_appname(&C.mongoc_client_t, byteptr) bool 29 | 30 | @[trusted] 31 | fn C.mongoc_client_pool_new(&C.mongoc_uri_t) &C.mongoc_client_pool_t 32 | @[trusted] 33 | fn C.mongoc_client_pool_pop(&C.mongoc_client_pool_t) &C.mongoc_client_t 34 | @[trusted] 35 | fn C.mongoc_client_pool_push(&C.mongoc_client_pool_t, &C.mongoc_client_t) 36 | @[trusted] 37 | fn C.mongoc_client_pool_destroy(&C.mongoc_client_pool_t) 38 | 39 | @[trusted] 40 | fn C.mongoc_client_get_database(&C.mongoc_client_t, &char) &C.mongoc_database_t 41 | @[trusted] 42 | fn C.mongoc_client_get_collection(&C.mongoc_client_t, byteptr, byteptr) &C.mongoc_collection_t 43 | @[trusted] 44 | fn C.mongoc_client_set_error_api(&C.mongoc_client_t, u32) bool 45 | 46 | // This function is deprecated and should not be used in new code. 47 | // Use the more convenient mongoc_collection_find_with_opts() instead. 48 | @[trusted] 49 | fn C.mongoc_collection_find(&C.mongoc_collection_t, &QueryFlags, u32, u32, u32, &C.bson_t, &C.bson_t, &C.mongoc_read_prefs_t) &C.mongoc_cursor_t 50 | @[trusted] 51 | fn C.mongoc_collection_find_with_opts(&C.mongoc_collection_t, &C.bson_t, &C.bson_t, &C.mongoc_read_prefs_t) &C.mongoc_cursor_t 52 | 53 | @[trusted] 54 | fn C.mongoc_collection_keys_to_index_string(&C.bson_t) byteptr 55 | 56 | // TODO implement 57 | @[trusted] 58 | fn C.mongoc_collection_find_and_modify(&C.mongoc_collection_t, &C.bson_t, &C.bson_t, &C.bson_t, &C.bson_t, bool, bool, bool, &C.bson_t, &C.bson_error_t) bool 59 | @[trusted] 60 | fn C.mongoc_collection_replace_one(&C.mongoc_collection_t, &C.bson_t, &C.bson_t, &C.bson_t, &C.bson_t, &C.bson_error_t) bool 61 | @[trusted] 62 | fn C.mongoc_collection_count_documents(&C.mongoc_collection_t, &C.bson_t, &C.bson_t, &C.mongoc_read_prefs_t, &C.bson_t, &C.bson_error_t) i64 63 | @[trusted] 64 | fn C.mongoc_collection_insert_one(&C.mongoc_collection_t, &C.bson_t, &C.bson_t, &C.bson_t, &C.bson_error_t) bool 65 | @[trusted] 66 | fn C.mongoc_collection_insert_many(&C.mongoc_collection_t, voidptr, int, &C.bson_t, &C.bson_error_t) bool 67 | @[trusted] 68 | fn C.mongoc_collection_update_one(&C.mongoc_collection_t, &C.bson_t, &C.bson_t, &C.bson_t, &C.bson_t, &C.bson_error_t) bool 69 | @[trusted] 70 | fn C.mongoc_collection_delete_one(&C.mongoc_collection_t, &C.bson_t, &C.bson_t, &C.bson_t, &C.bson_error_t) bool 71 | @[trusted] 72 | fn C.mongoc_collection_create_bulk_operation_with_opts(&C.mongoc_collection_t, &C.bson_t) &C.mongoc_bulk_operation_t 73 | @[trusted] 74 | fn C.mongoc_collection_destroy(&C.mongoc_collection_t) 75 | 76 | @[trusted] 77 | fn C.mongoc_database_create_collection(&C.mongoc_database_t, byteptr, &C.bson_t, &C.bson_error_t) &C.mongoc_collection_t 78 | @[trusted] 79 | fn C.mongoc_database_add_user(&C.mongoc_database_t, byteptr, byteptr, &C.bson_t, &C.bson_t, &C.bson_error_t) bool 80 | @[trusted] 81 | fn C.mongoc_database_find_collections_with_opts(&C.mongoc_database_t, &C.bson_t) &C.mongoc_cursor_t 82 | @[trusted] 83 | fn C.mongoc_database_write_command_with_opts(&C.mongoc_database_t, &C.bson_t, &C.bson_t, &C.bson_t, &C.bson_error_t) bool 84 | @[trusted] 85 | fn C.mongoc_database_drop(&C.mongoc_database_t, &C.bson_error_t) bool 86 | @[trusted] 87 | fn C.mongoc_database_destroy(&C.mongoc_database_t) 88 | 89 | @[trusted] 90 | fn C.mongoc_cursor_next(&C.mongoc_cursor_t, &&C.bson_t) bool 91 | @[trusted] 92 | fn C.mongoc_cursor_set_limit(&C.mongoc_cursor_t, int) bool 93 | @[trusted] 94 | fn C.mongoc_cursor_get_limit(&C.mongoc_cursor_t, int) u64 95 | @[trusted] 96 | fn C.mongoc_cursor_clone(&C.mongoc_cursor_t) &C.mongoc_cursor_t 97 | @[trusted] 98 | fn C.mongoc_cursor_error(&C.mongoc_cursor_t, &C.bson_error_t) bool 99 | @[trusted] 100 | fn C.mongoc_cursor_error_document(&C.mongoc_cursor_t, &C.bson_error_t, &&C.bson_t) bool 101 | @[trusted] 102 | fn C.mongoc_cursor_destroy(&C.mongoc_cursor_t) 103 | @[trusted] 104 | fn C.mongoc_cursor_more(&C.mongoc_cursor_t) bool 105 | @[trusted] 106 | fn C.mongoc_cursor_current(&C.mongoc_cursor_t) bool 107 | 108 | // fn C.mongoc_cursor_get_host(&C.mongoc_cursor_t) 109 | 110 | @[trusted] 111 | fn C.mongoc_stream_timed_out(&C.mongoc_stream_t) bool 112 | @[trusted] 113 | fn C.mongoc_stream_should_retry(&C.mongoc_stream_t) bool 114 | @[trusted] 115 | fn C.mongoc_stream_close(&C.mongoc_stream_t) int 116 | @[trusted] 117 | fn C.mongoc_stream_flush(&C.mongoc_stream_t) int 118 | @[trusted] 119 | fn C.mongoc_stream_destroy(&C.mongoc_stream_t) 120 | 121 | @[trusted] 122 | fn C.mongoc_stream_file_new(int) &C.mongoc_stream_file_t 123 | 124 | @[trusted] 125 | fn C.mongoc_cleanup() 126 | -------------------------------------------------------------------------------- /src/mongo_structs.c.v: -------------------------------------------------------------------------------- 1 | module mongo 2 | 3 | #flag -I @VMODROOT/thirdparty/libbson-1.0 4 | #flag -I @VMODROOT/thirdparty/libmongoc-1.0 5 | #flag -l mongoc-1.0 6 | #flag -l bson-1.0 7 | 8 | #include "mongoc/mongoc.h" 9 | #include "bson/bson.h" 10 | 11 | // http://mongoc.org/libmongoc/current/mongoc_client_t.html 12 | @[typedef] 13 | pub struct C.mongoc_client_t {} 14 | 15 | // http://mongoc.org/libmongoc/current/mongoc_client_pool_new.html 16 | @[typedef] 17 | pub struct C.mongoc_client_pool_t {} 18 | 19 | // http://mongoc.org/libmongoc/current/mongoc_database_t.html 20 | @[typedef] 21 | pub struct C.mongoc_database_t {} 22 | 23 | // http://mongoc.org/libmongoc/current/mongoc_collection_t.html 24 | @[typedef] 25 | pub struct C.mongoc_collection_t {} 26 | 27 | // http://mongoc.org/libmongoc/current/mongoc_write_concern_t.html 28 | @[typedef] 29 | pub struct C.mongoc_write_concern_t {} 30 | 31 | // http://mongoc.org/libmongoc/current/mongoc_uri_t.html 32 | @[typedef] 33 | pub struct C.mongoc_uri_t {} 34 | 35 | // http://mongoc.org/libmongoc/current/mongoc_cursor_t.html 36 | @[typedef] 37 | pub struct C.mongoc_cursor_t {} 38 | 39 | // http://mongoc.org/libmongoc/1.17.0/mongoc_query_flags_t.html 40 | @[typedef] 41 | pub struct C.mongoc_query_flags_t {} 42 | 43 | // http://mongoc.org/libmongoc/current/mongoc_read_prefs_t.html 44 | @[typedef] 45 | pub struct C.mongoc_read_prefs_t {} 46 | 47 | // http://mongoc.org/libmongoc/current/mongoc_stream_t.html 48 | @[typedef] 49 | pub struct C.mongoc_stream_t {} 50 | 51 | // http://mongoc.org/libmongoc/current/mongoc_stream_file_t.html 52 | @[typedef] 53 | pub struct C.mongoc_stream_file_t {} 54 | 55 | // https://mongoc.org/libmongoc/current/mongoc_bulk_operation_t.html 56 | @[typedef] 57 | pub struct C.mongoc_bulk_operation_t {} 58 | -------------------------------------------------------------------------------- /src/mongo_utils.v: -------------------------------------------------------------------------------- 1 | module mongo 2 | 3 | pub fn bson_create_index(field_name string, order int) &C.bson_t { 4 | if order !in [1, -1] { 5 | error('order not valid, must be 1 or -1') 6 | } 7 | bson_index := new_from_json('{"${field_name}": ${order}}') 8 | index_name := collection_keys_to_index_string(bson_index) 9 | println(index_name) 10 | return new_from_json('') 11 | } 12 | -------------------------------------------------------------------------------- /src/stream.v: -------------------------------------------------------------------------------- 1 | module mongo 2 | 3 | import os 4 | 5 | @[inline] 6 | pub fn new_stream_file(file os.File) &C.mongoc_stream_file_t { 7 | return C.mongoc_stream_file_new(file.fd) 8 | } 9 | 10 | // [inline] 11 | // pub fn (stream &C.mongoc_stream_t) timed_out() bool { 12 | // return C.mongoc_stream_timed_out(stream) 13 | // } 14 | 15 | // [inline] 16 | // pub fn (stream &C.mongoc_stream_t) should_retry() bool { 17 | // return C.mongoc_stream_should_retry(stream) 18 | // } 19 | 20 | // [inline] 21 | // pub fn (stream &C.mongoc_stream_t) close() int { 22 | // return C.mongoc_stream_close(stream) 23 | // } 24 | 25 | // [inline] 26 | // pub fn (stream &C.mongoc_stream_t) flush() int { 27 | // return C.mongoc_stream_flush(stream) 28 | // } 29 | 30 | // [inline] 31 | // pub fn (stream &C.mongoc_stream_t) destroy() { 32 | // C.mongoc_stream_destroy(stream) 33 | // } 34 | -------------------------------------------------------------------------------- /src/test_mongo.v: -------------------------------------------------------------------------------- 1 | module mongo 2 | 3 | /* 4 | import mongo.bson 5 | 6 | const ( 7 | uri = 'mongodb://127.0.0.1:27017' 8 | mongo_uri = uri_new(uri) 9 | client = client_new_from_uri(mongo_uri) 10 | db_name = 'db_name' 11 | collection_name = 'collection_name' 12 | collection = client_get_collection(client, db_name, collection_name) 13 | ) 14 | 15 | fn test_insert() { 16 | doc := bson.new_from_json('{"insert":"test"}') 17 | assert collection_insert_one(collection, doc) == true 18 | } 19 | 20 | fn test_update() { 21 | selector := bson.new_from_json('{"update":"test"}') 22 | update := bson.new_from_json('{"\$set":{"update2":"test2"}}') 23 | 24 | collection_insert_one(collection, selector) 25 | 26 | assert collection_update_one(collection, selector, update) == true 27 | } 28 | 29 | fn test_delete() { 30 | doc := bson.new_from_json('{"delete":"test"}') 31 | 32 | collection_insert_one(collection, doc) 33 | assert collection_delete_one(collection, doc) == true 34 | } 35 | */ 36 | -------------------------------------------------------------------------------- /src/thirdparty/libbson-1.0/bson.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-present MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* Including bson.h is superseded. Use bson/bson.h instead. */ 18 | #include "bson/bson.h" -------------------------------------------------------------------------------- /src/thirdparty/libbson-1.0/bson/bson-clock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "bson-prelude.h" 18 | 19 | 20 | #ifndef BSON_CLOCK_H 21 | #define BSON_CLOCK_H 22 | 23 | 24 | #include "bson-compat.h" 25 | #include "bson-macros.h" 26 | #include "bson-types.h" 27 | 28 | 29 | BSON_BEGIN_DECLS 30 | 31 | 32 | BSON_EXPORT (int64_t) 33 | bson_get_monotonic_time (void); 34 | BSON_EXPORT (int) 35 | bson_gettimeofday (struct timeval *tv); 36 | 37 | 38 | BSON_END_DECLS 39 | 40 | 41 | #endif /* BSON_CLOCK_H */ 42 | -------------------------------------------------------------------------------- /src/thirdparty/libbson-1.0/bson/bson-compat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "bson-prelude.h" 18 | 19 | 20 | #ifndef BSON_COMPAT_H 21 | #define BSON_COMPAT_H 22 | 23 | 24 | #if defined(__MINGW32__) 25 | #if defined(__USE_MINGW_ANSI_STDIO) 26 | #if __USE_MINGW_ANSI_STDIO < 1 27 | #error "__USE_MINGW_ANSI_STDIO > 0 is required for correct PRI* macros" 28 | #endif 29 | #else 30 | #define __USE_MINGW_ANSI_STDIO 1 31 | #endif 32 | #endif 33 | 34 | #include "bson-config.h" 35 | #include "bson-macros.h" 36 | 37 | 38 | #ifdef BSON_OS_WIN32 39 | #if defined(_WIN32_WINNT) && (_WIN32_WINNT < 0x0600) 40 | #undef _WIN32_WINNT 41 | #endif 42 | #ifndef _WIN32_WINNT 43 | #define _WIN32_WINNT 0x0600 44 | #endif 45 | #ifndef NOMINMAX 46 | #define NOMINMAX 47 | #endif 48 | #include 49 | #ifndef WIN32_LEAN_AND_MEAN 50 | #define WIN32_LEAN_AND_MEAN 51 | #include 52 | #undef WIN32_LEAN_AND_MEAN 53 | #else 54 | #include 55 | #endif 56 | #include 57 | #include 58 | #endif 59 | 60 | 61 | #ifdef BSON_OS_UNIX 62 | #include 63 | #include 64 | #endif 65 | 66 | 67 | #include "bson-macros.h" 68 | 69 | 70 | #include 71 | #include 72 | #include 73 | #include 74 | #include 75 | #include 76 | #include 77 | #include 78 | #include 79 | #include 80 | #include 81 | 82 | 83 | BSON_BEGIN_DECLS 84 | 85 | #if !defined(_MSC_VER) || (_MSC_VER >= 1800) 86 | #include 87 | #endif 88 | #ifdef _MSC_VER 89 | #ifndef __cplusplus 90 | /* benign redefinition of type */ 91 | #pragma warning(disable : 4142) 92 | #ifndef _SSIZE_T_DEFINED 93 | #define _SSIZE_T_DEFINED 94 | typedef SSIZE_T ssize_t; 95 | #endif 96 | #ifndef _SIZE_T_DEFINED 97 | #define _SIZE_T_DEFINED 98 | typedef SIZE_T size_t; 99 | #endif 100 | #pragma warning(default : 4142) 101 | #else 102 | /* 103 | * MSVC++ does not include ssize_t, just size_t. 104 | * So we need to synthesize that as well. 105 | */ 106 | #pragma warning(disable : 4142) 107 | #ifndef _SSIZE_T_DEFINED 108 | #define _SSIZE_T_DEFINED 109 | typedef SSIZE_T ssize_t; 110 | #endif 111 | #pragma warning(default : 4142) 112 | #endif 113 | #ifndef PRIi32 114 | #define PRIi32 "d" 115 | #endif 116 | #ifndef PRId32 117 | #define PRId32 "d" 118 | #endif 119 | #ifndef PRIu32 120 | #define PRIu32 "u" 121 | #endif 122 | #ifndef PRIi64 123 | #define PRIi64 "I64i" 124 | #endif 125 | #ifndef PRId64 126 | #define PRId64 "I64i" 127 | #endif 128 | #ifndef PRIu64 129 | #define PRIu64 "I64u" 130 | #endif 131 | #endif 132 | 133 | #if defined(__MINGW32__) && !defined(INIT_ONCE_STATIC_INIT) 134 | #define INIT_ONCE_STATIC_INIT RTL_RUN_ONCE_INIT 135 | typedef RTL_RUN_ONCE INIT_ONCE; 136 | #endif 137 | 138 | #ifdef BSON_HAVE_STDBOOL_H 139 | #include 140 | #elif !defined(__bool_true_false_are_defined) 141 | #ifndef __cplusplus 142 | typedef signed char bool; 143 | #define false 0 144 | #define true 1 145 | #endif 146 | #define __bool_true_false_are_defined 1 147 | #endif 148 | 149 | 150 | #if defined(__GNUC__) 151 | #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) 152 | #define bson_sync_synchronize() __sync_synchronize () 153 | #elif defined(__i386__) || defined(__i486__) || defined(__i586__) || \ 154 | defined(__i686__) || defined(__x86_64__) 155 | #define bson_sync_synchronize() asm volatile("mfence" ::: "memory") 156 | #else 157 | #define bson_sync_synchronize() asm volatile("sync" ::: "memory") 158 | #endif 159 | #elif defined(_MSC_VER) 160 | #define bson_sync_synchronize() MemoryBarrier () 161 | #endif 162 | 163 | 164 | #if !defined(va_copy) && defined(__va_copy) 165 | #define va_copy(dst, src) __va_copy (dst, src) 166 | #endif 167 | 168 | 169 | #if !defined(va_copy) 170 | #define va_copy(dst, src) ((dst) = (src)) 171 | #endif 172 | 173 | 174 | #ifdef _MSC_VER 175 | /** Expands the arguments if compiling with MSVC, otherwise empty */ 176 | #define BSON_IF_MSVC(...) __VA_ARGS__ 177 | /** Expands the arguments if compiling with GCC or Clang, otherwise empty */ 178 | #define BSON_IF_GNU_LIKE(...) 179 | #elif defined(__GNUC__) || defined(__clang__) 180 | /** Expands the arguments if compiling with MSVC, otherwise empty */ 181 | #define BSON_IF_MSVC(...) 182 | /** Expands the arguments if compiling with GCC or Clang, otherwise empty */ 183 | #define BSON_IF_GNU_LIKE(...) __VA_ARGS__ 184 | #endif 185 | 186 | #ifdef BSON_OS_WIN32 187 | /** Expands the arguments if compiling for Windows, otherwise empty */ 188 | #define BSON_IF_WINDOWS(...) __VA_ARGS__ 189 | /** Expands the arguments if compiling for POSIX, otherwise empty */ 190 | #define BSON_IF_POSIX(...) 191 | #elif defined(BSON_OS_UNIX) 192 | /** Expands the arguments if compiling for Windows, otherwise empty */ 193 | #define BSON_IF_WINDOWS(...) 194 | /** Expands the arguments if compiling for POSIX, otherwise empty */ 195 | #define BSON_IF_POSIX(...) __VA_ARGS__ 196 | #endif 197 | 198 | 199 | BSON_END_DECLS 200 | 201 | 202 | #endif /* BSON_COMPAT_H */ 203 | -------------------------------------------------------------------------------- /src/thirdparty/libbson-1.0/bson/bson-config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-present MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #if !defined(BSON_INSIDE) && !defined(BSON_COMPILATION) 18 | #error "Only can be included directly." 19 | #endif 20 | 21 | #ifndef BSON_CONFIG_H 22 | #define BSON_CONFIG_H 23 | 24 | /* 25 | * Define to 1234 for Little Endian, 4321 for Big Endian. 26 | */ 27 | #define BSON_BYTE_ORDER 1234 28 | 29 | 30 | /* 31 | * Define to 1 if you have stdbool.h 32 | */ 33 | #define BSON_HAVE_STDBOOL_H 1 34 | #if BSON_HAVE_STDBOOL_H != 1 35 | # undef BSON_HAVE_STDBOOL_H 36 | #endif 37 | 38 | 39 | /* 40 | * Define to 1 for POSIX-like systems, 2 for Windows. 41 | */ 42 | #define BSON_OS 1 43 | 44 | 45 | /* 46 | * Define to 1 if you have clock_gettime() available. 47 | */ 48 | #define BSON_HAVE_CLOCK_GETTIME 1 49 | #if BSON_HAVE_CLOCK_GETTIME != 1 50 | # undef BSON_HAVE_CLOCK_GETTIME 51 | #endif 52 | 53 | 54 | /* 55 | * Define to 1 if you have strings.h available on your platform. 56 | */ 57 | #define BSON_HAVE_STRINGS_H 1 58 | #if BSON_HAVE_STRINGS_H != 1 59 | # undef BSON_HAVE_STRINGS_H 60 | #endif 61 | 62 | 63 | /* 64 | * Define to 1 if you have strnlen available on your platform. 65 | */ 66 | #define BSON_HAVE_STRNLEN 1 67 | #if BSON_HAVE_STRNLEN != 1 68 | # undef BSON_HAVE_STRNLEN 69 | #endif 70 | 71 | 72 | /* 73 | * Define to 1 if you have snprintf available on your platform. 74 | */ 75 | #define BSON_HAVE_SNPRINTF 1 76 | #if BSON_HAVE_SNPRINTF != 1 77 | # undef BSON_HAVE_SNPRINTF 78 | #endif 79 | 80 | 81 | /* 82 | * Define to 1 if you have gmtime_r available on your platform. 83 | */ 84 | #define BSON_HAVE_GMTIME_R 1 85 | #if BSON_HAVE_GMTIME_R != 1 86 | # undef BSON_HAVE_GMTIME_R 87 | #endif 88 | 89 | 90 | /* 91 | * Define to 1 if you have struct timespec available on your platform. 92 | */ 93 | #define BSON_HAVE_TIMESPEC 1 94 | #if BSON_HAVE_TIMESPEC != 1 95 | # undef BSON_HAVE_TIMESPEC 96 | #endif 97 | 98 | 99 | /* 100 | * Define to 1 if you want extra aligned types in libbson 101 | */ 102 | #define BSON_EXTRA_ALIGN 1 103 | #if BSON_EXTRA_ALIGN != 1 104 | # undef BSON_EXTRA_ALIGN 105 | #endif 106 | 107 | 108 | /* 109 | * Define to 1 if you have rand_r available on your platform. 110 | */ 111 | #define BSON_HAVE_RAND_R 1 112 | #if BSON_HAVE_RAND_R != 1 113 | # undef BSON_HAVE_RAND_R 114 | #endif 115 | 116 | 117 | /* 118 | * Define to 1 if you have strlcpy available on your platform. 119 | */ 120 | #define BSON_HAVE_STRLCPY 0 121 | #if BSON_HAVE_STRLCPY != 1 122 | # undef BSON_HAVE_STRLCPY 123 | #endif 124 | 125 | #endif /* BSON_CONFIG_H */ 126 | -------------------------------------------------------------------------------- /src/thirdparty/libbson-1.0/bson/bson-context.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "bson-prelude.h" 18 | 19 | 20 | #ifndef BSON_CONTEXT_H 21 | #define BSON_CONTEXT_H 22 | 23 | 24 | #include "bson-macros.h" 25 | #include "bson-types.h" 26 | 27 | 28 | BSON_BEGIN_DECLS 29 | 30 | 31 | /** 32 | * @brief Initialize a new context with the given flags 33 | * 34 | * @param flags Flags used to configure the behavior of the context. For most 35 | * cases, this should be BSON_CONTEXT_NONE. 36 | * 37 | * @return A newly allocated context. Must be freed with bson_context_destroy() 38 | * 39 | * @note If you expect your pid to change without notice, such as from an 40 | * unexpected call to fork(), then specify BSON_CONTEXT_DISABLE_PID_CACHE in 41 | * `flags`. 42 | */ 43 | BSON_EXPORT (bson_context_t *) 44 | bson_context_new (bson_context_flags_t flags); 45 | 46 | /** 47 | * @brief Destroy and free a bson_context_t created by bson_context_new() 48 | */ 49 | BSON_EXPORT (void) 50 | bson_context_destroy (bson_context_t *context); 51 | 52 | /** 53 | * @brief Obtain a pointer to the application-default bson_context_t 54 | * 55 | * @note This context_t MUST NOT be passed to bson_context_destroy() 56 | */ 57 | BSON_EXPORT (bson_context_t *) 58 | bson_context_get_default (void); 59 | 60 | 61 | BSON_END_DECLS 62 | 63 | 64 | #endif /* BSON_CONTEXT_H */ 65 | -------------------------------------------------------------------------------- /src/thirdparty/libbson-1.0/bson/bson-decimal128.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "bson-prelude.h" 18 | 19 | 20 | #ifndef BSON_DECIMAL128_H 21 | #define BSON_DECIMAL128_H 22 | 23 | 24 | #include 25 | 26 | #include "bson-macros.h" 27 | #include "bson-config.h" 28 | #include "bson-types.h" 29 | 30 | 31 | /** 32 | * BSON_DECIMAL128_STRING: 33 | * 34 | * The length of a decimal128 string (with null terminator). 35 | * 36 | * 1 for the sign 37 | * 35 for digits and radix 38 | * 2 for exponent indicator and sign 39 | * 4 for exponent digits 40 | */ 41 | #define BSON_DECIMAL128_STRING 43 42 | #define BSON_DECIMAL128_INF "Infinity" 43 | #define BSON_DECIMAL128_NAN "NaN" 44 | 45 | 46 | BSON_BEGIN_DECLS 47 | 48 | BSON_EXPORT (void) 49 | bson_decimal128_to_string (const bson_decimal128_t *dec, char *str); 50 | 51 | 52 | /* Note: @string must be ASCII characters only! */ 53 | BSON_EXPORT (bool) 54 | bson_decimal128_from_string (const char *string, bson_decimal128_t *dec); 55 | 56 | BSON_EXPORT (bool) 57 | bson_decimal128_from_string_w_len (const char *string, 58 | int len, 59 | bson_decimal128_t *dec); 60 | 61 | BSON_END_DECLS 62 | 63 | 64 | #endif /* BSON_DECIMAL128_H */ 65 | -------------------------------------------------------------------------------- /src/thirdparty/libbson-1.0/bson/bson-error.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "bson-prelude.h" 18 | 19 | 20 | #ifndef BSON_ERROR_H 21 | #define BSON_ERROR_H 22 | 23 | 24 | #include "bson-compat.h" 25 | #include "bson-macros.h" 26 | #include "bson-types.h" 27 | 28 | 29 | BSON_BEGIN_DECLS 30 | 31 | 32 | #define BSON_ERROR_JSON 1 33 | #define BSON_ERROR_READER 2 34 | #define BSON_ERROR_INVALID 3 35 | 36 | 37 | BSON_EXPORT (void) 38 | bson_set_error (bson_error_t *error, 39 | uint32_t domain, 40 | uint32_t code, 41 | const char *format, 42 | ...) BSON_GNUC_PRINTF (4, 5); 43 | BSON_EXPORT (char *) 44 | bson_strerror_r (int err_code, char *buf, size_t buflen); 45 | 46 | 47 | BSON_END_DECLS 48 | 49 | 50 | #endif /* BSON_ERROR_H */ 51 | -------------------------------------------------------------------------------- /src/thirdparty/libbson-1.0/bson/bson-json.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "bson-prelude.h" 18 | 19 | 20 | #ifndef BSON_JSON_H 21 | #define BSON_JSON_H 22 | 23 | 24 | #include "bson.h" 25 | 26 | 27 | BSON_BEGIN_DECLS 28 | 29 | 30 | typedef struct _bson_json_reader_t bson_json_reader_t; 31 | 32 | 33 | typedef enum { 34 | BSON_JSON_ERROR_READ_CORRUPT_JS = 1, 35 | BSON_JSON_ERROR_READ_INVALID_PARAM, 36 | BSON_JSON_ERROR_READ_CB_FAILURE, 37 | } bson_json_error_code_t; 38 | 39 | 40 | /** 41 | * BSON_MAX_LEN_UNLIMITED 42 | * 43 | * Denotes unlimited length limit when converting BSON to JSON. 44 | */ 45 | #define BSON_MAX_LEN_UNLIMITED -1 46 | 47 | /** 48 | * bson_json_mode_t: 49 | * 50 | * This enumeration contains the different modes to serialize BSON into extended 51 | * JSON. 52 | */ 53 | typedef enum { 54 | BSON_JSON_MODE_LEGACY, 55 | BSON_JSON_MODE_CANONICAL, 56 | BSON_JSON_MODE_RELAXED, 57 | } bson_json_mode_t; 58 | 59 | 60 | BSON_EXPORT (bson_json_opts_t *) 61 | bson_json_opts_new (bson_json_mode_t mode, int32_t max_len); 62 | BSON_EXPORT (void) 63 | bson_json_opts_destroy (bson_json_opts_t *opts); 64 | 65 | 66 | typedef ssize_t (*bson_json_reader_cb) (void *handle, 67 | uint8_t *buf, 68 | size_t count); 69 | typedef void (*bson_json_destroy_cb) (void *handle); 70 | 71 | 72 | BSON_EXPORT (bson_json_reader_t *) 73 | bson_json_reader_new (void *data, 74 | bson_json_reader_cb cb, 75 | bson_json_destroy_cb dcb, 76 | bool allow_multiple, 77 | size_t buf_size); 78 | BSON_EXPORT (bson_json_reader_t *) 79 | bson_json_reader_new_from_fd (int fd, bool close_on_destroy); 80 | BSON_EXPORT (bson_json_reader_t *) 81 | bson_json_reader_new_from_file (const char *filename, bson_error_t *error); 82 | BSON_EXPORT (void) 83 | bson_json_reader_destroy (bson_json_reader_t *reader); 84 | BSON_EXPORT (int) 85 | bson_json_reader_read (bson_json_reader_t *reader, 86 | bson_t *bson, 87 | bson_error_t *error); 88 | BSON_EXPORT (bson_json_reader_t *) 89 | bson_json_data_reader_new (bool allow_multiple, size_t size); 90 | BSON_EXPORT (void) 91 | bson_json_data_reader_ingest (bson_json_reader_t *reader, 92 | const uint8_t *data, 93 | size_t len); 94 | 95 | 96 | BSON_END_DECLS 97 | 98 | 99 | #endif /* BSON_JSON_H */ 100 | -------------------------------------------------------------------------------- /src/thirdparty/libbson-1.0/bson/bson-keys.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "bson-prelude.h" 18 | 19 | 20 | #ifndef BSON_KEYS_H 21 | #define BSON_KEYS_H 22 | 23 | 24 | #include "bson-macros.h" 25 | #include "bson-types.h" 26 | 27 | 28 | BSON_BEGIN_DECLS 29 | 30 | 31 | BSON_EXPORT (size_t) 32 | bson_uint32_to_string (uint32_t value, 33 | const char **strptr, 34 | char *str, 35 | size_t size); 36 | 37 | 38 | BSON_END_DECLS 39 | 40 | 41 | #endif /* BSON_KEYS_H */ 42 | -------------------------------------------------------------------------------- /src/thirdparty/libbson-1.0/bson/bson-md5.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 1999, 2002 Aladdin Enterprises. All rights reserved. 3 | 4 | This software is provided 'as-is', without any express or implied 5 | warranty. In no event will the authors be held liable for any damages 6 | arising from the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it 10 | freely, subject to the following restrictions: 11 | 12 | 1. The origin of this software must not be misrepresented; you must not 13 | claim that you wrote the original software. If you use this software 14 | in a product, an acknowledgement in the product documentation would be 15 | appreciated but is not required. 16 | 2. Altered source versions must be plainly marked as such, and must not be 17 | misrepresented as being the original software. 18 | 3. This notice may not be removed or altered from any source distribution. 19 | 20 | L. Peter Deutsch 21 | ghost@aladdin.com 22 | 23 | */ 24 | /* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */ 25 | /* 26 | Independent implementation of MD5 (RFC 1321). 27 | 28 | This code implements the MD5 Algorithm defined in RFC 1321, whose 29 | text is available at 30 | http://www.ietf.org/rfc/rfc1321.txt 31 | The code is derived from the text of the RFC, including the test suite 32 | (section A.5) but excluding the rest of Appendix A. It does not include 33 | any code or documentation that is identified in the RFC as being 34 | copyrighted. 35 | 36 | The original and principal author of md5.h is L. Peter Deutsch 37 | . Other authors are noted in the change history 38 | that follows (in reverse chronological order): 39 | 40 | 2002-04-13 lpd Removed support for non-ANSI compilers; removed 41 | references to Ghostscript; clarified derivation from RFC 1321; 42 | now handles byte order either statically or dynamically. 43 | 1999-11-04 lpd Edited comments slightly for automatic TOC extraction. 44 | 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5); 45 | added conditionalization for C++ compilation from Martin 46 | Purschke . 47 | 1999-05-03 lpd Original version. 48 | */ 49 | 50 | 51 | /* 52 | * The following MD5 implementation has been modified to use types as 53 | * specified in libbson. 54 | */ 55 | 56 | #include "bson-prelude.h" 57 | 58 | 59 | #ifndef BSON_MD5_H 60 | #define BSON_MD5_H 61 | 62 | 63 | #include "bson-endian.h" 64 | 65 | 66 | BSON_BEGIN_DECLS 67 | 68 | 69 | typedef struct { 70 | uint32_t count[2]; /* message length in bits, lsw first */ 71 | uint32_t abcd[4]; /* digest buffer */ 72 | uint8_t buf[64]; /* accumulate block */ 73 | } bson_md5_t; 74 | 75 | 76 | BSON_EXPORT (void) 77 | bson_md5_init (bson_md5_t *pms) BSON_GNUC_DEPRECATED; 78 | BSON_EXPORT (void) 79 | bson_md5_append (bson_md5_t *pms, 80 | const uint8_t *data, 81 | uint32_t nbytes) BSON_GNUC_DEPRECATED; 82 | BSON_EXPORT (void) 83 | bson_md5_finish (bson_md5_t *pms, uint8_t digest[16]) BSON_GNUC_DEPRECATED; 84 | 85 | 86 | BSON_END_DECLS 87 | 88 | 89 | #endif /* BSON_MD5_H */ 90 | -------------------------------------------------------------------------------- /src/thirdparty/libbson-1.0/bson/bson-memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "bson-prelude.h" 18 | 19 | 20 | #ifndef BSON_MEMORY_H 21 | #define BSON_MEMORY_H 22 | 23 | 24 | #include "bson-macros.h" 25 | #include "bson-types.h" 26 | 27 | 28 | BSON_BEGIN_DECLS 29 | 30 | 31 | typedef void *(*bson_realloc_func) (void *mem, size_t num_bytes, void *ctx); 32 | 33 | 34 | typedef struct _bson_mem_vtable_t { 35 | void *(*malloc) (size_t num_bytes); 36 | void *(*calloc) (size_t n_members, size_t num_bytes); 37 | void *(*realloc) (void *mem, size_t num_bytes); 38 | void (*free) (void *mem); 39 | void *padding[4]; 40 | } bson_mem_vtable_t; 41 | 42 | 43 | BSON_EXPORT (void) 44 | bson_mem_set_vtable (const bson_mem_vtable_t *vtable); 45 | BSON_EXPORT (void) 46 | bson_mem_restore_vtable (void); 47 | BSON_EXPORT (void *) 48 | bson_malloc (size_t num_bytes); 49 | BSON_EXPORT (void *) 50 | bson_malloc0 (size_t num_bytes); 51 | BSON_EXPORT (void *) 52 | bson_realloc (void *mem, size_t num_bytes); 53 | BSON_EXPORT (void *) 54 | bson_realloc_ctx (void *mem, size_t num_bytes, void *ctx); 55 | BSON_EXPORT (void) 56 | bson_free (void *mem); 57 | BSON_EXPORT (void) 58 | bson_zero_free (void *mem, size_t size); 59 | 60 | 61 | BSON_END_DECLS 62 | 63 | 64 | #endif /* BSON_MEMORY_H */ 65 | -------------------------------------------------------------------------------- /src/thirdparty/libbson-1.0/bson/bson-oid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "bson-prelude.h" 18 | 19 | 20 | #ifndef BSON_OID_H 21 | #define BSON_OID_H 22 | 23 | 24 | #include 25 | 26 | #include "bson-context.h" 27 | #include "bson-macros.h" 28 | #include "bson-types.h" 29 | #include "bson-endian.h" 30 | 31 | 32 | BSON_BEGIN_DECLS 33 | 34 | 35 | BSON_EXPORT (int) 36 | bson_oid_compare (const bson_oid_t *oid1, const bson_oid_t *oid2); 37 | BSON_EXPORT (void) 38 | bson_oid_copy (const bson_oid_t *src, bson_oid_t *dst); 39 | BSON_EXPORT (bool) 40 | bson_oid_equal (const bson_oid_t *oid1, const bson_oid_t *oid2); 41 | BSON_EXPORT (bool) 42 | bson_oid_is_valid (const char *str, size_t length); 43 | BSON_EXPORT (time_t) 44 | bson_oid_get_time_t (const bson_oid_t *oid); 45 | BSON_EXPORT (uint32_t) 46 | bson_oid_hash (const bson_oid_t *oid); 47 | BSON_EXPORT (void) 48 | bson_oid_init (bson_oid_t *oid, bson_context_t *context); 49 | BSON_EXPORT (void) 50 | bson_oid_init_from_data (bson_oid_t *oid, const uint8_t *data); 51 | BSON_EXPORT (void) 52 | bson_oid_init_from_string (bson_oid_t *oid, const char *str); 53 | BSON_EXPORT (void) 54 | bson_oid_init_sequence (bson_oid_t *oid, 55 | bson_context_t *context) BSON_GNUC_DEPRECATED; 56 | BSON_EXPORT (void) 57 | bson_oid_to_string (const bson_oid_t *oid, char str[25]); 58 | 59 | 60 | /** 61 | * bson_oid_compare_unsafe: 62 | * @oid1: A bson_oid_t. 63 | * @oid2: A bson_oid_t. 64 | * 65 | * Performs a qsort() style comparison between @oid1 and @oid2. 66 | * 67 | * This function is meant to be as fast as possible and therefore performs 68 | * no argument validation. That is the callers responsibility. 69 | * 70 | * Returns: An integer < 0 if @oid1 is less than @oid2. Zero if they are equal. 71 | * An integer > 0 if @oid1 is greater than @oid2. 72 | */ 73 | static BSON_INLINE int 74 | bson_oid_compare_unsafe (const bson_oid_t *oid1, const bson_oid_t *oid2) 75 | { 76 | return memcmp (oid1, oid2, sizeof *oid1); 77 | } 78 | 79 | 80 | /** 81 | * bson_oid_equal_unsafe: 82 | * @oid1: A bson_oid_t. 83 | * @oid2: A bson_oid_t. 84 | * 85 | * Checks the equality of @oid1 and @oid2. 86 | * 87 | * This function is meant to be as fast as possible and therefore performs 88 | * no checks for argument validity. That is the callers responsibility. 89 | * 90 | * Returns: true if @oid1 and @oid2 are equal; otherwise false. 91 | */ 92 | static BSON_INLINE bool 93 | bson_oid_equal_unsafe (const bson_oid_t *oid1, const bson_oid_t *oid2) 94 | { 95 | return !memcmp (oid1, oid2, sizeof *oid1); 96 | } 97 | 98 | /** 99 | * bson_oid_hash_unsafe: 100 | * @oid: A bson_oid_t. 101 | * 102 | * This function performs a DJB style hash upon the bytes contained in @oid. 103 | * The result is a hash key suitable for use in a hashtable. 104 | * 105 | * This function is meant to be as fast as possible and therefore performs no 106 | * validation of arguments. The caller is responsible to ensure they are 107 | * passing valid arguments. 108 | * 109 | * Returns: A uint32_t containing a hash code. 110 | */ 111 | static BSON_INLINE uint32_t 112 | bson_oid_hash_unsafe (const bson_oid_t *oid) 113 | { 114 | uint32_t hash = 5381; 115 | uint32_t i; 116 | 117 | for (i = 0; i < sizeof oid->bytes; i++) { 118 | hash = ((hash << 5) + hash) + oid->bytes[i]; 119 | } 120 | 121 | return hash; 122 | } 123 | 124 | 125 | /** 126 | * bson_oid_copy_unsafe: 127 | * @src: A bson_oid_t to copy from. 128 | * @dst: A bson_oid_t to copy into. 129 | * 130 | * Copies the contents of @src into @dst. This function is meant to be as 131 | * fast as possible and therefore performs no argument checking. It is the 132 | * callers responsibility to ensure they are passing valid data into the 133 | * function. 134 | */ 135 | static BSON_INLINE void 136 | bson_oid_copy_unsafe (const bson_oid_t *src, bson_oid_t *dst) 137 | { 138 | memcpy (dst, src, sizeof *src); 139 | } 140 | 141 | 142 | /** 143 | * bson_oid_parse_hex_char: 144 | * @hex: A character to parse to its integer value. 145 | * 146 | * This function contains a jump table to return the integer value for a 147 | * character containing a hexadecimal value (0-9, a-f, A-F). If the character 148 | * is not a hexadecimal character then zero is returned. 149 | * 150 | * Returns: An integer between 0 and 15. 151 | */ 152 | static BSON_INLINE uint8_t 153 | bson_oid_parse_hex_char (char hex) 154 | { 155 | switch (hex) { 156 | case '0': 157 | return 0; 158 | case '1': 159 | return 1; 160 | case '2': 161 | return 2; 162 | case '3': 163 | return 3; 164 | case '4': 165 | return 4; 166 | case '5': 167 | return 5; 168 | case '6': 169 | return 6; 170 | case '7': 171 | return 7; 172 | case '8': 173 | return 8; 174 | case '9': 175 | return 9; 176 | case 'a': 177 | case 'A': 178 | return 0xa; 179 | case 'b': 180 | case 'B': 181 | return 0xb; 182 | case 'c': 183 | case 'C': 184 | return 0xc; 185 | case 'd': 186 | case 'D': 187 | return 0xd; 188 | case 'e': 189 | case 'E': 190 | return 0xe; 191 | case 'f': 192 | case 'F': 193 | return 0xf; 194 | default: 195 | return 0; 196 | } 197 | } 198 | 199 | 200 | /** 201 | * bson_oid_init_from_string_unsafe: 202 | * @oid: A bson_oid_t to store the result. 203 | * @str: A 24-character hexadecimal encoded string. 204 | * 205 | * Parses a string containing 24 hexadecimal encoded bytes into a bson_oid_t. 206 | * This function is meant to be as fast as possible and inlined into your 207 | * code. For that purpose, the function does not perform any sort of bounds 208 | * checking and it is the callers responsibility to ensure they are passing 209 | * valid input to the function. 210 | */ 211 | static BSON_INLINE void 212 | bson_oid_init_from_string_unsafe (bson_oid_t *oid, const char *str) 213 | { 214 | int i; 215 | 216 | for (i = 0; i < 12; i++) { 217 | oid->bytes[i] = (uint8_t) ((bson_oid_parse_hex_char (str[2 * i]) << 4) | 218 | (bson_oid_parse_hex_char (str[2 * i + 1]))); 219 | } 220 | } 221 | 222 | 223 | /** 224 | * bson_oid_get_time_t_unsafe: 225 | * @oid: A bson_oid_t. 226 | * 227 | * Fetches the time @oid was generated. 228 | * 229 | * Returns: A time_t containing the UNIX timestamp of generation. 230 | */ 231 | static BSON_INLINE time_t 232 | bson_oid_get_time_t_unsafe (const bson_oid_t *oid) 233 | { 234 | uint32_t t; 235 | 236 | memcpy (&t, oid, sizeof (t)); 237 | return BSON_UINT32_FROM_BE (t); 238 | } 239 | 240 | 241 | BSON_END_DECLS 242 | 243 | 244 | #endif /* BSON_OID_H */ 245 | -------------------------------------------------------------------------------- /src/thirdparty/libbson-1.0/bson/bson-prelude.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-present MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #if !defined(BSON_INSIDE) && !defined(BSON_COMPILATION) 18 | #error "Only can be included directly." 19 | #endif 20 | -------------------------------------------------------------------------------- /src/thirdparty/libbson-1.0/bson/bson-reader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "bson-prelude.h" 18 | 19 | 20 | #ifndef BSON_READER_H 21 | #define BSON_READER_H 22 | 23 | 24 | #include "bson-compat.h" 25 | #include "bson-oid.h" 26 | #include "bson-types.h" 27 | 28 | 29 | BSON_BEGIN_DECLS 30 | 31 | 32 | #define BSON_ERROR_READER_BADFD 1 33 | 34 | 35 | /* 36 | *-------------------------------------------------------------------------- 37 | * 38 | * bson_reader_read_func_t -- 39 | * 40 | * This function is a callback used by bson_reader_t to read the 41 | * next chunk of data from the underlying opaque file descriptor. 42 | * 43 | * This function is meant to operate similar to the read() function 44 | * as part of libc on UNIX-like systems. 45 | * 46 | * Parameters: 47 | * @handle: The handle to read from. 48 | * @buf: The buffer to read into. 49 | * @count: The number of bytes to read. 50 | * 51 | * Returns: 52 | * 0 for end of stream. 53 | * -1 for read failure. 54 | * Greater than zero for number of bytes read into @buf. 55 | * 56 | * Side effects: 57 | * None. 58 | * 59 | *-------------------------------------------------------------------------- 60 | */ 61 | 62 | typedef ssize_t (*bson_reader_read_func_t) (void *handle, /* IN */ 63 | void *buf, /* IN */ 64 | size_t count); /* IN */ 65 | 66 | 67 | /* 68 | *-------------------------------------------------------------------------- 69 | * 70 | * bson_reader_destroy_func_t -- 71 | * 72 | * Destroy callback to release any resources associated with the 73 | * opaque handle. 74 | * 75 | * Parameters: 76 | * @handle: the handle provided to bson_reader_new_from_handle(). 77 | * 78 | * Returns: 79 | * None. 80 | * 81 | * Side effects: 82 | * None. 83 | * 84 | *-------------------------------------------------------------------------- 85 | */ 86 | 87 | typedef void (*bson_reader_destroy_func_t) (void *handle); /* IN */ 88 | 89 | 90 | BSON_EXPORT (bson_reader_t *) 91 | bson_reader_new_from_handle (void *handle, 92 | bson_reader_read_func_t rf, 93 | bson_reader_destroy_func_t df); 94 | BSON_EXPORT (bson_reader_t *) 95 | bson_reader_new_from_fd (int fd, bool close_on_destroy); 96 | BSON_EXPORT (bson_reader_t *) 97 | bson_reader_new_from_file (const char *path, bson_error_t *error); 98 | BSON_EXPORT (bson_reader_t *) 99 | bson_reader_new_from_data (const uint8_t *data, size_t length); 100 | BSON_EXPORT (void) 101 | bson_reader_destroy (bson_reader_t *reader); 102 | BSON_EXPORT (void) 103 | bson_reader_set_read_func (bson_reader_t *reader, bson_reader_read_func_t func); 104 | BSON_EXPORT (void) 105 | bson_reader_set_destroy_func (bson_reader_t *reader, 106 | bson_reader_destroy_func_t func); 107 | BSON_EXPORT (const bson_t *) 108 | bson_reader_read (bson_reader_t *reader, bool *reached_eof); 109 | BSON_EXPORT (off_t) 110 | bson_reader_tell (bson_reader_t *reader); 111 | BSON_EXPORT (void) 112 | bson_reader_reset (bson_reader_t *reader); 113 | 114 | BSON_END_DECLS 115 | 116 | 117 | #endif /* BSON_READER_H */ 118 | -------------------------------------------------------------------------------- /src/thirdparty/libbson-1.0/bson/bson-string.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "bson-prelude.h" 18 | 19 | 20 | #ifndef BSON_STRING_H 21 | #define BSON_STRING_H 22 | 23 | 24 | #include 25 | 26 | #include "bson-macros.h" 27 | #include "bson-types.h" 28 | 29 | 30 | BSON_BEGIN_DECLS 31 | 32 | 33 | typedef struct { 34 | char *str; 35 | uint32_t len; 36 | uint32_t alloc; 37 | } bson_string_t; 38 | 39 | 40 | BSON_EXPORT (bson_string_t *) 41 | bson_string_new (const char *str); 42 | BSON_EXPORT (char *) 43 | bson_string_free (bson_string_t *string, bool free_segment); 44 | BSON_EXPORT (void) 45 | bson_string_append (bson_string_t *string, const char *str); 46 | BSON_EXPORT (void) 47 | bson_string_append_c (bson_string_t *string, char str); 48 | BSON_EXPORT (void) 49 | bson_string_append_unichar (bson_string_t *string, bson_unichar_t unichar); 50 | BSON_EXPORT (void) 51 | bson_string_append_printf (bson_string_t *string, const char *format, ...) 52 | BSON_GNUC_PRINTF (2, 3); 53 | BSON_EXPORT (void) 54 | bson_string_truncate (bson_string_t *string, uint32_t len); 55 | BSON_EXPORT (char *) 56 | bson_strdup (const char *str); 57 | BSON_EXPORT (char *) 58 | bson_strdup_printf (const char *format, ...) BSON_GNUC_PRINTF (1, 2); 59 | BSON_EXPORT (char *) 60 | bson_strdupv_printf (const char *format, va_list args) BSON_GNUC_PRINTF (1, 0); 61 | BSON_EXPORT (char *) 62 | bson_strndup (const char *str, size_t n_bytes); 63 | BSON_EXPORT (void) 64 | bson_strncpy (char *dst, const char *src, size_t size); 65 | BSON_EXPORT (int) 66 | bson_vsnprintf (char *str, size_t size, const char *format, va_list ap) 67 | BSON_GNUC_PRINTF (3, 0); 68 | BSON_EXPORT (int) 69 | bson_snprintf (char *str, size_t size, const char *format, ...) 70 | BSON_GNUC_PRINTF (3, 4); 71 | BSON_EXPORT (void) 72 | bson_strfreev (char **strv); 73 | BSON_EXPORT (size_t) 74 | bson_strnlen (const char *s, size_t maxlen); 75 | BSON_EXPORT (int64_t) 76 | bson_ascii_strtoll (const char *str, char **endptr, int base); 77 | BSON_EXPORT (int) 78 | bson_strcasecmp (const char *s1, const char *s2); 79 | BSON_EXPORT (bool) 80 | bson_isspace (int c); 81 | 82 | 83 | BSON_END_DECLS 84 | 85 | 86 | #endif /* BSON_STRING_H */ 87 | -------------------------------------------------------------------------------- /src/thirdparty/libbson-1.0/bson/bson-utf8.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "bson-prelude.h" 18 | 19 | 20 | #ifndef BSON_UTF8_H 21 | #define BSON_UTF8_H 22 | 23 | 24 | #include "bson-macros.h" 25 | #include "bson-types.h" 26 | 27 | 28 | BSON_BEGIN_DECLS 29 | 30 | 31 | BSON_EXPORT (bool) 32 | bson_utf8_validate (const char *utf8, size_t utf8_len, bool allow_null); 33 | BSON_EXPORT (char *) 34 | bson_utf8_escape_for_json (const char *utf8, ssize_t utf8_len); 35 | BSON_EXPORT (bson_unichar_t) 36 | bson_utf8_get_char (const char *utf8); 37 | BSON_EXPORT (const char *) 38 | bson_utf8_next_char (const char *utf8); 39 | BSON_EXPORT (void) 40 | bson_utf8_from_unichar (bson_unichar_t unichar, char utf8[6], uint32_t *len); 41 | 42 | 43 | BSON_END_DECLS 44 | 45 | 46 | #endif /* BSON_UTF8_H */ 47 | -------------------------------------------------------------------------------- /src/thirdparty/libbson-1.0/bson/bson-value.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "bson-prelude.h" 18 | 19 | 20 | #ifndef BSON_VALUE_H 21 | #define BSON_VALUE_H 22 | 23 | 24 | #include "bson-macros.h" 25 | #include "bson-types.h" 26 | 27 | 28 | BSON_BEGIN_DECLS 29 | 30 | 31 | BSON_EXPORT (void) 32 | bson_value_copy (const bson_value_t *src, bson_value_t *dst); 33 | BSON_EXPORT (void) 34 | bson_value_destroy (bson_value_t *value); 35 | 36 | 37 | BSON_END_DECLS 38 | 39 | 40 | #endif /* BSON_VALUE_H */ 41 | -------------------------------------------------------------------------------- /src/thirdparty/libbson-1.0/bson/bson-version-functions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | #include "bson-prelude.h" 19 | 20 | 21 | #ifndef BSON_VERSION_FUNCTIONS_H 22 | #define BSON_VERSION_FUNCTIONS_H 23 | 24 | #include "bson-types.h" 25 | 26 | BSON_BEGIN_DECLS 27 | 28 | BSON_EXPORT (int) 29 | bson_get_major_version (void); 30 | BSON_EXPORT (int) 31 | bson_get_minor_version (void); 32 | BSON_EXPORT (int) 33 | bson_get_micro_version (void); 34 | BSON_EXPORT (const char *) 35 | bson_get_version (void); 36 | BSON_EXPORT (bool) 37 | bson_check_version (int required_major, int required_minor, int required_micro); 38 | 39 | BSON_END_DECLS 40 | 41 | #endif /* BSON_VERSION_FUNCTIONS_H */ 42 | -------------------------------------------------------------------------------- /src/thirdparty/libbson-1.0/bson/bson-version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | #if !defined (BSON_INSIDE) && !defined (BSON_COMPILATION) 19 | #error "Only can be included directly." 20 | #endif 21 | 22 | 23 | #ifndef BSON_VERSION_H 24 | #define BSON_VERSION_H 25 | 26 | 27 | /** 28 | * BSON_MAJOR_VERSION: 29 | * 30 | * BSON major version component (e.g. 1 if %BSON_VERSION is 1.2.3) 31 | */ 32 | #define BSON_MAJOR_VERSION (1) 33 | 34 | 35 | /** 36 | * BSON_MINOR_VERSION: 37 | * 38 | * BSON minor version component (e.g. 2 if %BSON_VERSION is 1.2.3) 39 | */ 40 | #define BSON_MINOR_VERSION (21) 41 | 42 | 43 | /** 44 | * BSON_MICRO_VERSION: 45 | * 46 | * BSON micro version component (e.g. 3 if %BSON_VERSION is 1.2.3) 47 | */ 48 | #define BSON_MICRO_VERSION (0) 49 | 50 | 51 | /** 52 | * BSON_PRERELEASE_VERSION: 53 | * 54 | * BSON prerelease version component (e.g. pre if %BSON_VERSION is 1.2.3-pre) 55 | */ 56 | #define BSON_PRERELEASE_VERSION () 57 | 58 | /** 59 | * BSON_VERSION: 60 | * 61 | * BSON version. 62 | */ 63 | #define BSON_VERSION (1.21.0) 64 | 65 | 66 | /** 67 | * BSON_VERSION_S: 68 | * 69 | * BSON version, encoded as a string, useful for printing and 70 | * concatenation. 71 | */ 72 | #define BSON_VERSION_S "1.21.0" 73 | 74 | 75 | /** 76 | * BSON_VERSION_HEX: 77 | * 78 | * BSON version, encoded as an hexadecimal number, useful for 79 | * integer comparisons. 80 | */ 81 | #define BSON_VERSION_HEX (BSON_MAJOR_VERSION << 24 | \ 82 | BSON_MINOR_VERSION << 16 | \ 83 | BSON_MICRO_VERSION << 8) 84 | 85 | 86 | /** 87 | * BSON_CHECK_VERSION: 88 | * @major: required major version 89 | * @minor: required minor version 90 | * @micro: required micro version 91 | * 92 | * Compile-time version checking. Evaluates to %TRUE if the version 93 | * of BSON is greater than the required one. 94 | */ 95 | #define BSON_CHECK_VERSION(major,minor,micro) \ 96 | (BSON_MAJOR_VERSION > (major) || \ 97 | (BSON_MAJOR_VERSION == (major) && BSON_MINOR_VERSION > (minor)) || \ 98 | (BSON_MAJOR_VERSION == (major) && BSON_MINOR_VERSION == (minor) && \ 99 | BSON_MICRO_VERSION >= (micro))) 100 | 101 | #endif /* BSON_VERSION_H */ 102 | -------------------------------------------------------------------------------- /src/thirdparty/libbson-1.0/bson/bson-writer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "bson-prelude.h" 18 | 19 | 20 | #ifndef BSON_WRITER_H 21 | #define BSON_WRITER_H 22 | 23 | 24 | #include "bson.h" 25 | 26 | 27 | BSON_BEGIN_DECLS 28 | 29 | 30 | /** 31 | * bson_writer_t: 32 | * 33 | * The bson_writer_t structure is a helper for writing a series of BSON 34 | * documents to a single malloc() buffer. You can provide a realloc() style 35 | * function to grow the buffer as you go. 36 | * 37 | * This is useful if you want to build a series of BSON documents right into 38 | * the target buffer for an outgoing packet. The offset parameter allows you to 39 | * start at an offset of the target buffer. 40 | */ 41 | typedef struct _bson_writer_t bson_writer_t; 42 | 43 | 44 | BSON_EXPORT (bson_writer_t *) 45 | bson_writer_new (uint8_t **buf, 46 | size_t *buflen, 47 | size_t offset, 48 | bson_realloc_func realloc_func, 49 | void *realloc_func_ctx); 50 | BSON_EXPORT (void) 51 | bson_writer_destroy (bson_writer_t *writer); 52 | BSON_EXPORT (size_t) 53 | bson_writer_get_length (bson_writer_t *writer); 54 | BSON_EXPORT (bool) 55 | bson_writer_begin (bson_writer_t *writer, bson_t **bson); 56 | BSON_EXPORT (void) 57 | bson_writer_end (bson_writer_t *writer); 58 | BSON_EXPORT (void) 59 | bson_writer_rollback (bson_writer_t *writer); 60 | 61 | 62 | BSON_END_DECLS 63 | 64 | 65 | #endif /* BSON_WRITER_H */ 66 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-present MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* Including mongoc.h is superseded. Use mongoc/mongoc.h instead. */ 18 | #include "mongoc/mongoc.h" -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-change-stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-present MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_CHANGE_STREAM_H 20 | #define MONGOC_CHANGE_STREAM_H 21 | 22 | #include 23 | 24 | #include "mongoc-macros.h" 25 | 26 | BSON_BEGIN_DECLS 27 | 28 | typedef struct _mongoc_change_stream_t mongoc_change_stream_t; 29 | 30 | MONGOC_EXPORT (void) 31 | mongoc_change_stream_destroy (mongoc_change_stream_t *); 32 | 33 | MONGOC_EXPORT (const bson_t *) 34 | mongoc_change_stream_get_resume_token (mongoc_change_stream_t *); 35 | 36 | MONGOC_EXPORT (bool) 37 | mongoc_change_stream_next (mongoc_change_stream_t *, const bson_t **); 38 | 39 | MONGOC_EXPORT (bool) 40 | mongoc_change_stream_error_document (const mongoc_change_stream_t *, 41 | bson_error_t *, 42 | const bson_t **); 43 | 44 | BSON_END_DECLS 45 | 46 | #endif /* MONGOC_CHANGE_STREAM_H */ 47 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-client-pool.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_CLIENT_POOL_H 20 | #define MONGOC_CLIENT_POOL_H 21 | 22 | #include 23 | 24 | #include "mongoc-macros.h" 25 | #include "mongoc-apm.h" 26 | #include "mongoc-client.h" 27 | #include "mongoc-config.h" 28 | #ifdef MONGOC_ENABLE_SSL 29 | #include "mongoc-ssl.h" 30 | #endif 31 | #include "mongoc-uri.h" 32 | 33 | 34 | BSON_BEGIN_DECLS 35 | 36 | 37 | typedef struct _mongoc_client_pool_t mongoc_client_pool_t; 38 | 39 | 40 | MONGOC_EXPORT (mongoc_client_pool_t *) 41 | mongoc_client_pool_new (const mongoc_uri_t *uri) BSON_GNUC_WARN_UNUSED_RESULT; 42 | MONGOC_EXPORT (mongoc_client_pool_t *) 43 | mongoc_client_pool_new_with_error (const mongoc_uri_t *uri, bson_error_t *error) 44 | BSON_GNUC_WARN_UNUSED_RESULT; 45 | MONGOC_EXPORT (void) 46 | mongoc_client_pool_destroy (mongoc_client_pool_t *pool); 47 | MONGOC_EXPORT (mongoc_client_t *) 48 | mongoc_client_pool_pop (mongoc_client_pool_t *pool) 49 | BSON_GNUC_WARN_UNUSED_RESULT; 50 | MONGOC_EXPORT (void) 51 | mongoc_client_pool_push (mongoc_client_pool_t *pool, mongoc_client_t *client); 52 | MONGOC_EXPORT (mongoc_client_t *) 53 | mongoc_client_pool_try_pop (mongoc_client_pool_t *pool) 54 | BSON_GNUC_WARN_UNUSED_RESULT; 55 | MONGOC_EXPORT (void) 56 | mongoc_client_pool_max_size (mongoc_client_pool_t *pool, 57 | uint32_t max_pool_size); 58 | MONGOC_EXPORT (void) 59 | mongoc_client_pool_min_size (mongoc_client_pool_t *pool, 60 | uint32_t min_pool_size) BSON_GNUC_DEPRECATED; 61 | #ifdef MONGOC_ENABLE_SSL 62 | MONGOC_EXPORT (void) 63 | mongoc_client_pool_set_ssl_opts (mongoc_client_pool_t *pool, 64 | const mongoc_ssl_opt_t *opts); 65 | #endif 66 | MONGOC_EXPORT (bool) 67 | mongoc_client_pool_set_apm_callbacks (mongoc_client_pool_t *pool, 68 | mongoc_apm_callbacks_t *callbacks, 69 | void *context); 70 | MONGOC_EXPORT (bool) 71 | mongoc_client_pool_set_error_api (mongoc_client_pool_t *pool, int32_t version); 72 | MONGOC_EXPORT (bool) 73 | mongoc_client_pool_set_appname (mongoc_client_pool_t *pool, 74 | const char *appname); 75 | MONGOC_EXPORT (bool) 76 | mongoc_client_pool_enable_auto_encryption (mongoc_client_pool_t *pool, 77 | mongoc_auto_encryption_opts_t *opts, 78 | bson_error_t *error); 79 | MONGOC_EXPORT (bool) 80 | mongoc_client_pool_set_server_api (mongoc_client_pool_t *pool, 81 | const mongoc_server_api_t *api, 82 | bson_error_t *error); 83 | 84 | BSON_END_DECLS 85 | 86 | 87 | #endif /* MONGOC_CLIENT_POOL_H */ 88 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-client-side-encryption.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-present MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_CLIENT_SIDE_ENCRYPTION_H 20 | #define MONGOC_CLIENT_SIDE_ENCRYPTION_H 21 | 22 | #include 23 | 24 | /* Forward declare */ 25 | struct _mongoc_client_t; 26 | struct _mongoc_client_pool_t; 27 | 28 | #define MONGOC_AEAD_AES_256_CBC_HMAC_SHA_512_RANDOM \ 29 | "AEAD_AES_256_CBC_HMAC_SHA_512-Random" 30 | #define MONGOC_AEAD_AES_256_CBC_HMAC_SHA_512_DETERMINISTIC \ 31 | "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic" 32 | 33 | BSON_BEGIN_DECLS 34 | 35 | typedef struct _mongoc_auto_encryption_opts_t mongoc_auto_encryption_opts_t; 36 | 37 | MONGOC_EXPORT (mongoc_auto_encryption_opts_t *) 38 | mongoc_auto_encryption_opts_new (void) BSON_GNUC_WARN_UNUSED_RESULT; 39 | 40 | MONGOC_EXPORT (void) 41 | mongoc_auto_encryption_opts_destroy (mongoc_auto_encryption_opts_t *opts); 42 | 43 | MONGOC_EXPORT (void) 44 | mongoc_auto_encryption_opts_set_keyvault_client ( 45 | mongoc_auto_encryption_opts_t *opts, struct _mongoc_client_t *client); 46 | 47 | MONGOC_EXPORT (void) 48 | mongoc_auto_encryption_opts_set_keyvault_client_pool ( 49 | mongoc_auto_encryption_opts_t *opts, struct _mongoc_client_pool_t *pool); 50 | 51 | MONGOC_EXPORT (void) 52 | mongoc_auto_encryption_opts_set_keyvault_namespace ( 53 | mongoc_auto_encryption_opts_t *opts, const char *db, const char *coll); 54 | 55 | MONGOC_EXPORT (void) 56 | mongoc_auto_encryption_opts_set_kms_providers ( 57 | mongoc_auto_encryption_opts_t *opts, const bson_t *kms_providers); 58 | 59 | MONGOC_EXPORT (void) 60 | mongoc_auto_encryption_opts_set_tls_opts (mongoc_auto_encryption_opts_t *opts, 61 | const bson_t *tls_opts); 62 | 63 | MONGOC_EXPORT (void) 64 | mongoc_auto_encryption_opts_set_schema_map (mongoc_auto_encryption_opts_t *opts, 65 | const bson_t *schema_map); 66 | 67 | MONGOC_EXPORT (void) 68 | mongoc_auto_encryption_opts_set_bypass_auto_encryption ( 69 | mongoc_auto_encryption_opts_t *opts, bool bypass_auto_encryption); 70 | 71 | MONGOC_EXPORT (void) 72 | mongoc_auto_encryption_opts_set_extra (mongoc_auto_encryption_opts_t *opts, 73 | const bson_t *extra); 74 | 75 | typedef struct _mongoc_client_encryption_opts_t mongoc_client_encryption_opts_t; 76 | typedef struct _mongoc_client_encryption_t mongoc_client_encryption_t; 77 | typedef struct _mongoc_client_encryption_encrypt_opts_t 78 | mongoc_client_encryption_encrypt_opts_t; 79 | typedef struct _mongoc_client_encryption_datakey_opts_t 80 | mongoc_client_encryption_datakey_opts_t; 81 | 82 | MONGOC_EXPORT (mongoc_client_encryption_opts_t *) 83 | mongoc_client_encryption_opts_new (void) BSON_GNUC_WARN_UNUSED_RESULT; 84 | 85 | MONGOC_EXPORT (void) 86 | mongoc_client_encryption_opts_destroy (mongoc_client_encryption_opts_t *opts); 87 | 88 | MONGOC_EXPORT (void) 89 | mongoc_client_encryption_opts_set_keyvault_client ( 90 | mongoc_client_encryption_opts_t *opts, 91 | struct _mongoc_client_t *keyvault_client); 92 | 93 | MONGOC_EXPORT (void) 94 | mongoc_client_encryption_opts_set_keyvault_namespace ( 95 | mongoc_client_encryption_opts_t *opts, const char *db, const char *coll); 96 | 97 | MONGOC_EXPORT (void) 98 | mongoc_client_encryption_opts_set_kms_providers ( 99 | mongoc_client_encryption_opts_t *opts, const bson_t *kms_providers); 100 | 101 | MONGOC_EXPORT (void) 102 | mongoc_client_encryption_opts_set_tls_opts ( 103 | mongoc_client_encryption_opts_t *opts, const bson_t *tls_opts); 104 | 105 | MONGOC_EXPORT (mongoc_client_encryption_t *) 106 | mongoc_client_encryption_new (mongoc_client_encryption_opts_t *opts, 107 | bson_error_t *error) BSON_GNUC_WARN_UNUSED_RESULT; 108 | 109 | MONGOC_EXPORT (void) 110 | mongoc_client_encryption_destroy ( 111 | mongoc_client_encryption_t *client_encryption); 112 | 113 | MONGOC_EXPORT (bool) 114 | mongoc_client_encryption_create_datakey ( 115 | mongoc_client_encryption_t *client_encryption, 116 | const char *kms_provider, 117 | mongoc_client_encryption_datakey_opts_t *opts, 118 | bson_value_t *keyid, 119 | bson_error_t *error); 120 | 121 | MONGOC_EXPORT (bool) 122 | mongoc_client_encryption_encrypt (mongoc_client_encryption_t *client_encryption, 123 | const bson_value_t *value, 124 | mongoc_client_encryption_encrypt_opts_t *opts, 125 | bson_value_t *ciphertext, 126 | bson_error_t *error); 127 | 128 | MONGOC_EXPORT (bool) 129 | mongoc_client_encryption_decrypt (mongoc_client_encryption_t *client_encryption, 130 | const bson_value_t *ciphertext, 131 | bson_value_t *value, 132 | bson_error_t *error); 133 | 134 | MONGOC_EXPORT (mongoc_client_encryption_encrypt_opts_t *) 135 | mongoc_client_encryption_encrypt_opts_new (void) BSON_GNUC_WARN_UNUSED_RESULT; 136 | 137 | MONGOC_EXPORT (void) 138 | mongoc_client_encryption_encrypt_opts_destroy ( 139 | mongoc_client_encryption_encrypt_opts_t *opts); 140 | 141 | MONGOC_EXPORT (void) 142 | mongoc_client_encryption_encrypt_opts_set_keyid ( 143 | mongoc_client_encryption_encrypt_opts_t *opts, const bson_value_t *keyid); 144 | 145 | MONGOC_EXPORT (void) 146 | mongoc_client_encryption_encrypt_opts_set_keyaltname ( 147 | mongoc_client_encryption_encrypt_opts_t *opts, const char *keyaltname); 148 | 149 | MONGOC_EXPORT (void) 150 | mongoc_client_encryption_encrypt_opts_set_algorithm ( 151 | mongoc_client_encryption_encrypt_opts_t *opts, const char *algorithm); 152 | 153 | MONGOC_EXPORT (mongoc_client_encryption_datakey_opts_t *) 154 | mongoc_client_encryption_datakey_opts_new (void) BSON_GNUC_WARN_UNUSED_RESULT; 155 | 156 | MONGOC_EXPORT (void) 157 | mongoc_client_encryption_datakey_opts_destroy ( 158 | mongoc_client_encryption_datakey_opts_t *opts); 159 | 160 | MONGOC_EXPORT (void) 161 | mongoc_client_encryption_datakey_opts_set_masterkey ( 162 | mongoc_client_encryption_datakey_opts_t *opts, const bson_t *masterkey); 163 | 164 | MONGOC_EXPORT (void) 165 | mongoc_client_encryption_datakey_opts_set_keyaltnames ( 166 | mongoc_client_encryption_datakey_opts_t *opts, 167 | char **keyaltnames, 168 | uint32_t keyaltnames_count); 169 | 170 | BSON_END_DECLS 171 | 172 | #endif /* MONGOC_CLIENT_SIDE_ENCRYPTION_H */ 173 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-cursor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_CURSOR_H 20 | #define MONGOC_CURSOR_H 21 | 22 | #include 23 | 24 | #include "mongoc-macros.h" 25 | #include "mongoc-host-list.h" 26 | 27 | 28 | BSON_BEGIN_DECLS 29 | 30 | typedef struct _mongoc_cursor_t mongoc_cursor_t; 31 | 32 | 33 | /* forward decl */ 34 | struct _mongoc_client_t; 35 | 36 | MONGOC_EXPORT (mongoc_cursor_t *) 37 | mongoc_cursor_clone (const mongoc_cursor_t *cursor) 38 | BSON_GNUC_WARN_UNUSED_RESULT; 39 | MONGOC_EXPORT (void) 40 | mongoc_cursor_destroy (mongoc_cursor_t *cursor); 41 | MONGOC_EXPORT (bool) 42 | mongoc_cursor_more (mongoc_cursor_t *cursor); 43 | MONGOC_EXPORT (bool) 44 | mongoc_cursor_next (mongoc_cursor_t *cursor, const bson_t **bson); 45 | MONGOC_EXPORT (bool) 46 | mongoc_cursor_error (mongoc_cursor_t *cursor, bson_error_t *error); 47 | MONGOC_EXPORT (bool) 48 | mongoc_cursor_error_document (mongoc_cursor_t *cursor, 49 | bson_error_t *error, 50 | const bson_t **doc); 51 | MONGOC_EXPORT (void) 52 | mongoc_cursor_get_host (mongoc_cursor_t *cursor, mongoc_host_list_t *host); 53 | MONGOC_EXPORT (bool) 54 | mongoc_cursor_is_alive (const mongoc_cursor_t *cursor) 55 | BSON_GNUC_DEPRECATED_FOR (mongoc_cursor_more); 56 | MONGOC_EXPORT (const bson_t *) 57 | mongoc_cursor_current (const mongoc_cursor_t *cursor); 58 | MONGOC_EXPORT (void) 59 | mongoc_cursor_set_batch_size (mongoc_cursor_t *cursor, uint32_t batch_size); 60 | MONGOC_EXPORT (uint32_t) 61 | mongoc_cursor_get_batch_size (const mongoc_cursor_t *cursor); 62 | MONGOC_EXPORT (bool) 63 | mongoc_cursor_set_limit (mongoc_cursor_t *cursor, int64_t limit); 64 | MONGOC_EXPORT (int64_t) 65 | mongoc_cursor_get_limit (const mongoc_cursor_t *cursor); 66 | /* These names include the term "hint" for backward compatibility, should be 67 | * mongoc_cursor_get_server_id, mongoc_cursor_set_server_id. */ 68 | MONGOC_EXPORT (bool) 69 | mongoc_cursor_set_hint (mongoc_cursor_t *cursor, uint32_t server_id); 70 | MONGOC_EXPORT (uint32_t) 71 | mongoc_cursor_get_hint (const mongoc_cursor_t *cursor); 72 | MONGOC_EXPORT (int64_t) 73 | mongoc_cursor_get_id (const mongoc_cursor_t *cursor); 74 | MONGOC_EXPORT (void) 75 | mongoc_cursor_set_max_await_time_ms (mongoc_cursor_t *cursor, 76 | uint32_t max_await_time_ms); 77 | MONGOC_EXPORT (uint32_t) 78 | mongoc_cursor_get_max_await_time_ms (const mongoc_cursor_t *cursor); 79 | MONGOC_EXPORT (mongoc_cursor_t *) 80 | mongoc_cursor_new_from_command_reply (struct _mongoc_client_t *client, 81 | bson_t *reply, 82 | uint32_t server_id) 83 | BSON_GNUC_WARN_UNUSED_RESULT 84 | BSON_GNUC_DEPRECATED_FOR (mongoc_cursor_new_from_command_reply_with_opts); 85 | MONGOC_EXPORT (mongoc_cursor_t *) 86 | mongoc_cursor_new_from_command_reply_with_opts (struct _mongoc_client_t *client, 87 | bson_t *reply, 88 | const bson_t *opts) 89 | BSON_GNUC_WARN_UNUSED_RESULT; 90 | 91 | BSON_END_DECLS 92 | 93 | 94 | #endif /* MONGOC_CURSOR_H */ 95 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-error.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_ERRORS_H 20 | #define MONGOC_ERRORS_H 21 | 22 | #include 23 | 24 | #include "mongoc-macros.h" 25 | 26 | #define MONGOC_ERROR_API_VERSION_LEGACY 1 27 | #define MONGOC_ERROR_API_VERSION_2 2 28 | 29 | BSON_BEGIN_DECLS 30 | 31 | 32 | typedef enum { 33 | MONGOC_ERROR_CLIENT = 1, 34 | MONGOC_ERROR_STREAM, 35 | MONGOC_ERROR_PROTOCOL, 36 | MONGOC_ERROR_CURSOR, 37 | MONGOC_ERROR_QUERY, 38 | MONGOC_ERROR_INSERT, 39 | MONGOC_ERROR_SASL, 40 | MONGOC_ERROR_BSON, 41 | MONGOC_ERROR_MATCHER, 42 | MONGOC_ERROR_NAMESPACE, 43 | MONGOC_ERROR_COMMAND, 44 | MONGOC_ERROR_COLLECTION, 45 | MONGOC_ERROR_GRIDFS, 46 | MONGOC_ERROR_SCRAM, 47 | MONGOC_ERROR_SERVER_SELECTION, 48 | MONGOC_ERROR_WRITE_CONCERN, 49 | MONGOC_ERROR_SERVER, /* Error API Version 2 only */ 50 | MONGOC_ERROR_TRANSACTION, 51 | MONGOC_ERROR_CLIENT_SIDE_ENCRYPTION, /* An error coming from libmongocrypt */ 52 | MONGOC_ERROR_POOL 53 | } mongoc_error_domain_t; 54 | 55 | 56 | typedef enum { 57 | MONGOC_ERROR_STREAM_INVALID_TYPE = 1, 58 | MONGOC_ERROR_STREAM_INVALID_STATE, 59 | MONGOC_ERROR_STREAM_NAME_RESOLUTION, 60 | MONGOC_ERROR_STREAM_SOCKET, 61 | MONGOC_ERROR_STREAM_CONNECT, 62 | MONGOC_ERROR_STREAM_NOT_ESTABLISHED, 63 | 64 | MONGOC_ERROR_CLIENT_NOT_READY, 65 | MONGOC_ERROR_CLIENT_TOO_BIG, 66 | MONGOC_ERROR_CLIENT_TOO_SMALL, 67 | MONGOC_ERROR_CLIENT_GETNONCE, 68 | MONGOC_ERROR_CLIENT_AUTHENTICATE, 69 | MONGOC_ERROR_CLIENT_NO_ACCEPTABLE_PEER, 70 | MONGOC_ERROR_CLIENT_IN_EXHAUST, 71 | 72 | MONGOC_ERROR_PROTOCOL_INVALID_REPLY, 73 | MONGOC_ERROR_PROTOCOL_BAD_WIRE_VERSION, 74 | 75 | MONGOC_ERROR_CURSOR_INVALID_CURSOR, 76 | 77 | MONGOC_ERROR_QUERY_FAILURE, 78 | 79 | MONGOC_ERROR_BSON_INVALID, 80 | 81 | MONGOC_ERROR_MATCHER_INVALID, 82 | 83 | MONGOC_ERROR_NAMESPACE_INVALID, 84 | MONGOC_ERROR_NAMESPACE_INVALID_FILTER_TYPE, 85 | 86 | MONGOC_ERROR_COMMAND_INVALID_ARG, 87 | 88 | MONGOC_ERROR_COLLECTION_INSERT_FAILED, 89 | MONGOC_ERROR_COLLECTION_UPDATE_FAILED, 90 | MONGOC_ERROR_COLLECTION_DELETE_FAILED, 91 | MONGOC_ERROR_COLLECTION_DOES_NOT_EXIST = 26, 92 | 93 | MONGOC_ERROR_GRIDFS_INVALID_FILENAME, 94 | 95 | MONGOC_ERROR_SCRAM_NOT_DONE, 96 | MONGOC_ERROR_SCRAM_PROTOCOL_ERROR, 97 | 98 | MONGOC_ERROR_QUERY_COMMAND_NOT_FOUND = 59, 99 | MONGOC_ERROR_QUERY_NOT_TAILABLE = 13051, 100 | 101 | MONGOC_ERROR_SERVER_SELECTION_BAD_WIRE_VERSION, 102 | MONGOC_ERROR_SERVER_SELECTION_FAILURE, 103 | MONGOC_ERROR_SERVER_SELECTION_INVALID_ID, 104 | 105 | MONGOC_ERROR_GRIDFS_CHUNK_MISSING, 106 | MONGOC_ERROR_GRIDFS_PROTOCOL_ERROR, 107 | 108 | /* Dup with query failure. */ 109 | MONGOC_ERROR_PROTOCOL_ERROR = 17, 110 | 111 | MONGOC_ERROR_WRITE_CONCERN_ERROR = 64, 112 | 113 | MONGOC_ERROR_DUPLICATE_KEY = 11000, 114 | 115 | MONGOC_ERROR_MAX_TIME_MS_EXPIRED = 50, 116 | 117 | MONGOC_ERROR_CHANGE_STREAM_NO_RESUME_TOKEN, 118 | MONGOC_ERROR_CLIENT_SESSION_FAILURE, 119 | MONGOC_ERROR_TRANSACTION_INVALID_STATE, 120 | MONGOC_ERROR_GRIDFS_CORRUPT, 121 | MONGOC_ERROR_GRIDFS_BUCKET_FILE_NOT_FOUND, 122 | MONGOC_ERROR_GRIDFS_BUCKET_STREAM, 123 | 124 | /* An error related to initializing client side encryption. */ 125 | MONGOC_ERROR_CLIENT_INVALID_ENCRYPTION_STATE, 126 | 127 | MONGOC_ERROR_CLIENT_INVALID_ENCRYPTION_ARG, 128 | 129 | 130 | /* An error related to server version api */ 131 | MONGOC_ERROR_CLIENT_API_ALREADY_SET, 132 | MONGOC_ERROR_CLIENT_API_FROM_POOL, 133 | MONGOC_ERROR_POOL_API_ALREADY_SET, 134 | MONGOC_ERROR_POOL_API_TOO_LATE, 135 | 136 | MONGOC_ERROR_CLIENT_INVALID_LOAD_BALANCER, 137 | } mongoc_error_code_t; 138 | 139 | MONGOC_EXPORT (bool) 140 | mongoc_error_has_label (const bson_t *reply, const char *label); 141 | 142 | BSON_END_DECLS 143 | 144 | 145 | #endif /* MONGOC_ERRORS_H */ 146 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-find-and-modify.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_FIND_AND_MODIFY_H 20 | #define MONGOC_FIND_AND_MODIFY_H 21 | 22 | #include 23 | 24 | #include "mongoc-macros.h" 25 | 26 | BSON_BEGIN_DECLS 27 | 28 | typedef enum { 29 | MONGOC_FIND_AND_MODIFY_NONE = 0, 30 | MONGOC_FIND_AND_MODIFY_REMOVE = 1 << 0, 31 | MONGOC_FIND_AND_MODIFY_UPSERT = 1 << 1, 32 | MONGOC_FIND_AND_MODIFY_RETURN_NEW = 1 << 2, 33 | } mongoc_find_and_modify_flags_t; 34 | 35 | typedef struct _mongoc_find_and_modify_opts_t mongoc_find_and_modify_opts_t; 36 | 37 | MONGOC_EXPORT (mongoc_find_and_modify_opts_t *) 38 | mongoc_find_and_modify_opts_new (void) BSON_GNUC_WARN_UNUSED_RESULT; 39 | 40 | MONGOC_EXPORT (bool) 41 | mongoc_find_and_modify_opts_set_sort (mongoc_find_and_modify_opts_t *opts, 42 | const bson_t *sort); 43 | 44 | MONGOC_EXPORT (void) 45 | mongoc_find_and_modify_opts_get_sort (const mongoc_find_and_modify_opts_t *opts, 46 | bson_t *sort); 47 | 48 | MONGOC_EXPORT (bool) 49 | mongoc_find_and_modify_opts_set_update (mongoc_find_and_modify_opts_t *opts, 50 | const bson_t *update); 51 | 52 | MONGOC_EXPORT (void) 53 | mongoc_find_and_modify_opts_get_update ( 54 | const mongoc_find_and_modify_opts_t *opts, bson_t *update); 55 | 56 | MONGOC_EXPORT (bool) 57 | mongoc_find_and_modify_opts_set_fields (mongoc_find_and_modify_opts_t *opts, 58 | const bson_t *fields); 59 | 60 | MONGOC_EXPORT (void) 61 | mongoc_find_and_modify_opts_get_fields ( 62 | const mongoc_find_and_modify_opts_t *opts, bson_t *fields); 63 | 64 | MONGOC_EXPORT (bool) 65 | mongoc_find_and_modify_opts_set_flags ( 66 | mongoc_find_and_modify_opts_t *opts, 67 | const mongoc_find_and_modify_flags_t flags); 68 | 69 | MONGOC_EXPORT (mongoc_find_and_modify_flags_t) 70 | mongoc_find_and_modify_opts_get_flags ( 71 | const mongoc_find_and_modify_opts_t *opts); 72 | 73 | MONGOC_EXPORT (bool) 74 | mongoc_find_and_modify_opts_set_bypass_document_validation ( 75 | mongoc_find_and_modify_opts_t *opts, bool bypass); 76 | 77 | MONGOC_EXPORT (bool) 78 | mongoc_find_and_modify_opts_get_bypass_document_validation ( 79 | const mongoc_find_and_modify_opts_t *opts); 80 | 81 | MONGOC_EXPORT (bool) 82 | mongoc_find_and_modify_opts_set_max_time_ms ( 83 | mongoc_find_and_modify_opts_t *opts, uint32_t max_time_ms); 84 | 85 | MONGOC_EXPORT (uint32_t) 86 | mongoc_find_and_modify_opts_get_max_time_ms ( 87 | const mongoc_find_and_modify_opts_t *opts); 88 | 89 | MONGOC_EXPORT (bool) 90 | mongoc_find_and_modify_opts_append (mongoc_find_and_modify_opts_t *opts, 91 | const bson_t *extra); 92 | 93 | MONGOC_EXPORT (void) 94 | mongoc_find_and_modify_opts_get_extra ( 95 | const mongoc_find_and_modify_opts_t *opts, bson_t *extra); 96 | 97 | MONGOC_EXPORT (void) 98 | mongoc_find_and_modify_opts_destroy (mongoc_find_and_modify_opts_t *opts); 99 | 100 | BSON_END_DECLS 101 | 102 | 103 | #endif /* MONGOC_FIND_AND_MODIFY_H */ 104 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-flags.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_FLAGS_H 20 | #define MONGOC_FLAGS_H 21 | 22 | #include 23 | 24 | 25 | BSON_BEGIN_DECLS 26 | 27 | 28 | /** 29 | * mongoc_delete_flags_t: 30 | * @MONGOC_DELETE_NONE: Specify no delete flags. 31 | * @MONGOC_DELETE_SINGLE_REMOVE: Only remove the first document matching the 32 | * document selector. 33 | * 34 | * This type is only for use with deprecated functions and should not be 35 | * used in new code. Use mongoc_remove_flags_t instead. 36 | * 37 | * #mongoc_delete_flags_t are used when performing a delete operation. 38 | */ 39 | typedef enum { 40 | MONGOC_DELETE_NONE = 0, 41 | MONGOC_DELETE_SINGLE_REMOVE = 1 << 0, 42 | } mongoc_delete_flags_t; 43 | 44 | 45 | /** 46 | * mongoc_remove_flags_t: 47 | * @MONGOC_REMOVE_NONE: Specify no delete flags. 48 | * @MONGOC_REMOVE_SINGLE_REMOVE: Only remove the first document matching the 49 | * document selector. 50 | * 51 | * #mongoc_remove_flags_t are used when performing a remove operation. 52 | */ 53 | typedef enum { 54 | MONGOC_REMOVE_NONE = 0, 55 | MONGOC_REMOVE_SINGLE_REMOVE = 1 << 0, 56 | } mongoc_remove_flags_t; 57 | 58 | 59 | /** 60 | * mongoc_insert_flags_t: 61 | * @MONGOC_INSERT_NONE: Specify no insert flags. 62 | * @MONGOC_INSERT_CONTINUE_ON_ERROR: Continue inserting documents from 63 | * the insertion set even if one fails. 64 | * 65 | * #mongoc_insert_flags_t are used when performing an insert operation. 66 | */ 67 | typedef enum { 68 | MONGOC_INSERT_NONE = 0, 69 | MONGOC_INSERT_CONTINUE_ON_ERROR = 1 << 0, 70 | } mongoc_insert_flags_t; 71 | 72 | 73 | #define MONGOC_INSERT_NO_VALIDATE (1U << 31) 74 | 75 | 76 | /** 77 | * mongoc_query_flags_t: 78 | * @MONGOC_QUERY_NONE: No query flags supplied. 79 | * @MONGOC_QUERY_TAILABLE_CURSOR: Cursor will not be closed when the last 80 | * data is retrieved. You can resume this cursor later. 81 | * @MONGOC_QUERY_SECONDARY_OK: Allow query of secondaries in a replica set. 82 | * @MONGOC_QUERY_OPLOG_REPLAY: Used internally by Mongo. 83 | * @MONGOC_QUERY_NO_CURSOR_TIMEOUT: The server normally times out idle 84 | * cursors after an inactivity period (10 minutes). This prevents that. 85 | * @MONGOC_QUERY_AWAIT_DATA: Use with %MONGOC_QUERY_TAILABLE_CURSOR. Block 86 | * rather than returning no data. After a period, time out. 87 | * @MONGOC_QUERY_EXHAUST: Stream the data down full blast in multiple 88 | * "more" packages. Faster when you are pulling a lot of data and 89 | * know you want to pull it all down. 90 | * @MONGOC_QUERY_PARTIAL: Get partial results from mongos if some shards 91 | * are down (instead of throwing an error). 92 | * 93 | * #mongoc_query_flags_t is used for querying a Mongo instance. 94 | */ 95 | typedef enum { 96 | MONGOC_QUERY_NONE = 0, 97 | MONGOC_QUERY_TAILABLE_CURSOR = 1 << 1, 98 | MONGOC_QUERY_SLAVE_OK = 1 << 2, 99 | MONGOC_QUERY_SECONDARY_OK = 1 << 2, 100 | MONGOC_QUERY_OPLOG_REPLAY = 1 << 3, 101 | MONGOC_QUERY_NO_CURSOR_TIMEOUT = 1 << 4, 102 | MONGOC_QUERY_AWAIT_DATA = 1 << 5, 103 | MONGOC_QUERY_EXHAUST = 1 << 6, 104 | MONGOC_QUERY_PARTIAL = 1 << 7, 105 | } mongoc_query_flags_t; 106 | 107 | 108 | /** 109 | * mongoc_reply_flags_t: 110 | * @MONGOC_REPLY_NONE: No flags set. 111 | * @MONGOC_REPLY_CURSOR_NOT_FOUND: Cursor was not found. 112 | * @MONGOC_REPLY_QUERY_FAILURE: Query failed, error document provided. 113 | * @MONGOC_REPLY_SHARD_CONFIG_STALE: Shard configuration is stale. 114 | * @MONGOC_REPLY_AWAIT_CAPABLE: Wait for data to be returned until timeout 115 | * has passed. Used with %MONGOC_QUERY_TAILABLE_CURSOR. 116 | * 117 | * #mongoc_reply_flags_t contains flags supplied by the Mongo server in reply 118 | * to a request. 119 | */ 120 | typedef enum { 121 | MONGOC_REPLY_NONE = 0, 122 | MONGOC_REPLY_CURSOR_NOT_FOUND = 1 << 0, 123 | MONGOC_REPLY_QUERY_FAILURE = 1 << 1, 124 | MONGOC_REPLY_SHARD_CONFIG_STALE = 1 << 2, 125 | MONGOC_REPLY_AWAIT_CAPABLE = 1 << 3, 126 | } mongoc_reply_flags_t; 127 | 128 | 129 | /** 130 | * mongoc_update_flags_t: 131 | * @MONGOC_UPDATE_NONE: No update flags specified. 132 | * @MONGOC_UPDATE_UPSERT: Perform an upsert. 133 | * @MONGOC_UPDATE_MULTI_UPDATE: Continue updating after first match. 134 | * 135 | * #mongoc_update_flags_t is used when updating documents found in Mongo. 136 | */ 137 | typedef enum { 138 | MONGOC_UPDATE_NONE = 0, 139 | MONGOC_UPDATE_UPSERT = 1 << 0, 140 | MONGOC_UPDATE_MULTI_UPDATE = 1 << 1, 141 | } mongoc_update_flags_t; 142 | 143 | 144 | #define MONGOC_UPDATE_NO_VALIDATE (1U << 31) 145 | 146 | BSON_END_DECLS 147 | 148 | 149 | #endif /* MONGOC_FLAGS_H */ 150 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-gridfs-bucket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-present MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_GRIDFS_BUCKET_H 20 | #define MONGOC_GRIDFS_BUCKET_H 21 | 22 | #include "bson/bson.h" 23 | #include "mongoc-collection.h" 24 | #include "mongoc-database.h" 25 | #include "mongoc-stream.h" 26 | 27 | BSON_BEGIN_DECLS 28 | 29 | typedef struct _mongoc_gridfs_bucket_t mongoc_gridfs_bucket_t; 30 | 31 | MONGOC_EXPORT (mongoc_gridfs_bucket_t *) 32 | mongoc_gridfs_bucket_new (mongoc_database_t *db, 33 | const bson_t *opts, 34 | const mongoc_read_prefs_t *read_prefs, 35 | bson_error_t *error) BSON_GNUC_WARN_UNUSED_RESULT; 36 | 37 | MONGOC_EXPORT (mongoc_stream_t *) 38 | mongoc_gridfs_bucket_open_upload_stream (mongoc_gridfs_bucket_t *bucket, 39 | const char *filename, 40 | const bson_t *opts, 41 | bson_value_t *file_id, 42 | bson_error_t *error) 43 | BSON_GNUC_WARN_UNUSED_RESULT; 44 | 45 | MONGOC_EXPORT (mongoc_stream_t *) 46 | mongoc_gridfs_bucket_open_upload_stream_with_id (mongoc_gridfs_bucket_t *bucket, 47 | const bson_value_t *file_id, 48 | const char *filename, 49 | const bson_t *opts, 50 | bson_error_t *error) 51 | BSON_GNUC_WARN_UNUSED_RESULT; 52 | 53 | MONGOC_EXPORT (bool) 54 | mongoc_gridfs_bucket_upload_from_stream (mongoc_gridfs_bucket_t *bucket, 55 | const char *filename, 56 | mongoc_stream_t *source, 57 | const bson_t *opts, 58 | bson_value_t *file_id, 59 | bson_error_t *error); 60 | 61 | MONGOC_EXPORT (bool) 62 | mongoc_gridfs_bucket_upload_from_stream_with_id (mongoc_gridfs_bucket_t *bucket, 63 | const bson_value_t *file_id, 64 | const char *filename, 65 | mongoc_stream_t *source, 66 | const bson_t *opts, 67 | bson_error_t *error); 68 | 69 | MONGOC_EXPORT (mongoc_stream_t *) 70 | mongoc_gridfs_bucket_open_download_stream (mongoc_gridfs_bucket_t *bucket, 71 | const bson_value_t *file_id, 72 | bson_error_t *error) 73 | BSON_GNUC_WARN_UNUSED_RESULT; 74 | 75 | MONGOC_EXPORT (bool) 76 | mongoc_gridfs_bucket_download_to_stream (mongoc_gridfs_bucket_t *bucket, 77 | const bson_value_t *file_id, 78 | mongoc_stream_t *destination, 79 | bson_error_t *error); 80 | 81 | MONGOC_EXPORT (bool) 82 | mongoc_gridfs_bucket_delete_by_id (mongoc_gridfs_bucket_t *bucket, 83 | const bson_value_t *file_id, 84 | bson_error_t *error); 85 | 86 | MONGOC_EXPORT (mongoc_cursor_t *) 87 | mongoc_gridfs_bucket_find (mongoc_gridfs_bucket_t *bucket, 88 | const bson_t *filter, 89 | const bson_t *opts) BSON_GNUC_WARN_UNUSED_RESULT; 90 | 91 | MONGOC_EXPORT (bool) 92 | mongoc_gridfs_bucket_stream_error (mongoc_stream_t *stream, 93 | bson_error_t *error); 94 | 95 | MONGOC_EXPORT (void) 96 | mongoc_gridfs_bucket_destroy (mongoc_gridfs_bucket_t *bucket); 97 | 98 | MONGOC_EXPORT (bool) 99 | mongoc_gridfs_bucket_abort_upload (mongoc_stream_t *stream); 100 | 101 | BSON_END_DECLS 102 | 103 | #endif /* MONGOC_GRIDFS_BUCKET_H */ 104 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-gridfs-file-list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 MongoDB Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_GRIDFS_FILE_LIST_H 20 | #define MONGOC_GRIDFS_FILE_LIST_H 21 | 22 | #include 23 | 24 | #include "mongoc-macros.h" 25 | #include "mongoc-gridfs-file.h" 26 | 27 | 28 | BSON_BEGIN_DECLS 29 | 30 | 31 | typedef struct _mongoc_gridfs_file_list_t mongoc_gridfs_file_list_t; 32 | 33 | 34 | MONGOC_EXPORT (mongoc_gridfs_file_t *) 35 | mongoc_gridfs_file_list_next (mongoc_gridfs_file_list_t *list) 36 | BSON_GNUC_WARN_UNUSED_RESULT; 37 | MONGOC_EXPORT (void) 38 | mongoc_gridfs_file_list_destroy (mongoc_gridfs_file_list_t *list); 39 | MONGOC_EXPORT (bool) 40 | mongoc_gridfs_file_list_error (mongoc_gridfs_file_list_t *list, 41 | bson_error_t *error); 42 | 43 | 44 | BSON_END_DECLS 45 | 46 | 47 | #endif /* MONGOC_GRIDFS_FILE_LIST_H */ 48 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-gridfs-file-page.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 MongoDB Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_GRIDFS_FILE_PAGE_H 20 | #define MONGOC_GRIDFS_FILE_PAGE_H 21 | 22 | #include 23 | 24 | #include "mongoc-stream.h" 25 | #include "mongoc-gridfs-file.h" 26 | #include "mongoc-gridfs-file-list.h" 27 | 28 | 29 | BSON_BEGIN_DECLS 30 | 31 | 32 | typedef struct _mongoc_gridfs_file_page_t mongoc_gridfs_file_page_t; 33 | 34 | 35 | BSON_END_DECLS 36 | 37 | 38 | #endif /* MONGOC_GRIDFS_FILE_PAGE_H */ 39 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-gridfs-file.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 MongoDB Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_GRIDFS_FILE_H 20 | #define MONGOC_GRIDFS_FILE_H 21 | 22 | #include 23 | 24 | #include "mongoc-macros.h" 25 | #include "mongoc-socket.h" 26 | 27 | BSON_BEGIN_DECLS 28 | 29 | 30 | #define MONGOC_GRIDFS_FILE_STR_HEADER(name) \ 31 | MONGOC_EXPORT (const char *) \ 32 | mongoc_gridfs_file_get_##name (mongoc_gridfs_file_t *file); \ 33 | MONGOC_EXPORT (void) \ 34 | mongoc_gridfs_file_set_##name (mongoc_gridfs_file_t *file, const char *str); 35 | 36 | 37 | #define MONGOC_GRIDFS_FILE_BSON_HEADER(name) \ 38 | MONGOC_EXPORT (const bson_t *) \ 39 | mongoc_gridfs_file_get_##name (mongoc_gridfs_file_t *file); \ 40 | MONGOC_EXPORT (void) \ 41 | mongoc_gridfs_file_set_##name (mongoc_gridfs_file_t *file, \ 42 | const bson_t *bson); 43 | 44 | 45 | typedef struct _mongoc_gridfs_file_t mongoc_gridfs_file_t; 46 | typedef struct _mongoc_gridfs_file_opt_t mongoc_gridfs_file_opt_t; 47 | 48 | 49 | struct _mongoc_gridfs_file_opt_t { 50 | const char *md5; 51 | const char *filename; 52 | const char *content_type; 53 | const bson_t *aliases; 54 | const bson_t *metadata; 55 | uint32_t chunk_size; 56 | }; 57 | 58 | 59 | MONGOC_GRIDFS_FILE_STR_HEADER (md5) 60 | MONGOC_GRIDFS_FILE_STR_HEADER (filename) 61 | MONGOC_GRIDFS_FILE_STR_HEADER (content_type) 62 | MONGOC_GRIDFS_FILE_BSON_HEADER (aliases) 63 | MONGOC_GRIDFS_FILE_BSON_HEADER (metadata) 64 | 65 | 66 | MONGOC_EXPORT (const bson_value_t *) 67 | mongoc_gridfs_file_get_id (mongoc_gridfs_file_t *file); 68 | 69 | MONGOC_EXPORT (int64_t) 70 | mongoc_gridfs_file_get_length (mongoc_gridfs_file_t *file); 71 | 72 | MONGOC_EXPORT (int32_t) 73 | mongoc_gridfs_file_get_chunk_size (mongoc_gridfs_file_t *file); 74 | 75 | MONGOC_EXPORT (int64_t) 76 | mongoc_gridfs_file_get_upload_date (mongoc_gridfs_file_t *file); 77 | 78 | MONGOC_EXPORT (ssize_t) 79 | mongoc_gridfs_file_writev (mongoc_gridfs_file_t *file, 80 | const mongoc_iovec_t *iov, 81 | size_t iovcnt, 82 | uint32_t timeout_msec); 83 | MONGOC_EXPORT (ssize_t) 84 | mongoc_gridfs_file_readv (mongoc_gridfs_file_t *file, 85 | mongoc_iovec_t *iov, 86 | size_t iovcnt, 87 | size_t min_bytes, 88 | uint32_t timeout_msec); 89 | MONGOC_EXPORT (int) 90 | mongoc_gridfs_file_seek (mongoc_gridfs_file_t *file, int64_t delta, int whence); 91 | 92 | MONGOC_EXPORT (uint64_t) 93 | mongoc_gridfs_file_tell (mongoc_gridfs_file_t *file); 94 | 95 | MONGOC_EXPORT (bool) 96 | mongoc_gridfs_file_set_id (mongoc_gridfs_file_t *file, 97 | const bson_value_t *id, 98 | bson_error_t *error); 99 | 100 | MONGOC_EXPORT (bool) 101 | mongoc_gridfs_file_save (mongoc_gridfs_file_t *file); 102 | 103 | MONGOC_EXPORT (void) 104 | mongoc_gridfs_file_destroy (mongoc_gridfs_file_t *file); 105 | 106 | MONGOC_EXPORT (bool) 107 | mongoc_gridfs_file_error (mongoc_gridfs_file_t *file, bson_error_t *error); 108 | 109 | MONGOC_EXPORT (bool) 110 | mongoc_gridfs_file_remove (mongoc_gridfs_file_t *file, bson_error_t *error); 111 | 112 | BSON_END_DECLS 113 | 114 | #endif /* MONGOC_GRIDFS_FILE_H */ 115 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-gridfs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 MongoDB Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_GRIDFS_H 20 | #define MONGOC_GRIDFS_H 21 | 22 | #include 23 | 24 | #include "mongoc-macros.h" 25 | #include "mongoc-stream.h" 26 | #include "mongoc-gridfs-file.h" 27 | #include "mongoc-collection.h" 28 | #include "mongoc-gridfs-file-list.h" 29 | 30 | 31 | BSON_BEGIN_DECLS 32 | 33 | 34 | typedef struct _mongoc_gridfs_t mongoc_gridfs_t; 35 | 36 | 37 | MONGOC_EXPORT (mongoc_gridfs_file_t *) 38 | mongoc_gridfs_create_file_from_stream (mongoc_gridfs_t *gridfs, 39 | mongoc_stream_t *stream, 40 | mongoc_gridfs_file_opt_t *opt) 41 | BSON_GNUC_WARN_UNUSED_RESULT; 42 | MONGOC_EXPORT (mongoc_gridfs_file_t *) 43 | mongoc_gridfs_create_file (mongoc_gridfs_t *gridfs, 44 | mongoc_gridfs_file_opt_t *opt) 45 | BSON_GNUC_WARN_UNUSED_RESULT; 46 | MONGOC_EXPORT (mongoc_gridfs_file_list_t *) 47 | mongoc_gridfs_find (mongoc_gridfs_t *gridfs, 48 | const bson_t *query) BSON_GNUC_WARN_UNUSED_RESULT 49 | BSON_GNUC_DEPRECATED_FOR (mongoc_gridfs_find_with_opts); 50 | MONGOC_EXPORT (mongoc_gridfs_file_t *) 51 | mongoc_gridfs_find_one (mongoc_gridfs_t *gridfs, 52 | const bson_t *query, 53 | bson_error_t *error) BSON_GNUC_WARN_UNUSED_RESULT 54 | BSON_GNUC_DEPRECATED_FOR (mongoc_gridfs_find_one_with_opts); 55 | MONGOC_EXPORT (mongoc_gridfs_file_list_t *) 56 | mongoc_gridfs_find_with_opts (mongoc_gridfs_t *gridfs, 57 | const bson_t *filter, 58 | const bson_t *opts) BSON_GNUC_WARN_UNUSED_RESULT; 59 | MONGOC_EXPORT (mongoc_gridfs_file_t *) 60 | mongoc_gridfs_find_one_with_opts (mongoc_gridfs_t *gridfs, 61 | const bson_t *filter, 62 | const bson_t *opts, 63 | bson_error_t *error) 64 | BSON_GNUC_WARN_UNUSED_RESULT; 65 | MONGOC_EXPORT (mongoc_gridfs_file_t *) 66 | mongoc_gridfs_find_one_by_filename (mongoc_gridfs_t *gridfs, 67 | const char *filename, 68 | bson_error_t *error) 69 | BSON_GNUC_WARN_UNUSED_RESULT; 70 | MONGOC_EXPORT (bool) 71 | mongoc_gridfs_drop (mongoc_gridfs_t *gridfs, bson_error_t *error); 72 | MONGOC_EXPORT (void) 73 | mongoc_gridfs_destroy (mongoc_gridfs_t *gridfs); 74 | MONGOC_EXPORT (mongoc_collection_t *) 75 | mongoc_gridfs_get_files (mongoc_gridfs_t *gridfs); 76 | MONGOC_EXPORT (mongoc_collection_t *) 77 | mongoc_gridfs_get_chunks (mongoc_gridfs_t *gridfs); 78 | MONGOC_EXPORT (bool) 79 | mongoc_gridfs_remove_by_filename (mongoc_gridfs_t *gridfs, 80 | const char *filename, 81 | bson_error_t *error); 82 | 83 | 84 | BSON_END_DECLS 85 | 86 | 87 | #endif /* MONGOC_GRIDFS_H */ 88 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-handshake.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-present MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | 20 | #ifndef MONGOC_HANDSHAKE_H 21 | #define MONGOC_HANDSHAKE_H 22 | 23 | #include 24 | 25 | #include "mongoc-macros.h" 26 | 27 | BSON_BEGIN_DECLS 28 | 29 | #define MONGOC_HANDSHAKE_APPNAME_MAX 128 30 | 31 | MONGOC_EXPORT (bool) 32 | mongoc_handshake_data_append (const char *driver_name, 33 | const char *driver_version, 34 | const char *platform); 35 | 36 | BSON_END_DECLS 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-host-list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_HOST_LIST_H 20 | #define MONGOC_HOST_LIST_H 21 | 22 | #include 23 | 24 | 25 | BSON_BEGIN_DECLS 26 | 27 | 28 | #ifdef _POSIX_HOST_NAME_MAX 29 | #define BSON_HOST_NAME_MAX _POSIX_HOST_NAME_MAX 30 | #else 31 | #define BSON_HOST_NAME_MAX 255 32 | #endif 33 | 34 | 35 | typedef struct _mongoc_host_list_t mongoc_host_list_t; 36 | 37 | 38 | struct _mongoc_host_list_t { 39 | mongoc_host_list_t *next; 40 | char host[BSON_HOST_NAME_MAX + 1]; 41 | char host_and_port[BSON_HOST_NAME_MAX + 7]; 42 | uint16_t port; 43 | int family; 44 | void *padding[4]; 45 | }; 46 | 47 | BSON_END_DECLS 48 | 49 | 50 | #endif /* MONGOC_HOST_LIST_H */ 51 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-index.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 MongoDB Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_INDEX_H 20 | #define MONGOC_INDEX_H 21 | 22 | #include 23 | 24 | #include "mongoc-macros.h" 25 | 26 | 27 | BSON_BEGIN_DECLS 28 | 29 | typedef struct { 30 | uint8_t twod_sphere_version; 31 | uint8_t twod_bits_precision; 32 | double twod_location_min; 33 | double twod_location_max; 34 | double haystack_bucket_size; 35 | uint8_t *padding[32]; 36 | } mongoc_index_opt_geo_t; 37 | 38 | typedef struct { 39 | int type; 40 | } mongoc_index_opt_storage_t; 41 | 42 | typedef enum { 43 | MONGOC_INDEX_STORAGE_OPT_MMAPV1, 44 | MONGOC_INDEX_STORAGE_OPT_WIREDTIGER, 45 | } mongoc_index_storage_opt_type_t; 46 | 47 | typedef struct { 48 | mongoc_index_opt_storage_t base; 49 | const char *config_str; 50 | void *padding[8]; 51 | } mongoc_index_opt_wt_t; 52 | 53 | typedef struct { 54 | bool is_initialized; 55 | bool background; 56 | bool unique; 57 | const char *name; 58 | bool drop_dups; 59 | bool sparse; 60 | int32_t expire_after_seconds; 61 | int32_t v; 62 | const bson_t *weights; 63 | const char *default_language; 64 | const char *language_override; 65 | mongoc_index_opt_geo_t *geo_options; 66 | mongoc_index_opt_storage_t *storage_options; 67 | const bson_t *partial_filter_expression; 68 | const bson_t *collation; 69 | void *padding[4]; 70 | } mongoc_index_opt_t; 71 | 72 | 73 | MONGOC_EXPORT (const mongoc_index_opt_t *) 74 | mongoc_index_opt_get_default (void) BSON_GNUC_PURE; 75 | MONGOC_EXPORT (const mongoc_index_opt_geo_t *) 76 | mongoc_index_opt_geo_get_default (void) BSON_GNUC_PURE; 77 | MONGOC_EXPORT (const mongoc_index_opt_wt_t *) 78 | mongoc_index_opt_wt_get_default (void) BSON_GNUC_PURE; 79 | MONGOC_EXPORT (void) 80 | mongoc_index_opt_init (mongoc_index_opt_t *opt); 81 | MONGOC_EXPORT (void) 82 | mongoc_index_opt_geo_init (mongoc_index_opt_geo_t *opt); 83 | MONGOC_EXPORT (void) 84 | mongoc_index_opt_wt_init (mongoc_index_opt_wt_t *opt); 85 | 86 | BSON_END_DECLS 87 | 88 | 89 | #endif /* MONGOC_INDEX_H */ 90 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-init.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_INIT_H 20 | #define MONGOC_INIT_H 21 | 22 | #include 23 | 24 | #include "mongoc-macros.h" 25 | 26 | BSON_BEGIN_DECLS 27 | 28 | 29 | MONGOC_EXPORT (void) 30 | mongoc_init (void); 31 | MONGOC_EXPORT (void) 32 | mongoc_cleanup (void); 33 | 34 | 35 | BSON_END_DECLS 36 | 37 | 38 | #endif /* MONGOC_INIT_H */ 39 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-iovec.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | 20 | #ifndef MONGOC_IOVEC_H 21 | #define MONGOC_IOVEC_H 22 | 23 | 24 | #include 25 | 26 | #ifdef _WIN32 27 | #include 28 | #else 29 | #include 30 | #endif 31 | 32 | BSON_BEGIN_DECLS 33 | 34 | 35 | #ifdef _WIN32 36 | typedef struct { 37 | size_t iov_len; 38 | char *iov_base; 39 | } mongoc_iovec_t; 40 | 41 | BSON_STATIC_ASSERT2 (sizeof_iovect_t, 42 | sizeof (mongoc_iovec_t) == sizeof (WSABUF)); 43 | BSON_STATIC_ASSERT2 (offsetof_iovec_base, 44 | offsetof (mongoc_iovec_t, iov_base) == 45 | offsetof (WSABUF, buf)); 46 | BSON_STATIC_ASSERT2 (offsetof_iovec_len, 47 | offsetof (mongoc_iovec_t, iov_len) == 48 | offsetof (WSABUF, len)); 49 | 50 | #else 51 | typedef struct iovec mongoc_iovec_t; 52 | #endif 53 | 54 | 55 | BSON_END_DECLS 56 | 57 | 58 | #endif /* MONGOC_IOVEC_H */ 59 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-log.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_LOG_H 20 | #define MONGOC_LOG_H 21 | 22 | #include 23 | 24 | #include "mongoc-macros.h" 25 | 26 | BSON_BEGIN_DECLS 27 | 28 | 29 | #ifndef MONGOC_LOG_DOMAIN 30 | #define MONGOC_LOG_DOMAIN "mongoc" 31 | #endif 32 | 33 | 34 | #define MONGOC_ERROR(...) \ 35 | mongoc_log (MONGOC_LOG_LEVEL_ERROR, MONGOC_LOG_DOMAIN, __VA_ARGS__) 36 | #define MONGOC_CRITICAL(...) \ 37 | mongoc_log (MONGOC_LOG_LEVEL_CRITICAL, MONGOC_LOG_DOMAIN, __VA_ARGS__) 38 | #define MONGOC_WARNING(...) \ 39 | mongoc_log (MONGOC_LOG_LEVEL_WARNING, MONGOC_LOG_DOMAIN, __VA_ARGS__) 40 | #define MONGOC_MESSAGE(...) \ 41 | mongoc_log (MONGOC_LOG_LEVEL_MESSAGE, MONGOC_LOG_DOMAIN, __VA_ARGS__) 42 | #define MONGOC_INFO(...) \ 43 | mongoc_log (MONGOC_LOG_LEVEL_INFO, MONGOC_LOG_DOMAIN, __VA_ARGS__) 44 | #define MONGOC_DEBUG(...) \ 45 | mongoc_log (MONGOC_LOG_LEVEL_DEBUG, MONGOC_LOG_DOMAIN, __VA_ARGS__) 46 | 47 | 48 | typedef enum { 49 | MONGOC_LOG_LEVEL_ERROR, 50 | MONGOC_LOG_LEVEL_CRITICAL, 51 | MONGOC_LOG_LEVEL_WARNING, 52 | MONGOC_LOG_LEVEL_MESSAGE, 53 | MONGOC_LOG_LEVEL_INFO, 54 | MONGOC_LOG_LEVEL_DEBUG, 55 | MONGOC_LOG_LEVEL_TRACE, 56 | } mongoc_log_level_t; 57 | 58 | 59 | /** 60 | * mongoc_log_func_t: 61 | * @log_level: The level of the log message. 62 | * @log_domain: The domain of the log message, such as "client". 63 | * @message: The message generated. 64 | * @user_data: User data provided to mongoc_log_set_handler(). 65 | * 66 | * This function prototype can be used to set a custom log handler for the 67 | * libmongoc library. This is useful if you would like to show them in a 68 | * user interface or alternate storage. 69 | */ 70 | typedef void (*mongoc_log_func_t) (mongoc_log_level_t log_level, 71 | const char *log_domain, 72 | const char *message, 73 | void *user_data); 74 | 75 | 76 | /** 77 | * mongoc_log_set_handler: 78 | * @log_func: A function to handle log messages. 79 | * @user_data: User data for @log_func. 80 | * 81 | * Sets the function to be called to handle logging. 82 | */ 83 | MONGOC_EXPORT (void) 84 | mongoc_log_set_handler (mongoc_log_func_t log_func, void *user_data); 85 | 86 | 87 | /** 88 | * mongoc_log: 89 | * @log_level: The log level. 90 | * @log_domain: The log domain (such as "client"). 91 | * @format: The format string for the log message. 92 | * 93 | * Logs a message using the currently configured logger. 94 | * 95 | * This method will hold a logging lock to prevent concurrent calls to the 96 | * logging infrastructure. It is important that your configured log function 97 | * does not re-enter the logging system or deadlock will occur. 98 | * 99 | */ 100 | MONGOC_EXPORT (void) 101 | mongoc_log (mongoc_log_level_t log_level, 102 | const char *log_domain, 103 | const char *format, 104 | ...) BSON_GNUC_PRINTF (3, 4); 105 | 106 | 107 | MONGOC_EXPORT (void) 108 | mongoc_log_default_handler (mongoc_log_level_t log_level, 109 | const char *log_domain, 110 | const char *message, 111 | void *user_data); 112 | 113 | 114 | /** 115 | * mongoc_log_level_str: 116 | * @log_level: The log level. 117 | * 118 | * Returns: The string representation of log_level 119 | */ 120 | MONGOC_EXPORT (const char *) 121 | mongoc_log_level_str (mongoc_log_level_t log_level); 122 | 123 | 124 | /** 125 | * mongoc_log_trace_enable: 126 | * 127 | * Enables tracing at runtime (if it has been enabled at compile time). 128 | */ 129 | MONGOC_EXPORT (void) 130 | mongoc_log_trace_enable (void); 131 | 132 | 133 | /** 134 | * mongoc_log_trace_disable: 135 | * 136 | * Disables tracing at runtime (if it has been enabled at compile time). 137 | */ 138 | MONGOC_EXPORT (void) 139 | mongoc_log_trace_disable (void); 140 | 141 | 142 | BSON_END_DECLS 143 | 144 | 145 | #endif /* MONGOC_LOG_H */ 146 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-macros.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_MACROS_H 20 | #define MONGOC_MACROS_H 21 | 22 | /* Decorate public functions: 23 | * - if MONGOC_STATIC, we're compiling a program that uses libmongoc as 24 | * a static library, don't decorate functions 25 | * - else if MONGOC_COMPILATION, we're compiling a static or shared libmongoc, 26 | * mark public functions for export from the shared lib (which has no effect 27 | * on the static lib) 28 | * - else, we're compiling a program that uses libmongoc as a shared library, 29 | * mark public functions as DLL imports for Microsoft Visual C. 30 | */ 31 | 32 | #ifdef _MSC_VER 33 | /* 34 | * Microsoft Visual C 35 | */ 36 | #ifdef MONGOC_STATIC 37 | #define MONGOC_API 38 | #elif defined(MONGOC_COMPILATION) 39 | #define MONGOC_API __declspec(dllexport) 40 | #else 41 | #define MONGOC_API __declspec(dllimport) 42 | #endif 43 | #define MONGOC_CALL __cdecl 44 | 45 | #elif defined(__GNUC__) 46 | /* 47 | * GCC 48 | */ 49 | #ifdef MONGOC_STATIC 50 | #define MONGOC_API 51 | #elif defined(MONGOC_COMPILATION) 52 | #define MONGOC_API __attribute__ ((visibility ("default"))) 53 | #else 54 | #define MONGOC_API 55 | #endif 56 | #define MONGOC_CALL 57 | 58 | #else 59 | /* 60 | * Other compilers 61 | */ 62 | #define MONGOC_API 63 | #define MONGOC_CALL 64 | 65 | #endif 66 | 67 | #define MONGOC_EXPORT(type) MONGOC_API type MONGOC_CALL 68 | 69 | #endif /* MONGOC_MACROS_H */ 70 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-matcher.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_MATCHER_H 20 | #define MONGOC_MATCHER_H 21 | 22 | #include 23 | 24 | #include "mongoc-macros.h" 25 | 26 | BSON_BEGIN_DECLS 27 | 28 | 29 | typedef struct _mongoc_matcher_t mongoc_matcher_t; 30 | 31 | 32 | MONGOC_EXPORT (mongoc_matcher_t *) 33 | mongoc_matcher_new (const bson_t *query, bson_error_t *error) 34 | BSON_GNUC_WARN_UNUSED_RESULT BSON_GNUC_DEPRECATED; 35 | MONGOC_EXPORT (bool) 36 | mongoc_matcher_match (const mongoc_matcher_t *matcher, 37 | const bson_t *document) BSON_GNUC_DEPRECATED; 38 | MONGOC_EXPORT (void) 39 | mongoc_matcher_destroy (mongoc_matcher_t *matcher) BSON_GNUC_DEPRECATED; 40 | 41 | 42 | BSON_END_DECLS 43 | 44 | 45 | #endif /* MONGOC_MATCHER_H */ 46 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-opcode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_OPCODE_H 20 | #define MONGOC_OPCODE_H 21 | 22 | #include 23 | 24 | 25 | BSON_BEGIN_DECLS 26 | 27 | 28 | typedef enum { 29 | MONGOC_OPCODE_REPLY = 1, 30 | MONGOC_OPCODE_UPDATE = 2001, 31 | MONGOC_OPCODE_INSERT = 2002, 32 | MONGOC_OPCODE_QUERY = 2004, 33 | MONGOC_OPCODE_GET_MORE = 2005, 34 | MONGOC_OPCODE_DELETE = 2006, 35 | MONGOC_OPCODE_KILL_CURSORS = 2007, 36 | MONGOC_OPCODE_COMPRESSED = 2012, 37 | MONGOC_OPCODE_MSG = 2013, 38 | } mongoc_opcode_t; 39 | 40 | 41 | BSON_END_DECLS 42 | 43 | 44 | #endif /* MONGOC_OPCODE_H */ 45 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-optional.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_OPTIONAL_H 20 | #define MONGOC_OPTIONAL_H 21 | 22 | #include 23 | 24 | #include "mongoc-macros.h" 25 | 26 | BSON_BEGIN_DECLS 27 | 28 | typedef struct { 29 | bool value; 30 | bool is_set; 31 | } mongoc_optional_t; 32 | 33 | MONGOC_EXPORT (void) 34 | mongoc_optional_init (mongoc_optional_t *opt); 35 | 36 | MONGOC_EXPORT (bool) 37 | mongoc_optional_is_set (const mongoc_optional_t *opt); 38 | 39 | MONGOC_EXPORT (bool) 40 | mongoc_optional_value (const mongoc_optional_t *opt); 41 | 42 | MONGOC_EXPORT (void) 43 | mongoc_optional_set_value (mongoc_optional_t *opt, bool val); 44 | 45 | MONGOC_EXPORT (void) 46 | mongoc_optional_copy (const mongoc_optional_t *source, mongoc_optional_t *copy); 47 | 48 | BSON_END_DECLS 49 | 50 | #endif /* MONGOC_OPTIONAL_H */ 51 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-prelude.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-present MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #if !defined(MONGOC_INSIDE) && !defined(MONGOC_COMPILATION) 18 | #error "Only can be included directly." 19 | #endif 20 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-rand.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | 20 | #ifndef MONGOC_RAND_H 21 | #define MONGOC_RAND_H 22 | 23 | 24 | #include 25 | 26 | #include "mongoc-macros.h" 27 | 28 | BSON_BEGIN_DECLS 29 | 30 | MONGOC_EXPORT (void) 31 | mongoc_rand_seed (const void *buf, int num); 32 | MONGOC_EXPORT (void) 33 | mongoc_rand_add (const void *buf, int num, double entropy); 34 | MONGOC_EXPORT (int) 35 | mongoc_rand_status (void); 36 | 37 | BSON_END_DECLS 38 | 39 | 40 | #endif /* MONGOC_RAND_H */ 41 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-read-concern.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_READ_CONCERN_H 20 | #define MONGOC_READ_CONCERN_H 21 | 22 | #include 23 | 24 | #include "mongoc-macros.h" 25 | 26 | BSON_BEGIN_DECLS 27 | 28 | 29 | #define MONGOC_READ_CONCERN_LEVEL_AVAILABLE "available" 30 | #define MONGOC_READ_CONCERN_LEVEL_LOCAL "local" 31 | #define MONGOC_READ_CONCERN_LEVEL_MAJORITY "majority" 32 | #define MONGOC_READ_CONCERN_LEVEL_LINEARIZABLE "linearizable" 33 | #define MONGOC_READ_CONCERN_LEVEL_SNAPSHOT "snapshot" 34 | 35 | typedef struct _mongoc_read_concern_t mongoc_read_concern_t; 36 | 37 | 38 | MONGOC_EXPORT (mongoc_read_concern_t *) 39 | mongoc_read_concern_new (void) BSON_GNUC_WARN_UNUSED_RESULT; 40 | MONGOC_EXPORT (mongoc_read_concern_t *) 41 | mongoc_read_concern_copy (const mongoc_read_concern_t *read_concern) 42 | BSON_GNUC_WARN_UNUSED_RESULT; 43 | MONGOC_EXPORT (void) 44 | mongoc_read_concern_destroy (mongoc_read_concern_t *read_concern); 45 | MONGOC_EXPORT (const char *) 46 | mongoc_read_concern_get_level (const mongoc_read_concern_t *read_concern); 47 | MONGOC_EXPORT (bool) 48 | mongoc_read_concern_set_level (mongoc_read_concern_t *read_concern, 49 | const char *level); 50 | MONGOC_EXPORT (bool) 51 | mongoc_read_concern_append (mongoc_read_concern_t *read_concern, bson_t *doc); 52 | MONGOC_EXPORT (bool) 53 | mongoc_read_concern_is_default (const mongoc_read_concern_t *read_concern); 54 | 55 | BSON_END_DECLS 56 | 57 | 58 | #endif /* MONGOC_READ_CONCERN_H */ 59 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-read-prefs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_READ_PREFS_H 20 | #define MONGOC_READ_PREFS_H 21 | 22 | #include 23 | 24 | #include "mongoc-macros.h" 25 | #include "mongoc-config.h" 26 | 27 | BSON_BEGIN_DECLS 28 | 29 | 30 | #define MONGOC_NO_MAX_STALENESS -1 31 | #define MONGOC_SMALLEST_MAX_STALENESS_SECONDS 90 32 | 33 | typedef struct _mongoc_read_prefs_t mongoc_read_prefs_t; 34 | 35 | 36 | typedef enum { 37 | /** Represents $readPreference.mode of 'primary' */ 38 | MONGOC_READ_PRIMARY = (1 << 0), 39 | /** Represents $readPreference.mode of 'secondary' */ 40 | MONGOC_READ_SECONDARY = (1 << 1), 41 | /** Represents $readPreference.mode of 'primaryPreferred' */ 42 | MONGOC_READ_PRIMARY_PREFERRED = (1 << 2) | MONGOC_READ_PRIMARY, 43 | /** Represents $readPreference.mode of 'secondaryPreferred' */ 44 | MONGOC_READ_SECONDARY_PREFERRED = (1 << 2) | MONGOC_READ_SECONDARY, 45 | /** Represents $readPreference.mode of 'nearest' */ 46 | MONGOC_READ_NEAREST = (1 << 3) | MONGOC_READ_SECONDARY, 47 | } mongoc_read_mode_t; 48 | 49 | 50 | MONGOC_EXPORT (mongoc_read_prefs_t *) 51 | mongoc_read_prefs_new (mongoc_read_mode_t read_mode) 52 | BSON_GNUC_WARN_UNUSED_RESULT; 53 | MONGOC_EXPORT (mongoc_read_prefs_t *) 54 | mongoc_read_prefs_copy (const mongoc_read_prefs_t *read_prefs) 55 | BSON_GNUC_WARN_UNUSED_RESULT; 56 | MONGOC_EXPORT (void) 57 | mongoc_read_prefs_destroy (mongoc_read_prefs_t *read_prefs); 58 | MONGOC_EXPORT (mongoc_read_mode_t) 59 | mongoc_read_prefs_get_mode (const mongoc_read_prefs_t *read_prefs); 60 | MONGOC_EXPORT (void) 61 | mongoc_read_prefs_set_mode (mongoc_read_prefs_t *read_prefs, 62 | mongoc_read_mode_t mode); 63 | MONGOC_EXPORT (const bson_t *) 64 | mongoc_read_prefs_get_tags (const mongoc_read_prefs_t *read_prefs); 65 | MONGOC_EXPORT (void) 66 | mongoc_read_prefs_set_tags (mongoc_read_prefs_t *read_prefs, 67 | const bson_t *tags); 68 | MONGOC_EXPORT (void) 69 | mongoc_read_prefs_add_tag (mongoc_read_prefs_t *read_prefs, const bson_t *tag); 70 | MONGOC_EXPORT (int64_t) 71 | mongoc_read_prefs_get_max_staleness_seconds ( 72 | const mongoc_read_prefs_t *read_prefs); 73 | MONGOC_EXPORT (void) 74 | mongoc_read_prefs_set_max_staleness_seconds (mongoc_read_prefs_t *read_prefs, 75 | int64_t max_staleness_seconds); 76 | MONGOC_EXPORT (const bson_t *) 77 | mongoc_read_prefs_get_hedge (const mongoc_read_prefs_t *read_prefs); 78 | MONGOC_EXPORT (void) 79 | mongoc_read_prefs_set_hedge (mongoc_read_prefs_t *read_prefs, 80 | const bson_t *hedge); 81 | MONGOC_EXPORT (bool) 82 | mongoc_read_prefs_is_valid (const mongoc_read_prefs_t *read_prefs); 83 | 84 | 85 | BSON_END_DECLS 86 | 87 | 88 | #endif /* MONGOC_READ_PREFS_H */ 89 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-server-api.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_SERVER_API_H 20 | #define MONGOC_SERVER_API_H 21 | 22 | #include 23 | 24 | #include "mongoc-optional.h" 25 | #include "mongoc-macros.h" 26 | 27 | BSON_BEGIN_DECLS 28 | 29 | typedef enum { MONGOC_SERVER_API_V1 } mongoc_server_api_version_t; 30 | 31 | typedef struct _mongoc_server_api_t mongoc_server_api_t; 32 | 33 | MONGOC_EXPORT (const char *) 34 | mongoc_server_api_version_to_string (mongoc_server_api_version_t version); 35 | 36 | MONGOC_EXPORT (bool) 37 | mongoc_server_api_version_from_string (const char *version, 38 | mongoc_server_api_version_t *out); 39 | 40 | MONGOC_EXPORT (mongoc_server_api_t *) 41 | mongoc_server_api_new (mongoc_server_api_version_t version) 42 | BSON_GNUC_WARN_UNUSED_RESULT; 43 | 44 | MONGOC_EXPORT (mongoc_server_api_t *) 45 | mongoc_server_api_copy (const mongoc_server_api_t *api) 46 | BSON_GNUC_WARN_UNUSED_RESULT; 47 | 48 | MONGOC_EXPORT (void) 49 | mongoc_server_api_destroy (mongoc_server_api_t *api); 50 | 51 | MONGOC_EXPORT (void) 52 | mongoc_server_api_strict (mongoc_server_api_t *api, bool strict); 53 | 54 | MONGOC_EXPORT (void) 55 | mongoc_server_api_deprecation_errors (mongoc_server_api_t *api, 56 | bool deprecation_errors); 57 | 58 | MONGOC_EXPORT (const mongoc_optional_t *) 59 | mongoc_server_api_get_deprecation_errors (const mongoc_server_api_t *api); 60 | 61 | MONGOC_EXPORT (const mongoc_optional_t *) 62 | mongoc_server_api_get_strict (const mongoc_server_api_t *api); 63 | 64 | MONGOC_EXPORT (mongoc_server_api_version_t) 65 | mongoc_server_api_get_version (const mongoc_server_api_t *api); 66 | 67 | BSON_END_DECLS 68 | 69 | #endif /* MONGOC_SERVER_API_H */ 70 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-server-description.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_SERVER_DESCRIPTION_H 20 | #define MONGOC_SERVER_DESCRIPTION_H 21 | 22 | #include 23 | 24 | #include "mongoc-macros.h" 25 | #include "mongoc-read-prefs.h" 26 | #include "mongoc-host-list.h" 27 | 28 | BSON_BEGIN_DECLS 29 | 30 | typedef struct _mongoc_server_description_t mongoc_server_description_t; 31 | 32 | MONGOC_EXPORT (void) 33 | mongoc_server_description_destroy (mongoc_server_description_t *description); 34 | 35 | MONGOC_EXPORT (mongoc_server_description_t *) 36 | mongoc_server_description_new_copy ( 37 | const mongoc_server_description_t *description) BSON_GNUC_WARN_UNUSED_RESULT; 38 | 39 | MONGOC_EXPORT (uint32_t) 40 | mongoc_server_description_id (const mongoc_server_description_t *description); 41 | 42 | MONGOC_EXPORT (mongoc_host_list_t *) 43 | mongoc_server_description_host (const mongoc_server_description_t *description); 44 | 45 | MONGOC_EXPORT (int64_t) 46 | mongoc_server_description_last_update_time ( 47 | const mongoc_server_description_t *description); 48 | 49 | MONGOC_EXPORT (int64_t) 50 | mongoc_server_description_round_trip_time ( 51 | const mongoc_server_description_t *description); 52 | 53 | MONGOC_EXPORT (const char *) 54 | mongoc_server_description_type (const mongoc_server_description_t *description); 55 | 56 | MONGOC_EXPORT (const bson_t *) 57 | mongoc_server_description_hello_response ( 58 | const mongoc_server_description_t *description); 59 | 60 | MONGOC_EXPORT (const bson_t *) 61 | mongoc_server_description_ismaster ( 62 | const mongoc_server_description_t *description) 63 | BSON_GNUC_DEPRECATED_FOR (mongoc_server_description_hello_response); 64 | 65 | MONGOC_EXPORT (int32_t) 66 | mongoc_server_description_compressor_id ( 67 | const mongoc_server_description_t *description); 68 | 69 | BSON_END_DECLS 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-socket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_SOCKET_H 20 | #define MONGOC_SOCKET_H 21 | 22 | #include 23 | #include "mongoc-macros.h" 24 | #include "mongoc-config.h" 25 | 26 | #ifdef _WIN32 27 | #include 28 | #include 29 | #else 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #endif 40 | 41 | #if defined(_AIX) && !defined(MONGOC_HAVE_SS_FAMILY) 42 | #define ss_family __ss_family 43 | #endif 44 | 45 | #include "mongoc-iovec.h" 46 | 47 | 48 | BSON_BEGIN_DECLS 49 | 50 | 51 | typedef MONGOC_SOCKET_ARG3 mongoc_socklen_t; 52 | 53 | typedef struct _mongoc_socket_t mongoc_socket_t; 54 | 55 | typedef struct { 56 | mongoc_socket_t *socket; 57 | int events; 58 | int revents; 59 | } mongoc_socket_poll_t; 60 | 61 | MONGOC_EXPORT (mongoc_socket_t *) 62 | mongoc_socket_accept (mongoc_socket_t *sock, 63 | int64_t expire_at) BSON_GNUC_WARN_UNUSED_RESULT; 64 | MONGOC_EXPORT (int) 65 | mongoc_socket_bind (mongoc_socket_t *sock, 66 | const struct sockaddr *addr, 67 | mongoc_socklen_t addrlen); 68 | MONGOC_EXPORT (int) 69 | mongoc_socket_close (mongoc_socket_t *socket); 70 | MONGOC_EXPORT (int) 71 | mongoc_socket_connect (mongoc_socket_t *sock, 72 | const struct sockaddr *addr, 73 | mongoc_socklen_t addrlen, 74 | int64_t expire_at); 75 | MONGOC_EXPORT (char *) 76 | mongoc_socket_getnameinfo (mongoc_socket_t *sock) BSON_GNUC_WARN_UNUSED_RESULT; 77 | MONGOC_EXPORT (void) 78 | mongoc_socket_destroy (mongoc_socket_t *sock); 79 | MONGOC_EXPORT (int) 80 | mongoc_socket_errno (mongoc_socket_t *sock); 81 | MONGOC_EXPORT (int) 82 | mongoc_socket_getsockname (mongoc_socket_t *sock, 83 | struct sockaddr *addr, 84 | mongoc_socklen_t *addrlen); 85 | MONGOC_EXPORT (int) 86 | mongoc_socket_listen (mongoc_socket_t *sock, unsigned int backlog); 87 | MONGOC_EXPORT (mongoc_socket_t *) 88 | mongoc_socket_new (int domain, 89 | int type, 90 | int protocol) BSON_GNUC_WARN_UNUSED_RESULT; 91 | MONGOC_EXPORT (ssize_t) 92 | mongoc_socket_recv (mongoc_socket_t *sock, 93 | void *buf, 94 | size_t buflen, 95 | int flags, 96 | int64_t expire_at); 97 | MONGOC_EXPORT (int) 98 | mongoc_socket_setsockopt (mongoc_socket_t *sock, 99 | int level, 100 | int optname, 101 | const void *optval, 102 | mongoc_socklen_t optlen); 103 | MONGOC_EXPORT (ssize_t) 104 | mongoc_socket_send (mongoc_socket_t *sock, 105 | const void *buf, 106 | size_t buflen, 107 | int64_t expire_at); 108 | MONGOC_EXPORT (ssize_t) 109 | mongoc_socket_sendv (mongoc_socket_t *sock, 110 | mongoc_iovec_t *iov, 111 | size_t iovcnt, 112 | int64_t expire_at); 113 | MONGOC_EXPORT (bool) 114 | mongoc_socket_check_closed (mongoc_socket_t *sock); 115 | MONGOC_EXPORT (void) 116 | mongoc_socket_inet_ntop (struct addrinfo *rp, char *buf, size_t buflen); 117 | MONGOC_EXPORT (ssize_t) 118 | mongoc_socket_poll (mongoc_socket_poll_t *sds, size_t nsds, int32_t timeout); 119 | 120 | 121 | BSON_END_DECLS 122 | 123 | 124 | #endif /* MONGOC_SOCKET_H */ 125 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-ssl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_SSL_H 20 | #define MONGOC_SSL_H 21 | 22 | #include 23 | 24 | #include "mongoc-macros.h" 25 | 26 | BSON_BEGIN_DECLS 27 | 28 | 29 | typedef struct _mongoc_ssl_opt_t mongoc_ssl_opt_t; 30 | 31 | 32 | struct _mongoc_ssl_opt_t { 33 | const char *pem_file; 34 | const char *pem_pwd; 35 | const char *ca_file; 36 | const char *ca_dir; 37 | const char *crl_file; 38 | bool weak_cert_validation; 39 | bool allow_invalid_hostname; 40 | void *internal; 41 | void *padding[6]; 42 | }; 43 | 44 | 45 | MONGOC_EXPORT (const mongoc_ssl_opt_t *) 46 | mongoc_ssl_opt_get_default (void) BSON_GNUC_PURE; 47 | 48 | 49 | BSON_END_DECLS 50 | 51 | 52 | #endif /* MONGOC_SSL_H */ 53 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-stream-buffered.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_STREAM_BUFFERED_H 20 | #define MONGOC_STREAM_BUFFERED_H 21 | 22 | #include 23 | 24 | #include "mongoc-macros.h" 25 | #include "mongoc-stream.h" 26 | 27 | 28 | BSON_BEGIN_DECLS 29 | 30 | 31 | MONGOC_EXPORT (mongoc_stream_t *) 32 | mongoc_stream_buffered_new (mongoc_stream_t *base_stream, 33 | size_t buffer_size) BSON_GNUC_WARN_UNUSED_RESULT; 34 | 35 | 36 | BSON_END_DECLS 37 | 38 | 39 | #endif /* MONGOC_STREAM_BUFFERED_H */ 40 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-stream-file.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_STREAM_FILE_H 20 | #define MONGOC_STREAM_FILE_H 21 | 22 | #include "mongoc-macros.h" 23 | #include "mongoc-stream.h" 24 | 25 | 26 | BSON_BEGIN_DECLS 27 | 28 | 29 | typedef struct _mongoc_stream_file_t mongoc_stream_file_t; 30 | 31 | 32 | MONGOC_EXPORT (mongoc_stream_t *) 33 | mongoc_stream_file_new (int fd) BSON_GNUC_WARN_UNUSED_RESULT; 34 | MONGOC_EXPORT (mongoc_stream_t *) 35 | mongoc_stream_file_new_for_path (const char *path, 36 | int flags, 37 | int mode) BSON_GNUC_WARN_UNUSED_RESULT; 38 | MONGOC_EXPORT (int) 39 | mongoc_stream_file_get_fd (mongoc_stream_file_t *stream); 40 | 41 | 42 | BSON_END_DECLS 43 | 44 | 45 | #endif /* MONGOC_STREAM_FILE_H */ 46 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-stream-gridfs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 MongoDB Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_STREAM_GRIDFS_H 20 | #define MONGOC_STREAM_GRIDFS_H 21 | 22 | #include 23 | 24 | #include "mongoc-macros.h" 25 | #include "mongoc-gridfs.h" 26 | #include "mongoc-stream.h" 27 | 28 | 29 | BSON_BEGIN_DECLS 30 | 31 | 32 | MONGOC_EXPORT (mongoc_stream_t *) 33 | mongoc_stream_gridfs_new (mongoc_gridfs_file_t *file) 34 | BSON_GNUC_WARN_UNUSED_RESULT; 35 | 36 | 37 | BSON_END_DECLS 38 | 39 | 40 | #endif /* MONGOC_STREAM_GRIDFS_H */ 41 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-stream-socket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_STREAM_SOCKET_H 20 | #define MONGOC_STREAM_SOCKET_H 21 | 22 | #include "mongoc-macros.h" 23 | #include "mongoc-socket.h" 24 | #include "mongoc-stream.h" 25 | 26 | 27 | BSON_BEGIN_DECLS 28 | 29 | 30 | typedef struct _mongoc_stream_socket_t mongoc_stream_socket_t; 31 | 32 | 33 | MONGOC_EXPORT (mongoc_stream_t *) 34 | mongoc_stream_socket_new (mongoc_socket_t *socket) BSON_GNUC_WARN_UNUSED_RESULT; 35 | MONGOC_EXPORT (mongoc_socket_t *) 36 | mongoc_stream_socket_get_socket (mongoc_stream_socket_t *stream); 37 | 38 | 39 | BSON_END_DECLS 40 | 41 | 42 | #endif /* MONGOC_STREAM_SOCKET_H */ 43 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-stream-tls-libressl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_STREAM_TLS_LIBRESSL_H 20 | #define MONGOC_STREAM_TLS_LIBRESSL_H 21 | 22 | #ifdef MONGOC_ENABLE_SSL_LIBRESSL 23 | 24 | #include 25 | 26 | #include "mongoc-macros.h" 27 | 28 | BSON_BEGIN_DECLS 29 | 30 | MONGOC_EXPORT (mongoc_stream_t *) 31 | mongoc_stream_tls_libressl_new (mongoc_stream_t *base_stream, 32 | const char *host, 33 | mongoc_ssl_opt_t *opt, 34 | int client) BSON_GNUC_WARN_UNUSED_RESULT; 35 | 36 | BSON_END_DECLS 37 | 38 | #endif /* MONGOC_ENABLE_SSL_LIBRESSL */ 39 | #endif /* MONGOC_STREAM_TLS_LIBRESSL_H */ 40 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-stream-tls-openssl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_STREAM_TLS_OPENSSL_H 20 | #define MONGOC_STREAM_TLS_OPENSSL_H 21 | 22 | #ifdef MONGOC_ENABLE_SSL_OPENSSL 23 | #include 24 | 25 | #include "mongoc-macros.h" 26 | 27 | BSON_BEGIN_DECLS 28 | 29 | MONGOC_EXPORT (mongoc_stream_t *) 30 | mongoc_stream_tls_openssl_new (mongoc_stream_t *base_stream, 31 | const char *host, 32 | mongoc_ssl_opt_t *opt, 33 | int client) BSON_GNUC_WARN_UNUSED_RESULT; 34 | 35 | BSON_END_DECLS 36 | 37 | #endif /* MONGOC_ENABLE_SSL_OPENSSL */ 38 | #endif /* MONGOC_STREAM_TLS_OPENSSL_H */ 39 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-stream-tls.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_STREAM_TLS_H 20 | #define MONGOC_STREAM_TLS_H 21 | 22 | #include 23 | 24 | #include "mongoc-macros.h" 25 | #include "mongoc-ssl.h" 26 | #include "mongoc-stream.h" 27 | 28 | 29 | BSON_BEGIN_DECLS 30 | 31 | typedef struct _mongoc_stream_tls_t mongoc_stream_tls_t; 32 | 33 | MONGOC_EXPORT (bool) 34 | mongoc_stream_tls_handshake (mongoc_stream_t *stream, 35 | const char *host, 36 | int32_t timeout_msec, 37 | int *events, 38 | bson_error_t *error); 39 | MONGOC_EXPORT (bool) 40 | mongoc_stream_tls_handshake_block (mongoc_stream_t *stream, 41 | const char *host, 42 | int32_t timeout_msec, 43 | bson_error_t *error); 44 | MONGOC_EXPORT (bool) 45 | mongoc_stream_tls_do_handshake (mongoc_stream_t *stream, int32_t timeout_msec) 46 | BSON_GNUC_DEPRECATED_FOR (mongoc_stream_tls_handshake); 47 | MONGOC_EXPORT (bool) 48 | mongoc_stream_tls_check_cert (mongoc_stream_t *stream, const char *host) 49 | BSON_GNUC_DEPRECATED_FOR (mongoc_stream_tls_handshake); 50 | MONGOC_EXPORT (mongoc_stream_t *) 51 | mongoc_stream_tls_new_with_hostname (mongoc_stream_t *base_stream, 52 | const char *host, 53 | mongoc_ssl_opt_t *opt, 54 | int client) BSON_GNUC_WARN_UNUSED_RESULT; 55 | MONGOC_EXPORT (mongoc_stream_t *) 56 | mongoc_stream_tls_new (mongoc_stream_t *base_stream, 57 | mongoc_ssl_opt_t *opt, 58 | int client) BSON_GNUC_WARN_UNUSED_RESULT 59 | BSON_GNUC_DEPRECATED_FOR (mongoc_stream_tls_new_with_hostname); 60 | 61 | 62 | BSON_END_DECLS 63 | 64 | 65 | #endif /* MONGOC_STREAM_TLS_H */ 66 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_STREAM_H 20 | #define MONGOC_STREAM_H 21 | 22 | #include "mongoc-macros.h" 23 | #include "mongoc-iovec.h" 24 | #include "mongoc-socket.h" 25 | 26 | 27 | BSON_BEGIN_DECLS 28 | 29 | 30 | typedef struct _mongoc_stream_t mongoc_stream_t; 31 | 32 | typedef struct _mongoc_stream_poll_t { 33 | mongoc_stream_t *stream; 34 | int events; 35 | int revents; 36 | } mongoc_stream_poll_t; 37 | 38 | struct _mongoc_stream_t { 39 | int type; 40 | void (*destroy) (mongoc_stream_t *stream); 41 | int (*close) (mongoc_stream_t *stream); 42 | int (*flush) (mongoc_stream_t *stream); 43 | ssize_t (*writev) (mongoc_stream_t *stream, 44 | mongoc_iovec_t *iov, 45 | size_t iovcnt, 46 | int32_t timeout_msec); 47 | ssize_t (*readv) (mongoc_stream_t *stream, 48 | mongoc_iovec_t *iov, 49 | size_t iovcnt, 50 | size_t min_bytes, 51 | int32_t timeout_msec); 52 | int (*setsockopt) (mongoc_stream_t *stream, 53 | int level, 54 | int optname, 55 | void *optval, 56 | mongoc_socklen_t optlen); 57 | mongoc_stream_t *(*get_base_stream) (mongoc_stream_t *stream); 58 | bool (*check_closed) (mongoc_stream_t *stream); 59 | ssize_t (*poll) (mongoc_stream_poll_t *streams, 60 | size_t nstreams, 61 | int32_t timeout); 62 | void (*failed) (mongoc_stream_t *stream); 63 | bool (*timed_out) (mongoc_stream_t *stream); 64 | bool (*should_retry) (mongoc_stream_t *stream); 65 | void *padding[3]; 66 | }; 67 | 68 | 69 | MONGOC_EXPORT (mongoc_stream_t *) 70 | mongoc_stream_get_base_stream (mongoc_stream_t *stream); 71 | MONGOC_EXPORT (mongoc_stream_t *) 72 | mongoc_stream_get_tls_stream (mongoc_stream_t *stream); 73 | MONGOC_EXPORT (int) 74 | mongoc_stream_close (mongoc_stream_t *stream); 75 | MONGOC_EXPORT (void) 76 | mongoc_stream_destroy (mongoc_stream_t *stream); 77 | MONGOC_EXPORT (void) 78 | mongoc_stream_failed (mongoc_stream_t *stream); 79 | MONGOC_EXPORT (int) 80 | mongoc_stream_flush (mongoc_stream_t *stream); 81 | MONGOC_EXPORT (ssize_t) 82 | mongoc_stream_writev (mongoc_stream_t *stream, 83 | mongoc_iovec_t *iov, 84 | size_t iovcnt, 85 | int32_t timeout_msec); 86 | MONGOC_EXPORT (ssize_t) 87 | mongoc_stream_write (mongoc_stream_t *stream, 88 | void *buf, 89 | size_t count, 90 | int32_t timeout_msec); 91 | MONGOC_EXPORT (ssize_t) 92 | mongoc_stream_readv (mongoc_stream_t *stream, 93 | mongoc_iovec_t *iov, 94 | size_t iovcnt, 95 | size_t min_bytes, 96 | int32_t timeout_msec); 97 | MONGOC_EXPORT (ssize_t) 98 | mongoc_stream_read (mongoc_stream_t *stream, 99 | void *buf, 100 | size_t count, 101 | size_t min_bytes, 102 | int32_t timeout_msec); 103 | MONGOC_EXPORT (int) 104 | mongoc_stream_setsockopt (mongoc_stream_t *stream, 105 | int level, 106 | int optname, 107 | void *optval, 108 | mongoc_socklen_t optlen); 109 | MONGOC_EXPORT (bool) 110 | mongoc_stream_check_closed (mongoc_stream_t *stream); 111 | MONGOC_EXPORT (bool) 112 | mongoc_stream_timed_out (mongoc_stream_t *stream); 113 | MONGOC_EXPORT (bool) 114 | mongoc_stream_should_retry (mongoc_stream_t *stream); 115 | MONGOC_EXPORT (ssize_t) 116 | mongoc_stream_poll (mongoc_stream_poll_t *streams, 117 | size_t nstreams, 118 | int32_t timeout); 119 | 120 | 121 | BSON_END_DECLS 122 | 123 | 124 | #endif /* MONGOC_STREAM_H */ 125 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-topology-description.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_TOPOLOGY_DESCRIPTION_H 20 | #define MONGOC_TOPOLOGY_DESCRIPTION_H 21 | 22 | #include 23 | 24 | #include "mongoc-macros.h" 25 | #include "mongoc-read-prefs.h" 26 | 27 | 28 | BSON_BEGIN_DECLS 29 | 30 | typedef struct _mongoc_topology_description_t mongoc_topology_description_t; 31 | 32 | MONGOC_EXPORT (void) 33 | mongoc_topology_description_destroy ( 34 | mongoc_topology_description_t *description); 35 | 36 | MONGOC_EXPORT (mongoc_topology_description_t *) 37 | mongoc_topology_description_new_copy ( 38 | const mongoc_topology_description_t *description) 39 | BSON_GNUC_WARN_UNUSED_RESULT; 40 | 41 | MONGOC_EXPORT (bool) 42 | mongoc_topology_description_has_readable_server ( 43 | const mongoc_topology_description_t *td, const mongoc_read_prefs_t *prefs); 44 | 45 | MONGOC_EXPORT (bool) 46 | mongoc_topology_description_has_writable_server ( 47 | const mongoc_topology_description_t *td); 48 | 49 | MONGOC_EXPORT (const char *) 50 | mongoc_topology_description_type (const mongoc_topology_description_t *td); 51 | 52 | MONGOC_EXPORT (mongoc_server_description_t **) 53 | mongoc_topology_description_get_servers ( 54 | const mongoc_topology_description_t *td, 55 | size_t *n) BSON_GNUC_WARN_UNUSED_RESULT; 56 | 57 | BSON_END_DECLS 58 | 59 | #endif /* MONGOC_TOPOLOGY_DESCRIPTION_H */ 60 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-version-functions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | 20 | #ifndef MONGOC_VERSION_FUNCTIONS_H 21 | #define MONGOC_VERSION_FUNCTIONS_H 22 | 23 | #include /* for "bool" */ 24 | 25 | #include "mongoc-macros.h" 26 | 27 | BSON_BEGIN_DECLS 28 | 29 | MONGOC_EXPORT (int) 30 | mongoc_get_major_version (void); 31 | MONGOC_EXPORT (int) 32 | mongoc_get_minor_version (void); 33 | MONGOC_EXPORT (int) 34 | mongoc_get_micro_version (void); 35 | MONGOC_EXPORT (const char *) 36 | mongoc_get_version (void); 37 | MONGOC_EXPORT (bool) 38 | mongoc_check_version (int required_major, 39 | int required_minor, 40 | int required_micro); 41 | 42 | BSON_END_DECLS 43 | 44 | #endif /* MONGOC_VERSION_FUNCTIONS_H */ 45 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | #if !defined (MONGOC_INSIDE) && !defined (MONGOC_COMPILATION) 19 | #error "Only can be included directly." 20 | #endif 21 | 22 | 23 | #ifndef MONGOC_VERSION_H 24 | #define MONGOC_VERSION_H 25 | 26 | 27 | /** 28 | * MONGOC_MAJOR_VERSION: 29 | * 30 | * MONGOC major version component (e.g. 1 if %MONGOC_VERSION is 1.2.3) 31 | */ 32 | #define MONGOC_MAJOR_VERSION (1) 33 | 34 | 35 | /** 36 | * MONGOC_MINOR_VERSION: 37 | * 38 | * MONGOC minor version component (e.g. 2 if %MONGOC_VERSION is 1.2.3) 39 | */ 40 | #define MONGOC_MINOR_VERSION (21) 41 | 42 | 43 | /** 44 | * MONGOC_MICRO_VERSION: 45 | * 46 | * MONGOC micro version component (e.g. 3 if %MONGOC_VERSION is 1.2.3) 47 | */ 48 | #define MONGOC_MICRO_VERSION (0) 49 | 50 | 51 | /** 52 | * MONGOC_PRERELEASE_VERSION: 53 | * 54 | * MONGOC prerelease version component (e.g. pre if %MONGOC_VERSION is 1.2.3-pre) 55 | */ 56 | #define MONGOC_PRERELEASE_VERSION () 57 | 58 | 59 | /** 60 | * MONGOC_VERSION: 61 | * 62 | * MONGOC version. 63 | */ 64 | #define MONGOC_VERSION (1.21.0) 65 | 66 | 67 | /** 68 | * MONGOC_VERSION_S: 69 | * 70 | * MONGOC version, encoded as a string, useful for printing and 71 | * concatenation. 72 | */ 73 | #define MONGOC_VERSION_S "1.21.0" 74 | 75 | 76 | /** 77 | * MONGOC_VERSION_HEX: 78 | * 79 | * MONGOC version, encoded as an hexadecimal number, useful for 80 | * integer comparisons. 81 | */ 82 | #define MONGOC_VERSION_HEX (MONGOC_MAJOR_VERSION << 24 | \ 83 | MONGOC_MINOR_VERSION << 16 | \ 84 | MONGOC_MICRO_VERSION << 8) 85 | 86 | 87 | /** 88 | * MONGOC_CHECK_VERSION: 89 | * @major: required major version 90 | * @minor: required minor version 91 | * @micro: required micro version 92 | * 93 | * Compile-time version checking. Evaluates to %TRUE if the version 94 | * of MONGOC is greater than the required one. 95 | */ 96 | #define MONGOC_CHECK_VERSION(major,minor,micro) \ 97 | (MONGOC_MAJOR_VERSION > (major) || \ 98 | (MONGOC_MAJOR_VERSION == (major) && MONGOC_MINOR_VERSION > (minor)) || \ 99 | (MONGOC_MAJOR_VERSION == (major) && MONGOC_MINOR_VERSION == (minor) && \ 100 | MONGOC_MICRO_VERSION >= (micro))) 101 | 102 | #endif /* MONGOC_VERSION_H */ 103 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc-write-concern.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "mongoc-prelude.h" 18 | 19 | #ifndef MONGOC_WRITE_CONCERN_H 20 | #define MONGOC_WRITE_CONCERN_H 21 | 22 | #include 23 | 24 | #include "mongoc-macros.h" 25 | 26 | BSON_BEGIN_DECLS 27 | 28 | 29 | #define MONGOC_WRITE_CONCERN_W_UNACKNOWLEDGED 0 30 | #define MONGOC_WRITE_CONCERN_W_ERRORS_IGNORED -1 /* deprecated */ 31 | #define MONGOC_WRITE_CONCERN_W_DEFAULT -2 32 | #define MONGOC_WRITE_CONCERN_W_MAJORITY -3 33 | #define MONGOC_WRITE_CONCERN_W_TAG -4 34 | 35 | 36 | typedef struct _mongoc_write_concern_t mongoc_write_concern_t; 37 | 38 | 39 | MONGOC_EXPORT (mongoc_write_concern_t *) 40 | mongoc_write_concern_new (void) BSON_GNUC_WARN_UNUSED_RESULT; 41 | MONGOC_EXPORT (mongoc_write_concern_t *) 42 | mongoc_write_concern_copy (const mongoc_write_concern_t *write_concern) 43 | BSON_GNUC_WARN_UNUSED_RESULT; 44 | MONGOC_EXPORT (void) 45 | mongoc_write_concern_destroy (mongoc_write_concern_t *write_concern); 46 | MONGOC_EXPORT (bool) 47 | mongoc_write_concern_get_fsync (const mongoc_write_concern_t *write_concern) 48 | BSON_GNUC_DEPRECATED; 49 | MONGOC_EXPORT (void) 50 | mongoc_write_concern_set_fsync (mongoc_write_concern_t *write_concern, 51 | bool fsync_) BSON_GNUC_DEPRECATED; 52 | MONGOC_EXPORT (bool) 53 | mongoc_write_concern_get_journal (const mongoc_write_concern_t *write_concern); 54 | MONGOC_EXPORT (bool) 55 | mongoc_write_concern_journal_is_set ( 56 | const mongoc_write_concern_t *write_concern); 57 | MONGOC_EXPORT (void) 58 | mongoc_write_concern_set_journal (mongoc_write_concern_t *write_concern, 59 | bool journal); 60 | MONGOC_EXPORT (int32_t) 61 | mongoc_write_concern_get_w (const mongoc_write_concern_t *write_concern); 62 | MONGOC_EXPORT (void) 63 | mongoc_write_concern_set_w (mongoc_write_concern_t *write_concern, int32_t w); 64 | MONGOC_EXPORT (const char *) 65 | mongoc_write_concern_get_wtag (const mongoc_write_concern_t *write_concern); 66 | MONGOC_EXPORT (void) 67 | mongoc_write_concern_set_wtag (mongoc_write_concern_t *write_concern, 68 | const char *tag); 69 | MONGOC_EXPORT (int32_t) 70 | mongoc_write_concern_get_wtimeout (const mongoc_write_concern_t *write_concern); 71 | MONGOC_EXPORT (int64_t) 72 | mongoc_write_concern_get_wtimeout_int64 ( 73 | const mongoc_write_concern_t *write_concern); 74 | MONGOC_EXPORT (void) 75 | mongoc_write_concern_set_wtimeout (mongoc_write_concern_t *write_concern, 76 | int32_t wtimeout_msec); 77 | MONGOC_EXPORT (void) 78 | mongoc_write_concern_set_wtimeout_int64 (mongoc_write_concern_t *write_concern, 79 | int64_t wtimeout_msec); 80 | MONGOC_EXPORT (bool) 81 | mongoc_write_concern_get_wmajority ( 82 | const mongoc_write_concern_t *write_concern); 83 | MONGOC_EXPORT (void) 84 | mongoc_write_concern_set_wmajority (mongoc_write_concern_t *write_concern, 85 | int32_t wtimeout_msec); 86 | MONGOC_EXPORT (bool) 87 | mongoc_write_concern_is_acknowledged ( 88 | const mongoc_write_concern_t *write_concern); 89 | MONGOC_EXPORT (bool) 90 | mongoc_write_concern_is_valid (const mongoc_write_concern_t *write_concern); 91 | MONGOC_EXPORT (bool) 92 | mongoc_write_concern_append (mongoc_write_concern_t *write_concern, 93 | bson_t *doc); 94 | MONGOC_EXPORT (bool) 95 | mongoc_write_concern_is_default (const mongoc_write_concern_t *write_concern); 96 | 97 | BSON_END_DECLS 98 | 99 | 100 | #endif /* MONGOC_WRITE_CONCERN_H */ 101 | -------------------------------------------------------------------------------- /src/thirdparty/libmongoc-1.0/mongoc/mongoc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 MongoDB, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | #ifndef MONGOC_H 19 | #define MONGOC_H 20 | 21 | 22 | #include 23 | 24 | #define MONGOC_INSIDE 25 | #include "mongoc-macros.h" 26 | #include "mongoc-apm.h" 27 | #include "mongoc-bulk-operation.h" 28 | #include "mongoc-change-stream.h" 29 | #include "mongoc-client.h" 30 | #include "mongoc-client-pool.h" 31 | #include "mongoc-client-side-encryption.h" 32 | #include "mongoc-collection.h" 33 | #include "mongoc-config.h" 34 | #include "mongoc-cursor.h" 35 | #include "mongoc-database.h" 36 | #include "mongoc-index.h" 37 | #include "mongoc-error.h" 38 | #include "mongoc-flags.h" 39 | #include "mongoc-gridfs.h" 40 | #include "mongoc-gridfs-bucket.h" 41 | #include "mongoc-gridfs-file.h" 42 | #include "mongoc-gridfs-file-list.h" 43 | #include "mongoc-gridfs-file-page.h" 44 | #include "mongoc-host-list.h" 45 | #include "mongoc-init.h" 46 | #include "mongoc-matcher.h" 47 | #include "mongoc-handshake.h" 48 | #include "mongoc-opcode.h" 49 | #include "mongoc-log.h" 50 | #include "mongoc-socket.h" 51 | #include "mongoc-client-session.h" 52 | #include "mongoc-stream.h" 53 | #include "mongoc-stream-buffered.h" 54 | #include "mongoc-stream-file.h" 55 | #include "mongoc-stream-gridfs.h" 56 | #include "mongoc-stream-socket.h" 57 | #include "mongoc-uri.h" 58 | #include "mongoc-write-concern.h" 59 | #include "mongoc-version.h" 60 | #include "mongoc-version-functions.h" 61 | #ifdef MONGOC_ENABLE_SSL 62 | #include "mongoc-rand.h" 63 | #include "mongoc-stream-tls.h" 64 | #include "mongoc-ssl.h" 65 | #endif 66 | #undef MONGOC_INSIDE 67 | 68 | 69 | #endif /* MONGOC_H */ 70 | -------------------------------------------------------------------------------- /src/uri.v: -------------------------------------------------------------------------------- 1 | module mongo 2 | 3 | pub fn uri_new(uri string) &C.mongoc_uri_t { 4 | return C.mongoc_uri_new(uri.str) 5 | } 6 | 7 | // // useless 8 | // pub fn (uri &C.mongoc_uri_t) new_client() &C.mongoc_client_t { 9 | // mut error := C.bson_error_t{} 10 | // client := C.mongoc_client_new_from_uri_with_error(uri, &error) 11 | // unsafe{println('error.message: $error.message.vstring()')} 12 | // return client 13 | // } 14 | 15 | pub fn (uri &C.mongoc_uri_t) destroy() { 16 | C.mongoc_uri_destroy(uri) 17 | } 18 | -------------------------------------------------------------------------------- /src/v.mod: -------------------------------------------------------------------------------- 1 | Module { 2 | name: 'mongo' 3 | description: 'V mongoDB C wrapper' 4 | version: '0.0.4' 5 | license: 'MIT' 6 | repo_url: 'https://github.com/vlang/mongo' 7 | dependencies: [] 8 | } --------------------------------------------------------------------------------