plainsaslhandler.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright 2004 The WebRTC Project Authors. All rights reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef THIRD_PARTY_LIBJINGLE_XMPP_XMPP_PLAINSASLHANDLER_H_
  11. #define THIRD_PARTY_LIBJINGLE_XMPP_XMPP_PLAINSASLHANDLER_H_
  12. #include <algorithm>
  13. #include "third_party/libjingle_xmpp/xmpp/saslhandler.h"
  14. #include "third_party/libjingle_xmpp/xmpp/saslplainmechanism.h"
  15. namespace jingle_xmpp {
  16. class PlainSaslHandler : public SaslHandler {
  17. public:
  18. PlainSaslHandler(const Jid & jid, const std::string & password,
  19. bool allow_plain) : jid_(jid), password_(password),
  20. allow_plain_(allow_plain) {}
  21. virtual ~PlainSaslHandler() {}
  22. // Should pick the best method according to this handler
  23. // returns the empty string if none are suitable
  24. virtual std::string ChooseBestSaslMechanism(const std::vector<std::string> & mechanisms, bool encrypted) {
  25. if (!encrypted && !allow_plain_) {
  26. return "";
  27. }
  28. std::vector<std::string>::const_iterator it = std::find(mechanisms.begin(), mechanisms.end(), "PLAIN");
  29. if (it == mechanisms.end()) {
  30. return "";
  31. }
  32. else {
  33. return "PLAIN";
  34. }
  35. }
  36. // Creates a SaslMechanism for the given mechanism name (you own it
  37. // once you get it). If not handled, return NULL.
  38. virtual SaslMechanism * CreateSaslMechanism(const std::string & mechanism) {
  39. if (mechanism == "PLAIN") {
  40. return new SaslPlainMechanism(jid_, password_);
  41. }
  42. return NULL;
  43. }
  44. private:
  45. Jid jid_;
  46. std::string password_;
  47. bool allow_plain_;
  48. };
  49. }
  50. #endif // THIRD_PARTY_LIBJINGLE_XMPP_XMPP_PLAINSASLHANDLER_H_