aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cpp/common
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2015-07-17 14:41:12 -0700
committerGravatar Craig Tiller <ctiller@google.com>2015-07-17 14:41:12 -0700
commitc9fef6f521d92ff0b89291c5546b15448444e246 (patch)
tree610a1a63a5ca9e22713b336d51865a99232d3fe6 /src/cpp/common
parenta2c622e25338896cf7658f0803d308f468a549f9 (diff)
parentfea28b79fb0a211b2ea8515dab25db19099ea595 (diff)
Merge github.com:grpc/grpc into no-worries-i-can-wait
Diffstat (limited to 'src/cpp/common')
-rw-r--r--src/cpp/common/auth_property_iterator.cc87
-rw-r--r--src/cpp/common/secure_auth_context.cc16
-rw-r--r--src/cpp/common/secure_auth_context.h4
3 files changed, 107 insertions, 0 deletions
diff --git a/src/cpp/common/auth_property_iterator.cc b/src/cpp/common/auth_property_iterator.cc
new file mode 100644
index 0000000000..e706c6c921
--- /dev/null
+++ b/src/cpp/common/auth_property_iterator.cc
@@ -0,0 +1,87 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <grpc++/auth_property_iterator.h>
+
+#include <grpc/grpc_security.h>
+
+namespace grpc {
+
+AuthPropertyIterator::AuthPropertyIterator()
+ : property_(nullptr), ctx_(nullptr), index_(0), name_(nullptr) {}
+
+AuthPropertyIterator::AuthPropertyIterator(
+ const grpc_auth_property* property, const grpc_auth_property_iterator* iter)
+ : property_(property),
+ ctx_(iter->ctx),
+ index_(iter->index),
+ name_(iter->name) {}
+
+AuthPropertyIterator::~AuthPropertyIterator() {}
+
+AuthPropertyIterator& AuthPropertyIterator::operator++() {
+ grpc_auth_property_iterator iter = {ctx_, index_, name_};
+ property_ = grpc_auth_property_iterator_next(&iter);
+ ctx_ = iter.ctx;
+ index_ = iter.index;
+ name_ = iter.name;
+ return *this;
+}
+
+AuthPropertyIterator AuthPropertyIterator::operator++(int) {
+ AuthPropertyIterator tmp(*this);
+ operator++();
+ return tmp;
+}
+
+bool AuthPropertyIterator::operator==(
+ const AuthPropertyIterator& rhs) const {
+ if (property_ == nullptr || rhs.property_ == nullptr) {
+ return property_ == rhs.property_;
+ } else {
+ return index_ == rhs.index_;
+ }
+}
+
+bool AuthPropertyIterator::operator!=(
+ const AuthPropertyIterator& rhs) const {
+ return !operator==(rhs);
+}
+
+const AuthProperty AuthPropertyIterator::operator*() {
+ return std::make_pair<grpc::string, grpc::string>(
+ grpc::string(property_->name),
+ grpc::string(property_->value, property_->value_length));
+}
+
+} // namespace grpc
diff --git a/src/cpp/common/secure_auth_context.cc b/src/cpp/common/secure_auth_context.cc
index 4513723653..87d7bab75c 100644
--- a/src/cpp/common/secure_auth_context.cc
+++ b/src/cpp/common/secure_auth_context.cc
@@ -77,4 +77,20 @@ std::vector<grpc::string> SecureAuthContext::FindPropertyValues(
return values;
}
+AuthPropertyIterator SecureAuthContext::begin() const {
+ if (ctx_) {
+ grpc_auth_property_iterator iter =
+ grpc_auth_context_property_iterator(ctx_);
+ const grpc_auth_property* property =
+ grpc_auth_property_iterator_next(&iter);
+ return AuthPropertyIterator(property, &iter);
+ } else {
+ return end();
+ }
+}
+
+AuthPropertyIterator SecureAuthContext::end() const {
+ return AuthPropertyIterator();
+}
+
} // namespace grpc
diff --git a/src/cpp/common/secure_auth_context.h b/src/cpp/common/secure_auth_context.h
index bba46803cd..264ed620a3 100644
--- a/src/cpp/common/secure_auth_context.h
+++ b/src/cpp/common/secure_auth_context.h
@@ -53,6 +53,10 @@ class SecureAuthContext GRPC_FINAL : public AuthContext {
std::vector<grpc::string> FindPropertyValues(const grpc::string& name) const
GRPC_OVERRIDE;
+ AuthPropertyIterator begin() const GRPC_OVERRIDE;
+
+ AuthPropertyIterator end() const GRPC_OVERRIDE;
+
private:
grpc_auth_context* ctx_;
};