Commit 00bd86e3 authored by Simon Morlat's avatar Simon Morlat
Browse files

implement checking of duplicated messages.

parent 5dd560b7
......@@ -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,
......
......@@ -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();
......
......@@ -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);
......
......@@ -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;
......
......@@ -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);
}
......
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