From f142e457d8a0b1cb25d513367faa3e48a9881dc0 Mon Sep 17 00:00:00 2001 From: emeric Date: Wed, 9 Jul 2014 14:25:25 +0200 Subject: [PATCH] WIP. User authentication on remote interface --- Makefile.am | 1 + TODO | 4 +- database/DatabaseHandler.hpp | 3 + database/User.hpp | 2 + remote/messages/auth.pb.cc | 846 ++++++++++++++++++++++++--- remote/messages/auth.pb.h | 717 +++++++++++++++++++---- remote/proto/auth.proto | 39 +- remote/server/AuthRequestHandler.cpp | 81 +++ remote/server/AuthRequestHandler.hpp | 28 + remote/server/RequestHandler.cpp | 53 +- remote/server/RequestHandler.hpp | 5 +- test/RemoteClientServer.cpp | 31 + 12 files changed, 1591 insertions(+), 219 deletions(-) create mode 100644 remote/server/AuthRequestHandler.cpp create mode 100644 remote/server/AuthRequestHandler.hpp diff --git a/Makefile.am b/Makefile.am index a14eb6e9..f40a0bf0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -57,6 +57,7 @@ lms_SOURCES = \ $(top_srcdir)/remote/server/Connection.cpp \ $(top_srcdir)/remote/server/ConnectionManager.cpp \ $(top_srcdir)/remote/server/AudioCollectionRequestHandler.cpp \ + $(top_srcdir)/remote/server/AuthRequestHandler.cpp \ $(top_srcdir)/remote/server/MediaRequestHandler.cpp \ $(top_srcdir)/remote/server/RequestHandler.cpp \ $(top_srcdir)/remote/server/Server.cpp \ diff --git a/TODO b/TODO index 59d91170..70da681a 100644 --- a/TODO +++ b/TODO @@ -3,8 +3,8 @@ - Rework the whole start/stop/try/cach/thread/interrupts things [Users] -- Do the feature - - Admin account to add/remove users, add path to watch for Audio/Video files +- Admin account to add/remove users, add path to watch for Audio/Video files +- Handle login lifetime? [Cover] - Scaling: find something more "reliable" than GIL and its customs extensions (adobe work, io_new) diff --git a/database/DatabaseHandler.hpp b/database/DatabaseHandler.hpp index f71b075c..55a37301 100644 --- a/database/DatabaseHandler.hpp +++ b/database/DatabaseHandler.hpp @@ -25,6 +25,9 @@ class Handler Wt::Dbo::Session& getSession() { return _session; } + User::pointer getCurrentUser(); // get the current user, may return empty + User::pointer getUser(const Wt::Auth::User& authUser); // Get or create the given user + Wt::Auth::AbstractUserDatabase& getUserDatabase(); Wt::Auth::Login& getLogin() { return _login; } diff --git a/database/User.hpp b/database/User.hpp index cc59a95b..a97849bf 100644 --- a/database/User.hpp +++ b/database/User.hpp @@ -13,6 +13,8 @@ class User { public: + typedef Wt::Dbo::ptr pointer; + template void persist(Action& a) { diff --git a/remote/messages/auth.pb.cc b/remote/messages/auth.pb.cc index f4042f3d..ea17e103 100644 --- a/remote/messages/auth.pb.cc +++ b/remote/messages/auth.pb.cc @@ -23,9 +23,18 @@ namespace { const ::google::protobuf::Descriptor* AuthRequest_descriptor_ = NULL; const ::google::protobuf::internal::GeneratedMessageReflection* AuthRequest_reflection_ = NULL; +const ::google::protobuf::Descriptor* AuthRequest_Password_descriptor_ = NULL; +const ::google::protobuf::internal::GeneratedMessageReflection* + AuthRequest_Password_reflection_ = NULL; +const ::google::protobuf::EnumDescriptor* AuthRequest_Type_descriptor_ = NULL; const ::google::protobuf::Descriptor* AuthResponse_descriptor_ = NULL; const ::google::protobuf::internal::GeneratedMessageReflection* AuthResponse_reflection_ = NULL; +const ::google::protobuf::Descriptor* AuthResponse_PasswordResult_descriptor_ = NULL; +const ::google::protobuf::internal::GeneratedMessageReflection* + AuthResponse_PasswordResult_reflection_ = NULL; +const ::google::protobuf::EnumDescriptor* AuthResponse_PasswordResult_Type_descriptor_ = NULL; +const ::google::protobuf::EnumDescriptor* AuthResponse_Type_descriptor_ = NULL; } // namespace @@ -38,8 +47,8 @@ void protobuf_AssignDesc_auth_2eproto() { GOOGLE_CHECK(file != NULL); AuthRequest_descriptor_ = file->message_type(0); static const int AuthRequest_offsets_[2] = { - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(AuthRequest, user_name_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(AuthRequest, user_password_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(AuthRequest, type_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(AuthRequest, password_), }; AuthRequest_reflection_ = new ::google::protobuf::internal::GeneratedMessageReflection( @@ -52,9 +61,27 @@ void protobuf_AssignDesc_auth_2eproto() { ::google::protobuf::DescriptorPool::generated_pool(), ::google::protobuf::MessageFactory::generated_factory(), sizeof(AuthRequest)); + AuthRequest_Password_descriptor_ = AuthRequest_descriptor_->nested_type(0); + static const int AuthRequest_Password_offsets_[2] = { + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(AuthRequest_Password, user_login_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(AuthRequest_Password, user_password_), + }; + AuthRequest_Password_reflection_ = + new ::google::protobuf::internal::GeneratedMessageReflection( + AuthRequest_Password_descriptor_, + AuthRequest_Password::default_instance_, + AuthRequest_Password_offsets_, + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(AuthRequest_Password, _has_bits_[0]), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(AuthRequest_Password, _unknown_fields_), + -1, + ::google::protobuf::DescriptorPool::generated_pool(), + ::google::protobuf::MessageFactory::generated_factory(), + sizeof(AuthRequest_Password)); + AuthRequest_Type_descriptor_ = AuthRequest_descriptor_->enum_type(0); AuthResponse_descriptor_ = file->message_type(1); - static const int AuthResponse_offsets_[1] = { - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(AuthResponse, error_), + static const int AuthResponse_offsets_[2] = { + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(AuthResponse, type_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(AuthResponse, password_result_), }; AuthResponse_reflection_ = new ::google::protobuf::internal::GeneratedMessageReflection( @@ -67,6 +94,24 @@ void protobuf_AssignDesc_auth_2eproto() { ::google::protobuf::DescriptorPool::generated_pool(), ::google::protobuf::MessageFactory::generated_factory(), sizeof(AuthResponse)); + AuthResponse_PasswordResult_descriptor_ = AuthResponse_descriptor_->nested_type(0); + static const int AuthResponse_PasswordResult_offsets_[2] = { + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(AuthResponse_PasswordResult, type_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(AuthResponse_PasswordResult, delay_), + }; + AuthResponse_PasswordResult_reflection_ = + new ::google::protobuf::internal::GeneratedMessageReflection( + AuthResponse_PasswordResult_descriptor_, + AuthResponse_PasswordResult::default_instance_, + AuthResponse_PasswordResult_offsets_, + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(AuthResponse_PasswordResult, _has_bits_[0]), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(AuthResponse_PasswordResult, _unknown_fields_), + -1, + ::google::protobuf::DescriptorPool::generated_pool(), + ::google::protobuf::MessageFactory::generated_factory(), + sizeof(AuthResponse_PasswordResult)); + AuthResponse_PasswordResult_Type_descriptor_ = AuthResponse_PasswordResult_descriptor_->enum_type(0); + AuthResponse_Type_descriptor_ = AuthResponse_descriptor_->enum_type(0); } namespace { @@ -81,8 +126,12 @@ void protobuf_RegisterTypes(const ::std::string&) { protobuf_AssignDescriptorsOnce(); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( AuthRequest_descriptor_, &AuthRequest::default_instance()); + ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( + AuthRequest_Password_descriptor_, &AuthRequest_Password::default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( AuthResponse_descriptor_, &AuthResponse::default_instance()); + ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( + AuthResponse_PasswordResult_descriptor_, &AuthResponse_PasswordResult::default_instance()); } } // namespace @@ -90,8 +139,12 @@ void protobuf_RegisterTypes(const ::std::string&) { void protobuf_ShutdownFile_auth_2eproto() { delete AuthRequest::default_instance_; delete AuthRequest_reflection_; + delete AuthRequest_Password::default_instance_; + delete AuthRequest_Password_reflection_; delete AuthResponse::default_instance_; delete AuthResponse_reflection_; + delete AuthResponse_PasswordResult::default_instance_; + delete AuthResponse_PasswordResult_reflection_; } void protobuf_AddDesc_auth_2eproto() { @@ -102,16 +155,30 @@ void protobuf_AddDesc_auth_2eproto() { ::Remote::protobuf_AddDesc_common_2eproto(); ::google::protobuf::DescriptorPool::InternalAddGeneratedFile( - "\n\nauth.proto\022\006Remote\032\014common.proto\"7\n\013Au" - "thRequest\022\021\n\tuser_name\030\001 \002(\t\022\025\n\ruser_pas" - "sword\030\002 \002(\t\",\n\014AuthResponse\022\034\n\005error\030\001 \002" - "(\0132\r.Remote.Error", 137); + "\n\nauth.proto\022\006Remote\032\014common.proto\"\266\001\n\013A" + "uthRequest\022&\n\004type\030\001 \002(\0162\030.Remote.AuthRe" + "quest.Type\022.\n\010password\030\002 \001(\0132\034.Remote.Au" + "thRequest.Password\0325\n\010Password\022\022\n\nuser_l" + "ogin\030\001 \002(\t\022\025\n\ruser_password\030\002 \002(\t\"\030\n\004Typ" + "e\022\020\n\014TypePassword\020\001\"\300\002\n\014AuthResponse\022\'\n\004" + "type\030\001 \002(\0162\031.Remote.AuthResponse.Type\022<\n" + "\017password_result\030\002 \001(\0132#.Remote.AuthResp" + "onse.PasswordResult\032\250\001\n\016PasswordResult\0226" + "\n\004type\030\001 \002(\0162(.Remote.AuthResponse.Passw" + "ordResult.Type\022\r\n\005delay\030\002 \001(\r\"O\n\004Type\022\027\n" + "\023TypePasswordInvalid\020\001\022\027\n\023TypeLoginThrot" + "tling\020\002\022\025\n\021TypePasswordValid\020\003\"\036\n\004Type\022\026" + "\n\022TypePasswordResult\020\001", 542); ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( "auth.proto", &protobuf_RegisterTypes); AuthRequest::default_instance_ = new AuthRequest(); + AuthRequest_Password::default_instance_ = new AuthRequest_Password(); AuthResponse::default_instance_ = new AuthResponse(); + AuthResponse_PasswordResult::default_instance_ = new AuthResponse_PasswordResult(); AuthRequest::default_instance_->InitAsDefaultInstance(); + AuthRequest_Password::default_instance_->InitAsDefaultInstance(); AuthResponse::default_instance_->InitAsDefaultInstance(); + AuthResponse_PasswordResult::default_instance_->InitAsDefaultInstance(); ::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_auth_2eproto); } @@ -124,39 +191,58 @@ struct StaticDescriptorInitializer_auth_2eproto { // =================================================================== +const ::google::protobuf::EnumDescriptor* AuthRequest_Type_descriptor() { + protobuf_AssignDescriptorsOnce(); + return AuthRequest_Type_descriptor_; +} +bool AuthRequest_Type_IsValid(int value) { + switch(value) { + case 1: + return true; + default: + return false; + } +} + #ifndef _MSC_VER -const int AuthRequest::kUserNameFieldNumber; -const int AuthRequest::kUserPasswordFieldNumber; +const AuthRequest_Type AuthRequest::TypePassword; +const AuthRequest_Type AuthRequest::Type_MIN; +const AuthRequest_Type AuthRequest::Type_MAX; +const int AuthRequest::Type_ARRAYSIZE; +#endif // _MSC_VER +#ifndef _MSC_VER +const int AuthRequest_Password::kUserLoginFieldNumber; +const int AuthRequest_Password::kUserPasswordFieldNumber; #endif // !_MSC_VER -AuthRequest::AuthRequest() +AuthRequest_Password::AuthRequest_Password() : ::google::protobuf::Message() { SharedCtor(); } -void AuthRequest::InitAsDefaultInstance() { +void AuthRequest_Password::InitAsDefaultInstance() { } -AuthRequest::AuthRequest(const AuthRequest& from) +AuthRequest_Password::AuthRequest_Password(const AuthRequest_Password& from) : ::google::protobuf::Message() { SharedCtor(); MergeFrom(from); } -void AuthRequest::SharedCtor() { +void AuthRequest_Password::SharedCtor() { _cached_size_ = 0; - user_name_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + user_login_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); user_password_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); ::memset(_has_bits_, 0, sizeof(_has_bits_)); } -AuthRequest::~AuthRequest() { +AuthRequest_Password::~AuthRequest_Password() { SharedDtor(); } -void AuthRequest::SharedDtor() { - if (user_name_ != &::google::protobuf::internal::kEmptyString) { - delete user_name_; +void AuthRequest_Password::SharedDtor() { + if (user_login_ != &::google::protobuf::internal::kEmptyString) { + delete user_login_; } if (user_password_ != &::google::protobuf::internal::kEmptyString) { delete user_password_; @@ -165,32 +251,32 @@ void AuthRequest::SharedDtor() { } } -void AuthRequest::SetCachedSize(int size) const { +void AuthRequest_Password::SetCachedSize(int size) const { GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); _cached_size_ = size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); } -const ::google::protobuf::Descriptor* AuthRequest::descriptor() { +const ::google::protobuf::Descriptor* AuthRequest_Password::descriptor() { protobuf_AssignDescriptorsOnce(); - return AuthRequest_descriptor_; + return AuthRequest_Password_descriptor_; } -const AuthRequest& AuthRequest::default_instance() { +const AuthRequest_Password& AuthRequest_Password::default_instance() { if (default_instance_ == NULL) protobuf_AddDesc_auth_2eproto(); return *default_instance_; } -AuthRequest* AuthRequest::default_instance_ = NULL; +AuthRequest_Password* AuthRequest_Password::default_instance_ = NULL; -AuthRequest* AuthRequest::New() const { - return new AuthRequest; +AuthRequest_Password* AuthRequest_Password::New() const { + return new AuthRequest_Password; } -void AuthRequest::Clear() { +void AuthRequest_Password::Clear() { if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) { - if (has_user_name()) { - if (user_name_ != &::google::protobuf::internal::kEmptyString) { - user_name_->clear(); + if (has_user_login()) { + if (user_login_ != &::google::protobuf::internal::kEmptyString) { + user_login_->clear(); } } if (has_user_password()) { @@ -203,20 +289,20 @@ void AuthRequest::Clear() { mutable_unknown_fields()->Clear(); } -bool AuthRequest::MergePartialFromCodedStream( +bool AuthRequest_Password::MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input) { #define DO_(EXPRESSION) if (!(EXPRESSION)) return false ::google::protobuf::uint32 tag; while ((tag = input->ReadTag()) != 0) { switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { - // required string user_name = 1; + // required string user_login = 1; case 1: { if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( - input, this->mutable_user_name())); + input, this->mutable_user_login())); ::google::protobuf::internal::WireFormat::VerifyUTF8String( - this->user_name().data(), this->user_name().length(), + this->user_login().data(), this->user_login().length(), ::google::protobuf::internal::WireFormat::PARSE); } else { goto handle_uninterpreted; @@ -258,15 +344,15 @@ bool AuthRequest::MergePartialFromCodedStream( #undef DO_ } -void AuthRequest::SerializeWithCachedSizes( +void AuthRequest_Password::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { - // required string user_name = 1; - if (has_user_name()) { + // required string user_login = 1; + if (has_user_login()) { ::google::protobuf::internal::WireFormat::VerifyUTF8String( - this->user_name().data(), this->user_name().length(), + this->user_login().data(), this->user_login().length(), ::google::protobuf::internal::WireFormat::SERIALIZE); ::google::protobuf::internal::WireFormatLite::WriteString( - 1, this->user_name(), output); + 1, this->user_login(), output); } // required string user_password = 2; @@ -284,16 +370,16 @@ void AuthRequest::SerializeWithCachedSizes( } } -::google::protobuf::uint8* AuthRequest::SerializeWithCachedSizesToArray( +::google::protobuf::uint8* AuthRequest_Password::SerializeWithCachedSizesToArray( ::google::protobuf::uint8* target) const { - // required string user_name = 1; - if (has_user_name()) { + // required string user_login = 1; + if (has_user_login()) { ::google::protobuf::internal::WireFormat::VerifyUTF8String( - this->user_name().data(), this->user_name().length(), + this->user_login().data(), this->user_login().length(), ::google::protobuf::internal::WireFormat::SERIALIZE); target = ::google::protobuf::internal::WireFormatLite::WriteStringToArray( - 1, this->user_name(), target); + 1, this->user_login(), target); } // required string user_password = 2; @@ -313,15 +399,15 @@ void AuthRequest::SerializeWithCachedSizes( return target; } -int AuthRequest::ByteSize() const { +int AuthRequest_Password::ByteSize() const { int total_size = 0; if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) { - // required string user_name = 1; - if (has_user_name()) { + // required string user_login = 1; + if (has_user_login()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::StringSize( - this->user_name()); + this->user_login()); } // required string user_password = 2; @@ -343,6 +429,266 @@ int AuthRequest::ByteSize() const { return total_size; } +void AuthRequest_Password::MergeFrom(const ::google::protobuf::Message& from) { + GOOGLE_CHECK_NE(&from, this); + const AuthRequest_Password* source = + ::google::protobuf::internal::dynamic_cast_if_available( + &from); + if (source == NULL) { + ::google::protobuf::internal::ReflectionOps::Merge(from, this); + } else { + MergeFrom(*source); + } +} + +void AuthRequest_Password::MergeFrom(const AuthRequest_Password& from) { + GOOGLE_CHECK_NE(&from, this); + if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { + if (from.has_user_login()) { + set_user_login(from.user_login()); + } + if (from.has_user_password()) { + set_user_password(from.user_password()); + } + } + mutable_unknown_fields()->MergeFrom(from.unknown_fields()); +} + +void AuthRequest_Password::CopyFrom(const ::google::protobuf::Message& from) { + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +void AuthRequest_Password::CopyFrom(const AuthRequest_Password& from) { + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool AuthRequest_Password::IsInitialized() const { + if ((_has_bits_[0] & 0x00000003) != 0x00000003) return false; + + return true; +} + +void AuthRequest_Password::Swap(AuthRequest_Password* other) { + if (other != this) { + std::swap(user_login_, other->user_login_); + std::swap(user_password_, other->user_password_); + std::swap(_has_bits_[0], other->_has_bits_[0]); + _unknown_fields_.Swap(&other->_unknown_fields_); + std::swap(_cached_size_, other->_cached_size_); + } +} + +::google::protobuf::Metadata AuthRequest_Password::GetMetadata() const { + protobuf_AssignDescriptorsOnce(); + ::google::protobuf::Metadata metadata; + metadata.descriptor = AuthRequest_Password_descriptor_; + metadata.reflection = AuthRequest_Password_reflection_; + return metadata; +} + + +// ------------------------------------------------------------------- + +#ifndef _MSC_VER +const int AuthRequest::kTypeFieldNumber; +const int AuthRequest::kPasswordFieldNumber; +#endif // !_MSC_VER + +AuthRequest::AuthRequest() + : ::google::protobuf::Message() { + SharedCtor(); +} + +void AuthRequest::InitAsDefaultInstance() { + password_ = const_cast< ::Remote::AuthRequest_Password*>(&::Remote::AuthRequest_Password::default_instance()); +} + +AuthRequest::AuthRequest(const AuthRequest& from) + : ::google::protobuf::Message() { + SharedCtor(); + MergeFrom(from); +} + +void AuthRequest::SharedCtor() { + _cached_size_ = 0; + type_ = 1; + password_ = NULL; + ::memset(_has_bits_, 0, sizeof(_has_bits_)); +} + +AuthRequest::~AuthRequest() { + SharedDtor(); +} + +void AuthRequest::SharedDtor() { + if (this != default_instance_) { + delete password_; + } +} + +void AuthRequest::SetCachedSize(int size) const { + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); +} +const ::google::protobuf::Descriptor* AuthRequest::descriptor() { + protobuf_AssignDescriptorsOnce(); + return AuthRequest_descriptor_; +} + +const AuthRequest& AuthRequest::default_instance() { + if (default_instance_ == NULL) protobuf_AddDesc_auth_2eproto(); + return *default_instance_; +} + +AuthRequest* AuthRequest::default_instance_ = NULL; + +AuthRequest* AuthRequest::New() const { + return new AuthRequest; +} + +void AuthRequest::Clear() { + if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) { + type_ = 1; + if (has_password()) { + if (password_ != NULL) password_->::Remote::AuthRequest_Password::Clear(); + } + } + ::memset(_has_bits_, 0, sizeof(_has_bits_)); + mutable_unknown_fields()->Clear(); +} + +bool AuthRequest::MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) { +#define DO_(EXPRESSION) if (!(EXPRESSION)) return false + ::google::protobuf::uint32 tag; + while ((tag = input->ReadTag()) != 0) { + switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { + // required .Remote.AuthRequest.Type type = 1; + case 1: { + if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == + ::google::protobuf::internal::WireFormatLite::WIRETYPE_VARINT) { + int value; + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< + int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>( + input, &value))); + if (::Remote::AuthRequest_Type_IsValid(value)) { + set_type(static_cast< ::Remote::AuthRequest_Type >(value)); + } else { + mutable_unknown_fields()->AddVarint(1, value); + } + } else { + goto handle_uninterpreted; + } + if (input->ExpectTag(18)) goto parse_password; + break; + } + + // optional .Remote.AuthRequest.Password password = 2; + case 2: { + if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == + ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) { + parse_password: + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( + input, mutable_password())); + } else { + goto handle_uninterpreted; + } + if (input->ExpectAtEnd()) return true; + break; + } + + default: { + handle_uninterpreted: + if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == + ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + return true; + } + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, mutable_unknown_fields())); + break; + } + } + } + return true; +#undef DO_ +} + +void AuthRequest::SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const { + // required .Remote.AuthRequest.Type type = 1; + if (has_type()) { + ::google::protobuf::internal::WireFormatLite::WriteEnum( + 1, this->type(), output); + } + + // optional .Remote.AuthRequest.Password password = 2; + if (has_password()) { + ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( + 2, this->password(), output); + } + + if (!unknown_fields().empty()) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + unknown_fields(), output); + } +} + +::google::protobuf::uint8* AuthRequest::SerializeWithCachedSizesToArray( + ::google::protobuf::uint8* target) const { + // required .Remote.AuthRequest.Type type = 1; + if (has_type()) { + target = ::google::protobuf::internal::WireFormatLite::WriteEnumToArray( + 1, this->type(), target); + } + + // optional .Remote.AuthRequest.Password password = 2; + if (has_password()) { + target = ::google::protobuf::internal::WireFormatLite:: + WriteMessageNoVirtualToArray( + 2, this->password(), target); + } + + if (!unknown_fields().empty()) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + unknown_fields(), target); + } + return target; +} + +int AuthRequest::ByteSize() const { + int total_size = 0; + + if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) { + // required .Remote.AuthRequest.Type type = 1; + if (has_type()) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::EnumSize(this->type()); + } + + // optional .Remote.AuthRequest.Password password = 2; + if (has_password()) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->password()); + } + + } + if (!unknown_fields().empty()) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + unknown_fields()); + } + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = total_size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); + return total_size; +} + void AuthRequest::MergeFrom(const ::google::protobuf::Message& from) { GOOGLE_CHECK_NE(&from, this); const AuthRequest* source = @@ -358,11 +704,11 @@ void AuthRequest::MergeFrom(const ::google::protobuf::Message& from) { void AuthRequest::MergeFrom(const AuthRequest& from) { GOOGLE_CHECK_NE(&from, this); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { - if (from.has_user_name()) { - set_user_name(from.user_name()); + if (from.has_type()) { + set_type(from.type()); } - if (from.has_user_password()) { - set_user_password(from.user_password()); + if (from.has_password()) { + mutable_password()->::Remote::AuthRequest_Password::MergeFrom(from.password()); } } mutable_unknown_fields()->MergeFrom(from.unknown_fields()); @@ -381,15 +727,18 @@ void AuthRequest::CopyFrom(const AuthRequest& from) { } bool AuthRequest::IsInitialized() const { - if ((_has_bits_[0] & 0x00000003) != 0x00000003) return false; + if ((_has_bits_[0] & 0x00000001) != 0x00000001) return false; + if (has_password()) { + if (!this->password().IsInitialized()) return false; + } return true; } void AuthRequest::Swap(AuthRequest* other) { if (other != this) { - std::swap(user_name_, other->user_name_); - std::swap(user_password_, other->user_password_); + std::swap(type_, other->type_); + std::swap(password_, other->password_); std::swap(_has_bits_[0], other->_has_bits_[0]); _unknown_fields_.Swap(&other->_unknown_fields_); std::swap(_cached_size_, other->_cached_size_); @@ -407,8 +756,306 @@ void AuthRequest::Swap(AuthRequest* other) { // =================================================================== +const ::google::protobuf::EnumDescriptor* AuthResponse_Type_descriptor() { + protobuf_AssignDescriptorsOnce(); + return AuthResponse_Type_descriptor_; +} +bool AuthResponse_Type_IsValid(int value) { + switch(value) { + case 1: + return true; + default: + return false; + } +} + #ifndef _MSC_VER -const int AuthResponse::kErrorFieldNumber; +const AuthResponse_Type AuthResponse::TypePasswordResult; +const AuthResponse_Type AuthResponse::Type_MIN; +const AuthResponse_Type AuthResponse::Type_MAX; +const int AuthResponse::Type_ARRAYSIZE; +#endif // _MSC_VER +const ::google::protobuf::EnumDescriptor* AuthResponse_PasswordResult_Type_descriptor() { + protobuf_AssignDescriptorsOnce(); + return AuthResponse_PasswordResult_Type_descriptor_; +} +bool AuthResponse_PasswordResult_Type_IsValid(int value) { + switch(value) { + case 1: + case 2: + case 3: + return true; + default: + return false; + } +} + +#ifndef _MSC_VER +const AuthResponse_PasswordResult_Type AuthResponse_PasswordResult::TypePasswordInvalid; +const AuthResponse_PasswordResult_Type AuthResponse_PasswordResult::TypeLoginThrottling; +const AuthResponse_PasswordResult_Type AuthResponse_PasswordResult::TypePasswordValid; +const AuthResponse_PasswordResult_Type AuthResponse_PasswordResult::Type_MIN; +const AuthResponse_PasswordResult_Type AuthResponse_PasswordResult::Type_MAX; +const int AuthResponse_PasswordResult::Type_ARRAYSIZE; +#endif // _MSC_VER +#ifndef _MSC_VER +const int AuthResponse_PasswordResult::kTypeFieldNumber; +const int AuthResponse_PasswordResult::kDelayFieldNumber; +#endif // !_MSC_VER + +AuthResponse_PasswordResult::AuthResponse_PasswordResult() + : ::google::protobuf::Message() { + SharedCtor(); +} + +void AuthResponse_PasswordResult::InitAsDefaultInstance() { +} + +AuthResponse_PasswordResult::AuthResponse_PasswordResult(const AuthResponse_PasswordResult& from) + : ::google::protobuf::Message() { + SharedCtor(); + MergeFrom(from); +} + +void AuthResponse_PasswordResult::SharedCtor() { + _cached_size_ = 0; + type_ = 1; + delay_ = 0u; + ::memset(_has_bits_, 0, sizeof(_has_bits_)); +} + +AuthResponse_PasswordResult::~AuthResponse_PasswordResult() { + SharedDtor(); +} + +void AuthResponse_PasswordResult::SharedDtor() { + if (this != default_instance_) { + } +} + +void AuthResponse_PasswordResult::SetCachedSize(int size) const { + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); +} +const ::google::protobuf::Descriptor* AuthResponse_PasswordResult::descriptor() { + protobuf_AssignDescriptorsOnce(); + return AuthResponse_PasswordResult_descriptor_; +} + +const AuthResponse_PasswordResult& AuthResponse_PasswordResult::default_instance() { + if (default_instance_ == NULL) protobuf_AddDesc_auth_2eproto(); + return *default_instance_; +} + +AuthResponse_PasswordResult* AuthResponse_PasswordResult::default_instance_ = NULL; + +AuthResponse_PasswordResult* AuthResponse_PasswordResult::New() const { + return new AuthResponse_PasswordResult; +} + +void AuthResponse_PasswordResult::Clear() { + if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) { + type_ = 1; + delay_ = 0u; + } + ::memset(_has_bits_, 0, sizeof(_has_bits_)); + mutable_unknown_fields()->Clear(); +} + +bool AuthResponse_PasswordResult::MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) { +#define DO_(EXPRESSION) if (!(EXPRESSION)) return false + ::google::protobuf::uint32 tag; + while ((tag = input->ReadTag()) != 0) { + switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { + // required .Remote.AuthResponse.PasswordResult.Type type = 1; + case 1: { + if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == + ::google::protobuf::internal::WireFormatLite::WIRETYPE_VARINT) { + int value; + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< + int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>( + input, &value))); + if (::Remote::AuthResponse_PasswordResult_Type_IsValid(value)) { + set_type(static_cast< ::Remote::AuthResponse_PasswordResult_Type >(value)); + } else { + mutable_unknown_fields()->AddVarint(1, value); + } + } else { + goto handle_uninterpreted; + } + if (input->ExpectTag(16)) goto parse_delay; + break; + } + + // optional uint32 delay = 2; + case 2: { + if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == + ::google::protobuf::internal::WireFormatLite::WIRETYPE_VARINT) { + parse_delay: + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< + ::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>( + input, &delay_))); + set_has_delay(); + } else { + goto handle_uninterpreted; + } + if (input->ExpectAtEnd()) return true; + break; + } + + default: { + handle_uninterpreted: + if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == + ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + return true; + } + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, mutable_unknown_fields())); + break; + } + } + } + return true; +#undef DO_ +} + +void AuthResponse_PasswordResult::SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const { + // required .Remote.AuthResponse.PasswordResult.Type type = 1; + if (has_type()) { + ::google::protobuf::internal::WireFormatLite::WriteEnum( + 1, this->type(), output); + } + + // optional uint32 delay = 2; + if (has_delay()) { + ::google::protobuf::internal::WireFormatLite::WriteUInt32(2, this->delay(), output); + } + + if (!unknown_fields().empty()) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + unknown_fields(), output); + } +} + +::google::protobuf::uint8* AuthResponse_PasswordResult::SerializeWithCachedSizesToArray( + ::google::protobuf::uint8* target) const { + // required .Remote.AuthResponse.PasswordResult.Type type = 1; + if (has_type()) { + target = ::google::protobuf::internal::WireFormatLite::WriteEnumToArray( + 1, this->type(), target); + } + + // optional uint32 delay = 2; + if (has_delay()) { + target = ::google::protobuf::internal::WireFormatLite::WriteUInt32ToArray(2, this->delay(), target); + } + + if (!unknown_fields().empty()) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + unknown_fields(), target); + } + return target; +} + +int AuthResponse_PasswordResult::ByteSize() const { + int total_size = 0; + + if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) { + // required .Remote.AuthResponse.PasswordResult.Type type = 1; + if (has_type()) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::EnumSize(this->type()); + } + + // optional uint32 delay = 2; + if (has_delay()) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::UInt32Size( + this->delay()); + } + + } + if (!unknown_fields().empty()) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + unknown_fields()); + } + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = total_size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); + return total_size; +} + +void AuthResponse_PasswordResult::MergeFrom(const ::google::protobuf::Message& from) { + GOOGLE_CHECK_NE(&from, this); + const AuthResponse_PasswordResult* source = + ::google::protobuf::internal::dynamic_cast_if_available( + &from); + if (source == NULL) { + ::google::protobuf::internal::ReflectionOps::Merge(from, this); + } else { + MergeFrom(*source); + } +} + +void AuthResponse_PasswordResult::MergeFrom(const AuthResponse_PasswordResult& from) { + GOOGLE_CHECK_NE(&from, this); + if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { + if (from.has_type()) { + set_type(from.type()); + } + if (from.has_delay()) { + set_delay(from.delay()); + } + } + mutable_unknown_fields()->MergeFrom(from.unknown_fields()); +} + +void AuthResponse_PasswordResult::CopyFrom(const ::google::protobuf::Message& from) { + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +void AuthResponse_PasswordResult::CopyFrom(const AuthResponse_PasswordResult& from) { + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool AuthResponse_PasswordResult::IsInitialized() const { + if ((_has_bits_[0] & 0x00000001) != 0x00000001) return false; + + return true; +} + +void AuthResponse_PasswordResult::Swap(AuthResponse_PasswordResult* other) { + if (other != this) { + std::swap(type_, other->type_); + std::swap(delay_, other->delay_); + std::swap(_has_bits_[0], other->_has_bits_[0]); + _unknown_fields_.Swap(&other->_unknown_fields_); + std::swap(_cached_size_, other->_cached_size_); + } +} + +::google::protobuf::Metadata AuthResponse_PasswordResult::GetMetadata() const { + protobuf_AssignDescriptorsOnce(); + ::google::protobuf::Metadata metadata; + metadata.descriptor = AuthResponse_PasswordResult_descriptor_; + metadata.reflection = AuthResponse_PasswordResult_reflection_; + return metadata; +} + + +// ------------------------------------------------------------------- + +#ifndef _MSC_VER +const int AuthResponse::kTypeFieldNumber; +const int AuthResponse::kPasswordResultFieldNumber; #endif // !_MSC_VER AuthResponse::AuthResponse() @@ -417,7 +1064,7 @@ AuthResponse::AuthResponse() } void AuthResponse::InitAsDefaultInstance() { - error_ = const_cast< ::Remote::Error*>(&::Remote::Error::default_instance()); + password_result_ = const_cast< ::Remote::AuthResponse_PasswordResult*>(&::Remote::AuthResponse_PasswordResult::default_instance()); } AuthResponse::AuthResponse(const AuthResponse& from) @@ -428,7 +1075,8 @@ AuthResponse::AuthResponse(const AuthResponse& from) void AuthResponse::SharedCtor() { _cached_size_ = 0; - error_ = NULL; + type_ = 1; + password_result_ = NULL; ::memset(_has_bits_, 0, sizeof(_has_bits_)); } @@ -438,7 +1086,7 @@ AuthResponse::~AuthResponse() { void AuthResponse::SharedDtor() { if (this != default_instance_) { - delete error_; + delete password_result_; } } @@ -465,8 +1113,9 @@ AuthResponse* AuthResponse::New() const { void AuthResponse::Clear() { if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) { - if (has_error()) { - if (error_ != NULL) error_->::Remote::Error::Clear(); + type_ = 1; + if (has_password_result()) { + if (password_result_ != NULL) password_result_->::Remote::AuthResponse_PasswordResult::Clear(); } } ::memset(_has_bits_, 0, sizeof(_has_bits_)); @@ -479,12 +1128,33 @@ bool AuthResponse::MergePartialFromCodedStream( ::google::protobuf::uint32 tag; while ((tag = input->ReadTag()) != 0) { switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { - // required .Remote.Error error = 1; + // required .Remote.AuthResponse.Type type = 1; case 1: { + if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == + ::google::protobuf::internal::WireFormatLite::WIRETYPE_VARINT) { + int value; + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< + int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>( + input, &value))); + if (::Remote::AuthResponse_Type_IsValid(value)) { + set_type(static_cast< ::Remote::AuthResponse_Type >(value)); + } else { + mutable_unknown_fields()->AddVarint(1, value); + } + } else { + goto handle_uninterpreted; + } + if (input->ExpectTag(18)) goto parse_password_result; + break; + } + + // optional .Remote.AuthResponse.PasswordResult password_result = 2; + case 2: { if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) { + parse_password_result: DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( - input, mutable_error())); + input, mutable_password_result())); } else { goto handle_uninterpreted; } @@ -510,10 +1180,16 @@ bool AuthResponse::MergePartialFromCodedStream( void AuthResponse::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { - // required .Remote.Error error = 1; - if (has_error()) { + // required .Remote.AuthResponse.Type type = 1; + if (has_type()) { + ::google::protobuf::internal::WireFormatLite::WriteEnum( + 1, this->type(), output); + } + + // optional .Remote.AuthResponse.PasswordResult password_result = 2; + if (has_password_result()) { ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( - 1, this->error(), output); + 2, this->password_result(), output); } if (!unknown_fields().empty()) { @@ -524,11 +1200,17 @@ void AuthResponse::SerializeWithCachedSizes( ::google::protobuf::uint8* AuthResponse::SerializeWithCachedSizesToArray( ::google::protobuf::uint8* target) const { - // required .Remote.Error error = 1; - if (has_error()) { + // required .Remote.AuthResponse.Type type = 1; + if (has_type()) { + target = ::google::protobuf::internal::WireFormatLite::WriteEnumToArray( + 1, this->type(), target); + } + + // optional .Remote.AuthResponse.PasswordResult password_result = 2; + if (has_password_result()) { target = ::google::protobuf::internal::WireFormatLite:: WriteMessageNoVirtualToArray( - 1, this->error(), target); + 2, this->password_result(), target); } if (!unknown_fields().empty()) { @@ -542,11 +1224,17 @@ int AuthResponse::ByteSize() const { int total_size = 0; if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) { - // required .Remote.Error error = 1; - if (has_error()) { + // required .Remote.AuthResponse.Type type = 1; + if (has_type()) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::EnumSize(this->type()); + } + + // optional .Remote.AuthResponse.PasswordResult password_result = 2; + if (has_password_result()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->error()); + this->password_result()); } } @@ -576,8 +1264,11 @@ void AuthResponse::MergeFrom(const ::google::protobuf::Message& from) { void AuthResponse::MergeFrom(const AuthResponse& from) { GOOGLE_CHECK_NE(&from, this); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { - if (from.has_error()) { - mutable_error()->::Remote::Error::MergeFrom(from.error()); + if (from.has_type()) { + set_type(from.type()); + } + if (from.has_password_result()) { + mutable_password_result()->::Remote::AuthResponse_PasswordResult::MergeFrom(from.password_result()); } } mutable_unknown_fields()->MergeFrom(from.unknown_fields()); @@ -598,15 +1289,16 @@ void AuthResponse::CopyFrom(const AuthResponse& from) { bool AuthResponse::IsInitialized() const { if ((_has_bits_[0] & 0x00000001) != 0x00000001) return false; - if (has_error()) { - if (!this->error().IsInitialized()) return false; + if (has_password_result()) { + if (!this->password_result().IsInitialized()) return false; } return true; } void AuthResponse::Swap(AuthResponse* other) { if (other != this) { - std::swap(error_, other->error_); + std::swap(type_, other->type_); + std::swap(password_result_, other->password_result_); std::swap(_has_bits_[0], other->_has_bits_[0]); _unknown_fields_.Swap(&other->_unknown_fields_); std::swap(_cached_size_, other->_cached_size_); diff --git a/remote/messages/auth.pb.h b/remote/messages/auth.pb.h index ef469b0c..17e84e86 100644 --- a/remote/messages/auth.pb.h +++ b/remote/messages/auth.pb.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include "common.pb.h" // @@protoc_insertion_point(includes) @@ -35,10 +36,170 @@ void protobuf_AssignDesc_auth_2eproto(); void protobuf_ShutdownFile_auth_2eproto(); class AuthRequest; +class AuthRequest_Password; class AuthResponse; +class AuthResponse_PasswordResult; +enum AuthRequest_Type { + AuthRequest_Type_TypePassword = 1 +}; +bool AuthRequest_Type_IsValid(int value); +const AuthRequest_Type AuthRequest_Type_Type_MIN = AuthRequest_Type_TypePassword; +const AuthRequest_Type AuthRequest_Type_Type_MAX = AuthRequest_Type_TypePassword; +const int AuthRequest_Type_Type_ARRAYSIZE = AuthRequest_Type_Type_MAX + 1; + +const ::google::protobuf::EnumDescriptor* AuthRequest_Type_descriptor(); +inline const ::std::string& AuthRequest_Type_Name(AuthRequest_Type value) { + return ::google::protobuf::internal::NameOfEnum( + AuthRequest_Type_descriptor(), value); +} +inline bool AuthRequest_Type_Parse( + const ::std::string& name, AuthRequest_Type* value) { + return ::google::protobuf::internal::ParseNamedEnum( + AuthRequest_Type_descriptor(), name, value); +} +enum AuthResponse_PasswordResult_Type { + AuthResponse_PasswordResult_Type_TypePasswordInvalid = 1, + AuthResponse_PasswordResult_Type_TypeLoginThrottling = 2, + AuthResponse_PasswordResult_Type_TypePasswordValid = 3 +}; +bool AuthResponse_PasswordResult_Type_IsValid(int value); +const AuthResponse_PasswordResult_Type AuthResponse_PasswordResult_Type_Type_MIN = AuthResponse_PasswordResult_Type_TypePasswordInvalid; +const AuthResponse_PasswordResult_Type AuthResponse_PasswordResult_Type_Type_MAX = AuthResponse_PasswordResult_Type_TypePasswordValid; +const int AuthResponse_PasswordResult_Type_Type_ARRAYSIZE = AuthResponse_PasswordResult_Type_Type_MAX + 1; + +const ::google::protobuf::EnumDescriptor* AuthResponse_PasswordResult_Type_descriptor(); +inline const ::std::string& AuthResponse_PasswordResult_Type_Name(AuthResponse_PasswordResult_Type value) { + return ::google::protobuf::internal::NameOfEnum( + AuthResponse_PasswordResult_Type_descriptor(), value); +} +inline bool AuthResponse_PasswordResult_Type_Parse( + const ::std::string& name, AuthResponse_PasswordResult_Type* value) { + return ::google::protobuf::internal::ParseNamedEnum( + AuthResponse_PasswordResult_Type_descriptor(), name, value); +} +enum AuthResponse_Type { + AuthResponse_Type_TypePasswordResult = 1 +}; +bool AuthResponse_Type_IsValid(int value); +const AuthResponse_Type AuthResponse_Type_Type_MIN = AuthResponse_Type_TypePasswordResult; +const AuthResponse_Type AuthResponse_Type_Type_MAX = AuthResponse_Type_TypePasswordResult; +const int AuthResponse_Type_Type_ARRAYSIZE = AuthResponse_Type_Type_MAX + 1; + +const ::google::protobuf::EnumDescriptor* AuthResponse_Type_descriptor(); +inline const ::std::string& AuthResponse_Type_Name(AuthResponse_Type value) { + return ::google::protobuf::internal::NameOfEnum( + AuthResponse_Type_descriptor(), value); +} +inline bool AuthResponse_Type_Parse( + const ::std::string& name, AuthResponse_Type* value) { + return ::google::protobuf::internal::ParseNamedEnum( + AuthResponse_Type_descriptor(), name, value); +} // =================================================================== +class AuthRequest_Password : public ::google::protobuf::Message { + public: + AuthRequest_Password(); + virtual ~AuthRequest_Password(); + + AuthRequest_Password(const AuthRequest_Password& from); + + inline AuthRequest_Password& operator=(const AuthRequest_Password& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const AuthRequest_Password& default_instance(); + + void Swap(AuthRequest_Password* other); + + // implements Message ---------------------------------------------- + + AuthRequest_Password* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const AuthRequest_Password& from); + void MergeFrom(const AuthRequest_Password& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // required string user_login = 1; + inline bool has_user_login() const; + inline void clear_user_login(); + static const int kUserLoginFieldNumber = 1; + inline const ::std::string& user_login() const; + inline void set_user_login(const ::std::string& value); + inline void set_user_login(const char* value); + inline void set_user_login(const char* value, size_t size); + inline ::std::string* mutable_user_login(); + inline ::std::string* release_user_login(); + inline void set_allocated_user_login(::std::string* user_login); + + // required string user_password = 2; + inline bool has_user_password() const; + inline void clear_user_password(); + static const int kUserPasswordFieldNumber = 2; + inline const ::std::string& user_password() const; + inline void set_user_password(const ::std::string& value); + inline void set_user_password(const char* value); + inline void set_user_password(const char* value, size_t size); + inline ::std::string* mutable_user_password(); + inline ::std::string* release_user_password(); + inline void set_allocated_user_password(::std::string* user_password); + + // @@protoc_insertion_point(class_scope:Remote.AuthRequest.Password) + private: + inline void set_has_user_login(); + inline void clear_has_user_login(); + inline void set_has_user_password(); + inline void clear_has_user_password(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + ::std::string* user_login_; + ::std::string* user_password_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(2 + 31) / 32]; + + friend void protobuf_AddDesc_auth_2eproto(); + friend void protobuf_AssignDesc_auth_2eproto(); + friend void protobuf_ShutdownFile_auth_2eproto(); + + void InitAsDefaultInstance(); + static AuthRequest_Password* default_instance_; +}; +// ------------------------------------------------------------------- + class AuthRequest : public ::google::protobuf::Message { public: AuthRequest(); @@ -91,43 +252,60 @@ class AuthRequest : public ::google::protobuf::Message { // nested types ---------------------------------------------------- + typedef AuthRequest_Password Password; + + typedef AuthRequest_Type Type; + static const Type TypePassword = AuthRequest_Type_TypePassword; + static inline bool Type_IsValid(int value) { + return AuthRequest_Type_IsValid(value); + } + static const Type Type_MIN = + AuthRequest_Type_Type_MIN; + static const Type Type_MAX = + AuthRequest_Type_Type_MAX; + static const int Type_ARRAYSIZE = + AuthRequest_Type_Type_ARRAYSIZE; + static inline const ::google::protobuf::EnumDescriptor* + Type_descriptor() { + return AuthRequest_Type_descriptor(); + } + static inline const ::std::string& Type_Name(Type value) { + return AuthRequest_Type_Name(value); + } + static inline bool Type_Parse(const ::std::string& name, + Type* value) { + return AuthRequest_Type_Parse(name, value); + } + // accessors ------------------------------------------------------- - // required string user_name = 1; - inline bool has_user_name() const; - inline void clear_user_name(); - static const int kUserNameFieldNumber = 1; - inline const ::std::string& user_name() const; - inline void set_user_name(const ::std::string& value); - inline void set_user_name(const char* value); - inline void set_user_name(const char* value, size_t size); - inline ::std::string* mutable_user_name(); - inline ::std::string* release_user_name(); - inline void set_allocated_user_name(::std::string* user_name); + // required .Remote.AuthRequest.Type type = 1; + inline bool has_type() const; + inline void clear_type(); + static const int kTypeFieldNumber = 1; + inline ::Remote::AuthRequest_Type type() const; + inline void set_type(::Remote::AuthRequest_Type value); - // required string user_password = 2; - inline bool has_user_password() const; - inline void clear_user_password(); - static const int kUserPasswordFieldNumber = 2; - inline const ::std::string& user_password() const; - inline void set_user_password(const ::std::string& value); - inline void set_user_password(const char* value); - inline void set_user_password(const char* value, size_t size); - inline ::std::string* mutable_user_password(); - inline ::std::string* release_user_password(); - inline void set_allocated_user_password(::std::string* user_password); + // optional .Remote.AuthRequest.Password password = 2; + inline bool has_password() const; + inline void clear_password(); + static const int kPasswordFieldNumber = 2; + inline const ::Remote::AuthRequest_Password& password() const; + inline ::Remote::AuthRequest_Password* mutable_password(); + inline ::Remote::AuthRequest_Password* release_password(); + inline void set_allocated_password(::Remote::AuthRequest_Password* password); // @@protoc_insertion_point(class_scope:Remote.AuthRequest) private: - inline void set_has_user_name(); - inline void clear_has_user_name(); - inline void set_has_user_password(); - inline void clear_has_user_password(); + inline void set_has_type(); + inline void clear_has_type(); + inline void set_has_password(); + inline void clear_has_password(); ::google::protobuf::UnknownFieldSet _unknown_fields_; - ::std::string* user_name_; - ::std::string* user_password_; + ::Remote::AuthRequest_Password* password_; + int type_; mutable int _cached_size_; ::google::protobuf::uint32 _has_bits_[(2 + 31) / 32]; @@ -141,6 +319,123 @@ class AuthRequest : public ::google::protobuf::Message { }; // ------------------------------------------------------------------- +class AuthResponse_PasswordResult : public ::google::protobuf::Message { + public: + AuthResponse_PasswordResult(); + virtual ~AuthResponse_PasswordResult(); + + AuthResponse_PasswordResult(const AuthResponse_PasswordResult& from); + + inline AuthResponse_PasswordResult& operator=(const AuthResponse_PasswordResult& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _unknown_fields_; + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return &_unknown_fields_; + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const AuthResponse_PasswordResult& default_instance(); + + void Swap(AuthResponse_PasswordResult* other); + + // implements Message ---------------------------------------------- + + AuthResponse_PasswordResult* New() const; + void CopyFrom(const ::google::protobuf::Message& from); + void MergeFrom(const ::google::protobuf::Message& from); + void CopyFrom(const AuthResponse_PasswordResult& from); + void MergeFrom(const AuthResponse_PasswordResult& from); + void Clear(); + bool IsInitialized() const; + + int ByteSize() const; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input); + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const; + int GetCachedSize() const { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const; + public: + + ::google::protobuf::Metadata GetMetadata() const; + + // nested types ---------------------------------------------------- + + typedef AuthResponse_PasswordResult_Type Type; + static const Type TypePasswordInvalid = AuthResponse_PasswordResult_Type_TypePasswordInvalid; + static const Type TypeLoginThrottling = AuthResponse_PasswordResult_Type_TypeLoginThrottling; + static const Type TypePasswordValid = AuthResponse_PasswordResult_Type_TypePasswordValid; + static inline bool Type_IsValid(int value) { + return AuthResponse_PasswordResult_Type_IsValid(value); + } + static const Type Type_MIN = + AuthResponse_PasswordResult_Type_Type_MIN; + static const Type Type_MAX = + AuthResponse_PasswordResult_Type_Type_MAX; + static const int Type_ARRAYSIZE = + AuthResponse_PasswordResult_Type_Type_ARRAYSIZE; + static inline const ::google::protobuf::EnumDescriptor* + Type_descriptor() { + return AuthResponse_PasswordResult_Type_descriptor(); + } + static inline const ::std::string& Type_Name(Type value) { + return AuthResponse_PasswordResult_Type_Name(value); + } + static inline bool Type_Parse(const ::std::string& name, + Type* value) { + return AuthResponse_PasswordResult_Type_Parse(name, value); + } + + // accessors ------------------------------------------------------- + + // required .Remote.AuthResponse.PasswordResult.Type type = 1; + inline bool has_type() const; + inline void clear_type(); + static const int kTypeFieldNumber = 1; + inline ::Remote::AuthResponse_PasswordResult_Type type() const; + inline void set_type(::Remote::AuthResponse_PasswordResult_Type value); + + // optional uint32 delay = 2; + inline bool has_delay() const; + inline void clear_delay(); + static const int kDelayFieldNumber = 2; + inline ::google::protobuf::uint32 delay() const; + inline void set_delay(::google::protobuf::uint32 value); + + // @@protoc_insertion_point(class_scope:Remote.AuthResponse.PasswordResult) + private: + inline void set_has_type(); + inline void clear_has_type(); + inline void set_has_delay(); + inline void clear_has_delay(); + + ::google::protobuf::UnknownFieldSet _unknown_fields_; + + int type_; + ::google::protobuf::uint32 delay_; + + mutable int _cached_size_; + ::google::protobuf::uint32 _has_bits_[(2 + 31) / 32]; + + friend void protobuf_AddDesc_auth_2eproto(); + friend void protobuf_AssignDesc_auth_2eproto(); + friend void protobuf_ShutdownFile_auth_2eproto(); + + void InitAsDefaultInstance(); + static AuthResponse_PasswordResult* default_instance_; +}; +// ------------------------------------------------------------------- + class AuthResponse : public ::google::protobuf::Message { public: AuthResponse(); @@ -193,28 +488,63 @@ class AuthResponse : public ::google::protobuf::Message { // nested types ---------------------------------------------------- + typedef AuthResponse_PasswordResult PasswordResult; + + typedef AuthResponse_Type Type; + static const Type TypePasswordResult = AuthResponse_Type_TypePasswordResult; + static inline bool Type_IsValid(int value) { + return AuthResponse_Type_IsValid(value); + } + static const Type Type_MIN = + AuthResponse_Type_Type_MIN; + static const Type Type_MAX = + AuthResponse_Type_Type_MAX; + static const int Type_ARRAYSIZE = + AuthResponse_Type_Type_ARRAYSIZE; + static inline const ::google::protobuf::EnumDescriptor* + Type_descriptor() { + return AuthResponse_Type_descriptor(); + } + static inline const ::std::string& Type_Name(Type value) { + return AuthResponse_Type_Name(value); + } + static inline bool Type_Parse(const ::std::string& name, + Type* value) { + return AuthResponse_Type_Parse(name, value); + } + // accessors ------------------------------------------------------- - // required .Remote.Error error = 1; - inline bool has_error() const; - inline void clear_error(); - static const int kErrorFieldNumber = 1; - inline const ::Remote::Error& error() const; - inline ::Remote::Error* mutable_error(); - inline ::Remote::Error* release_error(); - inline void set_allocated_error(::Remote::Error* error); + // required .Remote.AuthResponse.Type type = 1; + inline bool has_type() const; + inline void clear_type(); + static const int kTypeFieldNumber = 1; + inline ::Remote::AuthResponse_Type type() const; + inline void set_type(::Remote::AuthResponse_Type value); + + // optional .Remote.AuthResponse.PasswordResult password_result = 2; + inline bool has_password_result() const; + inline void clear_password_result(); + static const int kPasswordResultFieldNumber = 2; + inline const ::Remote::AuthResponse_PasswordResult& password_result() const; + inline ::Remote::AuthResponse_PasswordResult* mutable_password_result(); + inline ::Remote::AuthResponse_PasswordResult* release_password_result(); + inline void set_allocated_password_result(::Remote::AuthResponse_PasswordResult* password_result); // @@protoc_insertion_point(class_scope:Remote.AuthResponse) private: - inline void set_has_error(); - inline void clear_has_error(); + inline void set_has_type(); + inline void clear_has_type(); + inline void set_has_password_result(); + inline void clear_has_password_result(); ::google::protobuf::UnknownFieldSet _unknown_fields_; - ::Remote::Error* error_; + ::Remote::AuthResponse_PasswordResult* password_result_; + int type_; mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(1 + 31) / 32]; + ::google::protobuf::uint32 _has_bits_[(2 + 31) / 32]; friend void protobuf_AddDesc_auth_2eproto(); friend void protobuf_AssignDesc_auth_2eproto(); @@ -228,126 +558,126 @@ class AuthResponse : public ::google::protobuf::Message { // =================================================================== -// AuthRequest +// AuthRequest_Password -// required string user_name = 1; -inline bool AuthRequest::has_user_name() const { +// required string user_login = 1; +inline bool AuthRequest_Password::has_user_login() const { return (_has_bits_[0] & 0x00000001u) != 0; } -inline void AuthRequest::set_has_user_name() { +inline void AuthRequest_Password::set_has_user_login() { _has_bits_[0] |= 0x00000001u; } -inline void AuthRequest::clear_has_user_name() { +inline void AuthRequest_Password::clear_has_user_login() { _has_bits_[0] &= ~0x00000001u; } -inline void AuthRequest::clear_user_name() { - if (user_name_ != &::google::protobuf::internal::kEmptyString) { - user_name_->clear(); +inline void AuthRequest_Password::clear_user_login() { + if (user_login_ != &::google::protobuf::internal::kEmptyString) { + user_login_->clear(); } - clear_has_user_name(); + clear_has_user_login(); } -inline const ::std::string& AuthRequest::user_name() const { - return *user_name_; +inline const ::std::string& AuthRequest_Password::user_login() const { + return *user_login_; } -inline void AuthRequest::set_user_name(const ::std::string& value) { - set_has_user_name(); - if (user_name_ == &::google::protobuf::internal::kEmptyString) { - user_name_ = new ::std::string; +inline void AuthRequest_Password::set_user_login(const ::std::string& value) { + set_has_user_login(); + if (user_login_ == &::google::protobuf::internal::kEmptyString) { + user_login_ = new ::std::string; } - user_name_->assign(value); + user_login_->assign(value); } -inline void AuthRequest::set_user_name(const char* value) { - set_has_user_name(); - if (user_name_ == &::google::protobuf::internal::kEmptyString) { - user_name_ = new ::std::string; +inline void AuthRequest_Password::set_user_login(const char* value) { + set_has_user_login(); + if (user_login_ == &::google::protobuf::internal::kEmptyString) { + user_login_ = new ::std::string; } - user_name_->assign(value); + user_login_->assign(value); } -inline void AuthRequest::set_user_name(const char* value, size_t size) { - set_has_user_name(); - if (user_name_ == &::google::protobuf::internal::kEmptyString) { - user_name_ = new ::std::string; +inline void AuthRequest_Password::set_user_login(const char* value, size_t size) { + set_has_user_login(); + if (user_login_ == &::google::protobuf::internal::kEmptyString) { + user_login_ = new ::std::string; } - user_name_->assign(reinterpret_cast(value), size); + user_login_->assign(reinterpret_cast(value), size); } -inline ::std::string* AuthRequest::mutable_user_name() { - set_has_user_name(); - if (user_name_ == &::google::protobuf::internal::kEmptyString) { - user_name_ = new ::std::string; +inline ::std::string* AuthRequest_Password::mutable_user_login() { + set_has_user_login(); + if (user_login_ == &::google::protobuf::internal::kEmptyString) { + user_login_ = new ::std::string; } - return user_name_; + return user_login_; } -inline ::std::string* AuthRequest::release_user_name() { - clear_has_user_name(); - if (user_name_ == &::google::protobuf::internal::kEmptyString) { +inline ::std::string* AuthRequest_Password::release_user_login() { + clear_has_user_login(); + if (user_login_ == &::google::protobuf::internal::kEmptyString) { return NULL; } else { - ::std::string* temp = user_name_; - user_name_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + ::std::string* temp = user_login_; + user_login_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); return temp; } } -inline void AuthRequest::set_allocated_user_name(::std::string* user_name) { - if (user_name_ != &::google::protobuf::internal::kEmptyString) { - delete user_name_; +inline void AuthRequest_Password::set_allocated_user_login(::std::string* user_login) { + if (user_login_ != &::google::protobuf::internal::kEmptyString) { + delete user_login_; } - if (user_name) { - set_has_user_name(); - user_name_ = user_name; + if (user_login) { + set_has_user_login(); + user_login_ = user_login; } else { - clear_has_user_name(); - user_name_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); + clear_has_user_login(); + user_login_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString); } } // required string user_password = 2; -inline bool AuthRequest::has_user_password() const { +inline bool AuthRequest_Password::has_user_password() const { return (_has_bits_[0] & 0x00000002u) != 0; } -inline void AuthRequest::set_has_user_password() { +inline void AuthRequest_Password::set_has_user_password() { _has_bits_[0] |= 0x00000002u; } -inline void AuthRequest::clear_has_user_password() { +inline void AuthRequest_Password::clear_has_user_password() { _has_bits_[0] &= ~0x00000002u; } -inline void AuthRequest::clear_user_password() { +inline void AuthRequest_Password::clear_user_password() { if (user_password_ != &::google::protobuf::internal::kEmptyString) { user_password_->clear(); } clear_has_user_password(); } -inline const ::std::string& AuthRequest::user_password() const { +inline const ::std::string& AuthRequest_Password::user_password() const { return *user_password_; } -inline void AuthRequest::set_user_password(const ::std::string& value) { +inline void AuthRequest_Password::set_user_password(const ::std::string& value) { set_has_user_password(); if (user_password_ == &::google::protobuf::internal::kEmptyString) { user_password_ = new ::std::string; } user_password_->assign(value); } -inline void AuthRequest::set_user_password(const char* value) { +inline void AuthRequest_Password::set_user_password(const char* value) { set_has_user_password(); if (user_password_ == &::google::protobuf::internal::kEmptyString) { user_password_ = new ::std::string; } user_password_->assign(value); } -inline void AuthRequest::set_user_password(const char* value, size_t size) { +inline void AuthRequest_Password::set_user_password(const char* value, size_t size) { set_has_user_password(); if (user_password_ == &::google::protobuf::internal::kEmptyString) { user_password_ = new ::std::string; } user_password_->assign(reinterpret_cast(value), size); } -inline ::std::string* AuthRequest::mutable_user_password() { +inline ::std::string* AuthRequest_Password::mutable_user_password() { set_has_user_password(); if (user_password_ == &::google::protobuf::internal::kEmptyString) { user_password_ = new ::std::string; } return user_password_; } -inline ::std::string* AuthRequest::release_user_password() { +inline ::std::string* AuthRequest_Password::release_user_password() { clear_has_user_password(); if (user_password_ == &::google::protobuf::internal::kEmptyString) { return NULL; @@ -357,7 +687,7 @@ inline ::std::string* AuthRequest::release_user_password() { return temp; } } -inline void AuthRequest::set_allocated_user_password(::std::string* user_password) { +inline void AuthRequest_Password::set_allocated_user_password(::std::string* user_password) { if (user_password_ != &::google::protobuf::internal::kEmptyString) { delete user_password_; } @@ -372,43 +702,180 @@ inline void AuthRequest::set_allocated_user_password(::std::string* user_passwor // ------------------------------------------------------------------- -// AuthResponse +// AuthRequest -// required .Remote.Error error = 1; -inline bool AuthResponse::has_error() const { +// required .Remote.AuthRequest.Type type = 1; +inline bool AuthRequest::has_type() const { return (_has_bits_[0] & 0x00000001u) != 0; } -inline void AuthResponse::set_has_error() { +inline void AuthRequest::set_has_type() { _has_bits_[0] |= 0x00000001u; } -inline void AuthResponse::clear_has_error() { +inline void AuthRequest::clear_has_type() { _has_bits_[0] &= ~0x00000001u; } -inline void AuthResponse::clear_error() { - if (error_ != NULL) error_->::Remote::Error::Clear(); - clear_has_error(); +inline void AuthRequest::clear_type() { + type_ = 1; + clear_has_type(); } -inline const ::Remote::Error& AuthResponse::error() const { - return error_ != NULL ? *error_ : *default_instance_->error_; +inline ::Remote::AuthRequest_Type AuthRequest::type() const { + return static_cast< ::Remote::AuthRequest_Type >(type_); } -inline ::Remote::Error* AuthResponse::mutable_error() { - set_has_error(); - if (error_ == NULL) error_ = new ::Remote::Error; - return error_; +inline void AuthRequest::set_type(::Remote::AuthRequest_Type value) { + assert(::Remote::AuthRequest_Type_IsValid(value)); + set_has_type(); + type_ = value; } -inline ::Remote::Error* AuthResponse::release_error() { - clear_has_error(); - ::Remote::Error* temp = error_; - error_ = NULL; + +// optional .Remote.AuthRequest.Password password = 2; +inline bool AuthRequest::has_password() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void AuthRequest::set_has_password() { + _has_bits_[0] |= 0x00000002u; +} +inline void AuthRequest::clear_has_password() { + _has_bits_[0] &= ~0x00000002u; +} +inline void AuthRequest::clear_password() { + if (password_ != NULL) password_->::Remote::AuthRequest_Password::Clear(); + clear_has_password(); +} +inline const ::Remote::AuthRequest_Password& AuthRequest::password() const { + return password_ != NULL ? *password_ : *default_instance_->password_; +} +inline ::Remote::AuthRequest_Password* AuthRequest::mutable_password() { + set_has_password(); + if (password_ == NULL) password_ = new ::Remote::AuthRequest_Password; + return password_; +} +inline ::Remote::AuthRequest_Password* AuthRequest::release_password() { + clear_has_password(); + ::Remote::AuthRequest_Password* temp = password_; + password_ = NULL; return temp; } -inline void AuthResponse::set_allocated_error(::Remote::Error* error) { - delete error_; - error_ = error; - if (error) { - set_has_error(); +inline void AuthRequest::set_allocated_password(::Remote::AuthRequest_Password* password) { + delete password_; + password_ = password; + if (password) { + set_has_password(); } else { - clear_has_error(); + clear_has_password(); + } +} + +// ------------------------------------------------------------------- + +// AuthResponse_PasswordResult + +// required .Remote.AuthResponse.PasswordResult.Type type = 1; +inline bool AuthResponse_PasswordResult::has_type() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void AuthResponse_PasswordResult::set_has_type() { + _has_bits_[0] |= 0x00000001u; +} +inline void AuthResponse_PasswordResult::clear_has_type() { + _has_bits_[0] &= ~0x00000001u; +} +inline void AuthResponse_PasswordResult::clear_type() { + type_ = 1; + clear_has_type(); +} +inline ::Remote::AuthResponse_PasswordResult_Type AuthResponse_PasswordResult::type() const { + return static_cast< ::Remote::AuthResponse_PasswordResult_Type >(type_); +} +inline void AuthResponse_PasswordResult::set_type(::Remote::AuthResponse_PasswordResult_Type value) { + assert(::Remote::AuthResponse_PasswordResult_Type_IsValid(value)); + set_has_type(); + type_ = value; +} + +// optional uint32 delay = 2; +inline bool AuthResponse_PasswordResult::has_delay() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void AuthResponse_PasswordResult::set_has_delay() { + _has_bits_[0] |= 0x00000002u; +} +inline void AuthResponse_PasswordResult::clear_has_delay() { + _has_bits_[0] &= ~0x00000002u; +} +inline void AuthResponse_PasswordResult::clear_delay() { + delay_ = 0u; + clear_has_delay(); +} +inline ::google::protobuf::uint32 AuthResponse_PasswordResult::delay() const { + return delay_; +} +inline void AuthResponse_PasswordResult::set_delay(::google::protobuf::uint32 value) { + set_has_delay(); + delay_ = value; +} + +// ------------------------------------------------------------------- + +// AuthResponse + +// required .Remote.AuthResponse.Type type = 1; +inline bool AuthResponse::has_type() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void AuthResponse::set_has_type() { + _has_bits_[0] |= 0x00000001u; +} +inline void AuthResponse::clear_has_type() { + _has_bits_[0] &= ~0x00000001u; +} +inline void AuthResponse::clear_type() { + type_ = 1; + clear_has_type(); +} +inline ::Remote::AuthResponse_Type AuthResponse::type() const { + return static_cast< ::Remote::AuthResponse_Type >(type_); +} +inline void AuthResponse::set_type(::Remote::AuthResponse_Type value) { + assert(::Remote::AuthResponse_Type_IsValid(value)); + set_has_type(); + type_ = value; +} + +// optional .Remote.AuthResponse.PasswordResult password_result = 2; +inline bool AuthResponse::has_password_result() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void AuthResponse::set_has_password_result() { + _has_bits_[0] |= 0x00000002u; +} +inline void AuthResponse::clear_has_password_result() { + _has_bits_[0] &= ~0x00000002u; +} +inline void AuthResponse::clear_password_result() { + if (password_result_ != NULL) password_result_->::Remote::AuthResponse_PasswordResult::Clear(); + clear_has_password_result(); +} +inline const ::Remote::AuthResponse_PasswordResult& AuthResponse::password_result() const { + return password_result_ != NULL ? *password_result_ : *default_instance_->password_result_; +} +inline ::Remote::AuthResponse_PasswordResult* AuthResponse::mutable_password_result() { + set_has_password_result(); + if (password_result_ == NULL) password_result_ = new ::Remote::AuthResponse_PasswordResult; + return password_result_; +} +inline ::Remote::AuthResponse_PasswordResult* AuthResponse::release_password_result() { + clear_has_password_result(); + ::Remote::AuthResponse_PasswordResult* temp = password_result_; + password_result_ = NULL; + return temp; +} +inline void AuthResponse::set_allocated_password_result(::Remote::AuthResponse_PasswordResult* password_result) { + delete password_result_; + password_result_ = password_result; + if (password_result) { + set_has_password_result(); + } else { + clear_has_password_result(); } } @@ -421,6 +888,18 @@ inline void AuthResponse::set_allocated_error(::Remote::Error* error) { namespace google { namespace protobuf { +template <> +inline const EnumDescriptor* GetEnumDescriptor< ::Remote::AuthRequest_Type>() { + return ::Remote::AuthRequest_Type_descriptor(); +} +template <> +inline const EnumDescriptor* GetEnumDescriptor< ::Remote::AuthResponse_PasswordResult_Type>() { + return ::Remote::AuthResponse_PasswordResult_Type_descriptor(); +} +template <> +inline const EnumDescriptor* GetEnumDescriptor< ::Remote::AuthResponse_Type>() { + return ::Remote::AuthResponse_Type_descriptor(); +} } // namespace google } // namespace protobuf diff --git a/remote/proto/auth.proto b/remote/proto/auth.proto index b432d44c..de3bfadd 100644 --- a/remote/proto/auth.proto +++ b/remote/proto/auth.proto @@ -4,12 +4,45 @@ package Remote; message AuthRequest { - required string user_name = 1; - required string user_password = 2; + message Password + { + required string user_login = 1; + required string user_password = 2; + } + + enum Type + { + TypePassword = 1; + } + + required Type type = 1; + + optional Password password = 2; } message AuthResponse { - required Error error = 1; + + message PasswordResult + { + enum Type + { + TypePasswordInvalid = 1; + TypeLoginThrottling = 2; // The attempt was not processed because of throttling + TypePasswordValid = 3; + } + required Type type = 1; + + optional uint32 delay = 2; // in seconds, in case of PasswordInvalid/LoginThrottling + } + + enum Type + { + TypePasswordResult = 1; + } + + required Type type = 1; + + optional PasswordResult password_result = 2; } diff --git a/remote/server/AuthRequestHandler.cpp b/remote/server/AuthRequestHandler.cpp new file mode 100644 index 00000000..1266392f --- /dev/null +++ b/remote/server/AuthRequestHandler.cpp @@ -0,0 +1,81 @@ +#include + +#include "AuthRequestHandler.hpp" + +namespace Remote { +namespace Server { + +AuthRequestHandler::AuthRequestHandler(Database::Handler& db) +: _db(db) +{ +} + +bool +AuthRequestHandler::process(const AuthRequest& request, AuthResponse& response) +{ + bool res = false; + + switch (request.type()) + { + case AuthRequest::TypePassword: + if (request.has_password()) + { + res = processPassword(request.password(), *response.mutable_password_result()); + if (res) + response.set_type(AuthResponse::TypePasswordResult); + } + else + std::cerr << "Bad AuthRequest::TypePassword" << std::endl; + break; + } + + return res; +} + + +bool +AuthRequestHandler::processPassword(const AuthRequest::Password& request, AuthResponse::PasswordResult& response) +{ + bool res = false; + + // Get the user + const Wt::Auth::User& user = _db.getUserDatabase().findWithIdentity(Wt::Auth::Identity::LoginName, request.user_login()); + if (user.isValid()) + { + // Now attempt to log the user in + + Wt::Auth::PasswordResult result = _db.getPasswordService().verifyPassword(user, request.user_password()); + switch( result ) + { + case Wt::Auth::PasswordInvalid: + response.set_type(AuthResponse::PasswordResult::TypePasswordInvalid); + res = true; + break; + case Wt::Auth::LoginThrottling: + response.set_type(AuthResponse::PasswordResult::TypeLoginThrottling); + response.set_delay(_db.getPasswordService().delayForNextAttempt(user)); + res = true; + break; + case Wt::Auth::PasswordValid: + response.set_type(AuthResponse::PasswordResult::TypePasswordValid); + // Log the user in + _db.getLogin().login( user ); + res = true; + break; + default: + break; + } + + } + else + { + std::cerr << "Invalid user '" << request.user_login() << std::endl; + response.set_type(AuthResponse::PasswordResult::TypePasswordInvalid); + } + + return res; +} + +} // namespace Remote +} // namespace Server + diff --git a/remote/server/AuthRequestHandler.hpp b/remote/server/AuthRequestHandler.hpp new file mode 100644 index 00000000..3543f3b8 --- /dev/null +++ b/remote/server/AuthRequestHandler.hpp @@ -0,0 +1,28 @@ +#ifndef REMOTE_AUTH_REQUEST_HANDLER +#define REMOTE_AUTH_REQUEST_HANDLER + +#include "messages/messages.pb.h" + +#include "database/DatabaseHandler.hpp" + +namespace Remote { +namespace Server { + +class AuthRequestHandler +{ + public: + AuthRequestHandler(Database::Handler& db); + + bool process(const AuthRequest& request, AuthResponse& response); + + private: + + bool processPassword(const AuthRequest::Password& request, AuthResponse::PasswordResult& response); + + Database::Handler& _db; +}; + +} // namespace Remote +} // namespace Server + +#endif diff --git a/remote/server/RequestHandler.cpp b/remote/server/RequestHandler.cpp index 24ac783c..7c09cb35 100644 --- a/remote/server/RequestHandler.cpp +++ b/remote/server/RequestHandler.cpp @@ -6,11 +6,18 @@ namespace Server { RequestHandler::RequestHandler(boost::filesystem::path dbPath) : _db( dbPath ), +_authRequestHandler(_db), _audioCollectionRequestHandler(_db), _mediaRequestHandler(_db) { } +RequestHandler::~RequestHandler() +{ + // TODO manually log out user if needed? + _db.getLogin().logout(); +} + bool RequestHandler::process(const ClientMessage& request, ServerMessage& response) { @@ -19,30 +26,44 @@ RequestHandler::process(const ClientMessage& request, ServerMessage& response) switch(request.type()) { - case ClientMessage_Type_AuthRequest: - - break; - case ClientMessage_Type_AudioCollectionRequest: - if (request.has_audio_collection_request()) + case ClientMessage::AuthRequest: + if (request.has_auth_request()) { - res = _audioCollectionRequestHandler.process(request.audio_collection_request(), *response.mutable_audio_collection_response()); + res = _authRequestHandler.process(request.auth_request(), *response.mutable_auth_response()); if (res) - response.set_type( ServerMessage::AudioCollectionResponse); + response.set_type(ServerMessage::AuthResponse); } else - std::cerr << "Malformed AudioCollectionRequest message!" << std::endl; + std::cerr << "Bad ClientMessage::AuthRequest !" << std::endl; + break; + case ClientMessage::AudioCollectionRequest: + // Not allowed if the user is not logged in + if (_db.getLogin().loggedIn()) + { + if (request.has_audio_collection_request()) + { + res = _audioCollectionRequestHandler.process(request.audio_collection_request(), *response.mutable_audio_collection_response()); + if (res) + response.set_type( ServerMessage::AudioCollectionResponse); + } + else + std::cerr << "Bad ClientMessage::AudioCollectionRequest message!" << std::endl; + } break; - case ClientMessage_Type_MediaRequest: - if (request.has_media_request()) + case ClientMessage::MediaRequest: + // Not allowed if the user is not logged in + if (_db.getLogin().loggedIn()) { - res = _mediaRequestHandler.process(request.media_request(), *response.mutable_media_response()); - if (res) - response.set_type( ServerMessage::MediaResponse); + if (request.has_media_request()) + { + res = _mediaRequestHandler.process(request.media_request(), *response.mutable_media_response()); + if (res) + response.set_type( ServerMessage::MediaResponse); + } + else + std::cerr << "Malformed ClientMessage::MediaRequest message!" << std::endl; } - else - std::cerr << "Malformed AudioCollectionRequest message!" << std::endl; - break; break; default: diff --git a/remote/server/RequestHandler.hpp b/remote/server/RequestHandler.hpp index 69a978e0..5701f199 100644 --- a/remote/server/RequestHandler.hpp +++ b/remote/server/RequestHandler.hpp @@ -7,6 +7,7 @@ #include "database/DatabaseHandler.hpp" +#include "AuthRequestHandler.hpp" #include "AudioCollectionRequestHandler.hpp" #include "MediaRequestHandler.hpp" @@ -18,15 +19,15 @@ class RequestHandler public: RequestHandler(boost::filesystem::path dbPath); + ~RequestHandler(); bool process(const ClientMessage& request, ServerMessage& response); - bool processAudioCollectionRequest(const AudioCollectionRequest& request, ServerMessage& response); - private: Database::Handler _db; + AuthRequestHandler _authRequestHandler; AudioCollectionRequestHandler _audioCollectionRequestHandler; MediaRequestHandler _mediaRequestHandler; }; diff --git a/test/RemoteClientServer.cpp b/test/RemoteClientServer.cpp index 62da00c6..55fb8cc5 100644 --- a/test/RemoteClientServer.cpp +++ b/test/RemoteClientServer.cpp @@ -432,6 +432,33 @@ class TestClient return response.audio_collection_response().revision().rev(); } + bool login(const std::string& username, const std::string& password) + { + // Send request + Remote::ClientMessage request; + + request.set_type( Remote::ClientMessage::AuthRequest ); + + request.mutable_auth_request()->set_type( Remote::AuthRequest::TypePassword); + request.mutable_auth_request()->mutable_password()->set_user_login( username ); + request.mutable_auth_request()->mutable_password()->set_user_password( password ); + + sendMsg(request); + + // Receive responses + Remote::ServerMessage response; + recvMsg(response); + + // Process message + if (!response.has_auth_response()) + throw std::runtime_error("not an auth response!"); + + if (!response.auth_response().has_password_result()) + throw std::runtime_error("not a password result!"); + + return (response.auth_response().password_result().type() == Remote::AuthResponse::PasswordResult::TypePasswordValid); + } + private: bool verifyCertificate(bool preverified, boost::asio::ssl::verify_context& ctx) @@ -684,6 +711,10 @@ int main() // connect to loopback TestClient client( boost::asio::ip::tcp::endpoint( boost::asio::ip::address_v4::loopback(), 5080)); + // Use a dumb account in order to test the login + if (!client.login("toto", "Tot&3131")) + throw std::runtime_error("login failed!"); + // **** REVISION *** std::string rev = client.getRevision(); std::cout << "Revision '" << rev << "'" << std::endl;