File: util.h

package info (click to toggle)
libmongocrypt 1.17.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,572 kB
  • sloc: ansic: 70,067; python: 4,547; cpp: 615; sh: 460; makefile: 44; awk: 8
file content (75 lines) | stat: -rw-r--r-- 2,878 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 * Copyright 2020-present MongoDB, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdlib.h>

#include "mongocrypt.h"
#include <mongoc/mongoc.h>

void _errexit_mongocrypt(mongocrypt_t *crypt, int line);
#define ERREXIT_MONGOCRYPT(crypt) _errexit_mongocrypt(crypt, __LINE__)

void _errexit_ctx(mongocrypt_ctx_t *ctx, int line);
#define ERREXIT_CTX(ctx) _errexit_ctx(ctx, __LINE__)

void _errexit_bson(bson_error_t *error, int line);
#define ERREXIT_BSON(err) _errexit_bson(err, __LINE__)

#define ERREXIT(...)                                                                                                   \
    if (1) {                                                                                                           \
        MONGOC_ERROR(__VA_ARGS__);                                                                                     \
        abort();                                                                                                       \
    } else                                                                                                             \
        ((void)0)

void _log_to_stdout(mongocrypt_log_level_t level, const char *message, uint32_t message_len, void *ctx);

char *util_getenv(const char *key);

mongocrypt_binary_t *util_bson_to_bin(bson_t *bson);

typedef struct {
    mongocrypt_ctx_t *ctx;
    mongoc_collection_t *keyvault_coll;
    mongoc_client_t *mongocryptd_client;
    mongoc_client_t *collinfo_client;
    const char *db_name;
    bool trace;
    const char *tls_ca_file;
    const char *tls_certificate_key_file;
} _state_machine_t;

bool _csfle_state_machine_run(_state_machine_t *state_machine, bson_t *result, bson_error_t *error);

bson_t *util_bin_to_bson(mongocrypt_binary_t *bin);

bson_t *util_read_json_file(const char *path);

void args_parse(bson_t *args, int argc, char **argv);

const char *bson_get_utf8(bson_t *bson, const char *key, const char *default_value);

const char *bson_req_utf8(bson_t *bson, const char *key);

const uint8_t *bson_get_bin(bson_t *bson, const char *dotkey, uint32_t *len);

const uint8_t *bson_req_bin(bson_t *bson, const char *dotkey, uint32_t *len);

bson_t *bson_get_json(bson_t *bson, const char *key);

bson_t *bson_req_json(bson_t *bson, const char *key);

bool bson_get_bool(bson_t *bson, const char *key, bool default_value);