proxy.c: deprecate linphone_proxy_config_normalize_phone and use...

proxy.c: deprecate linphone_proxy_config_normalize_phone and use linphone_proxy_config_normalize_phone_number instead
parent 4619c551
......@@ -402,11 +402,15 @@ LINPHONE_PUBLIC bool_t linphone_proxy_config_is_phone_number(LinphoneProxyConfig
* @param result the newly normalized number
* @param result_len the size of the normalized number \a result
* @return TRUE if a phone number was recognized, FALSE otherwise.
* @deprecated use linphone_proxy_config_normalize_phone_number()
*/
LINPHONE_PUBLIC bool_t linphone_proxy_config_normalize_number(LinphoneProxyConfig *proxy, const char *username, char *result, size_t result_len);
/**
* Same objective as linphone_proxy_config_normalize_number but allocates a new string
* Normalize a human readable phone number into a basic string. 888-444-222 becomes 888444222
* or +33888444222 depending on the #LinphoneProxyConfig object. However this argument is OPTIONNAL
* and if not provided, a default one will be used.
* This function will always generate a normalized username; if input is not a phone number, output will be a copy of input.
* @param proxy #LinphoneProxyConfig object containing country code and/or escape symbol. If NULL passed, will use default configuration.
* @param username the string to parse
* @return NULL if invalid phone number, normalized phone number from username input otherwise.
......
......@@ -151,7 +151,7 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *ajvm, void *reserved)
{
#ifdef ANDROID
ms_set_jvm(ajvm);
#endif /*ANDROID*/
jvm=ajvm;
return JNI_VERSION_1_2;
......@@ -1996,7 +1996,7 @@ extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_needsEchoCalibration
if(sound_description != NULL && sound_description == &genericSoundDeviceDescriptor){
return TRUE;
}
if (ms_snd_card_get_capabilities(sndcard) & MS_SND_CARD_CAP_BUILTIN_ECHO_CANCELLER) return FALSE;
if (ms_snd_card_get_minimal_latency(sndcard) != 0) return FALSE;
return TRUE;
......@@ -2182,16 +2182,17 @@ extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_normalizePhone
if (jnumber == 0) {
ms_error("cannot normalized null number");
}
char * normalized_phone;
const char* number = env->GetStringUTFChars(jnumber, NULL);
int len = env->GetStringLength(jnumber);
if (len == 0) {
ms_warning("cannot normalize empty number");
return jnumber;
}
char targetBuff[2*len];// returned number can be greater than origin (specially in case of prefix insertion
linphone_proxy_config_normalize_number((LinphoneProxyConfig*)proxyCfg,number,targetBuff,sizeof(targetBuff));
jstring normalizedNumber = env->NewStringUTF(targetBuff);
normalized_phone = linphone_proxy_config_normalize_phone_number((LinphoneProxyConfig*)proxyCfg,number);
jstring normalizedNumber = env->NewStringUTF(normalized_phone ? normalized_phone : number);
env->ReleaseStringUTFChars(jnumber, number);
ms_free(normalized_phone);
return normalizedNumber;
}
extern "C" jint Java_org_linphone_core_LinphoneProxyConfigImpl_lookupCCCFromIso(JNIEnv* env, jobject thiz, jlong proxyCfg, jstring jiso) {
......@@ -3283,7 +3284,7 @@ static void message_state_changed(LinphoneChatMessage* msg, LinphoneChatMessageS
jmethodID method = env->GetMethodID(clazz, "onLinphoneChatMessageStateChanged","(Lorg/linphone/core/LinphoneChatMessage;Lorg/linphone/core/LinphoneChatMessage$State;)V");
jobject jmessage = getChatMessage(env, msg);
env->DeleteLocalRef(clazz);
jclass chatMessageStateClass = (jclass)env->FindClass("org/linphone/core/LinphoneChatMessage$State");
jmethodID chatMessageStateFromIntId = env->GetStaticMethodID(chatMessageStateClass, "fromInt","(I)Lorg/linphone/core/LinphoneChatMessage$State;");
env->CallVoidMethod(listener, method, jmessage, env->CallStaticObjectMethod(chatMessageStateClass, chatMessageStateFromIntId, (jint)state));
......@@ -3326,7 +3327,7 @@ static void file_transfer_recv(LinphoneChatMessage *msg, const LinphoneContent*
jclass clazz = (jclass) env->GetObjectClass(listener);
jmethodID method = env->GetMethodID(clazz, "onLinphoneChatMessageFileTransferReceived", "(Lorg/linphone/core/LinphoneChatMessage;Lorg/linphone/core/LinphoneContent;Lorg/linphone/core/LinphoneBuffer;)V");
env->DeleteLocalRef(clazz);
jobject jmessage = getChatMessage(env, msg);
jobject jbuffer = buffer ? create_java_linphone_buffer(env, buffer) : NULL;
jobject jcontent = content ? create_java_linphone_content(env, content) : NULL;
......@@ -3352,7 +3353,7 @@ static LinphoneBuffer* file_transfer_send(LinphoneChatMessage *msg, const Linph
jclass clazz = (jclass) env->GetObjectClass(listener);
jmethodID method = env->GetMethodID(clazz, "onLinphoneChatMessageFileTransferSent","(Lorg/linphone/core/LinphoneChatMessage;Lorg/linphone/core/LinphoneContent;IILorg/linphone/core/LinphoneBuffer;)V");
env->DeleteLocalRef(clazz);
jobject jmessage = getChatMessage(env, msg);
jobject jbuffer = create_java_linphone_buffer(env, NULL);
jobject jcontent = content ? create_java_linphone_content(env, content) : NULL;
......@@ -3360,7 +3361,7 @@ static LinphoneBuffer* file_transfer_send(LinphoneChatMessage *msg, const Linph
if (jcontent) {
env->DeleteLocalRef(jcontent);
}
buffer = create_c_linphone_buffer_from_java_linphone_buffer(env, jbuffer);
env->DeleteLocalRef(jbuffer);
return buffer;
......@@ -3370,7 +3371,7 @@ extern "C" void Java_org_linphone_core_LinphoneChatMessageImpl_setListener(JNIEn
jobject listener = env->NewGlobalRef(jlistener);
LinphoneChatMessage *message = (LinphoneChatMessage *)ptr;
LinphoneChatMessageCbs *cbs;
message->cb_ud = listener;
cbs = linphone_chat_message_get_callbacks(message);
linphone_chat_message_cbs_set_msg_state_changed(cbs, message_state_changed);
......@@ -4649,7 +4650,7 @@ static jobject create_java_linphone_content(JNIEnv *env, const LinphoneContent *
}
jobject jobj = env->NewObject(contentClass, ctor, jname, jtype, jsubtype, jdata, jencoding, jsize);
env->DeleteLocalRef(contentClass);
env->DeleteLocalRef(jtype);
env->DeleteLocalRef(jsubtype);
......@@ -4659,7 +4660,7 @@ static jobject create_java_linphone_content(JNIEnv *env, const LinphoneContent *
if (jname) {
env->DeleteLocalRef(jname);
}
return jobj;
}
......@@ -4695,7 +4696,7 @@ static LinphoneBuffer* create_c_linphone_buffer_from_java_linphone_buffer(JNIEnv
bufferClass = (jclass)env->FindClass("org/linphone/core/LinphoneBufferImpl");
getSizeMethod = env->GetMethodID(bufferClass, "getSize", "()I");
getDataMethod = env->GetMethodID(bufferClass, "getContent", "()[B");
jsize = env->CallIntMethod(jbuffer, getSizeMethod);
jdata = env->CallObjectMethod(jbuffer, getDataMethod);
jcontent = reinterpret_cast<jbyteArray>(jdata);
......@@ -4705,7 +4706,7 @@ static LinphoneBuffer* create_c_linphone_buffer_from_java_linphone_buffer(JNIEnv
env->ReleaseByteArrayElements(jcontent, (jbyte*)content, JNI_ABORT);
}
env->DeleteLocalRef(bufferClass);
return buffer;
}
......
......@@ -881,68 +881,12 @@ static char* replace_icp_with_plus_new(char *phone, const char *icp){
}
bool_t linphone_proxy_config_normalize_number(LinphoneProxyConfig *proxy, const char *username, char *result, size_t result_len){
bool_t ret;
LinphoneProxyConfig *tmpproxy = proxy ? proxy : linphone_proxy_config_new();
char * normalized_phone = linphone_proxy_config_normalize_phone_number(proxy, username);
const char * output = normalized_phone ? normalized_phone : username;
memset(result, 0, result_len);
if (linphone_proxy_config_is_phone_number(tmpproxy, username)){
dial_plan_t dialplan = {0};
char *flatten=flatten_number(username);
ms_debug("Flattened number is '%s'",flatten);
/*username does not contain a dial prefix nor the tmpproxy, nothing else to do*/
if (tmpproxy->dial_prefix==NULL || tmpproxy->dial_prefix[0]=='\0'){
strncpy(result,flatten,result_len-1);
} else {
lookup_dial_plan_by_ccc(tmpproxy->dial_prefix,&dialplan);
ms_debug("Using dial plan '%s'",dialplan.country);
/* the number has international prefix or +, so nothing to do*/
if (flatten[0]=='+'){
ms_debug("Prefix already present.");
/*eventually replace the plus by the international calling prefix of the country*/
if (tmpproxy->dial_escape_plus) {
replace_plus_with_icp(flatten,result,result_len,dialplan.icp);
}else{
strncpy(result, flatten, result_len-1);
}
}else if (strstr(flatten,dialplan.icp)==flatten){
if (tmpproxy->dial_escape_plus){
strncpy(result, flatten, result_len-1);
}else{
replace_icp_with_plus(flatten, result, result_len, dialplan.icp);
}
}else{
int numlen;
int i=0;
int skip;
numlen=strlen(flatten);
/*keep at most national number significant digits */
skip=numlen-dialplan.nnl;
if (skip<0) skip=0;
/*first prepend international calling prefix or +*/
if (tmpproxy->dial_escape_plus){
strncpy(result,dialplan.icp,result_len);
i+=strlen(dialplan.icp);
}else{
strncpy(result,"+",result_len);
i+=1;
}
/*add prefix*/
if (result_len-i>strlen(dialplan.ccc)){
strcpy(result+i,dialplan.ccc);
i+=strlen(dialplan.ccc);
}
/*add user digits */
strncpy(result+i,flatten+skip,result_len-i-1);
}
}
ms_free(flatten);
ret = TRUE;
} else {
strncpy(result,username,result_len-1);
ret = FALSE;
}
if (proxy==NULL) ms_free(tmpproxy);
return ret;
memcpy(result, output, MIN(strlen(output) + 1, result_len));
ms_free(normalized_phone);
return output != username;
}
char* linphone_proxy_config_normalize_phone_number(LinphoneProxyConfig *proxy, const char *username) {
......@@ -1042,11 +986,10 @@ LinphoneAddress* linphone_proxy_config_normalize_sip_uri(LinphoneProxyConfig *pr
if (uri==NULL){
return NULL;
} else {
char normalized_username[128];
char* normalized_phone = linphone_proxy_config_normalize_phone_number(proxy,username);
linphone_address_set_display_name(uri,NULL);
linphone_proxy_config_normalize_number(proxy,username,normalized_username,
sizeof(normalized_username));
linphone_address_set_username(uri,normalized_username);
linphone_address_set_username(uri,normalized_phone ? normalized_phone : username);
ms_free(normalized_phone);
return _linphone_core_destroy_addr_if_not_sip(uri);
}
} else {
......
......@@ -24,7 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
int main(int argc , char *argv[]){
LinphoneProxyConfig *cfg;
char normalized_number[32];
char *normalized_number;
if (argc<2){
fprintf(stderr,"Usage:\n%s <phone number> [<country code>] [--escape-plus]\nReturns normalized number.", argv[0]);
return -1;
......@@ -35,14 +35,18 @@ int main(int argc , char *argv[]){
linphone_proxy_config_set_dial_prefix(cfg,argv[2]);
if (argc>3 && strcmp(argv[3],"--escape-plus")==0)
linphone_proxy_config_set_dial_escape_plus(cfg,TRUE);
linphone_proxy_config_normalize_number(cfg,argv[1],normalized_number,sizeof(normalized_number));
normalized_number = linphone_proxy_config_normalize_phone_number(cfg,argv[1]);
printf("Normalized number is %s\n",normalized_number);
/*check extracted ccc*/
if (linphone_dial_plan_lookup_ccc_from_e164(normalized_number) != atoi(linphone_proxy_config_get_dial_prefix(cfg))) {
printf("Error ccc [%i] not correctly parsed\n",linphone_dial_plan_lookup_ccc_from_e164(normalized_number));
if (!normalized_number) {
printf("Invalid phone number: %s\n", normalized_number)
} else {
printf("Extracted ccc is [%i] \n",linphone_dial_plan_lookup_ccc_from_e164(normalized_number));
printf("Normalized number is %s\n",normalized_number);
/*check extracted ccc*/
if (linphone_dial_plan_lookup_ccc_from_e164(normalized_number) != atoi(linphone_proxy_config_get_dial_prefix(cfg))) {
printf("Error ccc [%i] not correctly parsed\n",linphone_dial_plan_lookup_ccc_from_e164(normalized_number));
} else {
printf("Extracted ccc is [%i] \n",linphone_dial_plan_lookup_ccc_from_e164(normalized_number));
}
}
return 0;
}
......@@ -18,10 +18,18 @@
#include "liblinphone_tester.h"
#include <stdlib.h>
const char* phone_normalization(LinphoneProxyConfig *proxy, const char* in) {
static char result[255];
linphone_proxy_config_normalize_number(proxy, in, result, 255-1);
return result;
char * output = linphone_proxy_config_normalize_phone_number(proxy, in);
if (output) {
memcpy(result, output, strlen(output)+1);
ms_free(output);
return result;
} else {
return NULL;
}
}
static void phone_normalization_without_proxy() {
......@@ -32,7 +40,7 @@ static void phone_normalization_without_proxy() {
BC_ASSERT_STRING_EQUAL(phone_normalization(NULL, "+33012345678"), "+33012345678");
BC_ASSERT_STRING_EQUAL(phone_normalization(NULL, "+3301234567891"), "+3301234567891");
BC_ASSERT_STRING_EQUAL(phone_normalization(NULL, "+33 01234567891"), "+3301234567891");
BC_ASSERT_STRING_EQUAL(phone_normalization(NULL, "I_AM_NOT_A_NUMBER"), "I_AM_NOT_A_NUMBER"); // invalid phone number
BC_ASSERT_PTR_NULL(phone_normalization(NULL, "I_AM_NOT_A_NUMBER")); // invalid phone number
}
static void phone_normalization_with_proxy() {
......@@ -50,7 +58,7 @@ static void phone_normalization_with_proxy() {
BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "0012345678"), "+12345678");
BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "01 2345678"), "+33012345678");
BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "01234567891"), "+33234567891"); // invalid phone number (too long)
BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "I_AM_NOT_A_NUMBER"), "I_AM_NOT_A_NUMBER"); // invalid phone number
BC_ASSERT_PTR_NULL(phone_normalization(proxy, "I_AM_NOT_A_NUMBER")); // invalid phone number
BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "+990012345678"), "+990012345678");
......@@ -60,7 +68,7 @@ static void phone_normalization_with_proxy() {
BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "+31952636505"), "+31952636505");
BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "0033952636505"), "+33952636505");
BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "0033952636505"), "+33952636505");
BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "toto"), "toto");
BC_ASSERT_PTR_NULL(phone_normalization(proxy, "toto"));
linphone_proxy_config_set_dial_prefix(proxy, "99");
BC_ASSERT_STRING_EQUAL(phone_normalization(proxy, "0012345678"), "+12345678");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment