/
ToParser.go
51 lines (44 loc) · 1.13 KB
/
ToParser.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package parser
import (
"gosips/core"
"gosips/sip/address"
"gosips/sip/header"
)
/* To Header parser.*/
type ToParser struct {
AddressParametersParser
}
/** Creates new ToParser
* @param String to set
*/
func NewToParser(to string) *ToParser {
this := &ToParser{}
this.AddressParametersParser.super(to)
return this
}
func NewToParserFromLexer(lexer core.Lexer) *ToParser {
this := &ToParser{}
this.AddressParametersParser.superFromLexer(lexer)
return this
}
func (this *ToParser) Parse() (sh header.Header, ParseException error) {
to := header.NewTo()
this.HeaderName(TokenTypes_TO)
if ParseException = this.AddressParametersParser.Parse(to); ParseException != nil {
return nil, ParseException
}
this.GetLexer().Match('\n')
addr := to.GetAddress().(*address.AddressImpl)
if addr.GetAddressType() == address.ADDRESS_SPEC {
// the parameters are header parameters.
if to.GetAddress().GetURI().IsSipURI() {
sipUri, _ := to.GetAddress().GetURI().(*address.SipURIImpl)
parms := sipUri.GetUriParms()
if parms != nil && parms.Len() > 0 {
to.SetParameters(parms)
sipUri.RemoveUriParms()
}
}
}
return to, nil
}