From 460b67e743647702a518c9a6bd641cb32eed7794 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Wed, 29 Jun 2011 17:52:25 +0200 Subject: [PATCH] grammar: Parse the Contact header properly --- grammar/SIPGrammar.st | 52 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/grammar/SIPGrammar.st b/grammar/SIPGrammar.st index efc267a..ecfdfe8 100644 --- a/grammar/SIPGrammar.st +++ b/grammar/SIPGrammar.st @@ -21,7 +21,7 @@ PackageLoader fileInPackage: 'PetitParser'. PP.PPCompositeParser subclass: SIPGrammar [ | Response StatusLine message_header CRLF SP HTAB HCOLON SWS LWS WSP COMMA SEMI SLASH COLON EQUAL - LAQUOT RAQUOT DQUOTE + LAQUOT RAQUOT DQUOTE STAR message_body SIPVersion StatusCode ReasonPhrase extension_header header_name header_value Request RequestLine Method extension_method @@ -304,7 +304,8 @@ PP.PPCompositeParser subclass: SIPGrammar [ "Simplified..." - ^ (self Via / self CSeq / self From / self To /extension_header), CRLF + ^ (self Via / self CSeq / self From / + self To / self Contact / extension_header), CRLF ] message_body [ @@ -491,11 +492,53 @@ PP.PPCompositeParser subclass: SIPGrammar [ ^ self SIPURI / self SIPSURI "/ self absoluteURI" ] + Contact [ + + ^ ('Contact' asParser / 'm' asParser), HCOLON, + (STAR / (self contact_param, (COMMA, self contact_param) star)) + ] + + contact_param [ + + ^ (self name_addr / self addr_spec), (SEMI, self contact_params) star + ] + + contact_params [ + + ^ self c_p_q / self c_p_expires / self contact_extension + ] + + c_p_q [ + + ^ $q asParser, EQUAL, self qvalue + ] + + c_p_expires [ + + ^ 'expires' asParser, EQUAL, self delta_seconds + ] + + contact_extension [ + + ^ self generic_param + ] + + delta_seconds [ + + ^ #digit asParser plus + ] + extension_header [ ^ header_name, HCOLON, header_value ] + qvalue [ + + ^ ($0 asParser, ($. asParser, #digit asParser max: 3) optional) / + ($1 asParser, ($. asParser, $0 asParser max: 3) optional) + ] + token [ @@ -584,4 +627,9 @@ PP.PPCompositeParser subclass: SIPGrammar [ ^ $" asParser ] + + STAR [ + + ^ SWS, $* asParser, SWS + ] ]