1 // Copyright 2009 The Archiveopteryx Developers <info@aox.org> 2 3 #ifndef MECHANISM_H 4 #define MECHANISM_H 5 6 #include "log.h" 7 #include "event.h" 8 #include "estring.h" 9 #include "ustring.h" 10 11 class User; 12 13 14 class SaslMechanism 15 : public EventHandler 16 { 17 public: ~SaslMechanism()18 virtual ~SaslMechanism() {} 19 20 enum Type { 21 Anonymous, 22 Plain, 23 Login, 24 CramMD5, 25 DigestMD5 26 }; 27 Type type() const; 28 EString name() const; 29 30 enum State { 31 AwaitingInitialResponse, 32 IssuingChallenge, AwaitingResponse, Authenticating, 33 Succeeded, Failed, Terminated 34 }; 35 State state() const; 36 void setState( State ); 37 38 void execute(); 39 void readInitialResponse( const EString * ); 40 void readResponse( const EString * ); 41 virtual EString challenge(); 42 virtual void parseResponse( const EString & ) = 0; 43 virtual void verify(); 44 45 bool done() const; 46 47 User * user() const; 48 UString login() const; 49 void setLogin( const UString & ); 50 void setLogin( const EString & ); 51 UString secret() const; 52 void setSecret( const UString & ); 53 void setSecret( const EString & ); 54 UString storedSecret() const; 55 void setStoredSecret( const UString & ); 56 virtual void setChallenge( const EString & ); 57 58 static SaslMechanism * create( const EString &, EventHandler *, 59 class SaslConnection * ); 60 61 static bool allowed( Type, bool ); 62 static EString allowedMechanisms( const EString &, bool ); 63 64 void log( const EString &, Log::Severity = Log::Info ); 65 66 void tick(); 67 68 protected: 69 SaslMechanism( EventHandler *, Type ); 70 private: 71 class SaslData *d; 72 }; 73 74 75 #endif 76