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