diff --git a/callagent/SIPDialog.st b/callagent/SIPDialog.st index fc7c00a..3972154 100644 --- a/callagent/SIPDialog.st +++ b/callagent/SIPDialog.st @@ -83,7 +83,13 @@ Object subclass: SIPDialog [ to_tag := aTag ] + callId: aCallId [ + + call_id := aCallId + ] + callId [ + ^ call_id ] @@ -155,27 +161,45 @@ Object subclass: SIPDialog [ ^ dest_port ] + checkCompatible: other [ + + "I am checking if the dialog is compatible." + + self callId = other callId ifFalse: [ + ^ self error: 'SIPDialog is not compatible due wrong CallID %1 %2.' + % {self callId. other callId}. + ]. + + self from_tag = other from_tag ifFalse: [ + ^ self error: 'SIPDialog is not compatible due wrong from tag %1 %2.' + % {self from_tag. other from_tag} + ]. + + self to_tag isNil ifFalse: [ + self to_tag = other to_tag ifFalse: [ + ^ self error: 'SIPDialog is not compatible due to tag %1 %2.' + % {self to_tag. other to_tag} + ]. + ]. + ] + newFromRequest: aReq [ - | to pos tag| + | to other | - "I try to confirm a dialog" + "I try to confirm a dialog, i also verify that it is somehow compatible." + + other := SIPDialog fromMessage: aReq. + self checkCompatible: other. "I am already confirmed." self isConfirmed ifTrue: [^self]. - "I have a tag but I am not confirmed, create a copy and confirm" - to_tag ifNotNil: [ - ^ self copy - confirm; - yourself]. - "There is no To... hmm return us" to := aReq parameter: 'To' ifAbsent: [^self]. - (tag := to tag) isNil ifTrue: [ - ^ self]. + to tag isNil ifTrue: [^self]. ^ self copy - toTag: tag; + toTag: to tag; confirm; yourself. ] diff --git a/callagent/SIPParserTest.st b/callagent/SIPParserTest.st index 09fbe35..abb07f7 100644 --- a/callagent/SIPParserTest.st +++ b/callagent/SIPParserTest.st @@ -74,4 +74,23 @@ PP.PPCompositeParserTest subclass: SIPParserTest [ assert: dialog callId = 'MzY3NzE3ODgyNw__@xiaoyu'; assert: dialog cseq = 1. ] + + testDialogCompatible [ + | initial_dialog dialog1 dialog2 | + initial_dialog := (SIPDialog + fromUser: 'sip:1000@on-waves.com' host: '0.0.0.0' port: 5060) + fromTag: 'MzQ4NTQ0MTg2NzIyNDEwNjkyNjY_'; + callId: 'MzY3NzE3ODgyNw__@xiaoyu'; + yourself. + self assert: initial_dialog isUnconfirmed. + self deny: initial_dialog isConfirmed. + + dialog1 := initial_dialog newFromRequest: (self parse: self testResponseData). + self deny: initial_dialog == dialog1. + self assert: dialog1 isConfirmed. + + dialog2 := dialog1 newFromRequest: (self parse: self testResponseData). + self assert: dialog1 == dialog2. + self assert: dialog2 isConfirmed. + ] ] diff --git a/callagent/SIPTransactions.st b/callagent/SIPTransactions.st index 76150d0..0f9ee5c 100644 --- a/callagent/SIPTransactions.st +++ b/callagent/SIPTransactions.st @@ -152,8 +152,6 @@ Object subclass: SIPTransaction [ fail_time cancel. ]. - "Verify the To/From tags here" - "Store all dialogs.... and match them..." dialog := initial_dialog newFromRequest: aReq.