]> sjero.net Git - linphone/commitdiff
implement checking of duplicated messages.
authorSimon Morlat <simon.morlat@linphone.org>
Tue, 6 Nov 2012 04:32:43 +0000 (05:32 +0100)
committerSimon Morlat <simon.morlat@linphone.org>
Tue, 6 Nov 2012 04:34:26 +0000 (05:34 +0100)
coreapi/callbacks.c
coreapi/linphonecore.c
coreapi/private.h
coreapi/sal.h
coreapi/sal_eXosip2.c

index a4a4232c436ebf397c945fba403a02a856f19381..f99c9b2247ef45f46683842bbc3e190d851e387f 100644 (file)
@@ -779,14 +779,33 @@ static void refer_received(Sal *sal, SalOp *op, const char *referto){
        }
 }
 
-static void text_received(Sal *sal, const char *from, const char *msg){
-       LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal);
-       linphone_core_message_received(lc,from,msg,NULL);
+static bool_t is_duplicate_msg(LinphoneCore *lc, const char *msg_id){
+       MSList *elem=lc->last_recv_msg_ids;
+       int i;
+       bool_t is_duplicate=FALSE;
+       for(i=0;elem!=NULL;elem=elem->next,i++){
+               if (strcmp((const char*)elem->data,msg_id)==0){
+                       is_duplicate=TRUE;
+               }
+       }
+       if (!is_duplicate){
+               lc->last_recv_msg_ids=ms_list_prepend(lc->last_recv_msg_ids,ms_strdup(msg_id));
+       }
+       if (i>=10){
+               ms_free(elem->data);
+               ms_list_remove_link(lc->last_recv_msg_ids,elem);
+       }
+       return is_duplicate;
 }
-void message_external_body_received(Sal *sal, const char *from, const char *url) {
+
+
+static void text_received(Sal *sal, const SalMessage *msg){
        LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal);
-       linphone_core_message_received(lc,from,NULL,url);
+       if (is_duplicate_msg(lc,msg->message_id)==FALSE){
+               linphone_core_message_received(lc,msg->from,msg->text,msg->url);
+       }
 }
