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