}
}
-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);
dtmf_received,
refer_received,
text_received,
- message_external_body_received,
text_delivery_update,
notify,
notify_presence,
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();
int max_calls;
LinphoneTunnel *tunnel;
char* device_id;
+ MSList *last_recv_msg_ids;
};
LinphoneTunnel *linphone_core_tunnel_new(LinphoneCore *lc);
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();
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);
SalOnDtmfReceived dtmf_received;
SalOnRefer refer_received;
SalOnTextReceived text_received;
- SalOnMessageExternalBodyReceived message_external_body;
SalOnTextDeliveryUpdate text_delivery_update;
SalOnNotify notify;
SalOnNotifyPresence notify_presence;
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){
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) {
&& 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
,&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);
}