1 /***************************************************************************
4 * Sun Jun 5 19:34:18 2005
5 * Copyright 2005 Simon Morlat
6 * Email simon dot morlat at linphone dot org
7 ****************************************************************************/
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include "linphonecore.h"
27 #include <eXosip2/eXosip.h>
29 LinphoneChatRoom * linphone_core_create_chat_room(LinphoneCore *lc, const char *to){
30 LinphoneAddress *parsed_url=NULL;
32 if (linphone_core_interpret_url(lc,to,&parsed_url,&route)){
33 LinphoneChatRoom *cr=ms_new0(LinphoneChatRoom,1);
35 cr->peer=linphone_address_as_string(parsed_url);
36 cr->peer_url=parsed_url;
38 lc->chatrooms=ms_list_append(lc->chatrooms,(void *)cr);
45 void linphone_chat_room_destroy(LinphoneChatRoom *cr){
46 LinphoneCore *lc=cr->lc;
47 lc->chatrooms=ms_list_remove(lc->chatrooms,(void *) cr);
48 linphone_address_destroy(cr->peer_url);
53 void linphone_chat_room_send_message(LinphoneChatRoom *cr, const char *msg){
54 const char *identity=linphone_core_get_identity(cr->lc);
55 osip_message_t *sip=NULL;
56 eXosip_message_build_request(&sip,"MESSAGE",cr->peer,identity,cr->route);
57 osip_message_set_content_type(sip,"text/plain");
58 osip_message_set_body(sip,msg,strlen(msg));
59 eXosip_message_send_request(sip);
62 bool_t linphone_chat_room_matches(LinphoneChatRoom *cr, const LinphoneAddress *from){
63 if (linphone_address_get_username(cr->peer_url) && linphone_address_get_username(from) &&
64 strcmp(linphone_address_get_username(cr->peer_url),linphone_address_get_username(from))==0) return TRUE;
68 void linphone_chat_room_text_received(LinphoneChatRoom *cr, LinphoneCore *lc, const char *from, const char *msg){
69 if (lc->vtable.text_received!=NULL) lc->vtable.text_received(lc, cr, from, msg);
72 void linphone_core_text_received(LinphoneCore *lc, eXosip_event_t *ev){
75 LinphoneChatRoom *cr=NULL;
77 osip_from_t *from_url=ev->request->from;
78 osip_body_t *body=NULL;
81 osip_message_get_body(ev->request,0,&body);
83 ms_error("Could not get text message from SIP body");
87 osip_from_to_str(from_url,&from);
88 uri=linphone_address_new(from);
90 linphone_address_clean(uri);
91 for(elem=lc->chatrooms;elem!=NULL;elem=ms_list_next(elem)){
92 cr=(LinphoneChatRoom*)elem->data;
93 if (linphone_chat_room_matches(cr,uri)){
98 from=linphone_address_as_string(uri);
100 /* create a new chat room */
101 cr=linphone_core_create_chat_room(lc,from);
103 linphone_address_destroy(uri);
104 linphone_chat_room_text_received(cr,lc,from,msg);
109 void linphone_chat_room_set_user_data(LinphoneChatRoom *cr, void * ud){
112 void * linphone_chat_room_get_user_data(LinphoneChatRoom *cr){
113 return cr->user_data;