Commit 1cf4eda4 authored by Erwan Croze's avatar Erwan Croze 👋🏻

Add chat message is secured JNI

parent c1cd0c4e
......@@ -4480,6 +4480,12 @@ extern "C" jint Java_org_linphone_core_LinphoneChatMessageImpl_downloadFile(JNIE
return (jint) linphone_chat_message_download_file((LinphoneChatMessage*)ptr);
}
extern "C" jboolean Java_org_linphone_core_LinphoneChatMessageImpl_isSecured(JNIEnv* env
,jobject thiz
,jlong ptr) {
return linphone_chat_message_is_secured((LinphoneChatMessage*)ptr);
}
static void message_state_changed(LinphoneChatMessage* msg, LinphoneChatMessageState state) {
JNIEnv *env = 0;
jint result = jvm->AttachCurrentThread(&env,NULL);
......
......@@ -8,17 +8,17 @@ public interface LinphoneChatMessage {
interface StateListener {
void onLinphoneChatMessageStateChanged(LinphoneChatMessage msg, State state);
}
interface LinphoneChatMessageListener {
void onLinphoneChatMessageStateChanged(LinphoneChatMessage msg, State state);
/**
* This function is called by the core upon an incoming File transfer is started. This function may be call several time for the same file in case of large file.
* @param content incoming content information
* @param buffer holding the received data. Empty buffer means end of file.
*/
void onLinphoneChatMessageFileTransferReceived(LinphoneChatMessage msg, LinphoneContent content, LinphoneBuffer buffer);
/**
* This function is called by the core when an outgoing file transfer is started. This function is called until size is set to 0.
* @param content incoming content information
......@@ -27,7 +27,7 @@ public interface LinphoneChatMessage {
* @param bufferToFill A LinphoneBuffer object holding the data written by the application. An empty buffer means end of file.
*/
void onLinphoneChatMessageFileTransferSent(LinphoneChatMessage msg, LinphoneContent content, int offset, int size, LinphoneBuffer bufferToFill);
/**
* File transfer progress indication callback prototype.
* @param content incoming content information
......@@ -40,7 +40,7 @@ public interface LinphoneChatMessage {
static private Vector<State> values = new Vector<State>();
private final int mValue;
public final int value() {return mValue;}
private final String mStringValue;
/**
* Initial state
......@@ -74,13 +74,13 @@ public interface LinphoneChatMessage {
* Message displayed to the remote user
*/
public final static State Displayed = new State(7,"Displayed");
private State(int value,String stringValue) {
mValue = value;
values.addElement(this);
mStringValue=stringValue;
}
public static State fromInt(int value) {
for (int i=0; i<values.size();i++) {
......@@ -96,88 +96,88 @@ public interface LinphoneChatMessage {
return mValue;
}
}
/**
* get text associated to this LinphoneChatMessage
*
*
* @return text sent along with the message
*/
String getText();
/**
* get peer address associated to this LinphoneChatMessage
*
* @return LinphoneAddress peer address
*/
LinphoneAddress getPeerAddress();
/**
* get from address associated to this LinphoneChatMessage
*
* @return LinphoneAddress from address
*/
LinphoneAddress getFrom();
/**
* Get destination address of the LinphoneChatMessage.
* @return the LinphoneAddress in the To field of the message.
*/
LinphoneAddress getTo();
/**
* Linphone message can carry external body as defined by rfc2017
* @return return external body url null if not present.
*/
String getExternalBodyUrl();
/**
* Linphone message can carry external body as defined by rfc2017
* @param url ex: access-type=URL; URL="http://www.foo.com/file"
*/
void setExternalBodyUrl(String url);
/**
* Add a custom header into the message.
*/
void addCustomHeader(String name, String value);
/**
* Obtain a header value.
* @param name
* @return the value of the header, or null if not found.
*/
String getCustomHeader(String name);
/**
* Gets the time at which the message was sent
* @return the time in milliseconds
*/
long getTime();
/**
* Gets the status of the message
* @return the status of the message
*/
LinphoneChatMessage.State getStatus();
/**
* Returns wether or not the message has been read
* @return true if it has been read, flase otherwise
*/
boolean isRead();
/**
* Returns wether the message has been sent or received
* @return true if the message has been sent, false if it has been received
*/
boolean isOutgoing();
/**
* THIS METHOD IS ONLY USED TO IMPORT OLD MESSAGES, DON'T USE IT FOR ANY OTHER USAGE!
*/
void store();
/**
* Returns the id used to id this message in the database
* @return the id used to id this message in the database
......@@ -188,13 +188,13 @@ public interface LinphoneChatMessage {
* @return the reason if response received
*/
Reason getReason();
/**
* Returns full error in case of failure when sending message.
* @return an ErrorInfo.
*/
ErrorInfo getErrorInfo();
/**
* Cancel an ongoing file transfer attached to this message.(upload or download).
*/
......@@ -204,13 +204,13 @@ public interface LinphoneChatMessage {
* @return a pointer to the LinphoneContent structure or NULL if not present.
*/
LinphoneContent getFileTransferInformation();
/**
* Sets data in the chat message
* @param data to store in the message
*/
void setAppData(String data);
/**
* @return the data stored in the chat message if any, else null
*/
......@@ -221,12 +221,12 @@ public interface LinphoneChatMessage {
* @param path The path to the file to use for the file transfer.
*/
void setFileTransferFilepath(String path);
/**
* Start the download of the file referenced in a LinphoneChatMessage from remote server.
*/
int downloadFile();
/**
* Set the callbacks associated with the LinphoneChatMessage.
*/
......@@ -245,5 +245,12 @@ public interface LinphoneChatMessage {
* This is for optimizing the memory resources at runtime. Not calling this does not result in a memory leak.
**/
void destroy();
/**
* Get if the message was encrypted when transfered
* @param message LinphoneChatMessage obj
* @return whether the message was encrypted when transfered or not
*/
boolean isSecured();
}
......@@ -19,15 +19,15 @@ public class LinphoneChatMessageImpl implements LinphoneChatMessage {
private native int downloadFile(long ptr);
private native void setListener(long ptr, LinphoneChatMessageListener listener);
private native void unref(long ptr);
protected LinphoneChatMessageImpl(long aNativePtr) {
nativePtr = aNativePtr;
}
public long getNativePtr() {
return nativePtr;
}
@Override
public String getText() {
byte rawText[];
......@@ -39,33 +39,33 @@ public class LinphoneChatMessageImpl implements LinphoneChatMessage {
}
return null;
}
@Override
public LinphoneAddress getPeerAddress() {
return new LinphoneAddressImpl(getPeerAddress(nativePtr),LinphoneAddressImpl.WrapMode.FromConst);
}
@Override
public String getExternalBodyUrl() {
return getExternalBodyUrl(nativePtr);
}
@Override
public void setExternalBodyUrl(String url) {
setExternalBodyUrl(nativePtr, url);
}
@Override
public LinphoneAddress getFrom() {
return new LinphoneAddressImpl(getFrom(nativePtr),LinphoneAddressImpl.WrapMode.FromConst);
}
private native long getTo(long ptr);
@Override
public LinphoneAddress getTo() {
return new LinphoneAddressImpl(getTo(nativePtr),LinphoneAddressImpl.WrapMode.FromConst);
}
private native void addCustomHeader(long nativePtr, String name, String value);
@Override
public void addCustomHeader(String name, String value) {
......@@ -76,27 +76,27 @@ public class LinphoneChatMessageImpl implements LinphoneChatMessage {
public String getCustomHeader(String name) {
return getCustomHeader(nativePtr,name);
}
public long getTime() {
return getTime(nativePtr) * 1000; // Need milliseconds, not seconds
}
public LinphoneChatMessage.State getStatus() {
return LinphoneChatMessage.State.fromInt(getStatus(nativePtr));
}
public boolean isRead() {
return isRead(nativePtr);
}
public boolean isOutgoing() {
return isOutgoing(nativePtr);
}
public void store() {
store(nativePtr);
}
public int getStorageId() {
return getStorageId(nativePtr);
}
......@@ -115,19 +115,19 @@ public class LinphoneChatMessageImpl implements LinphoneChatMessage {
destroy();
super.finalize();
}
private native Object getFileTransferInformation(long ptr);
@Override
public LinphoneContent getFileTransferInformation() {
return (LinphoneContent) getFileTransferInformation(nativePtr);
}
private native void setAppData(long ptr, String data);
@Override
public void setAppData(String data) {
setAppData(nativePtr, data);
}
private native String getAppData(long ptr);
@Override
public String getAppData() {
......@@ -139,22 +139,22 @@ public class LinphoneChatMessageImpl implements LinphoneChatMessage {
public void cancelFileTransfer() {
cancelFileTransfer(nativePtr);
}
@Override
public void setFileTransferFilepath(String path) {
setFileTransferFilepath(nativePtr, path);
}
@Override
public int downloadFile() {
return downloadFile(nativePtr);
}
@Override
public void setListener(LinphoneChatMessageListener listener) {
setListener(nativePtr, listener);
}
private native void putChar(long nativePtr, long character);
@Override
public void putChar(long character) throws LinphoneCoreException {
......@@ -166,4 +166,10 @@ public class LinphoneChatMessageImpl implements LinphoneChatMessage {
nativePtr = 0;
}
}
private native boolean isSecured(long nativePtr);
@Override
public boolean isSecured() {
return isSecured(nativePtr);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment