chat.c 4.35 KB
Newer Older
aymeric's avatar
aymeric committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/***************************************************************************
 *            chat.c
 *
 *  Sun Jun  5 19:34:18 2005
 *  Copyright  2005  Simon Morlat
 *  Email simon dot morlat at linphone dot org
 ****************************************************************************/

/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
24

25 26 27 28
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xmlwriter.h>

29 30
#include <linphone/utils/utils.h>

31
#include "linphone/core.h"
32
#include "private.h"
33
#include "linphone/lpconfig.h"
34
#include "belle-sip/belle-sip.h"
johan's avatar
johan committed
35
#include "ortp/b64.h"
36
#include "linphone/wrapper_utils.h"
Simon Morlat's avatar
Simon Morlat committed
37

38
#include "c-wrapper/c-wrapper.h"
Ronan's avatar
Ronan committed
39 40 41
#include "chat/chat-room/basic-chat-room.h"
#include "chat/chat-room/client-group-chat-room.h"
#include "chat/chat-room/real-time-text-chat-room-p.h"
42
#include "chat/chat-room/real-time-text-chat-room.h"
Ronan's avatar
Ronan committed
43
#include "content/content-type.h"
44
#include "core/core.h"
45

Ronan's avatar
Ronan committed
46 47
using namespace std;

48 49
void linphone_core_disable_chat(LinphoneCore *lc, LinphoneReason deny_reason) {
	lc->chat_deny_code = deny_reason;
Simon Morlat's avatar
Simon Morlat committed
50 51
}

52 53
void linphone_core_enable_chat(LinphoneCore *lc) {
	lc->chat_deny_code = LinphoneReasonNone;
Simon Morlat's avatar
Simon Morlat committed
54 55
}

56 57
bool_t linphone_core_chat_enabled(const LinphoneCore *lc) {
	return lc->chat_deny_code != LinphoneReasonNone;
Simon Morlat's avatar
Simon Morlat committed
58
}
Simon Morlat's avatar
Simon Morlat committed
59

60 61 62 63 64
const bctbx_list_t *linphone_core_get_chat_rooms (LinphoneCore *lc) {
	if (lc->chat_rooms)
		bctbx_list_free_with_data(lc->chat_rooms, (bctbx_list_free_func)linphone_chat_room_unref);
	lc->chat_rooms = L_GET_RESOLVED_C_LIST_FROM_CPP_LIST(lc->cppCore->getChatRooms());
	return lc->chat_rooms;
65 66
}

67
LinphoneChatRoom *_linphone_core_create_chat_room_from_call(LinphoneCall *call){
68
	LinphoneChatRoom *cr = linphone_chat_room_new(linphone_call_get_core(call),
69
		linphone_address_clone(linphone_call_get_remote_address(call)));
Ghislain MARY's avatar
Ghislain MARY committed
70
	linphone_chat_room_set_call(cr, call);
71 72 73
	return cr;
}

74 75
LinphoneChatRoom *linphone_core_get_chat_room (LinphoneCore *lc, const LinphoneAddress *addr) {
	return L_GET_C_BACK_PTR(lc->cppCore->getOrCreateBasicChatRoom(*L_GET_CPP_PTR_FROM_C_OBJECT(addr)));
76 77
}

78 79
LinphoneChatRoom *linphone_core_create_client_group_chat_room (LinphoneCore *lc, const char *subject) {
	return L_GET_C_BACK_PTR(lc->cppCore->createClientGroupChatRoom(L_C_TO_STRING(subject)));
80 81
}

82 83
void linphone_core_delete_chat_room (LinphoneCore *, LinphoneChatRoom *cr) {
	LinphonePrivate::Core::deleteChatRoom(L_GET_CPP_PTR_FROM_C_OBJECT(cr));
Simon Morlat's avatar
Simon Morlat committed
84 85
}

86
LinphoneChatRoom *linphone_core_get_chat_room_from_uri(LinphoneCore *lc, const char *to) {
87
	return L_GET_C_BACK_PTR(lc->cppCore->getOrCreateBasicChatRoom(L_C_TO_STRING(to)));
88
}
89

Ronan's avatar
Ronan committed
90
int linphone_core_message_received(LinphoneCore *lc, LinphonePrivate::SalOp *op, const SalMessage *sal_msg) {
91
	LinphoneReason reason = LinphoneReasonNotAcceptable;
92
	LinphoneChatRoom *cr = L_GET_C_BACK_PTR(lc->cppCore->findChatRoom(LinphonePrivate::Address(op->get_from())));
93 94 95 96 97 98 99 100 101 102
	if (cr)
		reason = L_GET_PRIVATE_FROM_C_OBJECT(cr)->messageReceived(op, sal_msg);
	else {
		LinphoneAddress *addr = linphone_address_new(sal_msg->from);
		linphone_address_clean(addr);
		cr = linphone_core_get_chat_room(lc, addr);
		if (cr)
			reason = L_GET_PRIVATE_FROM_C_OBJECT(cr)->messageReceived(op, sal_msg);
		linphone_address_unref(addr);
	}
103
	return reason;
aymeric's avatar
aymeric committed
104 105
}

Sylvain Berfini's avatar
Sylvain Berfini committed
106
void linphone_core_real_time_text_received(LinphoneCore *lc, LinphoneChatRoom *cr, uint32_t character, LinphoneCall *call) {
107
	if (linphone_core_realtime_text_enabled(lc)) {
Ronan's avatar
Ronan committed
108 109
		shared_ptr<LinphonePrivate::RealTimeTextChatRoom> rttcr =
			static_pointer_cast<LinphonePrivate::RealTimeTextChatRoom>(L_GET_CPP_PTR_FROM_C_OBJECT(cr));
110
		L_GET_PRIVATE(rttcr)->realtimeTextReceived(character, call);
Ronan's avatar
Ronan committed
111
		//L_GET_PRIVATE(static_pointer_cast<LinphonePrivate::RealTimeTextChatRoom>(L_GET_CPP_PTR_FROM_C_OBJECT(cr)))->realtimeTextReceived(character, call);
112
	}
113
}