-
Notifications
You must be signed in to change notification settings - Fork 0
/
omaha.go
264 lines (229 loc) · 7.52 KB
/
omaha.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/*
Implements the Google omaha protocol.
Omaha is a request/response protocol using XML. Requests are made by
clients and responses are given by the Omaha server.
http://code.google.com/p/omaha/wiki/ServerProtocol
*/
package omaha
import (
"encoding/xml"
)
type Request struct {
XMLName xml.Name `xml:"request" datastore:"-"`
Os Os `xml:"os"`
Apps []*App `xml:"app"`
Protocol string `xml:"protocol,attr"`
Version string `xml:"version,attr,omitempty"`
IsMachine string `xml:"ismachine,attr,omitempty"`
SessionId string `xml:"sessionid,attr,omitempty"`
UserId string `xml:"userid,attr,omitempty"`
InstallSource string `xml:"installsource,attr,omitempty"`
TestSource string `xml:"testsource,attr,omitempty"`
RequestId string `xml:"requestid,attr,omitempty"`
UpdaterVersion string `xml:"updaterversion,attr,omitempty"`
}
func NewRequest(version string, platform string, sp string, arch string) *Request {
r := new(Request)
r.Protocol = "3.0"
r.Os = Os{Version: version, Platform: platform, Sp: sp, Arch: arch}
return r
}
func (r *Request) AddApp(id string, version string) *App {
a := NewApp(id)
a.Version = version
r.Apps = append(r.Apps, a)
return a
}
/* Response
*/
type Response struct {
XMLName xml.Name `xml:"response" datastore:"-" json:"-"`
DayStart DayStart `xml:"daystart"`
Apps []*App `xml:"app"`
Protocol string `xml:"protocol,attr"`
Server string `xml:"server,attr"`
}
func NewResponse(server string) *Response {
r := &Response{Server: server, Protocol: "3.0"}
r.DayStart.ElapsedSeconds = "0"
return r
}
type DayStart struct {
ElapsedSeconds string `xml:"elapsed_seconds,attr"`
}
func (r *Response) AddApp(id string) *App {
a := NewApp(id)
r.Apps = append(r.Apps, a)
return a
}
type App struct {
XMLName xml.Name `xml:"app" datastore"-" json:"-"`
Ping *Ping `xml:"ping"`
UpdateCheck *UpdateCheck `xml:"updatecheck"`
Events []*Event `xml:"event" json:",omitempty"`
Id string `xml:"appid,attr,omitempty"`
Version string `xml:"version,attr,omitempty"`
NextVersion string `xml:"nextversion,attr,omitempty"`
Lang string `xml:"lang,attr,omitempty"`
Client string `xml:"client,attr,omitempty"`
InstallAge string `xml:"installage,attr,omitempty"`
Status string `xml:"status,attr,omitempty"`
// update engine extensions
Track string `xml:"track,attr,omitempty"`
FromTrack string `xml:"from_track,attr,omitempty"`
// coreos update engine extensions
BootId string `xml:"bootid,attr,omitempty"`
MachineID string `xml:"machineid,attr,omitempty"`
OEM string `xml:"oem,attr,omitempty"`
}
func NewApp(id string) *App {
a := &App{Id: id}
return a
}
func (a *App) AddUpdateCheck() *UpdateCheck {
a.UpdateCheck = new(UpdateCheck)
return a.UpdateCheck
}
func (a *App) AddPing() *Ping {
a.Ping = new(Ping)
return a.Ping
}
func (a *App) AddEvent() *Event {
event := new(Event)
a.Events = append(a.Events, event)
return event
}
type UpdateCheck struct {
XMLName xml.Name `xml:"updatecheck" datastore:"-" json:"-"`
Urls *Urls `xml:"urls"`
Manifest *Manifest `xml:"manifest"`
TargetVersionPrefix string `xml:"targetversionprefix,attr,omitempty"`
Status string `xml:"status,attr,omitempty"`
}
func (u *UpdateCheck) AddUrl(codebase string) *Url {
if u.Urls == nil {
u.Urls = new(Urls)
}
url := new(Url)
url.CodeBase = codebase
u.Urls.Urls = append(u.Urls.Urls, *url)
return url
}
func (u *UpdateCheck) AddManifest(version string) *Manifest {
u.Manifest = &Manifest{Version: version}
return u.Manifest
}
type Ping struct {
XMLName xml.Name `xml:"ping" datastore:"-" json:"-"`
LastReportDays string `xml:"r,attr,omitempty"`
Status string `xml:"status,attr,omitempty"`
}
type Os struct {
XMLName xml.Name `xml:"os" datastore:"-" json:"-"`
Platform string `xml:"platform,attr,omitempty"`
Version string `xml:"version,attr,omitempty"`
Sp string `xml:"sp,attr,omitempty"`
Arch string `xml:"arch,attr,omitempty"`
}
func NewOs(platform string, version string, sp string, arch string) *Os {
o := &Os{Version: version, Platform: platform, Sp: sp, Arch: arch}
return o
}
type Event struct {
XMLName xml.Name `xml:"event" datastore:"-" json:"-"`
Type string `xml:"eventtype,attr,omitempty"`
Result string `xml:"eventresult,attr,omitempty"`
PreviousVersion string `xml:"previousversion,attr,omitempty"`
ErrorCode string `xml:"errorcode,attr,omitempty"`
}
type Urls struct {
XMLName xml.Name `xml:"urls" datastore:"-" json:"-"`
Urls []Url `xml:"url" json:",omitempty"`
}
type Url struct {
XMLName xml.Name `xml:"url" datastore:"-" json:"-"`
CodeBase string `xml:"codebase,attr"`
}
type Manifest struct {
XMLName xml.Name `xml:"manifest" datastore:"-" json:"-"`
Packages Packages `xml:"packages"`
Actions Actions `xml:"actions"`
Version string `xml:"version,attr"`
}
type Packages struct {
XMLName xml.Name `xml:"packages" datastore:"-" json:"-"`
Packages []Package `xml:"package" json:",omitempty"`
}
type Package struct {
XMLName xml.Name `xml:"package" datastore:"-" json:"-"`
Hash string `xml:"hash,attr"`
Name string `xml:"name,attr"`
Size string `xml:"size,attr"`
Required bool `xml:"required,attr"`
}
func (m *Manifest) AddPackage(hash string, name string, size string, required bool) *Package {
p := &Package{Hash: hash, Name: name, Size: size, Required: required}
m.Packages.Packages = append(m.Packages.Packages, *p)
return p
}
type Actions struct {
XMLName xml.Name `xml:"actions" datastore:"-" json:"-"`
Actions []*Action `xml:"action" json:",omitempty"`
}
type Action struct {
XMLName xml.Name `xml:"action" datastore:"-" json:"-"`
Event string `xml:"event,attr"`
// Extensions added by update_engine
ChromeOSVersion string `xml:"ChromeOSVersion,attr"`
Sha256 string `xml:"sha256,attr"`
NeedsAdmin bool `xml:"needsadmin,attr"`
IsDelta bool `xml:"IsDelta,attr"`
DisablePayloadBackoff bool `xml:"DisablePayloadBackoff,attr,omitempty"`
MetadataSignatureRsa string `xml:"MetadataSignatureRsa,attr,omitempty"`
MetadataSize string `xml:"MetadataSize,attr,omitempty"`
Deadline string `xml:"deadline,attr,omitempty"`
}
func (m *Manifest) AddAction(event string) *Action {
a := &Action{Event: event}
m.Actions.Actions = append(m.Actions.Actions, a)
return a
}
var EventTypes = map[int]string{
0: "unknown",
1: "download complete",
2: "install complete",
3: "update complete",
4: "uninstall",
5: "download started",
6: "install started",
9: "new application install started",
10: "setup started",
11: "setup finished",
12: "update application started",
13: "update download started",
14: "update download finished",
15: "update installer started",
16: "setup update begin",
17: "setup update complete",
20: "register product complete",
30: "OEM install first check",
40: "app-specific command started",
41: "app-specific command ended",
100: "setup failure",
102: "COM server failure",
103: "setup update failure",
800: "ping",
}
var EventResults = map[int]string{
0: "error",
1: "success",
2: "success reboot",
3: "success restart browser",
4: "cancelled",
5: "error installer MSI",
6: "error installer other",
7: "noupdate",
8: "error installer system",
9: "update deferred",
10: "handoff error",
}