forked from rainliu/sip
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CallInfoParser.go
86 lines (71 loc) · 1.96 KB
/
CallInfoParser.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
package parser
import (
"sip/core"
"sip/address"
"sip/header"
)
/** SIPParser for CallInfo header.
*/
type CallInfoParser struct {
ParametersParser
}
/**
* Creates a new instance of CallInfoParser
* @param callInfo the header to parse
*/
func NewCallInfoParser(callInfo string) *CallInfoParser {
this := &CallInfoParser{}
this.ParametersParser.super(callInfo)
return this
}
/** Constructor
* @param lexer the lexer to use to parse the header
*/
func NewCallInfoParserFromLexer(lexer core.Lexer) *CallInfoParser {
this := &CallInfoParser{}
this.ParametersParser.superFromLexer(lexer)
return this
}
/** parse the CallInfo String header
* @return Header (CallInfoList object)
* @throws SIPParseException if the message does not respect the spec.
*/
func (this *CallInfoParser) Parse() (sh header.Header, ParseException error) {
callInfoList := header.NewCallInfoList()
var ch byte
var uri address.URI
lexer := this.GetLexer()
this.HeaderName(TokenTypes_CALL_INFO)
for ch, _ = lexer.LookAheadK(0); ch != '\n'; ch, _ = lexer.LookAheadK(0) {
callInfo := header.NewCallInfo()
callInfo.SetHeaderName(core.SIPHeaderNames_CALL_INFO)
lexer.SPorHT()
lexer.Match('<')
urlParser := NewURLParserFromLexer(lexer)
if uri, ParseException = urlParser.UriReference(); ParseException != nil {
return nil, ParseException
}
callInfo.SetInfo(uri)
lexer.Match('>')
lexer.SPorHT()
this.ParametersParser.Parse(callInfo)
callInfoList.PushBack(callInfo)
for ch, _ = lexer.LookAheadK(0); ch == ','; ch, _ = lexer.LookAheadK(0) {
lexer.Match(',')
lexer.SPorHT()
callInfo = header.NewCallInfo()
lexer.SPorHT()
lexer.Match('<')
urlParser = NewURLParserFromLexer(lexer)
if uri, ParseException = urlParser.UriReference(); ParseException != nil {
return nil, ParseException
}
callInfo.SetInfo(uri)
lexer.Match('>')
lexer.SPorHT()
this.ParametersParser.Parse(callInfo)
callInfoList.PushBack(callInfo)
}
}
return callInfoList, nil
}