info.c 4.13 KB
Newer Older
Simon Morlat's avatar
Simon Morlat committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/***************************************************************************
 *            info.c
 *
 *  Thu May  16 11:48:01 2013
 *  Copyright  2013  Belledonne Communications SARL
 *  Author 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.
 */
 
26
#include "linphone/core.h"
Simon Morlat's avatar
Simon Morlat committed
27
#include "private.h"
28
#include "linphone/lpconfig.h"
Simon Morlat's avatar
Simon Morlat committed
29 30 31


struct _LinphoneInfoMessage{
32
	belle_sip_object_t base;
33
	LinphoneContent *content;
Simon Morlat's avatar
Simon Morlat committed
34 35 36
	SalCustomHeader *headers;
};

37 38
static void _linphone_info_message_uninit(LinphoneInfoMessage *im);
static void _linphone_info_message_copy(LinphoneInfoMessage *im, const LinphoneInfoMessage *orig);
Simon Morlat's avatar
Simon Morlat committed
39

40
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneInfoMessage);
Ghislain MARY's avatar
Ghislain MARY committed
41
BELLE_SIP_DECLARE_VPTR_NO_EXPORT(LinphoneInfoMessage);
42 43 44 45 46 47 48 49
BELLE_SIP_INSTANCIATE_VPTR(LinphoneInfoMessage, belle_sip_object_t,
	_linphone_info_message_uninit, // uninit
	_linphone_info_message_copy, // clone
	NULL, // marshal
	FALSE
);

static void _linphone_info_message_uninit(LinphoneInfoMessage *im) {
50 51
	if (im->content) linphone_content_unref(im->content);
	if (im->headers) sal_custom_header_free(im->headers);
Simon Morlat's avatar
Simon Morlat committed
52 53
}

54 55 56 57 58 59 60
LinphoneInfoMessage *linphone_info_message_ref(LinphoneInfoMessage *im) {
	return (LinphoneInfoMessage *)belle_sip_object_ref(im);
}

void linphone_info_message_unref(LinphoneInfoMessage *im) {
	belle_sip_object_unref(im);
}
61

62 63 64 65 66
void linphone_info_message_destroy(LinphoneInfoMessage *im){
	linphone_info_message_unref(im);
}

static void _linphone_info_message_copy(LinphoneInfoMessage *im, const LinphoneInfoMessage *orig) {
67
	if (orig->content) im->content=linphone_content_copy(orig->content);
68
	if (orig->headers) im->headers=sal_custom_header_clone(orig->headers);
69 70 71 72
}

LinphoneInfoMessage *linphone_info_message_copy(const LinphoneInfoMessage *orig){
	return (LinphoneInfoMessage *)belle_sip_object_clone((const belle_sip_object_t *)orig);
73 74
}

Simon Morlat's avatar
Simon Morlat committed
75
LinphoneInfoMessage *linphone_core_create_info_message(LinphoneCore *lc){
76
	return belle_sip_object_new(LinphoneInfoMessage);
Simon Morlat's avatar
Simon Morlat committed
77 78
}

79
LinphoneStatus linphone_call_send_info_message(LinphoneCall *call, const LinphoneInfoMessage *info) {
80 81 82
	SalBodyHandler *body_handler = sal_body_handler_from_content(info->content);
	sal_op_set_sent_custom_header(call->op, info->headers);
	return sal_send_info(call->op,NULL, NULL, body_handler);
Simon Morlat's avatar
Simon Morlat committed
83 84 85 86 87 88 89
}

void linphone_info_message_add_header(LinphoneInfoMessage *im, const char *name, const char *value){
	im->headers=sal_custom_header_append(im->headers, name, value);
}

const char *linphone_info_message_get_header(const LinphoneInfoMessage *im, const char *name){
90
	return sal_custom_header_find(im->headers,name);
Simon Morlat's avatar
Simon Morlat committed
91 92 93
}

void linphone_info_message_set_content(LinphoneInfoMessage *im,  const LinphoneContent *content){
94
	im->content=linphone_content_copy(content);
Simon Morlat's avatar
Simon Morlat committed
95 96 97
}

const LinphoneContent * linphone_info_message_get_content(const LinphoneInfoMessage *im){
98
	return (im->content && linphone_content_get_type(im->content)) ? im->content : NULL;
Simon Morlat's avatar
Simon Morlat committed
99 100
}

101
void linphone_core_notify_info_message(LinphoneCore* lc,SalOp *op, SalBodyHandler *body_handler){
102 103
	LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
	if (call){
104
		LinphoneInfoMessage *info=linphone_core_create_info_message(lc);
105
		info->headers=sal_custom_header_clone(sal_op_get_recv_custom_header(op));
106
		if (body_handler) info->content=linphone_content_from_sal_body_handler(body_handler);
107
		linphone_call_notify_info_message_received(call, info);
108
		linphone_info_message_unref(info);
109
	}
Simon Morlat's avatar
Simon Morlat committed
110
}