1 /* 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 29 namespace grpc_core { 30 namespace { 31 32 void* 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 } 39 void target_authority_table_destroy(void* p) { 40 TargetAuthorityTable* table = static_cast<TargetAuthorityTable*>(p); 41 table->Unref(); 42 } 43 int 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 } 48 const 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 54 grpc_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 60 TargetAuthorityTable* FindTargetAuthorityTableInArgs( 61 const grpc_channel_args* args) { 62 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; 73 } 74 75 } // namespace grpc_core 76