forked from rainliu/sip
-
Notifications
You must be signed in to change notification settings - Fork 1
/
StatusLineParser.go
59 lines (50 loc) · 1.36 KB
/
StatusLineParser.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
package parser
import (
"sip/core"
"sip/header"
"strings"
)
/** SIPParser for the SIP status line.
*/
type StatusLineParser struct {
SIPParser
}
func NewStatusLineParser(statusLine string) *StatusLineParser {
this := &StatusLineParser{}
this.CoreParser.Super(statusLine)
this.SetLexer(NewSIPLexer("status_lineLexer", statusLine))
return this
}
func NewStatusLineParserFromLexer(lexer core.Lexer) *StatusLineParser {
this := &StatusLineParser{}
this.SetLexer(lexer)
this.GetLexer().SelectLexer("status_lineLexer")
return this
}
func (this *StatusLineParser) StatusCode() (scode int, ParseException error) {
scode, ParseException = this.GetLexer().Number()
return scode, ParseException
}
func (this *StatusLineParser) ReasonPhrase() string {
return strings.TrimSpace(this.GetLexer().GetRest())
}
func (this *StatusLineParser) Parse() (sl *header.StatusLine, ParseException error) {
retval := header.NewStatusLine()
lexer := this.GetLexer()
var version string
if version, ParseException = this.SipVersion(); ParseException != nil {
return nil, ParseException
}
retval.SetSipVersion(version)
lexer.SPorHT()
var scode int
if scode, ParseException = this.StatusCode(); ParseException != nil {
return nil, ParseException
}
retval.SetStatusCode(scode)
lexer.SPorHT()
rp := this.ReasonPhrase()
retval.SetReasonPhrase(rp)
lexer.SPorHT()
return retval, nil
}