-
Notifications
You must be signed in to change notification settings - Fork 24
/
SetParameterValues.go
78 lines (68 loc) · 2 KB
/
SetParameterValues.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
77
78
package cwmp
import (
"encoding/xml"
"fmt"
"strconv"
"time"
"github.com/ca17/teamsacs/common/xmlx"
)
// SetParameterValues set param
type SetParameterValues struct {
ID string
Name string
NoMore int
Params map[string]ValueStruct
ParameterKey string
}
type setParameterValuesBodyStruct struct {
Body setParameterValuesStruct `xml:"cwmp:SetParameterValues"`
}
type setParameterValuesStruct struct {
ParamList ParameterListStruct `xml:"ParameterList"`
ParameterKey string
}
// GetName get msg type
func (msg *SetParameterValues) GetName() string {
return "SetParameterValues"
}
// GetID get msg id
func (msg *SetParameterValues) 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 *SetParameterValues) 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.Params))
paramList := ParameterListStruct{Type: "cwmp:ParameterValueStruct[" + paramLen + "]"}
for k, v := range msg.Params {
param := ParameterValueStruct{
Name: NodeStruct{Value: k},
Value: NodeStruct{Type: v.Type, Value: v.Value}}
paramList.Params = append(paramList.Params, param)
}
body := setParameterValuesStruct{
ParamList: paramList,
ParameterKey: msg.ParameterKey,
}
env.Body = setParameterValuesBodyStruct{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 *SetParameterValues) Parse(doc *xmlx.Document) {
// TODO
}