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