Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright 2014, Google Inc. |
| 4 | * 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 | |
yangg | 59dfc90 | 2014-12-19 14:00:14 -0800 | [diff] [blame] | 34 | #include <grpc++/channel_arguments.h> |
nnoble | 0c475f0 | 2014-12-05 15:37:39 -0800 | [diff] [blame] | 35 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 36 | #include <grpc/grpc_security.h> |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 37 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 38 | namespace grpc { |
| 39 | |
Craig Tiller | ecd4934 | 2015-01-18 14:36:47 -0800 | [diff] [blame] | 40 | void ChannelArguments::SetSslTargetNameOverride(const grpc::string &name) { |
yangg | 59dfc90 | 2014-12-19 14:00:14 -0800 | [diff] [blame] | 41 | SetString(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG, name); |
| 42 | } |
| 43 | |
yangg | 7cebec7 | 2014-12-22 12:47:45 -0800 | [diff] [blame] | 44 | grpc::string ChannelArguments::GetSslTargetNameOverride() const { |
chenw | a49839f | 2014-12-22 15:30:25 -0800 | [diff] [blame] | 45 | for (unsigned int i = 0; i < args_.size(); i++) { |
yangg | 7cebec7 | 2014-12-22 12:47:45 -0800 | [diff] [blame] | 46 | 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 Tiller | ecd4934 | 2015-01-18 14:36:47 -0800 | [diff] [blame] | 53 | void ChannelArguments::SetInt(const grpc::string &key, int value) { |
yangg | 59dfc90 | 2014-12-19 14:00:14 -0800 | [diff] [blame] | 54 | grpc_arg arg; |
| 55 | arg.type = GRPC_ARG_INTEGER; |
| 56 | strings_.push_back(key); |
Craig Tiller | ecd4934 | 2015-01-18 14:36:47 -0800 | [diff] [blame] | 57 | arg.key = const_cast<char *>(strings_.back().c_str()); |
yangg | 59dfc90 | 2014-12-19 14:00:14 -0800 | [diff] [blame] | 58 | arg.value.integer = value; |
| 59 | |
| 60 | args_.push_back(arg); |
| 61 | } |
| 62 | |
Craig Tiller | ecd4934 | 2015-01-18 14:36:47 -0800 | [diff] [blame] | 63 | void ChannelArguments::SetString(const grpc::string &key, |
| 64 | const grpc::string &value) { |
yangg | 59dfc90 | 2014-12-19 14:00:14 -0800 | [diff] [blame] | 65 | grpc_arg arg; |
| 66 | arg.type = GRPC_ARG_STRING; |
| 67 | strings_.push_back(key); |
Craig Tiller | ecd4934 | 2015-01-18 14:36:47 -0800 | [diff] [blame] | 68 | arg.key = const_cast<char *>(strings_.back().c_str()); |
yangg | 59dfc90 | 2014-12-19 14:00:14 -0800 | [diff] [blame] | 69 | strings_.push_back(value); |
Craig Tiller | ecd4934 | 2015-01-18 14:36:47 -0800 | [diff] [blame] | 70 | arg.value.string = const_cast<char *>(strings_.back().c_str()); |
yangg | 59dfc90 | 2014-12-19 14:00:14 -0800 | [diff] [blame] | 71 | |
| 72 | args_.push_back(arg); |
| 73 | } |
| 74 | |
Craig Tiller | ecd4934 | 2015-01-18 14:36:47 -0800 | [diff] [blame] | 75 | void ChannelArguments::SetChannelArgs(grpc_channel_args *channel_args) const { |
yangg | 59dfc90 | 2014-12-19 14:00:14 -0800 | [diff] [blame] | 76 | channel_args->num_args = args_.size(); |
| 77 | if (channel_args->num_args > 0) { |
Craig Tiller | ecd4934 | 2015-01-18 14:36:47 -0800 | [diff] [blame] | 78 | channel_args->args = const_cast<grpc_arg *>(&args_[0]); |
yangg | 59dfc90 | 2014-12-19 14:00:14 -0800 | [diff] [blame] | 79 | } |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | } // namespace grpc |