info.c 3.8 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
/***************************************************************************
 *            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.
 */
25

26
#include "linphone/api/c-content.h"
27 28
#include "linphone/core.h"
#include "linphone/lpconfig.h"
Simon Morlat's avatar
Simon Morlat committed
29

30
#include "c-wrapper/c-wrapper.h"
Simon Morlat's avatar
Simon Morlat committed
31 32

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

38 39
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
40

41
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneInfoMessage);
Ghislain MARY's avatar
Ghislain MARY committed
42
BELLE_SIP_DECLARE_VPTR_NO_EXPORT(LinphoneInfoMessage);
43 44 45 46 47 48 49 50
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) {
51 52
	if (im->content) linphone_content_unref(im->content);
	if (im->headers) sal_custom_header_free(im->headers);
Simon Morlat's avatar
Simon Morlat committed
53 54
}

55 56 57 58 59 60 61
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);
}
62

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

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

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

Simon Morlat's avatar
Simon Morlat committed
76
LinphoneInfoMessage *linphone_core_create_info_message(LinphoneCore *lc){
77
	return belle_sip_object_new(LinphoneInfoMessage);
Simon Morlat's avatar
Simon Morlat committed
78 79 80 81 82 83 84
}

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){
85
	return sal_custom_header_find(im->headers,name);
Simon Morlat's avatar
Simon Morlat committed
86 87
}

88 89 90 91
void linphone_info_message_set_content (LinphoneInfoMessage *im, const LinphoneContent *content) {
	if (im->content)
		linphone_content_unref(im->content);
	im->content = linphone_content_copy(content);
Simon Morlat's avatar
Simon Morlat committed
92 93 94
}

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

98 99 100 101
SalCustomHeader *linphone_info_message_get_headers (const LinphoneInfoMessage *im) {
	return im->headers;
}

102 103 104 105
void linphone_info_message_set_headers (LinphoneInfoMessage *im, const SalCustomHeader *headers) {
	if (im->headers) {
		sal_custom_header_free(im->headers);
		im->headers = nullptr;
106
	}
107 108
	if (headers)
		im->headers = sal_custom_header_clone(headers);
Simon Morlat's avatar
Simon Morlat committed
109
}