void linphone_core_message_received(LinphoneCore *lc, const char *from, const char *raw_msg,const char* external_url) { MSList *elem; LinphoneChatRoom *cr=NULL; LinphoneAddress *addr; char *cleanfrom; LinphoneChatMessage* msg; addr=linphone_address_new(from); linphone_address_clean(addr); for(elem=lc->chatrooms; elem!=NULL; elem=ms_list_next(elem)) { cr=(LinphoneChatRoom*)elem->data; if (linphone_chat_room_matches(cr,addr)) { break; } cr=NULL; } cleanfrom=linphone_address_as_string(addr); if (cr==NULL) { /* create a new chat room */ cr=linphone_core_create_chat_room(lc,cleanfrom); } msg = linphone_chat_room_create_message(cr, raw_msg); linphone_chat_message_set_from(msg, cr->peer_url); if (external_url) { linphone_chat_message_set_external_body_url(msg, external_url); } linphone_address_destroy(addr); linphone_chat_room_message_received(cr,lc,msg); ms_free(cleanfrom); }
void linphone_core_message_received(LinphoneCore *lc, SalOp *op, const SalMessage *sal_msg){ LinphoneChatRoom *cr=NULL; LinphoneAddress *addr; char *cleanfrom; char *from; LinphoneChatMessage* msg; const SalCustomHeader *ch; addr=linphone_address_new(sal_msg->from); linphone_address_clean(addr); cr=linphone_core_get_chat_room(lc,addr); cleanfrom=linphone_address_as_string(addr); from=linphone_address_as_string_uri_only(addr); if (cr==NULL){ /* create a new chat room */ cr=linphone_core_create_chat_room(lc,cleanfrom); } msg = linphone_chat_room_create_message(cr, sal_msg->text); linphone_chat_message_set_from(msg, cr->peer_url); { LinphoneAddress *to; to=sal_op_get_to(op) ? linphone_address_new(sal_op_get_to(op)) : linphone_address_new(linphone_core_get_identity(lc)); msg->to=to; } msg->time=sal_msg->time; msg->state=LinphoneChatMessageStateDelivered; msg->is_read=FALSE; msg->dir=LinphoneChatMessageIncoming; ch=sal_op_get_recv_custom_header(op); if (ch) msg->custom_headers=sal_custom_header_clone(ch); if (sal_msg->url) { linphone_chat_message_set_external_body_url(msg, sal_msg->url); } linphone_address_destroy(addr); msg->storage_id=linphone_chat_message_store(msg); linphone_chat_room_message_received(cr,lc,msg); ms_free(cleanfrom); ms_free(from); }