Initial commit

This commit is contained in:
Brandon Philips 2013-03-27 16:58:22 -07:00
commit d1b8d0aa1b
10 changed files with 265 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
pkg

3
README.md Normal file
View File

@ -0,0 +1,3 @@
Implementation of the omaha protocol in Go.
https://code.google.com/p/omaha/

View File

@ -0,0 +1 @@
AC07C722-45D6-4D0E-B1D4-2E1E297569A1

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<request protocol="3.0" version="1.3.23.0" ismachine="0" sessionid="{5FAD27D4-6BFA-4daa-A1B3-5A1F821FEE0F}" userid="{D0BBD725-742D-44ae-8D46-0231E881D58E}" installsource="scheduler" testsource="ossdev" requestid="{C8F6EDF3-B623-4ee6-B2DA-1D08A0B4C665}">
<os platform="win" version="6.1" sp="" arch="x64"/>
<app appid="{430FD4D0-B729-4F61-AA34-91526481799D}" version="1.3.23.0" nextversion="" lang="en" brand="GGLS" client="someclientid" installage="39">
<updatecheck/>
<ping r="1"/>
</app>
<app appid="{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}" version="2.2.2.0" nextversion="" lang="en" brand="GGLS" client="" installage="6">
<updatecheck/>
<ping r="1"/>
</app>
</request>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<request protocol="3.0" version="ChromeOSUpdateEngine-0.1.0.0" updaterversion="ChromeOSUpdateEngine-0.1.0.0" installsource="ondemandupdate" ismachine="1">
<os version="Indy" platform="Chrome OS" sp="ForcedUpdate_x86_64"></os>
<app appid="{87efface-864d-49a5-9bb3-4b050a7c227a}" version="ForcedUpdate" track="" from_track="developer-build" lang="en-US" board="amd64-generic" hardware_class="" delta_okay="false" >
<event eventtype="3" eventresult="1"></event>
</app>
</request>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<response" protocol="3.0">
<daystart elapsed_seconds="49051"/>
<app appid="{87efface-864d-49a5-9bb3-4b050a7c227a}" status="ok">
<ping status="ok"/>
<updatecheck status="noupdate"/>
</app>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<request protocol="3.0" version="ChromeOSUpdateEngine-0.1.0.0" updaterversion="ChromeOSUpdateEngine-0.1.0.0" installsource="ondemandupdate" ismachine="1">
<os version="Indy" platform="Chrome OS" sp="ForcedUpdate_x86_64"></os>
<app appid="{87efface-864d-49a5-9bb3-4b050a7c227a}" version="ForcedUpdate" track="" from_track="developer-build" lang="en-US" board="amd64-generic" hardware_class="" delta_okay="false" >
<ping active="1" a="-1" r="-1"></ping>
<updatecheck targetversionprefix=""></updatecheck>
<event eventtype="3" eventresult="2" previousversion=""></event>
</app>
</request>

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<response protocol="3.0">
<daystart elapsed_seconds="49008"/>
<app appid="{87efface-864d-49a5-9bb3-4b050a7c227a}" status="ok">
<ping status="ok"/>
<updatecheck status="ok">
<urls>
<url codebase="http://kam:8080/static/"/>
</urls>
<manifest version="9999.0.0">
<packages>
<package hash="+LXvjiaPkeYDLHoNKlf9qbJwvnk=" name="update.gz" size="67546213"
required="true"/>
</packages>
<actions>
<action event="postinstall"
ChromeOSVersion="9999.0.0"
sha256="0VAlQW3RE99SGtSB5R4m08antAHO8XDoBMKDyxQT/Mg="
needsadmin="false"
IsDelta="True"
/>
</actions>
</manifest>
</updatecheck>
</app>
</response>

138
src/omaha/omaha.go Normal file
View File

@ -0,0 +1,138 @@
/*
Package that 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
The
*/
package omaha
import "encoding/xml"
type Request struct {
Os 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(os *Os, app *App) *Request {
r := new(Request)
r.Protocol = "3.0"
r.AddApp(app)
r.Os = *os
return r
}
func (r *Request) AddApp(a *App) {
r.Apps = append(r.Apps, *a)
}
// app element
type App struct {
XMLName xml.Name `xml:"app"`
UpdateCheck *UpdateCheck `xml:"updatecheck"`
Ping *Ping
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"`
}
func NewApp(id string, version string) *App {
a := new(App)
a.Id = id
a.Version = version
return a
}
type UpdateCheck struct {
XMLName xml.Name `xml:"updatecheck"`
TargetVersionPrefix string `xml:"targetversionprefix,attr,omitempty"`
}
func (a *App) AddUpdateCheck() {
a.UpdateCheck = new(UpdateCheck)
}
type Ping struct {
XMLName xml.Name `xml:"ping"`
LastReportDays string `xml:"r,attr,omitempty"`
}
type Os struct {
XMLName xml.Name `xml:"os"`
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 := new(Os)
o.Platform = platform
o.Version = version
o.Sp = sp
o.Arch = arch
return o
}
func (a *App) AddPing() {
}
type Event struct {
XMLName xml.Name `xml:"event"`
EventType string `xml:"eventtype,attr,omitempty"`
EventResult string `xml:"eventresult,attr,omitempty"`
PreviousVersion string `xml:"previousversion,attr,omitempty"`
}
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",
}
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",
}

60
src/omaha/omaha_test.go Normal file
View File

@ -0,0 +1,60 @@
package omaha
import (
"testing"
"fmt"
"encoding/xml"
"io/ioutil"
"os"
)
func TestOmahaUpdateCheck(t *testing.T) {
file, err := os.Open("fixtures/update-engine/update/request.xml")
if err != nil {
t.Error(err)
}
fix, err := ioutil.ReadAll(file)
if err != nil {
t.Error(err)
}
v := Request{}
xml.Unmarshal(fix, &v)
if v.Os.Version != "Indy" {
t.Error("Unexpected version", v.Os.Version)
}
if v.Apps[0].Id != "{87efface-864d-49a5-9bb3-4b050a7c227a}" {
t.Error("Expected an App Id")
}
if v.Apps[0].UpdateCheck == nil {
t.Error("Expected an UpdateCheck")
}
}
func ExampleOmaha_NewRequest() {
os := NewOs("linux", "3.0", "", "x64")
app := NewApp("{27BD862E-8AE8-4886-A055-F7F1A6460627}", "1.0.0.0")
app.AddUpdateCheck()
request := NewRequest(os, app)
if raw, err := xml.MarshalIndent(request, "", " "); err != nil {
fmt.Println(err)
return
} else {
fmt.Printf("%s%s\n", xml.Header, raw)
}
// Output:
// <?xml version="1.0" encoding="UTF-8"?>
//
// <Request protocol="3.0">
// <os platform="linux" version="3.0" arch="x64"></os>
// <app appid="{27BD862E-8AE8-4886-A055-F7F1A6460627}" version="1.0.0.0">
// <updatecheck></updatecheck>
// </app>
// </Request>
}