Commit edd42fcf authored by Ghislain MARY's avatar Ghislain MARY
Browse files

Rework sal to be able multipart LinphoneContent objects.

parent 96d249c6
......@@ -166,8 +166,7 @@ belle_sip_response_t *sal_create_response_from_request(Sal *sal, belle_sip_reque
void sal_op_assign_recv_headers(SalOp *op, belle_sip_message_t *incoming);
void sal_op_add_body(SalOp *op, belle_sip_message_t *req, const SalBody *body);
bool_t sal_op_get_body(SalOp *op, belle_sip_message_t *msg, SalBody *salbody);
SalBodyHandler * sal_op_get_body_handler(SalOp *op, belle_sip_message_t *msg);
SalReason sal_reason_to_sip_code(SalReason r);
......
......@@ -669,15 +669,19 @@ static void process_request_event(void *op_base, const belle_sip_request_event_t
}
}else{
SalBody salbody;
if (sal_op_get_body(op,(belle_sip_message_t*)req,&salbody)) {
if (sal_body_has_type(&salbody,"application","dtmf-relay")){
belle_sip_message_t *msg = BELLE_SIP_MESSAGE(req);
belle_sip_body_handler_t *body_handler = BELLE_SIP_BODY_HANDLER(sal_op_get_body_handler(op, msg));
if (body_handler) {
belle_sip_header_content_type_t *content_type = belle_sip_message_get_header_by_type(msg, belle_sip_header_content_type_t);
if (content_type
&& (strcmp(belle_sip_header_content_type_get_type(content_type), "application") == 0)
&& (strcmp(belle_sip_header_content_type_get_subtype(content_type), "dtmf-relay") == 0)) {
char tmp[10];
if (sal_lines_get_value(salbody.data, "Signal",tmp, sizeof(tmp))){
if (sal_lines_get_value(belle_sip_message_get_body(msg), "Signal",tmp, sizeof(tmp))){
op->base.root->callbacks.dtmf_received(op,tmp[0]);
}
}else
op->base.root->callbacks.info_received(op,&salbody);
op->base.root->callbacks.info_received(op, (SalBodyHandler *)body_handler);
} else {
op->base.root->callbacks.info_received(op,NULL);
}
......
......@@ -77,7 +77,7 @@ static void subscribe_process_timeout(void *user_ctx, const belle_sip_timeout_ev
static void subscribe_process_transaction_terminated(void *user_ctx, const belle_sip_transaction_terminated_event_t *event) {
}
static void handle_notify(SalOp *op, belle_sip_request_t *req, const char *eventname, SalBody * body){
static void handle_notify(SalOp *op, belle_sip_request_t *req, const char *eventname, SalBodyHandler* body_handler){
SalSubscribeStatus sub_state;
belle_sip_header_subscription_state_t* subscription_state_header=belle_sip_message_get_header_by_type(req,belle_sip_header_subscription_state_t);
belle_sip_response_t* resp;
......@@ -89,7 +89,7 @@ static void handle_notify(SalOp *op, belle_sip_request_t *req, const char *event
} else
sub_state=SalSubscribeActive;
sal_op_ref(op);
op->base.root->callbacks.notify(op,sub_state,eventname,body);
op->base.root->callbacks.notify(op,sub_state,eventname,body_handler);
resp=sal_op_create_response_from_request(op,req,200);
belle_sip_server_transaction_send_response(server_transaction,resp);
sal_op_unref(op);
......@@ -102,7 +102,7 @@ static void subscribe_process_request_event(void *op_base, const belle_sip_reque
belle_sip_dialog_state_t dialog_state;
belle_sip_header_expires_t* expires = belle_sip_message_get_header_by_type(req,belle_sip_header_expires_t);
belle_sip_header_t *event_header;
SalBody body;
belle_sip_body_handler_t *body_handler;
belle_sip_response_t* resp;
const char *eventname=NULL;
const char *method=belle_sip_request_get_method(req);
......@@ -112,7 +112,7 @@ static void subscribe_process_request_event(void *op_base, const belle_sip_reque
op->pending_server_trans=server_transaction;
event_header=belle_sip_message_get_header((belle_sip_message_t*)req,"Event");
sal_op_get_body(op,(belle_sip_message_t*)req,&body);
body_handler = BELLE_SIP_BODY_HANDLER(sal_op_get_body_handler(op, BELLE_SIP_MESSAGE(req)));
if (event_header==NULL){
ms_warning("No event header in incoming SUBSCRIBE.");
......@@ -132,7 +132,7 @@ static void subscribe_process_request_event(void *op_base, const belle_sip_reque
belle_sip_dialog_set_application_data(op->dialog, sal_op_ref(op));
ms_message("new incoming subscription from [%s] to [%s]",sal_op_get_from(op),sal_op_get_to(op));
}else{ /*this is a NOTIFY*/
handle_notify(op,req,eventname,&body);
handle_notify(op, req, eventname, (SalBodyHandler *)body_handler);
return;
}
}
......@@ -140,7 +140,10 @@ static void subscribe_process_request_event(void *op_base, const belle_sip_reque
switch(dialog_state) {
case BELLE_SIP_DIALOG_NULL: {
op->base.root->callbacks.subscribe_received(op,eventname,body.type ? &body : NULL);
const char *type = NULL;
belle_sip_header_content_type_t *content_type = belle_sip_message_get_header_by_type(BELLE_SIP_MESSAGE(req), belle_sip_header_content_type_t);
if (content_type) type = belle_sip_header_content_type_get_type(content_type);
op->base.root->callbacks.subscribe_received(op, eventname, type ? (SalBodyHandler *)body_handler : NULL);
break;
}
case BELLE_SIP_DIALOG_EARLY:
......@@ -149,7 +152,7 @@ static void subscribe_process_request_event(void *op_base, const belle_sip_reque
case BELLE_SIP_DIALOG_CONFIRMED:
if (strcmp("NOTIFY",method)==0) {
handle_notify(op,req,eventname,&body);
handle_notify(op, req, eventname, (SalBodyHandler *)body_handler);
} else if (strcmp("SUBSCRIBE",method)==0) {
/*either a refresh of an unsubscribe*/
if (expires && belle_sip_header_expires_get_expires(expires)>0) {
......@@ -185,7 +188,7 @@ void sal_op_subscribe_fill_cbs(SalOp*op) {
}
int sal_subscribe(SalOp *op, const char *from, const char *to, const char *eventname, int expires, const SalBody *body){
int sal_subscribe(SalOp *op, const char *from, const char *to, const char *eventname, int expires, const SalBodyHandler *body_handler){
belle_sip_request_t *req=NULL;
if (from)
......@@ -207,13 +210,13 @@ int sal_subscribe(SalOp *op, const char *from, const char *to, const char *event
}
belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),op->event);
belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(belle_sip_header_expires_create(expires)));
sal_op_add_body(op,(belle_sip_message_t*)req,body);
belle_sip_message_set_body_handler(BELLE_SIP_MESSAGE(req), BELLE_SIP_BODY_HANDLER(body_handler));
return sal_op_send_and_create_refresher(op,req,expires,subscribe_refresher_listener);
}else if (op->refresher){
const belle_sip_transaction_t *tr=(const belle_sip_transaction_t*) belle_sip_refresher_get_transaction(op->refresher);
belle_sip_request_t *last_req=belle_sip_transaction_get_request(tr);
/* modify last request to update body*/
sal_op_add_body(op,(belle_sip_message_t*)last_req,body);
belle_sip_message_set_body_handler(BELLE_SIP_MESSAGE(last_req), BELLE_SIP_BODY_HANDLER(body_handler));
return belle_sip_refresher_refresh(op->refresher,expires);
}
ms_warning("sal_subscribe(): no dialog and no refresher ?");
......@@ -224,7 +227,7 @@ int sal_unsubscribe(SalOp *op){
if (op->refresher){
const belle_sip_transaction_t *tr=(const belle_sip_transaction_t*) belle_sip_refresher_get_transaction(op->refresher);
belle_sip_request_t *last_req=belle_sip_transaction_get_request(tr);
sal_op_add_body(op,(belle_sip_message_t*)last_req,NULL);
belle_sip_message_set_body(BELLE_SIP_MESSAGE(last_req), NULL, 0);
belle_sip_refresher_refresh(op->refresher,0);
return 0;
}
......@@ -247,7 +250,7 @@ int sal_subscribe_decline(SalOp *op, SalReason reason){
return 0;
}
int sal_notify(SalOp *op, const SalBody *body){
int sal_notify(SalOp *op, const SalBodyHandler *body_handler){
belle_sip_request_t* notify;
if (!op->dialog) return -1;
......@@ -258,8 +261,7 @@ int sal_notify(SalOp *op, const SalBody *body){
belle_sip_message_add_header(BELLE_SIP_MESSAGE(notify)
,BELLE_SIP_HEADER(belle_sip_header_subscription_state_create(BELLE_SIP_SUBSCRIPTION_STATE_ACTIVE,600)));
sal_op_add_body(op,(belle_sip_message_t*)notify, body);
belle_sip_message_set_body_handler(BELLE_SIP_MESSAGE(notify), BELLE_SIP_BODY_HANDLER(body_handler));
return sal_op_send_request(op,notify);
}
......
......@@ -706,50 +706,17 @@ const char *sal_op_get_remote_contact(const SalOp *op){
return op->base.remote_contact;
}
void sal_op_add_body(SalOp *op, belle_sip_message_t *req, const SalBody *body){
belle_sip_message_remove_header((belle_sip_message_t*)req,"Content-type");
belle_sip_message_remove_header((belle_sip_message_t*)req,"Content-length");
belle_sip_message_remove_header((belle_sip_message_t*)req,"Content-encoding");
belle_sip_message_set_body((belle_sip_message_t*)req,NULL,0);
if (body && body->type && body->subtype && body->data){
belle_sip_message_add_header((belle_sip_message_t*)req,
(belle_sip_header_t*)belle_sip_header_content_type_create(body->type,body->subtype));
belle_sip_message_add_header((belle_sip_message_t*)req,
(belle_sip_header_t*)belle_sip_header_content_length_create(body->size));
belle_sip_message_set_body((belle_sip_message_t*)req,(const char*)body->data,body->size);
if (body->encoding){
belle_sip_message_add_header((belle_sip_message_t*)req,(belle_sip_header_t*)
belle_sip_header_create("Content-encoding",body->encoding));
}
}
}
bool_t sal_op_get_body(SalOp *op, belle_sip_message_t *msg, SalBody *salbody){
const char *body = NULL;
belle_sip_header_content_type_t *content_type;
belle_sip_header_content_length_t *clen=NULL;
belle_sip_header_t *content_encoding;
content_type=belle_sip_message_get_header_by_type(msg,belle_sip_header_content_type_t);
if (content_type){
body=belle_sip_message_get_body(msg);
clen=belle_sip_message_get_header_by_type(msg,belle_sip_header_content_length_t);
}
content_encoding=belle_sip_message_get_header(msg,"Content-encoding");
memset(salbody,0,sizeof(SalBody));
if (content_type && body && clen) {
salbody->type=belle_sip_header_content_type_get_type(content_type);
salbody->subtype=belle_sip_header_content_type_get_subtype(content_type);
salbody->data=body;
salbody->size=belle_sip_header_content_length_get_content_length(clen);
if (content_encoding)
salbody->encoding=belle_sip_header_get_unparsed_value(content_encoding);
return TRUE;
}
return FALSE;
SalBodyHandler * sal_op_get_body_handler(SalOp *op, belle_sip_message_t *msg) {
belle_sip_body_handler_t *body_handler = belle_sip_message_get_body_handler(msg);
if (body_handler != NULL) {
belle_sip_header_content_type_t *content_type = belle_sip_message_get_header_by_type(msg, belle_sip_header_content_type_t);
belle_sip_header_content_length_t *content_length = belle_sip_message_get_header_by_type(msg, belle_sip_header_content_length_t);
belle_sip_header_t *content_encoding = belle_sip_message_get_header(msg, "Content-Encoding");
if (content_type != NULL) belle_sip_body_handler_add_header(body_handler, BELLE_SIP_HEADER(content_type));
if (content_length != NULL) belle_sip_body_handler_add_header(body_handler, BELLE_SIP_HEADER(content_length));
if (content_encoding != NULL) belle_sip_body_handler_add_header(body_handler, content_encoding);
}
return (SalBodyHandler *)body_handler;
}
void sal_op_set_privacy(SalOp* op,SalPrivacyMask privacy) {
......
......@@ -19,12 +19,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "sal_impl.h"
int sal_send_info(SalOp *op, const char *from, const char *to, const SalBody *body){
int sal_send_info(SalOp *op, const char *from, const char *to, const SalBodyHandler *body_handler){
if (op->dialog){
belle_sip_request_t *req;
belle_sip_dialog_enable_pending_trans_checking(op->dialog,op->base.root->pending_trans_checking);
req=belle_sip_dialog_create_queued_request(op->dialog,"INFO");
sal_op_add_body(op,(belle_sip_message_t*)req,body);
belle_sip_message_set_body_handler(BELLE_SIP_MESSAGE(req), BELLE_SIP_BODY_HANDLER(body_handler));
return sal_op_send_request(op,req);
}
return -1;
......
......@@ -96,7 +96,7 @@ int sal_publish_presence(SalOp *op, const char *from, const char *to, int expire
}
}
int sal_publish(SalOp *op, const char *from, const char *to, const char *eventname, int expires, const SalBody *body){
int sal_publish(SalOp *op, const char *from, const char *to, const char *eventname, int expires, const SalBodyHandler *body_handler){
belle_sip_request_t *req=NULL;
if(!op->refresher || !belle_sip_refresher_get_transaction(op->refresher)) {
if (from)
......@@ -114,7 +114,7 @@ int sal_publish(SalOp *op, const char *from, const char *to, const char *eventna
belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(sal_op_create_contact(op)));
}
belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),belle_sip_header_create("Event",eventname));
sal_op_add_body(op,BELLE_SIP_MESSAGE(req),body);
belle_sip_message_set_body_handler(BELLE_SIP_MESSAGE(req), BELLE_SIP_BODY_HANDLER(body_handler));
if (expires!=-1)
return sal_op_send_and_create_refresher(op,req,expires,publish_refresher_listener);
else return sal_op_send_request(op,req);
......@@ -123,7 +123,11 @@ int sal_publish(SalOp *op, const char *from, const char *to, const char *eventna
const belle_sip_client_transaction_t* last_publish_trans=belle_sip_refresher_get_transaction(op->refresher);
belle_sip_request_t* last_publish=belle_sip_transaction_get_request(BELLE_SIP_TRANSACTION(last_publish_trans));
/*update body*/
sal_op_add_body(op,BELLE_SIP_MESSAGE(last_publish),expires!=0 ? body : NULL);
if (expires == 0) {
belle_sip_message_set_body(BELLE_SIP_MESSAGE(last_publish), NULL, 0);
} else {
belle_sip_message_set_body_handler(BELLE_SIP_MESSAGE(last_publish), BELLE_SIP_BODY_HANDLER(body_handler));
}
return belle_sip_refresher_refresh(op->refresher,expires==-1 ? BELLE_SIP_REFRESHER_REUSE_EXPIRES : expires);
}
}
......@@ -1276,9 +1276,9 @@ static void text_delivery_update(SalOp *op, SalTextDeliveryStatus status){
}
}
static void info_received(SalOp *op, const SalBody *body){
static void info_received(SalOp *op, SalBodyHandler *body_handler){
LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
linphone_core_notify_info_message(lc,op,body);
linphone_core_notify_info_message(lc,op,body_handler);
}
static void subscribe_response(SalOp *op, SalSubscribeStatus status){
......@@ -1299,7 +1299,7 @@ static void subscribe_response(SalOp *op, SalSubscribeStatus status){
}
}
static void notify(SalOp *op, SalSubscribeStatus st, const char *eventname, const SalBody *body){
static void notify(SalOp *op, SalSubscribeStatus st, const char *eventname, SalBodyHandler *body_handler){
LinphoneEvent *lev=(LinphoneEvent*)sal_op_get_user_pointer(op);
LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
......@@ -1308,7 +1308,7 @@ static void notify(SalOp *op, SalSubscribeStatus st, const char *eventname, cons
lev=linphone_event_new_with_out_of_dialog_op(lc,op,LinphoneSubscriptionOutgoing,eventname);
}
{
LinphoneContent *ct=linphone_content_from_sal_body(body);
LinphoneContent *ct=linphone_content_from_sal_body_handler(body_handler);
if (ct) linphone_core_notify_notify_received(lc,lev,eventname,ct);
}
if (st!=SalSubscribeNone){
......@@ -1316,7 +1316,7 @@ static void notify(SalOp *op, SalSubscribeStatus st, const char *eventname, cons
}
}
static void subscribe_received(SalOp *op, const char *eventname, const SalBody *body){
static void subscribe_received(SalOp *op, const char *eventname, const SalBodyHandler *body_handler){
LinphoneEvent *lev=(LinphoneEvent*)sal_op_get_user_pointer(op);
LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
......
......@@ -215,8 +215,7 @@ static void linphone_chat_message_process_response_from_post_file(void *data,
linphone_content_get_subtype(msg->file_transfer_information)));
/* insert it in a multipart body handler which will manage the boundaries of multipart msg */
bh = belle_sip_multipart_body_handler_new(linphone_chat_message_file_transfer_on_progress, msg,
first_part_bh);
bh = belle_sip_multipart_body_handler_new(linphone_chat_message_file_transfer_on_progress, msg, first_part_bh, NULL);
linphone_chat_message_ref(msg);
_release_http_request(msg);
......
......@@ -22,23 +22,46 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static void linphone_content_set_sal_body_handler(LinphoneContent *content, SalBodyHandler *body_handler) {
if (content->body_handler != NULL) {
sal_body_handler_unref(content->body_handler);
content->body_handler = NULL;
}
content->body_handler = sal_body_handler_ref(body_handler);
}
static LinphoneContent * linphone_content_new_with_body_handler(SalBodyHandler *body_handler) {
LinphoneContent *content = belle_sip_object_new(LinphoneContent);
belle_sip_object_ref(content);
content->owned_fields = TRUE;
content->cryptoContext = NULL; /* this field is managed externally by encryption/decryption functions so be careful to initialise it to NULL */
if (body_handler == NULL) {
linphone_content_set_sal_body_handler(content, sal_body_handler_new());
} else {
linphone_content_set_sal_body_handler(content, body_handler);
}
return content;
}
static void linphone_content_destroy(LinphoneContent *content) {
if (content->owned_fields == TRUE) {
if (content->lcp.type) belle_sip_free(content->lcp.type);
if (content->lcp.subtype) belle_sip_free(content->lcp.subtype);
if (content->lcp.data) belle_sip_free(content->lcp.data);
if (content->lcp.encoding) belle_sip_free(content->lcp.encoding);
if (content->lcp.name) belle_sip_free(content->lcp.name);
if (content->lcp.key) belle_sip_free(content->lcp.key);
if (content->body_handler) sal_body_handler_unref(content->body_handler);
if (content->name) belle_sip_free(content->name);
if (content->key) belle_sip_free(content->key);
/* note : crypto context is allocated/destroyed by the encryption function */
}
}
static void linphone_content_clone(LinphoneContent *obj, const LinphoneContent *ref) {
obj->owned_fields = TRUE;
linphone_content_set_type(obj, linphone_content_get_type(ref));
linphone_content_set_subtype(obj, linphone_content_get_subtype(ref));
linphone_content_set_encoding(obj, linphone_content_get_encoding(ref));
linphone_content_set_sal_body_handler(obj, sal_body_handler_new());
if ((linphone_content_get_type(ref) != NULL) || (linphone_content_get_subtype(ref) != NULL)) {
linphone_content_set_type(obj, linphone_content_get_type(ref));
linphone_content_set_subtype(obj, linphone_content_get_subtype(ref));
}
if (linphone_content_get_encoding(ref) != NULL) {
linphone_content_set_encoding(obj, linphone_content_get_encoding(ref));
}
linphone_content_set_name(obj, linphone_content_get_name(ref));
linphone_content_set_key(obj, linphone_content_get_key(ref), linphone_content_get_key_size(ref));
if (linphone_content_get_buffer(ref) != NULL) {
......@@ -81,163 +104,138 @@ void linphone_content_set_user_data(LinphoneContent *content, void *ud) {
}
const char * linphone_content_get_type(const LinphoneContent *content) {
return content->lcp.type;
return sal_body_handler_get_type(content->body_handler);
}
void linphone_content_set_type(LinphoneContent *content, const char *type) {
if (content->lcp.type != NULL) {
belle_sip_free(content->lcp.type);
content->lcp.type = NULL;
}
if (type != NULL) {
content->lcp.type = belle_sip_strdup(type);
}
sal_body_handler_set_type(content->body_handler, type);
}
const char * linphone_content_get_subtype(const LinphoneContent *content) {
return content->lcp.subtype;
return sal_body_handler_get_subtype(content->body_handler);
}
void linphone_content_set_subtype(LinphoneContent *content, const char *subtype) {
if (content->lcp.subtype != NULL) {
belle_sip_free(content->lcp.subtype);
content->lcp.subtype = NULL;
}
if (subtype != NULL) {
content->lcp.subtype = belle_sip_strdup(subtype);
}
sal_body_handler_set_subtype(content->body_handler, subtype);
}
void * linphone_content_get_buffer(const LinphoneContent *content) {
return content->lcp.data;
return sal_body_handler_get_data(content->body_handler);
}
void linphone_content_set_buffer(LinphoneContent *content, const void *buffer, size_t size) {
content->lcp.size = size;
content->lcp.data = belle_sip_malloc(size + 1);
memcpy(content->lcp.data, buffer, size);
((char *)content->lcp.data)[size] = '\0';
void *data;
sal_body_handler_set_size(content->body_handler, size);
data = belle_sip_malloc(size + 1);
memcpy(data, buffer, size);
((char *)data)[size] = '\0';
sal_body_handler_set_data(content->body_handler, data);
}
const char * linphone_content_get_string_buffer(const LinphoneContent *content) {
return (char *)content->lcp.data;
return (const char *)linphone_content_get_buffer(content);
}
void linphone_content_set_string_buffer(LinphoneContent *content, const char *buffer) {
content->lcp.size = strlen(buffer);
content->lcp.data = belle_sip_strdup(buffer);
sal_body_handler_set_size(content->body_handler, strlen(buffer));
sal_body_handler_set_data(content->body_handler, belle_sip_strdup(buffer));
}
size_t linphone_content_get_size(const LinphoneContent *content) {
return content->lcp.size;
return sal_body_handler_get_size(content->body_handler);
}
void linphone_content_set_size(LinphoneContent *content, size_t size) {
content->lcp.size = size;
sal_body_handler_set_size(content->body_handler, size);
}
const char * linphone_content_get_encoding(const LinphoneContent *content) {
return content->lcp.encoding;
return sal_body_handler_get_encoding(content->body_handler);
}
void linphone_content_set_encoding(LinphoneContent *content, const char *encoding) {
if (content->lcp.encoding != NULL) {
belle_sip_free(content->lcp.encoding);
content->lcp.encoding = NULL;
}
if (encoding != NULL) {
content->lcp.encoding = belle_sip_strdup(encoding);
}
sal_body_handler_set_encoding(content->body_handler, encoding);
}
const char * linphone_content_get_name(const LinphoneContent *content) {
return content->lcp.name;
return content->name;
}
void linphone_content_set_name(LinphoneContent *content, const char *name) {
if (content->lcp.name != NULL) {
belle_sip_free(content->lcp.name);
content->lcp.name = NULL;
if (content->name != NULL) {
belle_sip_free(content->name);
content->name = NULL;
}
if (name != NULL) {
content->lcp.name = belle_sip_strdup(name);
content->name = belle_sip_strdup(name);
}
}
size_t linphone_content_get_key_size(const LinphoneContent *content) {
return content->lcp.keyLength;
return content->keyLength;
}
const char * linphone_content_get_key(const LinphoneContent *content) {
return content->lcp.key;
return content->key;
}
void linphone_content_set_key(LinphoneContent *content, const char *key, const size_t keyLength) {
if (content->lcp.key != NULL) {
belle_sip_free(content->lcp.key);
content->lcp.key = NULL;
if (content->key != NULL) {
belle_sip_free(content->key);
content->key = NULL;
}
if (key != NULL) {
content->lcp.key = belle_sip_malloc(keyLength);
memcpy(content->lcp.key, key, keyLength);
content->key = belle_sip_malloc(keyLength);
memcpy(content->key, key, keyLength);
}
}
/* crypto context is managed(allocated/freed) by the encryption function, so provide the address of field in the private structure */
void ** linphone_content_get_cryptoContext_address(LinphoneContent *content) {
return &(content->lcp.cryptoContext);
return &(content->cryptoContext);
}
bool_t linphone_content_is_multipart(const LinphoneContent *content) {
// TODO
return FALSE;
}
LinphoneContent * linphone_content_new(void) {
LinphoneContent *content = belle_sip_object_new(LinphoneContent);
belle_sip_object_ref(content);
content->owned_fields = TRUE;
content->lcp.cryptoContext = NULL; /* this field is managed externally by encryption/decryption functions so be careful to initialise it to NULL */
return content;
LinphoneContent * linphone_content_get_part(const LinphoneContent *content) {
// TODO
return NULL;
}
LinphoneContent * linphone_content_copy(const LinphoneContent *ref) {
return (LinphoneContent *)belle_sip_object_ref(belle_sip_object_clone(BELLE_SIP_OBJECT(ref)));
void linphone_content_add_part(LinphoneContent *content, LinphoneContent *part) {
// TODO
}
LinphoneContent * linphone_content_from_sal_body(const SalBody *ref) {
if (ref && ref->type) {
LinphoneContent *content = linphone_content_new();
linphone_content_set_type(content, ref->type);
linphone_content_set_subtype(content, ref->subtype);
linphone_content_set_encoding(content, ref->encoding);
if (ref->data != NULL) {
linphone_content_set_buffer(content, ref->data, ref->size);
} else {
linphone_content_set_size(content, ref->size);
}
return content;
}
const char * linphone_content_get_custom_header(const LinphoneContent *content, const char *header_name) {
// TODO
return NULL;
}
SalBody *sal_body_from_content(SalBody *body, const LinphoneContent *content) {
if (content && linphone_content_get_type(content)) {
body->type = linphone_content_get_type(content);
body->subtype = linphone_content_get_subtype(content);
body->data = linphone_content_get_buffer(content);
body->size = linphone_content_get_size(content);
body->encoding = linphone_content_get_encoding(content);
return body;
}
return NULL;
void linphone_content_add_custom_header(LinphoneContent *content, const char *header_name, const char *header_value) {
// TODO
}
LinphoneContent * linphone_content_private_to_linphone_content(const LinphoneContentPrivate *lcp) {
LinphoneContent *content = belle_sip_object_new(LinphoneContent);
memcpy(&content->lcp, lcp, sizeof(LinphoneContentPrivate));
content->owned_fields = FALSE;
return content;
LinphoneContent * linphone_content_new(void) {
return linphone_content_new_with_body_handler(NULL);
}
LinphoneContent * linphone_content_copy(const LinphoneContent *ref) {
return (LinphoneContent *)belle_sip_object_ref(belle_sip_object_clone(BELLE_SIP_OBJECT(ref)));
}
LinphoneContent * linphone_content_from_sal_body_handler(SalBodyHandler *body_handler) {
if (body_handler) {
return linphone_content_new_with_body_handler(body_handler);
}
return NULL;
}
LinphoneContentPrivate * linphone_content_to_linphone_content_private(const LinphoneContent *content) {
return (LinphoneContentPrivate *)&content->lcp;
SalBodyHandler * sal_body_handler_from_content(const LinphoneContent *content) {