blob: 1eeb557f6a4b7985bd64e4073f8c448b1ed7e34d [file] [log] [blame]
Mark D. Roth3e7f2df2018-02-26 13:17:06 -08001/*
2 *
3 * Copyright 2017 gRPC authors.
4 *
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
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
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.
16 *
17 */
18
19#include <grpc/support/port_platform.h>
20
21#include <grpc/support/log.h>
22
23#include "src/core/lib/channel/channel_args.h"
24#include "src/core/lib/security/transport/target_authority_table.h"
25
26// Channel arg key for the mapping of target addresses to their authorities.
27#define GRPC_ARG_TARGET_AUTHORITY_TABLE "grpc.target_authority_table"
28
29namespace grpc_core {
30namespace {
31
32void* target_authority_table_copy(void* p) {
33 TargetAuthorityTable* table = static_cast<TargetAuthorityTable*>(p);
34 // TODO(roth): When channel_args are converted to C++, pass the
35 // RefCountedPtr<> directly instead of managing the ref manually.
36 table->Ref().release();
37 return p;
38}
39void target_authority_table_destroy(void* p) {
40 TargetAuthorityTable* table = static_cast<TargetAuthorityTable*>(p);
41 table->Unref();
42}
43int target_authority_table_cmp(void* a, void* b) {
44 return TargetAuthorityTable::Cmp(
45 *static_cast<const TargetAuthorityTable*>(a),
46 *static_cast<const TargetAuthorityTable*>(b));
47}
48const grpc_arg_pointer_vtable target_authority_table_arg_vtable = {
49 target_authority_table_copy, target_authority_table_destroy,
50 target_authority_table_cmp};
51
52} // namespace
53
54grpc_arg CreateTargetAuthorityTableChannelArg(TargetAuthorityTable* table) {
55 return grpc_channel_arg_pointer_create((char*)GRPC_ARG_TARGET_AUTHORITY_TABLE,
56 table,
57 &target_authority_table_arg_vtable);
58}
59
60TargetAuthorityTable* FindTargetAuthorityTableInArgs(
61 const grpc_channel_args* args) {
Noah Eisen7ea8a602018-06-14 11:43:18 -040062 const grpc_arg* arg =
63 grpc_channel_args_find(args, GRPC_ARG_TARGET_AUTHORITY_TABLE);
64 if (arg != nullptr) {
65 if (arg->type == GRPC_ARG_POINTER) {
66 return static_cast<TargetAuthorityTable*>(arg->value.pointer.p);
67 } else {
68 gpr_log(GPR_ERROR, "value of " GRPC_ARG_TARGET_AUTHORITY_TABLE
69 " channel arg was not pointer type; ignoring");
70 }
71 }
72 return nullptr;
Mark D. Roth3e7f2df2018-02-26 13:17:06 -080073}
74
75} // namespace grpc_core