Commit 70c6de05 authored by Ghislain MARY's avatar Ghislain MARY

Separate body handlers begin transfer callbacks for receiving and sending...

Separate body handlers begin transfer callbacks for receiving and sending files (the file body handler needs to open the file in different modes in these 2 cases).
parent b8bc7f2a
......@@ -1030,13 +1030,15 @@ void belle_sip_header_extension_set_value(belle_sip_header_extension_t* extensio
BELLE_SIP_DECLARE_CUSTOM_VPTR_BEGIN(belle_sip_body_handler_t,belle_sip_object_t)
void (*begin_transfer)(belle_sip_body_handler_t *obj);
void (*begin_recv_transfer)(belle_sip_body_handler_t *obj);
void (*begin_send_transfer)(belle_sip_body_handler_t *obj);
void (*end_transfer)(belle_sip_body_handler_t *obj);
void (*chunk_recv)(belle_sip_body_handler_t *obj, belle_sip_message_t *msg, off_t offset, uint8_t *buf, size_t size);
int (*chunk_send)(belle_sip_body_handler_t *obj, belle_sip_message_t *msg, off_t offset, uint8_t *buf, size_t * size);
BELLE_SIP_DECLARE_CUSTOM_VPTR_END
void belle_sip_body_handler_begin_transfer(belle_sip_body_handler_t *obj);
void belle_sip_body_handler_begin_recv_transfer(belle_sip_body_handler_t *obj);
void belle_sip_body_handler_begin_send_transfer(belle_sip_body_handler_t *obj);
void belle_sip_body_handler_recv_chunk(belle_sip_body_handler_t *obj, belle_sip_message_t *msg, uint8_t *buf, size_t size);
int belle_sip_body_handler_send_chunk(belle_sip_body_handler_t *obj, belle_sip_message_t *msg, uint8_t *buf, size_t *size);
void belle_sip_body_handler_end_transfer(belle_sip_body_handler_t *obj);
......
......@@ -56,7 +56,7 @@ static void belle_sip_body_handler_destroy(belle_sip_body_handler_t *obj){
static belle_sip_error_code belle_sip_body_handler_marshal(belle_sip_body_handler_t *obj, char *buff, size_t buff_size, size_t *offset) {
int ret;
size_t len;
if (*offset == 0) belle_sip_body_handler_begin_transfer(obj);
if (*offset == 0) belle_sip_body_handler_begin_send_transfer(obj);
do {
len = buff_size - *offset;
ret = belle_sip_body_handler_send_chunk(obj, NULL, (uint8_t*)buff + *offset, &len);
......@@ -77,7 +77,8 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_BEGIN(belle_sip_body_handler_t)
(belle_sip_object_marshal_t) belle_sip_body_handler_marshal,
BELLE_SIP_DEFAULT_BUFSIZE_HINT
},
NULL, /* begin_transfer */
NULL, /* begin_recv_transfer */
NULL, /* begin_send_transfer */
NULL, /* end_transfer */
NULL, /*chunk_recv*/
NULL /*chunk_send*/
......@@ -125,14 +126,22 @@ static void update_progress(belle_sip_body_handler_t *obj, belle_sip_message_t *
obj->progress_cb(obj,msg,obj->user_data,obj->transfered_size,obj->expected_size);
}
void belle_sip_body_handler_begin_transfer(belle_sip_body_handler_t *obj){
void belle_sip_body_handler_begin_recv_transfer(belle_sip_body_handler_t *obj){
BELLE_SIP_OBJECT_VPTR_TYPE(belle_sip_body_handler_t) *vptr = BELLE_SIP_OBJECT_VPTR(obj, belle_sip_body_handler_t);
if (vptr->begin_transfer != NULL) {
vptr->begin_transfer(obj);
if (vptr->begin_recv_transfer != NULL) {
vptr->begin_recv_transfer(obj);
}
obj->transfered_size=0;
}
void belle_sip_body_handler_begin_send_transfer(belle_sip_body_handler_t *obj) {
BELLE_SIP_OBJECT_VPTR_TYPE(belle_sip_body_handler_t) *vptr = BELLE_SIP_OBJECT_VPTR(obj, belle_sip_body_handler_t);
if (vptr->begin_send_transfer != NULL) {
vptr->begin_send_transfer(obj);
}
obj->transfered_size = 0;
}
void belle_sip_body_handler_recv_chunk(belle_sip_body_handler_t *obj, belle_sip_message_t *msg, uint8_t *buf, size_t size){
BELLE_SIP_OBJECT_VPTR(obj,belle_sip_body_handler_t)->chunk_recv(obj,msg,(off_t)obj->transfered_size,buf,size);
obj->transfered_size+=size;
......@@ -220,6 +229,7 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_BEGIN(belle_sip_memory_body_handler_t)
},
NULL,
NULL,
NULL,
belle_sip_memory_body_handler_recv_chunk,
belle_sip_memory_body_handler_send_chunk
}
......@@ -451,6 +461,7 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_BEGIN(belle_sip_user_body_handler_t)
BELLE_SIP_DEFAULT_BUFSIZE_HINT
},
belle_sip_user_body_handler_begin_transfer,
belle_sip_user_body_handler_begin_transfer,
belle_sip_user_body_handler_end_transfer,
belle_sip_user_body_handler_recv_chunk,
belle_sip_user_body_handler_send_chunk
......@@ -512,7 +523,7 @@ static void belle_sip_file_body_handler_clone(belle_sip_file_body_handler_t *obj
}
}
static void belle_sip_file_body_handler_begin_transfer(belle_sip_body_handler_t *base) {
static void belle_sip_file_body_handler_begin_recv_transfer(belle_sip_body_handler_t *base) {
belle_sip_file_body_handler_t *obj = (belle_sip_file_body_handler_t *)base;
bctbx_vfs_t *vfs = bctbx_vfs_get_default();
......@@ -527,6 +538,21 @@ static void belle_sip_file_body_handler_begin_transfer(belle_sip_body_handler_t
}
}
static void belle_sip_file_body_handler_begin_send_transfer(belle_sip_body_handler_t *base) {
belle_sip_file_body_handler_t *obj = (belle_sip_file_body_handler_t *)base;
bctbx_vfs_t *vfs = bctbx_vfs_get_default();
if (obj->filepath == NULL) return;
obj->file = bctbx_file_open(vfs, obj->filepath, "r");
if (!obj->file) {
bctbx_error("Can't open file %s", obj->filepath);
}
if (obj->user_bh && obj->user_bh->start_cb) {
obj->user_bh->start_cb((belle_sip_user_body_handler_t*)&(obj->user_bh->base), obj->user_bh->base.user_data);
}
}
static void belle_sip_file_body_handler_end_transfer(belle_sip_body_handler_t *base) {
belle_sip_file_body_handler_t *obj = (belle_sip_file_body_handler_t *)base;
......@@ -591,7 +617,8 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_BEGIN(belle_sip_file_body_handler_t)
NULL,
BELLE_SIP_DEFAULT_BUFSIZE_HINT
},
belle_sip_file_body_handler_begin_transfer,
belle_sip_file_body_handler_begin_recv_transfer,
belle_sip_file_body_handler_begin_send_transfer,
belle_sip_file_body_handler_end_transfer,
belle_sip_file_body_handler_recv_chunk,
belle_sip_file_body_handler_send_chunk
......@@ -642,12 +669,22 @@ static void belle_sip_multipart_body_handler_clone(belle_sip_multipart_body_hand
obj->parts=belle_sip_list_copy_with_data(obj->parts,(void *(*)(void*))belle_sip_object_clone_and_ref);
}
static void belle_sip_multipart_body_handler_begin_transfer(belle_sip_body_handler_t *obj) {
static void belle_sip_multipart_body_handler_begin_recv_transfer(belle_sip_body_handler_t *obj) {
const belle_sip_list_t *it;
belle_sip_multipart_body_handler_t *obj_multipart = (belle_sip_multipart_body_handler_t *)obj;
for (it = obj_multipart->parts; it != NULL; it = it->next) {
belle_sip_body_handler_t *bh = BELLE_SIP_BODY_HANDLER(it->data);
belle_sip_body_handler_begin_recv_transfer(bh);
}
obj_multipart->transfer_current_part = obj_multipart->parts;
}
static void belle_sip_multipart_body_handler_begin_send_transfer(belle_sip_body_handler_t *obj) {
const belle_sip_list_t *it;
belle_sip_multipart_body_handler_t *obj_multipart = (belle_sip_multipart_body_handler_t *)obj;
for (it = obj_multipart->parts; it != NULL; it = it->next) {
belle_sip_body_handler_t *bh = BELLE_SIP_BODY_HANDLER(it->data);
belle_sip_body_handler_begin_transfer(bh);
belle_sip_body_handler_begin_send_transfer(bh);
}
obj_multipart->transfer_current_part = obj_multipart->parts;
}
......@@ -743,7 +780,8 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_BEGIN(belle_sip_multipart_body_handler_t)
NULL,
BELLE_SIP_DEFAULT_BUFSIZE_HINT
},
belle_sip_multipart_body_handler_begin_transfer,
belle_sip_multipart_body_handler_begin_recv_transfer,
belle_sip_multipart_body_handler_begin_send_transfer,
belle_sip_multipart_body_handler_end_transfer,
belle_sip_multipart_body_handler_recv_chunk,
belle_sip_multipart_body_handler_send_chunk
......@@ -777,7 +815,7 @@ belle_sip_multipart_body_handler_t *belle_sip_multipart_body_handler_new_from_bu
belle_sip_body_handler_init((belle_sip_body_handler_t *)obj, belle_sip_multipart_body_handler_progress_cb, NULL);
belle_sip_multipart_body_handler_set_boundary(obj_multipart, boundary);
obj_multipart->base.expected_size = bufsize;
belle_sip_body_handler_begin_transfer(obj);
belle_sip_body_handler_begin_recv_transfer(obj);
belle_sip_body_handler_recv_chunk(obj, NULL, (uint8_t *)buffer, bufsize);
belle_sip_body_handler_end_transfer(obj);
return obj_multipart;
......
......@@ -411,7 +411,7 @@ static int check_body(belle_sip_channel_t *obj){
belle_sip_message_set_body_handler(msg,(bh=(belle_sip_body_handler_t*)belle_sip_memory_body_handler_new(NULL,NULL)));
}
}
belle_sip_body_handler_begin_transfer(bh);
belle_sip_body_handler_begin_recv_transfer(bh);
}
return expect_body;
}
......@@ -1259,7 +1259,7 @@ static void _send_message(belle_sip_channel_t *obj){
size_t max_body_len=sizeof(buffer)-1-len;
if (body_len>0 && body_len<=max_body_len){ /*if size is known and fits into our buffer, send together with headers*/
belle_sip_body_handler_begin_transfer(bh);
belle_sip_body_handler_begin_send_transfer(bh);
do{
max_body_len=sizeof(buffer)-1-len;
ret=belle_sip_body_handler_send_chunk(bh,msg,(uint8_t*)buffer+len,&max_body_len);
......@@ -1272,7 +1272,7 @@ static void _send_message(belle_sip_channel_t *obj){
if (body_len==0){
belle_sip_fatal("Sending bodies whose size is not known must be done in chunked mode, which is not supported yet.");
}
belle_sip_body_handler_begin_transfer(bh);
belle_sip_body_handler_begin_send_transfer(bh);
obj->out_state=OUTPUT_STREAM_SENDING_BODY;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment