forked from rainliu/sip
-
Notifications
You must be signed in to change notification settings - Fork 1
/
AlertInfoParser.go
96 lines (81 loc) · 2.37 KB
/
AlertInfoParser.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
88
89
90
91
92
93
94
95
96
package parser
import (
"sip/core"
"sip/address"
"sip/header"
)
/** SIPParser for AlertInfo header.
*/
type AlertInfoParser struct {
ParametersParser
}
/**
* Creates a new instance of AlertInfo SIPParser
* @param alertInfo the header to parse
*/
func NewAlertInfoParser(alertInfo string) *AlertInfoParser {
this := &AlertInfoParser{}
this.ParametersParser.super(alertInfo)
return this
}
/** Constructor
* @param lexer the lexer to use to parse the header
*/
func NewAlertInfoParserFromLexer(lexer core.Lexer) *AlertInfoParser {
this := &AlertInfoParser{}
this.ParametersParser.superFromLexer(lexer)
return this
}
func (this *AlertInfoParser) super(buffer string) {
this.ParametersParser.super(buffer)
}
func (this *AlertInfoParser) superFromLexer(lexer core.Lexer) {
this.ParametersParser.superFromLexer(lexer)
}
/** parse the AlertInfo String header
* @return Header (AlertInfoList object)
* @throws SIPParseException if the message does not respect the spec.
*/
func (this *AlertInfoParser) Parse() (sh header.Header, ParseException error) {
alertInfoList := header.NewAlertInfoList()
var ch byte
var uri address.URI
lexer := this.GetLexer()
this.HeaderName(TokenTypes_ALERT_INFO)
for ch, _ = lexer.LookAheadK(0); ch != '\n'; ch, _ = lexer.LookAheadK(0) {
alertInfo := header.NewAlertInfo()
alertInfo.SetHeaderName(core.SIPHeaderNames_ALERT_INFO)
lexer.SPorHT()
lexer.Match('<')
urlParser := NewURLParserFromLexer(lexer)
if uri, ParseException = urlParser.UriReference(); ParseException != nil {
return nil, ParseException
}
alertInfo.SetAlertInfo(uri)
lexer.Match('>')
lexer.SPorHT()
if ParseException = this.ParametersParser.Parse(alertInfo); ParseException != nil {
return nil, ParseException
}
alertInfoList.PushBack(alertInfo)
for ch, _ = lexer.LookAheadK(0); ch == ','; ch, _ = lexer.LookAheadK(0) {
lexer.Match(',')
lexer.SPorHT()
alertInfo = header.NewAlertInfo()
lexer.SPorHT()
lexer.Match('<')
urlParser = NewURLParserFromLexer(lexer)
if uri, ParseException = urlParser.UriReference(); ParseException != nil {
return nil, ParseException
}
alertInfo.SetAlertInfo(uri)
lexer.Match('>')
lexer.SPorHT()
if ParseException = this.ParametersParser.Parse(alertInfo); ParseException != nil {
return nil, ParseException
}
alertInfoList.PushBack(alertInfo)
}
}
return alertInfoList, nil
}