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"
28 LinphoneChatRoom * linphone_core_create_chat_room(LinphoneCore *lc, const char *to){
29 LinphoneAddress *parsed_url=NULL;
31 if ((parsed_url=linphone_core_interpret_url(lc,to))!=NULL){
32 LinphoneChatRoom *cr=ms_new0(LinphoneChatRoom,1);
34 cr->peer=linphone_address_as_string(parsed_url);
35 cr->peer_url=parsed_url;
36 lc->chatrooms=ms_list_append(lc->chatrooms,(void *)cr);
43 void linphone_chat_room_destroy(LinphoneChatRoom *cr){
44 LinphoneCore *lc=cr->lc;
45 lc->chatrooms=ms_list_remove(lc->chatrooms,(void *) cr);
46 linphone_address_destroy(cr->peer_url);
49 sal_op_release(cr->op);
52 void linphone_chat_room_send_message(LinphoneChatRoom *cr, const char *msg){
53 const char *route=NULL;
54 const char *identity=linphone_core_find_best_identity(cr->lc,cr->peer_url,&route);
57 if((call = linphone_core_get_call_by_remote_address(cr->lc,cr->peer))!=NULL){
58 if (call->state==LinphoneCallConnected ||
59 call->state==LinphoneCallStreamsRunning ||
60 call->state==LinphoneCallPaused ||
61 call->state==LinphoneCallPausing ||
62 call->state==LinphoneCallPausedByRemote){
63 ms_message("send SIP message through the existing call.");
68 /*sending out of calls*/
69 op = sal_op_new(cr->lc->sal);
70 sal_op_set_route(op,route);
72 sal_op_release (cr->op);
77 sal_text_send(op,identity,cr->peer,msg);
80 bool_t linphone_chat_room_matches(LinphoneChatRoom *cr, const LinphoneAddress *from){
81 if (linphone_address_get_username(cr->peer_url) && linphone_address_get_username(from) &&
82 strcmp(linphone_address_get_username(cr->peer_url),linphone_address_get_username(from))==0) return TRUE;
86 void linphone_chat_room_text_received(LinphoneChatRoom *cr, LinphoneCore *lc, const LinphoneAddress *from, const char *msg){
87 if (lc->vtable.text_received!=NULL) lc->vtable.text_received(lc, cr, from, msg);
90 void linphone_core_text_received(LinphoneCore *lc, const char *from, const char *msg){
92 LinphoneChatRoom *cr=NULL;
93 LinphoneAddress *addr;
96 addr=linphone_address_new(from);
97 linphone_address_clean(addr);
98 for(elem=lc->chatrooms;elem!=NULL;elem=ms_list_next(elem)){
99 cr=(LinphoneChatRoom*)elem->data;
100 if (linphone_chat_room_matches(cr,addr)){
105 cleanfrom=linphone_address_as_string(addr);
107 /* create a new chat room */
108 cr=linphone_core_create_chat_room(lc,cleanfrom);
111 linphone_address_destroy(addr);
112 linphone_chat_room_text_received(cr,lc,cr->peer_url,msg);
117 void linphone_chat_room_set_user_data(LinphoneChatRoom *cr, void * ud){
120 void * linphone_chat_room_get_user_data(LinphoneChatRoom *cr){
121 return cr->user_data;
123 const LinphoneAddress* linphone_chat_room_get_peer_address(LinphoneChatRoom *cr) {