diff --git a/coreapi/account_creator.c b/coreapi/account_creator.c index 4a13fc551..ead252c1f 100644 --- a/coreapi/account_creator.c +++ b/coreapi/account_creator.c @@ -101,6 +101,14 @@ void linphone_account_creator_cbs_set_activate_phone_number_link(LinphoneAccount cbs->activate_phone_number_link = cb; } +void linphone_account_creator_cbs_set_is_account_linked(LinphoneAccountCreatorCbs *cbs, LinphoneAccountCreatorCbsStatusCb cb) { + cbs->is_account_linked = cb; +} + +LinphoneAccountCreatorCbsStatusCb linphone_account_creator_cbs_get_is_account_linked(const LinphoneAccountCreatorCbs *cbs) { + return cbs->is_account_linked; +} + LinphoneAccountCreatorCbsStatusCb linphone_account_creator_cbs_get_is_account_activated(const LinphoneAccountCreatorCbs *cbs) { return cbs->is_account_activated; } @@ -701,6 +709,36 @@ LinphoneAccountCreatorStatus linphone_account_creator_link_phone_number_with_acc linphone_xml_rpc_request_unref(request); return LinphoneAccountCreatorOK; } + +static void _get_phone_number_for_account_cb(LinphoneXmlRpcRequest *request) { + LinphoneAccountCreator *creator = (LinphoneAccountCreator *)linphone_xml_rpc_request_get_user_data(request); + if (creator->callbacks->is_account_linked != NULL) { + LinphoneAccountCreatorStatus status = LinphoneAccountCreatorReqFailed; + const char* resp = linphone_xml_rpc_request_get_string_response(request); + if (linphone_xml_rpc_request_get_status(request) == LinphoneXmlRpcStatusOk) { + status = (strcmp(resp, "ERROR_USERNAME_PARAMETER_NOT_FOUND") == 0 + || strcmp(resp, "ERROR_ACCOUNT_DOESNT_EXIST") == 0 + || strcmp(resp, "ERROR_ALIAS_DOESNT_EXIST") == 0) ? LinphoneAccountCreatorAccountNotLinked : LinphoneAccountCreatorAccountLinked; + } + creator->callbacks->link_phone_number_with_account(creator, status, resp); + } +} + +LinphoneAccountCreatorStatus linphone_account_creator_is_account_linked(LinphoneAccountCreator *creator) { + LinphoneXmlRpcRequest *request; + if (!creator->username || !creator->domain) { + return LinphoneAccountCreatorReqFailed; + } + request = linphone_xml_rpc_request_new_with_args("get_phone_number_for_account",LinphoneXmlRpcArgString, + LinphoneXmlRpcArgString, creator->username, + LinphoneXmlRpcArgString, creator->domain, + LinphoneXmlRpcArgNone); + linphone_xml_rpc_request_set_user_data(request, creator); + linphone_xml_rpc_request_cbs_set_response(linphone_xml_rpc_request_get_callbacks(request), _get_phone_number_for_account_cb); + linphone_xml_rpc_session_send_request(creator->xmlrpc_session, request); + linphone_xml_rpc_request_unref(request); + return LinphoneAccountCreatorOK; +} /****************** END OF LINK PHONE NUMBER WITH ACCOUNT SECTION *************/ /****************** START OF ACTIVE PHONE NUMBER LINK **************************/ diff --git a/coreapi/account_creator.h b/coreapi/account_creator.h index 09c7523b9..f8400f02d 100644 --- a/coreapi/account_creator.h +++ b/coreapi/account_creator.h @@ -49,6 +49,9 @@ typedef enum _LinphoneAccountCreatorStatus { LinphoneAccountCreatorAccountAlreadyActivated, LinphoneAccountCreatorAccountNotActivated, + LinphoneAccountCreatorAccountLinked, + LinphoneAccountCreatorAccountNotLinked, + LinphoneAccountCreatorEmailInvalid, LinphoneAccountCreatorUsernameInvalid, LinphoneAccountCreatorUsernameTooShort, @@ -312,6 +315,13 @@ LINPHONE_PUBLIC LinphoneAccountCreatorStatus linphone_account_creator_activate_p LINPHONE_PUBLIC LinphoneAccountCreatorStatus linphone_account_creator_recover_phone_account(LinphoneAccountCreator *creator); +/** + * Send an XML-RPC request to ask if an account is linked with a phone number + * @param[in] creator LinphoneAccountCreator object + * @return if this account is linked with a phone number +**/ +LINPHONE_PUBLIC LinphoneAccountCreatorStatus linphone_account_creator_is_account_linked(LinphoneAccountCreator *creator); + /** * Configure an account (create a proxy config and authentication info for it). * @param[in] creator LinphoneAccountCreator object @@ -346,6 +356,20 @@ LINPHONE_PUBLIC void *linphone_account_creator_cbs_get_user_data(const LinphoneA **/ LINPHONE_PUBLIC void linphone_account_creator_cbs_set_user_data(LinphoneAccountCreatorCbs *cbs, void *ud); +/** + * Get the current linked tested callback. + * @param[in] cbs LinphoneAccountCreatorCbs object. + * @return The current linked tested callback. +**/ +LINPHONE_PUBLIC LinphoneAccountCreatorCbsStatusCb linphone_account_creator_cbs_get_is_account_linked(const LinphoneAccountCreatorCbs *cbs); + +/** + * Set the linked tested callback + * @param[in] cbs LinphoneAccountCreatorCbs object. + * @param[in] cb The existence tested callback to be used. +**/ +LINPHONE_PUBLIC void linphone_account_creator_cbs_set_is_account_linked(LinphoneAccountCreatorCbs *cbs, LinphoneAccountCreatorCbsStatusCb cb); + /** * Get the existence tested callback. * @param[in] cbs LinphoneAccountCreatorCbs object. diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index 2490a2421..7026fe9b4 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -8066,6 +8066,32 @@ static void account_creator_activate_phone_number_link(LinphoneAccountCreator *c ms_error("cannot attach VM\n"); return; } + + LinphoneAccountCreatorCbs *cbs = linphone_account_creator_get_callbacks(creator); + jobject listener = (jobject) linphone_account_creator_cbs_get_user_data(cbs); + if (listener == NULL) { + ms_error("account_creator_response() notification without listener"); + return ; + } + + LinphoneCore *lc = (LinphoneCore *)creator->core; + LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); + + jclass clazz = (jclass) env->GetObjectClass(listener); + jmethodID method = env->GetMethodID(clazz, "onAccountCreatorPhoneNumberLinkActivated","(Lorg/linphone/core/LinphoneAccountCreator;Lorg/linphone/core/LinphoneAccountCreator$Status;)V"); + env->DeleteLocalRef(clazz); + + jobject statusObject = env->CallStaticObjectMethod(ljb->accountCreatorStatusClass, ljb->accountCreatorStatusFromIntId, (jint)status); + env->CallVoidMethod(listener, method, getAccountCreator(env, creator), statusObject); +} + +static void account_creator_is_account_linked(LinphoneAccountCreator *creator, LinphoneAccountCreatorStatus status, const char *resp) { + JNIEnv *env = 0; + jint result = jvm->AttachCurrentThread(&env,NULL); + if (result != 0) { + ms_error("cannot attach VM\n"); + return; + } LinphoneAccountCreatorCbs *cbs = linphone_account_creator_get_callbacks(creator); jobject listener = (jobject) linphone_account_creator_cbs_get_user_data(cbs); @@ -8078,7 +8104,7 @@ static void account_creator_activate_phone_number_link(LinphoneAccountCreator *c LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc); jclass clazz = (jclass) env->GetObjectClass(listener); - jmethodID method = env->GetMethodID(clazz, "onAccountCreatorPhoneNumberLinkActivated","(Lorg/linphone/core/LinphoneAccountCreator;Lorg/linphone/core/LinphoneAccountCreator$Status;)V"); + jmethodID method = env->GetMethodID(clazz, "onAccountCreatorIsAccountLinked","(Lorg/linphone/core/LinphoneAccountCreator;Lorg/linphone/core/LinphoneAccountCreator$Status;)V"); env->DeleteLocalRef(clazz); jobject statusObject = env->CallStaticObjectMethod(ljb->accountCreatorStatusClass, ljb->accountCreatorStatusFromIntId, (jint)status); @@ -8315,6 +8341,11 @@ extern "C" jint Java_org_linphone_core_LinphoneAccountCreatorImpl_activateAccoun return (jint) linphone_account_creator_activate_account(account_creator); } +extern "C" jint Java_org_linphone_core_LinphoneAccountCreatorImpl_isAccountLinked(JNIEnv *env, jobject thiz, jlong ptr) { + LinphoneAccountCreator *account_creator = (LinphoneAccountCreator *)ptr; + return (jint) linphone_account_creator_is_account_linked(account_creator); +} + extern "C" jint Java_org_linphone_core_LinphoneAccountCreatorImpl_isAccountActivated(JNIEnv *env, jobject thiz, jlong ptr) { LinphoneAccountCreator *account_creator = (LinphoneAccountCreator *)ptr; return (jint) linphone_account_creator_is_account_activated(account_creator); diff --git a/coreapi/private.h b/coreapi/private.h index 641bca192..66194714a 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -1335,6 +1335,7 @@ struct _LinphoneAccountCreatorCbs { LinphoneAccountCreatorCbsStatusCb link_phone_number_with_account; LinphoneAccountCreatorCbsStatusCb activate_phone_number_link; LinphoneAccountCreatorCbsStatusCb recover_phone_account; + LinphoneAccountCreatorCbsStatusCb is_account_linked; }; BELLE_SIP_DECLARE_VPTR(LinphoneAccountCreatorCbs); diff --git a/java/common/org/linphone/core/LinphoneAccountCreator.java b/java/common/org/linphone/core/LinphoneAccountCreator.java index 6eeab11fa..298a4acb9 100644 --- a/java/common/org/linphone/core/LinphoneAccountCreator.java +++ b/java/common/org/linphone/core/LinphoneAccountCreator.java @@ -30,6 +30,7 @@ public interface LinphoneAccountCreator { void onAccountCreatorPhoneNumberLinkActivated(LinphoneAccountCreator accountCreator, Status status); void onAccountCreatorIsAccountActivated(LinphoneAccountCreator accountCreator, Status status); void onAccountCreatorPhoneAccountRecovered(LinphoneAccountCreator accountCreator, Status status); + void onAccountCreatorIsAccountLinked(LinphoneAccountCreator accountCreator, Status status); } public static class Status { @@ -48,21 +49,23 @@ public interface LinphoneAccountCreator { public final static Status AccountActivated = new Status(7, "AccountActivated"); public final static Status AccountAlreadyActivated = new Status(8, "AccountAlreadyActivated"); public final static Status AccountNotActivated = new Status(9, "AccountNotActivated"); - public final static Status EmailInvalid = new Status(10, "EmailInvalid"); - public final static Status UsernameInvalid = new Status(11, "UsernameInvalid"); - public final static Status UsernameTooShort = new Status(12, "UsernameTooShort"); - public final static Status UsernameTooLong = new Status(13, "UsernameTooLong"); - public final static Status UsernameInvalidSize = new Status(14, "UsernameInvalidSize"); - public final static Status PhoneNumberInvalid = new Status(15, "PhoneNumberInvalid"); - public final static Status PhoneNumberTooShort = new Status(16, "PhoneNumberTooShort"); - public final static Status PhoneNumberTooLong = new Status(17, "PhoneNumberTooLong"); - public final static Status PasswordTooShort = new Status(18, "PasswordTooShort"); - public final static Status PasswordTooLong = new Status(19, "PasswordTooLong"); - public final static Status DomainInvalid = new Status(20, "DomainInvalid"); - public final static Status RouteInvalid = new Status(21, "RouteInvalid"); - public final static Status DisplayNameInvalid = new Status(22, "DisplayNameInvalid"); - public final static Status TransportNotSupported = new Status(23, "TransportNotSupported"); - public final static Status CountryCodeInvalid = new Status(24, "CountryCodeInvalid"); + public final static Status AccountLinked = new Status(10, "AccountLinked"); + public final static Status AccountNotLinked = new Status(11, "AccountNotLinked"); + public final static Status EmailInvalid = new Status(12, "EmailInvalid"); + public final static Status UsernameInvalid = new Status(13, "UsernameInvalid"); + public final static Status UsernameTooShort = new Status(14, "UsernameTooShort"); + public final static Status UsernameTooLong = new Status(15, "UsernameTooLong"); + public final static Status UsernameInvalidSize = new Status(16, "UsernameInvalidSize"); + public final static Status PhoneNumberInvalid = new Status(17, "PhoneNumberInvalid"); + public final static Status PhoneNumberTooShort = new Status(18, "PhoneNumberTooShort"); + public final static Status PhoneNumberTooLong = new Status(19, "PhoneNumberTooLong"); + public final static Status PasswordTooShort = new Status(20, "PasswordTooShort"); + public final static Status PasswordTooLong = new Status(21, "PasswordTooLong"); + public final static Status DomainInvalid = new Status(22, "DomainInvalid"); + public final static Status RouteInvalid = new Status(23, "RouteInvalid"); + public final static Status DisplayNameInvalid = new Status(24, "DisplayNameInvalid"); + public final static Status TransportNotSupported = new Status(25, "TransportNotSupported"); + public final static Status CountryCodeInvalid = new Status(26, "CountryCodeInvalid"); private Status(int value, String stringValue) { mValue = value; @@ -138,7 +141,9 @@ public interface LinphoneAccountCreator { Status linkPhoneNumberWithAccount(); Status activatePhoneNumberLink(); - + + Status isAccountLinked(); + Status recoverPhoneAccount(); LinphoneProxyConfig configure(); diff --git a/java/impl/org/linphone/core/LinphoneAccountCreatorImpl.java b/java/impl/org/linphone/core/LinphoneAccountCreatorImpl.java index aa6a0199b..d47cedc7e 100644 --- a/java/impl/org/linphone/core/LinphoneAccountCreatorImpl.java +++ b/java/impl/org/linphone/core/LinphoneAccountCreatorImpl.java @@ -177,6 +177,12 @@ public class LinphoneAccountCreatorImpl implements LinphoneAccountCreator { public Status activateAccount() { return Status.fromInt(activateAccount(nativePtr)); } + + private native int isAccountLinked(long ptr); + @Override + public Status isAccountLinked() { + return Status.fromInt(isAccountLinked(nativePtr)); + } private native int isAccountActivated(long ptr); @Override