summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2014-09-04 15:12:46 +0200
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2014-09-04 15:15:34 +0200
commit4451c8e89cf1bbce895d2d7b03fedd49edd752ed (patch)
treecdc35fc3fb6911ca584e54dd6f98aa84bf700d5c
parent89e653a41aff48b9d861673affd17722744ed8cb (diff)
grammar: Avoid re-creating parsers used as building block
Enforcing the legemtimate status values is better done in the parser and not in the grammar. We don't do it in the parser yet but that can be done later.
-rw-r--r--TODO2
-rw-r--r--grammar/SIPGrammar.st80
2 files changed, 17 insertions, 65 deletions
diff --git a/TODO b/TODO
index 52c1217..8ce4dc4 100644
--- a/TODO
+++ b/TODO
@@ -32,6 +32,8 @@ General:
need to re-send the 401/403?
* Compare with MGCPCommands and share code... in SIPRequest
* Via we should indicate the received address and port...
+* Verify that status code is valid. It used to be done inside the
+ grammar but that is not the right place.
* 3xx, 4xx, 5xx, 6xx are final. We should not allow any other messages.
diff --git a/grammar/SIPGrammar.st b/grammar/SIPGrammar.st
index fe5d40d..ed1a5a6 100644
--- a/grammar/SIPGrammar.st
+++ b/grammar/SIPGrammar.st
@@ -23,7 +23,8 @@ PP.PPCompositeParser subclass: SIPGrammar [
message_body SIPVersion StatusCode ReasonPhrase
extension_header header_name header_value
Request RequestLine Method extension_method
- RequestURI quoted_string token
+ RequestURI quoted_string token commonUriParser paramchar
+ header
|
"http://sofia-sip.org/repos/sofia-sip/libsofia-sip-ua/sip/GRAMMAR"
<category: 'OsmoSIP-Grammar'>
@@ -69,14 +70,17 @@ PP.PPCompositeParser subclass: SIPGrammar [
SIPURI [
<category: 'request'>
- ^ 'sip:' asParser , self userinfo optional,
- self hostport, self uri_parameters, self headers optional.
+ ^ 'sip:' asParser , commonUriParser
+ ]
+
+ commonUriParser [
+ ^self userinfo optional, self hostport, self uri_parameters,
+ self headers optional.
]
SIPSURI [
<category: 'request'>
- ^ 'sips:' asParser , self userinfo optional,
- self hostport, self uri_parameters, self headers optional.
+ ^ 'sips:' asParser , commonUriParser
]
hostport [
@@ -113,17 +117,17 @@ PP.PPCompositeParser subclass: SIPGrammar [
pname [
<category: 'generic'>
- ^ self paramchar plus flatten
+ ^paramchar
]
pvalue [
<category: 'generic'>
- ^ self paramchar plus flatten
+ ^paramchar
]
paramchar [
<category: 'generic'>
- ^ self param_unreserved / self unreserved / self escaped
+ ^ (self param_unreserved / self unreserved / self escaped) plus flatten
]
param_unreserved [
@@ -134,12 +138,12 @@ PP.PPCompositeParser subclass: SIPGrammar [
headers [
<category: 'generic'>
- ^ $? asParser, self header, ($& asParser, self header) star
+ ^ $? asParser, header, ($& asParser, header) star
]
header [
<category: 'generic'>
- ^ self hname, $= asParser, self hvalue
+ ^self hname, $= asParser, self hvalue
]
hname [
@@ -247,61 +251,7 @@ PP.PPCompositeParser subclass: SIPGrammar [
StatusCode [
<category: 'response'>
"Combined into one..."
- ^ '100' asParser / "Trying"
- '101' asParser / "Early Dialog.. of Linphone"
- '180' asParser / "Ringing"
- '181' asParser / "Call Is Being Forwarded"
- '182' asParser / "Queued"
- '183' asParser / "Session Progress"
-
- '200' asParser / "OK"
-
- '300' asParser / "Multiple Choices"
- '301' asParser / "Moved Permanently"
- '302' asParser / "Moved Temporarily"
- '380' asParser / "Alternative Service"
-
- '400' asParser / "Bad Request"
- '401' asParser / "Unauthorized"
- '402' asParser / "Payment Required"
- '403' asParser / "Forbidden"
- '404' asParser / "Not Found"
- '405' asParser / "Method Not Allowed"
- '406' asParser / "Not Acceptable"
- '407' asParser / "Proxy Authentication Required"
- '408' asParser / "Request Timeout"
- '410' asParser / "Gone"
- '413' asParser / "Request Entity Too Large"
- '414' asParser / "Request-URI Too Large"
- '415' asParser / "Unsupported Media Type"
- '416' asParser / "Unsupported URI Scheme"
- '420' asParser / "Bad Extension"
- '421' asParser / "Extension Required"
- '423' asParser / "Interval Too Brief"
- '480' asParser / "Temporarily not available"
- '481' asParser / "Call Leg/Transaction Does Not Exist"
- '482' asParser / "Loop Detected"
- '483' asParser / "Too Many Hops"
- '484' asParser / "Address Incomplete"
- '485' asParser / "Ambiguous"
- '486' asParser / "Busy Here"
- '487' asParser / "Request Terminated"
- '488' asParser / "Not Acceptable Here"
- '491' asParser / "Request Pending"
- '493' asParser / "Undecipherable"
-
- '500' asParser / "Internal Server Error"
- '501' asParser / "Not Implemented"
- '502' asParser / "Bad Gateway"
- '503' asParser / "Service Unavailable"
- '504' asParser / "Server Time-out"
- '505' asParser / "SIP Version not supported"
- '513' asParser / "Message Too Large"
-
- '600' asParser / "Busy Everywhere"
- '603' asParser /"Decline"
- '604' asParser /"Does not exist anywhere"
- '606' asParser "Not Acceptable"
+ ^ (#digit asParser min: 3 max: 3) flatten
]
ReasonPhrase [