saslplainmechanism.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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_SASLPLAINMECHANISM_H_
  11. #define THIRD_PARTY_LIBJINGLE_XMPP_XMPP_SASLPLAINMECHANISM_H_
  12. #include "third_party/libjingle_xmpp/xmpp/saslmechanism.h"
  13. namespace jingle_xmpp {
  14. class SaslPlainMechanism : public SaslMechanism {
  15. public:
  16. SaslPlainMechanism(const jingle_xmpp::Jid user_jid, const std::string & password) :
  17. user_jid_(user_jid), password_(password) {}
  18. virtual std::string GetMechanismName() { return "PLAIN"; }
  19. virtual XmlElement * StartSaslAuth() {
  20. // send initial request
  21. XmlElement * el = new XmlElement(QN_SASL_AUTH, true);
  22. el->AddAttr(QN_MECHANISM, "PLAIN");
  23. std::stringstream ss;
  24. ss.write("\0", 1);
  25. ss << user_jid_.node();
  26. ss.write("\0", 1);
  27. ss << password_;
  28. el->AddText(Base64EncodeFromArray(ss.str().data(), ss.str().length()));
  29. return el;
  30. }
  31. private:
  32. Jid user_jid_;
  33. std::string password_;
  34. };
  35. }
  36. #endif // THIRD_PARTY_LIBJINGLE_XMPP_XMPP_SASLPLAINMECHANISM_H_