forked from rainliu/sip
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ProxyRequireParser.go
73 lines (58 loc) · 1.66 KB
/
ProxyRequireParser.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
package parser
import (
"sip/core"
"sip/header"
)
/** SIPParser for ProxyRequire header.
*/
type ProxyRequireParser struct {
HeaderParser
}
/** Creates a new instance of ProxyRequireParser
*@param require the header to parse
*/
func NewProxyRequireParser(require string) *ProxyRequireParser {
this := &ProxyRequireParser{}
this.HeaderParser.super(require)
return this
}
/** Constructor
* @param lexer the lexer to use to parse the header
*/
func NewProxyRequireParserFromLexer(lexer core.Lexer) *ProxyRequireParser {
this := &ProxyRequireParser{}
this.HeaderParser.superFromLexer(lexer)
return this
}
/** parse the String message
* @return SIPHeader (ProxyRequireList object)
* @throws SIPParseException if the message does not respect the spec.
*/
func (this *ProxyRequireParser) Parse() (sh header.Header, ParseException error) {
proxyRequireList := header.NewProxyRequireList()
var ch byte
lexer := this.GetLexer()
this.HeaderName(TokenTypes_PROXY_REQUIRE)
for ch, _ = lexer.LookAheadK(0); ch != '\n'; ch, _ = lexer.LookAheadK(0) {
r := header.NewProxyRequire()
r.SetHeaderName(core.SIPHeaderNames_PROXY_REQUIRE)
// Parsing the option tag
lexer.Match(TokenTypes_ID)
token := lexer.GetNextToken()
r.SetOptionTag(token.GetTokenValue())
lexer.SPorHT()
proxyRequireList.PushBack(r)
for ch, _ = lexer.LookAheadK(0); ch == ','; ch, _ = lexer.LookAheadK(0) {
lexer.Match(',')
lexer.SPorHT()
r = header.NewProxyRequire()
// Parsing the option tag
lexer.Match(TokenTypes_ID)
token = lexer.GetNextToken()
r.SetOptionTag(token.GetTokenValue())
lexer.SPorHT()
proxyRequireList.PushBack(r)
}
}
return proxyRequireList, nil
}