From: Simon Morlat Date: Fri, 7 Sep 2012 11:04:27 +0000 (+0200) Subject: remove adherence from Sal to liblinphone, improve notification of failed messageso X-Git-Url: http://sjero.net/git/?p=linphone;a=commitdiff_plain;h=f815b0d5aaec61743302a1a5c48f62abe8224948 remove adherence from Sal to liblinphone, improve notification of failed messageso --- diff --git a/coreapi/callbacks.c b/coreapi/callbacks.c index 161aaab2..cd20cf6b 100644 --- a/coreapi/callbacks.c +++ b/coreapi/callbacks.c @@ -801,6 +801,28 @@ static void notify_refer(SalOp *op, SalReferStatus status){ } } +static LinphoneChatMessageState chatStatusSal2Linphone(SalTextDeliveryStatus status){ + switch(status){ + case SalTextDeliveryInProgress: + return LinphoneChatMessageStateInProgress; + case SalTextDeliveryDone: + return LinphoneChatMessageStateDelivered; + case SalTextDeliveryFailed: + return LinphoneChatMessageStateNotDelivered; + } + return LinphoneChatMessageStateIdle; +} + +static void text_delivery_update(SalOp *op, SalTextDeliveryStatus status){ + LinphoneChatMessage *chat_msg=(LinphoneChatMessage* )sal_op_get_user_pointer(op); + if (chat_msg && chat_msg->cb) { + chat_msg->cb(chat_msg + ,chatStatusSal2Linphone(status) + ,chat_msg->cb_ud); + } + linphone_chat_message_destroy(chat_msg); +} + SalCallbacks linphone_sal_callbacks={ call_received, call_ringing, @@ -818,12 +840,13 @@ SalCallbacks linphone_sal_callbacks={ dtmf_received, refer_received, text_received, + text_delivery_update, notify, notify_presence, notify_refer, subscribe_received, subscribe_closed, - ping_reply + ping_reply, }; diff --git a/coreapi/chat.c b/coreapi/chat.c index 3d336dbc..75829306 100644 --- a/coreapi/chat.c +++ b/coreapi/chat.c @@ -136,10 +136,12 @@ LinphoneChatMessage* linphone_chat_room_create_message(const LinphoneChatRoom *c msg->message=ms_strdup(message); return msg; } + void linphone_chat_message_destroy(LinphoneChatMessage* msg) { - if (msg->message) ms_free((void*)msg->message); - ms_free((void*)msg); + if (msg->message) ms_free(msg->message); + ms_free(msg); } + void linphone_chat_room_send_message2(LinphoneChatRoom *cr, LinphoneChatMessage* msg,LinphoneChatMessageStateChangeCb status_cb,void* ud) { msg->cb=status_cb; msg->cb_ud=ud; diff --git a/coreapi/private.h b/coreapi/private.h index 2bf643d4..6affd159 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -91,7 +91,7 @@ typedef struct _CallCallbackObj static const int linphone_call_magic=0x3343; struct _LinphoneChatMessage { - const char* message; + char* message; LinphoneChatRoom* chat_room; LinphoneChatMessageStateChangeCb cb; void* cb_ud; diff --git a/coreapi/sal.h b/coreapi/sal.h index 8faa1137..e12cdaf0 100644 --- a/coreapi/sal.h +++ b/coreapi/sal.h @@ -253,6 +253,12 @@ typedef enum SalSubscribeStatus{ SalSubscribeTerminated }SalSubscribeStatus; +typedef enum SalTextDeliveryStatus{ + SalTextDeliveryInProgress, + SalTextDeliveryDone, + SalTextDeliveryFailed +}SalTextDeliveryStatus; + typedef void (*SalOnCallReceived)(SalOp *op); typedef void (*SalOnCallRinging)(SalOp *op); typedef void (*SalOnCallAccepted)(SalOp *op); @@ -269,6 +275,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)(Sal *sal, const char *from, const char *msg); +typedef void (*SalOnTextDeliveryUpdate)(SalOp *op, SalTextDeliveryStatus status); typedef void (*SalOnNotify)(SalOp *op, const char *from, const char *event); typedef void (*SalOnNotifyRefer)(SalOp *op, SalReferStatus state); typedef void (*SalOnNotifyPresence)(SalOp *op, SalSubscribeStatus ss, SalPresenceStatus status, const char *msg); @@ -293,6 +300,7 @@ typedef struct SalCallbacks{ SalOnDtmfReceived dtmf_received; SalOnRefer refer_received; SalOnTextReceived text_received; + SalOnTextDeliveryUpdate text_delivery_update; SalOnNotify notify; SalOnNotifyPresence notify_presence; SalOnNotifyRefer notify_refer; diff --git a/coreapi/sal_eXosip2.c b/coreapi/sal_eXosip2.c index 447ce34e..d3ce1692 100644 --- a/coreapi/sal_eXosip2.c +++ b/coreapi/sal_eXosip2.c @@ -21,7 +21,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #endif #include "sal_eXosip2.h" -#include "private.h" #include "offeranswer.h" #ifdef ANDROID @@ -98,12 +97,12 @@ static void sal_remove_register(Sal *sal, int rid){ } } -static SalOp * sal_find_other(Sal *sal, osip_message_t *response){ +static SalOp * sal_find_other(Sal *sal, osip_message_t *message){ const MSList *elem; SalOp *op; - osip_call_id_t *callid=osip_message_get_call_id(response); + osip_call_id_t *callid=osip_message_get_call_id(message); if (callid==NULL) { - ms_error("There is no call-id in this response !"); + ms_error("There is no call-id in this message !"); return NULL; } for(elem=sal->other_transactions;elem!=NULL;elem=elem->next){ @@ -931,9 +930,9 @@ void sal_op_authenticate(SalOp *h, const SalAuthInfo *info){ } void sal_op_cancel_authentication(SalOp *h) { if (h->rid >0) { - sal_op_get_sal(h)->callbacks.register_failure(h,SalErrorFailure, SalReasonForbidden,_("Authentication failure")); + sal_op_get_sal(h)->callbacks.register_failure(h,SalErrorFailure, SalReasonForbidden,"Authentication failure"); } else if (h->cid >0) { - sal_op_get_sal(h)->callbacks.call_failure(h,SalErrorFailure, SalReasonForbidden,_("Authentication failure"),0); + sal_op_get_sal(h)->callbacks.call_failure(h,SalErrorFailure, SalReasonForbidden,"Authentication failure",0); } else { ms_warning("Auth failure not handled"); } @@ -999,6 +998,7 @@ static SalOp *find_op(Sal *sal, eXosip_event_t *ev){ return sal_find_in_subscribe(sal,ev->nid); } if (ev->response) return sal_find_other(sal,ev->response); + else if (ev->request) return sal_find_other(sal,ev->request); return NULL; } @@ -1953,7 +1953,6 @@ static bool_t registration_failure(Sal *sal, eXosip_event_t *ev){ static void other_request_reply(Sal *sal,eXosip_event_t *ev){ SalOp *op=find_op(sal,ev); - LinphoneChatMessage* chat_msg; if (op==NULL){ ms_warning("other_request_reply(): Receiving response to unknown request."); return; @@ -1963,16 +1962,18 @@ static void other_request_reply(Sal *sal,eXosip_event_t *ev){ update_contact_from_response(op,ev->response); if (ev->request && strcmp(osip_message_get_method(ev->request),"OPTIONS")==0) sal->callbacks.ping_reply(op); - else if (ev->request && strcmp(osip_message_get_method(ev->request),"MESSAGE")==0) { - /*out of call message acknolegment*/ - chat_msg=(LinphoneChatMessage* )op->base.user_pointer; - if (chat_msg->cb) { - chat_msg->cb(chat_msg - ,(ev->response->status_code==200?LinphoneChatMessageStateDelivered:LinphoneChatMessageStateNotDelivered) - ,chat_msg->cb_ud); + } + if (ev->request && strcmp(osip_message_get_method(ev->request),"MESSAGE")==0) { + /*out of call message acknolegment*/ + SalTextDeliveryStatus status=SalTextDeliveryFailed; + if (ev->response){ + if (ev->response->status_code<200){ + status=SalTextDeliveryInProgress; + }else if (ev->response->status_code<300 && ev->response->status_code>=200){ + status=SalTextDeliveryDone; } - linphone_chat_message_destroy(chat_msg); } + sal->callbacks.text_delivery_update(op,status); } } @@ -2081,8 +2082,8 @@ static bool_t process_event(Sal *sal, eXosip_event_t *ev){ if (ev->response && (ev->response->status_code == 407 || ev->response->status_code == 401)){ return process_authentication(sal,ev); } - case EXOSIP_SUBSCRIPTION_SERVERFAILURE: - case EXOSIP_SUBSCRIPTION_GLOBALFAILURE: + case EXOSIP_SUBSCRIPTION_SERVERFAILURE: + case EXOSIP_SUBSCRIPTION_GLOBALFAILURE: sal_exosip_subscription_closed(sal,ev); break; case EXOSIP_REGISTRATION_FAILURE: diff --git a/gtk/chat.c b/gtk/chat.c index 4138f672..cb866a92 100644 --- a/gtk/chat.c +++ b/gtk/chat.c @@ -90,6 +90,10 @@ const char* linphone_gtk_get_used_identity(){ else return linphone_core_get_primary_contact(lc); } +static void on_chat_state_changed(LinphoneChatMessage *msg, LinphoneChatMessageState state, void *user_pointer){ + g_message("chat message state is %s",linphone_chat_message_state_to_string(state)); +} + void linphone_gtk_send_text(GtkWidget *button){ GtkWidget *w=gtk_widget_get_toplevel(button); GtkWidget *entry=linphone_gtk_get_widget(w,"text_entry"); @@ -97,10 +101,12 @@ void linphone_gtk_send_text(GtkWidget *button){ const gchar *entered; entered=gtk_entry_get_text(GTK_ENTRY(entry)); if (strlen(entered)>0) { + LinphoneChatMessage *msg; linphone_gtk_push_text(GTK_TEXT_VIEW(linphone_gtk_get_widget(w,"textlog")), linphone_gtk_get_used_identity(), entered,TRUE); - linphone_chat_room_send_message(cr,entered); + msg=linphone_chat_room_create_message(cr,entered); + linphone_chat_room_send_message2(cr,msg,on_chat_state_changed,NULL); gtk_entry_set_text(GTK_ENTRY(entry),""); } }