diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index 340210805..c61dbdf8a 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -3173,7 +3173,7 @@ extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getUpnpExternalIpaddr * Signature: (JJLjava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object; */ JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCoreImpl_subscribe(JNIEnv *env, jobject jcore, jlong coreptr, jlong addrptr, - jstring jevname, jint expires, jstring jtype, jstring jsubtype, jbyteArray jdata, jstring jencoding){ + jstring jevname, jint expires, jstring jtype, jstring jsubtype, jbyteArray jdata, jstring jencoding){ LinphoneCore *lc=(LinphoneCore*)coreptr; LinphoneAddress *addr=(LinphoneAddress*)addrptr; LinphoneContent content={0}; @@ -3185,7 +3185,7 @@ JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCoreImpl_subscribe(JNIE 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.encoding=jencoding ? (char*)env->GetStringUTFChars(jencoding,NULL) : NULL; content.data=(void*)env->GetByteArrayElements(jdata,NULL); content.size=env->GetArrayLength(jdata); } @@ -3221,7 +3221,7 @@ JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCoreImpl_publish(JNIEnv 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.encoding=jencoding ? (char*)env->GetStringUTFChars(jencoding,NULL) : NULL; content.data=(void*)env->GetByteArrayElements(jdata,NULL); content.size=env->GetArrayLength(jdata); } @@ -3633,6 +3633,90 @@ JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneEventImpl_getSubscriptionS return linphone_event_get_subscription_state(ev); } +JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCoreImpl_createSubscribe(JNIEnv *env, jobject thiz, jlong jcore, jlong jaddr, jstring jeventname, jint expires) { + LinphoneCore *lc = (LinphoneCore*) jcore; + LinphoneCoreData* lcData = (LinphoneCoreData*) linphone_core_get_user_data(lc); + LinphoneAddress *addr = (LinphoneAddress*) jaddr; + LinphoneEvent *event; + jobject jevent = NULL; + const char *event_name = env->GetStringUTFChars(jeventname, NULL); + + event = linphone_core_create_subscribe(lc, addr, event_name, expires); + env->ReleaseStringUTFChars(jeventname, event_name); + if (event) { + jevent = lcData->getEvent(env, event); + } + 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) { + LinphoneContent 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 ? &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 jobject JNICALL Java_org_linphone_core_LinphoneCoreImpl_createPublish(JNIEnv *env, jobject thiz, jlong jcore, jlong jaddr, jstring jeventname, jint expires) { + LinphoneCore *lc = (LinphoneCore*) jcore; + LinphoneCoreData* lcData = (LinphoneCoreData*) linphone_core_get_user_data(lc); + LinphoneAddress *addr = (LinphoneAddress*) jaddr; + LinphoneEvent *event; + jobject jevent = NULL; + const char *event_name = env->GetStringUTFChars(jeventname, NULL); + + event = linphone_core_create_publish(lc, addr, event_name, expires); + env->ReleaseStringUTFChars(jeventname, event_name); + if (event) { + jevent = lcData->getEvent(env, event); + } + 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) { + LinphoneContent 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 ? &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_addCustomHeader(JNIEnv *env, jobject thiz, jlong jevent, jstring jname, jstring jvalue) { + const char *name = jname ? env->GetStringUTFChars(jname, NULL) : NULL; + const char *value = jvalue ? env->GetStringUTFChars(jvalue, NULL) : NULL; + linphone_event_add_custom_header((LinphoneEvent*) jevent, name, value); + if (jname) env->ReleaseStringUTFChars(jname, name); + if (jvalue) env->ReleaseStringUTFChars(jvalue, value); +} + +JNIEXPORT jstring JNICALL Java_org_linphone_core_LinphoneEventImpl_getCustomHeader(JNIEnv *env, jobject thiz, jlong jevent, jstring jname) { + const char *name = jname ? env->GetStringUTFChars(jname, NULL) : NULL; + const char *header = linphone_event_get_custom_header((LinphoneEvent*) jevent, name); + jstring jheader = header ? env->NewStringUTF(header) : NULL; + if (jname) env->ReleaseStringUTFChars(jname, name); + return jheader; +} + /* * Class: org_linphone_core_LinphoneEventImpl * Method: unref diff --git a/java/common/org/linphone/core/LinphoneCore.java b/java/common/org/linphone/core/LinphoneCore.java index 114150acf..55be3eb24 100644 --- a/java/common/org/linphone/core/LinphoneCore.java +++ b/java/common/org/linphone/core/LinphoneCore.java @@ -1433,7 +1433,30 @@ public interface LinphoneCore { * @param content optional content of the subscription. * @return a LinphoneEvent representing the subscription context. */ - public LinphoneEvent subscribe(LinphoneAddress resource, String event, int expires, LinphoneContent content ); + public LinphoneEvent subscribe(LinphoneAddress resource, String event, int expires, LinphoneContent content); + + /** + * Create an outgoing subscription, specifying the destination resource, the event name, and an optional content body. + * If accepted, the subscription runs for a finite period, but is automatically renewed if not terminated before. + * Unlike linphone_core_subscribe() the subscription isn't sent immediately. It will be send when calling linphone_event_send_subscribe(). + * @param resource the destination resource + * @param event the event name + * @param expires the whished duration of the subscription + * @param body an optional body, may be NULL. + * @return a LinphoneEvent holding the context of the created subcription. + */ + public LinphoneEvent createSubscribe(LinphoneAddress resource, String event, int expires); + + /** + * Create a publish context for an event state. + * After being created, the publish must be sent using linphone_event_send_publish(). + * After expiry, the publication is refreshed unless it is terminated before. + * @param resource the resource uri for the event + * @param event the event name + * @param expires the lifetime of the publication + * @return the LinphoneEvent holding the context of the publish. + */ + public LinphoneEvent createPublish(LinphoneAddress resource, String event, int expires); /** * Publish an event. diff --git a/java/common/org/linphone/core/LinphoneEvent.java b/java/common/org/linphone/core/LinphoneEvent.java index 865200dfd..cdc34d404 100644 --- a/java/common/org/linphone/core/LinphoneEvent.java +++ b/java/common/org/linphone/core/LinphoneEvent.java @@ -68,4 +68,30 @@ public interface LinphoneEvent { * @return */ Object getUserContext(); + + /** + * Add a custom header to an outgoing susbscription or publish. + * @param name header's name + * @param value the header's value. + */ + void addCustomHeader(String name, String value); + + /** + * Obtain the value of a given header for an incoming subscription. + * @param name header's name + * @return the header's value or NULL if such header doesn't exist. + */ + String getCustomHeader(String name); + + /** + * Send a subscription previously created by linphone_core_create_subscribe(). + * @param body optional content to attach with the subscription. + */ + void sendSubscribe(LinphoneContent body); + + /** + * Send a publish created by linphone_core_create_publish(). + * @param body the new data to be published + */ + void sendPublish(LinphoneContent body); } diff --git a/java/impl/org/linphone/core/LinphoneCoreImpl.java b/java/impl/org/linphone/core/LinphoneCoreImpl.java index d3803df22..f7d91c1e9 100644 --- a/java/impl/org/linphone/core/LinphoneCoreImpl.java +++ b/java/impl/org/linphone/core/LinphoneCoreImpl.java @@ -1047,6 +1047,19 @@ class LinphoneCoreImpl implements LinphoneCore { content!=null ? content.getType() : null, content!=null ? content.getSubtype() : null, content!=null ? content.getData() : null, content!=null ? content.getEncoding() : null); } + + private native Object createSubscribe(long core, long addr, String event, int expires); + @Override + public LinphoneEvent createSubscribe(LinphoneAddress resource, + String event, int expires) { + return (LinphoneEvent)createSubscribe(nativePtr, ((LinphoneAddressImpl)resource).nativePtr, event, expires); + } + private native Object createPublish(long core, long addr, String event, int expires); + @Override + public LinphoneEvent createPublish(LinphoneAddress resource, + String event, int expires) { + return (LinphoneEvent)createPublish(nativePtr, ((LinphoneAddressImpl)resource).nativePtr, event, expires); + } public void setChatDatabasePath(String path) { setChatDatabasePath(nativePtr, path); diff --git a/java/impl/org/linphone/core/LinphoneEventImpl.java b/java/impl/org/linphone/core/LinphoneEventImpl.java index 9890f7cdf..42d14ef20 100644 --- a/java/impl/org/linphone/core/LinphoneEventImpl.java +++ b/java/impl/org/linphone/core/LinphoneEventImpl.java @@ -1,5 +1,6 @@ package org.linphone.core; + public class LinphoneEventImpl implements LinphoneEvent { private Object mUserContext; private long mNativePtr; @@ -88,4 +89,34 @@ public class LinphoneEventImpl implements LinphoneEvent { unref(mNativePtr); } + private native void addCustomHeader(long ptr, String name, String value); + @Override + public void addCustomHeader(String name, String value) { + addCustomHeader(mNativePtr, name, value); + } + + private native String getCustomHeader(long ptr, String name); + @Override + public String getCustomHeader(String name) { + return getCustomHeader(mNativePtr, name); + } + + private native void sendSubscribe(long ptr, String type, String subtype, byte data [], String encoding); + @Override + public void sendSubscribe(LinphoneContent body) { + if (body != null) + sendSubscribe(mNativePtr, body.getType(), body.getSubtype(), body.getData(), body.getEncoding()); + else + sendSubscribe(mNativePtr, null, null, null, null); + } + + private native void sendPublish(long ptr, String type, String subtype, byte data [], String encoding); + @Override + public void sendPublish(LinphoneContent body) { + if (body != null) + sendPublish(mNativePtr, body.getType(), body.getSubtype(), body.getData(), body.getEncoding()); + else + sendPublish(mNativePtr, null, null, null, null); + } + }