forked from rainliu/sip
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ErrorInfoParser.go
92 lines (75 loc) · 2.16 KB
/
ErrorInfoParser.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
package parser
import (
"sip/core"
"sip/address"
"sip/header"
)
/** SIPParser for ErrorInfo header.
*/
type ErrorInfoParser struct {
ParametersParser
}
/**
* Creates a new instance of ErrorInfoParser
* @param errorInfo the header to parse
*/
func NewErrorInfoParser(errorInfo string) *ErrorInfoParser {
this := &ErrorInfoParser{}
this.ParametersParser.super(errorInfo)
return this
}
/** Constructor
* @param lexer the lexer to use to parse the header
*/
func NewErrorInfoParserFromLexer(lexer core.Lexer) *ErrorInfoParser {
this := &ErrorInfoParser{}
this.ParametersParser.superFromLexer(lexer)
return this
}
/** parse the ErrorInfo String header
* @return Header (ErrorInfoList object)
* @throws SIPParseException if the message does not respect the spec.
*/
func (this *ErrorInfoParser) Parse() (sh header.Header, ParseException error) {
errorInfoList := header.NewErrorInfoList()
var ch byte
var uri address.URI
lexer := this.GetLexer()
this.HeaderName(TokenTypes_ERROR_INFO)
for ch, _ = lexer.LookAheadK(0); ch != '\n'; ch, _ = lexer.LookAheadK(0) {
errorInfo := header.NewErrorInfo()
errorInfo.SetHeaderName(core.SIPHeaderNames_ERROR_INFO)
lexer.SPorHT()
lexer.Match('<')
urlParser := NewURLParserFromLexer(lexer)
if uri, ParseException = urlParser.UriReference(); ParseException != nil {
return nil, ParseException
}
errorInfo.SetErrorInfo(uri)
lexer.Match('>')
lexer.SPorHT()
if ParseException = this.ParametersParser.Parse(errorInfo); ParseException != nil {
return nil, ParseException
}
errorInfoList.PushBack(errorInfo)
for ch, _ = lexer.LookAheadK(0); ch == ','; ch, _ = lexer.LookAheadK(0) {
lexer.Match(',')
lexer.SPorHT()
errorInfo = header.NewErrorInfo()
lexer.SPorHT()
lexer.Match('<')
urlParser = NewURLParserFromLexer(lexer)
if uri, ParseException = urlParser.UriReference(); ParseException != nil {
return nil, ParseException
}
errorInfo.SetErrorInfo(uri)
lexer.Match('>')
lexer.SPorHT()
if ParseException = this.ParametersParser.Parse(errorInfo); ParseException != nil {
return nil, ParseException
}
errorInfoList.PushBack(errorInfo)
}
}
return errorInfoList, nil
}