]> sjero.net Git - linphone/blob - coreapi/linphonecore_jni.cc
Added JNI getFrom to LinphoneChatMessage
[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/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                 if (chatMessageClass) 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->chatMessageClass,lcData->chatMessageCtrId,(jlong)msg));
406                 }
407         static void ecCalibrationStatus(LinphoneCore *lc, LinphoneEcCalibratorStatus status, int delay_ms, void *data) {
408                 JNIEnv *env = 0;
409                 jint result = jvm->AttachCurrentThread(&env,NULL);
410                 if (result != 0) {
411                         ms_error("cannot attach VM\n");
412                         return;
413                 }
414                 LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
415                 env->CallVoidMethod(lcData->listener
416                                                         ,lcData->ecCalibrationStatusId
417                                                         ,lcData->core
418                                                         ,env->CallStaticObjectMethod(lcData->ecCalibratorStatusClass,lcData->ecCalibratorStatusFromIntId,(jint)status)
419                                                         ,delay_ms
420                                                         ,data ? data : NULL);
421                 if (data != NULL &&status !=LinphoneEcCalibratorInProgress ) {
422                         //final state, releasing global ref
423                         env->DeleteGlobalRef((jobject)data);
424                 }
425
426         }
427
428
429 };
430 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_newLinphoneCore(JNIEnv*  env
431                 ,jobject  thiz
432                 ,jobject jlistener
433                 ,jstring juserConfig
434                 ,jstring jfactoryConfig
435                 ,jobject  juserdata){
436
437         const char* userConfig = juserConfig?env->GetStringUTFChars(juserConfig, NULL):NULL;
438         const char* factoryConfig = jfactoryConfig?env->GetStringUTFChars(jfactoryConfig, NULL):NULL;
439         LinphoneCoreData* ldata = new LinphoneCoreData(env,thiz,jlistener,juserdata);
440
441 #ifdef HAVE_ILBC
442         libmsilbc_init(); // requires an fpu
443 #endif
444 #ifdef HAVE_X264
445         libmsx264_init();
446 #endif
447 #ifdef HAVE_AMR
448         libmsamr_init();
449 #endif
450 #ifdef HAVE_SILK
451         libmssilk_init();
452 #endif
453 #ifdef HAVE_G729
454         libmsbcg729_init();
455 #endif
456         jlong nativePtr = (jlong)linphone_core_new(     &ldata->vTable
457                         ,userConfig
458                         ,factoryConfig
459                         ,ldata);
460         //clear auth info list
461         linphone_core_clear_all_auth_info((LinphoneCore*) nativePtr);
462         //clear existing proxy config
463         linphone_core_clear_proxy_config((LinphoneCore*) nativePtr);
464
465         if (userConfig) env->ReleaseStringUTFChars(juserConfig, userConfig);
466         if (factoryConfig) env->ReleaseStringUTFChars(jfactoryConfig, factoryConfig);
467         return nativePtr;
468 }
469 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_delete(JNIEnv*  env
470                 ,jobject  thiz
471                 ,jlong lc) {
472         LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc);
473         linphone_core_destroy((LinphoneCore*)lc);
474         delete lcData;
475 }
476
477 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_clearProxyConfigs(JNIEnv* env, jobject thiz,jlong lc) {
478         linphone_core_clear_proxy_config((LinphoneCore*)lc);
479 }
480
481 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDefaultProxyConfig(  JNIEnv*  env
482                 ,jobject  thiz
483                 ,jlong lc
484                 ,jlong pc) {
485         linphone_core_set_default_proxy((LinphoneCore*)lc,(LinphoneProxyConfig*)pc);
486 }
487 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getDefaultProxyConfig( JNIEnv*  env
488                 ,jobject  thiz
489                 ,jlong lc) {
490         LinphoneProxyConfig *config=0;
491         linphone_core_get_default_proxy((LinphoneCore*)lc,&config);
492         return (jlong)config;
493 }
494
495 extern "C" jlongArray Java_org_linphone_core_LinphoneCoreImpl_getProxyConfigList(JNIEnv* env, jobject thiz, jlong lc) {
496         const MSList* proxies = linphone_core_get_proxy_config_list((LinphoneCore*)lc);
497         int proxyCount = ms_list_size(proxies);
498         jlongArray jProxies = env->NewLongArray(proxyCount);
499         jlong *jInternalArray = env->GetLongArrayElements(jProxies, NULL);
500
501         for (int i = 0; i < proxyCount; i++ ) {
502                 jInternalArray[i] = (unsigned long) (proxies->data);
503                 proxies = proxies->next;
504         }
505
506         env->ReleaseLongArrayElements(jProxies, jInternalArray, 0);
507
508         return jProxies;
509 }
510
511 extern "C" int Java_org_linphone_core_LinphoneCoreImpl_addProxyConfig(  JNIEnv*  env
512                 ,jobject  thiz
513                 ,jobject jproxyCfg
514                 ,jlong lc
515                 ,jlong pc) {
516         LinphoneProxyConfig* proxy = (LinphoneProxyConfig*)pc;
517         linphone_proxy_config_set_user_data(proxy, env->NewGlobalRef(jproxyCfg));
518
519         return linphone_core_add_proxy_config((LinphoneCore*)lc,(LinphoneProxyConfig*)pc);
520 }
521
522 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_clearAuthInfos(JNIEnv* env, jobject thiz,jlong lc) {
523         linphone_core_clear_all_auth_info((LinphoneCore*)lc);
524 }
525
526 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_refreshRegisters(JNIEnv* env, jobject thiz,jlong lc) {
527         linphone_core_refresh_registers((LinphoneCore*)lc);
528 }
529
530 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addAuthInfo(    JNIEnv*  env
531                 ,jobject  thiz
532                 ,jlong lc
533                 ,jlong pc) {
534         linphone_core_add_auth_info((LinphoneCore*)lc,(LinphoneAuthInfo*)pc);
535 }
536 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_iterate(        JNIEnv*  env
537                 ,jobject  thiz
538                 ,jlong lc) {
539         linphone_core_iterate((LinphoneCore*)lc);
540 }
541 extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_invite(      JNIEnv*  env
542                 ,jobject  thiz
543                 ,jlong lc
544                 ,jstring juri) {
545         const char* uri = env->GetStringUTFChars(juri, NULL);
546         LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc);
547         LinphoneCall* lCall = linphone_core_invite((LinphoneCore*)lc,uri);
548         env->ReleaseStringUTFChars(juri, uri);
549         return lcd->getCall(env,lCall);
550 }
551 extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_inviteAddress(       JNIEnv*  env
552                 ,jobject  thiz
553                 ,jlong lc
554                 ,jlong to) {
555         LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc);
556         return lcd->getCall(env, linphone_core_invite_address((LinphoneCore*)lc,(LinphoneAddress*)to));
557 }
558
559 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_terminateCall(  JNIEnv*  env
560                 ,jobject  thiz
561                 ,jlong lc
562                 ,jlong call) {
563         linphone_core_terminate_call((LinphoneCore*)lc,(LinphoneCall*)call);
564 }
565
566 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getRemoteAddress(      JNIEnv*  env
567                 ,jobject  thiz
568                 ,jlong lc) {
569         return (jlong)linphone_core_get_current_call_remote_address((LinphoneCore*)lc);
570 }
571 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isInCall(   JNIEnv*  env
572                 ,jobject  thiz
573                 ,jlong lc) {
574
575         return linphone_core_in_call((LinphoneCore*)lc);
576 }
577 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isInComingInvitePending(    JNIEnv*  env
578                 ,jobject  thiz
579                 ,jlong lc) {
580
581         return linphone_core_inc_invite_pending((LinphoneCore*)lc);
582 }
583 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_acceptCall(     JNIEnv*  env
584                 ,jobject  thiz
585                 ,jlong lc
586                 ,jlong call) {
587
588         linphone_core_accept_call((LinphoneCore*)lc,(LinphoneCall*)call);
589 }
590
591 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_acceptCallWithParams(JNIEnv *env,
592                 jobject thiz,
593                 jlong lc,
594                 jlong call,
595                 jlong params){
596         linphone_core_accept_call_with_params((LinphoneCore*)lc,(LinphoneCall*)call, (LinphoneCallParams*)params);
597 }
598
599 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_acceptCallUpdate(JNIEnv *env,
600                 jobject thiz,
601                 jlong lc,
602                 jlong call,
603                 jlong params){
604         linphone_core_accept_call_update((LinphoneCore*)lc,(LinphoneCall*)call, (LinphoneCallParams*)params);
605 }
606
607 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_deferCallUpdate(JNIEnv *env,
608                 jobject thiz,
609                 jlong lc,
610                 jlong call){
611         linphone_core_defer_call_update((LinphoneCore*)lc,(LinphoneCall*)call);
612 }
613
614 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getCallLog(    JNIEnv*  env
615                 ,jobject  thiz
616                 ,jlong lc
617                 ,jint position) {
618                 return (jlong)ms_list_nth_data(linphone_core_get_call_logs((LinphoneCore*)lc),position);
619 }
620 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getNumberOfCallLogs(    JNIEnv*  env
621                 ,jobject  thiz
622                 ,jlong lc) {
623                 return ms_list_size(linphone_core_get_call_logs((LinphoneCore*)lc));
624 }
625 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setNetworkStateReachable(       JNIEnv*  env
626                 ,jobject  thiz
627                 ,jlong lc
628                 ,jboolean isReachable) {
629                 linphone_core_set_network_reachable((LinphoneCore*)lc,isReachable);
630 }
631
632 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isNetworkStateReachable(    JNIEnv*  env
633                 ,jobject  thiz
634                 ,jlong lc) {
635                 return linphone_core_is_network_reachable((LinphoneCore*)lc);
636 }
637
638 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPlaybackGain(        JNIEnv*  env
639                 ,jobject  thiz
640                 ,jlong lc
641                 ,jfloat gain) {
642                 linphone_core_set_playback_gain_db((LinphoneCore*)lc,gain);
643 }
644
645 extern "C" float Java_org_linphone_core_LinphoneCoreImpl_getPlaybackGain(       JNIEnv*  env
646                 ,jobject  thiz
647                 ,jlong lc) {
648                 return linphone_core_get_playback_gain_db((LinphoneCore*)lc);
649 }
650
651 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_muteMic(        JNIEnv*  env
652                 ,jobject  thiz
653                 ,jlong lc
654                 ,jboolean isMuted) {
655                 linphone_core_mute_mic((LinphoneCore*)lc,isMuted);
656 }
657
658 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_interpretUrl(  JNIEnv*  env
659                 ,jobject  thiz
660                 ,jlong lc
661                 ,jstring jurl) {
662         const char* url = env->GetStringUTFChars(jurl, NULL);
663         jlong result = (jlong)linphone_core_interpret_url((LinphoneCore*)lc,url);
664         env->ReleaseStringUTFChars(jurl, url);
665         return result;
666 }
667 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_sendDtmf(       JNIEnv*  env
668                 ,jobject  thiz
669                 ,jlong lc
670                 ,jchar dtmf) {
671         linphone_core_send_dtmf((LinphoneCore*)lc,dtmf);
672 }
673 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_playDtmf(       JNIEnv*  env
674                 ,jobject  thiz
675                 ,jlong lc
676                 ,jchar dtmf
677                 ,jint duration) {
678         linphone_core_play_dtmf((LinphoneCore*)lc,dtmf,duration);
679 }
680 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_stopDtmf(       JNIEnv*  env
681                 ,jobject  thiz
682                 ,jlong lc) {
683         linphone_core_stop_dtmf((LinphoneCore*)lc);
684 }
685
686 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_getMissedCallsCount(JNIEnv*  env
687                                                                                                                                                 ,jobject  thiz
688                                                                                                                                                 ,jlong lc) {
689         linphone_core_get_missed_calls_count((LinphoneCore*)lc);
690 }
691
692 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_resetMissedCallsCount(JNIEnv*  env
693                                                                                                                                                 ,jobject  thiz
694                                                                                                                                                 ,jlong lc) {
695         linphone_core_reset_missed_calls_count((LinphoneCore*)lc);
696 }
697
698 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_removeCallLog(JNIEnv*  env
699                                                                                                                                                 ,jobject  thiz
700                                                                                                                                                 ,jlong lc, jlong log) {
701         linphone_core_remove_call_log((LinphoneCore*)lc, (LinphoneCallLog*) log);
702 }
703
704 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_clearCallLogs(JNIEnv*  env
705                                                                                                                                                 ,jobject  thiz
706                                                                                                                                                 ,jlong lc) {
707         linphone_core_clear_call_logs((LinphoneCore*)lc);
708 }
709 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isMicMuted( JNIEnv*  env
710                 ,jobject  thiz
711                 ,jlong lc) {
712         return linphone_core_is_mic_muted((LinphoneCore*)lc);
713 }
714 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_findPayloadType(JNIEnv*  env
715                                                                                                                                                         ,jobject  thiz
716                                                                                                                                                         ,jlong lc
717                                                                                                                                                         ,jstring jmime
718                                                                                                                                                         ,jint rate
719                                                                                                                                                         ,jint channels) {
720         const char* mime = env->GetStringUTFChars(jmime, NULL);
721         jlong result = (jlong)linphone_core_find_payload_type((LinphoneCore*)lc,mime,rate,channels);
722         env->ReleaseStringUTFChars(jmime, mime);
723         return result;
724 }
725 extern "C" jlongArray Java_org_linphone_core_LinphoneCoreImpl_listVideoPayloadTypes(JNIEnv*  env
726                                                                                                                                                         ,jobject  thiz
727                                                                                                                                                         ,jlong lc) {
728         const MSList* codecs = linphone_core_get_video_codecs((LinphoneCore*)lc);
729         int codecsCount = ms_list_size(codecs);
730         jlongArray jCodecs = env->NewLongArray(codecsCount);
731         jlong *jInternalArray = env->GetLongArrayElements(jCodecs, NULL);
732
733         for (int i = 0; i < codecsCount; i++ ) {
734                 jInternalArray[i] = (unsigned long) (codecs->data);
735                 codecs = codecs->next;
736         }
737
738         env->ReleaseLongArrayElements(jCodecs, jInternalArray, 0);
739
740         return jCodecs;
741 }
742
743 extern "C" jlongArray Java_org_linphone_core_LinphoneCoreImpl_listAudioPayloadTypes(JNIEnv*  env
744                                                                                                                                                         ,jobject  thiz
745                                                                                                                                                         ,jlong lc) {
746         const MSList* codecs = linphone_core_get_audio_codecs((LinphoneCore*)lc);
747         int codecsCount = ms_list_size(codecs);
748         jlongArray jCodecs = env->NewLongArray(codecsCount);
749         jlong *jInternalArray = env->GetLongArrayElements(jCodecs, NULL);
750
751         for (int i = 0; i < codecsCount; i++ ) {
752                 jInternalArray[i] = (unsigned long) (codecs->data);
753                 codecs = codecs->next;
754         }
755
756         env->ReleaseLongArrayElements(jCodecs, jInternalArray, 0);
757
758         return jCodecs;
759 }
760
761 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_enablePayloadType(JNIEnv*  env
762                                                                                                                                                         ,jobject  thiz
763                                                                                                                                                         ,jlong lc
764                                                                                                                                                         ,jlong pt
765                                                                                                                                                         ,jboolean enable) {
766         return linphone_core_enable_payload_type((LinphoneCore*)lc,(PayloadType*)pt,enable);
767 }
768 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableEchoCancellation(JNIEnv*  env
769                                                                                                                                                         ,jobject  thiz
770                                                                                                                                                         ,jlong lc
771                                                                                                                                                         ,jboolean enable) {
772         linphone_core_enable_echo_cancellation((LinphoneCore*)lc,enable);
773 }
774 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableEchoLimiter(JNIEnv*  env
775                                                                                                                                                         ,jobject  thiz
776                                                                                                                                                         ,jlong lc
777                                                                                                                                                         ,jboolean enable) {
778         linphone_core_enable_echo_limiter((LinphoneCore*)lc,enable);
779 }
780 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isEchoCancellationEnabled(JNIEnv*  env
781                                                                                                                                                         ,jobject  thiz
782                                                                                                                                                         ,jlong lc
783                                                                                                                                                         ) {
784         return linphone_core_echo_cancellation_enabled((LinphoneCore*)lc);
785 }
786
787 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isEchoLimiterEnabled(JNIEnv*  env
788                                                                                                                                                         ,jobject  thiz
789                                                                                                                                                         ,jlong lc
790                                                                                                                                                         ) {
791         return linphone_core_echo_limiter_enabled((LinphoneCore*)lc);
792 }
793
794 extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_getCurrentCall(JNIEnv*  env
795                                                                                                                                                         ,jobject  thiz
796                                                                                                                                                         ,jlong lc
797                                                                                                                                                         ) {
798         LinphoneCoreData *lcdata=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc);
799         
800         return lcdata->getCall(env,linphone_core_get_current_call((LinphoneCore*)lc));
801 }
802 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addFriend(JNIEnv*  env
803                                                                                                                                                         ,jobject  thiz
804                                                                                                                                                         ,jlong lc
805                                                                                                                                                         ,jlong aFriend
806                                                                                                                                                         ) {
807         linphone_core_add_friend((LinphoneCore*)lc,(LinphoneFriend*)aFriend);
808 }
809 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPresenceInfo(JNIEnv*  env
810                                                                                                                                                         ,jobject  thiz
811                                                                                                                                                         ,jlong lc
812                                                                                                                                                         ,jint minute_away
813                                                                                                                                                         ,jstring jalternative_contact
814                                                                                                                                                         ,jint status) {
815         const char* alternative_contact = jalternative_contact?env->GetStringUTFChars(jalternative_contact, NULL):NULL;
816         linphone_core_set_presence_info((LinphoneCore*)lc,minute_away,alternative_contact,(LinphoneOnlineStatus)status);
817         if (alternative_contact) env->ReleaseStringUTFChars(jalternative_contact, alternative_contact);
818 }
819
820 extern "C" long Java_org_linphone_core_LinphoneCoreImpl_createChatRoom(JNIEnv*  env
821                                                                                                                                                         ,jobject  thiz
822                                                                                                                                                         ,jlong lc
823                                                                                                                                                         ,jstring jto) {
824
825         const char* to = env->GetStringUTFChars(jto, NULL);
826         LinphoneChatRoom* lResult = linphone_core_create_chat_room((LinphoneCore*)lc,to);
827         env->ReleaseStringUTFChars(jto, to);
828         return (long)lResult;
829 }
830
831 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableVideo(JNIEnv*  env
832                                                                                                                                                         ,jobject  thiz
833                                                                                                                                                         ,jlong lc
834                                                                                                                                                         ,jboolean vcap_enabled
835                                                                                                                                                         ,jboolean display_enabled) {
836         linphone_core_enable_video((LinphoneCore*)lc, vcap_enabled,display_enabled);
837
838 }
839 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isVideoEnabled(JNIEnv*  env
840                                                                                                                                                         ,jobject  thiz
841                                                                                                                                                         ,jlong lc) {
842         return linphone_core_video_enabled((LinphoneCore*)lc);
843 }
844 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPlayFile(JNIEnv*  env
845                                                                                                                                                         ,jobject  thiz
846                                                                                                                                                         ,jlong lc
847                                                                                                                                                         ,jstring jpath) {
848         const char* path = jpath?env->GetStringUTFChars(jpath, NULL):NULL;
849         linphone_core_set_play_file((LinphoneCore*)lc,path);
850         if (path) env->ReleaseStringUTFChars(jpath, path);
851 }
852 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setRing(JNIEnv*  env
853                                                                                                                                                         ,jobject  thiz
854                                                                                                                                                         ,jlong lc
855                                                                                                                                                         ,jstring jpath) {
856         const char* path = jpath?env->GetStringUTFChars(jpath, NULL):NULL;
857         linphone_core_set_ring((LinphoneCore*)lc,path);
858         if (path) env->ReleaseStringUTFChars(jpath, path);
859 }
860 extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getRing(JNIEnv*  env
861                                                                                                                                                         ,jobject  thiz
862                                                                                                                                                         ,jlong lc
863                                                                                                                                                         ) {
864         const char* path = linphone_core_get_ring((LinphoneCore*)lc);
865         if (path) {
866                 return env->NewStringUTF(path);
867         } else {
868                 return NULL;
869         }
870 }
871 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setRootCA(JNIEnv*  env
872                                                                                                                                                         ,jobject  thiz
873                                                                                                                                                         ,jlong lc
874                                                                                                                                                         ,jstring jpath) {
875         const char* path = jpath?env->GetStringUTFChars(jpath, NULL):NULL;
876         linphone_core_set_root_ca((LinphoneCore*)lc,path);
877         if (path) env->ReleaseStringUTFChars(jpath, path);
878 }
879 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableKeepAlive(JNIEnv*  env
880                                                                                                                                 ,jobject  thiz
881                                                                                                                                 ,jlong lc
882                                                                                                                                 ,jboolean enable) {
883         linphone_core_enable_keep_alive((LinphoneCore*)lc,enable);
884
885 }
886 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isKeepAliveEnabled(JNIEnv*  env
887                                                                                                                                 ,jobject  thiz
888                                                                                                                                 ,jlong lc) {
889         return linphone_core_keep_alive_enabled((LinphoneCore*)lc);
890
891 }
892 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_startEchoCalibration(JNIEnv*  env
893                                                                                                                                                                 ,jobject  thiz
894                                                                                                                                                                 ,jlong lc
895                                                                                                                                                                 ,jobject data) {
896         return linphone_core_start_echo_calibration((LinphoneCore*)lc
897                                                                                                         , LinphoneCoreData::ecCalibrationStatus
898                                                                                                         , data?env->NewGlobalRef(data):NULL);
899
900 }
901
902 extern "C" int Java_org_linphone_core_LinphoneCoreImpl_getMediaEncryption(JNIEnv*  env
903                                                                                                                                                         ,jobject  thiz
904                                                                                                                                                         ,jlong lc
905                                                                                                                                                         ) {
906         return (int)linphone_core_get_media_encryption((LinphoneCore*)lc);
907 }
908
909 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setMediaEncryption(JNIEnv*  env
910                                                                                                                                                         ,jobject  thiz
911                                                                                                                                                         ,jlong lc
912                                                                                                                                                         ,int menc) {
913         linphone_core_set_media_encryption((LinphoneCore*)lc,(LinphoneMediaEncryption)menc);
914 }
915
916 extern "C" int Java_org_linphone_core_LinphoneCallParamsImpl_getMediaEncryption(JNIEnv*  env
917                                                                                                                                                         ,jobject  thiz
918                                                                                                                                                         ,jlong cp
919                                                                                                                                                         ) {
920         return (int)linphone_call_params_get_media_encryption((LinphoneCallParams*)cp);
921 }
922
923 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_mediaEncryptionSupported(JNIEnv*  env
924                                                                                                                                                         ,jobject  thiz
925                                                                                                                                                         ,jlong lc, jint menc
926                                                                                                                                                         ) {
927         return linphone_core_media_encryption_supported((LinphoneCore*)lc,(LinphoneMediaEncryption)menc);
928 }
929
930 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_setMediaEncryption(JNIEnv*  env
931                                                                                                                                                         ,jobject  thiz
932                                                                                                                                                         ,jlong cp
933                                                                                                                                                         ,int jmenc) {
934         linphone_call_params_set_media_encryption((LinphoneCallParams*)cp,(LinphoneMediaEncryption)jmenc);
935 }
936
937 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_getMediaEncryptionMandatory(JNIEnv*  env
938                                                                                                                                                         ,jobject  thiz
939                                                                                                                                                         ,jlong lc
940                                                                                                                                                         ) {
941         return linphone_core_is_media_encryption_mandatory((LinphoneCore*)lc);
942 }
943
944 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setMediaEncryptionMandatory(JNIEnv*  env
945                                                                                                                                                         ,jobject  thiz
946                                                                                                                                                         ,jlong lc
947                                                                                                                                                         , jboolean yesno
948                                                                                                                                                         ) {
949         linphone_core_set_media_encryption_mandatory((LinphoneCore*)lc, yesno);
950 }
951
952 //ProxyConfig
953
954 extern "C" jlong Java_org_linphone_core_LinphoneProxyConfigImpl_newLinphoneProxyConfig(JNIEnv*  env,jobject  thiz) {
955         LinphoneProxyConfig* proxy = linphone_proxy_config_new();
956         return  (jlong) proxy;
957 }
958
959 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_delete(JNIEnv*  env,jobject  thiz,jlong ptr) {
960         linphone_proxy_config_destroy((LinphoneProxyConfig*)ptr);
961 }
962 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setIdentity(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jidentity) {
963         const char* identity = env->GetStringUTFChars(jidentity, NULL);
964         linphone_proxy_config_set_identity((LinphoneProxyConfig*)proxyCfg,identity);
965         env->ReleaseStringUTFChars(jidentity, identity);
966 }
967 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getIdentity(JNIEnv* env,jobject thiz,jlong proxyCfg) {
968         const char* identity = linphone_proxy_config_get_identity((LinphoneProxyConfig*)proxyCfg);
969         if (identity) {
970                 return env->NewStringUTF(identity);
971         } else {
972                 return NULL;
973         }
974 }
975 extern "C" int Java_org_linphone_core_LinphoneProxyConfigImpl_setProxy(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jproxy) {
976         const char* proxy = env->GetStringUTFChars(jproxy, NULL);
977         int err=linphone_proxy_config_set_server_addr((LinphoneProxyConfig*)proxyCfg,proxy);
978         env->ReleaseStringUTFChars(jproxy, proxy);
979         return err;
980 }
981 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getProxy(JNIEnv* env,jobject thiz,jlong proxyCfg) {
982         const char* proxy = linphone_proxy_config_get_addr((LinphoneProxyConfig*)proxyCfg);
983         if (proxy) {
984                 return env->NewStringUTF(proxy);
985         } else {
986                 return NULL;
987         }
988 }
989 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setContactParameters(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jparams) {
990         const char* params = env->GetStringUTFChars(jparams, NULL);
991         linphone_proxy_config_set_contact_parameters((LinphoneProxyConfig*)proxyCfg, params);
992         env->ReleaseStringUTFChars(jparams, params);
993 }
994 extern "C" int Java_org_linphone_core_LinphoneProxyConfigImpl_setRoute(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jroute) {
995         if (jroute != NULL) {
996                 const char* route = env->GetStringUTFChars(jroute, NULL);
997                 int err=linphone_proxy_config_set_route((LinphoneProxyConfig*)proxyCfg,route);
998                 env->ReleaseStringUTFChars(jroute, route);
999                 return err;
1000         } else {
1001                 return linphone_proxy_config_set_route((LinphoneProxyConfig*)proxyCfg,NULL);
1002         }
1003 }
1004 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getRoute(JNIEnv* env,jobject thiz,jlong proxyCfg) {
1005         const char* route = linphone_proxy_config_get_route((LinphoneProxyConfig*)proxyCfg);
1006         if (route) {
1007                 return env->NewStringUTF(route);
1008         } else {
1009                 return NULL;
1010         }
1011 }
1012
1013 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_enableRegister(JNIEnv* env,jobject thiz,jlong proxyCfg,jboolean enableRegister) {
1014         linphone_proxy_config_enable_register((LinphoneProxyConfig*)proxyCfg,enableRegister);
1015 }
1016 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_isRegistered(JNIEnv* env,jobject thiz,jlong proxyCfg) {
1017         return linphone_proxy_config_is_registered((LinphoneProxyConfig*)proxyCfg);
1018 }
1019 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_isRegisterEnabled(JNIEnv* env,jobject thiz,jlong proxyCfg) {
1020         return linphone_proxy_config_register_enabled((LinphoneProxyConfig*)proxyCfg);
1021 }
1022 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_edit(JNIEnv* env,jobject thiz,jlong proxyCfg) {
1023         linphone_proxy_config_edit((LinphoneProxyConfig*)proxyCfg);
1024 }
1025 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_done(JNIEnv* env,jobject thiz,jlong proxyCfg) {
1026         linphone_proxy_config_done((LinphoneProxyConfig*)proxyCfg);
1027 }
1028 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_normalizePhoneNumber(JNIEnv* env,jobject thiz,jlong proxyCfg,jstring jnumber) {
1029         if (jnumber == 0) {
1030                 ms_error("cannot normalized null number");
1031         }
1032         const char* number = env->GetStringUTFChars(jnumber, NULL);
1033         int len = env->GetStringLength(jnumber);
1034         if (len == 0) {
1035                 ms_warning("cannot normalize empty number");
1036                 return jnumber;
1037         }
1038         char targetBuff[2*len];// returned number can be greater than origin (specially in case of prefix insertion
1039         linphone_proxy_config_normalize_number((LinphoneProxyConfig*)proxyCfg,number,targetBuff,sizeof(targetBuff));
1040         jstring normalizedNumber = env->NewStringUTF(targetBuff);
1041         env->ReleaseStringUTFChars(jnumber, number);
1042         return normalizedNumber;
1043 }
1044 extern "C" jstring Java_org_linphone_core_LinphoneProxyConfigImpl_getDomain(JNIEnv* env
1045                                                                                                                                                         ,jobject thiz
1046                                                                                                                                                         ,jlong proxyCfg) {
1047         const char* domain = linphone_proxy_config_get_domain((LinphoneProxyConfig*)proxyCfg);
1048         if (domain) {
1049                 return env->NewStringUTF(domain);
1050         } else {
1051                 return NULL;
1052         }
1053 }
1054 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setDialEscapePlus(JNIEnv* env,jobject thiz,jlong proxyCfg,jboolean value) {
1055         linphone_proxy_config_set_dial_escape_plus((LinphoneProxyConfig*)proxyCfg,value);
1056 }
1057
1058 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setDialPrefix(JNIEnv* env
1059                                                                                                                                         ,jobject thiz
1060                                                                                                                                         ,jlong proxyCfg
1061                                                                                                                                         ,jstring jprefix) {
1062         const char* prefix = env->GetStringUTFChars(jprefix, NULL);
1063         linphone_proxy_config_set_dial_prefix((LinphoneProxyConfig*)proxyCfg,prefix);
1064         env->ReleaseStringUTFChars(jprefix, prefix);
1065 }
1066 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_enablePublish(JNIEnv* env
1067                                                                                                                                                                 ,jobject thiz
1068                                                                                                                                                                 ,jlong proxyCfg
1069                                                                                                                                                                 ,jboolean val) {
1070         linphone_proxy_config_enable_publish((LinphoneProxyConfig*)proxyCfg,val);
1071 }
1072 extern "C" jboolean Java_org_linphone_core_LinphoneProxyConfigImpl_publishEnabled(JNIEnv* env,jobject thiz,jlong proxyCfg) {
1073         return linphone_proxy_config_publish_enabled((LinphoneProxyConfig*)proxyCfg);
1074 }
1075
1076 //Auth Info
1077
1078 extern "C" jlong Java_org_linphone_core_LinphoneAuthInfoImpl_newLinphoneAuthInfo(JNIEnv* env
1079                 , jobject thiz
1080                 , jstring jusername
1081                 , jstring juserid
1082                 , jstring jpassword
1083                 , jstring jha1
1084                 , jstring jrealm) {
1085
1086         const char* username = env->GetStringUTFChars(jusername, NULL);
1087         const char* password = env->GetStringUTFChars(jpassword, NULL);
1088         jlong auth = (jlong)linphone_auth_info_new(username,NULL,password,NULL,NULL);
1089
1090         env->ReleaseStringUTFChars(jusername, username);
1091         env->ReleaseStringUTFChars(jpassword, password);
1092         return auth;
1093
1094 }
1095 extern "C" void Java_org_linphone_core_LinphoneAuthInfoImpl_delete(JNIEnv* env
1096                 , jobject thiz
1097                 , jlong ptr) {
1098         linphone_auth_info_destroy((LinphoneAuthInfo*)ptr);
1099 }
1100
1101 //LinphoneAddress
1102
1103 extern "C" jlong Java_org_linphone_core_LinphoneAddressImpl_newLinphoneAddressImpl(JNIEnv*  env
1104                                                                                                                                                                         ,jobject  thiz
1105                                                                                                                                                                         ,jstring juri
1106                                                                                                                                                                         ,jstring jdisplayName) {
1107         const char* uri = env->GetStringUTFChars(juri, NULL);
1108         LinphoneAddress* address = linphone_address_new(uri);
1109         if (jdisplayName && address) {
1110                 const char* displayName = env->GetStringUTFChars(jdisplayName, NULL);
1111                 linphone_address_set_display_name(address,displayName);
1112                 env->ReleaseStringUTFChars(jdisplayName, displayName);
1113         }
1114         env->ReleaseStringUTFChars(juri, uri);
1115
1116         return  (jlong) address;
1117 }
1118 extern "C" void Java_org_linphone_core_LinphoneAddressImpl_delete(JNIEnv*  env
1119                                                                                                                                                 ,jobject  thiz
1120                                                                                                                                                 ,jlong ptr) {
1121         linphone_address_destroy((LinphoneAddress*)ptr);
1122 }
1123
1124 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getDisplayName(JNIEnv*  env
1125                                                                                                                                                 ,jobject  thiz
1126                                                                                                                                                 ,jlong ptr) {
1127         const char* displayName = linphone_address_get_display_name((LinphoneAddress*)ptr);
1128         if (displayName) {
1129                 return env->NewStringUTF(displayName);
1130         } else {
1131                 return 0;
1132         }
1133 }
1134 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getUserName(JNIEnv*  env
1135                                                                                                                                                 ,jobject  thiz
1136                                                                                                                                                 ,jlong ptr) {
1137         const char* userName = linphone_address_get_username((LinphoneAddress*)ptr);
1138         if (userName) {
1139                 return env->NewStringUTF(userName);
1140         } else {
1141                 return 0;
1142         }
1143 }
1144 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_getDomain(JNIEnv*  env
1145                                                                                                                                                 ,jobject  thiz
1146                                                                                                                                                 ,jlong ptr) {
1147         const char* domain = linphone_address_get_domain((LinphoneAddress*)ptr);
1148         if (domain) {
1149                 return env->NewStringUTF(domain);
1150         } else {
1151                 return 0;
1152         }
1153 }
1154
1155 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_toString(JNIEnv*  env
1156                                                                                                                                                 ,jobject  thiz
1157                                                                                                                                                 ,jlong ptr) {
1158         char* uri = linphone_address_as_string((LinphoneAddress*)ptr);
1159         jstring juri =env->NewStringUTF(uri);
1160         ms_free(uri);
1161         return juri;
1162 }
1163 extern "C" jstring Java_org_linphone_core_LinphoneAddressImpl_toUri(JNIEnv*  env
1164                                                                                                                                                 ,jobject  thiz
1165                                                                                                                                                 ,jlong ptr) {
1166         char* uri = linphone_address_as_string_uri_only((LinphoneAddress*)ptr);
1167         jstring juri =env->NewStringUTF(uri);
1168         ms_free(uri);
1169         return juri;
1170 }
1171 extern "C" void Java_org_linphone_core_LinphoneAddressImpl_setDisplayName(JNIEnv*  env
1172                                                                                                                                                 ,jobject  thiz
1173                                                                                                                                                 ,jlong address
1174                                                                                                                                                 ,jstring jdisplayName) {
1175         const char* displayName = jdisplayName!= NULL?env->GetStringUTFChars(jdisplayName, NULL):NULL;
1176         linphone_address_set_display_name((LinphoneAddress*)address,displayName);
1177         if (displayName != NULL) env->ReleaseStringUTFChars(jdisplayName, displayName);
1178 }
1179
1180
1181 //CallLog
1182 extern "C" jlong Java_org_linphone_core_LinphoneCallLogImpl_getFrom(JNIEnv*  env
1183                                                                                                                                                 ,jobject  thiz
1184                                                                                                                                                 ,jlong ptr) {
1185         return (jlong)((LinphoneCallLog*)ptr)->from;
1186 }
1187 extern "C" int Java_org_linphone_core_LinphoneCallLogImpl_getStatus(JNIEnv*  env
1188                                                                                                                                                 ,jobject  thiz
1189                                                                                                                                                 ,jlong ptr) {
1190         return (jlong)((LinphoneCallLog*)ptr)->status;
1191 }
1192 extern "C" jlong Java_org_linphone_core_LinphoneCallLogImpl_getTo(JNIEnv*  env
1193                                                                                                                                                 ,jobject  thiz
1194                                                                                                                                                 ,jlong ptr) {
1195         return (jlong)((LinphoneCallLog*)ptr)->to;
1196 }
1197 extern "C" jboolean Java_org_linphone_core_LinphoneCallLogImpl_isIncoming(JNIEnv*  env
1198                                                                                                                                                 ,jobject  thiz
1199                                                                                                                                                 ,jlong ptr) {
1200         return ((LinphoneCallLog*)ptr)->dir==LinphoneCallIncoming?JNI_TRUE:JNI_FALSE;
1201 }
1202 extern "C" jstring Java_org_linphone_core_LinphoneCallLogImpl_getStartDate(JNIEnv*  env
1203                                                                                                                                                 ,jobject  thiz
1204                                                                                                                                                 ,jlong ptr) {
1205         jstring jvalue =env->NewStringUTF(((LinphoneCallLog*)ptr)->start_date);
1206         return jvalue;
1207 }
1208 extern "C" jint Java_org_linphone_core_LinphoneCallLogImpl_getCallDuration(JNIEnv*  env
1209                                                                                                                                                 ,jobject  thiz
1210                                                                                                                                                 ,jlong ptr) {
1211         return ((LinphoneCallLog*)ptr)->duration;
1212 }
1213
1214 /*payloadType*/
1215 extern "C" jstring Java_org_linphone_core_PayloadTypeImpl_toString(JNIEnv*  env,jobject  thiz,jlong ptr) {
1216         PayloadType* pt = (PayloadType*)ptr;
1217         char* value = ms_strdup_printf("[%s] clock [%i], bitrate [%i]"
1218                                                                         ,payload_type_get_mime(pt)
1219                                                                         ,payload_type_get_rate(pt)
1220                                                                         ,payload_type_get_bitrate(pt));
1221         jstring jvalue =env->NewStringUTF(value);
1222         ms_free(value);
1223         return jvalue;
1224 }
1225 extern "C" jstring Java_org_linphone_core_PayloadTypeImpl_getMime(JNIEnv*  env,jobject  thiz,jlong ptr) {
1226         PayloadType* pt = (PayloadType*)ptr;
1227         jstring jvalue =env->NewStringUTF(payload_type_get_mime(pt));
1228         return jvalue;
1229 }
1230 extern "C" jint Java_org_linphone_core_PayloadTypeImpl_getRate(JNIEnv*  env,jobject  thiz, jlong ptr) {
1231         PayloadType* pt = (PayloadType*)ptr;
1232         return payload_type_get_rate(pt);
1233 }
1234
1235 //LinphoneCall
1236 extern "C" void Java_org_linphone_core_LinphoneCallImpl_finalize(JNIEnv*  env
1237                                                                                                                                                 ,jobject  thiz
1238                                                                                                                                                 ,jlong ptr) {
1239         LinphoneCall *call=(LinphoneCall*)ptr;
1240         linphone_call_unref(call);
1241 }
1242
1243 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getCallLog(    JNIEnv*  env
1244                                                                                                                                                 ,jobject  thiz
1245                                                                                                                                                 ,jlong ptr) {
1246         return (jlong)linphone_call_get_call_log((LinphoneCall*)ptr);
1247 }
1248
1249 extern "C" void Java_org_linphone_core_LinphoneCallImpl_takeSnapshot(   JNIEnv*  env
1250                                                                                                                                                 ,jobject  thiz
1251                                                                                                                                                 ,jlong ptr, jstring path) {
1252         const char* filePath = path != NULL ? env->GetStringUTFChars(path, NULL) : NULL;
1253         linphone_call_take_video_snapshot((LinphoneCall*)ptr, filePath);
1254 }
1255
1256 extern "C" void Java_org_linphone_core_LinphoneCallImpl_zoomVideo(              JNIEnv*  env
1257                                                                                                                                                 ,jobject  thiz
1258                                                                                                                                                 ,jlong ptr, jfloat zoomFactor, jfloat cx, jfloat cy) {
1259         linphone_call_zoom_video((LinphoneCall*)ptr, zoomFactor, &cx, &cy);
1260 }
1261
1262 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isIncoming( JNIEnv*  env
1263                                                                                                                                                 ,jobject  thiz
1264                                                                                                                                                 ,jlong ptr) {
1265         return linphone_call_get_dir((LinphoneCall*)ptr)==LinphoneCallIncoming?JNI_TRUE:JNI_FALSE;
1266 }
1267
1268 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getRemoteAddress(      JNIEnv*  env
1269                                                                                                                                                 ,jobject  thiz
1270                                                                                                                                                 ,jlong ptr) {
1271         return (jlong)linphone_call_get_remote_address((LinphoneCall*)ptr);
1272 }
1273
1274 extern "C" jint Java_org_linphone_core_LinphoneCallImpl_getState(       JNIEnv*  env
1275                                                                                                                                                 ,jobject  thiz
1276                                                                                                                                                 ,jlong ptr) {
1277         return (jint)linphone_call_get_state((LinphoneCall*)ptr);
1278 }
1279 extern "C" void Java_org_linphone_core_LinphoneCallImpl_enableEchoCancellation( JNIEnv*  env
1280                                                                                                                                                 ,jobject  thiz
1281                                                                                                                                                 ,jlong ptr
1282                                                                                                                                                 ,jboolean value) {
1283         linphone_call_enable_echo_cancellation((LinphoneCall*)ptr,value);
1284 }
1285 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isEchoCancellationEnabled(  JNIEnv*  env
1286                                                                                                                                                 ,jobject  thiz
1287                                                                                                                                                 ,jlong ptr) {
1288         return linphone_call_echo_cancellation_enabled((LinphoneCall*)ptr);
1289 }
1290
1291 extern "C" void Java_org_linphone_core_LinphoneCallImpl_enableEchoLimiter(      JNIEnv*  env
1292                                                                                                                                                 ,jobject  thiz
1293                                                                                                                                                 ,jlong ptr
1294                                                                                                                                                 ,jboolean value) {
1295         linphone_call_enable_echo_limiter((LinphoneCall*)ptr,value);
1296 }
1297 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isEchoLimiterEnabled(       JNIEnv*  env
1298                                                                                                                                                 ,jobject  thiz
1299                                                                                                                                                 ,jlong ptr) {
1300         return linphone_call_echo_limiter_enabled((LinphoneCall*)ptr);
1301 }
1302
1303 extern "C" jobject Java_org_linphone_core_LinphoneCallImpl_getReplacedCall(     JNIEnv*  env
1304                                                                                                                                                 ,jobject  thiz
1305                                                                                                                                                 ,jlong ptr) {
1306         LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data(linphone_call_get_core((LinphoneCall*)ptr));       
1307         return lcd->getCall(env,linphone_call_get_replaced_call((LinphoneCall*)ptr));
1308 }
1309
1310 extern "C" jfloat Java_org_linphone_core_LinphoneCallImpl_getCurrentQuality(    JNIEnv*  env
1311                                                                                                                                                 ,jobject  thiz
1312                                                                                                                                                 ,jlong ptr) {
1313         return (jfloat)linphone_call_get_current_quality((LinphoneCall*)ptr);
1314 }
1315
1316 extern "C" jfloat Java_org_linphone_core_LinphoneCallImpl_getAverageQuality(    JNIEnv*  env
1317                                                                                                                                                 ,jobject  thiz
1318                                                                                                                                                 ,jlong ptr) {
1319         return (jfloat)linphone_call_get_average_quality((LinphoneCall*)ptr);
1320 }
1321
1322
1323 //LinphoneFriend
1324 extern "C" long Java_org_linphone_core_LinphoneFriendImpl_newLinphoneFriend(JNIEnv*  env
1325                                                                                                                                                 ,jobject  thiz
1326                                                                                                                                                 ,jstring jFriendUri) {
1327         LinphoneFriend* lResult;
1328
1329         if (jFriendUri) {
1330                 const char* friendUri = env->GetStringUTFChars(jFriendUri, NULL);
1331                 lResult= linphone_friend_new_with_addr(friendUri);
1332                 env->ReleaseStringUTFChars(jFriendUri, friendUri);
1333         } else {
1334                 lResult = linphone_friend_new();
1335         }
1336         return (long)lResult;
1337 }
1338 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_setAddress(JNIEnv*  env
1339                                                                                                                                                 ,jobject  thiz
1340                                                                                                                                                 ,jlong ptr
1341                                                                                                                                                 ,jlong linphoneAddress) {
1342         linphone_friend_set_addr((LinphoneFriend*)ptr,(LinphoneAddress*)linphoneAddress);
1343 }
1344 extern "C" long Java_org_linphone_core_LinphoneFriendImpl_getAddress(JNIEnv*  env
1345                                                                                                                                                 ,jobject  thiz
1346                                                                                                                                                 ,jlong ptr) {
1347         return (long)linphone_friend_get_address((LinphoneFriend*)ptr);
1348 }
1349 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_setIncSubscribePolicy(JNIEnv*  env
1350                                                                                                                                                 ,jobject  thiz
1351                                                                                                                                                 ,jlong ptr
1352                                                                                                                                                 ,jint policy) {
1353         linphone_friend_set_inc_subscribe_policy((LinphoneFriend*)ptr,(LinphoneSubscribePolicy)policy);
1354 }
1355 extern "C" jint Java_org_linphone_core_LinphoneFriendImpl_getIncSubscribePolicy(JNIEnv*  env
1356                                                                                                                                                 ,jobject  thiz
1357                                                                                                                                                 ,jlong ptr) {
1358         return linphone_friend_get_inc_subscribe_policy((LinphoneFriend*)ptr);
1359 }
1360 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_enableSubscribes(JNIEnv*  env
1361                                                                                                                                                 ,jobject  thiz
1362                                                                                                                                                 ,jlong ptr
1363                                                                                                                                                 ,jboolean value) {
1364         linphone_friend_enable_subscribes((LinphoneFriend*)ptr,value);
1365 }
1366 extern "C" jboolean Java_org_linphone_core_LinphoneFriendImpl_isSubscribesEnabled(JNIEnv*  env
1367                                                                                                                                                 ,jobject  thiz
1368                                                                                                                                                 ,jlong ptr) {
1369         return linphone_friend_subscribes_enabled((LinphoneFriend*)ptr);
1370 }
1371 extern "C" jboolean Java_org_linphone_core_LinphoneFriendImpl_getStatus(JNIEnv*  env
1372                                                                                                                                                 ,jobject  thiz
1373                                                                                                                                                 ,jlong ptr) {
1374         return linphone_friend_get_status((LinphoneFriend*)ptr);
1375 }
1376 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_edit(JNIEnv*  env
1377                                                                                                                                                 ,jobject  thiz
1378                                                                                                                                                 ,jlong ptr) {
1379         return linphone_friend_edit((LinphoneFriend*)ptr);
1380 }
1381 extern "C" void Java_org_linphone_core_LinphoneFriendImpl_done(JNIEnv*  env
1382                                                                                                                                                 ,jobject  thiz
1383                                                                                                                                                 ,jlong ptr) {
1384          linphone_friend_done((LinphoneFriend*)ptr);
1385 }
1386 //LinphoneChatRoom
1387 extern "C" long Java_org_linphone_core_LinphoneChatRoomImpl_getPeerAddress(JNIEnv*  env
1388                                                                                                                                                 ,jobject  thiz
1389                                                                                                                                                 ,jlong ptr) {
1390         return (long) linphone_chat_room_get_peer_address((LinphoneChatRoom*)ptr);
1391 }
1392 extern "C" jlong Java_org_linphone_core_LinphoneChatRoomImpl_createLinphoneChatMessage(JNIEnv*  env
1393                                                                                                                                                 ,jobject  thiz
1394                                                                                                                                                 ,jlong ptr
1395                                                                                                                                                 ,jstring jmessage) {
1396         const char* message = env->GetStringUTFChars(jmessage, NULL);
1397         LinphoneChatMessage *chatMessage = linphone_chat_room_create_message((LinphoneChatRoom *)ptr, message);
1398         env->ReleaseStringUTFChars(jmessage, message);
1399
1400         return (jlong) chatMessage;
1401 }
1402 extern "C" void Java_org_linphone_core_LinphoneChatMessageImpl_setUserData(JNIEnv*  env
1403                                                                                                                                                 ,jobject  thiz
1404                                                                                                                                                 ,jlong ptr) {
1405         jobject ud = env->NewGlobalRef(thiz);
1406         linphone_chat_message_set_user_data((LinphoneChatMessage*)ptr,(void*) ud);
1407 }
1408 extern "C" jstring Java_org_linphone_core_LinphoneChatMessageImpl_getMessage(JNIEnv*  env
1409                                                                                                                                                 ,jobject  thiz
1410                                                                                                                                                 ,jlong ptr) {
1411         jstring jvalue =env->NewStringUTF(linphone_chat_message_get_message((LinphoneChatMessage*)ptr));
1412         return jvalue;
1413 }
1414 extern "C" jstring Java_org_linphone_core_LinphoneChatMessageImpl_getExternalBodyUrl(JNIEnv*  env
1415                                                                                                                                                 ,jobject  thiz
1416                                                                                                                                                 ,jlong ptr) {
1417         jstring jvalue =env->NewStringUTF(linphone_chat_message_get_external_body_url((LinphoneChatMessage*)ptr));
1418         return jvalue;
1419 }
1420 extern "C" void Java_org_linphone_core_LinphoneChatMessageImpl_setExternalBodyUrl(JNIEnv*  env
1421                                                                                                                                                 ,jobject  thiz
1422                                                                                                                                                 ,jlong ptr
1423                                                                                                                                                 ,jstring jurl) {
1424         const char* url = env->GetStringUTFChars(jurl, NULL);
1425         linphone_chat_message_set_external_body_url((LinphoneChatMessage *)ptr, url);
1426         env->ReleaseStringUTFChars(jurl, url);
1427 }
1428 extern "C" jlong Java_org_linphone_core_LinphoneChatMessageImpl_getFrom(JNIEnv*  env
1429                                                                                                                                                 ,jobject  thiz
1430                                                                                                                                                 ,jlong ptr) {
1431         return (jlong) linphone_chat_message_get_from((LinphoneChatMessage*)ptr);
1432 }
1433 extern "C" jlong Java_org_linphone_core_LinphoneChatMessageImpl_getPeerAddress(JNIEnv*  env
1434                                                                                                                                                 ,jobject  thiz
1435                                                                                                                                                 ,jlong ptr) {
1436         return (jlong) linphone_chat_message_get_peer_address((LinphoneChatMessage*)ptr);
1437 }
1438 extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_sendMessage(JNIEnv*  env
1439                                                                                                                                                 ,jobject  thiz
1440                                                                                                                                                 ,jlong ptr
1441                                                                                                                                                 ,jstring jmessage) {
1442         const char* message = env->GetStringUTFChars(jmessage, NULL);
1443         linphone_chat_room_send_message((LinphoneChatRoom*)ptr, message);
1444         env->ReleaseStringUTFChars(jmessage, message);
1445 }
1446
1447 static void chat_room_impl_callback(LinphoneChatMessage* msg, LinphoneChatMessageState state, void* ud) {
1448         JNIEnv *env = 0;
1449         jint result = jvm->AttachCurrentThread(&env,NULL);
1450         if (result != 0) {
1451                 ms_error("cannot attach VM\n");
1452                 return;
1453         }
1454
1455         jobject listener = (jobject) ud;
1456         jclass clazz = (jclass) env->GetObjectClass(listener);
1457         jmethodID method = env->GetMethodID(clazz, "onLinphoneChatMessageStateChanged","(Lorg/linphone/core/LinphoneChatMessage;Lorg/linphone/core/LinphoneChatMessage$State;)V");
1458
1459         LinphoneCore *lc = linphone_chat_room_get_lc(linphone_chat_message_get_chat_room(msg));
1460         LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_get_user_data(lc);
1461         env->CallVoidMethod(
1462                         listener,
1463                         method,
1464                         (jobject)linphone_chat_message_get_user_data(msg),
1465                         env->CallStaticObjectMethod(lcData->chatMessageStateClass,lcData->chatMessageStateFromIntId,(jint)state));
1466
1467         if (state == LinphoneChatMessageStateDelivered || state == LinphoneChatMessageStateNotDelivered) {
1468                 env->DeleteGlobalRef(listener);
1469         }
1470 }
1471 extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_sendMessage2(JNIEnv*  env
1472                                                                                                                                                 ,jobject  thiz
1473                                                                                                                                                 ,jlong ptr
1474                                                                                                                                                 ,jlong jmessage
1475                                                                                                                                                 ,jobject jlistener) {
1476         jobject listener = env->NewGlobalRef(jlistener);
1477         linphone_chat_room_send_message2((LinphoneChatRoom*)ptr, (LinphoneChatMessage*)jmessage, chat_room_impl_callback, (void*)listener);
1478 }
1479 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setVideoWindowId(JNIEnv* env
1480                                                                                                                                                 ,jobject thiz
1481                                                                                                                                                 ,jlong lc
1482                                                                                                                                                 ,jobject obj) {
1483         jobject oldWindow = (jobject) linphone_core_get_native_video_window_id((LinphoneCore*)lc);
1484         if (oldWindow != NULL) {
1485                 env->DeleteGlobalRef(oldWindow);
1486         }
1487         if (obj != NULL) {
1488                 obj = env->NewGlobalRef(obj);
1489         }
1490         linphone_core_set_native_video_window_id((LinphoneCore*)lc,(unsigned long)obj);
1491 }
1492
1493 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPreviewWindowId(JNIEnv* env
1494                                                                                                                                                 ,jobject thiz
1495                                                                                                                                                 ,jlong lc
1496                                                                                                                                                 ,jobject obj) {
1497         jobject oldWindow = (jobject) linphone_core_get_native_preview_window_id((LinphoneCore*)lc);
1498         if (oldWindow != NULL) {
1499                 env->DeleteGlobalRef(oldWindow);
1500         }
1501         if (obj != NULL) {
1502                 obj = env->NewGlobalRef(obj);
1503         }
1504         linphone_core_set_native_preview_window_id((LinphoneCore*)lc,(unsigned long)obj);
1505 }
1506
1507 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDeviceRotation(JNIEnv* env
1508                                                                                                                                                 ,jobject thiz
1509                                                                                                                                                 ,jlong lc
1510                                                                                                                                                 ,jint rotation) {
1511         linphone_core_set_device_rotation((LinphoneCore*)lc,rotation);
1512 }
1513
1514
1515 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setFirewallPolicy(JNIEnv *env, jobject thiz, jlong lc, int enum_value){
1516         linphone_core_set_firewall_policy((LinphoneCore*)lc,(LinphoneFirewallPolicy)enum_value);
1517 }
1518
1519 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getFirewallPolicy(JNIEnv *env, jobject thiz, jlong lc){
1520         return linphone_core_get_firewall_policy((LinphoneCore*)lc);
1521 }
1522
1523 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setStunServer(JNIEnv *env, jobject thiz, jlong lc, jstring jserver){
1524         const char* server = NULL;
1525         if (jserver) server=env->GetStringUTFChars(jserver, NULL);
1526         linphone_core_set_stun_server((LinphoneCore*)lc,server);
1527         if (server) env->ReleaseStringUTFChars(jserver,server);
1528 }
1529
1530 extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getStunServer(JNIEnv *env, jobject thiz, jlong lc){
1531         const char *ret= linphone_core_get_stun_server((LinphoneCore*)lc);
1532         if (ret==NULL) return NULL;
1533         jstring jvalue =env->NewStringUTF(ret);
1534         return jvalue;
1535 }
1536
1537 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_audioBandwidth(JNIEnv *env, jobject thiz, jlong lcp, jint bw){
1538         linphone_call_params_set_audio_bandwidth_limit((LinphoneCallParams*)lcp, bw);
1539 }
1540
1541 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_enableVideo(JNIEnv *env, jobject thiz, jlong lcp, jboolean b){
1542         linphone_call_params_enable_video((LinphoneCallParams*)lcp, b);
1543 }
1544
1545 extern "C" jboolean Java_org_linphone_core_LinphoneCallParamsImpl_getVideoEnabled(JNIEnv *env, jobject thiz, jlong lcp){
1546         return linphone_call_params_video_enabled((LinphoneCallParams*)lcp);
1547 }
1548
1549 extern "C" jboolean Java_org_linphone_core_LinphoneCallParamsImpl_localConferenceMode(JNIEnv *env, jobject thiz, jlong lcp){
1550         return linphone_call_params_local_conference_mode((LinphoneCallParams*)lcp);
1551 }
1552
1553 extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_destroy(JNIEnv *env, jobject thiz, jlong lc){
1554         return linphone_call_params_destroy((LinphoneCallParams*)lc);
1555 }
1556 extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_createDefaultCallParams(JNIEnv *env, jobject thiz, jlong lc){
1557         return (jlong) linphone_core_create_default_call_parameters((LinphoneCore*)lc);
1558 }
1559
1560 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getRemoteParams(JNIEnv *env, jobject thiz, jlong lc){
1561         return (jlong) linphone_call_params_copy(linphone_call_get_remote_params((LinphoneCall*)lc));
1562 }
1563
1564 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getCurrentParamsCopy(JNIEnv *env, jobject thiz, jlong lc){
1565         return (jlong) linphone_call_params_copy(linphone_call_get_current_params((LinphoneCall*)lc));
1566 }
1567
1568 extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_enableCamera(JNIEnv *env, jobject thiz, jlong lc, jboolean b){
1569         linphone_call_enable_camera((LinphoneCall *)lc, (bool_t) b);
1570 }
1571
1572 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_cameraEnabled(JNIEnv *env, jobject thiz, jlong lc){
1573         linphone_call_camera_enabled((LinphoneCall *)lc);
1574 }
1575
1576 extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_inviteAddressWithParams(JNIEnv *env, jobject thiz, jlong lc, jlong addr, jlong params){
1577         LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)lc);
1578         return  lcd->getCall(env,linphone_core_invite_address_with_params((LinphoneCore *)lc, (const LinphoneAddress *)addr, (const LinphoneCallParams *)params));
1579 }
1580
1581 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_updateAddressWithParams(JNIEnv *env, jobject thiz, jlong lc, jlong call, jlong params){
1582         return (jint) linphone_core_update_call((LinphoneCore *)lc, (LinphoneCall *)call, (LinphoneCallParams *)params);
1583 }
1584
1585 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_updateCall(JNIEnv *env, jobject thiz, jlong lc, jlong call, jlong params){
1586         return (jint) linphone_core_update_call((LinphoneCore *)lc, (LinphoneCall *)call, (const LinphoneCallParams *)params);
1587 }
1588
1589
1590 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setPreferredVideoSize(JNIEnv *env, jobject thiz, jlong lc, jint width, jint height){
1591         MSVideoSize vsize;
1592         vsize.width = (int)width;
1593         vsize.height = (int)height;
1594         linphone_core_set_preferred_video_size((LinphoneCore *)lc, vsize);
1595 }
1596
1597 extern "C" jintArray Java_org_linphone_core_LinphoneCoreImpl_getPreferredVideoSize(JNIEnv *env, jobject thiz, jlong lc){
1598         MSVideoSize vsize = linphone_core_get_preferred_video_size((LinphoneCore *)lc);
1599     jintArray arr = env->NewIntArray(2);
1600         int tVsize [2]= {vsize.width,vsize.height};
1601     env->SetIntArrayRegion(arr, 0, 2, tVsize);
1602     return arr;
1603 }
1604
1605 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDownloadBandwidth(JNIEnv *env, jobject thiz, jlong lc, jint bw){
1606         linphone_core_set_download_bandwidth((LinphoneCore *)lc, (int) bw);
1607 }
1608
1609 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setUploadBandwidth(JNIEnv *env, jobject thiz, jlong lc, jint bw){
1610         linphone_core_set_upload_bandwidth((LinphoneCore *)lc, (int) bw);
1611 }
1612
1613 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setDownloadPtime(JNIEnv *env, jobject thiz, jlong lc, jint ptime){
1614         linphone_core_set_download_ptime((LinphoneCore *)lc, (int) ptime);
1615 }
1616
1617 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setUploadPtime(JNIEnv *env, jobject thiz, jlong lc, jint ptime){
1618         linphone_core_set_upload_ptime((LinphoneCore *)lc, (int) ptime);
1619 }
1620
1621 extern "C" int Java_org_linphone_core_LinphoneProxyConfigImpl_getState(JNIEnv*  env,jobject thiz,jlong ptr) {
1622         return (int) linphone_proxy_config_get_state((const LinphoneProxyConfig *) ptr);
1623 }
1624 extern "C" void Java_org_linphone_core_LinphoneProxyConfigImpl_setExpires(JNIEnv*  env,jobject thiz,jlong ptr,jint delay) {
1625         linphone_proxy_config_expires((LinphoneProxyConfig *) ptr, (int) delay);
1626 }
1627
1628 extern "C" jint Java_org_linphone_core_LinphoneCallImpl_getDuration(JNIEnv*  env,jobject thiz,jlong ptr) {
1629         linphone_call_get_duration((LinphoneCall *) ptr);
1630 }
1631
1632 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getSignalingTransportPort(JNIEnv* env,jobject thiz,jlong ptr, jint code) {
1633         LCSipTransports tr;
1634         linphone_core_get_sip_transports((LinphoneCore *) ptr, &tr);
1635                 switch (code) {
1636         case 0:
1637                 return tr.udp_port;
1638         case 1:
1639                 return tr.tcp_port;
1640         case 3:
1641                 return tr.tls_port;
1642         default:
1643                 return -2;
1644         }
1645 }
1646
1647 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setSignalingTransportPorts(JNIEnv*  env,jobject thiz,jlong ptr,jint udp, jint tcp, jint tls) {
1648         LinphoneCore *lc = (LinphoneCore *) ptr;
1649         LCSipTransports tr;
1650         tr.udp_port = udp;
1651         tr.tcp_port = tcp;
1652         tr.tls_port = tls;
1653
1654         linphone_core_set_sip_transports(lc, &tr); // tr will be copied
1655 }
1656
1657 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableIpv6(JNIEnv* env,jobject  thiz
1658               ,jlong lc, jboolean enable) {
1659               linphone_core_enable_ipv6((LinphoneCore*)lc,enable);
1660 }
1661
1662 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_adjustSoftwareVolume(JNIEnv* env,jobject  thiz
1663               ,jlong ptr, jint db) {
1664         linphone_core_set_playback_gain_db((LinphoneCore *) ptr, db);
1665 }
1666
1667 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_pauseCall(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall) {
1668         return linphone_core_pause_call((LinphoneCore *) pCore, (LinphoneCall *) pCall);
1669 }
1670 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_pauseAllCalls(JNIEnv *env,jobject thiz,jlong pCore) {
1671         return linphone_core_pause_all_calls((LinphoneCore *) pCore);
1672 }
1673 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_resumeCall(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall) {
1674         return linphone_core_resume_call((LinphoneCore *) pCore, (LinphoneCall *) pCall);
1675 }
1676 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isInConference(JNIEnv *env,jobject thiz,jlong pCore) {
1677         return linphone_core_is_in_conference((LinphoneCore *) pCore);
1678 }
1679 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_enterConference(JNIEnv *env,jobject thiz,jlong pCore) {
1680         return 0 == linphone_core_enter_conference((LinphoneCore *) pCore);
1681 }
1682 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_leaveConference(JNIEnv *env,jobject thiz,jlong pCore) {
1683         linphone_core_leave_conference((LinphoneCore *) pCore);
1684 }
1685 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addAllToConference(JNIEnv *env,jobject thiz,jlong pCore) {
1686         linphone_core_add_all_to_conference((LinphoneCore *) pCore);
1687 }
1688 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_addToConference(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall) {
1689         linphone_core_add_to_conference((LinphoneCore *) pCore, (LinphoneCall *) pCall);
1690 }
1691 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_removeFromConference(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall) {
1692         linphone_core_remove_from_conference((LinphoneCore *) pCore, (LinphoneCall *) pCall);
1693 }
1694
1695 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_terminateConference(JNIEnv *env,jobject thiz,jlong pCore) {
1696         linphone_core_terminate_conference((LinphoneCore *) pCore);
1697 }
1698 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getConferenceSize(JNIEnv *env,jobject thiz,jlong pCore) {
1699         return linphone_core_get_conference_size((LinphoneCore *) pCore);
1700 }
1701 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_terminateAllCalls(JNIEnv *env,jobject thiz,jlong pCore) {
1702         linphone_core_terminate_all_calls((LinphoneCore *) pCore);
1703 }
1704 extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_getCall(JNIEnv *env,jobject thiz,jlong pCore,jint position) {
1705         LinphoneCoreData *lcd=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)pCore);
1706         LinphoneCall* lCall = (LinphoneCall*) ms_list_nth_data(linphone_core_get_calls((LinphoneCore *) pCore),position);
1707         return lcd->getCall(env,lCall);
1708 }
1709 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getCallsNb(JNIEnv *env,jobject thiz,jlong pCore) {
1710         return ms_list_size(linphone_core_get_calls((LinphoneCore *) pCore));
1711 }
1712
1713 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_transferCall(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall, jstring jReferTo) {
1714         const char* cReferTo=env->GetStringUTFChars(jReferTo, NULL);
1715         linphone_core_transfer_call((LinphoneCore *) pCore, (LinphoneCall *) pCall, cReferTo);
1716         env->ReleaseStringUTFChars(jReferTo, cReferTo);
1717 }
1718 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_transferCallToAnother(JNIEnv *env,jobject thiz,jlong pCore, jlong pCall, jlong pDestCall) {
1719         linphone_core_transfer_call_to_another((LinphoneCore *) pCore, (LinphoneCall *) pCall, (LinphoneCall *) pDestCall);
1720 }
1721
1722 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setZrtpSecretsCache(JNIEnv *env,jobject thiz,jlong pCore, jstring jFile) {
1723         if (jFile) {
1724                 const char* cFile=env->GetStringUTFChars(jFile, NULL);
1725                 linphone_core_set_zrtp_secrets_file((LinphoneCore *) pCore,cFile);
1726                 env->ReleaseStringUTFChars(jFile, cFile);
1727         } else {
1728                 linphone_core_set_zrtp_secrets_file((LinphoneCore *) pCore,NULL);
1729         }
1730 }
1731
1732 extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_findCallFromUri(JNIEnv *env,jobject thiz,jlong pCore, jstring jUri) {
1733         const char* cUri=env->GetStringUTFChars(jUri, NULL);
1734         LinphoneCall *call= (LinphoneCall *) linphone_core_find_call_from_uri((LinphoneCore *) pCore,cUri);
1735         env->ReleaseStringUTFChars(jUri, cUri);
1736         LinphoneCoreData *lcdata=(LinphoneCoreData*)linphone_core_get_user_data((LinphoneCore*)pCore);
1737         return (jobject) lcdata->getCall(env,call);
1738 }
1739
1740
1741 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_setVideoDevice(JNIEnv *env,jobject thiz,jlong pCore,jint id) {
1742         LinphoneCore* lc = (LinphoneCore *) pCore;
1743         const char** devices = linphone_core_get_video_devices(lc);
1744         if (devices == NULL) {
1745                 ms_error("No existing video devices\n");
1746                 return -1;
1747         }
1748         int i;
1749         for(i=0; i<=id; i++) {
1750                 if (devices[i] == NULL)
1751                         break;
1752                 ms_message("Existing device %d : %s\n", i, devices[i]);
1753                 if (i==id) {
1754                         return linphone_core_set_video_device(lc, devices[i]);
1755                 }
1756         }
1757         return -1;
1758 }
1759
1760 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getVideoDevice(JNIEnv *env,jobject thiz,jlong pCore) {
1761         LinphoneCore* lc = (LinphoneCore *) pCore;
1762         const char** devices = linphone_core_get_video_devices(lc);
1763         if (devices == NULL) {
1764                 ms_error("No existing video devices\n");
1765                 return -1;
1766         }
1767         const char* cam = linphone_core_get_video_device(lc);
1768         if (cam == NULL) {
1769                 ms_error("No current video device\n");
1770         } else {
1771                 int i=0;
1772                 while(devices[i] != NULL) {
1773                         if (strcmp(devices[i], cam) == 0)
1774                                 return i;
1775                         i++;
1776                 }
1777         }
1778         ms_warning("Returning default (0) device\n");
1779         return 0;
1780 }
1781
1782 extern "C" jstring Java_org_linphone_core_LinphoneCallImpl_getAuthenticationToken(JNIEnv*  env,jobject thiz,jlong ptr) {
1783         LinphoneCall *call = (LinphoneCall *) ptr;
1784         const char* token = linphone_call_get_authentication_token(call);
1785         if (token == NULL) return NULL;
1786         return env->NewStringUTF(token);
1787 }
1788 extern "C" jboolean Java_org_linphone_core_LinphoneCallImpl_isAuthenticationTokenVerified(JNIEnv*  env,jobject thiz,jlong ptr) {
1789         LinphoneCall *call = (LinphoneCall *) ptr;
1790         return linphone_call_get_authentication_token_verified(call);
1791 }
1792 extern "C" void Java_org_linphone_core_LinphoneCallImpl_setAuthenticationTokenVerified(JNIEnv*  env,jobject thiz,jlong ptr,jboolean verified) {
1793         LinphoneCall *call = (LinphoneCall *) ptr;
1794         linphone_call_set_authentication_token_verified(call, verified);
1795 }
1796
1797 extern "C" jfloat Java_org_linphone_core_LinphoneCallImpl_getPlayVolume(JNIEnv* env, jobject thiz, jlong ptr) {
1798         LinphoneCall *call = (LinphoneCall *) ptr;
1799         return linphone_call_get_play_volume(call);
1800 }
1801
1802 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_soundResourcesLocked(JNIEnv* env,jobject thiz,jlong ptr){
1803         return linphone_core_sound_resources_locked((LinphoneCore *) ptr);
1804 }
1805
1806 // Needed by Galaxy S (can't switch to/from speaker while playing and still keep mic working)
1807 // Implemented directly in msandroid.cpp (sound filters for Android).
1808 extern "C" void msandroid_hack_speaker_state(bool speakerOn);
1809
1810 extern "C" void Java_org_linphone_LinphoneManager_hackSpeakerState(JNIEnv*  env,jobject thiz,jboolean speakerOn){
1811         msandroid_hack_speaker_state(speakerOn);
1812 }
1813 // End Galaxy S hack functions
1814
1815
1816 extern "C" jint Java_org_linphone_core_LinphoneCoreImpl_getMaxCalls(JNIEnv *env,jobject thiz,jlong pCore) {
1817         return (jint) linphone_core_get_max_calls((LinphoneCore *) pCore);
1818 }
1819 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setMaxCalls(JNIEnv *env,jobject thiz,jlong pCore, jint max) {
1820         linphone_core_set_max_calls((LinphoneCore *) pCore, (int) max);
1821 }
1822
1823 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_tunnelAddServerAndMirror(JNIEnv *env,jobject thiz,jlong pCore,
1824                 jstring jHost, jint port, jint mirror, jint delay) {
1825         LinphoneTunnel *tunnel=((LinphoneCore *) pCore)->tunnel;
1826         if (!tunnel) return;
1827         const char* cHost=env->GetStringUTFChars(jHost, NULL);
1828         linphone_tunnel_add_server_and_mirror(tunnel, cHost, port, mirror, delay);
1829         env->ReleaseStringUTFChars(jHost, cHost);
1830 }
1831
1832 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_tunnelSetHttpProxy(JNIEnv *env,jobject thiz,jlong pCore,
1833                 jstring jHost, jint port, jstring username, jstring password) {
1834
1835         LinphoneTunnel *tunnel=((LinphoneCore *) pCore)->tunnel;
1836         if (!tunnel) return;
1837         const char* cHost=(jHost!=NULL) ? env->GetStringUTFChars(jHost, NULL) : NULL;
1838         const char* cUsername= (username!=NULL) ? env->GetStringUTFChars(username, NULL) : NULL;
1839         const char* cPassword= (password!=NULL) ? env->GetStringUTFChars(password, NULL) : NULL;
1840         linphone_tunnel_set_http_proxy(tunnel,cHost, port,cUsername,cPassword);
1841         if (cHost) env->ReleaseStringUTFChars(jHost, cHost);
1842         if (cUsername) env->ReleaseStringUTFChars(username, cUsername);
1843         if (cPassword) env->ReleaseStringUTFChars(password, cPassword);
1844 }
1845
1846
1847 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_tunnelAutoDetect(JNIEnv *env,jobject thiz,jlong pCore) {
1848         LinphoneTunnel *tunnel=((LinphoneCore *) pCore)->tunnel; if (!tunnel) return;
1849         linphone_tunnel_auto_detect(tunnel);
1850
1851 }
1852
1853 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_tunnelCleanServers(JNIEnv *env,jobject thiz,jlong pCore) {
1854         LinphoneTunnel *tunnel=((LinphoneCore *) pCore)->tunnel; if (!tunnel) return;
1855         linphone_tunnel_clean_servers(tunnel);
1856 }
1857
1858 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_tunnelEnable(JNIEnv *env,jobject thiz,jlong pCore, jboolean enable) {
1859         LinphoneTunnel *tunnel=((LinphoneCore *) pCore)->tunnel; if (!tunnel) return;
1860         linphone_tunnel_enable(tunnel, enable);
1861 }
1862
1863
1864 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setUserAgent(JNIEnv *env,jobject thiz,jlong pCore, jstring name, jstring version){
1865         const char* cname=env->GetStringUTFChars(name, NULL);
1866         const char* cversion=env->GetStringUTFChars(version, NULL);
1867         linphone_core_set_user_agent(cname,cversion);
1868         env->ReleaseStringUTFChars(name, cname);
1869         env->ReleaseStringUTFChars(version, cversion);
1870 }
1871
1872 extern "C" jboolean Java_org_linphone_core_LinphoneCoreImpl_isTunnelAvailable(JNIEnv *env,jobject thiz){
1873         return linphone_core_tunnel_available();
1874 }
1875
1876 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setVideoPolicy(JNIEnv *env, jobject thiz, jlong lc, jboolean autoInitiate, jboolean autoAccept){
1877         LinphoneVideoPolicy vpol;
1878         vpol.automatically_initiate = autoInitiate;
1879         vpol.automatically_accept = autoAccept;
1880         linphone_core_set_video_policy((LinphoneCore *)lc, &vpol);
1881 }
1882
1883 extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setCpuCountNative(JNIEnv *env, jobject thiz, jint count) {
1884         ms_set_cpu_count(count);
1885 }
1886
1887 extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getVersion(JNIEnv*  env,jobject  thiz,jlong ptr) {
1888         jstring jvalue =env->NewStringUTF(linphone_core_get_version());
1889         return jvalue;
1890 }