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

Generated on Fri May 16 08:34:08 2008 for SecondLife by  doxygen 1.5.5