diff options
Diffstat (limited to 'examples/example6_authenticator.hpp')
-rw-r--r-- | examples/example6_authenticator.hpp | 66 |
1 files changed, 36 insertions, 30 deletions
diff --git a/examples/example6_authenticator.hpp b/examples/example6_authenticator.hpp index 64336e2a..56f02392 100644 --- a/examples/example6_authenticator.hpp +++ b/examples/example6_authenticator.hpp @@ -3,20 +3,23 @@ #if VMIME_HAVE_SASL_SUPPORT // SASL authentication handler -class interactiveAuthenticator : public vmime::security::sasl::defaultSASLAuthenticator -{ - const std::vector <vmime::shared_ptr <vmime::security::sasl::SASLMechanism> > getAcceptableMechanisms - (const std::vector <vmime::shared_ptr <vmime::security::sasl::SASLMechanism> >& available, - const vmime::shared_ptr <vmime::security::sasl::SASLMechanism>& suggested) const - { +class interactiveAuthenticator : public vmime::security::sasl::defaultSASLAuthenticator { + + const std::vector <vmime::shared_ptr <vmime::security::sasl::SASLMechanism> > + getAcceptableMechanisms( + const std::vector <vmime::shared_ptr <vmime::security::sasl::SASLMechanism> >& available, + const vmime::shared_ptr <vmime::security::sasl::SASLMechanism>& suggested + ) const { + std::cout << std::endl << "Available SASL mechanisms:" << std::endl; - for (unsigned int i = 0 ; i < available.size() ; ++i) - { + for (unsigned int i = 0 ; i < available.size() ; ++i) { + std::cout << " " << available[i]->getName(); - if (suggested && available[i]->getName() == suggested->getName()) + if (suggested && available[i]->getName() == suggested->getName()) { std::cout << "(suggested)"; + } } std::cout << std::endl << std::endl; @@ -24,31 +27,33 @@ class interactiveAuthenticator : public vmime::security::sasl::defaultSASLAuthen return defaultSASLAuthenticator::getAcceptableMechanisms(available, suggested); } - void setSASLMechanism(const vmime::shared_ptr <vmime::security::sasl::SASLMechanism>& mech) - { + void setSASLMechanism(const vmime::shared_ptr <vmime::security::sasl::SASLMechanism>& mech) { + std::cout << "Trying '" << mech->getName() << "' authentication mechanism" << std::endl; defaultSASLAuthenticator::setSASLMechanism(mech); } - const vmime::string getUsername() const - { - if (m_username.empty()) + const vmime::string getUsername() const { + + if (m_username.empty()) { m_username = getUserInput("Username"); + } return m_username; } - const vmime::string getPassword() const - { - if (m_password.empty()) + const vmime::string getPassword() const { + + if (m_password.empty()) { m_password = getUserInput("Password"); + } return m_password; } - static const vmime::string getUserInput(const std::string& prompt) - { + static const vmime::string getUserInput(const std::string& prompt) { + std::cout << prompt << ": "; std::cout.flush(); @@ -67,26 +72,28 @@ private: #else // !VMIME_HAVE_SASL_SUPPORT // Simple authentication handler -class interactiveAuthenticator : public vmime::security::defaultAuthenticator -{ - const vmime::string getUsername() const - { - if (m_username.empty()) +class interactiveAuthenticator : public vmime::security::defaultAuthenticator { + + const vmime::string getUsername() const { + + if (m_username.empty()) { m_username = getUserInput("Username"); + } return m_username; } - const vmime::string getPassword() const - { - if (m_password.empty()) + const vmime::string getPassword() const { + + if (m_password.empty()) { m_password = getUserInput("Password"); + } return m_password; } - static const vmime::string getUserInput(const std::string& prompt) - { + static const vmime::string getUserInput(const std::string& prompt) { + std::cout << prompt << ": "; std::cout.flush(); @@ -103,4 +110,3 @@ private: }; #endif // VMIME_HAVE_SASL_SUPPORT - |