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