Resolve bug on Stream parser (both SIP and HTTP)

This commit is contained in:
bossiel 2010-06-02 22:51:57 +00:00
parent b149a0618b
commit 3bb9c865d8
10 changed files with 46 additions and 20 deletions

View File

@ -7,7 +7,7 @@
%%proxy_ip 192.168.0.13 # IP address or FQDN
%%proxy_port 5081
%%proxy_trans tcp # udp, tcp, tls or sctp
%%expires 36 # expires used by all dialogs
%%expires 10 # expires used by all dialogs
%%sleep-sec 1.0 # number of seconds to wait before sending next sip message
%%reg-sid
@ -46,12 +46,12 @@
--header Allow-Events=refer, presence, presence.winfo, xcap-diff, conference >>(sub-reg-sid)
#subscribe to presence event package (alice)
#++sub --to sip:alice@$$(domain) --xp $$(expires) --header Event=presence --header Supported=eventlist\
# --header Accept=multipart/related, application/rlmi+xml, application/pidf+xml, application/rpid+xml, application/xcap-diff+xml, message/external-body \
# --header Allow-Events=refer, presence, presence.winfo, xcap-diff, conference >>(sub-pres-sid)
++sub --to sip:alice@$$(domain) --xp $$(expires) --header Event=presence --header Supported=eventlist\
--header Accept=multipart/related, application/rlmi+xml, application/pidf+xml, application/rpid+xml, application/xcap-diff+xml, message/external-body \
--header Allow-Events=refer, presence, presence.winfo, xcap-diff, conference >>(sub-pres-sid)
#publish
#++sn --path ./publish.sn
++sn --path ./publish.sn
#send Pager Mode IM
#++m --to sip:alice@$$(domain) \

View File

@ -27,9 +27,9 @@
++r
# REGISTER
++reg --xp $$(expires) --caps +g.oma.sip-im --caps +g.3gpp.smsip --caps language="en,fr" \
--header Action-Header=Myheader-value @@action\
>>(reg-sid)
#++reg --xp $$(expires) --caps +g.oma.sip-im --caps +g.3gpp.smsip --caps language="en,fr" \
# --header Action-Header=Myheader-value @@action\
# >>(reg-sid)
# sleep
#++sleep --sec $$(sleep-sec)

View File

@ -5,13 +5,13 @@
#++sn --path ./core-colibria.sn
# Ericsson
#++sn --path ./core-ericsson.sn
++sn --path ./core-ericsson.sn
# Inexbee
#++sn --path ./core-inexbee.sn
# Micromethod
++sn --path ./core-micromethod.sn
#++sn --path ./core-micromethod.sn
# Nokia Siemens Networks
#++sn --path ./core-nsn.sn

View File

