Added a XmlRpc helper to separate xmlrpc calls from those of the in-app purchase helper
This commit is contained in:
parent
390c34387d
commit
2b8da0c053
5 changed files with 756 additions and 123 deletions
|
@ -139,11 +139,6 @@ public class InAppPurchaseActivity extends Activity implements InAppPurchaseList
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivateAccountSuccessful(boolean success) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(final String error) {
|
||||
Log.e(error);
|
||||
|
|
|
@ -27,6 +27,8 @@ import org.json.JSONException;
|
|||
import org.json.JSONObject;
|
||||
import org.linphone.LinphonePreferences;
|
||||
import org.linphone.mediastream.Log;
|
||||
import org.linphone.xmlrpc.XmlRpcHelper;
|
||||
import org.linphone.xmlrpc.XmlRpcListenerBase;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
|
@ -45,10 +47,8 @@ import android.util.Patterns;
|
|||
|
||||
import com.android.vending.billing.IInAppBillingService;
|
||||
|
||||
import de.timroes.axmlrpc.XMLRPCCallback;
|
||||
import de.timroes.axmlrpc.XMLRPCClient;
|
||||
import de.timroes.axmlrpc.XMLRPCException;
|
||||
import de.timroes.axmlrpc.XMLRPCServerException;
|
||||
|
||||
/**
|
||||
* @author Sylvain Berfini
|
||||
|
@ -332,73 +332,23 @@ public class InAppPurchaseHelper {
|
|||
}
|
||||
|
||||
public void recoverAccount(String sipUsername, String purchasedData, String signature) {
|
||||
XMLRPCClient client = null;
|
||||
try {
|
||||
client = new XMLRPCClient(new URL(LinphonePreferences.instance().getInAppPurchaseValidatingServerUrl()));
|
||||
} catch (MalformedURLException e) {
|
||||
Log.e(e);
|
||||
Log.e("[In-app purchase] Can't reach the server !");
|
||||
mListener.onError(CLIENT_ERROR_SERVER_NOT_REACHABLE);
|
||||
}
|
||||
|
||||
if (client != null) {
|
||||
client.callAsync(new XMLRPCCallback() {
|
||||
@Override
|
||||
public void onServerError(long id, XMLRPCServerException error) {
|
||||
Log.e(error);
|
||||
Log.e("[In-app purchase] Server can't validate the payload and it's signature !");
|
||||
mListener.onError(SERVER_ERROR_SIGNATURE_VERIFICATION_FAILED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(long id, Object result) {
|
||||
Log.d("[In-app purchase] recoverAccount server result is " + result);
|
||||
mListener.onRecoverAccountSuccessful(result.equals("OK"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(long id, XMLRPCException error) {
|
||||
Log.e(error);
|
||||
Log.e("[In-app purchase] Server can't validate the payload and it's signature !");
|
||||
mListener.onError(SERVER_ERROR_SIGNATURE_VERIFICATION_FAILED);
|
||||
}
|
||||
}, "recover_account", mGmailAccount, sipUsername, purchasedData, signature, "google", mGmailAccount);
|
||||
}
|
||||
XmlRpcHelper helper = new XmlRpcHelper();
|
||||
helper.createAccountAsync(new XmlRpcListenerBase() {
|
||||
@Override
|
||||
public void onAccountCreated(String result) {
|
||||
mListener.onRecoverAccountSuccessful(true);
|
||||
}
|
||||
}, mGmailAccount, sipUsername, purchasedData, signature, mGmailAccount, null);
|
||||
}
|
||||
|
||||
public void activateAccount(String sipUsername, String purchasedData, String signature) {
|
||||
XMLRPCClient client = null;
|
||||
try {
|
||||
client = new XMLRPCClient(new URL(LinphonePreferences.instance().getInAppPurchaseValidatingServerUrl()));
|
||||
} catch (MalformedURLException e) {
|
||||
Log.e(e);
|
||||
Log.e("[In-app purchase] Can't reach the server !");
|
||||
mListener.onError(CLIENT_ERROR_SERVER_NOT_REACHABLE);
|
||||
}
|
||||
|
||||
if (client != null) {
|
||||
client.callAsync(new XMLRPCCallback() {
|
||||
@Override
|
||||
public void onServerError(long id, XMLRPCServerException error) {
|
||||
Log.e(error);
|
||||
Log.e("[In-app purchase] Server can't validate the payload and it's signature !");
|
||||
mListener.onError(SERVER_ERROR_SIGNATURE_VERIFICATION_FAILED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(long id, Object result) {
|
||||
Log.d("[In-app purchase] activateAccount server result is " + result);
|
||||
mListener.onActivateAccountSuccessful(result.equals("OK"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(long id, XMLRPCException error) {
|
||||
Log.e(error);
|
||||
Log.e("[In-app purchase] Server can't validate the payload and it's signature !");
|
||||
mListener.onError(SERVER_ERROR_SIGNATURE_VERIFICATION_FAILED);
|
||||
}
|
||||
}, "activate_account", mGmailAccount, sipUsername, purchasedData, signature, "google");
|
||||
}
|
||||
XmlRpcHelper helper = new XmlRpcHelper();
|
||||
helper.activateAccountAsync(new XmlRpcListenerBase() {
|
||||
@Override
|
||||
public void onAccountActivated(String result) {
|
||||
mListener.onActivateAccountSuccessful(true);
|
||||
}
|
||||
}, mGmailAccount, sipUsername, purchasedData, signature);
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
|
@ -434,6 +384,8 @@ public class InAppPurchaseHelper {
|
|||
if (client != null) {
|
||||
try {
|
||||
Object result = client.call("get_expiration_date", mGmailAccount, purchasedData, signature, "google");
|
||||
Log.e(purchasedData);
|
||||
Log.e(signature);
|
||||
long longExpire = -1;
|
||||
String expire = (String)result;
|
||||
|
||||
|
@ -463,61 +415,36 @@ public class InAppPurchaseHelper {
|
|||
}
|
||||
|
||||
private void verifySignatureAndCreateAccountAsync(final VerifiedSignatureListener listener, final String purchasedData, final String signature, String username) {
|
||||
XMLRPCClient client = null;
|
||||
try {
|
||||
client = new XMLRPCClient(new URL(LinphonePreferences.instance().getInAppPurchaseValidatingServerUrl()));
|
||||
} catch (MalformedURLException e) {
|
||||
Log.e(e);
|
||||
Log.e("[In-app purchase] Can't reach the server !");
|
||||
mListener.onError(CLIENT_ERROR_SERVER_NOT_REACHABLE);
|
||||
}
|
||||
|
||||
if (client != null) {
|
||||
client.callAsync(new XMLRPCCallback() {
|
||||
@Override
|
||||
public void onServerError(long id, XMLRPCServerException error) {
|
||||
Log.e(error);
|
||||
Log.e("[In-app purchase] Server can't validate the payload and it's signature !");
|
||||
mListener.onError(SERVER_ERROR_SIGNATURE_VERIFICATION_FAILED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(long id, Object result) {
|
||||
XmlRpcHelper helper = new XmlRpcHelper();
|
||||
helper.createAccountAsync(new XmlRpcListenerBase() {
|
||||
@Override
|
||||
public void onAccountCreated(String result) {
|
||||
try {
|
||||
long longExpire = -1;
|
||||
String expire = (String)result;
|
||||
|
||||
try {
|
||||
long longExpire = -1;
|
||||
String expire = (String)result;
|
||||
|
||||
try {
|
||||
longExpire = Long.parseLong(expire);
|
||||
} catch (NumberFormatException nfe) {
|
||||
Log.e("[In-app purchase] Server failure: " + result);
|
||||
listener.onParsedAndVerifiedSignatureQueryFinished(null);
|
||||
mListener.onError(SERVER_ERROR_UNKNOWN_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
JSONObject json = new JSONObject(purchasedData);
|
||||
String productId = json.getString(PURCHASE_DETAILS_PRODUCT_ID);
|
||||
Purchasable item = new Purchasable(productId);
|
||||
item.setExpire(longExpire);
|
||||
item.setPayloadAndSignature(purchasedData, signature);
|
||||
//TODO parse JSON result to get the purchasable in it
|
||||
listener.onParsedAndVerifiedSignatureQueryFinished(item);
|
||||
return;
|
||||
} catch (JSONException e) {
|
||||
Log.e(e);
|
||||
longExpire = Long.parseLong(expire);
|
||||
} catch (NumberFormatException nfe) {
|
||||
Log.e("[In-app purchase] Server failure: " + result);
|
||||
listener.onParsedAndVerifiedSignatureQueryFinished(null);
|
||||
mListener.onError(SERVER_ERROR_UNKNOWN_ERROR);
|
||||
return;
|
||||
}
|
||||
Log.e("[In-app purchase] Server can't validate the payload and it's signature !");
|
||||
mListener.onError(SERVER_ERROR_SIGNATURE_VERIFICATION_FAILED);
|
||||
|
||||
JSONObject json = new JSONObject(purchasedData);
|
||||
String productId = json.getString(PURCHASE_DETAILS_PRODUCT_ID);
|
||||
Purchasable item = new Purchasable(productId);
|
||||
item.setExpire(longExpire);
|
||||
item.setPayloadAndSignature(purchasedData, signature);
|
||||
//TODO parse JSON result to get the purchasable in it
|
||||
listener.onParsedAndVerifiedSignatureQueryFinished(item);
|
||||
return;
|
||||
} catch (JSONException e) {
|
||||
Log.e(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(long id, XMLRPCException error) {
|
||||
Log.e(error);
|
||||
Log.e("[In-app purchase] Server can't validate the payload and it's signature !");
|
||||
}
|
||||
}, "create_account_from_in_app_purchase", mGmailAccount, username, purchasedData, signature, "google", mGmailAccount);
|
||||
}
|
||||
}
|
||||
}, mGmailAccount, username, purchasedData, signature, mGmailAccount, null);
|
||||
}
|
||||
|
||||
interface VerifiedSignatureListener {
|
||||
|
|
626
src/org/linphone/xmlrpc/XmlRpcHelper.java
Normal file
626
src/org/linphone/xmlrpc/XmlRpcHelper.java
Normal file
|
@ -0,0 +1,626 @@
|
|||
package org.linphone.xmlrpc;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.linphone.LinphonePreferences;
|
||||
import org.linphone.mediastream.Log;
|
||||
|
||||
import de.timroes.axmlrpc.XMLRPCCallback;
|
||||
import de.timroes.axmlrpc.XMLRPCClient;
|
||||
import de.timroes.axmlrpc.XMLRPCException;
|
||||
import de.timroes.axmlrpc.XMLRPCServerException;
|
||||
|
||||
public class XmlRpcHelper {
|
||||
public static final String OS = "GOOGLE";
|
||||
public static final String SERVER_ERROR_INVALID_ACCOUNT = "ERROR_INVALID_ACCOUNT";
|
||||
public static final String SERVER_ERROR_PURCHASE_CANCELLED = "ERROR_PURCHASE_CANCELLED";
|
||||
public static final String SERVER_ERROR_RECEIPT_PARSING_FAILED = "ERROR_RECEIPT_PARSING_FAILED";
|
||||
public static final String SERVER_ERROR_UID_ALREADY_IN_USE = "ERROR_UID_ALREADY_IN_USE";
|
||||
public static final String SERVER_ERROR_SIGNATURE_VERIFICATION_FAILED = "ERROR_SIGNATURE_VERIFICATION_FAILED";
|
||||
public static final String SERVER_ERROR_ACCOUNT_ALREADY_EXISTS = "ERROR_ACCOUNT_ALREADY_EXISTS";
|
||||
public static final String SERVER_ERROR_UNKNOWN_ERROR = "ERROR_UNKNOWN_ERROR";
|
||||
|
||||
public static final String CLIENT_ERROR_INVALID_SERVER_URL = "INVALID_SERVER_URL";
|
||||
public static final String CLIENT_ERROR_SERVER_NOT_REACHABLE = "SERVER_NOT_REACHABLE";
|
||||
|
||||
private XMLRPCClient mXmlRpcClient;
|
||||
|
||||
public XmlRpcHelper() {
|
||||
try {
|
||||
mXmlRpcClient = new XMLRPCClient(new URL(LinphonePreferences.instance().getInAppPurchaseValidatingServerUrl()));
|
||||
} catch (MalformedURLException e) {
|
||||
Log.e(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void createAccountAsync(final XmlRpcListener listener, String gmailAccount, String username, String payload, String signature, String email, String password) {
|
||||
if (mXmlRpcClient != null) {
|
||||
mXmlRpcClient.callAsync(new XMLRPCCallback() {
|
||||
@Override
|
||||
public void onServerError(long id, XMLRPCServerException error) {
|
||||
Log.e(error);
|
||||
listener.onError(error.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(long id, Object object) {
|
||||
String result = (String)object;
|
||||
|
||||
if (result.startsWith("ERROR_")) {
|
||||
Log.e(result);
|
||||
listener.onError(result);
|
||||
return;
|
||||
}
|
||||
|
||||
listener.onAccountCreated(result);
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(long id, XMLRPCException error) {
|
||||
Log.e(error);
|
||||
listener.onError(error.toString());
|
||||
}
|
||||
}, "create_account_from_in_app_purchase", gmailAccount, username, payload, signature, OS, email, password == null ? "" : password);
|
||||
} else {
|
||||
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
|
||||
listener.onError(CLIENT_ERROR_INVALID_SERVER_URL);
|
||||
}
|
||||
}
|
||||
|
||||
public String createAccount(String gmailAccount, String username, String payload, String signature, String email, String password) {
|
||||
if (mXmlRpcClient != null) {
|
||||
try {
|
||||
Object object = mXmlRpcClient.call("create_account_from_in_app_purchase", gmailAccount, username, payload, signature, OS, email, password == null ? "" : password);
|
||||
String result = (String)object;
|
||||
|
||||
if (result.startsWith("ERROR_")) {
|
||||
Log.e(result);
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
|
||||
} catch (XMLRPCException e) {
|
||||
Log.e(e);
|
||||
}
|
||||
} else {
|
||||
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void getAccountExpireAsync(final XmlRpcListener listener, String gmailAccount, String payload, String signature) {
|
||||
if (mXmlRpcClient != null) {
|
||||
mXmlRpcClient.callAsync(new XMLRPCCallback() {
|
||||
@Override
|
||||
public void onServerError(long id, XMLRPCServerException error) {
|
||||
Log.e(error);
|
||||
listener.onError(error.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(long id, Object object) {
|
||||
String result = (String)object;
|
||||
|
||||
if (result.startsWith("ERROR_")) {
|
||||
Log.e(result);
|
||||
listener.onError(result);
|
||||
return;
|
||||
}
|
||||
|
||||
listener.onAccountExpireFetched(result);
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(long id, XMLRPCException error) {
|
||||
Log.e(error);
|
||||
listener.onError(error.toString());
|
||||
}
|
||||
}, "get_expiration_date", gmailAccount, payload, signature, OS);
|
||||
} else {
|
||||
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
|
||||
listener.onError(CLIENT_ERROR_INVALID_SERVER_URL);
|
||||
}
|
||||
}
|
||||
|
||||
public String getAccountExpire(String gmailAccount, String payload, String signature) {
|
||||
if (mXmlRpcClient != null) {
|
||||
try {
|
||||
Object object = mXmlRpcClient.call("get_expiration_date", gmailAccount, payload, signature, OS);
|
||||
String result = (String)object;
|
||||
|
||||
if (result.startsWith("ERROR_")) {
|
||||
Log.e(result);
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
|
||||
} catch (XMLRPCException e) {
|
||||
Log.e(e);
|
||||
}
|
||||
} else {
|
||||
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void getAccountExpireAsync(final XmlRpcListener listener, String username, String password) {
|
||||
if (mXmlRpcClient != null) {
|
||||
mXmlRpcClient.callAsync(new XMLRPCCallback() {
|
||||
@Override
|
||||
public void onServerError(long id, XMLRPCServerException error) {
|
||||
Log.e(error);
|
||||
listener.onError(error.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(long id, Object object) {
|
||||
String result = (String)object;
|
||||
|
||||
if (result.startsWith("ERROR_")) {
|
||||
Log.e(result);
|
||||
listener.onError(result);
|
||||
return;
|
||||
}
|
||||
|
||||
listener.onAccountExpireFetched(result);
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(long id, XMLRPCException error) {
|
||||
Log.e(error);
|
||||
listener.onError(error.toString());
|
||||
}
|
||||
}, "get_expiration_for_account", username, password, OS);
|
||||
} else {
|
||||
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
|
||||
listener.onError(CLIENT_ERROR_INVALID_SERVER_URL);
|
||||
}
|
||||
}
|
||||
|
||||
public String getAccountExpire(String username, String password) {
|
||||
if (mXmlRpcClient != null) {
|
||||
try {
|
||||
Object object = mXmlRpcClient.call("get_expiration_for_account", username, password, OS);
|
||||
String result = (String)object;
|
||||
|
||||
if (result.startsWith("ERROR_")) {
|
||||
Log.e(result);
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
|
||||
} catch (XMLRPCException e) {
|
||||
Log.e(e);
|
||||
}
|
||||
} else {
|
||||
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void activateAccountAsync(final XmlRpcListener listener, String gmailAccount, String username, String payload, String signature) {
|
||||
if (mXmlRpcClient != null) {
|
||||
mXmlRpcClient.callAsync(new XMLRPCCallback() {
|
||||
@Override
|
||||
public void onServerError(long id, XMLRPCServerException error) {
|
||||
Log.e(error);
|
||||
listener.onError(error.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(long id, Object object) {
|
||||
String result = (String)object;
|
||||
|
||||
if (result.startsWith("ERROR_")) {
|
||||
Log.e(result);
|
||||
listener.onError(result);
|
||||
return;
|
||||
}
|
||||
|
||||
listener.onAccountActivated(result);
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(long id, XMLRPCException error) {
|
||||
Log.e(error);
|
||||
listener.onError(error.toString());
|
||||
}
|
||||
}, "activate_account", gmailAccount, username, payload, signature, OS);
|
||||
} else {
|
||||
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
|
||||
listener.onError(CLIENT_ERROR_INVALID_SERVER_URL);
|
||||
}
|
||||
}
|
||||
|
||||
public String activateAccount(String gmailAccount, String username, String payload, String signature) {
|
||||
if (mXmlRpcClient != null) {
|
||||
try {
|
||||
Object object = mXmlRpcClient.call("activate_account", gmailAccount, username, payload, signature, OS);
|
||||
String result = (String)object;
|
||||
|
||||
if (result.startsWith("ERROR_")) {
|
||||
Log.e(result);
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
|
||||
} catch (XMLRPCException e) {
|
||||
Log.e(e);
|
||||
}
|
||||
} else {
|
||||
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void isAccountActivatedAsync(final XmlRpcListener listener, String username) {
|
||||
if (mXmlRpcClient != null) {
|
||||
mXmlRpcClient.callAsync(new XMLRPCCallback() {
|
||||
@Override
|
||||
public void onServerError(long id, XMLRPCServerException error) {
|
||||
Log.e(error);
|
||||
listener.onError(error.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(long id, Object object) {
|
||||
String result = (String)object;
|
||||
if ("OK".equals(result)) {
|
||||
listener.onAccountActivatedFetched(true);
|
||||
} else if (!"ERROR_ACCOUNT_NOT_ACTIVATED".equals(result)) {
|
||||
Log.e(result);
|
||||
}
|
||||
listener.onAccountActivatedFetched(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(long id, XMLRPCException error) {
|
||||
Log.e(error);
|
||||
listener.onError(error.toString());
|
||||
}
|
||||
}, "check_account_activated", username);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAccountActivated(String username) {
|
||||
if (mXmlRpcClient != null) {
|
||||
try {
|
||||
Object object = mXmlRpcClient.call("check_account_activated", username);
|
||||
String result = (String)object;
|
||||
if ("OK".equals(result)) {
|
||||
return true;
|
||||
} else if (!"ERROR_ACCOUNT_NOT_ACTIVATED".equals(result)) {
|
||||
Log.e(result);
|
||||
}
|
||||
} catch (XMLRPCException e) {
|
||||
Log.e(e);
|
||||
}
|
||||
} else {
|
||||
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void isTrialAccountAsync(final XmlRpcListener listener, String username, String password) {
|
||||
if (mXmlRpcClient != null) {
|
||||
mXmlRpcClient.callAsync(new XMLRPCCallback() {
|
||||
@Override
|
||||
public void onServerError(long id, XMLRPCServerException error) {
|
||||
Log.e(error);
|
||||
listener.onError(error.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(long id, Object object) {
|
||||
String result = (String)object;
|
||||
listener.onAccountFetched("OK".equals(result));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(long id, XMLRPCException error) {
|
||||
Log.e(error);
|
||||
listener.onError(error.toString());
|
||||
}
|
||||
}, "is_account_paid", username, password, OS);
|
||||
} else {
|
||||
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
|
||||
listener.onError(CLIENT_ERROR_INVALID_SERVER_URL);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isTrialAccount(String username, String password) {
|
||||
if (mXmlRpcClient != null) {
|
||||
try {
|
||||
Object object = mXmlRpcClient.call("is_account_paid", username, password, OS);
|
||||
String result = (String)object;
|
||||
return "OK".equals(result);
|
||||
} catch (XMLRPCException e) {
|
||||
Log.e(e);
|
||||
}
|
||||
} else {
|
||||
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void isAccountAsync(final XmlRpcListener listener, String username) {
|
||||
if (mXmlRpcClient != null) {
|
||||
mXmlRpcClient.callAsync(new XMLRPCCallback() {
|
||||
@Override
|
||||
public void onServerError(long id, XMLRPCServerException error) {
|
||||
Log.e(error);
|
||||
listener.onError(error.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(long id, Object object) {
|
||||
String result = (String)object;
|
||||
if ("OK".equals(result)) {
|
||||
listener.onAccountFetched(true);
|
||||
} else if (!"ERROR_ACCOUNT_DOESNT_EXIST".equals(result)) {
|
||||
Log.e(result);
|
||||
}
|
||||
listener.onAccountFetched(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(long id, XMLRPCException error) {
|
||||
Log.e(error);
|
||||
listener.onError(error.toString());
|
||||
}
|
||||
}, "check_account_activated", username);
|
||||
} else {
|
||||
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
|
||||
listener.onError(CLIENT_ERROR_INVALID_SERVER_URL);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAccount(String username) {
|
||||
if (mXmlRpcClient != null) {
|
||||
try {
|
||||
Object object = mXmlRpcClient.call("check_account_activated", username);
|
||||
String result = (String)object;
|
||||
if ("OK".equals(result)) {
|
||||
return true;
|
||||
} else if (!"ERROR_ACCOUNT_DOESNT_EXIST".equals(result)) {
|
||||
Log.e(result);
|
||||
}
|
||||
} catch (XMLRPCException e) {
|
||||
Log.e(e);
|
||||
}
|
||||
} else {
|
||||
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void changeAccountEmailAsync(final XmlRpcListener listener, String username, String password, String newEmail) {
|
||||
if (mXmlRpcClient != null) {
|
||||
mXmlRpcClient.callAsync(new XMLRPCCallback() {
|
||||
@Override
|
||||
public void onServerError(long id, XMLRPCServerException error) {
|
||||
Log.e(error);
|
||||
listener.onError(error.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(long id, Object object) {
|
||||
String result = (String)object;
|
||||
|
||||
if (result.startsWith("ERROR_")) {
|
||||
Log.e(result);
|
||||
listener.onError(result);
|
||||
return;
|
||||
}
|
||||
|
||||
listener.onAccountEmailChanged(result);
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(long id, XMLRPCException error) {
|
||||
Log.e(error);
|
||||
listener.onError(error.toString());
|
||||
}
|
||||
}, "change_email", username, password, newEmail, OS);
|
||||
} else {
|
||||
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
|
||||
listener.onError(CLIENT_ERROR_INVALID_SERVER_URL);
|
||||
}
|
||||
}
|
||||
|
||||
public String changeAccountEmail(String username, String password, String newEmail) {
|
||||
if (mXmlRpcClient != null) {
|
||||
try {
|
||||
Object object = mXmlRpcClient.call("change_email", username, password, newEmail, OS);
|
||||
String result = (String)object;
|
||||
|
||||
if (result.startsWith("ERROR_")) {
|
||||
Log.e(result);
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
|
||||
} catch (XMLRPCException e) {
|
||||
Log.e(e);
|
||||
}
|
||||
} else {
|
||||
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void changeAccountPasswordAsync(final XmlRpcListener listener, String username, String oldPassword, String newPassword) {
|
||||
if (mXmlRpcClient != null) {
|
||||
mXmlRpcClient.callAsync(new XMLRPCCallback() {
|
||||
@Override
|
||||
public void onServerError(long id, XMLRPCServerException error) {
|
||||
Log.e(error);
|
||||
listener.onError(error.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(long id, Object object) {
|
||||
String result = (String)object;
|
||||
|
||||
if (result.startsWith("ERROR_")) {
|
||||
Log.e(result);
|
||||
listener.onAccountPasswordChanged(result);
|
||||
return;
|
||||
}
|
||||
|
||||
listener.onAccountPasswordChanged(result);
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(long id, XMLRPCException error) {
|
||||
Log.e(error);
|
||||
listener.onError(error.toString());
|
||||
}
|
||||
}, "change_password", username, oldPassword, newPassword, OS);
|
||||
} else {
|
||||
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
|
||||
listener.onError(CLIENT_ERROR_INVALID_SERVER_URL);
|
||||
}
|
||||
}
|
||||
|
||||
public String changeAccountPassword(String username, String oldPassword, String newPassword) {
|
||||
if (mXmlRpcClient != null) {
|
||||
try {
|
||||
Object object = mXmlRpcClient.call("change_password", username, oldPassword, newPassword, OS);
|
||||
String result = (String)object;
|
||||
|
||||
if (result.startsWith("ERROR_")) {
|
||||
Log.e(result);
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
|
||||
} catch (XMLRPCException e) {
|
||||
Log.e(e);
|
||||
}
|
||||
} else {
|
||||
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void sendRecoverPasswordLinkByEmailAsync(final XmlRpcListener listener, String usernameOrEmail) {
|
||||
if (mXmlRpcClient != null) {
|
||||
mXmlRpcClient.callAsync(new XMLRPCCallback() {
|
||||
@Override
|
||||
public void onServerError(long id, XMLRPCServerException error) {
|
||||
Log.e(error);
|
||||
listener.onError(error.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(long id, Object object) {
|
||||
String result = (String)object;
|
||||
|
||||
if (result.startsWith("ERROR_")) {
|
||||
Log.e(result);
|
||||
listener.onError(result);
|
||||
return;
|
||||
}
|
||||
|
||||
listener.onRecoverPasswordLinkSent(result);
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(long id, XMLRPCException error) {
|
||||
Log.e(error);
|
||||
listener.onError(error.toString());
|
||||
}
|
||||
}, "send_reset_account_password_email", usernameOrEmail);
|
||||
} else {
|
||||
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
|
||||
listener.onError(CLIENT_ERROR_INVALID_SERVER_URL);
|
||||
}
|
||||
}
|
||||
|
||||
public String sendRecoverPasswordLinkByEmail(String usernameOrEmail) {
|
||||
if (mXmlRpcClient != null) {
|
||||
try {
|
||||
Object object = mXmlRpcClient.call("send_reset_account_password_email", usernameOrEmail);
|
||||
String result = (String)object;
|
||||
|
||||
if (result.startsWith("ERROR_")) {
|
||||
Log.e(result);
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
|
||||
} catch (XMLRPCException e) {
|
||||
Log.e(e);
|
||||
}
|
||||
} else {
|
||||
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void sendActivateAccountLinkByEmailAsync(final XmlRpcListener listener, String usernameOrEmail) {
|
||||
if (mXmlRpcClient != null) {
|
||||
mXmlRpcClient.callAsync(new XMLRPCCallback() {
|
||||
@Override
|
||||
public void onServerError(long id, XMLRPCServerException error) {
|
||||
Log.e(error);
|
||||
listener.onError(error.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(long id, Object object) {
|
||||
String result = (String)object;
|
||||
|
||||
if (result.startsWith("ERROR_")) {
|
||||
Log.e(result);
|
||||
listener.onError(result);
|
||||
return;
|
||||
}
|
||||
|
||||
listener.onActivateAccountLinkSent(result);
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(long id, XMLRPCException error) {
|
||||
Log.e(error);
|
||||
listener.onError(error.toString());
|
||||
}
|
||||
}, "resend_activation_email", usernameOrEmail);
|
||||
} else {
|
||||
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
|
||||
listener.onError(CLIENT_ERROR_INVALID_SERVER_URL);
|
||||
}
|
||||
}
|
||||
|
||||
public String sendActivateAccountLinkByEmail(String usernameOrEmail) {
|
||||
if (mXmlRpcClient != null) {
|
||||
try {
|
||||
Object object = mXmlRpcClient.call("resend_activation_email", usernameOrEmail);
|
||||
String result = (String)object;
|
||||
|
||||
if (result.startsWith("ERROR_")) {
|
||||
Log.e(result);
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
|
||||
} catch (XMLRPCException e) {
|
||||
Log.e(e);
|
||||
}
|
||||
} else {
|
||||
Log.e(CLIENT_ERROR_INVALID_SERVER_URL);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
15
src/org/linphone/xmlrpc/XmlRpcListener.java
Normal file
15
src/org/linphone/xmlrpc/XmlRpcListener.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
package org.linphone.xmlrpc;
|
||||
|
||||
public interface XmlRpcListener {
|
||||
public void onError(String error);
|
||||
public void onAccountCreated(String result);
|
||||
public void onAccountExpireFetched(String result);
|
||||
public void onAccountActivated(String result);
|
||||
public void onAccountActivatedFetched(boolean isActivated);
|
||||
public void onTrialAccountFetched(boolean isTrial);
|
||||
public void onAccountFetched(boolean isExisting);
|
||||
public void onAccountEmailChanged(String result);
|
||||
public void onAccountPasswordChanged(String result);
|
||||
public void onRecoverPasswordLinkSent(String result);
|
||||
public void onActivateAccountLinkSent(String result);
|
||||
}
|
70
src/org/linphone/xmlrpc/XmlRpcListenerBase.java
Normal file
70
src/org/linphone/xmlrpc/XmlRpcListenerBase.java
Normal file
|
@ -0,0 +1,70 @@
|
|||
package org.linphone.xmlrpc;
|
||||
|
||||
public class XmlRpcListenerBase implements XmlRpcListener {
|
||||
@Override
|
||||
public void onError(String error) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccountCreated(String result) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccountExpireFetched(String result) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccountActivated(String result) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccountActivatedFetched(boolean isActivated) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTrialAccountFetched(boolean isTrial) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccountFetched(boolean isExisting) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccountEmailChanged(String result) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccountPasswordChanged(String result) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRecoverPasswordLinkSent(String result) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivateAccountLinkSent(String result) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue