Resolve bug in linked-list.

Begin replacing SIP uri basic parser by Ragel scanners.
This commit is contained in:
bossiel 2010-01-07 19:26:38 +00:00
parent 41faa71862
commit 10c50761cf
8 changed files with 1016 additions and 48607 deletions

View File

@ -298,6 +298,7 @@ void tsk_list_remove_item_by_pred(tsk_list_t* list, tsk_list_func_predicate pred
if(curr == list->tail)
{ /* Found at last position */
list->tail = prev;
list->tail->next = 0;
}
else
{

View File

@ -38,7 +38,7 @@
#define RUN_TEST_HEAP 0
#define RUN_TEST_STRINGS 0
#define RUN_TEST_URL 0
#define RUN_TEST_MUTEX 1
#define RUN_TEST_MUTEX 0
#define RUN_TEST_CONDWAIT 0
#define RUN_TEST_SEMAPHORE 0
#define RUN_TEST_SAFEOBJECT 0
@ -49,7 +49,7 @@
#define RUN_TEST_BUFFER 0
#define RUN_TEST_MD5 0
#define RUN_TEST_SHA1 0
#define RUN_TEST_BASE64 0
#define RUN_TEST_BASE64 1
#if RUN_TEST_LISTS || RUN_TEST_ALL
#include "test_lists.h"

View File

@ -31,45 +31,87 @@
#define TINYSIP_RAGEL_STATE_H
#include "tinysip_config.h"
#include "tsk_params.h"
TSIP_BEGIN_DECLS
#define SCANNER_SET_STRING(string) \
if(!string) \
{ \
int len = (int)(te - ts); \
if(len >0) \
{ \
string = tsk_calloc(len+1, sizeof(char)), memcpy(string, ts, len); \
} \
}
#define PARSER_SET_STRING(string) \
if(!string) \
{ \
int len = (int)(p - tag_start); \
if(string)free(string); \
string = tsk_calloc(len+1, sizeof(char)), memcpy(string, tag_start, len); \
}
#define PARSER_SET_INTEGER(integer) \
int len = (int)(p - tag_start); \
if(len>0) \
#define SCANNER_SET_INTEGER(integer) \
{ \
char* tmp = tsk_calloc(len+1, sizeof(char)); \
memcpy(tmp, tag_start, len); \
integer = atoi(tmp); \
free(tmp); \
int len = (int)(te - ts); \
if(len>=0) \
{ \
char* tmp = tsk_calloc(len+1, sizeof(char)); \
memcpy(tmp, ts, len); \
integer = atoi(tmp); \
free(tmp); \
} \
}
#define PARSER_SET_INTEGER(integer) \
{ \
int len = (int)(p - tag_start); \
if(len>0) \
{ \
char* tmp = tsk_calloc(len+1, sizeof(char)); \
memcpy(tmp, tag_start, len); \
integer = atoi(tmp); \
free(tmp); \
} \
}
#define PARSER_ADD_PARAM(dest) \
size_t len = (size_t)(p - tag_start); \
tsk_param_t *param = tsk_params_parse_param(tag_start, len); \
if(param) \
{ \
if(!dest) dest = TSK_LIST_CREATE(); \
tsk_list_push_back_data(dest, ((void**) &param)); \
size_t len = (size_t)(p - tag_start); \
tsk_param_t *param = tsk_params_parse_param(tag_start, len); \
if(param) \
{ \
if(!dest) dest = TSK_LIST_CREATE(); \
tsk_list_push_back_data(dest, ((void**) &param)); \
} \
}
#define SACANNER_ADD_PARAM(dest) \
{ \
int len = (int)(te - ts); \
if(len >0) \
{ \
tsk_param_t *param = tsk_params_parse_param(ts, len); \
if(param) \
{ \
if(!dest) dest = TSK_LIST_CREATE(); \
tsk_list_push_back_data(dest, ((void**) &param)); \
} \
} \
}
#define PARSER_ADD_STRING(dest) \
size_t len = (size_t)(p - tag_start); \
tsk_string_t *string = TSK_STRING_CREATE(0); \
string->value = tsk_calloc(len+1, sizeof(char)), memcpy(string->value, tag_start, len); \
if(!dest) \
{ \
dest = TSK_LIST_CREATE(); \
} \
tsk_list_push_back_data(dest, ((void**) &string));
{ \
size_t len = (size_t)(p - tag_start); \
tsk_string_t *string = TSK_STRING_CREATE(0); \
string->value = tsk_calloc(len+1, sizeof(char)), memcpy(string->value, tag_start, len); \
if(!dest) \
{ \
dest = TSK_LIST_CREATE(); \
} \
tsk_list_push_back_data(dest, ((void**) &string)); \
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// @struct tsip_parser_s

View File

@ -5,13 +5,13 @@
export OPTIONS="-C -L -G2"
# SIP/SIPS/TEL URI parser
#ragel.exe $OPTIONS -o ../source/parsers/tsip_parser_uri.c tsip_parser_uri.rl
ragel.exe $OPTIONS -o ../source/parsers/tsip_parser_uri.c tsip_parser_uri.rl
# SIP message (both requests an responses) parser.
ragel.exe $OPTIONS -o ../source/parsers/tsip_parser_message.c tsip_parser_message.rl
#ragel.exe $OPTIONS -o ../source/parsers/tsip_parser_message.c tsip_parser_message.rl
# SIP headers parser
ragel.exe $OPTIONS -o ../source/parsers/tsip_parser_header.c tsip_parser_header.rl
#ragel.exe $OPTIONS -o ../source/parsers/tsip_parser_header.c tsip_parser_header.rl
# ==Allow

View File

@ -39,14 +39,34 @@
/***********************************
* Ragel state machine.
*/
%%{
machine tsip_machine_userinfo;
# Includes
include tsip_machine_utils "./tsip_machine_utils.rl";
action parse_toto
{
TSK_DEBUG_INFO("PARSE_TOTO [%s]", tag_start);
}
action parse_titi
{
TSK_DEBUG_INFO("PARSE_TITI [%s]", tag_start);
}
}%%
%%{
machine tsip_machine_parser_uri;
# Includes
include tsip_machine_utils "./tsip_machine_utils.rl";
include tsip_machine_userinfo;
action tag
{
TSK_DEBUG_INFO("PARSER_URI::TAG");
tag_start = p;
}
@ -62,34 +82,45 @@
action parse_scheme
{
PARSER_SET_STRING(uri->scheme);
TSK_DEBUG_INFO("PARSER_URI::SCHEME");
PARSER_SET_STRING(uri->scheme);
}
action parse_user_name
{
TSK_DEBUG_INFO("PARSER_URI::USER_NAME");
PARSER_SET_STRING(uri->user_name);
}
action parse_password
{
TSK_DEBUG_INFO("PARSER_URI::PASSWORD");
PARSER_SET_STRING(uri->password);
}
action parse_host
{
TSK_DEBUG_INFO("PARSER_URI::HOST");
PARSER_SET_STRING(uri->host);
}
action parse_port
{
TSK_DEBUG_INFO("PARSER_URI::PORT");
PARSER_SET_INTEGER(uri->port);
}
action parse_param
{
TSK_DEBUG_INFO("PARSER_URI::PARAM");
PARSER_ADD_PARAM(uri->params);
}
action has_arobase
{
tsk_strcontains(tag_start, "@")
}
action eob
{
}
@ -104,13 +135,88 @@
my_userinfo = ( user>tag %parse_user_name | telephone_subscriber ) :> ( ":" password>tag %parse_password )? "@";
UNKNOWN_URI = (scheme)>tag %parse_scheme HCOLON <:any*;
SIP_URI = ("sip:"i %is_sip | "sips:"i %is_sips) my_userinfo? my_hostport uri_parameters headers?;
TEL_URI = ("tel:"i >is_tel) telephone_subscriber;
#SIP_URI = ("sip:"i %is_sip | "sips:"i %is_sips) (((my_userinfo my_hostport) when has_arobase) | (my_hostport)) uri_parameters headers?;
#SIP_URI = ("sip:"i %is_sip | "sips:"i %is_sips) my_userinfo? my_hostport uri_parameters headers?;
SIP_URI := |*
("sip:"i %is_sip | "sips:"i %is_sips) => parse_scheme;
*|;
#SIP_URI =
# ("sip:"i %is_sip | "sips:"i %is_sips)
# ((any when has_arobase)*) %parse_toto | any* %parse_titi
# uri_parameters headers?;
#SIP_URI = ( "sip:"i %is_sip | "sips:"i %is_sips ) > 0 >tag
# ( ((any when has_arobase)*) %parse_toto | (any*) %parse_titi ) >1
# ( uri_parameters headers? ) >2;
#SIP_URI =
# start: (
# ( "sip:"i %is_sip | "sips:"i %is_sips ) >tag %tag -> check
# ),
# check: (
# ( (any* when has_arobase) )%parse_user_name -> usrinfo | (any*)-> hport
# ),
# usrinfo: (
# (any)* %parse_toto-> hport
# ),
# hport: (
# (any)* -> final
# );
URI = ((SIP_URI)>1 | (TEL_URI)>1 | (UNKNOWN_URI)>0);
#TEL_URI = ("tel:"i %is_tel) telephone_subscriber;
#URI = SIP_URI;
#URI = ((SIP_URI)>1 | (TEL_URI)>1 | (UNKNOWN_URI)>0);
# Entry point
main := URI;
#main := (
# ("sip:"i %is_sip | "sips:"i %is_sips) @ { fcall SIP_URI; }
# );
sip_usrinfo := ( ( user>tag %parse_user_name ) :> ( ":" password>tag %parse_password )? :>> '@' ) @{ fgoto main; };
main := |*
("sip:"i %is_sip | "sips:"i %is_sips) > 100
{
if(tsk_strcontains(te, "@"))
{
fgoto sip_usrinfo;
}
};
( (IPv6reference >is_ipv6)>89 | (IPv4address >is_ipv4)>88 | (hostname >is_hostname)>87 ) > 90
{
SCANNER_SET_STRING(uri->host);
};
(":" port) >80
{
ts++;
SCANNER_SET_INTEGER(uri->port);
};
( ";" (pname ( "=" pvalue )?) ) > 70
{
ts++;
SACANNER_ADD_PARAM(uri->params);
};
(any*) > 0
{
TSK_DEBUG_INFO("OOOOOOOOOK* \np=%s\n\nts=%s\nte=%s\n", p,ts, te);
//fgoto sip_hostport;
};
*|;
#main := ({ fcall SIP_URI; });
}%%
@ -133,6 +239,10 @@ tsip_uri_t *tsip_uri_parse(const char *data, size_t size)
const char *p = data;
const char *pe = p + size;
const char *eof = pe;
const char *ts = 0, *te = 0;
int act =0;
tsip_uri_t *uri = TSIP_URI_CREATE(uri_unknown);
const char *tag_start = 0;

File diff suppressed because it is too large Load Diff

View File

@ -43,9 +43,9 @@
#define RUN_TEST_ALL 0
#define RUN_TEST_MESSAGES 0
#define RUN_TEST_URI 0
#define RUN_TEST_URI 1
#define RUN_TEST_TRANSAC 0
#define RUN_TEST_STACK 1
#define RUN_TEST_STACK 0
#ifdef _WIN32_WCE
int _tmain(int argc, _TCHAR* argv[])

View File

@ -27,9 +27,9 @@
const char* uris[] =
{
//== SIP:
/*"sip:alice@atlanta.com;p1=23",
"sip:alice@atlanta.com;p1=23",
"sip:*666*@atlanta.com",
"sip:#66#@atlanta.com",*/
"sip:#66#@atlanta.com",
"sip:alice:secretword@atlanta.com",
"sip:alice:secretword@atlanta.com:65535;transport=tcp",
"sip:+1-212-555-1212:1234@gateway.com;user=phone",