info.c 4.38 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 26 27 28 29 30 31
/***************************************************************************
 *            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.
 */
 
#include "linphonecore.h"
#include "private.h"
#include "lpconfig.h"


struct _LinphoneInfoMessage{
32
	LinphoneContent *content;
Simon Morlat's avatar
Simon Morlat committed
33 34 35 36 37 38 39 40
	SalCustomHeader *headers;
};


/**
 * Destroy a LinphoneInfoMessage
**/
void linphone_info_message_destroy(LinphoneInfoMessage *im){
41 42
	if (im->content) linphone_content_unref(im->content);
	if (im->headers) sal_custom_header_free(im->headers);
Simon Morlat's avatar
Simon Morlat committed
43 44 45
	ms_free(im);
}

46 47 48

LinphoneInfoMessage *linphone_info_message_copy(const LinphoneInfoMessage *orig){
	LinphoneInfoMessage *im=ms_new0(LinphoneInfoMessage,1);
49
	if (orig->content) im->content=linphone_content_copy(orig->content);
50 51 52 53
	if (orig->headers) im->headers=sal_custom_header_clone(orig->headers);
	return im;
}

Simon Morlat's avatar
Simon Morlat committed
54 55
/**
 * Creates an empty info message.
56
 * @param lc the LinphoneCore
Simon Morlat's avatar
Simon Morlat committed
57 58 59 60 61 62 63 64 65 66 67
 * @return a new LinphoneInfoMessage.
 * 
 * The info message can later be filled with information using linphone_info_message_add_header() or linphone_info_message_set_content(),
 * and finally sent with linphone_core_send_info_message().
**/
LinphoneInfoMessage *linphone_core_create_info_message(LinphoneCore *lc){
	LinphoneInfoMessage *im=ms_new0(LinphoneInfoMessage,1);
	return im;
}

/**
68 69
 * Send a LinphoneInfoMessage through an established call
 * @param call the call
Simon Morlat's avatar
Simon Morlat committed
70 71
 * @param info the info message
**/
72 73 74 75
int linphone_call_send_info_message(LinphoneCall *call, const LinphoneInfoMessage *info) {
	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
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
}

/**
 * Add a header to an info message to be sent.
 * @param im the info message
 * @param name the header'name
 * @param value the header's value
**/
void linphone_info_message_add_header(LinphoneInfoMessage *im, const char *name, const char *value){
	im->headers=sal_custom_header_append(im->headers, name, value);
}

/**
 * Obtain a header value from a received info message.
 * @param im the info message
 * @param name the header'name
 * @return the corresponding header's value, or NULL if not exists.
**/
const char *linphone_info_message_get_header(const LinphoneInfoMessage *im, const char *name){
95
	return sal_custom_header_find(im->headers,name);
Simon Morlat's avatar
Simon Morlat committed
96 97 98 99 100 101 102 103 104
}

/**
 * Assign a content to the info message.
 * @param im the linphone info message
 * @param content the content described as a #LinphoneContent structure.
 * All fields of the LinphoneContent are copied, thus the application can destroy/modify/recycloe the content object freely ater the function returns.
**/
void linphone_info_message_set_content(LinphoneInfoMessage *im,  const LinphoneContent *content){
105
	im->content=linphone_content_copy(content);
Simon Morlat's avatar
Simon Morlat committed
106 107 108 109 110 111
}

/**
 * Returns the info message's content as a #LinphoneContent structure.
**/
const LinphoneContent * linphone_info_message_get_content(const LinphoneInfoMessage *im){
112
	return (im->content && linphone_content_get_type(im->content)) ? im->content : NULL;
Simon Morlat's avatar
Simon Morlat committed
113 114
}

115
void linphone_core_notify_info_message(LinphoneCore* lc,SalOp *op, SalBodyHandler *body_handler){
116 117 118 119
	LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
	if (call){
		LinphoneInfoMessage *info=ms_new0(LinphoneInfoMessage,1);
		info->headers=sal_custom_header_clone(sal_op_get_recv_custom_header(op));
120
		if (body_handler) info->content=linphone_content_from_sal_body_handler(body_handler);
121
		linphone_core_notify_info_received(lc,call,info);
122 123
		linphone_info_message_destroy(info);
	}
Simon Morlat's avatar
Simon Morlat committed
124
}