@ -244,8 +244,10 @@ int ret = thttp_action_GET(session, "http://ipv6.google.com",
/**@defgroup thttp_stack_group HTTP/HTTPS stack
*/
/** Callback function used by the transport layer to alert the stack when new messages come.
*/
/* min size of a stream chunck to form a valid HTTP message */
#define THTTP_MIN_STREAM_CHUNCK_SIZE 0x32
/** Callback function used by the transport layer to alert the stack when new messages come. */
static int thttp_transport_layer_stream_cb(const tnet_transport_event_t* e)
{
int ret = -1;
@ -306,6 +308,7 @@ static int thttp_transport_layer_stream_cb(const tnet_transport_event_t* e)
tsk_buffer_append(dialog->buf, e->data, e->size);
/* Check if we have all HTTP headers. */
parse_buffer:
if((endOfheaders = tsk_strindexOf(TSK_BUFFER_DATA(dialog->buf), TSK_BUFFER_SIZE(dialog->buf), "\r\n\r\n"/*2CRLF*/)) < 0){
TSK_DEBUG_INFO("No all HTTP headers in the TCP buffer.");
goto bail;
@ -369,10 +372,15 @@ static int thttp_transport_layer_stream_cb(const tnet_transport_event_t* e)
}
}
/* Alert the operation (FSM) */
/* Alert the dialog (FSM) */
if(message){
if(have_all_content){ /* only if we have all data */
ret = thttp_dialog_fsm_act(dialog, thttp_atype_i_message, message, tsk_null);
/* Parse next chunck */
if(TSK_BUFFER_SIZE(dialog->buf) >= THTTP_MIN_STREAM_CHUNCK_SIZE){
TSK_OBJECT_SAFE_FREE(message);
goto parse_buffer;
}
}
}

View File

@ -65,7 +65,7 @@ void test_url_parser()
printf("port: %u\n", url->port);
printf("hpath: %s\n", url->hpath);
printf("search: %s\n", url->search);
printf("host-type: %s\n", url->host_type == host_ipv4 ? "IPv4" : (url->host_type == host_ipv6 ? "IPv6" : (url->host_type == host_hostname ? "HOSTNAME" : "UNKNOWN")) );
printf("host-type: %s\n", url->host_type == thttp_host_ipv4 ? "IPv4" : (url->host_type == thttp_host_ipv6 ? "IPv6" : (url->host_type == thttp_host_hostname ? "HOSTNAME" : "UNKNOWN")) );
printf("---PARAMS---\n");

View File

@ -43,7 +43,7 @@
#include "tsk_debug.h"
#include "tsk_time.h"
#define DEBUG_STATE_MACHINE 1
#define DEBUG_STATE_MACHINE 0
#define TSIP_DIALOG_PUBLISH_TIMER_SCHEDULE(TX) TSIP_DIALOG_TIMER_SCHEDULE(publish, TX)
#define TSIP_DIALOG_PUBLISH_SIGNAL(self, type, code, phrase, message) \
tsip_publish_event_signal(type, TSIP_DIALOG(self)->ss, code, phrase, message)

View File

@ -47,7 +47,7 @@
#include "tsk_debug.h"
#include "tsk_time.h"
#define DEBUG_STATE_MACHINE 1
#define DEBUG_STATE_MACHINE 0
#define TSIP_DIALOG_REGISTER_TIMER_SCHEDULE(TX) TSIP_DIALOG_TIMER_SCHEDULE(register, TX)
#define TSIP_DIALOG_REGISTER_SIGNAL(self, type, code, phrase, message) \
tsip_register_event_signal(type, TSIP_DIALOG(self)->ss, code, phrase, message)

View File

@ -43,7 +43,7 @@
#define DEBUG_STATE_MACHINE 1
#define DEBUG_STATE_MACHINE 0
#define TSIP_DIALOG_SUBSCRIBE_TIMER_SCHEDULE(TX) TSIP_DIALOG_TIMER_SCHEDULE(subscribe, TX)
#define TSIP_DIALOG_SUBSCRIBE_SIGNAL(self, type, code, phrase, message) \
tsip_subscribe_event_signal(type, TSIP_DIALOG(self)->ss, code, phrase, message)

View File

@ -75,7 +75,7 @@
#include "tsk_debug.h"
#define DEBUG_STATE_MACHINE 1
#define DEBUG_STATE_MACHINE 0
#define TRANSAC_NICT_TIMER_SCHEDULE(TX) TRANSAC_TIMER_SCHEDULE(nict, TX)

View File

@ -39,6 +39,13 @@
#include "tsk_thread.h"
#include "tsk_debug.h"
/* max size of a stream chunck to form a valid SIP message */
#define TSIP_MAX_STREAM_CHUNCK_SIZE 0xFFFF
/* min size of a stream chunck to form a valid SIP message
* (Request/Response)-Line, Via, From, To, Call-Id, CSeq and Content-Length
* Tests have been done with both compact and full headers */
#define TSIP_MIN_STREAM_CHUNCK_SIZE 0xA0
tsip_transport_layer_t* tsip_transport_layer_create(tsip_stack_t *stack)
{
return tsk_object_new(tsip_transport_layer_def_t, stack);
@ -99,7 +106,8 @@ static int tsip_transport_layer_stream_cb(const tnet_transport_event_t* e)
*/
/* Check if buffer is too big to be valid (have we missed some chuncks?) */
if(TSK_BUFFER_SIZE(transport->buff_stream) >= 0xFFFF){
if(TSK_BUFFER_SIZE(transport->buff_stream) >= TSIP_MAX_STREAM_CHUNCK_SIZE){
TSK_DEBUG_ERROR("TCP Buffer is too big to be valid");
tsk_buffer_cleanup(transport->buff_stream);
}
@ -107,6 +115,7 @@ static int tsip_transport_layer_stream_cb(const tnet_transport_event_t* e)
tsk_buffer_append(transport->buff_stream, e->data, e->size);
/* Check if we have all SIP headers. */
parse_buffer:
if((endOfheaders = tsk_strindexOf(TSK_BUFFER_DATA(transport->buff_stream),TSK_BUFFER_SIZE(transport->buff_stream), "\r\n\r\n"/*2CRLF*/)) < 0){
TSK_DEBUG_INFO("No all SIP headers in the TCP buffer.");
goto bail;
@ -142,8 +151,17 @@ static int tsip_transport_layer_stream_cb(const tnet_transport_event_t* e)
message->sockfd = e->fd;
/* Alert transaction/dialog layer */
ret = tsip_transport_layer_handle_incoming_msg(transport, message);
/* Parse next chunck */
if(TSK_BUFFER_SIZE(transport->buff_stream) >= TSIP_MIN_STREAM_CHUNCK_SIZE){
/* message already passed to the dialog/transac layers */
TSK_OBJECT_SAFE_FREE(message);
goto parse_buffer;
}
}
else{
TSK_DEBUG_ERROR("Failed to parse SIP message");
ret = -15;
}
else ret = -15;
bail:
TSK_OBJECT_SAFE_FREE(message);