[asterisk-dev] [Code Review] SIP: refactoring parsing functions and the addition of new unit tests

David Vossel dvossel at digium.com
Tue Feb 2 12:28:53 CST 2010



> On 2010-02-01 21:01:48, Russell Bryant wrote:
> > /trunk/channels/sip/reqresp-parser.c, line 125
> > <https://reviewboard.asterisk.org/r/477/diff/2/?file=7908#file7908line125>
> >
> >     I guess no validation is being done to verify that "port" is a valid port?
> 
> Mark Michelson wrote:
>     Also, the part after the question mark is invalid. headers in a SIP URI are ampersand-separated name=value pairs.
>     
>     I realize that the headers aren't actually parsed in your example, but I think that it would be a good idea to have something valid there.

I fixed this string to have some valid looking (but made up) headers after the ? to validate it still gets parsed correctly.  The port doesn't have to be valid for this function right now.  All the users of parse_uri determine what to do with an invalid port, but I think this is logic that should be in parse_uri in the future. 


- David


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviewboard.asterisk.org/r/477/#review1432
-----------------------------------------------------------


On 2010-02-02 12:22:49, David Vossel wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviewboard.asterisk.org/r/477/
> -----------------------------------------------------------
> 
> (Updated 2010-02-02 12:22:49)
> 
> 
> Review request for Asterisk Developers.
> 
> 
> Summary
> -------
> 
> ----- Changes -----
> New files
> - channels/sip/sip.h – A new header for shared #define, enum, and struct definitions.
> - channels/sip/include/sip-utils.h – sip util functions shared among the all the sip APIs
> - channels/sip/include/config-parser.h – sip config-parser API
> - channels/sip/config-parser.c  – Contains sip.conf parsing helper functions with unit tests.
> - channels/sip/include/reqresp-parser.h – sip request response parser API
> - channels/sip/reqresp-parser.c – Contains sip request and response parsing helper functions with unit tests.
> 
> New Unit Tests 
> - sip_parse_uri_test
> - sip_parse_host_test
> - sip_parse_register_line_test
> 
> Code Refactoring
> - All reusable #define, enum, and struct definitions were moved out of chan_sip.c into sip.h. During this process formatting changes were made to comments in both sip.h and chan_sip.c in order to better adhere to the coding guidelines.
> - The beginnings of three new sip APIs, sip-utils.h, config-parser.h, reqresp-parser.h using existing chan_sip.c functions.
> - parse_uri() and get_calleridname() were moved from chan_sip.c to request-parser.c along with unit tests for both functions.
> - sip_parse_host() and sip_parse_register_line() were moved from chan_sip.c to config-parser.c along with unit tests for both functions.
> 
> Changes to parse_uri()
> -removal of the options parameter.  It was never used and did not behave correctly.
> -additional check for [?header] field. When this field was present, the transport type was not being set correctly.
> 
> ----- Overview -----
> 
> This patch is introduced with the hope that unit tests for all our sip parsing functions will be written soon.  chan_sip is a huge file, and with the addition of each unit test chan_sip is going to grow larger and harder to maintain.  I'm proposing we begin refactoring chan_sip, starting with the parsing functions.  With each parsing function we move into a separate helper file, a unit test should accompany it.  I've attempted to lay down the ground work for this change by creating two new parser helper files (config-parser.c and reqresp-parser.c) and moving all shared structs, enums, and defines from chan_sip.c into a shared sip.h file.  We can't verify everything in Asterisk using unit tests, but string parsing is one area where unit tests make the most sense.  By beginning to restructure the code in this way, chan_sip not only becomes less bloated, but Asterisk as a whole will become more stable.
> 
> 
> UPDATE:  This is an update to my original review request.  The major change made here is that each new .c file in the sip/ directory now has it's own header file in sip/include/.  I did this because I do not think it is a good idea to start putting function prototypes into the main sip.h file.  We should really be breaking up these functions into separate APIs.
> 
> 
> Diffs
> -----
> 
>   /trunk/channels/Makefile 244328 
>   /trunk/channels/chan_sip.c 244328 
>   /trunk/channels/sip/config_parser.c PRE-CREATION 
>   /trunk/channels/sip/include/config_parser.h PRE-CREATION 
>   /trunk/channels/sip/include/reqresp_parser.h PRE-CREATION 
>   /trunk/channels/sip/include/sip.h PRE-CREATION 
>   /trunk/channels/sip/include/sip_utils.h PRE-CREATION 
>   /trunk/channels/sip/reqresp_parser.c PRE-CREATION 
> 
> Diff: https://reviewboard.asterisk.org/r/477/diff
> 
> 
> Testing
> -------
> 
> compiled and ran unit tests.
> 
> 
> Thanks,
> 
> David
> 
>




More information about the asterisk-dev mailing list