-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsoap.go
91 lines (76 loc) · 2.54 KB
/
soap.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
79
80
81
82
83
84
85
86
87
88
89
90
91
package eyego
import (
"encoding/xml"
"bytes"
"io"
)
const (
soapStart = `<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="EyeFi/SOAP/EyeFilm"><SOAP-ENV:Body>`
soapEnd = `</SOAP-ENV:Body></SOAP-ENV:Envelope>`
)
type SoapStartSession struct {
MacAddress string `xml:"macaddress"`
CNonce string `xml:"cnonce"`
TransferMode string `xml:"transfermode"`
TransferModeTimestamp string `xml:"transfermodetimestamp"`
}
type SoapStartSessionResponse struct {
Credential string `xml:"credential"`
SNonce string `xml:"snonce"`
TransferMode string `xml:"transfermode"`
TransferModeTimestamp string `xml:"transfermodetimestamp"`
UpSyncAllowed string `xml:"upsyncallowed"`
XMLName xml.Name `xml:"ns1:StartSessionResponse"`
}
type GetPhotoStatus struct {
Credential string `xml:"credential"`
MacAddress string `xml:"macaddress"`
Filename string `xml:"filename"`
FileSize string `xml:"filesize"`
FileSignature string `xml:"filesignature"`
Flags string `xml:"flags"`
}
type GetPhotoStatusResponse struct {
FileID string `xml:"fileid"`
Offset string `xml:"offset"`
XMLName xml.Name `xml:"ns1:GetPhotoStatusResponse"`
}
type UploadPhoto struct {
FileID string `xml:"fileid"`
MacAddress string `xml:"macaddress"`
Filename string `xml:"filename"`
FileSize string `xml:"filesize"`
FileSignature string `xml:"filesignature"`
Encryption string `xml:"encryption"`
Flags string `xml:"flags"`
}
type UploadPhotoResponse struct {
Success string `xml:"success"`
XMLName xml.Name `xml:"ns1:UploadPhotoResponse"`
}
type MarkLastPhotoInRoll struct {
MacAddress string `xml:"macaddress"`
MergeDelta string `xml:"mergedelta"`
}
type MarkLastPhotoInRollResponse struct {
XMLName xml.Name `xml:"ns1:MarkLastPhotoInRollResponse"`
}
func ParseSoap(s string, target interface {}) {
if s[0:len(soapStart)] != soapStart || s[len(s) - len(soapEnd):len(s)] != soapEnd {
panic("Unknown soap request:\n" + s)
}
body := s[len(soapStart):len(s) - len(soapEnd)]
parser := xml.NewDecoder(bytes.NewBufferString(body))
parser.Decode(target)
}
func CreateSoap(body interface{}) string {
buffer := bytes.NewBuffer(make([]byte, 0))
WriteSoap(body, buffer)
return string(buffer.Bytes())
}
func WriteSoap(body interface{}, writer io.Writer) {
encoder := xml.NewEncoder(writer)
writer.Write([]byte(soapStart))
encoder.Encode(body)
writer.Write([]byte(soapEnd))
}