1 /*
2 *
3 * Copyright 2019 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 "absl/container/inlined_vector.h"
20
21 #include <grpcpp/security/tls_credentials_options.h>
22
23 #include "src/cpp/common/tls_credentials_options_util.h"
24
25 namespace grpc {
26 namespace experimental {
27
28 /** The C schedule and cancel functions for the server authorization check
29 * config. They populate a C server authorization check arg with the result
30 * of a C++ server authorization check schedule/cancel API. **/
TlsServerAuthorizationCheckConfigCSchedule(void *,grpc_tls_server_authorization_check_arg * arg)31 int TlsServerAuthorizationCheckConfigCSchedule(
32 void* /*config_user_data*/, grpc_tls_server_authorization_check_arg* arg) {
33 if (arg == nullptr || arg->config == nullptr ||
34 arg->config->context() == nullptr) {
35 gpr_log(GPR_ERROR,
36 "server authorization check arg was not properly initialized");
37 return 1;
38 }
39 TlsServerAuthorizationCheckConfig* cpp_config =
40 static_cast<TlsServerAuthorizationCheckConfig*>(arg->config->context());
41 TlsServerAuthorizationCheckArg* cpp_arg =
42 new TlsServerAuthorizationCheckArg(arg);
43 int schedule_result = cpp_config->Schedule(cpp_arg);
44 return schedule_result;
45 }
46
TlsServerAuthorizationCheckConfigCCancel(void *,grpc_tls_server_authorization_check_arg * arg)47 void TlsServerAuthorizationCheckConfigCCancel(
48 void* /*config_user_data*/, grpc_tls_server_authorization_check_arg* arg) {
49 if (arg == nullptr || arg->config == nullptr ||
50 arg->config->context() == nullptr) {
51 gpr_log(GPR_ERROR,
52 "server authorization check arg was not properly initialized");
53 return;
54 }
55 if (arg->context == nullptr) {
56 gpr_log(GPR_ERROR,
57 "server authorization check arg schedule has already completed");
58 return;
59 }
60 TlsServerAuthorizationCheckConfig* cpp_config =
61 static_cast<TlsServerAuthorizationCheckConfig*>(arg->config->context());
62 TlsServerAuthorizationCheckArg* cpp_arg =
63 static_cast<TlsServerAuthorizationCheckArg*>(arg->context);
64 cpp_config->Cancel(cpp_arg);
65 }
66
TlsServerAuthorizationCheckArgDestroyContext(void * context)67 void TlsServerAuthorizationCheckArgDestroyContext(void* context) {
68 if (context != nullptr) {
69 TlsServerAuthorizationCheckArg* cpp_arg =
70 static_cast<TlsServerAuthorizationCheckArg*>(context);
71 delete cpp_arg;
72 }
73 }
74
75 } // namespace experimental
76 } // namespace grpc
77