3 // Copyright 2020 gRPC authors.
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 #include <grpc/support/port_platform.h>
21 #include "src/core/ext/xds/certificate_provider_registry.h"
23 #include "absl/container/inlined_vector.h"
31 void RegisterCertificateProviderFactory(
32 std::unique_ptr<CertificateProviderFactory> factory) {
33 gpr_log(GPR_DEBUG, "registering certificate provider factory for \"%s\"",
35 for (size_t i = 0; i < factories_.size(); ++i) {
36 GPR_ASSERT(strcmp(factories_[i]->name(), factory->name()) != 0);
38 factories_.push_back(std::move(factory));
41 CertificateProviderFactory* LookupCertificateProviderFactory(
42 absl::string_view name) const {
43 for (size_t i = 0; i < factories_.size(); ++i) {
44 if (name == factories_[i]->name()) {
45 return factories_[i].get();
52 // We currently support 3 factories without doing additional
53 // allocation. This number could be raised if there is a case where
54 // more factories are needed and the additional allocations are
55 // hurting performance (which is unlikely, since these allocations
56 // only occur at gRPC initialization time).
57 absl::InlinedVector<std::unique_ptr<CertificateProviderFactory>, 3>
61 static RegistryState* g_state = nullptr;
66 // CertificateProviderRegistry
69 CertificateProviderFactory*
70 CertificateProviderRegistry::LookupCertificateProviderFactory(
71 absl::string_view name) {
72 GPR_ASSERT(g_state != nullptr);
73 return g_state->LookupCertificateProviderFactory(name);
76 void CertificateProviderRegistry::InitRegistry() {
77 if (g_state == nullptr) g_state = new RegistryState();
80 void CertificateProviderRegistry::ShutdownRegistry() {
85 void CertificateProviderRegistry::RegisterCertificateProviderFactory(
86 std::unique_ptr<CertificateProviderFactory> factory) {
88 g_state->RegisterCertificateProviderFactory(std::move(factory));
91 } // namespace grpc_core
94 // Plugin registration
97 void grpc_certificate_provider_registry_init() {
98 grpc_core::CertificateProviderRegistry::InitRegistry();
101 void grpc_certificate_provider_registry_shutdown() {
102 grpc_core::CertificateProviderRegistry::ShutdownRegistry();