-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathauthorization.go
55 lines (51 loc) · 1.21 KB
/
authorization.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
// Copyright 2011, Shelby Ramsey. All rights reserved.
// Copyright 2018, Eugen Biegler. All rights reserved.
// Use of this code is governed by a BSD license that can be
// found in the LICENSE.txt file.
package sipparser
// Imports from go standard library
import (
"errors"
"strings"
)
type Authorization struct {
Val string
Credentials string
Username string
//Params []*Param
}
/*
func (a *Authorization) GetParam(param string) *Param {
if a.Params == nil {
return nil
}
for i := range a.Params {
if a.Params[i].Param == param {
return a.Params[i]
}
}
return nil
}
*/
func (a *Authorization) parse() error {
pos := strings.IndexRune(a.Val, ' ')
if pos == -1 {
return errors.New("Authorization.parse err: no LWS found")
}
a.Credentials = a.Val[0:pos]
if len(a.Val)-1 <= pos {
return errors.New("Authorization.parse err: no digest-resp found")
}
a.Username = extractParam("username=\"", a.Val)
/*
a.Params = make([]*Param, 0)
parts := strings.Split(a.Val[pos+1:], ",")
for i := range parts {
a.Params = append(a.Params, getParam(strings.Replace(parts[i], "\"", "", -1)))
}
if a.GetParam("username") != nil {
a.Username = a.GetParam("username").Val
}
*/
return nil
}