forked from rainliu/sip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RequestLineParser.go
58 lines (49 loc) · 1.37 KB
/
RequestLineParser.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
package parser
import (
"github.com/tutuvss/sip/core"
"github.com/tutuvss/sip/address"
"github.com/tutuvss/sip/header"
)
/** SIPParser for the SIP request line.
*/
type RequestLineParser struct {
SIPParser
}
func NewRequestLineParser(requestLine string) *RequestLineParser {
this := &RequestLineParser{}
this.CoreParser.Super(requestLine)
this.SetLexer(NewSIPLexer("method_keywordLexer", requestLine))
return this
}
func NewRequestLineParserFromLexer(lexer core.Lexer) *RequestLineParser {
this := &RequestLineParser{}
this.SetLexer(lexer)
this.GetLexer().SelectLexer("method_keywordLexer")
return this
}
func (this *RequestLineParser) Parse() (rl *header.RequestLine, ParseException error) {
var m, v string
var url address.URI
retval := header.NewRequestLine()
lexer := this.GetLexer()
if m, ParseException = this.Method(); ParseException != nil {
return nil, ParseException
}
lexer.SPorHT()
retval.SetMethod(m)
lexer.SelectLexer("sip_urlLexer")
urlParser := NewURLParserFromLexer(this.GetLexer())
if url, ParseException = urlParser.UriReference(); ParseException != nil {
return nil, ParseException
}
lexer.SPorHT()
retval.SetUri(url)
lexer.SelectLexer("request_lineLexer")
if v, ParseException = this.SipVersion(); ParseException != nil {
return nil, ParseException
}
retval.SetSipVersion(v)
lexer.SPorHT()
lexer.Match('\n')
return retval, nil
}