Skip to content

Commit cf56954

Browse files
authored
CDRIVER-6151 replaced mcd-time.h with mlib utilities (#2168)
* replace use of `mcd-time.h` with `mlib` utilities * remove `mcd-time.h`
1 parent 378b138 commit cf56954

14 files changed

+78
-399
lines changed

src/libmongoc/src/mongoc/mcd-azure.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include <mongoc/mongoc-util-private.h>
2121

2222
#include <mlib/cmp.h>
23+
#include <mlib/duration.h>
24+
#include <mlib/timer.h>
2325

2426
#define AZURE_API_VERSION "2018-02-01"
2527

@@ -122,7 +124,7 @@ mcd_azure_access_token_try_init_from_json_str(mcd_azure_access_token *out,
122124
// which the token will be valid. strtoll() will saturate on range errors
123125
// and return zero on parse errors.
124126
char *parse_end;
125-
long long s = strtoll(expires_in_str, &parse_end, 0);
127+
const long long expires_in = strtoll(expires_in_str, &parse_end, 0);
126128
if (parse_end != expires_in_str + expires_in_len) {
127129
// Did not parse the entire string. Bad
128130
_mongoc_set_error(error,
@@ -132,7 +134,7 @@ mcd_azure_access_token_try_init_from_json_str(mcd_azure_access_token *out,
132134
mlib_in_range(int, expires_in_len) ? (int)expires_in_len : INT_MAX,
133135
expires_in_str);
134136
} else {
135-
out->expires_in = mcd_seconds(s);
137+
out->expires_in = mlib_duration(expires_in, s);
136138
okay = true;
137139
}
138140
}
@@ -174,7 +176,7 @@ mcd_azure_access_token_from_imds(mcd_azure_access_token *const out,
174176
mcd_azure_imds_request req = MCD_AZURE_IMDS_REQUEST_INIT;
175177
mcd_azure_imds_request_init(&req, opt_imds_host, opt_port, opt_extra_headers);
176178

177-
if (!_mongoc_http_send(&req.req, 3 * 1000, false, NULL, &resp, error)) {
179+
if (!_mongoc_http_send(&req.req, mlib_expires_after(mlib_duration(3, s)), false, NULL, &resp, error)) {
178180
goto fail;
179181
}
180182

src/libmongoc/src/mongoc/mcd-azure.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121

2222
#include <mongoc/mongoc-http-private.h>
2323

24-
#include <mongoc/mcd-time.h>
2524
#include <mongoc/mongoc.h>
2625

26+
#include <mlib/duration.h>
27+
2728
/**
2829
* @brief An Azure OAuth2 access token obtained from the Azure API
2930
*/
@@ -36,7 +37,7 @@ typedef struct mcd_azure_access_token {
3637
char *token_type;
3738
/// The duration after which it will the token will expires. This is relative
3839
/// to the "issue time" of the token.
39-
mcd_duration expires_in;
40+
mlib_duration expires_in;
4041
} mcd_azure_access_token;
4142

4243
/**

0 commit comments

Comments
 (0)