diff --git a/callagent/MGCPCallAgent.st b/callagent/MGCPCallAgent.st
index d1f0444..8532303 100644
--- a/callagent/MGCPCallAgent.st
+++ b/callagent/MGCPCallAgent.st
@@ -143,8 +143,8 @@ MGCPCallAgentBase subclass: MGCPCallAgent [
[
| res data id trans |
data := aData data copyFrom: 1 to: aData size.
- res := MGCPGrammar new parse: data asString.
- id := res first third asInteger.
+ res := MGCPParser new parse: data asString.
+ id := res transactionId asInteger.
trans := sem critical: [transactions copy].
trans do: [:each |
diff --git a/callagent/MGCPParser.st b/callagent/MGCPParser.st
new file mode 100644
index 0000000..18c3a2f
--- /dev/null
+++ b/callagent/MGCPParser.st
@@ -0,0 +1,37 @@
+"
+ (C) 2011 by Holger Hans Peter Freyther
+ All Rights Reserved
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+"
+
+MGCPGrammar subclass: MGCPParser [
+
+
+
+ MGCPMessage [
+
+ ^ super MGCPMessage => [:nodes | nodes]
+ ]
+
+ MGCPCommand [
+
+ ^ super MGCPCommand => [:nodes | nil]
+ ]
+
+ MGCPResponse [
+
+ ^ super MGCPResponse => [:nodes | MGCPResponse fromDict: nodes]
+ ]
+]
diff --git a/callagent/MGCPResponse.st b/callagent/MGCPResponse.st
new file mode 100644
index 0000000..babcff6
--- /dev/null
+++ b/callagent/MGCPResponse.st
@@ -0,0 +1,96 @@
+"
+ (C) 2011 by Holger Hans Peter Freyther
+ All Rights Reserved
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+"
+
+Object subclass: MGCPResponse [
+ | code transaction params sdp |
+
+
+
+
+ MGCPResponse class >> fromDict: aDict [
+
+ ^ self new
+ initialize;
+ responseCode: aDict first first;
+ transaction: aDict first third;
+ addParamsFromDict: aDict second;
+ addSDPFromDict: aDict third;
+ yourself
+ ]
+
+ initialize [
+
+ params := Dictionary new.
+ ]
+
+ responseCode: aCode [
+
+ code := aCode asInteger
+ ]
+
+ transaction: aTrans [
+
+ transaction := aTrans.
+ ]
+
+ addParamsFromDict: aList [
+
+
+ aList do: [:each |
+ params at: each first first asString put: each first fourth].
+ ]
+
+ addSDPFromDict: aDict [
+ | str |
+
+
+ str := WriteStream on: (String new).
+ aDict second do: [:each |
+ str
+ nextPutAll: each first;
+ cr; nl.
+ ].
+
+ sdp := str contents.
+ ]
+
+ transactionId [
+
+ ^ transaction
+ ]
+
+ code [
+
+ ^ code
+ ]
+
+ isSuccess [
+
+ ^ code >= 200 and: [code < 300].
+ ]
+
+ sdp [
+
+ ^ sdp
+ ]
+
+ parameterAt: aKey ifAbsent: aBlock [
+ ^ params at: aKey ifAbsent: aBlock.
+ ]
+
+]
diff --git a/callagent/Tests.st b/callagent/Tests.st
index 8479564..3990aed 100644
--- a/callagent/Tests.st
+++ b/callagent/Tests.st
@@ -259,3 +259,40 @@ TestCase subclass: MGCPEndpointAllocTest [
self assert: endp endpointName = '4@mgw'.
]
]
+
+PP.PPCompositeParserTest subclass: MGCPParserTest [
+
+
+ parserClass [
+ ^MGCPParser
+ ]
+
+ testRespParse [
+ | nl res sdp |
+ nl := Character cr asString, Character nl asString.
+
+ sdp := 'v=0', nl,
+ 'o=- 258696477 0 IN IP4 172.16.1.107', nl,
+ 's=-', nl,
+ 'c=IN IP4 172.16.1.107', nl,
+ 't=0 0', nl,
+ 'm=audio 6666 RTP/AVP 127', nl,
+ 'a=rtpmap:127 GSM-EFR/8000/1', nl,
+ 'a=ptime:20', nl,
+ 'a=recvonly', nl,
+ 'm=image 4402 udptl t38', nl,
+ 'a=T38FaxVersion:0', nl,
+ 'a=T38MaxBitRate:14400', nl.
+
+ res := self parse: '200 32323 OK', nl,
+ 'I: 233434', nl,
+ nl,
+ sdp.
+
+ self assert: res code = 200.
+ self assert: res isSuccess.
+ self assert: res transactionId = '32323'.
+ self assert: res sdp = sdp.
+ self assert: (res parameterAt: 'I' ifAbsent: []) = '233434'.
+ ]
+]
diff --git a/grammar/MGCPGrammar.st b/grammar/MGCPGrammar.st
index fe2056c..62e98cf 100644
--- a/grammar/MGCPGrammar.st
+++ b/grammar/MGCPGrammar.st
@@ -19,7 +19,7 @@
PackageLoader fileInPackage: 'PetitParser'.
PP.PPCompositeParser subclass: MGCPGrammar [
- | MGCPMessage EOL One_WSP MGCPMessage MGCPCommandLine MGCPVerb transaction_id endpointName MGCPversion MGCPParameter MGCPCommand ParameterValue SDPRecord SDPLine SDPinformation MGCPResponse MGCPResponseLine responseCode responseString packageName |
+ | MGCPMessage EOL One_WSP MGCPMessage MGCPCommandLine MGCPVerb transaction_id endpointName MGCPversion MGCPParameter MGCPCommand ParameterValue SDPRecord SDPLine SDPinformation MGCPResponseLine responseCode responseString packageName |
@@ -41,7 +41,7 @@ PP.PPCompositeParser subclass: MGCPGrammar [
MGCPMessage [
- ^ MGCPCommand / MGCPResponse
+ ^ MGCPCommand / self MGCPResponse
]
MGCPCommandLine [
diff --git a/package.xml b/package.xml
index 0ebcfa1..ffcf9bd 100644
--- a/package.xml
+++ b/package.xml
@@ -8,16 +8,19 @@
callagent/MGCPCallAgent.st
callagent/MGCPCommands.st
+ callagent/MGCPResponse.st
callagent/MGCPEndpoint.st
callagent/MGCPLogArea.st
callagent/MGCPTransaction.st
callagent/MGCPTrunk.st
+ callagent/MGCPParser.st
Osmo.MGCPGrammarTest
Osmo.MGCPCommandTest
Osmo.MGCPEndpointAllocTest
Osmo.MGCPTransactionTest
+ Osmo.MGCPParserTest
grammar/MGCPGrammarTest.st
callagent/Tests.st