From 93f5e85967cb1e62a4000c75b1e32bacddae4a13 Mon Sep 17 00:00:00 2001 From: Guillaume Beraudo Date: Thu, 13 Feb 2014 11:54:11 +0100 Subject: [PATCH] Expose chat message reason based on LinphoneReason. The response code is not exposed to allow mrtp in the future. There is no possibility to retrieve the code or the sip reason phrase. --- coreapi/bellesip_sal/sal_op_message.c | 5 +++-- coreapi/callbacks.c | 3 ++- coreapi/chat.c | 4 ++++ coreapi/linphonecore.h | 1 + coreapi/linphonecore_jni.cc | 6 ++++++ coreapi/private.h | 2 ++ include/sal/sal.h | 2 +- java/common/org/linphone/core/LinphoneChatMessage.java | 5 +++++ java/impl/org/linphone/core/LinphoneChatMessageImpl.java | 6 ++++++ 9 files changed, 30 insertions(+), 4 deletions(-) diff --git a/coreapi/bellesip_sal/sal_op_message.c b/coreapi/bellesip_sal/sal_op_message.c index 25402aef2..10507a12f 100644 --- a/coreapi/bellesip_sal/sal_op_message.c +++ b/coreapi/bellesip_sal/sal_op_message.c @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static void process_error( SalOp* op) { if (op->dir == SalOpDirOutgoing) { - op->base.root->callbacks.text_delivery_update(op,SalTextDeliveryFailed); + op->base.root->callbacks.text_delivery_update(op, SalTextDeliveryFailed, SalReasonUnknown); } else { ms_warning("unexpected io error for incoming message on op [%p]",op); } @@ -65,8 +65,9 @@ static void process_response_event(void *op_base, const belle_sip_response_event /*reset op to make sure transaction terminated does not need op belle_sip_transaction_set_application_data(BELLE_SIP_TRANSACTION(client_transaction),NULL);*/ } - op->base.root->callbacks.text_delivery_update(op,status); + SalReason reason = code == 403 ? SalReasonForbidden : SalReasonUnknown; + op->base.root->callbacks.text_delivery_update(op,status, reason); } static bool_t is_plain_text(belle_sip_header_content_type_t* content_type) { return strcmp("text",belle_sip_header_content_type_get_type(content_type))==0 diff --git a/coreapi/callbacks.c b/coreapi/callbacks.c index f22d35f20..13ac204f7 100644 --- a/coreapi/callbacks.c +++ b/coreapi/callbacks.c @@ -1024,7 +1024,7 @@ static int op_equals(LinphoneCall *a, SalOp *b) { return a->op !=b; /*return 0 if equals*/ } -static void text_delivery_update(SalOp *op, SalTextDeliveryStatus status){ +static void text_delivery_update(SalOp *op, SalTextDeliveryStatus status, SalReason reason){ LinphoneChatMessage *chat_msg=(LinphoneChatMessage* )sal_op_get_user_pointer(op); const MSList* calls; @@ -1035,6 +1035,7 @@ static void text_delivery_update(SalOp *op, SalTextDeliveryStatus status){ calls = linphone_core_get_calls(chat_msg->chat_room->lc); chat_msg->state=chatStatusSal2Linphone(status); + chat_msg->reason=reason; linphone_chat_message_store_state(chat_msg); if (chat_msg && chat_msg->cb) { ms_message("Notifying text delivery with status %i",chat_msg->state); diff --git a/coreapi/chat.c b/coreapi/chat.c index 6dc8ae57a..39003fbbf 100644 --- a/coreapi/chat.c +++ b/coreapi/chat.c @@ -790,6 +790,10 @@ void linphone_chat_message_destroy(LinphoneChatMessage* msg) { } +LinphoneReason linphone_chat_message_get_reason(LinphoneChatMessage* msg) { + return linphone_reason_from_sal(msg->reason); +} + /** * @} */ diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index 0c6580bae..aec4df508 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -1044,6 +1044,7 @@ LINPHONE_PUBLIC const char * linphone_chat_message_get_custom_header(LinphoneCha LINPHONE_PUBLIC bool_t linphone_chat_message_is_read(LinphoneChatMessage* message); LINPHONE_PUBLIC bool_t linphone_chat_message_is_outgoing(LinphoneChatMessage* message); LINPHONE_PUBLIC unsigned int linphone_chat_message_get_storage_id(LinphoneChatMessage* message); +LINPHONE_PUBLIC LinphoneReason linphone_chat_message_get_reason(LinphoneChatMessage* msg); /** * @} */ diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index 3ac117faa..760ce3f29 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -2324,6 +2324,12 @@ extern "C" jstring Java_org_linphone_core_LinphoneChatMessageImpl_getText(JNIEnv return jvalue; } +extern "C" jint Java_org_linphone_core_LinphoneChatMessageImpl_getReason(JNIEnv* env + ,jobject thiz + ,jlong ptr) { + return linphone_chat_message_get_reason((LinphoneChatMessage*)ptr); +} + extern "C" jstring Java_org_linphone_core_LinphoneChatMessageImpl_getCustomHeader(JNIEnv* env ,jobject thiz ,jlong ptr, jstring jheader_name) { diff --git a/coreapi/private.h b/coreapi/private.h index a4ec17857..89d4ae7b1 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -25,6 +25,7 @@ #ifndef _PRIVATE_H #define _PRIVATE_H #ifdef __cplusplus + extern "C" { #endif #include "linphonecore.h" @@ -145,6 +146,7 @@ struct _LinphoneChatMessage { LinphoneChatMessageState state; bool_t is_read; unsigned int storage_id; + LinphoneReason reason; }; typedef struct StunCandidate{ diff --git a/include/sal/sal.h b/include/sal/sal.h index 7a7134754..644649d13 100644 --- a/include/sal/sal.h +++ b/include/sal/sal.h @@ -391,7 +391,7 @@ typedef void (*SalOnVfuRequest)(SalOp *op); typedef void (*SalOnDtmfReceived)(SalOp *op, char dtmf); typedef void (*SalOnRefer)(Sal *sal, SalOp *op, const char *referto); typedef void (*SalOnTextReceived)(SalOp *op, const SalMessage *msg); -typedef void (*SalOnTextDeliveryUpdate)(SalOp *op, SalTextDeliveryStatus status); +typedef void (*SalOnTextDeliveryUpdate)(SalOp *op, SalTextDeliveryStatus, SalReason); typedef void (*SalOnIsComposingReceived)(SalOp *op, const SalIsComposing *is_composing); typedef void (*SalOnNotifyRefer)(SalOp *op, SalReferStatus state); typedef void (*SalOnSubscribeResponse)(SalOp *op, SalSubscribeStatus status, SalError error, SalReason reason); diff --git a/java/common/org/linphone/core/LinphoneChatMessage.java b/java/common/org/linphone/core/LinphoneChatMessage.java index 8345df382..7d5d8b472 100644 --- a/java/common/org/linphone/core/LinphoneChatMessage.java +++ b/java/common/org/linphone/core/LinphoneChatMessage.java @@ -141,4 +141,9 @@ public interface LinphoneChatMessage { * @return the id used to id this message in the database */ int getStorageId(); + + /** + * @return the reason if response received + */ + Reason getReason(); } diff --git a/java/impl/org/linphone/core/LinphoneChatMessageImpl.java b/java/impl/org/linphone/core/LinphoneChatMessageImpl.java index 8ce49c747..2708a82af 100644 --- a/java/impl/org/linphone/core/LinphoneChatMessageImpl.java +++ b/java/impl/org/linphone/core/LinphoneChatMessageImpl.java @@ -94,4 +94,10 @@ public class LinphoneChatMessageImpl implements LinphoneChatMessage { public int getStorageId() { return getStorageId(nativePtr); } + + private native int getReason(long ptr); + + public Reason getReason() { + return Reason.fromInt(getReason(nativePtr)); + } }