diff --git a/build/android/Android.mk b/build/android/Android.mk index 96fe57e16..b0d51fc32 100755 --- a/build/android/Android.mk +++ b/build/android/Android.mk @@ -53,6 +53,7 @@ LOCAL_SRC_FILES := \ enum.c \ event.c \ friend.c \ + friendlist.c \ info.c \ linphonecall.c \ linphonecore.c \ diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index c58e1b48c..cd0324bb1 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -3341,17 +3341,25 @@ extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_markAsRead(JNIEnv* extern "C" jlong Java_org_linphone_core_LinphoneChatRoomImpl_createFileTransferMessage(JNIEnv* env, jobject thiz, jlong ptr, jstring jname, jstring jtype, jstring jsubtype, jint data_size) { - LinphoneContentPrivate content = {0}; + LinphoneCore *lc = linphone_chat_room_get_core((LinphoneChatRoom*) ptr); + LinphoneContent * content = linphone_core_create_content(lc); LinphoneChatMessage *message = NULL; + const char *tmp; - content.type = (char*)env->GetStringUTFChars(jtype, NULL); - content.subtype = (char*)env->GetStringUTFChars(jsubtype, NULL); - content.name = (char*)env->GetStringUTFChars(jname, NULL); - content.size = data_size; - message = linphone_chat_room_create_file_transfer_message((LinphoneChatRoom *)ptr, LINPHONE_CONTENT(&content)); - env->ReleaseStringUTFChars(jtype, content.type); - env->ReleaseStringUTFChars(jsubtype, content.subtype); - env->ReleaseStringUTFChars(jname, content.name); + linphone_content_set_type(content, tmp = env->GetStringUTFChars(jtype, NULL)); + env->ReleaseStringUTFChars(jtype, tmp); + + linphone_content_set_subtype(content, tmp = env->GetStringUTFChars(jsubtype, NULL)); + env->ReleaseStringUTFChars(jsubtype, tmp); + + linphone_content_set_name(content, tmp = env->GetStringUTFChars(jname, NULL)); + env->ReleaseStringUTFChars(jname, tmp); + + linphone_content_set_size(content, data_size); + + message = linphone_chat_room_create_file_transfer_message((LinphoneChatRoom *)ptr, content); + + linphone_content_unref(content); return (jlong) message; } @@ -4727,6 +4735,34 @@ extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getUpnpExternalIpaddr return jvalue; } +static LinphoneContent *create_content_from_java_args(JNIEnv *env, LinphoneCore *lc, jstring jtype, jstring jsubtype, jbyteArray jdata, jstring jencoding, jstring jname){ + LinphoneContent *content = NULL; + if (jtype){ + content = linphone_core_create_content(lc); + void *data = (void*)env->GetByteArrayElements(jdata,NULL); + const char *tmp; + + linphone_content_set_type(content, tmp = env->GetStringUTFChars(jtype, NULL)); + env->ReleaseStringUTFChars(jtype, tmp); + + linphone_content_set_subtype(content, tmp = env->GetStringUTFChars(jsubtype, NULL)); + env->ReleaseStringUTFChars(jsubtype, tmp); + + if (jname){ + linphone_content_set_name(content, tmp = env->GetStringUTFChars(jname, NULL)); + env->ReleaseStringUTFChars(jname, tmp); + } + + if (jencoding){ + linphone_content_set_encoding(content, tmp = env->GetStringUTFChars(jencoding,NULL)); + env->ReleaseStringUTFChars(jencoding, tmp); + } + + linphone_content_set_buffer(content, data, env->GetArrayLength(jdata)); + env->ReleaseByteArrayElements(jdata,(jbyte*)data,JNI_ABORT); + } + return content; +} /* * Class: org_linphone_core_LinphoneCoreImpl @@ -4737,25 +4773,14 @@ JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCoreImpl_subscribe(JNIE jstring jevname, jint expires, jstring jtype, jstring jsubtype, jbyteArray jdata, jstring jencoding){ LinphoneCore *lc=(LinphoneCore*)coreptr; LinphoneAddress *addr=(LinphoneAddress*)addrptr; - LinphoneContentPrivate content={0}; + LinphoneContent * content = create_content_from_java_args(env, (LinphoneCore*)coreptr, jtype, jsubtype, jdata, jencoding, NULL); LinphoneEvent *ev; jobject jev=NULL; const char *evname=env->GetStringUTFChars(jevname,NULL); - if (jtype){ - content.type=(char*)env->GetStringUTFChars(jtype,NULL); - content.subtype=(char*)env->GetStringUTFChars(jsubtype,NULL); - content.encoding=jencoding ? (char*)env->GetStringUTFChars(jencoding,NULL) : NULL; - content.data=(void*)env->GetByteArrayElements(jdata,NULL); - content.size=env->GetArrayLength(jdata); - } - ev=linphone_core_subscribe(lc,addr,evname,expires,content.type ? LINPHONE_CONTENT(&content) : NULL); - if (jtype){ - env->ReleaseStringUTFChars(jtype,content.type); - env->ReleaseStringUTFChars(jsubtype,content.subtype); - if (jencoding) env->ReleaseStringUTFChars(jencoding,content.encoding); - env->ReleaseByteArrayElements(jdata,(jbyte*)content.data,JNI_ABORT); - } + + ev=linphone_core_subscribe(lc,addr,evname,expires, content); + if (content) linphone_content_unref(content); env->ReleaseStringUTFChars(jevname,evname); if (ev){ jev=getEvent(env,ev); @@ -4772,25 +4797,13 @@ JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCoreImpl_publish(JNIEnv jstring jtype, jstring jsubtype, jbyteArray jdata, jstring jencoding){ LinphoneCore *lc=(LinphoneCore*)coreptr; LinphoneAddress *addr=(LinphoneAddress*)addrptr; - LinphoneContentPrivate content={0}; + LinphoneContent * content = create_content_from_java_args(env, (LinphoneCore*)coreptr, jtype, jsubtype, jdata, jencoding, NULL); LinphoneEvent *ev; jobject jev=NULL; const char *evname=env->GetStringUTFChars(jevname,NULL); - if (jtype){ - content.type=(char*)env->GetStringUTFChars(jtype,NULL); - content.subtype=(char*)env->GetStringUTFChars(jsubtype,NULL); - content.encoding=jencoding ? (char*)env->GetStringUTFChars(jencoding,NULL) : NULL; - content.data=(void*)env->GetByteArrayElements(jdata,NULL); - content.size=env->GetArrayLength(jdata); - } - ev=linphone_core_publish(lc,addr,evname,expires,content.type ? LINPHONE_CONTENT(&content) : NULL); - if (jtype){ - env->ReleaseStringUTFChars(jtype,content.type); - env->ReleaseStringUTFChars(jsubtype,content.subtype); - if (jencoding) env->ReleaseStringUTFChars(jencoding,content.encoding); - env->ReleaseByteArrayElements(jdata,(jbyte*)content.data,JNI_ABORT); - } + ev=linphone_core_publish(lc,addr,evname,expires, content); + if (content) linphone_content_unref(content); env->ReleaseStringUTFChars(jevname,evname); if (ev){ jev=getEvent(env,ev); @@ -4932,20 +4945,22 @@ static jobject create_java_linphone_content(JNIEnv *env, const LinphoneContent * jstring jtype, jsubtype, jencoding, jname; jbyteArray jdata = NULL; jint jsize = 0; - const LinphoneContentPrivate *content = LINPHONE_CONTENT_PRIVATE(icontent); + const char *tmp; + void *data; contentClass = (jclass)env->FindClass("org/linphone/core/LinphoneContentImpl"); ctor = env->GetMethodID(contentClass,"", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[BLjava/lang/String;I)V"); - jtype = env->NewStringUTF(content->type); - jsubtype = env->NewStringUTF(content->subtype); - jencoding = content->encoding ? env->NewStringUTF(content->encoding) : NULL; - jname = content->name ? env->NewStringUTF(content->name) : NULL; - jsize = (jint) content->size; + jtype = env->NewStringUTF(linphone_content_get_type(icontent)); + jsubtype = env->NewStringUTF(linphone_content_get_subtype(icontent)); + jencoding = ((tmp = linphone_content_get_encoding(icontent))) ? env->NewStringUTF(tmp) : NULL; + jname = ((tmp = linphone_content_get_name(icontent))) ? env->NewStringUTF(tmp) : NULL; + jsize = (jint) linphone_content_get_size(icontent); - if (content->data){ - jdata = env->NewByteArray(content->size); - env->SetByteArrayRegion(jdata, 0, content->size, (jbyte*)content->data); + data = linphone_content_get_buffer(icontent); + if (data){ + jdata = env->NewByteArray(linphone_content_get_size(icontent)); + env->SetByteArrayRegion(jdata, 0, linphone_content_get_size(icontent), (jbyte*)data); } jobject jobj = env->NewObject(contentClass, ctor, jname, jtype, jsubtype, jdata, jencoding, jsize); @@ -5028,16 +5043,22 @@ JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneInfoMessageImpl_getCont * Signature: (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V */ JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneInfoMessageImpl_setContent(JNIEnv *env, jobject jobj, jlong infoptr, jstring jtype, jstring jsubtype, jstring jdata){ - LinphoneContentPrivate content={0}; - - content.type=(char*)env->GetStringUTFChars(jtype,NULL); - content.subtype=(char*)env->GetStringUTFChars(jsubtype,NULL); - content.data=(void*)env->GetStringUTFChars(jdata,NULL); - content.size=strlen((char*)content.data); - linphone_info_message_set_content((LinphoneInfoMessage*)infoptr,LINPHONE_CONTENT(&content)); - env->ReleaseStringUTFChars(jtype,content.type); - env->ReleaseStringUTFChars(jsubtype,content.subtype); - env->ReleaseStringUTFChars(jdata,(char*)content.data); + LinphoneInfoMessage *infomsg = (LinphoneInfoMessage*) infoptr; + LinphoneContent * content = linphone_content_new(); + const char *tmp; + + linphone_content_set_type(content, tmp = env->GetStringUTFChars(jtype,NULL)); + env->ReleaseStringUTFChars(jtype, tmp); + + linphone_content_set_type(content, tmp = env->GetStringUTFChars(jsubtype,NULL)); + env->ReleaseStringUTFChars(jsubtype, tmp); + + + linphone_content_set_string_buffer(content, tmp = env->GetStringUTFChars(jdata,NULL)); + env->ReleaseStringUTFChars(jdata, tmp); + + linphone_info_message_set_content((LinphoneInfoMessage*)infoptr, content); + linphone_content_unref(content); } /* @@ -5137,25 +5158,15 @@ JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneEventImpl_denySubscription * Signature: (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)I */ JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneEventImpl_notify(JNIEnv *env, jobject jobj, jlong evptr, jstring jtype, jstring jsubtype, jbyteArray jdata, jstring jencoding){ - LinphoneContentPrivate content={0}; + LinphoneContent * content = create_content_from_java_args(env, linphone_event_get_core((LinphoneEvent *)evptr), + jtype, jsubtype, jdata, jencoding, NULL); LinphoneEvent *ev=(LinphoneEvent*)evptr; jint err; - if (jtype){ - content.type=(char*)env->GetStringUTFChars(jtype,NULL); - content.subtype=(char*)env->GetStringUTFChars(jsubtype,NULL); - content.encoding=jencoding ? (char*)env->GetStringUTFChars(jsubtype,NULL) : NULL; - content.data=(void*)env->GetByteArrayElements(jdata,NULL); - content.size=env->GetArrayLength(jdata); - } + err=linphone_event_notify(ev, content); - err=linphone_event_notify(ev,content.type ? LINPHONE_CONTENT(&content) : NULL); - - if (jtype){ - env->ReleaseStringUTFChars(jtype,content.type); - env->ReleaseStringUTFChars(jsubtype,content.subtype); - if (jencoding) env->ReleaseStringUTFChars(jencoding,content.encoding); - env->ReleaseByteArrayElements(jdata,(jbyte*)content.data,JNI_ABORT); + if (content){ + linphone_content_unref(content); } return err; } @@ -5166,26 +5177,14 @@ JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneEventImpl_notify(JNIEnv *e * Signature: (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)I */ JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneEventImpl_updateSubscribe(JNIEnv *env, jobject jobj, jlong evptr, jstring jtype, jstring jsubtype, jbyteArray jdata, jstring jencoding){ - LinphoneContentPrivate content={0}; + LinphoneContent * content = create_content_from_java_args(env, linphone_event_get_core((LinphoneEvent *)evptr), + jtype, jsubtype, jdata, jencoding, NULL); LinphoneEvent *ev=(LinphoneEvent*)evptr; jint err; - if (jtype){ - content.type=(char*)env->GetStringUTFChars(jtype,NULL); - content.subtype=(char*)env->GetStringUTFChars(jsubtype,NULL); - content.encoding=jencoding ? (char*)env->GetStringUTFChars(jsubtype,NULL) : NULL; - content.data=(void*)env->GetByteArrayElements(jdata,NULL); - content.size=env->GetArrayLength(jdata); - } + err=linphone_event_update_subscribe(ev, content); - err=linphone_event_update_subscribe(ev,content.type ? LINPHONE_CONTENT(&content) : NULL); - - if (jtype){ - env->ReleaseStringUTFChars(jtype,content.type); - env->ReleaseStringUTFChars(jsubtype,content.subtype); - if (jencoding) env->ReleaseStringUTFChars(jencoding,content.encoding); - env->ReleaseByteArrayElements(jdata,(jbyte*)content.data,JNI_ABORT); - } + if (content) linphone_content_unref(content); return err; } @@ -5195,26 +5194,14 @@ JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneEventImpl_updateSubscribe( * Signature: (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)I */ JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneEventImpl_updatePublish(JNIEnv *env, jobject jobj, jlong evptr, jstring jtype, jstring jsubtype, jbyteArray jdata, jstring jencoding){ - LinphoneContentPrivate content={0}; + LinphoneContent * content = create_content_from_java_args(env, linphone_event_get_core((LinphoneEvent *)evptr), + jtype, jsubtype, jdata, jencoding, NULL); LinphoneEvent *ev=(LinphoneEvent*)evptr; jint err; + + err=linphone_event_update_publish(ev, content); - if (jtype){ - content.type=(char*)env->GetStringUTFChars(jtype,NULL); - content.subtype=(char*)env->GetStringUTFChars(jsubtype,NULL); - content.encoding=jencoding ? (char*)env->GetStringUTFChars(jsubtype,NULL) : NULL; - content.data=(void*)env->GetByteArrayElements(jdata,NULL); - content.size=env->GetArrayLength(jdata); - } - - err=linphone_event_update_publish(ev,content.type ? LINPHONE_CONTENT(&content) : NULL); - - if (jtype){ - env->ReleaseStringUTFChars(jtype,content.type); - env->ReleaseStringUTFChars(jsubtype,content.subtype); - if (jencoding) env->ReleaseStringUTFChars(jencoding,content.encoding); - env->ReleaseByteArrayElements(jdata,(jbyte*)content.data,JNI_ABORT); - } + if (content) linphone_content_unref(content); return err; } @@ -5279,22 +5266,12 @@ JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCoreImpl_createSubscrib return jevent; } -JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneEventImpl_sendSubscribe(JNIEnv *env, jobject thiz, jlong jevent, jstring jtype, jstring jsubtype, jbyteArray jdata, jstring jencoding) { - LinphoneContentPrivate content = {0}; - if (jtype) { - content.type = (char*) env->GetStringUTFChars(jtype, NULL); - content.subtype = (char*) env->GetStringUTFChars(jsubtype, NULL); - content.encoding = jencoding ? (char*) env->GetStringUTFChars(jencoding, NULL) : NULL; - content.data = (void*) env->GetByteArrayElements(jdata, NULL); - content.size = env->GetArrayLength(jdata); - } - linphone_event_send_subscribe((LinphoneEvent*) jevent, content.type ? LINPHONE_CONTENT(&content) : NULL); - if (jtype) { - env->ReleaseStringUTFChars(jtype, content.type); - env->ReleaseStringUTFChars(jsubtype, content.subtype); - if (jencoding) env->ReleaseStringUTFChars(jencoding, content.encoding); - env->ReleaseByteArrayElements(jdata, (jbyte*) content.data, JNI_ABORT); - } +JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneEventImpl_sendSubscribe(JNIEnv *env, jobject thiz, jlong eventptr, jstring jtype, jstring jsubtype, jbyteArray jdata, jstring jencoding) { + LinphoneContent *content = create_content_from_java_args(env, linphone_event_get_core((LinphoneEvent*)eventptr), + jtype, jsubtype, jdata, jencoding, NULL); + + linphone_event_send_subscribe((LinphoneEvent*) eventptr, content); + if (content) linphone_content_unref(content); } JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCoreImpl_createPublish(JNIEnv *env, jobject thiz, jlong jcore, jlong jaddr, jstring jeventname, jint expires) { @@ -5312,22 +5289,11 @@ JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCoreImpl_createPublish( return jevent; } -JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneEventImpl_sendPublish(JNIEnv *env, jobject thiz, jlong jevent, jstring jtype, jstring jsubtype, jbyteArray jdata, jstring jencoding) { - LinphoneContentPrivate content = {0}; - if (jtype) { - content.type = (char*) env->GetStringUTFChars(jtype, NULL); - content.subtype = (char*) env->GetStringUTFChars(jsubtype, NULL); - content.encoding = jencoding ? (char*) env->GetStringUTFChars(jencoding, NULL) : NULL; - content.data = (void*) env->GetByteArrayElements(jdata, NULL); - content.size = env->GetArrayLength(jdata); - } - linphone_event_send_publish((LinphoneEvent*) jevent, content.type ? LINPHONE_CONTENT(&content) : NULL); - if (jtype) { - env->ReleaseStringUTFChars(jtype, content.type); - env->ReleaseStringUTFChars(jsubtype, content.subtype); - if (jencoding) env->ReleaseStringUTFChars(jencoding, content.encoding); - env->ReleaseByteArrayElements(jdata, (jbyte*) content.data, JNI_ABORT); - } +JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneEventImpl_sendPublish(JNIEnv *env, jobject thiz, jlong eventptr, jstring jtype, jstring jsubtype, jbyteArray jdata, jstring jencoding) { + LinphoneContent *content = create_content_from_java_args(env, linphone_event_get_core((LinphoneEvent*)eventptr), + jtype, jsubtype, jdata, jencoding, NULL); + linphone_event_send_publish((LinphoneEvent*) eventptr, content); + if (content) linphone_content_unref(content); } JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneEventImpl_addCustomHeader(JNIEnv *env, jobject thiz, jlong jevent, jstring jname, jstring jvalue) { diff --git a/coreapi/message_storage.c b/coreapi/message_storage.c index 3bf74f6ea..d3c1f6338 100644 --- a/coreapi/message_storage.c +++ b/coreapi/message_storage.c @@ -253,7 +253,7 @@ void linphone_sql_request_all(sqlite3* db,const char *stmt, LinphoneCore* lc){ } static int linphone_chat_message_store_content(LinphoneChatMessage *msg) { - LinphoneCore *lc = linphone_chat_room_get_lc(msg->chat_room); + LinphoneCore *lc = linphone_chat_room_get_core(msg->chat_room); int id = -1; if (lc->db) { LinphoneContent *content = msg->file_transfer_information; @@ -273,7 +273,7 @@ static int linphone_chat_message_store_content(LinphoneChatMessage *msg) { } unsigned int linphone_chat_message_store(LinphoneChatMessage *msg){ - LinphoneCore *lc=linphone_chat_room_get_lc(msg->chat_room); + LinphoneCore *lc=linphone_chat_room_get_core(msg->chat_room); int id = 0; if (lc->db){ @@ -330,7 +330,7 @@ void linphone_chat_message_store_appdata(LinphoneChatMessage* msg){ } void linphone_chat_room_mark_as_read(LinphoneChatRoom *cr){ - LinphoneCore *lc=linphone_chat_room_get_lc(cr); + LinphoneCore *lc=linphone_chat_room_get_core(cr); int read=1; char *peer; char *buf; @@ -351,7 +351,7 @@ void linphone_chat_room_mark_as_read(LinphoneChatRoom *cr){ } void linphone_chat_room_update_url(LinphoneChatRoom *cr, LinphoneChatMessage *msg) { - LinphoneCore *lc=linphone_chat_room_get_lc(cr); + LinphoneCore *lc=linphone_chat_room_get_core(cr); char *buf; if (lc->db==NULL) return ; @@ -362,7 +362,7 @@ void linphone_chat_room_update_url(LinphoneChatRoom *cr, LinphoneChatMessage *ms } static int linphone_chat_room_get_messages_count(LinphoneChatRoom *cr, bool_t unread_only){ - LinphoneCore *lc=linphone_chat_room_get_lc(cr); + LinphoneCore *lc=linphone_chat_room_get_core(cr); int numrows=0; char *peer; char *buf; @@ -433,7 +433,7 @@ void linphone_chat_room_delete_history(LinphoneChatRoom *cr){ } MSList *linphone_chat_room_get_history_range(LinphoneChatRoom *cr, int startm, int endm){ - LinphoneCore *lc=linphone_chat_room_get_lc(cr); + LinphoneCore *lc=linphone_chat_room_get_core(cr); MSList *ret; char *buf,*buf2; char *peer;