/*returns TRUE if a body is expected, and initialize a few things in the input stream context*/ static int check_body(belle_sip_channel_t *obj){ belle_sip_message_t *msg=obj->input_stream.msg; belle_sip_header_content_length_t* content_length_header = belle_sip_message_get_header_by_type(msg,belle_sip_header_content_length_t); int expect_body=FALSE; obj->input_stream.content_length= content_length_header ? belle_sip_header_content_length_get_content_length(content_length_header) : 0; if (BELLE_SIP_OBJECT_IS_INSTANCE_OF(msg,belle_sip_response_t) || BELLE_SIP_OBJECT_IS_INSTANCE_OF(msg,belle_sip_request_t)){ expect_body=obj->input_stream.content_length>0; }else{/*http*/ if (belle_sip_message_get_header_by_type(msg, belle_sip_header_content_type_t)!=NULL){ belle_sip_header_t *transfer_encoding=belle_sip_message_get_header(msg,"Transfer-Encoding"); if (transfer_encoding){ const char *value=belle_sip_header_get_unparsed_value(transfer_encoding); if (strstr(value,"chunked")!=0){ 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; } } if (expect_body){ belle_sip_body_handler_t *bh; /*should notify the listeners*/ BELLE_SIP_INVOKE_LISTENERS_ARG1_ARG2(obj->listeners,belle_sip_channel_listener_t,on_message_headers,obj,msg); /*check if the listener has setup a body handler, otherwise create a default one*/ if ((bh=belle_sip_message_get_body_handler(msg))==NULL){ 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); } return expect_body; }
SalBodyHandler * sal_body_handler_new(void) { belle_sip_memory_body_handler_t *body_handler = belle_sip_memory_body_handler_new(NULL, NULL); return (SalBodyHandler *)BELLE_SIP_BODY_HANDLER(body_handler); }