forked from rainliu/sip
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ContactParser.go
63 lines (56 loc) · 1.46 KB
/
ContactParser.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
55
56
57
58
59
60
61
62
63
package parser
import (
"sip/core"
"sip/header"
"strconv"
)
/**
* A parser for The SIP contact header.
*/
type ContactParser struct {
AddressParametersParser
}
func NewContactParser(contact string) *ContactParser {
this := &ContactParser{}
this.AddressParametersParser.super(contact)
return this
}
func NewContactParserFromLexer(lexer core.Lexer) *ContactParser {
this := &ContactParser{}
this.AddressParametersParser.superFromLexer(lexer)
return this
}
func (this *ContactParser) Parse() (sh header.Header, ParseException error) {
retval := header.NewContactList()
// past the header name and the colon.
lexer := this.GetLexer()
var la byte
this.HeaderName(TokenTypes_CONTACT)
for {
contact := header.NewContact()
if la, _ = lexer.LookAheadK(0); la == '*' {
lexer.Match('*')
contact.SetWildCardFlag(true)
} else {
if ParseException = this.AddressParametersParser.Parse(contact); ParseException != nil {
return nil, ParseException
}
if contact.HasParameter(header.ParameterNames_EXPIRES) {
if _, ParseException = strconv.Atoi(contact.GetParameter(header.ParameterNames_EXPIRES)); ParseException != nil {
return nil, ParseException
}
}
}
retval.AddContact(contact)
lexer.SPorHT()
if la, _ = lexer.LookAheadK(0); la == ',' {
lexer.Match(',')
lexer.SPorHT()
} else if la, _ = lexer.LookAheadK(0); la == '\n' {
break
} else {
return nil, this.CreateParseException("unexpected char")
}
}
return retval, nil
}