auth_property_iterator.cc 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. *
  3. * Copyright 2015, 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. #include <grpc++/security/auth_context.h>
  34. #include <grpc/grpc_security.h>
  35. namespace grpc {
  36. AuthPropertyIterator::AuthPropertyIterator()
  37. : property_(nullptr), ctx_(nullptr), index_(0), name_(nullptr) {}
  38. AuthPropertyIterator::AuthPropertyIterator(
  39. const grpc_auth_property* property, const grpc_auth_property_iterator* iter)
  40. : property_(property),
  41. ctx_(iter->ctx),
  42. index_(iter->index),
  43. name_(iter->name) {}
  44. AuthPropertyIterator::~AuthPropertyIterator() {}
  45. AuthPropertyIterator& AuthPropertyIterator::operator++() {
  46. grpc_auth_property_iterator iter = {ctx_, index_, name_};
  47. property_ = grpc_auth_property_iterator_next(&iter);
  48. ctx_ = iter.ctx;
  49. index_ = iter.index;
  50. name_ = iter.name;
  51. return *this;
  52. }
  53. AuthPropertyIterator AuthPropertyIterator::operator++(int) {
  54. AuthPropertyIterator tmp(*this);
  55. operator++();
  56. return tmp;
  57. }
  58. bool AuthPropertyIterator::operator==(const AuthPropertyIterator& rhs) const {
  59. if (property_ == nullptr || rhs.property_ == nullptr) {
  60. return property_ == rhs.property_;
  61. } else {
  62. return index_ == rhs.index_;
  63. }
  64. }
  65. bool AuthPropertyIterator::operator!=(const AuthPropertyIterator& rhs) const {
  66. return !operator==(rhs);
  67. }
  68. const AuthProperty AuthPropertyIterator::operator*() {
  69. return std::pair<grpc::string_ref, grpc::string_ref>(
  70. property_->name,
  71. grpc::string_ref(property_->value, property_->value_length));
  72. }
  73. } // namespace grpc