+
 static void notify(SalOp *op, const char *from, const char *msg){
        LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
        LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer (op);
@@ -902,7 +921,6 @@ SalCallbacks linphone_sal_callbacks={
        dtmf_received,
        refer_received,
        text_received,
-       message_external_body_received,
        text_delivery_update,
        notify,
        notify_presence,
index d980e818edd404f73e5fc01111ef3617c8a9f615..8de92f23b94d0dac90bd431f54a0163481bc75f7 100644 (file)
@@ -4823,6 +4823,9 @@ static void linphone_core_uninit(LinphoneCore *lc)
 
        ms_list_for_each(lc->call_logs,(void (*)(void*))linphone_call_log_destroy);
        lc->call_logs=ms_list_free(lc->call_logs);
+       
+       ms_list_for_each(lc->last_recv_msg_ids,ms_free);
+       lc->last_recv_msg_ids=ms_list_free(lc->last_recv_msg_ids);
 
        linphone_core_free_payload_types(lc);
        ortp_exit();
index e6ed960bcd2bfba1e2456029460aaf7e7e9cd100..12909190ffdd8e68c3449e29babdbd7e87b35e5b 100644 (file)
@@ -566,6 +566,7 @@ struct _LinphoneCore
        int max_calls;
        LinphoneTunnel *tunnel;
        char* device_id;
+       MSList *last_recv_msg_ids;
 };
 
 LinphoneTunnel *linphone_core_tunnel_new(LinphoneCore *lc);
index 54a075ed6169e817cf4ce0aefc665432c49396ca..e5eb1c190d79126338632318eb39dbc0daf5ed28 100644 (file)
@@ -188,6 +188,13 @@ typedef struct SalMediaDescription{
        bool_t ice_completed;
 } SalMediaDescription;
 
+typedef struct SalMessage{
+       const char *from;
+       const char *text;
+       const char *url;
+       const char *message_id;
+}SalMessage;
+
 #define SAL_MEDIA_DESCRIPTION_MAX_MESSAGE_ATTRIBUTES 5
 
 SalMediaDescription *sal_media_description_new();
@@ -280,8 +287,7 @@ typedef void (*SalOnRegisterFailure)(SalOp *op, SalError error, SalReason reason
 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 (*SalOnMessageExternalBodyReceived)(Sal *sal, const char *from, const char *url);
+typedef void (*SalOnTextReceived)(Sal *sal, const SalMessage *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);
@@ -307,7 +313,6 @@ typedef struct SalCallbacks{
        SalOnDtmfReceived dtmf_received;
        SalOnRefer refer_received;
        SalOnTextReceived text_received;
-       SalOnMessageExternalBodyReceived message_external_body;
        SalOnTextDeliveryUpdate text_delivery_update;
        SalOnNotify notify;
        SalOnNotifyPresence notify_presence;
index b83cc4f24614461db42bd43f006015900e38874c..2f6d4ae80e620c126cfba75de38c472a67e129f6 100644 (file)
@@ -343,8 +343,6 @@ void sal_set_callbacks(Sal *ctx, const SalCallbacks *cbs){
                ctx->callbacks.text_received=(SalOnTextReceived)unimplemented_stub;
        if (ctx->callbacks.ping_reply==NULL)
                ctx->callbacks.ping_reply=(SalOnPingReply)unimplemented_stub;
-       if (ctx->callbacks.message_external_body==NULL)
-               ctx->callbacks.message_external_body=(SalOnMessageExternalBodyReceived)unimplemented_stub;
 }
 
 int sal_unlisten_ports(Sal *ctx){
@@ -1728,11 +1726,13 @@ static bool_t comes_from_local_if(osip_message_t *msg){
 
 static void text_received(Sal *sal, eXosip_event_t *ev){
        osip_body_t *body=NULL;
-       char *from=NULL,*msg;
+       char *from=NULL,*msg=NULL;
        osip_content_type_t* content_type;
        osip_uri_param_t* external_body_url; 
        char unquoted_external_body_url [256];
        int external_body_size=0;
+       SalMessage salmsg;
+       char message_id[256]={0};
        
        content_type= osip_message_get_content_type(ev->request);
        if (!content_type) {
@@ -1744,13 +1744,12 @@ static void text_received(Sal *sal, eXosip_event_t *ev){
                && strcmp(content_type->type, "text")==0 
                && content_type->subtype
                && strcmp(content_type->subtype, "plain")==0 ) {
-       osip_message_get_body(ev->request,0,&body);
-       if (body==NULL){
-               ms_error("Could not get text message from SIP body");
-               return;
-       }
-       msg=body->body;
-       sal->callbacks.text_received(sal,from,msg);
+               osip_message_get_body(ev->request,0,&body);
+               if (body==NULL){
+                       ms_error("Could not get text message from SIP body");
+                       return;
+               }
+               msg=body->body;
        } if (content_type->type 
                  && strcmp(content_type->type, "message")==0 
                  && content_type->subtype
@@ -1762,11 +1761,18 @@ static void text_received(Sal *sal, eXosip_event_t *ev){
                                ,&external_body_url->gvalue[1]
                                ,external_body_size=MIN(strlen(external_body_url->gvalue)-1,sizeof(unquoted_external_body_url)));
                unquoted_external_body_url[external_body_size-1]='\0';
-               sal->callbacks.message_external_body(sal,from,unquoted_external_body_url);
-               
        } else {
                ms_warning("Unsupported content type [%s/%s]",content_type->type,content_type->subtype);
+               osip_free(from);
+               return;
        }
+       snprintf(message_id,sizeof(message_id)-1,"%s%s",ev->request->call_id->number,ev->request->cseq->number);
+       
+       salmsg.from=from;
+       salmsg.text=msg;
+       salmsg.url=external_body_size>0 ? unquoted_external_body_url : NULL;
+       salmsg.message_id=message_id;
+       sal->callbacks.text_received(sal,&salmsg);
        osip_free(from);
 }