Commit ea073ee8 authored by Simon Morlat's avatar Simon Morlat

modifications of http chunked mode (receiving): each segment of data received...

modifications of http chunked mode (receiving): each segment of data received is immediately pushed to the body, without waiting for the end of the chunk.
This makes it more tolerant to servers sending big chunks of data.
parent d8cee801
......@@ -106,6 +106,7 @@ belle_sip_object_t *belle_sip_object_weak_ref(void *obj, belle_sip_object_destro
void belle_sip_object_weak_unref(void *obj, belle_sip_object_destroy_notify_t destroy_notify, void *userpointer){
belle_sip_object_t *o=BELLE_SIP_OBJECT(obj);
weak_ref_t *ref,*prevref=NULL,*next=NULL;
int found=FALSE;
if (o->ref==-1) return; /*too late and avoid recursions*/
for(ref=o->weak_refs;ref!=NULL;ref=next){
......@@ -114,12 +115,13 @@ void belle_sip_object_weak_unref(void *obj, belle_sip_object_destroy_notify_t de
if (prevref==NULL) o->weak_refs=next;
else prevref->next=next;
belle_sip_free(ref);
return;
found=TRUE;
/*do not break or return, someone could have put twice the same weak ref on the same object*/
}else{
prevref=ref;
}
}
belle_sip_fatal("Could not find weak_ref, you're a looser.");
if (!found) belle_sip_fatal("Could not find weak_ref, you're a looser.");
}
static void belle_sip_object_loose_weak_refs(belle_sip_object_t *obj){
......
......@@ -309,6 +309,7 @@ static int check_body(belle_sip_channel_t *obj){
obj->input_stream.chuncked_mode=1;
obj->input_stream.content_length=0;
obj->input_stream.chunk_size=-1;
obj->input_stream.chunk_read_size=0;
}
}
expect_body=TRUE;
......@@ -351,12 +352,13 @@ static int acquire_body_simple(belle_sip_channel_t *obj, int end_of_stream){
return BELLE_SIP_STOP;
}
static int acquire_chuncked_body(belle_sip_channel_t *obj, int end_of_stream){
static int acquire_chuncked_body(belle_sip_channel_t *obj){
belle_sip_channel_input_stream_t *st=&obj->input_stream;
int readsize;
do{
if (st->chunk_size==-1){
char *tmp;
belle_sip_message("seeing: %s",st->read_ptr);
/*belle_sip_message("seeing: %s",st->read_ptr);*/
while ( (tmp=strstr(st->read_ptr,"\r\n"))==st->read_ptr){/*skip \r\n*/
st->read_ptr+=2;
}
......@@ -372,8 +374,9 @@ static int acquire_chuncked_body(belle_sip_channel_t *obj, int end_of_stream){
belle_sip_channel_message_ready(obj);
return BELLE_SIP_CONTINUE;
}else{
belle_sip_message("Getting chunk of %i bytes",(int)chunksize);
belle_sip_message("Will get a chunk of %i bytes",(int)chunksize);
st->chunk_size=chunksize;
st->chunk_read_size=0;
st->read_ptr=tmp+2;
}
}else{
......@@ -386,10 +389,14 @@ static int acquire_chuncked_body(belle_sip_channel_t *obj, int end_of_stream){
return BELLE_SIP_STOP;
}
}
if (st->chunk_size<=st->write_ptr-st->read_ptr){
readsize=MIN(st->write_ptr-st->read_ptr,st->chunk_size-st->chunk_read_size);
if (readsize>0){
feed_body(obj,readsize);
st->chunk_read_size+=readsize;
}
if (st->chunk_size==st->chunk_read_size){
/*we have a chunk completed*/
st->content_length+=st->chunk_size;
feed_body(obj,st->chunk_size);
belle_sip_message("Chunk of [%i] bytes completed",st->chunk_size);
st->chunk_size=-1;/*wait for next chunk indicator*/
}else{
......@@ -401,7 +408,7 @@ static int acquire_chuncked_body(belle_sip_channel_t *obj, int end_of_stream){
static int acquire_body(belle_sip_channel_t *obj, int end_of_stream){
if (obj->input_stream.chuncked_mode)
return acquire_chuncked_body(obj,end_of_stream);
return acquire_chuncked_body(obj);
else return acquire_body_simple(obj,end_of_stream);
}
......
......@@ -83,6 +83,7 @@ typedef struct belle_sip_channel_input_stream{
int content_length;
int chuncked_mode;
int chunk_size;
int chunk_read_size;
}belle_sip_channel_input_stream_t;
typedef struct belle_sip_stream_channel belle_sip_stream_channel_t;
......
......@@ -161,6 +161,7 @@ static void belle_sip_transaction_reset_dialog(belle_sip_transaction_t *tr, bell
}
void belle_sip_transaction_set_dialog(belle_sip_transaction_t *t, belle_sip_dialog_t *dialog){
if (t->dialog==dialog) return;
if (dialog) belle_sip_object_weak_ref(dialog,(belle_sip_object_destroy_notify_t)belle_sip_transaction_reset_dialog,t);
if (t->dialog) belle_sip_object_weak_unref(t->dialog,(belle_sip_object_destroy_notify_t)belle_sip_transaction_reset_dialog,t);
t->dialog=dialog;
......
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