blob: abf0fc1c0ad7a44dfb59d619d66c1cdfbadfbd7d [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001/*
2 *
Craig Tiller06059952015-02-18 08:34:56 -08003 * Copyright 2015, Google Inc.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08004 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
yangg59dfc902014-12-19 14:00:14 -080034#include <grpc++/channel_arguments.h>
nnoble0c475f02014-12-05 15:37:39 -080035
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080036#include <grpc/grpc_security.h>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080037
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080038namespace grpc {
39
Craig Tillerecd49342015-01-18 14:36:47 -080040void ChannelArguments::SetSslTargetNameOverride(const grpc::string &name) {
yangg59dfc902014-12-19 14:00:14 -080041 SetString(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG, name);
42}
43
yangg7cebec72014-12-22 12:47:45 -080044grpc::string ChannelArguments::GetSslTargetNameOverride() const {
chenwa49839f2014-12-22 15:30:25 -080045 for (unsigned int i = 0; i < args_.size(); i++) {
yangg7cebec72014-12-22 12:47:45 -080046 if (grpc::string(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG) == args_[i].key) {
47 return args_[i].value.string;
48 }
49 }
50 return "";
51}
52
Craig Tillerecd49342015-01-18 14:36:47 -080053void ChannelArguments::SetInt(const grpc::string &key, int value) {
yangg59dfc902014-12-19 14:00:14 -080054 grpc_arg arg;
55 arg.type = GRPC_ARG_INTEGER;
56 strings_.push_back(key);
Craig Tillerecd49342015-01-18 14:36:47 -080057 arg.key = const_cast<char *>(strings_.back().c_str());
yangg59dfc902014-12-19 14:00:14 -080058 arg.value.integer = value;
59
60 args_.push_back(arg);
61}
62
Craig Tillerecd49342015-01-18 14:36:47 -080063void ChannelArguments::SetString(const grpc::string &key,
64 const grpc::string &value) {
yangg59dfc902014-12-19 14:00:14 -080065 grpc_arg arg;
66 arg.type = GRPC_ARG_STRING;
67 strings_.push_back(key);
Craig Tillerecd49342015-01-18 14:36:47 -080068 arg.key = const_cast<char *>(strings_.back().c_str());
yangg59dfc902014-12-19 14:00:14 -080069 strings_.push_back(value);
Craig Tillerecd49342015-01-18 14:36:47 -080070 arg.value.string = const_cast<char *>(strings_.back().c_str());
yangg59dfc902014-12-19 14:00:14 -080071
72 args_.push_back(arg);
73}
74
Craig Tillerecd49342015-01-18 14:36:47 -080075void ChannelArguments::SetChannelArgs(grpc_channel_args *channel_args) const {
yangg59dfc902014-12-19 14:00:14 -080076 channel_args->num_args = args_.size();
77 if (channel_args->num_args > 0) {
Craig Tillerecd49342015-01-18 14:36:47 -080078 channel_args->args = const_cast<grpc_arg *>(&args_[0]);
yangg59dfc902014-12-19 14:00:14 -080079 }
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080080}
81
Craig Tiller190d3602015-02-18 09:23:38 -080082} // namespace grpc