diff --git a/coreapi/bellesip_sal/sal_op_message.c b/coreapi/bellesip_sal/sal_op_message.c index 25402aef2..4eec76c6e 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,403, "process error"); } else { ms_warning("unexpected io error for incoming message on op [%p]",op); } @@ -54,19 +54,8 @@ static void process_response_event(void *op_base, const belle_sip_response_event SalOp* op = (SalOp*)op_base; /*belle_sip_client_transaction_t *client_transaction=belle_sip_response_event_get_client_transaction(event);*/ int code = belle_sip_response_get_status_code(belle_sip_response_event_get_response(event)); - SalTextDeliveryStatus status; - if (code>=100 && code <200) - status=SalTextDeliveryInProgress; - else if (code>=200 && code <300) - status=SalTextDeliveryDone; - else - status=SalTextDeliveryFailed; - if (status != SalTextDeliveryInProgress) { - /*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); - + const char *reason = belle_sip_response_get_reason_phrase(belle_sip_response_event_get_response(event)); + op->base.root->callbacks.text_delivery_update(op,code, 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..fe9b53aef 100644 --- a/coreapi/callbacks.c +++ b/coreapi/callbacks.c @@ -1024,7 +1024,17 @@ 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 SalTextDeliveryStatus code_to_text_delivery_status(int code) { + if (code>=100 && code <200) + return SalTextDeliveryInProgress; + else if (code>=200 && code <300) + return SalTextDeliveryDone; + else + return SalTextDeliveryFailed; +} + +static void text_delivery_update(SalOp *op, int code, const char *reason){ + SalTextDeliveryStatus status = code_to_text_delivery_status(code); LinphoneChatMessage *chat_msg=(LinphoneChatMessage* )sal_op_get_user_pointer(op); const MSList* calls; @@ -1035,6 +1045,8 @@ 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->response_code=code; + chat_msg->response_reason=ms_strdup(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..2a756fef9 100644 --- a/coreapi/chat.c +++ b/coreapi/chat.c @@ -786,9 +786,17 @@ void linphone_chat_message_destroy(LinphoneChatMessage* msg) { if (msg->from) linphone_address_destroy(msg->from); if (msg->to) linphone_address_destroy(msg->to); if (msg->custom_headers) sal_custom_header_free(msg->custom_headers); + if (msg->response_reason) ms_free(msg->response_reason); ms_free(msg); } +int linphone_chat_message_get_response_code(LinphoneChatMessage* msg) { + return msg->response_code; +} + +const char *linphone_chat_message_get_response_reason(LinphoneChatMessage* msg) { + return msg->response_reason; +} /** * @} diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index e91d627ac..28d459d15 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -1044,6 +1044,8 @@ 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 int linphone_chat_message_get_response_code(LinphoneChatMessage* msg); +LINPHONE_PUBLIC const char *linphone_chat_message_get_response_reason(LinphoneChatMessage* msg); /** * @} */ diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index 3ac117faa..7051c6abe 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -2324,6 +2324,20 @@ extern "C" jstring Java_org_linphone_core_LinphoneChatMessageImpl_getText(JNIEnv return jvalue; } +extern "C" jint Java_org_linphone_core_LinphoneChatMessageImpl_getResponseCode(JNIEnv* env + ,jobject thiz + ,jlong ptr) { + return linphone_chat_message_get_response_code((LinphoneChatMessage*)ptr); +} + +extern "C" jstring Java_org_linphone_core_LinphoneChatMessageImpl_getResponseReason(JNIEnv* env + ,jobject thiz + ,jlong ptr) { + const char *reason = linphone_chat_message_get_response_reason((LinphoneChatMessage*)ptr); + return env->NewStringUTF(reason); + +} + 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 a2264af68..af5459035 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,8 @@ struct _LinphoneChatMessage { LinphoneChatMessageState state; bool_t is_read; unsigned int storage_id; + int response_code; + char *response_reason; }; typedef struct StunCandidate{ diff --git a/include/sal/sal.h b/include/sal/sal.h index 5c93786a9..a216730b1 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, int code, const char *reason); 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..c6985a33e 100644 --- a/java/common/org/linphone/core/LinphoneChatMessage.java +++ b/java/common/org/linphone/core/LinphoneChatMessage.java @@ -141,4 +141,14 @@ public interface LinphoneChatMessage { * @return the id used to id this message in the database */ int getStorageId(); + + /** + * @return the response code or 0 if no response received + */ + int getResponseCode(); + + /** + * @return the response reason or null if no response received + */ + String getResponseReason(); } diff --git a/java/impl/org/linphone/core/LinphoneChatMessageImpl.java b/java/impl/org/linphone/core/LinphoneChatMessageImpl.java index 8ce49c747..a6f591bfa 100644 --- a/java/impl/org/linphone/core/LinphoneChatMessageImpl.java +++ b/java/impl/org/linphone/core/LinphoneChatMessageImpl.java @@ -14,6 +14,8 @@ public class LinphoneChatMessageImpl implements LinphoneChatMessage { private native boolean isOutgoing(long ptr); private native void store(long ptr); private native int getStorageId(long ptr); + private native int getResponseCode(long ptr); + private native String getResponseReason(long ptr); protected LinphoneChatMessageImpl(long aNativePtr) { nativePtr = aNativePtr; @@ -94,4 +96,12 @@ public class LinphoneChatMessageImpl implements LinphoneChatMessage { public int getStorageId() { return getStorageId(nativePtr); } + + public int getResponseCode() { + return getResponseCode(nativePtr); + } + + public String getResponseReason() { + return getResponseReason(nativePtr); + } }