00001 /* 00002 * Funambol is a mobile platform developed by Funambol, Inc. 00003 * Copyright (C) 2010 Funambol, Inc. 00004 * 00005 * This program is free software; you can redistribute it and/or modify it under 00006 * the terms of the GNU Affero General Public License version 3 as published by 00007 * the Free Software Foundation with the addition of the following permission 00008 * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED 00009 * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE 00010 * WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. 00011 * 00012 * This program is distributed in the hope that it will be useful, but WITHOUT 00013 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00014 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 00015 * details. 00016 * 00017 * You should have received a copy of the GNU Affero General Public License 00018 * along with this program; if not, see http://www.gnu.org/licenses or write to 00019 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00020 * MA 02110-1301 USA. 00021 * 00022 * You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite 00023 * 305, Redwood City, CA 94063, USA, or at email address info@funambol.com. 00024 * 00025 * The interactive user interfaces in modified source and object code versions 00026 * of this program must display Appropriate Legal Notices, as required under 00027 * Section 5 of the GNU Affero General Public License version 3. 00028 * 00029 * In accordance with Section 7(b) of the GNU Affero General Public License 00030 * version 3, these Appropriate Legal Notices must retain the display of the 00031 * "Powered by Funambol" logo. If the display of the logo is not reasonably 00032 * feasible for technical reasons, the Appropriate Legal Notices must display 00033 * the words "Powered by Funambol". 00034 */ 00035 00036 #ifndef __MSU_MANAGER_H__ 00037 #define __MSU_MANAGER_H__ 00038 00039 #include "http/httpConnection.h" 00040 #include "msu/MSUDeviceInfo.h" 00041 #include "msu/JsonMSUMessage.h" 00042 00043 BEGIN_FUNAMBOL_NAMESPACE 00044 00045 typedef enum EMSUStatusCode 00046 { 00047 EMSUSuccess = 0, // OK 00048 EMSUConnectionSetupError, // Error setting up the connection 00049 EMSUInvalidCredentials, // Login authentication failed 00050 EMSUGenericHttpError, // Http error 00051 EMSUSapiInvalidResponse, // Bad SAPI response received 00052 EMSUSapiMessageParseError, // Error occurred parsing the JSON body received 00053 EMSUSapiMessageFormatError, // Error occurred formatting the JSON body to send 00054 EMSUInvalidCaptchaToken, // Signup failed because token provided is wrong 00055 EMSUInvalidUserId, // Signup failed because username provided is invalid 00056 EMSUInvalidPassword, // Signup failed because password provided is invalid 00057 EMSUInvalidParam, // An invalid parameter is passed 00058 EMSUWrongPassword, // User already exists (PRO-1113) 00059 EMSUNetworkError, // Network error (timeouts, etc..) 00060 EMSUGenericError 00061 }; 00062 00063 class MSUManager 00064 { 00065 private: 00066 StringBuffer serverUrl; 00067 const char* userAgent; 00068 00073 StringBuffer sessionId; 00074 00075 JsonMSUMessage* jsonMessage; 00076 HttpConnection* httpConnection; 00077 00078 static const char* sapiLoginUrlFmt; 00079 static const char* sapiGetCaptchaUrlFmt; 00080 static const char* sapiSignUpUrlFmt; 00081 00082 public: 00083 MSUManager(const char* url, const char* user_agent); 00084 ~MSUManager(); 00085 00086 EMSUStatusCode login(const char* username, const char* password); 00087 EMSUStatusCode getCaptchaUrl(char** captchaUrl); 00088 EMSUStatusCode getCaptcha(const char* captchaRequestUrl, unsigned char** captchaImage, int *captchaImageSize); 00089 00101 EMSUStatusCode signup(const char* username, const char* password, const char *token, MSUDeviceInfo* deviceInfo); 00102 00103 const char* getJsonErrorDescription() const { return jsonMessage->getErrorMessage().c_str(); } 00104 const char* getJsonErrorCode() const { return jsonMessage->getErrorCode().c_str(); } 00105 }; 00106 00107 END_FUNAMBOL_NAMESPACE 00108 00109 #endif // __MSU_MANAGER_H__