-
Notifications
You must be signed in to change notification settings - Fork 24
/
GetParameterValues.go
76 lines (66 loc) · 1.94 KB
/
GetParameterValues.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
package cwmp
import (
"encoding/xml"
"fmt"
"strconv"
"time"
"github.com/ca17/teamsacs/common/xmlx"
)
// GetParameterValues get paramvalues
type GetParameterValues struct {
ID string
Name string
NoMore int
ParameterNames []string
}
type getParameterValuesBodyStruct struct {
Body getParameterValuesStruct `xml:"cwmp:GetParameterValues"`
}
type getParameterValuesStruct struct {
Params parameterNamesStruct `xml:"ParameterNames"`
}
type parameterNamesStruct struct {
Type string `xml:"soap-enc:arrayType,attr"`
ParamNames []string `xml:"string"`
}
// GetName get type name
func (msg *GetParameterValues) GetName() string {
return "GetParameterValues"
}
// GetID get tr069 msg id
func (msg *GetParameterValues) GetID() string {
if len(msg.ID) < 1 {
msg.ID = fmt.Sprintf("ID:intrnl.unset.id.%s%d.%d", msg.GetName(), time.Now().Unix(), time.Now().UnixNano())
}
return msg.ID
}
// CreateXML encode into xml
func (msg *GetParameterValues) CreateXML() []byte {
env := Envelope{}
id := IDStruct{"1", msg.GetID()}
env.XmlnsEnv = "http://schemas.xmlsoap.org/soap/envelope/"
env.XmlnsEnc = "http://schemas.xmlsoap.org/soap/encoding/"
env.XmlnsXsd = "http://www.w3.org/2001/XMLSchema"
env.XmlnsXsi = "http://www.w3.org/2001/XMLSchema-instance"
env.XmlnsCwmp = "urn:dslforum-org:cwmp-1-0"
env.Header = HeaderStruct{ID: id, NoMore: msg.NoMore}
paramLen := strconv.Itoa(len(msg.ParameterNames))
paramNames := parameterNamesStruct{
Type: XsdString + "[" + paramLen + "]",
}
for _, v := range msg.ParameterNames {
paramNames.ParamNames = append(paramNames.ParamNames, v)
}
body := getParameterValuesStruct{paramNames}
env.Body = getParameterValuesBodyStruct{body}
output, err := xml.MarshalIndent(env, " ", " ")
// output, err := xml.Marshal(env)
if err != nil {
fmt.Printf("error: %v\n", err)
}
return output
}
// Parse decode from xml
func (msg *GetParameterValues) Parse(doc *xmlx.Document) {
// TODO
}