forked from rainliu/sip
-
Notifications
You must be signed in to change notification settings - Fork 1
/
AcceptParser.go
87 lines (72 loc) · 1.98 KB
/
AcceptParser.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package parser
import (
"sip/core"
"sip/header"
)
/** SIPParser for Accept header.
*/
type AcceptParser struct {
ParametersParser
}
/**
* Creates a new instance of Accept SIPParser
* @param accept the header to parse
*/
func NewAcceptParser(accept string) *AcceptParser {
this := &AcceptParser{}
this.ParametersParser.super(accept)
return this
}
/** Constructor
* @param lexer the lexer to use to parse the header
*/
func NewAcceptParserFromLexer(lexer core.Lexer) *AcceptParser {
this := &AcceptParser{}
this.ParametersParser.superFromLexer(lexer)
return this
}
func (this *AcceptParser) super(buffer string) {
this.ParametersParser.super(buffer)
}
func (this *AcceptParser) superFromLexer(lexer core.Lexer) {
this.ParametersParser.superFromLexer(lexer)
}
/** parse the Accept String header
* @return Header (AcceptList object)
* @throws SIPParseException if the message does not respect the spec.
*/
func (this *AcceptParser) Parse() (sh header.Header, ParseException error) {
acceptList := header.NewAcceptList()
var ch byte
lexer := this.GetLexer()
this.HeaderName(TokenTypes_ACCEPT)
accept := header.NewAccept()
accept.SetHeaderName(core.SIPHeaderNames_ACCEPT)
lexer.SPorHT()
lexer.Match(TokenTypes_ID)
token := lexer.GetNextToken()
accept.SetContentType(token.GetTokenValue())
lexer.Match('/')
lexer.Match(TokenTypes_ID)
token = lexer.GetNextToken()
accept.SetContentSubType(token.GetTokenValue())
lexer.SPorHT()
this.ParametersParser.Parse(accept)
acceptList.PushBack(accept)
for ch, _ = lexer.LookAheadK(0); ch == ','; ch, _ = lexer.LookAheadK(0) {
lexer.Match(',')
lexer.SPorHT()
accept = header.NewAccept()
lexer.Match(TokenTypes_ID)
token = lexer.GetNextToken()
accept.SetContentType(token.GetTokenValue())
lexer.Match('/')
lexer.Match(TokenTypes_ID)
token = lexer.GetNextToken()
accept.SetContentSubType(token.GetTokenValue())
lexer.SPorHT()
this.ParametersParser.Parse(accept)
acceptList.PushBack(accept)
}
return acceptList, nil
}