]> sjero.net Git - linphone/blob - coreapi/linphonecore_jni.cc
rename LinphoneTunnelManager LinphoneTunnel
[linphone] / coreapi / linphonecore_jni.cc
1 /*
2 linphonecore_jni.cc
3 Copyright (C) 2010  Belledonne Communications, Grenoble, France
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18  */
19 #include <jni.h>
20 #include "linphonecore_utils.h"
21 #include <ortp/zrtp.h>
22
23 #ifdef TUNNEL_ENABLED
24 #include "linphone_tunnel_manager.h"
25 #endif
26
27 extern "C" {
28 #include "mediastreamer2/mediastream.h"
29 }
30 #include "mediastreamer2/msjava.h"
31 #include "private.h"
32 #include <cpu-features.h>
33
34 #ifdef ANDROID
35 #include <android/log.h>
36 extern "C" void libmsilbc_init();
37 #ifdef HAVE_X264
38 extern "C" void libmsx264_init();
39 #endif
40 #ifdef HAVE_AMR
41 extern "C" void libmsamr_init();
42 #endif
43 #ifdef HAVE_SILK
44 extern "C" void libmssilk_init();
45 #endif
46 #endif /*ANDROID*/
47
48 static JavaVM *jvm=0;
49
50 #ifdef ANDROID
51 static void linphone_android_log_handler(OrtpLogLevel lev, const char *fmt, va_list args){
52         int prio;
53         switch(lev){
54         case ORTP_DEBUG:        prio = ANDROID_LOG_DEBUG;       break;
55         case ORTP_MESSAGE:      prio = ANDROID_LOG_INFO;        break;
56         case ORTP_WARNING:      prio = ANDROID_LOG_WARN;        break;
57         case ORTP_ERROR:        prio = ANDROID_LOG_ERROR;       break;
58         case ORTP_FATAL:        prio = ANDROID_LOG_FATAL;       break;
59         default:                prio = ANDROID_LOG_DEFAULT;     break;
60         }
61         __android_log_vprint(prio, LOG_DOMAIN, fmt, args);
62 }
63
64 int dumbMethodForAllowingUsageOfCpuFeaturesFromStaticLibMediastream() {
65         return (android_getCpuFamily() == ANDROID_CPU_FAMILY_ARM && (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0);
66 }
67 #endif /*ANDROID*/
68
69 JNIEXPORT jint JNICALL  JNI_OnLoad(JavaVM *ajvm, void *reserved)
70 {
71 #ifdef ANDROID
72         ms_set_jvm(ajvm);
73 #endif /*ANDROID*/
74         jvm=ajvm;
75         return JNI_VERSION_1_2;
76 }
77
78
79 //LinphoneFactory
80 extern "C" void Java_org_linphone_core_LinphoneCoreFactoryImpl_setDebugMode(JNIEnv*  env
81                 ,jobject  thiz
82                 ,jboolean isDebug) {
83         if (isDebug) {
84                 linphone_core_enable_logs_with_cb(linphone_android_log_handler);
85         } else {
86                 linphone_core_disable_logs();
87         }
88 }
89 // LinphoneCore
90
91 class LinphoneCoreData {
92 public:
93         LinphoneCoreData(JNIEnv*  env, jobject lc,jobject alistener, jobject auserdata) {
94
95                 core = env->NewGlobalRef(lc);
96                 listener = env->NewGlobalRef(alistener);
97                 userdata = auserdata?env->NewGlobalRef(auserdata):0;
98                 memset(&vTable,0,sizeof(vTable));
99                 vTable.show = showInterfaceCb;
100                 vTable.auth_info_requested = authInfoRequested;
101                 vTable.display_status = displayStatusCb;
102                 vTable.display_message = displayMessageCb;
103                 vTable.display_warning = displayMessageCb;
104                 vTable.global_state_changed = globalStateChange;
105                 vTable.registration_state_changed = registrationStateChange;
106                 vTable.call_state_changed = callStateChange;
107                 vTable.call_encryption_changed = callEncryptionChange;
108                 vTable.text_received = text_received;
109                 vTable.new_subscription_request = new_subscription_request;
110                 vTable.notify_presence_recv = notify_presence_recv;
111
112                 listenerClass = (jclass)env->NewGlobalRef(env->GetObjectClass( alistener));
113
114                 /*displayStatus(LinphoneCore lc,String message);*/
115                 displayStatusId = env->GetMethodID(listenerClass,"displayStatus","(Lorg/linphone/core/LinphoneCore;Ljava/lang/String;)V");
116
117                 /*void generalState(LinphoneCore lc,int state); */
118                 globalStateId = env->GetMethodID(listenerClass,"globalState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCore$GlobalState;Ljava/lang/String;)V");
119                 globalStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$GlobalState"));
120                 globalStateFromIntId = env->GetStaticMethodID(globalStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$GlobalState;");
121
122                 /*registrationState(LinphoneCore lc, LinphoneProxyConfig cfg, LinphoneCore.RegistrationState cstate, String smessage);*/
123                 registrationStateId = env->GetMethodID(listenerClass,"registrationState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneProxyConfig;Lorg/linphone/core/LinphoneCore$RegistrationState;Ljava/lang/String;)V");
124                 registrationStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$RegistrationState"));
125                 registrationStateFromIntId = env->GetStaticMethodID(registrationStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$RegistrationState;");
126
127                 /*callState(LinphoneCore lc, LinphoneCall call, LinphoneCall.State cstate,String message);*/
128                 callStateId = env->GetMethodID(listenerClass,"callState","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;Lorg/linphone/core/LinphoneCall$State;Ljava/lang/String;)V");
129                 callStateClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCall$State"));
130                 callStateFromIntId = env->GetStaticMethodID(callStateClass,"fromInt","(I)Lorg/linphone/core/LinphoneCall$State;");
131
132                 /*callEncryption(LinphoneCore lc, LinphoneCall call, boolean encrypted,String auth_token);*/
133                 callEncryptionChangedId=env->GetMethodID(listenerClass,"callEncryptionChanged","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCall;ZLjava/lang/String;)V");
134
135                 /*void ecCalibrationStatus(LinphoneCore.EcCalibratorStatus status, int delay_ms, Object data);*/
136                 ecCalibrationStatusId = env->GetMethodID(listenerClass,"ecCalibrationStatus","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneCore$EcCalibratorStatus;ILjava/lang/Object;)V");
137                 ecCalibratorStatusClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCore$EcCalibratorStatus"));
138                 ecCalibratorStatusFromIntId = env->GetStaticMethodID(ecCalibratorStatusClass,"fromInt","(I)Lorg/linphone/core/LinphoneCore$EcCalibratorStatus;");
139
140                 /*void newSubscriptionRequest(LinphoneCore lc, LinphoneFriend lf, String url)*/
141                 newSubscriptionRequestId = env->GetMethodID(listenerClass,"newSubscriptionRequest","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneFriend;Ljava/lang/String;)V");
142
143                 /*void notifyPresenceReceived(LinphoneCore lc, LinphoneFriend lf);*/
144                 notifyPresenceReceivedId = env->GetMethodID(listenerClass,"notifyPresenceReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneFriend;)V");
145
146                 /*void textReceived(LinphoneCore lc, LinphoneChatRoom cr,LinphoneAddress from,String message);*/
147                 textReceivedId = env->GetMethodID(listenerClass,"textReceived","(Lorg/linphone/core/LinphoneCore;Lorg/linphone/core/LinphoneChatRoom;Lorg/linphone/core/LinphoneAddress;Ljava/lang/String;)V");
148
149                 proxyClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneProxyConfigImpl"));
150                 proxyCtrId = env->GetMethodID(proxyClass,"<init>", "(J)V");
151
152                 callClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneCallImpl"));
153                 callCtrId = env->GetMethodID(callClass,"<init>", "(J)V");
154
155                 chatRoomClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneChatRoomImpl"));
156                 chatRoomCtrId = env->GetMethodID(chatRoomClass,"<init>", "(J)V");
157
158                 friendClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneFriendImpl"));;
159                 friendCtrId =env->GetMethodID(friendClass,"<init>", "(J)V");
160
161                 addressClass = (jclass)env->NewGlobalRef(env->FindClass("org/linphone/core/LinphoneAddressImpl"));
162                 addressCtrId =env->GetMethodID(addressClass,"<init>", "(J)V");
163
164         }
165
166         ~LinphoneCoreData() {
167                 JNIEnv *env = 0;
168                 jvm->AttachCurrentThread(&env,NULL);
169                 env->DeleteGlobalRef(core);
170                 env->DeleteGlobalRef(listener);
171                 if (userdata) env->DeleteGlobalRef(userdata);
172                 env->DeleteGlobalRef(listenerClass);
173                 env->DeleteGlobalRef(globalStateClass);
174                 env->DeleteGlobalRef(registrationStateClass);
175                 env->DeleteGlobalRef(callStateClass);
176                 env->DeleteGlobalRef(proxyClass);
177                 env->DeleteGlobalRef(callClass);
178                 env->DeleteGlobalRef(chatRoomClass);
179                 env->DeleteGlobalRef(friendClass);
180
181         }
182         jobject core;
183         jobject listener;
184         jobject userdata;
185
186         jclass listenerClass;
187         jmethodID displayStatusId;
188         jmethodID newSubscriptionRequestId;
189         jmethodID notifyPresenceReceivedId;
190         jmethodID textReceivedId;
191
192         jclass globalStateClass;
193         jmethodID globalStateId;
194         jmethodID globalStateFromIntId;
195
196         jclass registrationStateClass;
197         jmethodID registrationStateId;
198         jmethodID registrationStateFromIntId;
199
200         jclass callStateClass;
201         jmethodID callStateId;
202         jmethodID callStateFromIntId;
203
204         jmethodID callEncryptionChangedId;
205
206         jclass ecCalibratorStatusClass;
207         jmethodID ecCalibrationStatusId;
208         jmethodID ecCalibratorStatusFromIntId;
209
210         jclass proxyClass;
211         jmethodID proxyCtrId;
212
213         jclass callClass;
214         jmethodID callCtrId;
215
216         jclass chatRoomClass;
217         jmethodID chatRoomCtrId;
218
219         jclass friendClass;
220         jmethodID friendCtrId;
221
222         jclass addressClass;
223         jmethodID addressCtrId;
224
225         LinphoneCoreVTable vTable;
226
227         static void showInterfaceCb(LinphoneCore *lc) {
228
229         }
230         static void byeReceivedCb(LinphoneCore *lc, const char *from) {
231
232         }
233         static void displayStatusCb(LinphoneCore *lc, const char *message) {
234                 JNIEnv *env = 0;
235                 jint result = jvm->AttachCurrentThread(&env,NULL);
236                 if (result != 0) {
237                         ms_error("cannot attach VM\n");
238                         return;
239                 }
240                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
241                 env->CallVoidMethod(lcData->listener,lcData->displayStatusId,lcData->core,env->NewStringUTF(message));
242         }
243         static void displayMessageCb(LinphoneCore *lc, const char *message) {
244
245         }
246         static void authInfoRequested(LinphoneCore *lc, const char *realm, const char *username) {
247
248         }
249         static void globalStateChange(LinphoneCore *lc, LinphoneGlobalState gstate,const char* message) {
250                 JNIEnv *env = 0;
251                 jint result = jvm->AttachCurrentThread(&env,NULL);
252                 if (result != 0) {
253                         ms_error("cannot attach VM\n");
254                         return;
255                 }
256                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
257                 env->CallVoidMethod(lcData->listener
258                                                         ,lcData->globalStateId
259                                                         ,lcData->core
260                                                         ,env->CallStaticObjectMethod(lcData->globalStateClass,lcData->globalStateFromIntId,(jint)gstate),
261                                                         message ? env->NewStringUTF(message) : NULL);
262         }
263         static void registrationStateChange(LinphoneCore *lc, LinphoneProxyConfig* proxy,LinphoneRegistrationState state,const char* message) {
264                 JNIEnv *env = 0;
265                 jint result = jvm->AttachCurrentThread(&env,NULL);
266                 if (result != 0) {
267                         ms_error("cannot attach VM\n");
268                         return;
269                 }
270                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
271                 env->CallVoidMethod(lcData->listener
272                                                         ,lcData->registrationStateId
273                                                         ,lcData->core
274                                                         ,env->NewObject(lcData->proxyClass,lcData->proxyCtrId,(jlong)proxy)
275                                                         ,env->CallStaticObjectMethod(lcData->registrationStateClass,lcData->registrationStateFromIntId,(jint)state),
276                                                         message ? env->NewStringUTF(message) : NULL);
277         }
278         jobject getCall(JNIEnv *env , LinphoneCall *call){
279                 jobject jobj=0;
280
281                 if (call!=NULL){
282                         void *up=linphone_call_get_user_pointer(call);
283                         
284                         if (up==NULL){
285                                 jobj=env->NewObject(callClass,callCtrId,(jlong)call);
286                                 jobj=env->NewGlobalRef(jobj);
287                                 linphone_call_set_user_pointer(call,(void*)jobj);
288                                 linphone_call_ref(call);
289                         }else{
290                                 jobj=(jobject)up;
291                         }
292                 }
293                 return jobj;
294         }
295
296         static void callStateChange(LinphoneCore *lc, LinphoneCall* call,LinphoneCallState state,const char* message) {
297                 JNIEnv *env = 0;
298                 jint result = jvm->AttachCurrentThread(&env,NULL);
299                 jobject jcall;
300                 if (result != 0) {
301                         ms_error("cannot attach VM\n");
302                         return;
303                 }
304                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
305                 env->CallVoidMethod(lcData->listener
306                                                         ,lcData->callStateId
307                                                         ,lcData->core
308                                                         ,(jcall=lcData->getCall(env,call))
309                                                         ,env->CallStaticObjectMethod(lcData->callStateClass,lcData->callStateFromIntId,(jint)state),
310                                                         message ? env->NewStringUTF(message) : NULL);
311                 if (state==LinphoneCallReleased){
312                         linphone_call_set_user_pointer(call,NULL);
313                         env->DeleteGlobalRef(jcall);
314                 }
315         }
316         static void callEncryptionChange(LinphoneCore *lc, LinphoneCall* call, bool_t encrypted,const char* authentication_token) {
317                 JNIEnv *env = 0;
318                 jint result = jvm->AttachCurrentThread(&env,NULL);
319                 if (result != 0) {
320                         ms_error("cannot attach VM\n");
321                         return;
322                 }
323                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
324                 env->CallVoidMethod(lcData->listener
325                                                         ,lcData->callEncryptionChangedId
326                                                         ,lcData->core
327                                                         ,lcData->getCall(env,call)
328                                                         ,encrypted
329                                                         ,authentication_token ? env->NewStringUTF(authentication_token) : NULL);
330         }
331         static void notify_presence_recv (LinphoneCore *lc,  LinphoneFriend *my_friend) {
332                 JNIEnv *env = 0;
333                 jint result = jvm->AttachCurrentThread(&env,NULL);
334                 if (result != 0) {
335                         ms_error("cannot attach VM\n");
336                         return;
337                 }
338                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
339                 env->CallVoidMethod(lcData->listener
340                                                         ,lcData->notifyPresenceReceivedId
341                                                         ,lcData->core
342                                                         ,env->NewObject(lcData->friendClass,lcData->friendCtrId,(jlong)my_friend));
343         }
344         static void new_subscription_request (LinphoneCore *lc,  LinphoneFriend *my_friend, const char* url) {
345                 JNIEnv *env = 0;
346                 jint result = jvm->AttachCurrentThread(&env,NULL);
347                 if (result != 0) {
348                         ms_error("cannot attach VM\n");
349                         return;
350                 }
351                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
352                 env->CallVoidMethod(lcData->listener
353                                                         ,lcData->newSubscriptionRequestId
354                                                         ,lcData->core
355                                                         ,env->NewObject(lcData->friendClass,lcData->friendCtrId,(jlong)my_friend)
356                                                         ,url ? env->NewStringUTF(url) : NULL);
357         }
358         static void text_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from, const char *message) {
359                 JNIEnv *env = 0;
360                 jint result = jvm->AttachCurrentThread(&env,NULL);
361                 if (result != 0) {
362                         ms_error("cannot attach VM\n");
363                         return;
364                 }
365                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
366                 env->CallVoidMethod(lcData->listener
367                                                         ,lcData->textReceivedId
368                                                         ,lcData->core
369                                                         ,env->NewObject(lcData->chatRoomClass,lcData->chatRoomCtrId,(jlong)room)
370                                                         ,env->NewObject(lcData->addressClass,lcData->addressCtrId,(jlong)from)
371                                                         ,message ? env->NewStringUTF(message) : NULL);
372         }
373         static void ecCalibrationStatus(LinphoneCore *lc, LinphoneEcCalibratorStatus status, int delay_ms, void *data) {
374                 JNIEnv *env = 0;
375                 jint result = jvm->AttachCurrentThread(&env,NULL);
376                 if (result != 0) {
377                         ms_error("cannot attach VM\n");
378                         return;
379                 }
380                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
381                 env->CallVoidMethod(lcData->listener
382                                                         ,lcData->ecCalibrationStatusId
383                                                         ,lcData->core
384                                                         ,env->CallStaticObjectMethod(lcData->ecCalibratorStatusClass,lcData->ecCalibratorStatusFromIntId,(jint)status)
385                                                         ,delay_ms
386                                                         ,data ? data : NULL);
387                 if (data != NULL &&status !=LinphoneEcCalibratorInProgress ) {
388                         //final state, releasing global ref
389                         env->DeleteGlobalRef((jobject)data);
390                 }
391
392         }
393
394
395 };
396 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_newLinphoneCore(JNIEnv*  env
397                 ,jobject  thiz
398                 ,jobject jlistener
399                 ,jstring juserConfig
400                 ,jstring jfactoryConfig
401                 ,jobject  juserdata){
402
403         const char* userConfig = juserConfig?env->GetStringUTFChars(juserConfig, NULL):NULL;
404         const char* factoryConfig = jfactoryConfig?env->GetStringUTFChars(jfactoryConfig, NULL):NULL;
405         LinphoneCoreData* ldata = new LinphoneCoreData(env,thiz,jlistener,juserdata);
406
407 #ifdef HAVE_ILBC
408         libmsilbc_init(); // requires an fpu
409 #endif
410 #ifdef HAVE_X264
411         libmsx264_init();
412 #endif
413 #ifdef HAVE_AMR
414         libmsamr_init();
415 #endif
416 #ifdef HAVE_SILK
417         libmssilk_init();
418 #endif
419         jlong nativePtr = (jlong)linphone_core_new(     &ldata->vTable
420                         ,userConfig
421                         ,factoryConfig
422                         ,ldata);
423         //clear auth info list
424         linphone_core_clear_all_auth_info((LinphoneCore*) nativePtr);
425         //clear existing proxy config
426         linphone_core_clear_proxy_config((LinphoneCore*) nativePtr);
427
428         if (userConfig) env->ReleaseStringUTFChars(juserConfig, userConfig);
429         if (factoryConfig) env->ReleaseStringUTFChars(jfactoryConfig, factoryConfig);
430         return nativePtr;
431 }
432 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_delete(JNIEnv*  env
433                 ,jobject  thiz
434                 ,jlong lc) {
435         LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc);
436         linphone_core_destroy((LinphoneCore*)lc);
437         delete lcData;
438 }
439
440 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_clearProxyConfigs(JNIEnv* env, jobject thiz,jlong lc) {
441         linphone_core_clear_proxy_config((LinphoneCore*)lc);
442 }
443
444 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDefaultProxyConfig(  JNIEnv*  env
445                 ,jobject  thiz
446                 ,jlong lc
447                 ,jlong pc) {
448         linphone_core_set_default_proxy((LinphoneCore*)lc,(LinphoneProxyConfig*)pc);
449 }
450 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getDefaultProxyConfig( JNIEnv*  env
451                 ,jobject  thiz
452                 ,jlong lc) {
453         LinphoneProxyConfig *config=0;
454         linphone_core_get_default_proxy((LinphoneCore*)lc,&config);
455         return (jlong)config;
456 }
457
458 extern "C" int Java_org_linphone_core_LinphoneCoreImpl_addProxyConfig(  JNIEnv*  env
459                 ,jobject  thiz
460                 ,jobject jproxyCfg
461                 ,jlong lc
462                 ,jlong pc) {
463         LinphoneProxyConfig* proxy = (LinphoneProxyConfig*)pc;
464         linphone_proxy_config_set_user_data(proxy, env->NewGlobalRef(jproxyCfg));
465
466         return linphone_core_add_proxy_config((LinphoneCore*)lc,(LinphoneProxyConfig*)pc);
467 }
468
469 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_clearAuthInfos(JNIEnv* env, jobject thiz,jlong lc) {
470         linphone_core_clear_all_auth_info((LinphoneCore*)lc);
471 }
472
473 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addAuthInfo(    JNIEnv*  env
474                 ,jobject  thiz
475                 ,jlong lc
476                 ,jlong pc) {
477         linphone_core_add_auth_info((LinphoneCore*)lc,(LinphoneAuthInfo*)pc);
478 }
479 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_iterate(        JNIEnv*  env
480                 ,jobject  thiz
481                 ,jlong lc) {
482         linphone_core_iterate((LinphoneCore*)lc);
483 }
484 extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_invite(      JNIEnv*  env
485                 ,jobject  thiz
486                 ,jlong lc
487                 ,jstring juri) {
488         const char* uri = env->GetStringUTFChars(juri, NULL);
489         LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc);
490         LinphoneCall* lCall = linphone_core_invite((LinphoneCore*)lc,uri);
491         env->ReleaseStringUTFChars(juri, uri);
492         return lcd->getCall(env,lCall);
493 }
494 extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_inviteAddress(       JNIEnv*  env
495                 ,jobject  thiz
496                 ,jlong lc
497                 ,jlong to) {
498         LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc);
499         return lcd->getCall(env, linphone_core_invite_address((LinphoneCore*)lc,(LinphoneAddress*)to));
500 }
501
502 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_terminateCall(  JNIEnv*  env
503                 ,jobject  thiz
504                 ,jlong lc
505                 ,jlong call) {
506         linphone_core_terminate_call((LinphoneCore*)lc,(LinphoneCall*)call);
507 }
508
509 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getRemoteAddress(      JNIEnv*  env
510                 ,jobject  thiz
511                 ,jlong lc) {
512         return (jlong)linphone_core_get_current_call_remote_address((LinphoneCore*)lc);
513 }
514 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isInCall(   JNIEnv*  env
515                 ,jobject  thiz
516                 ,jlong lc) {
517
518         return linphone_core_in_call((LinphoneCore*)lc);
519 }
520 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isInComingInvitePending(    JNIEnv*  env
521                 ,jobject  thiz
522                 ,jlong lc) {
523
524         return linphone_core_inc_invite_pending((LinphoneCore*)lc);
525 }
526 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_acceptCall(     JNIEnv*  env
527                 ,jobject  thiz
528                 ,jlong lc
529                 ,jlong call) {
530
531         linphone_core_accept_call((LinphoneCore*)lc,(LinphoneCall*)call);
532 }
533
534 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getCallLog(    JNIEnv*  env
535                 ,jobject  thiz
536                 ,jlong lc
537                 ,jint position) {
538                 return (jlong)ms_list_nth_data(linphone_core_get_call_logs((LinphoneCore*)lc),position);
539 }
540 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getNumberOfCallLogs(    JNIEnv*  env
541                 ,jobject  thiz
542                 ,jlong lc) {
543                 return ms_list_size(linphone_core_get_call_logs((LinphoneCore*)lc));
544 }
545 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setNetworkStateReachable(       JNIEnv*  env
546                 ,jobject  thiz
547                 ,jlong lc
548                 ,jboolean isReachable) {
549                 linphone_core_set_network_reachable((LinphoneCore*)lc,isReachable);
550 }
551
552 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPlaybackGain(        JNIEnv*  env
553                 ,jobject  thiz
554                 ,jlong lc
555                 ,jfloat gain) {
556                 linphone_core_set_playback_gain_db((LinphoneCore*)lc,gain);
557 }
558
559 extern "C" float Java_org_linphone_core_LinphoneCoreImpl_getPlaybackGain(       JNIEnv*  env
560                 ,jobject  thiz
561                 ,jlong lc) {
562                 return linphone_core_get_playback_gain_db((LinphoneCore*)lc);
563 }
564
565 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_muteMic(        JNIEnv*  env
566                 ,jobject  thiz
567                 ,jlong lc
568                 ,jboolean isMuted) {
569                 linphone_core_mute_mic((LinphoneCore*)lc,isMuted);
570 }
571
572 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_interpretUrl(  JNIEnv*  env
573                 ,jobject  thiz
574                 ,jlong lc
575                 ,jstring jurl) {
576         const char* url = env->GetStringUTFChars(jurl, NULL);
577         jlong result = (jlong)linphone_core_interpret_url((LinphoneCore*)lc,url);
578         env->ReleaseStringUTFChars(jurl, url);
579         return result;
580 }
581 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_sendDtmf(       JNIEnv*  env
582                 ,jobject  thiz
583                 ,jlong lc
584                 ,jchar dtmf) {
585         linphone_core_send_dtmf((LinphoneCore*)lc,dtmf);
586 }
587 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_playDtmf(       JNIEnv*  env
588                 ,jobject  thiz
589                 ,jlong lc
590                 ,jchar dtmf
591                 ,jint duration) {
592         linphone_core_play_dtmf((LinphoneCore*)lc,dtmf,duration);
593 }
594 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_stopDtmf(       JNIEnv*  env
595                 ,jobject  thiz
596                 ,jlong lc) {
597         linphone_core_stop_dtmf((LinphoneCore*)lc);
598 }
599
600 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_clearCallLogs(JNIEnv*  env
601                                                                                                                                                 ,jobject  thiz
602                                                                                                                                                 ,jlong lc) {
603         linphone_core_clear_call_logs((LinphoneCore*)lc);
604 }
605 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isMicMuted( JNIEnv*  env
606                 ,jobject  thiz
607                 ,jlong lc) {
608         return linphone_core_is_mic_muted((LinphoneCore*)lc);
609 }
610 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_findPayloadType(JNIEnv*  env
611                                                                                                                                                         ,jobject  thiz
612                                                                                                                                                         ,jlong lc
613                                                                                                                                                         ,jstring jmime
614                                                                                                                                                         ,jint rate) {
615         const char* mime = env->GetStringUTFChars(jmime, NULL);
616         jlong result = (jlong)linphone_core_find_payload_type((LinphoneCore*)lc,mime,rate);
617         env->ReleaseStringUTFChars(jmime, mime);
618         return result;
619 }
620 extern "C" jlongArray Java_org_linphone_core_LinphoneCoreImpl_listVideoPayloadTypes(JNIEnv*  env
621                                                                                                                                                         ,jobject  thiz
622                                                                                                                                                         ,jlong lc) {
623         const MSList* codecs = linphone_core_get_video_codecs((LinphoneCore*)lc);
624         int codecsCount = ms_list_size(codecs);
625         jlongArray jCodecs = env->NewLongArray(codecsCount);
626         jlong *jInternalArray = env->GetLongArrayElements(jCodecs, NULL);
627
628         for (int i = 0; i < codecsCount; i++ ) {
629                 jInternalArray[i] = (unsigned long) (codecs->data);
630                 codecs = codecs->next;
631         }
632
633         env->ReleaseLongArrayElements(jCodecs, jInternalArray, 0);
634
635         return jCodecs;
636 }
637
638 extern "C" jlongArray Java_org_linphone_core_LinphoneCoreImpl_listAudioPayloadTypes(JNIEnv*  env
639                                                                                                                                                         ,jobject  thiz
640                                                                                                                                                         ,jlong lc) {
641         const MSList* codecs = linphone_core_get_audio_codecs((LinphoneCore*)lc);
642         int codecsCount = ms_list_size(codecs);
643         jlongArray jCodecs = env->NewLongArray(codecsCount);
644         jlong *jInternalArray = env->GetLongArrayElements(jCodecs, NULL);
645
646         for (int i = 0; i < codecsCount; i++ ) {
647                 jInternalArray[i] = (unsigned long) (codecs->data);
648                 codecs = codecs->next;
649         }
650
651         env->ReleaseLongArrayElements(jCodecs, jInternalArray, 0);
652
653         return jCodecs;
654 }
655
656 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_enablePayloadType(JNIEnv*  env
657                                                                                                                                                         ,jobject  thiz
658                                                                                                                                                         ,jlong lc
659                                                                                                                                                         ,jlong pt
660                                                                                                                                                         ,jboolean enable) {
661         return linphone_core_enable_payload_type((LinphoneCore*)lc,(PayloadType*)pt,enable);
662 }
663 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableEchoCancellation(JNIEnv*  env
664                                                                                                                                                         ,jobject  thiz
665                                                                                                                                                         ,jlong lc
666                                                                                                                                                         ,jboolean enable) {
667         linphone_core_enable_echo_cancellation((LinphoneCore*)lc,enable);
668 }
669 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableEchoLimiter(JNIEnv*  env
670                                                                                                                                                         ,jobject  thiz
671                                                                                                                                                         ,jlong lc
672                                                                                                                                                         ,jboolean enable) {
673         linphone_core_enable_echo_limiter((LinphoneCore*)lc,enable);
674 }
675 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isEchoCancellationEnabled(JNIEnv*  env
676                                                                                                                                                         ,jobject  thiz
677                                                                                                                                                         ,jlong lc
678                                                                                                                                                         ) {
679         return linphone_core_echo_cancellation_enabled((LinphoneCore*)lc);
680 }
681
682 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isEchoLimiterEnabled(JNIEnv*  env
683                                                                                                                                                         ,jobject  thiz
684                                                                                                                                                         ,jlong lc
685                                                                                                                                                         ) {
686         return linphone_core_echo_limiter_enabled((LinphoneCore*)lc);
687 }
688
689 extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_getCurrentCall(JNIEnv*  env
690                                                                                                                                                         ,jobject  thiz
691                                                                                                                                                         ,jlong lc
692                                                                                                                                                         ) {
693         LinphoneCoreData *lcdata=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc);
694         
695         return lcdata->getCall(env,linphone_core_get_current_call((LinphoneCore*)lc));
696 }
697 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addFriend(JNIEnv*  env
698                                                                                                                                                         ,jobject  thiz
699                                                                                                                                                         ,jlong lc
700                                                                                                                                                         ,jlong aFriend
701                                                                                                                                                         ) {
702         linphone_core_add_friend((LinphoneCore*)lc,(LinphoneFriend*)aFriend);
703 }
704 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPresenceInfo(JNIEnv*  env
705                                                                                                                                                         ,jobject  thiz
706                                                                                                                                                         ,jlong lc
707                                                                                                                                                         ,jint minute_away
708                                                                                                                                                         ,jstring jalternative_contact
709                                                                                                                                                         ,jint status) {
710         const char* alternative_contact = jalternative_contact?env->GetStringUTFChars(jalternative_contact, NULL):NULL;
711         linphone_core_set_presence_info((LinphoneCore*)lc,minute_away,alternative_contact,(LinphoneOnlineStatus)status);
712         if (alternative_contact) env->ReleaseStringUTFChars(jalternative_contact, alternative_contact);
713 }
714
715 extern "C" long Java_org_linphone_core_LinphoneCoreImpl_createChatRoom(JNIEnv*  env
716                                                                                                                                                         ,jobject  thiz
717                                                                                                                                                         ,jlong lc
718                                                                                                                                                         ,jstring jto) {
719
720         const char* to = env->GetStringUTFChars(jto, NULL);
721         LinphoneChatRoom* lResult = linphone_core_create_chat_room((LinphoneCore*)lc,to);
722         env->ReleaseStringUTFChars(jto, to);
723         return (long)lResult;
724 }
725
726 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableVideo(JNIEnv*  env
727                                                                                                                                                         ,jobject  thiz
728                                                                                                                                                         ,jlong lc
729                                                                                                                                                         ,jboolean vcap_enabled
730                                                                                                                                                         ,jboolean display_enabled) {
731         linphone_core_enable_video((LinphoneCore*)lc, vcap_enabled,display_enabled);
732
733 }
734 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isVideoEnabled(JNIEnv*  env
735                                                                                                                                                         ,jobject  thiz
736                                                                                                                                                         ,jlong lc) {
737         return linphone_core_video_enabled((LinphoneCore*)lc);
738 }
739 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPlayFile(JNIEnv*  env
740                                                                                                                                                         ,jobject  thiz
741                                                                                                                                                         ,jlong lc
742                                                                                                                                                         ,jstring jpath) {
743         const char* path = jpath?env->GetStringUTFChars(jpath, NULL):NULL;
744         linphone_core_set_play_file((LinphoneCore*)lc,path);
745         if (path) env->ReleaseStringUTFChars(jpath, path);
746 }
747 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setRing(JNIEnv*  env
748                                                                                                                                                         ,jobject  thiz
749                                                                                                                                                         ,jlong lc
750                                                                                                                                                         ,jstring jpath) {
751         const char* path = jpath?env->GetStringUTFChars(jpath, NULL):NULL;
752         linphone_core_set_ring((LinphoneCore*)lc,path);
753         if (path) env->ReleaseStringUTFChars(jpath, path);
754 }
755 extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getRing(JNIEnv*  env
756                                                                                                                                                         ,jobject  thiz
757                                                                                                                                                         ,jlong lc
758                                                                                                                                                         ) {
759         const char* path = linphone_core_get_ring((LinphoneCore*)lc);
760         if (path) {
761                 return env->NewStringUTF(path);
762         } else {
763                 return NULL;
764         }
765 }
766 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setRootCA(JNIEnv*  env
767                                                                                                                                                         ,jobject  thiz
768                                                                                                                                                         ,jlong lc
769                                                                                                                                                         ,jstring jpath) {
770         const char* path = jpath?env->GetStringUTFChars(jpath, NULL):NULL;
771         linphone_core_set_root_ca((LinphoneCore*)lc,path);
772         if (path) env->ReleaseStringUTFChars(jpath, path);
773 }
774 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableKeepAlive(JNIEnv*  env
775                                                                                                                                 ,jobject  thiz
776                                                                                                                                 ,jlong lc
777                                                                                                                                 ,jboolean enable) {
778         linphone_core_enable_keep_alive((LinphoneCore*)lc,enable);
779
780 }
781 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isKeepAliveEnabled(JNIEnv*  env
782                                                                                                                                 ,jobject  thiz
783                                                                                                                                 ,jlong lc) {
784         return linphone_core_keep_alive_enabled((LinphoneCore*)lc);
785
786 }
787 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_startEchoCalibration(JNIEnv*  env
788                                                                                                                                                                 ,jobject  thiz
789                                                                                                                                                                 ,jlong lc
790                                                                                                                                                                 ,jobject data) {
791         return linphone_core_start_echo_calibration((LinphoneCore*)lc
792                                                                                                         , LinphoneCoreData::ecCalibrationStatus
793                                                                                                         , data?env->NewGlobalRef(data):NULL);
794
795 }
796
797 extern "C" int Java_org_linphone_core_LinphoneCoreImpl_getMediaEncryption(JNIEnv*  env
798                                                                                                                                                         ,jobject  thiz
799                                                                                                                                                         ,jlong lc
800                                                                                                                                                         ) {
801         return (int)linphone_core_get_media_encryption((LinphoneCore*)lc);
802 }
803
804 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setMediaEncryption(JNIEnv*  env
805                                                                                                                                                         ,jobject  thiz
806                                                                                                                                                         ,jlong lc
807                                                                                                                                                         ,int menc) {
808         linphone_core_set_media_encryption((LinphoneCore*)lc,(LinphoneMediaEncryption)menc);
809 }
810
811 extern "C" int Java_org_linphone_core_LinphoneCallParamsImpl_getMediaEncryption(JNIEnv*  env
812                                                                                                                                                         ,jobject  thiz
813                                                                                                                                                         ,jlong cp
814                                                                                                                                                         ) {
815         return (int)linphone_call_params_get_media_encryption((LinphoneCallParams*)cp);
816 }
817
818 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_mediaEncryptionSupported(JNIEnv*  env
819                                                                                                                                                         ,jobject  thiz
820                                                                                                                                                         ,jlong lc, jint menc
821                                                                                                                                                         ) {
822         return linphone_core_media_encryption_supported((LinphoneCore*)lc,(LinphoneMediaEncryption)menc);
823 }
824
825 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_setMediaEncryption(JNIEnv*  env
826                                                                                                                                                         ,jobject  thiz
827                                                                                                                                                         ,jlong cp
828                                                                                                                                                         ,int jmenc) {
829         linphone_call_params_set_media_encryption((LinphoneCallParams*)cp,(LinphoneMediaEncryption)jmenc);
830 }
831
832 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_getMediaEncryptionMandatory(JNIEnv*  env
833                                                                                                                                                         ,jobject  thiz
834                                                                                                                                                         ,jlong lc
835                                                                                                                                                         ) {
836         return linphone_core_is_media_encryption_mandatory((LinphoneCore*)lc);
837 }
838
839 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setMediaEncryptionMandatory(JNIEnv*  env
840                                                                                                                                                         ,jobject  thiz
841                                                                                                                                                         ,jlong lc
842                                                                                                                                                         , jboolean yesno
843                                                                                                                                                         ) {
844         linphone_core_set_media_encryption_mandatory((LinphoneCore*)lc, yesno);
845 }
846
847 //ProxyConfig
848
849 extern "C" jlong Java_org_linphone_core_LinphoneProxyConfigImpl_newLinphoneProxyConfig(JNIEnv*  env,jobject  thiz) {
850         LinphoneProxyConfig* proxy = linphone_proxy_config_new();
851         return  (jlong) proxy;
852 }
853
854 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_delete(JNIEnv*  env,jobject  thiz,jlong ptr) {
855         linphone_proxy_config_destroy((LinphoneProxyConfig*)ptr);
856 }
857 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setIdentity(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jidentity) {
858         const char* identity = env->GetStringUTFChars(jidentity, NULL);
859         linphone_proxy_config_set_identity((LinphoneProxyConfig*)proxyCfg,identity);
860         env->ReleaseStringUTFChars(jidentity, identity);
861 }
862 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getIdentity(JNIEnv* env,jobject thiz,jlong proxyCfg) {
863         const char* identity = linphone_proxy_config_get_identity((LinphoneProxyConfig*)proxyCfg);
864         if (identity) {
865                 return env->NewStringUTF(identity);
866         } else {
867                 return NULL;
868         }
869 }
870 extern "C" int Java_org_linphone_core_LinphoneProxyConfigImpl_setProxy(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jproxy) {
871         const char* proxy = env->GetStringUTFChars(jproxy, NULL);
872         int err=linphone_proxy_config_set_server_addr((LinphoneProxyConfig*)proxyCfg,proxy);
873         env->ReleaseStringUTFChars(jproxy, proxy);
874         return err;
875 }
876 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getProxy(JNIEnv* env,jobject thiz,jlong proxyCfg) {
877         const char* proxy = linphone_proxy_config_get_addr((LinphoneProxyConfig*)proxyCfg);
878         if (proxy) {
879                 return env->NewStringUTF(proxy);
880         } else {
881                 return NULL;
882         }
883 }
884 extern "C" int Java_org_linphone_core_LinphoneProxyConfigImpl_setRoute(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jroute) {
885         if (jroute != NULL) {
886                 const char* route = env->GetStringUTFChars(jroute, NULL);
887                 int err=linphone_proxy_config_set_route((LinphoneProxyConfig*)proxyCfg,route);
888                 env->ReleaseStringUTFChars(jroute, route);
889                 return err;
890         } else {
891                 return linphone_proxy_config_set_route((LinphoneProxyConfig*)proxyCfg,NULL);
892         }
893 }
894 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getRoute(JNIEnv* env,jobject thiz,jlong proxyCfg) {
895         const char* route = linphone_proxy_config_get_route((LinphoneProxyConfig*)proxyCfg);
896         if (route) {
897                 return env->NewStringUTF(route);
898         } else {
899                 return NULL;
900         }
901 }
902
903 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_enableRegister(JNIEnv* env,jobject thiz,jlong proxyCfg,jboolean enableRegister) {
904         linphone_proxy_config_enable_register((LinphoneProxyConfig*)proxyCfg,enableRegister);
905 }
906 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_isRegistered(JNIEnv* env,jobject thiz,jlong proxyCfg) {
907         return linphone_proxy_config_is_registered((LinphoneProxyConfig*)proxyCfg);
908 }
909 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_isRegisterEnabled(JNIEnv* env,jobject thiz,jlong proxyCfg) {
910         return linphone_proxy_config_register_enabled((LinphoneProxyConfig*)proxyCfg);
911 }
912 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_edit(JNIEnv* env,jobject thiz,jlong proxyCfg) {
913         linphone_proxy_config_edit((LinphoneProxyConfig*)proxyCfg);
914 }
915 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_done(JNIEnv* env,jobject thiz,jlong proxyCfg) {
916         linphone_proxy_config_done((LinphoneProxyConfig*)proxyCfg);
917 }
918 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_normalizePhoneNumber(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jnumber) {
919         if (jnumber == 0) {
920                 ms_error("cannot normalized null number");
921         }
922         const char* number = env->GetStringUTFChars(jnumber, NULL);
923         int len = env->GetStringLength(jnumber);
924         if (len == 0) {
925                 ms_warning("cannot normalize empty number");
926                 return jnumber;
927         }
928         char targetBuff[2*len];// returned number can be greater than origin (specially in case of prefix insertion
929         linphone_proxy_config_normalize_number((LinphoneProxyConfig*)proxyCfg,number,targetBuff,sizeof(targetBuff));
930         jstring normalizedNumber = env->NewStringUTF(targetBuff);
931         env->ReleaseStringUTFChars(jnumber, number);
932         return normalizedNumber;
933 }
934 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getDomain(JNIEnv* env
935                                                                                                                                                         ,jobject thiz
936                                                                                                                                                         ,jlong proxyCfg) {
937         const char* domain = linphone_proxy_config_get_domain((LinphoneProxyConfig*)proxyCfg);
938         if (domain) {
939                 return env->NewStringUTF(domain);
940         } else {
941                 return NULL;
942         }
943 }
944 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setDialEscapePlus(JNIEnv* env,jobject thiz,jlong proxyCfg,jboolean value) {
945         linphone_proxy_config_set_dial_escape_plus((LinphoneProxyConfig*)proxyCfg,value);
946 }
947
948 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setDialPrefix(JNIEnv* env
949                                                                                                                                         ,jobject thiz
950                                                                                                                                         ,jlong proxyCfg
951                                                                                                                                         ,jstring jprefix) {
952         const char* prefix = env->GetStringUTFChars(jprefix, NULL);
953         linphone_proxy_config_set_dial_prefix((LinphoneProxyConfig*)proxyCfg,prefix);
954         env->ReleaseStringUTFChars(jprefix, prefix);
955 }
956 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_enablePublish(JNIEnv* env
957                                                                                                                                                                 ,jobject thiz
958                                                                                                                                                                 ,jlong proxyCfg
959                                                                                                                                                                 ,jboolean val) {
960         linphone_proxy_config_enable_publish((LinphoneProxyConfig*)proxyCfg,val);
961 }
962 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_publishEnabled(JNIEnv* env,jobject thiz,jlong proxyCfg) {
963         return linphone_proxy_config_publish_enabled((LinphoneProxyConfig*)proxyCfg);
964 }
965
966 //Auth Info
967
968 extern "C" jlong Java_org_linphone_core_LinphoneAuthInfoImpl_newLinphoneAuthInfo(JNIEnv* env
969                 , jobject thiz
970                 , jstring jusername
971                 , jstring juserid
972                 , jstring jpassword
973                 , jstring jha1
974                 , jstring jrealm) {
975
976         const char* username = env->GetStringUTFChars(jusername, NULL);
977         const char* password = env->GetStringUTFChars(jpassword, NULL);
978         jlong auth = (jlong)linphone_auth_info_new(username,NULL,password,NULL,NULL);
979
980         env->ReleaseStringUTFChars(jusername, username);
981         env->ReleaseStringUTFChars(jpassword, password);
982         return auth;
983
984 }
985 extern "C" void Java_org_linphone_core_LinphoneAuthInfoImpl_delete(JNIEnv* env
986                 , jobject thiz
987                 , jlong ptr) {
988         linphone_auth_info_destroy((LinphoneAuthInfo*)ptr);
989 }
990
991 //LinphoneAddress
992
993 extern "C" jlong Java_org_linphone_core_LinphoneAddressImpl_newLinphoneAddressImpl(JNIEnv*  env
994                                                                                                                                                                         ,jobject  thiz
995                                                                                                                                                                         ,jstring juri
996                                                                                                                                                                         ,jstring jdisplayName) {
997         const char* uri = env->GetStringUTFChars(juri, NULL);
998         LinphoneAddress* address = linphone_address_new(uri);
999         if (jdisplayName && address) {
1000                 const char* displayName = env->GetStringUTFChars(jdisplayName, NULL);
1001                 linphone_address_set_display_name(address,displayName);
1002                 env->ReleaseStringUTFChars(jdisplayName, displayName);
1003         }
1004         env->ReleaseStringUTFChars(juri, uri);
1005
1006         return  (jlong) address;
1007 }
1008 extern "C" void Java_org_linphone_core_LinphoneAddressImpl_delete(JNIEnv*  env
1009                                                                                                                                                 ,jobject  thiz
1010                                                                                                                                                 ,jlong ptr) {
1011         linphone_address_destroy((LinphoneAddress*)ptr);
1012 }
1013
1014 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getDisplayName(JNIEnv*  env
1015                                                                                                                                                 ,jobject  thiz
1016                                                                                                                                                 ,jlong ptr) {
1017         const char* displayName = linphone_address_get_display_name((LinphoneAddress*)ptr);
1018         if (displayName) {
1019                 return env->NewStringUTF(displayName);
1020         } else {
1021                 return 0;
1022         }
1023 }
1024 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getUserName(JNIEnv*  env
1025                                                                                                                                                 ,jobject  thiz
1026                                                                                                                                                 ,jlong ptr) {
1027         const char* userName = linphone_address_get_username((LinphoneAddress*)ptr);
1028         if (userName) {
1029                 return env->NewStringUTF(userName);
1030         } else {
1031                 return 0;
1032         }
1033 }
1034 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getDomain(JNIEnv*  env
1035                                                                                                                                                 ,jobject  thiz
1036                                                                                                                                                 ,jlong ptr) {
1037         const char* domain = linphone_address_get_domain((LinphoneAddress*)ptr);
1038         if (domain) {
1039                 return env->NewStringUTF(domain);
1040         } else {
1041                 return 0;
1042         }
1043 }
1044
1045 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_toString(JNIEnv*  env
1046                                                                                                                                                 ,jobject  thiz
1047                                                                                                                                                 ,jlong ptr) {
1048         char* uri = linphone_address_as_string((LinphoneAddress*)ptr);
1049         jstring juri =env->NewStringUTF(uri);
1050         ms_free(uri);
1051         return juri;
1052 }
1053 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_toUri(JNIEnv*  env
1054                                                                                                                                                 ,jobject  thiz
1055                                                                                                                                                 ,jlong ptr) {
1056         char* uri = linphone_address_as_string_uri_only((LinphoneAddress*)ptr);
1057         jstring juri =env->NewStringUTF(uri);
1058         ms_free(uri);
1059         return juri;
1060 }
1061 extern "C" void Java_org_linphone_core_LinphoneAddressImpl_setDisplayName(JNIEnv*  env
1062                                                                                                                                                 ,jobject  thiz
1063                                                                                                                                                 ,jlong address
1064                                                                                                                                                 ,jstring jdisplayName) {
1065         const char* displayName = jdisplayName!= NULL?env->GetStringUTFChars(jdisplayName, NULL):NULL;
1066         linphone_address_set_display_name((LinphoneAddress*)address,displayName);
1067         if (displayName != NULL) env->ReleaseStringUTFChars(jdisplayName, displayName);
1068 }
1069
1070
1071 //CallLog
1072 extern "C" jlong Java_org_linphone_core_LinphoneCallLogImpl_getFrom(JNIEnv*  env
1073                                                                                                                                                 ,jobject  thiz
1074                                                                                                                                                 ,jlong ptr) {
1075         return (jlong)((LinphoneCallLog*)ptr)->from;
1076 }
1077 extern "C" jlong Java_org_linphone_core_LinphoneCallLogImpl_getTo(JNIEnv*  env
1078                                                                                                                                                 ,jobject  thiz
1079                                                                                                                                                 ,jlong ptr) {
1080         return (jlong)((LinphoneCallLog*)ptr)->to;
1081 }
1082 extern "C" jboolean Java_org_linphone_core_LinphoneCallLogImpl_isIncoming(JNIEnv*  env
1083                                                                                                                                                 ,jobject  thiz
1084                                                                                                                                                 ,jlong ptr) {
1085         return ((LinphoneCallLog*)ptr)->dir==LinphoneCallIncoming?JNI_TRUE:JNI_FALSE;
1086 }
1087
1088 /*payloadType*/
1089 extern "C" jstring Java_org_linphone_core_PayloadTypeImpl_toString(JNIEnv*  env,jobject  thiz,jlong ptr) {
1090         PayloadType* pt = (PayloadType*)ptr;
1091         char* value = ms_strdup_printf("[%s] clock [%i], bitrate [%i]"
1092                                                                         ,payload_type_get_mime(pt)
1093                                                                         ,payload_type_get_rate(pt)
1094                                                                         ,payload_type_get_bitrate(pt));
1095         jstring jvalue =env->NewStringUTF(value);
1096         ms_free(value);
1097         return jvalue;
1098 }
1099 extern "C" jstring Java_org_linphone_core_PayloadTypeImpl_getMime(JNIEnv*  env,jobject  thiz,jlong ptr) {
1100         PayloadType* pt = (PayloadType*)ptr;
1101         jstring jvalue =env->NewStringUTF(payload_type_get_mime(pt));
1102         return jvalue;
1103 }
1104 extern "C" jint Java_org_linphone_core_PayloadTypeImpl_getRate(JNIEnv*  env,jobject  thiz, jlong ptr) {
1105         PayloadType* pt = (PayloadType*)ptr;
1106         return payload_type_get_rate(pt);
1107 }
1108
1109 //LinphoneCall
1110 extern "C" void Java_org_linphone_core_LinphoneCallImpl_finalize(JNIEnv*  env
1111                                                                                                                                                 ,jobject  thiz
1112                                                                                                                                                 ,jlong ptr) {
1113         LinphoneCall *call=(LinphoneCall*)ptr;
1114         linphone_call_unref(call);
1115 }
1116
1117 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getCallLog(    JNIEnv*  env
1118                                                                                                                                                 ,jobject  thiz
1119                                                                                                                                                 ,jlong ptr) {
1120         return (jlong)linphone_call_get_call_log((LinphoneCall*)ptr);
1121 }
1122
1123 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isIncoming( JNIEnv*  env
1124                                                                                                                                                 ,jobject  thiz
1125                                                                                                                                                 ,jlong ptr) {
1126         return linphone_call_get_dir((LinphoneCall*)ptr)==LinphoneCallIncoming?JNI_TRUE:JNI_FALSE;
1127 }
1128
1129 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getRemoteAddress(      JNIEnv*  env
1130                                                                                                                                                 ,jobject  thiz
1131                                                                                                                                                 ,jlong ptr) {
1132         return (jlong)linphone_call_get_remote_address((LinphoneCall*)ptr);
1133 }
1134
1135 extern "C" jint Java_org_linphone_core_LinphoneCallImpl_getState(       JNIEnv*  env
1136                                                                                                                                                 ,jobject  thiz
1137                                                                                                                                                 ,jlong ptr) {
1138         return (jint)linphone_call_get_state((LinphoneCall*)ptr);
1139 }
1140 extern "C" void Java_org_linphone_core_LinphoneCallImpl_enableEchoCancellation( JNIEnv*  env
1141                                                                                                                                                 ,jobject  thiz
1142                                                                                                                                                 ,jlong ptr
1143                                                                                                                                                 ,jboolean value) {
1144         linphone_call_enable_echo_cancellation((LinphoneCall*)ptr,value);
1145 }
1146 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isEchoCancellationEnabled(  JNIEnv*  env
1147                                                                                                                                                 ,jobject  thiz
1148                                                                                                                                                 ,jlong ptr) {
1149         return linphone_call_echo_cancellation_enabled((LinphoneCall*)ptr);
1150 }
1151
1152 extern "C" void Java_org_linphone_core_LinphoneCallImpl_enableEchoLimiter(      JNIEnv*  env
1153                                                                                                                                                 ,jobject  thiz
1154                                                                                                                                                 ,jlong ptr
1155                                                                                                                                                 ,jboolean value) {
1156         linphone_call_enable_echo_limiter((LinphoneCall*)ptr,value);
1157 }
1158 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isEchoLimiterEnabled(       JNIEnv*  env
1159                                                                                                                                                 ,jobject  thiz
1160                                                                                                                                                 ,jlong ptr) {
1161         return linphone_call_echo_limiter_enabled((LinphoneCall*)ptr);
1162 }
1163
1164 extern "C" jobject Java_org_linphone_core_LinphoneCallImpl_getReplacedCall(     JNIEnv*  env
1165                                                                                                                                                 ,jobject  thiz
1166                                                                                                                                                 ,jlong ptr) {
1167         LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data(linphone_call_get_core((LinphoneCall*)ptr));       
1168         return lcd->getCall(env,linphone_call_get_replaced_call((LinphoneCall*)ptr));
1169 }
1170
1171 extern "C" jfloat Java_org_linphone_core_LinphoneCallImpl_getCurrentQuality(    JNIEnv*  env
1172                                                                                                                                                 ,jobject  thiz
1173                                                                                                                                                 ,jlong ptr) {
1174         return (jfloat)linphone_call_get_current_quality((LinphoneCall*)ptr);
1175 }
1176
1177 extern "C" jfloat Java_org_linphone_core_LinphoneCallImpl_getAverageQuality(    JNIEnv*  env
1178                                                                                                                                                 ,jobject  thiz
1179                                                                                                                                                 ,jlong ptr) {
1180         return (jfloat)linphone_call_get_average_quality((LinphoneCall*)ptr);
1181 }
1182
1183
1184 //LinphoneFriend
1185 extern "C" long Java_org_linphone_core_LinphoneFriendImpl_newLinphoneFriend(JNIEnv*  env
1186                                                                                                                                                 ,jobject  thiz
1187                                                                                                                                                 ,jstring jFriendUri) {
1188         LinphoneFriend* lResult;
1189
1190         if (jFriendUri) {
1191                 const char* friendUri = env->GetStringUTFChars(jFriendUri, NULL);
1192                 lResult= linphone_friend_new_with_addr(friendUri);
1193                 env->ReleaseStringUTFChars(jFriendUri, friendUri);
1194         } else {
1195                 lResult = linphone_friend_new();
1196         }
1197         return (long)lResult;
1198 }
1199 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_setAddress(JNIEnv*  env
1200                                                                                                                                                 ,jobject  thiz
1201                                                                                                                                                 ,jlong ptr
1202                                                                                                                                                 ,jlong linphoneAddress) {
1203         linphone_friend_set_addr((LinphoneFriend*)ptr,(LinphoneAddress*)linphoneAddress);
1204 }
1205 extern "C" long Java_org_linphone_core_LinphoneFriendImpl_getAddress(JNIEnv*  env
1206                                                                                                                                                 ,jobject  thiz
1207                                                                                                                                                 ,jlong ptr) {
1208         return (long)linphone_friend_get_address((LinphoneFriend*)ptr);
1209 }
1210 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_setIncSubscribePolicy(JNIEnv*  env
1211                                                                                                                                                 ,jobject  thiz
1212                                                                                                                                                 ,jlong ptr
1213                                                                                                                                                 ,jint policy) {
1214         linphone_friend_set_inc_subscribe_policy((LinphoneFriend*)ptr,(LinphoneSubscribePolicy)policy);
1215 }
1216 extern "C" jint Java_org_linphone_core_LinphoneFriendImpl_getIncSubscribePolicy(JNIEnv*  env
1217                                                                                                                                                 ,jobject  thiz
1218                                                                                                                                                 ,jlong ptr) {
1219         return linphone_friend_get_inc_subscribe_policy((LinphoneFriend*)ptr);
1220 }
1221 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_enableSubscribes(JNIEnv*  env
1222                                                                                                                                                 ,jobject  thiz
1223                                                                                                                                                 ,jlong ptr
1224                                                                                                                                                 ,jboolean value) {
1225         linphone_friend_enable_subscribes((LinphoneFriend*)ptr,value);
1226 }
1227 extern "C" jboolean Java_org_linphone_core_LinphoneFriendImpl_isSubscribesEnabled(JNIEnv*  env
1228                                                                                                                                                 ,jobject  thiz
1229                                                                                                                                                 ,jlong ptr) {
1230         return linphone_friend_subscribes_enabled((LinphoneFriend*)ptr);
1231 }
1232 extern "C" jboolean Java_org_linphone_core_LinphoneFriendImpl_getStatus(JNIEnv*  env
1233                                                                                                                                                 ,jobject  thiz
1234                                                                                                                                                 ,jlong ptr) {
1235         return linphone_friend_get_status((LinphoneFriend*)ptr);
1236 }
1237 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_edit(JNIEnv*  env
1238                                                                                                                                                 ,jobject  thiz
1239                                                                                                                                                 ,jlong ptr) {
1240         return linphone_friend_edit((LinphoneFriend*)ptr);
1241 }
1242 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_done(JNIEnv*  env
1243                                                                                                                                                 ,jobject  thiz
1244                                                                                                                                                 ,jlong ptr) {
1245          linphone_friend_done((LinphoneFriend*)ptr);
1246 }
1247 //LinphoneChatRoom
1248 extern "C" long Java_org_linphone_core_LinphoneChatRoomImpl_getPeerAddress(JNIEnv*  env
1249                                                                                                                                                 ,jobject  thiz
1250                                                                                                                                                 ,jlong ptr) {
1251         return (long) linphone_chat_room_get_peer_address((LinphoneChatRoom*)ptr);
1252 }
1253 extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_sendMessage(JNIEnv*  env
1254                                                                                                                                                 ,jobject  thiz
1255                                                                                                                                                 ,jlong ptr
1256                                                                                                                                                 ,jstring jmessage) {
1257         const char* message = env->GetStringUTFChars(jmessage, NULL);
1258         linphone_chat_room_send_message((LinphoneChatRoom*)ptr,message);
1259         env->ReleaseStringUTFChars(jmessage, message);
1260
1261 }
1262
1263 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setVideoWindowId(JNIEnv* env
1264                                                                                                                                                 ,jobject thiz
1265                                                                                                                                                 ,jlong lc
1266                                                                                                                                                 ,jobject obj) {
1267         jobject oldWindow = (jobject) linphone_core_get_native_video_window_id((LinphoneCore*)lc);
1268         if (oldWindow != NULL) {
1269                 env->DeleteGlobalRef(oldWindow);
1270         }
1271         if (obj != NULL) {
1272                 obj = env->NewGlobalRef(obj);
1273         }
1274         linphone_core_set_native_video_window_id((LinphoneCore*)lc,(unsigned long)obj);
1275 }
1276
1277 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPreviewWindowId(JNIEnv* env
1278                                                                                                                                                 ,jobject thiz
1279                                                                                                                                                 ,jlong lc
1280                                                                                                                                                 ,jobject obj) {
1281         jobject oldWindow = (jobject) linphone_core_get_native_preview_window_id((LinphoneCore*)lc);
1282         if (oldWindow != NULL) {
1283                 env->DeleteGlobalRef(oldWindow);
1284         }
1285         if (obj != NULL) {
1286                 obj = env->NewGlobalRef(obj);
1287         }
1288         linphone_core_set_native_preview_window_id((LinphoneCore*)lc,(unsigned long)obj);
1289 }
1290
1291 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDeviceRotation(JNIEnv* env
1292                                                                                                                                                 ,jobject thiz
1293                                                                                                                                                 ,jlong lc
1294                                                                                                                                                 ,jint rotation) {
1295         linphone_core_set_device_rotation((LinphoneCore*)lc,rotation);
1296 }
1297
1298
1299 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setFirewallPolicy(JNIEnv *env, jobject thiz, jlong lc, int enum_value){
1300         linphone_core_set_firewall_policy((LinphoneCore*)lc,(LinphoneFirewallPolicy)enum_value);
1301 }
1302
1303 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getFirewallPolicy(JNIEnv *env, jobject thiz, jlong lc){
1304         return linphone_core_get_firewall_policy((LinphoneCore*)lc);
1305 }
1306
1307 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setStunServer(JNIEnv *env, jobject thiz, jlong lc, jstring jserver){
1308         const char* server = NULL;
1309         if (jserver) server=env->GetStringUTFChars(jserver, NULL);
1310         linphone_core_set_stun_server((LinphoneCore*)lc,server);
1311         if (server) env->ReleaseStringUTFChars(jserver,server);
1312 }
1313
1314 extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getStunServer(JNIEnv *env, jobject thiz, jlong lc){
1315         const char *ret= linphone_core_get_stun_server((LinphoneCore*)lc);
1316         if (ret==NULL) return NULL;
1317         jstring jvalue =env->NewStringUTF(ret);
1318         return jvalue;
1319 }
1320
1321 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_audioBandwidth(JNIEnv *env, jobject thiz, jlong lcp, jint bw){
1322         linphone_call_params_set_audio_bandwidth_limit((LinphoneCallParams*)lcp, bw);
1323 }
1324
1325 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_enableVideo(JNIEnv *env, jobject thiz, jlong lcp, jboolean b){
1326         linphone_call_params_enable_video((LinphoneCallParams*)lcp, b);
1327 }
1328
1329 extern "C" jboolean Java_org_linphone_core_LinphoneCallParamsImpl_getVideoEnabled(JNIEnv *env, jobject thiz, jlong lcp){
1330         return linphone_call_params_video_enabled((LinphoneCallParams*)lcp);
1331 }
1332
1333 extern "C" jboolean Java_org_linphone_core_LinphoneCallParamsImpl_localConferenceMode(JNIEnv *env, jobject thiz, jlong lcp){
1334         return linphone_call_params_local_conference_mode((LinphoneCallParams*)lcp);
1335 }
1336
1337 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_destroy(JNIEnv *env, jobject thiz, jlong lc){
1338         return linphone_call_params_destroy((LinphoneCallParams*)lc);
1339 }
1340 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_createDefaultCallParams(JNIEnv *env, jobject thiz, jlong lc){
1341         return (jlong) linphone_core_create_default_call_parameters((LinphoneCore*)lc);
1342 }
1343
1344 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getCurrentParamsCopy(JNIEnv *env, jobject thiz, jlong lc){
1345         return (jlong) linphone_call_params_copy(linphone_call_get_current_params((LinphoneCall*)lc));
1346 }
1347
1348 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_enableCamera(JNIEnv *env, jobject thiz, jlong lc, jboolean b){
1349         linphone_call_enable_camera((LinphoneCall *)lc, (bool_t) b);
1350 }
1351
1352 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_cameraEnabled(JNIEnv *env, jobject thiz, jlong lc){
1353         linphone_call_camera_enabled((LinphoneCall *)lc);
1354 }
1355
1356 extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_inviteAddressWithParams(JNIEnv *env, jobject thiz, jlong lc, jlong addr, jlong params){
1357         LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc);
1358         return  lcd->getCall(env,linphone_core_invite_address_with_params((LinphoneCore *)lc, (const LinphoneAddress *)addr, (const LinphoneCallParams *)params));
1359 }
1360
1361 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_updateAddressWithParams(JNIEnv *env, jobject thiz, jlong lc, jlong call, jlong params){
1362         return (jint) linphone_core_update_call((LinphoneCore *)lc, (LinphoneCall *)call, (LinphoneCallParams *)params);
1363 }
1364
1365 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_updateCall(JNIEnv *env, jobject thiz, jlong lc, jlong call, jlong params){
1366         return (jint) linphone_core_update_call((LinphoneCore *)lc, (LinphoneCall *)call, (const LinphoneCallParams *)params);
1367 }
1368
1369
1370 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPreferredVideoSize(JNIEnv *env, jobject thiz, jlong lc, jint width, jint height){
1371         MSVideoSize vsize;
1372         vsize.width = (int)width;
1373         vsize.height = (int)height;
1374         linphone_core_set_preferred_video_size((LinphoneCore *)lc, vsize);
1375 }
1376
1377 extern "C" jintArray Java_org_linphone_core_LinphoneCoreImpl_getPreferredVideoSize(JNIEnv *env, jobject thiz, jlong lc){
1378         MSVideoSize vsize = linphone_core_get_preferred_video_size((LinphoneCore *)lc);
1379     jintArray arr = env->NewIntArray(2);
1380         int tVsize [2]= {vsize.width,vsize.height};
1381     env->SetIntArrayRegion(arr, 0, 2, tVsize);
1382     return arr;
1383 }
1384
1385 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDownloadBandwidth(JNIEnv *env, jobject thiz, jlong lc, jint bw){
1386         linphone_core_set_download_bandwidth((LinphoneCore *)lc, (int) bw);
1387 }
1388
1389 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setUploadBandwidth(JNIEnv *env, jobject thiz, jlong lc, jint bw){
1390         linphone_core_set_upload_bandwidth((LinphoneCore *)lc, (int) bw);
1391 }
1392
1393 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDownloadPtime(JNIEnv *env, jobject thiz, jlong lc, jint ptime){
1394         linphone_core_set_download_ptime((LinphoneCore *)lc, (int) ptime);
1395 }
1396
1397 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setUploadPtime(JNIEnv *env, jobject thiz, jlong lc, jint ptime){
1398         linphone_core_set_upload_ptime((LinphoneCore *)lc, (int) ptime);
1399 }
1400
1401 extern "C" int Java_org_linphone_core_LinphoneProxyConfigImpl_getState(JNIEnv*  env,jobject thiz,jlong ptr) {
1402         return (int) linphone_proxy_config_get_state((const LinphoneProxyConfig *) ptr);
1403 }
1404 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setExpires(JNIEnv*  env,jobject thiz,jlong ptr,jint delay) {
1405         linphone_proxy_config_expires((LinphoneProxyConfig *) ptr, (int) delay);
1406 }
1407
1408 extern "C" jint Java_org_linphone_core_LinphoneCallImpl_getDuration(JNIEnv*  env,jobject thiz,jlong ptr) {
1409         linphone_call_get_duration((LinphoneCall *) ptr);
1410 }
1411
1412 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getSignalingTransportPort(JNIEnv* env,jobject thiz,jlong ptr, jint code) {
1413         LCSipTransports tr;
1414         linphone_core_get_sip_transports((LinphoneCore *) ptr, &tr);
1415                 switch (code) {
1416         case 0:
1417                 return tr.udp_port;
1418         case 1:
1419                 return tr.tcp_port;
1420         case 3:
1421                 return tr.tls_port;
1422         default:
1423                 return -2;
1424         }
1425 }
1426
1427 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setSignalingTransportPorts(JNIEnv*  env,jobject thiz,jlong ptr,jint udp, jint tcp, jint tls) {
1428         LinphoneCore *lc = (LinphoneCore *) ptr;
1429         LCSipTransports tr;
1430         tr.udp_port = udp;
1431         tr.tcp_port = tcp;
1432         tr.tls_port = tls;
1433
1434         linphone_core_set_sip_transports(lc, &tr); // tr will be copied
1435 }
1436
1437 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableIpv6(JNIEnv* env,jobject  thiz
1438               ,jlong lc, jboolean enable) {
1439               linphone_core_enable_ipv6((LinphoneCore*)lc,enable);
1440 }
1441
1442 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_adjustSoftwareVolume(JNIEnv* env,jobject  thiz
1443               ,jlong ptr, jint db) {
1444         linphone_core_set_playback_gain_db((LinphoneCore *) ptr, db);
1445 }
1446
1447 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_pauseCall(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall) {
1448         return linphone_core_pause_call((LinphoneCore *) pCore, (LinphoneCall *) pCall);
1449 }
1450 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_pauseAllCalls(JNIEnv *env,jobject thiz,jlong pCore) {
1451         return linphone_core_pause_all_calls((LinphoneCore *) pCore);
1452 }
1453 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_resumeCall(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall) {
1454         return linphone_core_resume_call((LinphoneCore *) pCore, (LinphoneCall *) pCall);
1455 }
1456 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isInConference(JNIEnv *env,jobject thiz,jlong pCore) {
1457         return linphone_core_is_in_conference((LinphoneCore *) pCore);
1458 }
1459 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_enterConference(JNIEnv *env,jobject thiz,jlong pCore) {
1460         return 0 == linphone_core_enter_conference((LinphoneCore *) pCore);
1461 }
1462 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_leaveConference(JNIEnv *env,jobject thiz,jlong pCore) {
1463         linphone_core_leave_conference((LinphoneCore *) pCore);
1464 }
1465 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addAllToConference(JNIEnv *env,jobject thiz,jlong pCore) {
1466         linphone_core_add_all_to_conference((LinphoneCore *) pCore);
1467 }
1468 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addToConference(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall) {
1469         linphone_core_add_to_conference((LinphoneCore *) pCore, (LinphoneCall *) pCall);
1470 }
1471 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_removeFromConference(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall) {
1472         linphone_core_remove_from_conference((LinphoneCore *) pCore, (LinphoneCall *) pCall);
1473 }
1474
1475 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_terminateConference(JNIEnv *env,jobject thiz,jlong pCore) {
1476         linphone_core_terminate_conference((LinphoneCore *) pCore);
1477 }
1478 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getConferenceSize(JNIEnv *env,jobject thiz,jlong pCore) {
1479         return linphone_core_get_conference_size((LinphoneCore *) pCore);
1480 }
1481 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_terminateAllCalls(JNIEnv *env,jobject thiz,jlong pCore) {
1482         linphone_core_terminate_all_calls((LinphoneCore *) pCore);
1483 }
1484 extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_getCall(JNIEnv *env,jobject thiz,jlong pCore,jint position) {
1485         LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)pCore);
1486         LinphoneCall* lCall = (LinphoneCall*) ms_list_nth_data(linphone_core_get_calls((LinphoneCore *) pCore),position);
1487         return lcd->getCall(env,lCall);
1488 }
1489 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getCallsNb(JNIEnv *env,jobject thiz,jlong pCore) {
1490         return ms_list_size(linphone_core_get_calls((LinphoneCore *) pCore));
1491 }
1492
1493 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_transferCall(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall, jstring jReferTo) {
1494         const char* cReferTo=env->GetStringUTFChars(jReferTo, NULL);
1495         linphone_core_transfer_call((LinphoneCore *) pCore, (LinphoneCall *) pCall, cReferTo);
1496         env->ReleaseStringUTFChars(jReferTo, cReferTo);
1497 }
1498 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_transferCallToAnother(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall, jlong pDestCall) {
1499         linphone_core_transfer_call_to_another((LinphoneCore *) pCore, (LinphoneCall *) pCall, (LinphoneCall *) pDestCall);
1500 }
1501
1502 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setZrtpSecretsCache(JNIEnv *env,jobject thiz,jlong pCore, jstring jFile) {
1503         if (jFile) {
1504                 const char* cFile=env->GetStringUTFChars(jFile, NULL);
1505                 linphone_core_set_zrtp_secrets_file((LinphoneCore *) pCore,cFile);
1506                 env->ReleaseStringUTFChars(jFile, cFile);
1507         } else {
1508                 linphone_core_set_zrtp_secrets_file((LinphoneCore *) pCore,NULL);
1509         }
1510 }
1511
1512 extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_findCallFromUri(JNIEnv *env,jobject thiz,jlong pCore, jstring jUri) {
1513         const char* cUri=env->GetStringUTFChars(jUri, NULL);
1514         LinphoneCall *call= (LinphoneCall *) linphone_core_find_call_from_uri((LinphoneCore *) pCore,cUri);
1515         env->ReleaseStringUTFChars(jUri, cUri);
1516         LinphoneCoreData *lcdata=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)pCore);
1517         return (jobject) lcdata->getCall(env,call);
1518 }
1519
1520
1521 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_setVideoDevice(JNIEnv *env,jobject thiz,jlong pCore,jint id) {
1522         LinphoneCore* lc = (LinphoneCore *) pCore;
1523         const char** devices = linphone_core_get_video_devices(lc);
1524         if (devices == NULL) {
1525                 ms_error("No existing video devices\n");
1526                 return -1;
1527         }
1528         int i;
1529         for(i=0; i<=id; i++) {
1530                 if (devices[i] == NULL)
1531                         break;
1532                 ms_message("Existing device %d : %s\n", i, devices[i]);
1533                 if (i==id) {
1534                         return linphone_core_set_video_device(lc, devices[i]);
1535                 }
1536         }
1537         return -1;
1538 }
1539
1540 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getVideoDevice(JNIEnv *env,jobject thiz,jlong pCore) {
1541         LinphoneCore* lc = (LinphoneCore *) pCore;
1542         const char** devices = linphone_core_get_video_devices(lc);
1543         if (devices == NULL) {
1544                 ms_error("No existing video devices\n");
1545                 return -1;
1546         }
1547         const char* cam = linphone_core_get_video_device(lc);
1548         if (cam == NULL) {
1549                 ms_error("No current video device\n");
1550         } else {
1551                 int i=0;
1552                 while(devices[i] != NULL) {
1553                         if (strcmp(devices[i], cam) == 0)
1554                                 return i;
1555                         i++;
1556                 }
1557         }
1558         ms_warning("Returning default (0) device\n");
1559         return 0;
1560 }
1561
1562 extern "C" jstring Java_org_linphone_core_LinphoneCallImpl_getAuthenticationToken(JNIEnv*  env,jobject thiz,jlong ptr) {
1563         LinphoneCall *call = (LinphoneCall *) ptr;
1564         const char* token = linphone_call_get_authentication_token(call);
1565         if (token == NULL) return NULL;
1566         return env->NewStringUTF(token);
1567 }
1568 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isAuthenticationTokenVerified(JNIEnv*  env,jobject thiz,jlong ptr) {
1569         LinphoneCall *call = (LinphoneCall *) ptr;
1570         return linphone_call_get_authentication_token_verified(call);
1571 }
1572 extern "C" void Java_org_linphone_core_LinphoneCallImpl_setAuthenticationTokenVerified(JNIEnv*  env,jobject thiz,jlong ptr,jboolean verified) {
1573         LinphoneCall *call = (LinphoneCall *) ptr;
1574         linphone_call_set_authentication_token_verified(call, verified);
1575 }
1576
1577
1578 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_soundResourcesLocked(JNIEnv* env,jobject thiz,jlong ptr){
1579         return linphone_core_sound_resources_locked((LinphoneCore *) ptr);
1580 }
1581
1582 // Needed by Galaxy S (can't switch to/from speaker while playing and still keep mic working)
1583 // Implemented directly in msandroid.cpp (sound filters for Android).
1584 extern "C" void msandroid_hack_speaker_state(bool speakerOn);
1585
1586 extern "C" void Java_org_linphone_LinphoneManager_hackSpeakerState(JNIEnv*  env,jobject thiz,jboolean speakerOn){
1587         msandroid_hack_speaker_state(speakerOn);
1588 }
1589 // End Galaxy S hack functions
1590
1591
1592 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getMaxCalls(JNIEnv *env,jobject thiz,jlong pCore) {
1593         return (jint) linphone_core_get_max_calls((LinphoneCore *) pCore);
1594 }
1595 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setMaxCalls(JNIEnv *env,jobject thiz,jlong pCore, jint max) {
1596         linphone_core_set_max_calls((LinphoneCore *) pCore, (int) max);
1597 }
1598
1599 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_tunnelAddServerAndMirror(JNIEnv *env,jobject thiz,jlong pCore,
1600                 jstring jHost, jint port, jint mirror, jint delay) {
1601 #ifdef TUNNEL_ENABLED
1602         LinphoneTunnel *tunnel=((LinphoneCore *) pCore)->tunnel; if (!tunnel) return;
1603         const char* cHost=env->GetStringUTFChars(jHost, NULL);
1604         linphone_tunnel_add_server_and_mirror(tunnel, cHost, port, mirror, delay);
1605         env->ReleaseStringUTFChars(jHost, cHost);
1606 #endif
1607 }
1608
1609 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_tunnelAutoDetect(JNIEnv *env,jobject thiz,jlong pCore) {
1610 #ifdef TUNNEL_ENABLED
1611         LinphoneTunnel *tunnel=((LinphoneCore *) pCore)->tunnel; if (!tunnel) return;
1612         linphone_tunnel_auto_detect(tunnel);
1613 #endif
1614 }
1615
1616 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_tunnelCleanServers(JNIEnv *env,jobject thiz,jlong pCore) {
1617 #ifdef TUNNEL_ENABLED
1618         LinphoneTunnel *tunnel=((LinphoneCore *) pCore)->tunnel; if (!tunnel) return;
1619         linphone_tunnel_clean_servers(tunnel);
1620 #endif
1621 }
1622
1623 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_tunnelEnable(JNIEnv *env,jobject thiz,jlong pCore, jboolean enable) {
1624 #ifdef TUNNEL_ENABLED
1625         LinphoneTunnel *tunnel=((LinphoneCore *) pCore)->tunnel; if (!tunnel) return;
1626         linphone_tunnel_enable(tunnel, enable);
1627 #endif
1628 }
1629
1630 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_tunnelEnableLogs(JNIEnv *env,jobject thiz,jlong pCore, jboolean enable) {
1631 #ifdef TUNNEL_ENABLED
1632         LinphoneTunnel *tunnel=((LinphoneCore *) pCore)->tunnel; if (!tunnel) return;
1633         linphone_tunnel_enable_logs(tunnel, enable);
1634 #endif
1635 }
1636
1637 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isTunnelAvailable(JNIEnv *env,jobject thiz){
1638         return linphone_core_tunnel_available();
1639 }