Home | History | Annotate | Download | only in xmpp
      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 
     11 #ifndef WEBRTC_LIBJINGLE_XMPP_SASLCOOKIEMECHANISM_H_
     12 #define WEBRTC_LIBJINGLE_XMPP_SASLCOOKIEMECHANISM_H_
     13 
     14 #include "webrtc/libjingle/xmllite/qname.h"
     15 #include "webrtc/libjingle/xmllite/xmlelement.h"
     16 #include "webrtc/libjingle/xmpp/constants.h"
     17 #include "webrtc/libjingle/xmpp/saslmechanism.h"
     18 
     19 namespace buzz {
     20 
     21 class SaslCookieMechanism : public SaslMechanism {
     22 
     23 public:
     24   SaslCookieMechanism(const std::string & mechanism,
     25                       const std::string & username,
     26                       const std::string & cookie,
     27                       const std::string & token_service)
     28     : mechanism_(mechanism),
     29       username_(username),
     30       cookie_(cookie),
     31       token_service_(token_service) {}
     32 
     33   SaslCookieMechanism(const std::string & mechanism,
     34                       const std::string & username,
     35                       const std::string & cookie)
     36     : mechanism_(mechanism),
     37       username_(username),
     38       cookie_(cookie),
     39       token_service_("") {}
     40 
     41   virtual std::string GetMechanismName() { return mechanism_; }
     42 
     43   virtual XmlElement * StartSaslAuth() {
     44     // send initial request
     45     XmlElement * el = new XmlElement(QN_SASL_AUTH, true);
     46     el->AddAttr(QN_MECHANISM, mechanism_);
     47     if (!token_service_.empty()) {
     48       el->AddAttr(QN_GOOGLE_AUTH_SERVICE, token_service_);
     49     }
     50 
     51     std::string credential;
     52     credential.append("\0", 1);
     53     credential.append(username_);
     54     credential.append("\0", 1);
     55     credential.append(cookie_);
     56     el->AddText(Base64Encode(credential));
     57     return el;
     58   }
     59 
     60 private:
     61   std::string mechanism_;
     62   std::string username_;
     63   std::string cookie_;
     64   std::string token_service_;
     65 };
     66 
     67 }
     68 
     69 #endif  // WEBRTC_LIBJINGLE_XMPP_SASLCOOKIEMECHANISM_H_
     70