forked from rainliu/sip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContentDispositionParser.go
58 lines (48 loc) · 1.47 KB
/
ContentDispositionParser.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/header"
)
/** SIPParser for ContentLanguage header.
*/
type ContentDispositionParser struct {
ParametersParser
}
/**
* Creates a new instance of ContentDispositionParser
* @param contentDisposition the header to parse
*/
func NewContentDispositionParser(contentDisposition string) *ContentDispositionParser {
this := &ContentDispositionParser{}
this.ParametersParser.super(contentDisposition)
return this
}
/** Constructor
* @param lexer the lexer to use to parse the header
*/
func NewContentDispositionParserFromLexer(lexer core.Lexer) *ContentDispositionParser {
this := &ContentDispositionParser{}
this.ParametersParser.superFromLexer(lexer)
return this
}
/** parse the ContentDispositionHeader String header
* @return Header (ContentDispositionList object)
* @throws SIPParseException if the message does not respect the spec.
*/
func (this *ContentDispositionParser) Parse() (sh header.Header, ParseException error) {
lexer := this.GetLexer()
this.HeaderName(TokenTypes_CONTENT_DISPOSITION)
cd := header.NewContentDisposition()
cd.SetHeaderName(core.SIPHeaderNames_CONTENT_DISPOSITION)
lexer.SPorHT()
lexer.Match(TokenTypes_ID)
token := lexer.GetNextToken()
cd.SetDispositionType(token.GetTokenValue())
lexer.SPorHT()
if ParseException = this.ParametersParser.Parse(cd); ParseException != nil {
return nil, ParseException
}
lexer.SPorHT()
lexer.Match('\n')
return cd, nil
}