lluserauth.h

Go to the documentation of this file.
00001 
00032 #ifndef LLUSERAUTH_H
00033 #define LLUSERAUTH_H
00034 
00035 #include <string>
00036 #include <vector>
00037 #include <map>
00038 
00039 class LLXMLRPCTransaction;
00040 
00041 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00042 // Class LLUserAuth
00043 //
00044 // This class encapsulates the authentication and initialization from
00045 // the login server. Construct an instance of this object, and call
00046 // the authenticate() method, and call authResponse() until it returns
00047 // a non-negative value. If that method returns E_OK, you can start
00048 // asking for responses via the getResponse() method. Here is some
00049 // sample code that gets the session id if login was successful:
00050 //
00051 //  auth.authenticate(...);
00052 //  while((auth.authResponse() < 0)) {sleep(1);}
00053 //  LLUUID session_id;
00054 //  if(0 == strcmp(auth.getResponse("login"), "true"))
00055 //  {
00056 //    const char* session_id_str = auth.getResponse("session-id");
00057 //    if(session_id_str) session_id.set(session_id_str);
00058 //  }
00059 //
00060 // Format for responses as maintained in login.cgi:
00061 // login = 'true' | 'false'
00062 // reason = [ 'data'  |    -- insufficient or poorly formatted data
00063 //            'ban' |      -- user is banned
00064 //            'update' |   -- viewer requires update
00065 //            'optional' | -- optional viewer update
00066 //            'key' |      -- mismatched first/last/passwd
00067 // message = human readable message for client
00068 // session-id = auth key
00069 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00070 
00071 class LLUserAuth
00072 {
00073 public:
00074         LLUserAuth();
00075         ~LLUserAuth();
00076 
00077         // These codes map to the curl return codes...
00078         typedef enum {
00079                 E_NO_RESPONSE_YET = -2,
00080                 E_DOWNLOADING = -1,
00081                 E_OK = 0,
00082                 E_COULDNT_RESOLVE_HOST,
00083                 E_SSL_PEER_CERTIFICATE,
00084                 E_SSL_CACERT,
00085                 E_SSL_CONNECT_ERROR,
00086                 E_UNHANDLED_ERROR,
00087                 E_LAST                                          // never use!
00088         } UserAuthcode;
00089 
00090         // used for holding options
00091         typedef std::map<std::string, std::string> response_t;
00092         typedef std::vector<response_t> options_t;
00093 
00094         void authenticate(
00095                 const char* auth_uri,
00096                 const char* auth_method,
00097                 const char* firstname,
00098                 const char* lastname,
00099                 const char* passwd,
00100                 const char* start,
00101                 BOOL skip_optional_update,
00102                 BOOL accept_tos,
00103                 BOOL accept_critical_message,
00104                 const LLUUID& viewer_digest,
00105                 BOOL last_exec_froze, 
00106                 const std::vector<const char*>& requested_options,
00107                 const std::string& hashed_mac,
00108                 const std::string& hashed_volume_serial);
00109 
00110         UserAuthcode authResponse();
00111         
00112         std::string errorMessage() const { return mErrorMessage; }
00113 
00114         // function to get a direct reponse from the login api by
00115         // name. returns NULL if the named response was not found.
00116         const char* getResponse(const char* name) const;
00117         BOOL getOptions(const char* name, options_t& options) const;
00118 
00119         F64 getLastTransferRateBPS() const { return mLastTransferRateBPS; }
00120 
00121 private:
00122         LLXMLRPCTransaction* mTransaction;
00123 
00124         UserAuthcode mAuthResponse;
00125         std::string mErrorMessage;
00126         
00127         // dealing with the XML
00128         typedef std::map<std::string, options_t> all_options_t;
00129         response_t mResponses;
00130         all_options_t mOptions;
00131         
00132         UserAuthcode parseResponse();
00133 
00134         F64 mLastTransferRateBPS;       // bits per second, only valid after a big transfer like inventory
00135 };
00136 
00137 extern LLUserAuth *gUserAuthp;
00138 
00139 #endif /* LLUSERAUTH_H */

Generated on Thu Jul 1 06:09:24 2010 for Second Life Viewer by  doxygen 1.4.7