Commit 288dc8ed authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Added callbacks for start/end states in user body handler

parent e69a6d2c
......@@ -61,15 +61,21 @@ BELLESIP_EXPORT int belle_sip_memory_body_handler_unapply_encoding(belle_sip_mem
#define BELLE_SIP_USER_BODY_HANDLER(obj) BELLE_SIP_CAST(obj,belle_sip_user_body_handler_t)
typedef void (*belle_sip_user_body_handler_start_callback_t)(belle_sip_user_body_handler_t *obj, void *user_data);
typedef void (*belle_sip_user_body_handler_recv_callback_t)(belle_sip_user_body_handler_t *obj, belle_sip_message_t *msg, void *user_data, size_t offset, uint8_t* buffer, size_t size);
typedef int (*belle_sip_user_body_handler_send_callback_t)(belle_sip_user_body_handler_t *obj, belle_sip_message_t *msg, void *user_data, size_t offset, uint8_t* buffer, size_t *size);
typedef void (*belle_sip_user_body_handler_stop_callback_t)(belle_sip_user_body_handler_t *obj, void *user_data);
BELLESIP_EXPORT belle_sip_user_body_handler_t *belle_sip_user_body_handler_new(
size_t total_size,
belle_sip_body_handler_progress_callback_t progress_cb,
belle_sip_user_body_handler_start_callback_t start_cb,
belle_sip_user_body_handler_recv_callback_t recv_cb,
belle_sip_user_body_handler_send_callback_t send_cb,
belle_sip_user_body_handler_stop_callback_t stop_cb,
void *data);
......
......@@ -380,10 +380,24 @@ belle_sip_memory_body_handler_t *belle_sip_memory_body_handler_new_copy_from_buf
struct belle_sip_user_body_handler{
belle_sip_body_handler_t base;
belle_sip_user_body_handler_start_callback_t start_cb;
belle_sip_user_body_handler_recv_callback_t recv_cb;
belle_sip_user_body_handler_send_callback_t send_cb;
belle_sip_user_body_handler_stop_callback_t stop_cb;
};
static void belle_sip_user_body_handler_begin_transfer(belle_sip_body_handler_t *base) {
belle_sip_user_body_handler_t *obj = (belle_sip_user_body_handler_t *)base;
if (obj->start_cb)
obj->start_cb((belle_sip_user_body_handler_t*)base, base->user_data);
}
static void belle_sip_user_body_handler_end_transfer(belle_sip_body_handler_t *base) {
belle_sip_user_body_handler_t *obj = (belle_sip_user_body_handler_t *)base;
if (obj->stop_cb)
obj->stop_cb((belle_sip_user_body_handler_t*)base, base->user_data);
}
static void belle_sip_user_body_handler_recv_chunk(belle_sip_body_handler_t *base, belle_sip_message_t *msg, size_t offset, uint8_t *buf, size_t size){
belle_sip_user_body_handler_t *obj=(belle_sip_user_body_handler_t*)base;
if (obj->recv_cb)
......@@ -401,8 +415,10 @@ static int belle_sip_user_body_handler_send_chunk(belle_sip_body_handler_t *base
}
static void belle_sip_user_body_handler_clone(belle_sip_user_body_handler_t *obj, const belle_sip_user_body_handler_t *orig){
obj->start_cb=orig->start_cb;
obj->recv_cb=orig->recv_cb;
obj->send_cb=orig->send_cb;
obj->stop_cb=orig->stop_cb;
}
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sip_user_body_handler_t);
......@@ -415,8 +431,8 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_BEGIN(belle_sip_user_body_handler_t)
NULL,
BELLE_SIP_DEFAULT_BUFSIZE_HINT
},
NULL,
NULL,
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
}
......@@ -425,14 +441,18 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_END
belle_sip_user_body_handler_t *belle_sip_user_body_handler_new(
size_t total_size,
belle_sip_body_handler_progress_callback_t progress_cb,
belle_sip_user_body_handler_start_callback_t start_cb,
belle_sip_user_body_handler_recv_callback_t recv_cb,
belle_sip_user_body_handler_send_callback_t send_cb,
belle_sip_user_body_handler_stop_callback_t stop_cb,
void *data){
belle_sip_user_body_handler_t * obj=belle_sip_object_new(belle_sip_user_body_handler_t);
belle_sip_body_handler_init((belle_sip_body_handler_t*)obj,progress_cb,data);
obj->base.expected_size=total_size;
obj->start_cb=start_cb;
obj->recv_cb=recv_cb;
obj->send_cb=send_cb;
obj->stop_cb=stop_cb;
return obj;
}
......@@ -482,10 +502,19 @@ static void belle_sip_file_body_handler_begin_transfer(belle_sip_body_handler_t
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;
if (obj->user_bh && obj->user_bh->stop_cb) {
obj->user_bh->stop_cb((belle_sip_user_body_handler_t*)&(obj->user_bh->base), obj->user_bh->base.user_data);
}
if (obj->file) {
ssize_t ret;
ret = bctbx_file_close(obj->file);
......
......@@ -244,7 +244,7 @@ static void https_post_long_body(void){
if (url_supported(url)==-1) {
return;
}
bh=belle_sip_user_body_handler_new(image_size+sizeof(MULTIPART_BEGIN)+sizeof(MULTIPART_END), on_progress, NULL, on_send_body, NULL);
bh=belle_sip_user_body_handler_new(image_size+sizeof(MULTIPART_BEGIN)+sizeof(MULTIPART_END), on_progress, NULL, NULL, on_send_body, NULL, NULL);
content_type=belle_sip_strdup_printf("multipart/form-data; boundary=%s",multipart_boudary);
uri=belle_generic_uri_parse(url);
......@@ -282,7 +282,7 @@ static void process_response_headers(void *data, const belle_http_response_event
FILE *file=belle_sip_object_data_get(BELLE_SIP_OBJECT(event->request),"file");
belle_sip_message_set_body_handler(
(belle_sip_message_t*)event->response,
(belle_sip_body_handler_t*)belle_sip_user_body_handler_new(0,on_progress,on_recv_body,NULL,file)
(belle_sip_body_handler_t*)belle_sip_user_body_handler_new(0,on_progress, NULL,on_recv_body,NULL, NULL,file)
);
}
}
......
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