diff options
author | David Garcia Quintas <dgq@google.com> | 2016-01-25 17:32:48 -0800 |
---|---|---|
committer | David Garcia Quintas <dgq@google.com> | 2016-01-25 17:32:48 -0800 |
commit | 2425bbbc5587665112bc372c14f6b5483c902370 (patch) | |
tree | 615d3fb670d87965bd54f2452d302be545a58dd2 /include/grpc++/impl/codegen | |
parent | f48e538003186a539fa6cfcda0b474c7cfbae506 (diff) |
Further work. Compiles. WIP
Diffstat (limited to 'include/grpc++/impl/codegen')
-rw-r--r-- | include/grpc++/impl/codegen/security/auth_context.h | 110 | ||||
-rw-r--r-- | include/grpc++/impl/codegen/server_interface.h | 1 | ||||
-rw-r--r-- | include/grpc++/impl/codegen/string_ref.h | 123 | ||||
-rw-r--r-- | include/grpc++/impl/codegen/sync.h | 45 | ||||
-rw-r--r-- | include/grpc++/impl/codegen/sync_cxx11.h | 49 | ||||
-rw-r--r-- | include/grpc++/impl/codegen/sync_no_cxx11.h | 105 |
6 files changed, 433 insertions, 0 deletions
diff --git a/include/grpc++/impl/codegen/security/auth_context.h b/include/grpc++/impl/codegen/security/auth_context.h new file mode 100644 index 0000000000..75f2482346 --- /dev/null +++ b/include/grpc++/impl/codegen/security/auth_context.h @@ -0,0 +1,110 @@ +/* + * + * 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. + * + */ + +#ifndef GRPCXX_IMPL_CODEGEN_SECURITY_AUTH_CONTEXT_H +#define GRPCXX_IMPL_CODEGEN_SECURITY_AUTH_CONTEXT_H + +#include <iterator> +#include <vector> + +#include <grpc++/impl/codegen/config.h> +#include <grpc++/impl/codegen/string_ref.h> + +struct grpc_auth_context; +struct grpc_auth_property; +struct grpc_auth_property_iterator; + +namespace grpc { +class SecureAuthContext; + +typedef std::pair<grpc::string_ref, grpc::string_ref> AuthProperty; + +class AuthPropertyIterator + : public std::iterator<std::input_iterator_tag, const AuthProperty> { + public: + ~AuthPropertyIterator(); + AuthPropertyIterator& operator++(); + AuthPropertyIterator operator++(int); + bool operator==(const AuthPropertyIterator& rhs) const; + bool operator!=(const AuthPropertyIterator& rhs) const; + const AuthProperty operator*(); + + protected: + AuthPropertyIterator(); + AuthPropertyIterator(const grpc_auth_property* property, + const grpc_auth_property_iterator* iter); + + private: + friend class SecureAuthContext; + const grpc_auth_property* property_; + // The following items form a grpc_auth_property_iterator. + const grpc_auth_context* ctx_; + size_t index_; + const char* name_; +}; + +/// Class encapsulating the Authentication Information. +/// +/// It includes the secure identity of the peer, the type of secure transport +/// used as well as any other properties required by the authorization layer. +class AuthContext { + public: + virtual ~AuthContext() {} + + /// Returns true if the peer is authenticated. + virtual bool IsPeerAuthenticated() const = 0; + + /// A peer identity. + /// + /// It is, in general, comprised of one or more properties (in which case they + /// have the same name). + virtual std::vector<grpc::string_ref> GetPeerIdentity() const = 0; + virtual grpc::string GetPeerIdentityPropertyName() const = 0; + + /// Returns all the property values with the given name. + virtual std::vector<grpc::string_ref> FindPropertyValues( + const grpc::string& name) const = 0; + + /// Iteration over all the properties. + virtual AuthPropertyIterator begin() const = 0; + virtual AuthPropertyIterator end() const = 0; + + // Mutation functions: should only be used by an AuthMetadataProcessor. + virtual void AddProperty(const grpc::string& key, + const grpc::string_ref& value) = 0; + virtual bool SetPeerIdentityPropertyName(const grpc::string& name) = 0; +}; + +} // namespace grpc + +#endif // GRPCXX_IMPL_CODEGEN_SECURITY_AUTH_CONTEXT_H diff --git a/include/grpc++/impl/codegen/server_interface.h b/include/grpc++/impl/codegen/server_interface.h index 2eadcb3428..b0bc10dc6d 100644 --- a/include/grpc++/impl/codegen/server_interface.h +++ b/include/grpc++/impl/codegen/server_interface.h @@ -45,6 +45,7 @@ class GenericServerContext; class RpcService; class RpcServiceMethod; class ServerAsyncStreamingInterface; +class ServerCompletionQueue; class ServerContext; class ServerCredentials; class Service; diff --git a/include/grpc++/impl/codegen/string_ref.h b/include/grpc++/impl/codegen/string_ref.h new file mode 100644 index 0000000000..bb5363fa3e --- /dev/null +++ b/include/grpc++/impl/codegen/string_ref.h @@ -0,0 +1,123 @@ +/* + * + * 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. + * + */ + +#ifndef GRPCXX_IMPL_CODEGEN_STRING_REF_H +#define GRPCXX_IMPL_CODEGEN_STRING_REF_H + +#include <iterator> +#include <iosfwd> + +#include <grpc++/impl/codegen/config.h> + +namespace grpc { + +/// This class is a non owning reference to a string. +/// +/// It should be a strict subset of the upcoming std::string_ref. +/// +/// \see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3442.html +/// +/// The constexpr is dropped or replaced with const for legacy compiler +/// compatibility. +class string_ref { + public: + // types + typedef const char* const_iterator; + typedef std::reverse_iterator<const_iterator> const_reverse_iterator; + + // constants + const static size_t npos; + + // construct/copy. + string_ref() : data_(nullptr), length_(0) {} + string_ref(const string_ref& other) + : data_(other.data_), length_(other.length_) {} + string_ref& operator=(const string_ref& rhs); + string_ref(const char* s); + string_ref(const char* s, size_t l) : data_(s), length_(l) {} + string_ref(const grpc::string& s) : data_(s.data()), length_(s.length()) {} + + // iterators + const_iterator begin() const { return data_; } + const_iterator end() const { return data_ + length_; } + const_iterator cbegin() const { return data_; } + const_iterator cend() const { return data_ + length_; } + const_reverse_iterator rbegin() const { + return const_reverse_iterator(end()); + } + const_reverse_iterator rend() const { + return const_reverse_iterator(begin()); + } + const_reverse_iterator crbegin() const { + return const_reverse_iterator(end()); + } + const_reverse_iterator crend() const { + return const_reverse_iterator(begin()); + } + + // capacity + size_t size() const { return length_; } + size_t length() const { return length_; } + size_t max_size() const { return length_; } + bool empty() const { return length_ == 0; } + + // element access + const char* data() const { return data_; } + + // string operations + int compare(string_ref x) const; + bool starts_with(string_ref x) const; + bool ends_with(string_ref x) const; + size_t find(string_ref s) const; + size_t find(char c) const; + + string_ref substr(size_t pos, size_t n = npos) const; + + private: + const char* data_; + size_t length_; +}; + +// Comparison operators +bool operator==(string_ref x, string_ref y); +bool operator!=(string_ref x, string_ref y); +bool operator<(string_ref x, string_ref y); +bool operator>(string_ref x, string_ref y); +bool operator<=(string_ref x, string_ref y); +bool operator>=(string_ref x, string_ref y); + +std::ostream& operator<<(std::ostream& stream, const string_ref& string); + +} // namespace grpc + +#endif // GRPCXX_IMPL_CODEGEN_STRING_REF_H diff --git a/include/grpc++/impl/codegen/sync.h b/include/grpc++/impl/codegen/sync.h new file mode 100644 index 0000000000..62194c7708 --- /dev/null +++ b/include/grpc++/impl/codegen/sync.h @@ -0,0 +1,45 @@ +/* + * + * 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. + * + */ + +#ifndef GRPCXX_IMPL_CODEGEN_SYNC_H +#define GRPCXX_IMPL_CODEGEN_SYNC_H + +#include <grpc++/impl/codegen/config.h> + +#ifdef GRPC_CXX0X_NO_THREAD +#include <grpc++/impl/codegen/sync_no_cxx11.h> +#else +#include <grpc++/impl/codegen/sync_cxx11.h> +#endif + +#endif // GRPCXX_IMPL_CODEGEN_SYNC_H diff --git a/include/grpc++/impl/codegen/sync_cxx11.h b/include/grpc++/impl/codegen/sync_cxx11.h new file mode 100644 index 0000000000..6626ca1f94 --- /dev/null +++ b/include/grpc++/impl/codegen/sync_cxx11.h @@ -0,0 +1,49 @@ +/* + * + * 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. + * + */ + +#ifndef GRPCXX_IMPL_CODEGEN_SYNC_CXX11_H +#define GRPCXX_IMPL_CODEGEN_SYNC_CXX11_H + +#include <condition_variable> +#include <mutex> + +namespace grpc { + +using std::condition_variable; +using std::mutex; +using std::lock_guard; +using std::unique_lock; + +} // namespace grpc + +#endif // GRPCXX_IMPL_CODEGEN_SYNC_CXX11_H diff --git a/include/grpc++/impl/codegen/sync_no_cxx11.h b/include/grpc++/impl/codegen/sync_no_cxx11.h new file mode 100644 index 0000000000..55c059ede7 --- /dev/null +++ b/include/grpc++/impl/codegen/sync_no_cxx11.h @@ -0,0 +1,105 @@ +/* + * + * 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. + * + */ + +#ifndef GRPCXX_IMPL_CODEGEN_SYNC_NO_CXX11_H +#define GRPCXX_IMPL_CODEGEN_SYNC_NO_CXX11_H + +#include <grpc/impl/codegen/sync.h> + +namespace grpc { + +template <class mutex> +class lock_guard; +class condition_variable; + +class mutex { + public: + mutex() { gpr_mu_init(&mu_); } + ~mutex() { gpr_mu_destroy(&mu_); } + + private: + ::gpr_mu mu_; + template <class mutex> + friend class lock_guard; + friend class condition_variable; +}; + +template <class mutex> +class lock_guard { + public: + lock_guard(mutex &mu) : mu_(mu), locked(true) { gpr_mu_lock(&mu.mu_); } + ~lock_guard() { unlock_internal(); } + + protected: + void lock_internal() { + if (!locked) gpr_mu_lock(&mu_.mu_); + locked = true; + } + void unlock_internal() { + if (locked) gpr_mu_unlock(&mu_.mu_); + locked = false; + } + + private: + mutex &mu_; + bool locked; + friend class condition_variable; +}; + +template <class mutex> +class unique_lock : public lock_guard<mutex> { + public: + unique_lock(mutex &mu) : lock_guard<mutex>(mu) {} + void lock() { this->lock_internal(); } + void unlock() { this->unlock_internal(); } +}; + +class condition_variable { + public: + condition_variable() { gpr_cv_init(&cv_); } + ~condition_variable() { gpr_cv_destroy(&cv_); } + void wait(lock_guard<mutex> &mu) { + mu.locked = false; + gpr_cv_wait(&cv_, &mu.mu_.mu_, gpr_inf_future(GPR_CLOCK_REALTIME)); + mu.locked = true; + } + void notify_one() { gpr_cv_signal(&cv_); } + void notify_all() { gpr_cv_broadcast(&cv_); } + + private: + gpr_cv cv_; +}; + +} // namespace grpc + +#endif // GRPCXX_IMPL_CODEGEN_SYNC_NO_CXX11_H |