Debian Codegraph @

crt/aws-c-auth/source/credentials_provider_delegate.c

raw symbols SCIP
1 /**
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0.
4 */
5
6 #include <aws/auth/private/credentials_utils.h>
7
8 struct aws_credentials_provider_delegate_impl {
9 aws_credentials_provider_delegate_get_credentials_fn *get_credentials;
10 void *user_data;
11 };
12
13 static int s_credentials_provider_delegate_get_credentials(
14 struct aws_credentials_provider *provider,
15 aws_on_get_credentials_callback_fn callback,
16 void *callback_user_data) {
17
18 struct aws_credentials_provider_delegate_impl *impl = provider->impl;
19 return impl->get_credentials(impl->user_data, callback, callback_user_data);
20 }
21
22 static void s_credentials_provider_delegate_destroy(struct aws_credentials_provider *provider) {
23 aws_credentials_provider_invoke_shutdown_callback(provider);
24 aws_mem_release(provider->allocator, provider);
25 }
26
27 static struct aws_credentials_provider_vtable s_credentials_provider_delegate_vtable = {
28 .get_credentials = s_credentials_provider_delegate_get_credentials,
29 .destroy = s_credentials_provider_delegate_destroy,
30 };
31
32 struct aws_credentials_provider *aws_credentials_provider_new_delegate(
33 struct aws_allocator *allocator,
34 const struct aws_credentials_provider_delegate_options *options) {
35
36 AWS_ASSERT(options);
37 AWS_ASSERT(options->get_credentials);
38
39 struct aws_credentials_provider *provider = NULL;
40 struct aws_credentials_provider_delegate_impl *impl = NULL;
41
42 aws_mem_acquire_many(
43 allocator,
44 2,
45 &provider,
46 sizeof(struct aws_credentials_provider),
47 &impl,
48 sizeof(struct aws_credentials_provider_delegate_impl));
49
50 if (!provider) {
51 return NULL;
52 }
53
54 AWS_ZERO_STRUCT(*provider);
55 AWS_ZERO_STRUCT(*impl);
56
57 aws_credentials_provider_init_base(provider, allocator, &s_credentials_provider_delegate_vtable, impl);
58 provider->shutdown_options = options->shutdown_options;
59
60 impl->get_credentials = options->get_credentials;
61 impl->user_data = options->delegate_user_data;
62
63 return provider;
64 }