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