forked from rainliu/sip
-
Notifications
You must be signed in to change notification settings - Fork 1
/
AllowEventsParser.go
72 lines (58 loc) · 1.63 KB
/
AllowEventsParser.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
64
65
66
67
68
69
70
71
72
package parser
import (
"sip/core"
"sip/header"
)
/** SIPParser for AllowEvents header.
*/
type AllowEventsParser struct {
HeaderParser
}
/**
* Creates a new instance of AllowEventsParser
* @param allowEvents the header to parse
*/
func NewAllowEventsParser(allowEvents string) *AllowEventsParser {
this := &AllowEventsParser{}
this.HeaderParser.super(allowEvents)
return this
}
/** Constructor
* @param lexer the lexer to use to parse the header
*/
func NewAllowEventsParserFromLexer(lexer core.Lexer) *AllowEventsParser {
this := &AllowEventsParser{}
this.HeaderParser.superFromLexer(lexer)
return this
}
/** parse the AllowEvents String header
* @return Header (AllowEventsList object)
* @throws SIPParseException if the message does not respect the spec.
*/
func (this *AllowEventsParser) Parse() (sh header.Header, ParseException error) {
allowEventsList := header.NewAllowEventsList()
var ch byte
lexer := this.GetLexer()
this.HeaderName(TokenTypes_ALLOW_EVENTS)
allowEvents := header.NewAllowEvents()
allowEvents.SetHeaderName(core.SIPHeaderNames_ALLOW_EVENTS)
lexer.SPorHT()
lexer.Match(TokenTypes_ID)
token := lexer.GetNextToken()
allowEvents.SetEventType(token.GetTokenValue())
allowEventsList.PushBack(allowEvents)
lexer.SPorHT()
for ch, _ = lexer.LookAheadK(0); ch == ','; ch, _ = lexer.LookAheadK(0) {
lexer.Match(',')
lexer.SPorHT()
allowEvents = header.NewAllowEvents()
lexer.Match(TokenTypes_ID)
token = lexer.GetNextToken()
allowEvents.SetEventType(token.GetTokenValue())
allowEventsList.PushBack(allowEvents)
lexer.SPorHT()
}
lexer.SPorHT()
lexer.Match('\n')
return allowEventsList, nil
}