forked from rainliu/sip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FromParser.go
54 lines (45 loc) · 1.25 KB
/
FromParser.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
52
53
54
package parser
import (
"github.com/tutuvss/sip/core"
"github.com/tutuvss/sip/address"
"github.com/tutuvss/sip/header"
)
/** From header parser.
*/
type FromParser struct {
AddressParametersParser
}
func NewFromParser(from string) *FromParser {
this := &FromParser{}
this.AddressParametersParser.super(from)
return this
}
func (this *FromParser) super(from string) {
this.AddressParametersParser.super(from)
}
func NewFromParserFromLexer(lexer core.Lexer) *FromParser {
this := &FromParser{}
this.AddressParametersParser.superFromLexer(lexer)
return this
}
func (this *FromParser) Parse() (sh header.Header, ParseException error) {
from := header.NewFrom()
this.HeaderName(TokenTypes_FROM)
if ParseException = this.AddressParametersParser.Parse(from); ParseException != nil {
return nil, ParseException
}
this.GetLexer().Match('\n')
addr := from.GetAddress().(*address.AddressImpl)
if addr.GetAddressType() == address.ADDRESS_SPEC {
// the parameters are header parameters.
if from.GetAddress().GetURI().IsSipURI() {
sipUri, _ := from.GetAddress().GetURI().(*address.SipURIImpl)
parms := sipUri.GetUriParms()
if parms != nil && parms.Len() > 0 {
from.SetParameters(parms)
sipUri.RemoveUriParms()
}
}
}
return from, nil
}