diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 4572bd668e3..7b2042bf9f4 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -14,10 +14,6 @@ "Comment": "null-5", "Rev": "75cd24fc2f2c2a2088577d12123ddee5f54e0675" }, - { - "ImportPath": "github.com/StackExchange/wmi", - "Rev": "8730d7ed549382cb1f889a576a7223c137be7989" - }, { "ImportPath": "github.com/alecthomas/kingpin", "Comment": "v2.1.0-2-gaedd543", @@ -115,11 +111,6 @@ "ImportPath": "github.com/fd/go-nat", "Rev": "50e7633d5f27d81490026a13e5b92d2e42d8c6bb" }, - { - "ImportPath": "github.com/go-ole/go-ole", - "Comment": "v1.1.1-64-g4246eab", - "Rev": "4246eab2a27c71c143f965432ace52990308d362" - }, { "ImportPath": "github.com/gogo/protobuf/io", "Rev": "0ac967c269268f1af7d9bcc7927ccc9a589b2b36" @@ -144,10 +135,6 @@ "ImportPath": "github.com/huin/goupnp", "Rev": "223008361153d7d434c1f0ac990cd3fcae6931f5" }, - { - "ImportPath": "github.com/inconshreveable/go-update", - "Rev": "68f5725818189545231c1fd8694793d45f2fc529" - }, { "ImportPath": "github.com/jackpal/go-nat-pmp", "Rev": "a45aa3d54aef73b504e15eb71bea0e5565b5e6e1" @@ -234,14 +221,6 @@ "ImportPath": "github.com/jbenet/goprocess", "Rev": "64a8220330a485070813201cc05b0c6777f6a516" }, - { - "ImportPath": "github.com/kardianos/osext", - "Rev": "8fef92e41e22a70e700a96b29f066cda30ea24ef" - }, - { - "ImportPath": "github.com/kr/binarydist", - "Rev": "9955b0ab8708602d411341e55fffd7e0700f86bd" - }, { "ImportPath": "github.com/matttproud/golang_protobuf_extensions/pbutil", "Rev": "fc2b8d3a73c4867e51861bbdd5ae3c1f0869dd6a" @@ -294,21 +273,6 @@ "ImportPath": "github.com/satori/go.uuid", "Rev": "7c7f2020c4c9491594b85767967f4619c2fa75f9" }, - { - "ImportPath": "github.com/shirou/gopsutil/common", - "Comment": "1.0.0-167-g6a274c3", - "Rev": "6a274c3628382ab316340478300f5282b89f7778" - }, - { - "ImportPath": "github.com/shirou/gopsutil/disk", - "Comment": "1.0.0-167-g6a274c3", - "Rev": "6a274c3628382ab316340478300f5282b89f7778" - }, - { - "ImportPath": "github.com/shirou/gopsutil/mem", - "Comment": "1.0.0-167-g6a274c3", - "Rev": "6a274c3628382ab316340478300f5282b89f7778" - }, { "ImportPath": "github.com/steakknife/hamming", "Comment": "0.0.10", @@ -346,6 +310,10 @@ "ImportPath": "github.com/whyrusleeping/go-multistream", "Rev": "31bb014803a6eba2261bda5593e42c016a5f33bb" }, + { + "ImportPath": "github.com/whyrusleeping/go-sysinfo", + "Rev": "769b7c0b50e8030895abc74ba8107ac715e3162a" + }, { "ImportPath": "github.com/whyrusleeping/multiaddr-filter", "Rev": "9e26222151125ecd3fc1fd190179b6bdd55f5608" diff --git a/Godeps/_workspace/src/github.com/StackExchange/wmi/LICENSE b/Godeps/_workspace/src/github.com/StackExchange/wmi/LICENSE deleted file mode 100644 index ae80b67209e..00000000000 --- a/Godeps/_workspace/src/github.com/StackExchange/wmi/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2013 Stack Exchange - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/Godeps/_workspace/src/github.com/StackExchange/wmi/README.md b/Godeps/_workspace/src/github.com/StackExchange/wmi/README.md deleted file mode 100644 index 3d5f67e149b..00000000000 --- a/Godeps/_workspace/src/github.com/StackExchange/wmi/README.md +++ /dev/null @@ -1,4 +0,0 @@ -wmi -=== - -Package wmi provides a WQL interface for WMI on Windows. diff --git a/Godeps/_workspace/src/github.com/StackExchange/wmi/wmi.go b/Godeps/_workspace/src/github.com/StackExchange/wmi/wmi.go deleted file mode 100644 index 1eddff91382..00000000000 --- a/Godeps/_workspace/src/github.com/StackExchange/wmi/wmi.go +++ /dev/null @@ -1,416 +0,0 @@ -// +build windows - -/* -Package wmi provides a WQL interface for WMI on Windows. - -Example code to print names of running processes: - - type Win32_Process struct { - Name string - } - - func main() { - var dst []Win32_Process - q := wmi.CreateQuery(&dst, "") - err := wmi.Query(q, &dst) - if err != nil { - log.Fatal(err) - } - for i, v := range dst { - println(i, v.Name) - } - } - -*/ -package wmi - -import ( - "bytes" - "errors" - "fmt" - "log" - "os" - "reflect" - "runtime" - "strconv" - "strings" - "sync" - "time" - - "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole" - "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil" -) - -var l = log.New(os.Stdout, "", log.LstdFlags) - -var ( - ErrInvalidEntityType = errors.New("wmi: invalid entity type") - lock sync.Mutex -) - -// QueryNamespace invokes Query with the given namespace on the local machine. -func QueryNamespace(query string, dst interface{}, namespace string) error { - return Query(query, dst, nil, namespace) -} - -// Query runs the WQL query and appends the values to dst. -// -// dst must have type *[]S or *[]*S, for some struct type S. Fields selected in -// the query must have the same name in dst. Supported types are all signed and -// unsigned integers, time.Time, string, bool, or a pointer to one of those. -// Array types are not supported. -// -// By default, the local machine and default namespace are used. These can be -// changed using connectServerArgs. See -// http://msdn.microsoft.com/en-us/library/aa393720.aspx for details. -// -// Query is a wrapper around DefaultClient.Query. -func Query(query string, dst interface{}, connectServerArgs ...interface{}) error { - return DefaultClient.Query(query, dst, connectServerArgs...) -} - -// A Client is an WMI query client. -// -// Its zero value (DefaultClient) is a usable client. -type Client struct { - // NonePtrZero specifies if nil values for fields which aren't pointers - // should be returned as the field types zero value. - // - // Setting this to true allows stucts without pointer fields to be used - // without the risk failure should a nil value returned from WMI. - NonePtrZero bool - - // PtrNil specifies if nil values for pointer fields should be returned - // as nil. - // - // Setting this to true will set pointer fields to nil where WMI - // returned nil, otherwise the types zero value will be returned. - PtrNil bool - - // AllowMissingFields specifies that struct fields not present in the - // query result should not result in an error. - // - // Setting this to true allows custom queries to be used with full - // struct definitions instead of having to define multiple structs. - AllowMissingFields bool -} - -// DefaultClient is the default Client and is used by Query, QueryNamespace -var DefaultClient = &Client{} - -// Query runs the WQL query and appends the values to dst. -// -// dst must have type *[]S or *[]*S, for some struct type S. Fields selected in -// the query must have the same name in dst. Supported types are all signed and -// unsigned integers, time.Time, string, bool, or a pointer to one of those. -// Array types are not supported. -// -// By default, the local machine and default namespace are used. These can be -// changed using connectServerArgs. See -// http://msdn.microsoft.com/en-us/library/aa393720.aspx for details. -func (c *Client) Query(query string, dst interface{}, connectServerArgs ...interface{}) error { - dv := reflect.ValueOf(dst) - if dv.Kind() != reflect.Ptr || dv.IsNil() { - return ErrInvalidEntityType - } - dv = dv.Elem() - mat, elemType := checkMultiArg(dv) - if mat == multiArgTypeInvalid { - return ErrInvalidEntityType - } - - lock.Lock() - defer lock.Unlock() - runtime.LockOSThread() - defer runtime.UnlockOSThread() - - err := ole.CoInitializeEx(0, ole.COINIT_MULTITHREADED) - if err != nil { - oleerr := err.(*ole.OleError) - // S_FALSE = 0x00000001 // CoInitializeEx was already called on this thread - if oleerr.Code() != ole.S_OK && oleerr.Code() != 0x00000001 { - return err - } - } else { - // Only invoke CoUninitialize if the thread was not initizlied before. - // This will allow other go packages based on go-ole play along - // with this library. - defer ole.CoUninitialize() - } - - unknown, err := oleutil.CreateObject("WbemScripting.SWbemLocator") - if err != nil { - return err - } - defer unknown.Release() - - wmi, err := unknown.QueryInterface(ole.IID_IDispatch) - if err != nil { - return err - } - defer wmi.Release() - - // service is a SWbemServices - serviceRaw, err := oleutil.CallMethod(wmi, "ConnectServer", connectServerArgs...) - if err != nil { - return err - } - service := serviceRaw.ToIDispatch() - defer serviceRaw.Clear() - - // result is a SWBemObjectSet - resultRaw, err := oleutil.CallMethod(service, "ExecQuery", query) - if err != nil { - return err - } - result := resultRaw.ToIDispatch() - defer resultRaw.Clear() - - count, err := oleInt64(result, "Count") - if err != nil { - return err - } - - // Initialize a slice with Count capacity - dv.Set(reflect.MakeSlice(dv.Type(), 0, int(count))) - - var errFieldMismatch error - for i := int64(0); i < count; i++ { - err := func() error { - // item is a SWbemObject, but really a Win32_Process - itemRaw, err := oleutil.CallMethod(result, "ItemIndex", i) - if err != nil { - return err - } - item := itemRaw.ToIDispatch() - defer itemRaw.Clear() - - ev := reflect.New(elemType) - if err = c.loadEntity(ev.Interface(), item); err != nil { - if _, ok := err.(*ErrFieldMismatch); ok { - // We continue loading entities even in the face of field mismatch errors. - // If we encounter any other error, that other error is returned. Otherwise, - // an ErrFieldMismatch is returned. - errFieldMismatch = err - } else { - return err - } - } - if mat != multiArgTypeStructPtr { - ev = ev.Elem() - } - dv.Set(reflect.Append(dv, ev)) - return nil - }() - if err != nil { - return err - } - } - return errFieldMismatch -} - -// ErrFieldMismatch is returned when a field is to be loaded into a different -// type than the one it was stored from, or when a field is missing or -// unexported in the destination struct. -// StructType is the type of the struct pointed to by the destination argument. -type ErrFieldMismatch struct { - StructType reflect.Type - FieldName string - Reason string -} - -func (e *ErrFieldMismatch) Error() string { - return fmt.Sprintf("wmi: cannot load field %q into a %q: %s", - e.FieldName, e.StructType, e.Reason) -} - -var timeType = reflect.TypeOf(time.Time{}) - -// loadEntity loads a SWbemObject into a struct pointer. -func (c *Client) loadEntity(dst interface{}, src *ole.IDispatch) (errFieldMismatch error) { - v := reflect.ValueOf(dst).Elem() - for i := 0; i < v.NumField(); i++ { - f := v.Field(i) - of := f - isPtr := f.Kind() == reflect.Ptr - if isPtr { - ptr := reflect.New(f.Type().Elem()) - f.Set(ptr) - f = f.Elem() - } - n := v.Type().Field(i).Name - if !f.CanSet() { - return &ErrFieldMismatch{ - StructType: of.Type(), - FieldName: n, - Reason: "CanSet() is false", - } - } - prop, err := oleutil.GetProperty(src, n) - if err != nil { - if !c.AllowMissingFields { - errFieldMismatch = &ErrFieldMismatch{ - StructType: of.Type(), - FieldName: n, - Reason: "no such struct field", - } - } - continue - } - defer prop.Clear() - - switch val := prop.Value().(type) { - case int8, int16, int32, int64, int: - v := reflect.ValueOf(val).Int() - switch f.Kind() { - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - f.SetInt(v) - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: - f.SetUint(uint64(v)) - default: - return &ErrFieldMismatch{ - StructType: of.Type(), - FieldName: n, - Reason: "not an integer class", - } - } - case uint8, uint16, uint32, uint64: - v := reflect.ValueOf(val).Uint() - switch f.Kind() { - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - f.SetInt(int64(v)) - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: - f.SetUint(v) - default: - return &ErrFieldMismatch{ - StructType: of.Type(), - FieldName: n, - Reason: "not an integer class", - } - } - case string: - switch f.Kind() { - case reflect.String: - f.SetString(val) - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - iv, err := strconv.ParseInt(val, 10, 64) - if err != nil { - return err - } - f.SetInt(iv) - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: - uv, err := strconv.ParseUint(val, 10, 64) - if err != nil { - return err - } - f.SetUint(uv) - case reflect.Struct: - switch f.Type() { - case timeType: - if len(val) == 25 { - mins, err := strconv.Atoi(val[22:]) - if err != nil { - return err - } - val = val[:22] + fmt.Sprintf("%02d%02d", mins/60, mins%60) - } - t, err := time.Parse("20060102150405.000000-0700", val) - if err != nil { - return err - } - f.Set(reflect.ValueOf(t)) - } - } - case bool: - switch f.Kind() { - case reflect.Bool: - f.SetBool(val) - default: - return &ErrFieldMismatch{ - StructType: of.Type(), - FieldName: n, - Reason: "not a bool", - } - } - default: - typeof := reflect.TypeOf(val) - if typeof == nil && (isPtr || c.NonePtrZero) { - if (isPtr && c.PtrNil) || (!isPtr && c.NonePtrZero) { - of.Set(reflect.Zero(of.Type())) - } - break - } - return &ErrFieldMismatch{ - StructType: of.Type(), - FieldName: n, - Reason: fmt.Sprintf("unsupported type (%T)", val), - } - } - } - return errFieldMismatch -} - -type multiArgType int - -const ( - multiArgTypeInvalid multiArgType = iota - multiArgTypeStruct - multiArgTypeStructPtr -) - -// checkMultiArg checks that v has type []S, []*S for some struct type S. -// -// It returns what category the slice's elements are, and the reflect.Type -// that represents S. -func checkMultiArg(v reflect.Value) (m multiArgType, elemType reflect.Type) { - if v.Kind() != reflect.Slice { - return multiArgTypeInvalid, nil - } - elemType = v.Type().Elem() - switch elemType.Kind() { - case reflect.Struct: - return multiArgTypeStruct, elemType - case reflect.Ptr: - elemType = elemType.Elem() - if elemType.Kind() == reflect.Struct { - return multiArgTypeStructPtr, elemType - } - } - return multiArgTypeInvalid, nil -} - -func oleInt64(item *ole.IDispatch, prop string) (int64, error) { - v, err := oleutil.GetProperty(item, prop) - if err != nil { - return 0, err - } - defer v.Clear() - - i := int64(v.Val) - return i, nil -} - -// CreateQuery returns a WQL query string that queries all columns of src. where -// is an optional string that is appended to the query, to be used with WHERE -// clauses. In such a case, the "WHERE" string should appear at the beginning. -func CreateQuery(src interface{}, where string) string { - var b bytes.Buffer - b.WriteString("SELECT ") - s := reflect.Indirect(reflect.ValueOf(src)) - t := s.Type() - if s.Kind() == reflect.Slice { - t = t.Elem() - } - if t.Kind() != reflect.Struct { - return "" - } - var fields []string - for i := 0; i < t.NumField(); i++ { - fields = append(fields, t.Field(i).Name) - } - b.WriteString(strings.Join(fields, ", ")) - b.WriteString(" FROM ") - b.WriteString(t.Name()) - b.WriteString(" " + where) - return b.String() -} diff --git a/Godeps/_workspace/src/github.com/StackExchange/wmi/wmi_test.go b/Godeps/_workspace/src/github.com/StackExchange/wmi/wmi_test.go deleted file mode 100644 index aea63dfeca3..00000000000 --- a/Godeps/_workspace/src/github.com/StackExchange/wmi/wmi_test.go +++ /dev/null @@ -1,316 +0,0 @@ -// +build windows - -package wmi - -import ( - "encoding/json" - "fmt" - "reflect" - "runtime" - "runtime/debug" - "sync" - "testing" - "time" -) - -func TestQuery(t *testing.T) { - var dst []Win32_Process - q := CreateQuery(&dst, "") - err := Query(q, &dst) - if err != nil { - t.Fatal(err) - } -} - -func TestFieldMismatch(t *testing.T) { - type s struct { - Name string - HandleCount uint32 - Blah uint32 - } - var dst []s - err := Query("SELECT Name, HandleCount FROM Win32_Process", &dst) - if err == nil || err.Error() != `wmi: cannot load field "Blah" into a "uint32": no such struct field` { - t.Error("Expected err field mismatch") - } -} - -func TestStrings(t *testing.T) { - printed := false - f := func() { - var dst []Win32_Process - zeros := 0 - q := CreateQuery(&dst, "") - for i := 0; i < 5; i++ { - err := Query(q, &dst) - if err != nil { - t.Fatal(err, q) - } - for _, d := range dst { - v := reflect.ValueOf(d) - for j := 0; j < v.NumField(); j++ { - f := v.Field(j) - if f.Kind() != reflect.String { - continue - } - s := f.Interface().(string) - if len(s) > 0 && s[0] == '\u0000' { - zeros++ - if !printed { - printed = true - j, _ := json.MarshalIndent(&d, "", " ") - t.Log("Example with \\u0000:\n", string(j)) - } - } - } - } - fmt.Println("iter", i, "zeros:", zeros) - } - if zeros > 0 { - t.Error("> 0 zeros") - } - } - - fmt.Println("Disabling GC") - debug.SetGCPercent(-1) - f() - fmt.Println("Enabling GC") - debug.SetGCPercent(100) - f() -} - -func TestNamespace(t *testing.T) { - var dst []Win32_Process - q := CreateQuery(&dst, "") - err := QueryNamespace(q, &dst, `root\CIMV2`) - if err != nil { - t.Fatal(err) - } - dst = nil - err = QueryNamespace(q, &dst, `broken\nothing`) - if err == nil { - t.Fatal("expected error") - } -} - -func TestCreateQuery(t *testing.T) { - type TestStruct struct { - Name string - Count int - } - var dst []TestStruct - output := "SELECT Name, Count FROM TestStruct WHERE Count > 2" - tests := []interface{}{ - &dst, - dst, - TestStruct{}, - &TestStruct{}, - } - for i, test := range tests { - if o := CreateQuery(test, "WHERE Count > 2"); o != output { - t.Error("bad output on", i, o) - } - } - if CreateQuery(3, "") != "" { - t.Error("expected empty string") - } -} - -func _TestMany(t *testing.T) { - limit := 5000 - fmt.Println("running until:", limit) - fmt.Println("No panics mean it succeeded. Other errors are OK.") - runtime.GOMAXPROCS(2) - wg := sync.WaitGroup{} - wg.Add(2) - go func() { - for i := 0; i < limit; i++ { - if i%25 == 0 { - fmt.Println(i) - } - var dst []Win32_PerfRawData_PerfDisk_LogicalDisk - q := CreateQuery(&dst, "") - err := Query(q, &dst) - if err != nil { - fmt.Println("ERROR disk", err) - } - } - wg.Done() - }() - go func() { - for i := 0; i > -limit; i-- { - if i%25 == 0 { - fmt.Println(i) - } - var dst []Win32_OperatingSystem - q := CreateQuery(&dst, "") - err := Query(q, &dst) - if err != nil { - fmt.Println("ERROR OS", err) - } - } - wg.Done() - }() - wg.Wait() -} - -type Win32_Process struct { - CSCreationClassName string - CSName string - Caption *string - CommandLine *string - CreationClassName string - CreationDate *time.Time - Description *string - ExecutablePath *string - ExecutionState *uint16 - Handle string - HandleCount uint32 - InstallDate *time.Time - KernelModeTime uint64 - MaximumWorkingSetSize *uint32 - MinimumWorkingSetSize *uint32 - Name string - OSCreationClassName string - OSName string - OtherOperationCount uint64 - OtherTransferCount uint64 - PageFaults uint32 - PageFileUsage uint32 - ParentProcessId uint32 - PeakPageFileUsage uint32 - PeakVirtualSize uint64 - PeakWorkingSetSize uint32 - Priority uint32 - PrivatePageCount uint64 - ProcessId uint32 - QuotaNonPagedPoolUsage uint32 - QuotaPagedPoolUsage uint32 - QuotaPeakNonPagedPoolUsage uint32 - QuotaPeakPagedPoolUsage uint32 - ReadOperationCount uint64 - ReadTransferCount uint64 - SessionId uint32 - Status *string - TerminationDate *time.Time - ThreadCount uint32 - UserModeTime uint64 - VirtualSize uint64 - WindowsVersion string - WorkingSetSize uint64 - WriteOperationCount uint64 - WriteTransferCount uint64 -} - -type Win32_PerfRawData_PerfDisk_LogicalDisk struct { - AvgDiskBytesPerRead uint64 - AvgDiskBytesPerRead_Base uint32 - AvgDiskBytesPerTransfer uint64 - AvgDiskBytesPerTransfer_Base uint32 - AvgDiskBytesPerWrite uint64 - AvgDiskBytesPerWrite_Base uint32 - AvgDiskQueueLength uint64 - AvgDiskReadQueueLength uint64 - AvgDiskSecPerRead uint32 - AvgDiskSecPerRead_Base uint32 - AvgDiskSecPerTransfer uint32 - AvgDiskSecPerTransfer_Base uint32 - AvgDiskSecPerWrite uint32 - AvgDiskSecPerWrite_Base uint32 - AvgDiskWriteQueueLength uint64 - Caption *string - CurrentDiskQueueLength uint32 - Description *string - DiskBytesPerSec uint64 - DiskReadBytesPerSec uint64 - DiskReadsPerSec uint32 - DiskTransfersPerSec uint32 - DiskWriteBytesPerSec uint64 - DiskWritesPerSec uint32 - FreeMegabytes uint32 - Frequency_Object uint64 - Frequency_PerfTime uint64 - Frequency_Sys100NS uint64 - Name string - PercentDiskReadTime uint64 - PercentDiskReadTime_Base uint64 - PercentDiskTime uint64 - PercentDiskTime_Base uint64 - PercentDiskWriteTime uint64 - PercentDiskWriteTime_Base uint64 - PercentFreeSpace uint32 - PercentFreeSpace_Base uint32 - PercentIdleTime uint64 - PercentIdleTime_Base uint64 - SplitIOPerSec uint32 - Timestamp_Object uint64 - Timestamp_PerfTime uint64 - Timestamp_Sys100NS uint64 -} - -type Win32_OperatingSystem struct { - BootDevice string - BuildNumber string - BuildType string - Caption *string - CodeSet string - CountryCode string - CreationClassName string - CSCreationClassName string - CSDVersion *string - CSName string - CurrentTimeZone int16 - DataExecutionPrevention_Available bool - DataExecutionPrevention_32BitApplications bool - DataExecutionPrevention_Drivers bool - DataExecutionPrevention_SupportPolicy *uint8 - Debug bool - Description *string - Distributed bool - EncryptionLevel uint32 - ForegroundApplicationBoost *uint8 - FreePhysicalMemory uint64 - FreeSpaceInPagingFiles uint64 - FreeVirtualMemory uint64 - InstallDate time.Time - LargeSystemCache *uint32 - LastBootUpTime time.Time - LocalDateTime time.Time - Locale string - Manufacturer string - MaxNumberOfProcesses uint32 - MaxProcessMemorySize uint64 - MUILanguages *[]string - Name string - NumberOfLicensedUsers *uint32 - NumberOfProcesses uint32 - NumberOfUsers uint32 - OperatingSystemSKU uint32 - Organization string - OSArchitecture string - OSLanguage uint32 - OSProductSuite uint32 - OSType uint16 - OtherTypeDescription *string - PAEEnabled *bool - PlusProductID *string - PlusVersionNumber *string - PortableOperatingSystem bool - Primary bool - ProductType uint32 - RegisteredUser string - SerialNumber string - ServicePackMajorVersion uint16 - ServicePackMinorVersion uint16 - SizeStoredInPagingFiles uint64 - Status string - SuiteMask uint32 - SystemDevice string - SystemDirectory string - SystemDrive string - TotalSwapSpaceSize *uint64 - TotalVirtualMemorySize uint64 - TotalVisibleMemorySize uint64 - Version string - WindowsDirectory string -} diff --git a/Godeps/_workspace/src/github.com/StackExchange/wmi/wmi_unix.go b/Godeps/_workspace/src/github.com/StackExchange/wmi/wmi_unix.go deleted file mode 100644 index 91d7b2addca..00000000000 --- a/Godeps/_workspace/src/github.com/StackExchange/wmi/wmi_unix.go +++ /dev/null @@ -1 +0,0 @@ -package wmi diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/.travis.yml b/Godeps/_workspace/src/github.com/go-ole/go-ole/.travis.yml deleted file mode 100644 index 0c2c02bdf2e..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/.travis.yml +++ /dev/null @@ -1,9 +0,0 @@ -language: go -sudo: false - -go: - - 1.1 - - 1.2 - - 1.3 - - 1.4 - - tip diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/ChangeLog.md b/Godeps/_workspace/src/github.com/go-ole/go-ole/ChangeLog.md deleted file mode 100644 index a67438f6a26..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/ChangeLog.md +++ /dev/null @@ -1,48 +0,0 @@ -# Version 1.x.x - -* **Add more test cases and reference new test COM server project.** (Placeholder for future additions) - -# Version 1.2.0-alphaX - -**Minimum supported version is now Go 1.4. Go 1.1 support is deprecated, but should still build.** - - * Added CI configuration for Travis-CI and AppVeyor. - * Added test InterfaceID and ClassID for the COM Test Server project. - * Added more inline documentation (#83). - * Added IEnumVARIANT implementation (#88). - * Added support for retrieving `time.Time` from VARIANT (#92). - * Added test case for IUnknown (#64). - * Added test case for IDispatch (#64). - * Added test cases for scalar variants (#64, #76). - -# Version 1.1.1 - - * Fixes for Linux build. - * Fixes for Windows build. - -# Version 1.1.0 - -The change to provide building on all platforms is a new feature. The increase in minor version reflects that and allows those who wish to stay on 1.0.x to continue to do so. Support for 1.0.x will be limited to bug fixes. - - * Move GUID out of variables.go into its own file to make new documentation available. - * Move OleError out of ole.go into its own file to make new documentation available. - * Add documentation to utility functions. - * Add documentation to variant receiver functions. - * Add documentation to ole structures. - * Make variant available to other systems outside of Windows. - * Make OLE structures available to other systems outside of Windows. - -## New Features - - * Library should now be built on all platforms supported by Go. Library will NOOP on any platform that is not Windows. - * More functions are now documented and available on godoc.org. - -# Version 1.0.1 - - 1. Fix package references from repository location change. - -# Version 1.0.0 - -This version is stable enough for use. The COM API is still incomplete, but provides enough functionality for accessing COM servers using IDispatch interface. - -There is no changelog for this version. Check commits for history. diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/README.md b/Godeps/_workspace/src/github.com/go-ole/go-ole/README.md deleted file mode 100644 index 42d2ddc163c..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/README.md +++ /dev/null @@ -1,46 +0,0 @@ -#Go OLE - -[![Build status](https://ci.appveyor.com/api/projects/status/qr0u2sf7q43us9fj?svg=true)](https://ci.appveyor.com/project/jacobsantos/go-ole-jgs28) -[![Build Status](https://travis-ci.org/go-ole/go-ole.svg?branch=master)](https://travis-ci.org/go-ole/go-ole) -[![GoDoc](https://godoc.org/github.com/go-ole/go-ole?status.svg)](https://godoc.org/github.com/go-ole/go-ole) - -Go bindings for Windows COM using shared libraries instead of cgo. - -By Yasuhiro Matsumoto. - -## Install - -To experiment with go-ole, you can just compile and run the example program: - -``` -go get github.com/go-ole/go-ole -cd /path/to/go-ole/ -go test - -cd /path/to/go-ole/example/excel -go run excel.go -``` - -## Continuous Integration - -Continuous integration configuration has been added for both Travis-CI and AppVeyor. You will have to add these to your own account for your fork in order for it to run. - -**Travis-CI** - -Travis-CI was added to check builds on Linux to ensure that `go get` works when cross building. Currently, Travis-CI is not used to test cross-building, but this may be changed in the future. It is also not currently possible to test the library on Linux, since COM API is specific to Windows and it is not currently possible to run a COM server on Linux or even connect to a remote COM server. - -**AppVeyor** - -AppVeyor is used to build on Windows using the (in-development) test COM server. It is currently only used to test the build and ensure that the code works on Windows. It will be used to register a COM server and then run the test cases based on the test COM server. - -The tests currently do run and do pass and this should be maintained with commits. - -##Versioning - -Go OLE uses [semantic versioning](http://semver.org) for version numbers, which is similar to the version contract of the Go language. Which means that the major version will always maintain backwards compatibility with minor versions. Minor versions will only add new additions and changes. Fixes will always be in patch. - -This contract should allow you to upgrade to new minor and patch versions without breakage or modifications to your existing code. Leave a ticket, if there is breakage, so that it could be fixed. - -##LICENSE - -Under the MIT License: http://mattn.mit-license.org/2013 diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/appveyor.yml b/Godeps/_workspace/src/github.com/go-ole/go-ole/appveyor.yml deleted file mode 100644 index cec0b247270..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/appveyor.yml +++ /dev/null @@ -1,74 +0,0 @@ -# Notes: -# - Minimal appveyor.yml file is an empty file. All sections are optional. -# - Indent each level of configuration with 2 spaces. Do not use tabs! -# - All section names are case-sensitive. -# - Section names should be unique on each level. - -version: "1.2.0.{build}-alpha-{branch}" - -os: Windows Server 2012 R2 - -branches: - only: - - master - - v1.1 - - v1.0 - -skip_tags: true - -clone_folder: c:\gopath\src\github.com\go-ole\go-ole - -environment: - GOPATH: c:\gopath - matrix: - - GOARCH: amd64 - GOVERSION: 1.4 - GOROOT: c:\go - DOWNLOADPLATFORM: "x64" - - GOARCH: 386 - GOVERSION: 1.4 - GOROOT: c:\go - DOWNLOADPLATFORM: "x86" - -matrix: - fast_finish: true - allow_failures: - - GOARCH: 386 - GOVERSION: 1.4 - GOROOT: c:\go - DOWNLOADPLATFORM: "x86" - -install: - - choco install mingw - - SET PATH=c:\tools\mingw64\bin;%PATH% - # - Download COM Server - - ps: Start-FileDownload "https://github.com/go-ole/test-com-server/releases/download/v1.0.0/test-com-server-${env:DOWNLOADPLATFORM}.zip" - - 7z e test-com-server-%DOWNLOADPLATFORM%.zip -oc:\gopath\src\github.com\go-ole\go-ole > NUL - - c:\gopath\src\github.com\go-ole\go-ole\build\register-assembly.bat - # - set - - go version - - go env - - c:\gopath\src\github.com\go-ole\go-ole\build\compile-go.bat - - go tool dist install -v cmd/8a - - go tool dist install -v cmd/8c - - go tool dist install -v cmd/8g - - go tool dist install -v cmd/8l - - go tool dist install -v cmd/6a - - go tool dist install -v cmd/6c - - go tool dist install -v cmd/6g - - go tool dist install -v cmd/6l - - go get -u golang.org/x/tools/cmd/cover - - go get -u golang.org/x/tools/cmd/godoc - - go get -u golang.org/x/tools/cmd/stringer - -build_script: - - cd c:\gopath\src\github.com\go-ole\go-ole - - go get -v -t ./... - - go build - - go test -v -cover ./... - -# disable automatic tests -test: off - -# disable deployment -deploy: off diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/build/compile-go.bat b/Godeps/_workspace/src/github.com/go-ole/go-ole/build/compile-go.bat deleted file mode 100644 index 61eed9496a8..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/build/compile-go.bat +++ /dev/null @@ -1,5 +0,0 @@ -@echo OFF - -echo "BUILD GOLANG" -cd "%GOROOT%\src" -./make.bat --dist-tool diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/build/register-assembly.bat b/Godeps/_workspace/src/github.com/go-ole/go-ole/build/register-assembly.bat deleted file mode 100644 index e2ca87fe522..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/build/register-assembly.bat +++ /dev/null @@ -1,8 +0,0 @@ -@ECHO OFF - -IF "x86" == "%DOWNLOADPLATFORM%" ( - CALL c:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe /codebase /nologo c:\gopath\src\github.com\go-ole\go-ole\TestCOMServer.dll -) -IF "x64" == "%DOWNLOADPLATFORM%" ( - CALL c:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe /codebase /nologo c:\gopath\src\github.com\go-ole\go-ole\TestCOMServer.dll -) diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/com.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/com.go deleted file mode 100644 index 06696087e48..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/com.go +++ /dev/null @@ -1,328 +0,0 @@ -// +build windows - -package ole - -import ( - "errors" - "syscall" - "time" - "unicode/utf16" - "unsafe" -) - -var ( - procCoInitialize, _ = modole32.FindProc("CoInitialize") - procCoInitializeEx, _ = modole32.FindProc("CoInitializeEx") - procCoUninitialize, _ = modole32.FindProc("CoUninitialize") - procCoCreateInstance, _ = modole32.FindProc("CoCreateInstance") - procCoTaskMemFree, _ = modole32.FindProc("CoTaskMemFree") - procCLSIDFromProgID, _ = modole32.FindProc("CLSIDFromProgID") - procCLSIDFromString, _ = modole32.FindProc("CLSIDFromString") - procStringFromCLSID, _ = modole32.FindProc("StringFromCLSID") - procStringFromIID, _ = modole32.FindProc("StringFromIID") - procIIDFromString, _ = modole32.FindProc("IIDFromString") - procGetUserDefaultLCID, _ = modkernel32.FindProc("GetUserDefaultLCID") - procCopyMemory, _ = modkernel32.FindProc("RtlMoveMemory") - procVariantInit, _ = modoleaut32.FindProc("VariantInit") - procVariantClear, _ = modoleaut32.FindProc("VariantClear") - procVariantTimeToSystemTime, _ = modoleaut32.FindProc("VariantTimeToSystemTime") - procSysAllocString, _ = modoleaut32.FindProc("SysAllocString") - procSysAllocStringLen, _ = modoleaut32.FindProc("SysAllocStringLen") - procSysFreeString, _ = modoleaut32.FindProc("SysFreeString") - procSysStringLen, _ = modoleaut32.FindProc("SysStringLen") - procCreateDispTypeInfo, _ = modoleaut32.FindProc("CreateDispTypeInfo") - procCreateStdDispatch, _ = modoleaut32.FindProc("CreateStdDispatch") - procGetActiveObject, _ = modoleaut32.FindProc("GetActiveObject") - - procGetMessageW, _ = moduser32.FindProc("GetMessageW") - procDispatchMessageW, _ = moduser32.FindProc("DispatchMessageW") -) - -// coInitialize initializes COM library on current thread. -// -// MSDN documentation suggests that this function should not be called. Call -// CoInitializeEx() instead. The reason has to do with threading and this -// function is only for single-threaded apartments. -// -// That said, most users of the library have gotten away with just this -// function. If you are experiencing threading issues, then use -// CoInitializeEx(). -func coInitialize() (err error) { - // http://msdn.microsoft.com/en-us/library/windows/desktop/ms678543(v=vs.85).aspx - // Suggests that no value should be passed to CoInitialized. - // Could just be Call() since the parameter is optional. <-- Needs testing to be sure. - hr, _, _ := procCoInitialize.Call(uintptr(0)) - if hr != 0 { - err = NewError(hr) - } - return -} - -// coInitializeEx initializes COM library with concurrency model. -func coInitializeEx(coinit uint32) (err error) { - // http://msdn.microsoft.com/en-us/library/windows/desktop/ms695279(v=vs.85).aspx - // Suggests that the first parameter is not only optional but should always be NULL. - hr, _, _ := procCoInitializeEx.Call(uintptr(0), uintptr(coinit)) - if hr != 0 { - err = NewError(hr) - } - return -} - -// CoInitialize initializes COM library on current thread. -// -// MSDN documentation suggests that this function should not be called. Call -// CoInitializeEx() instead. The reason has to do with threading and this -// function is only for single-threaded apartments. -// -// That said, most users of the library have gotten away with just this -// function. If you are experiencing threading issues, then use -// CoInitializeEx(). -func CoInitialize(p uintptr) (err error) { - // p is ignored and won't be used. - // Avoid any variable not used errors. - p = uintptr(0) - return coInitialize() -} - -// CoInitializeEx initializes COM library with concurrency model. -func CoInitializeEx(p uintptr, coinit uint32) (err error) { - // Avoid any variable not used errors. - p = uintptr(0) - return coInitializeEx(coinit) -} - -// CoUninitialize uninitializes COM Library. -func CoUninitialize() { - procCoUninitialize.Call() -} - -// CoTaskMemFree frees memory pointer. -func CoTaskMemFree(memptr uintptr) { - procCoTaskMemFree.Call(memptr) -} - -// CLSIDFromProgID retrieves Class Identifier with the given Program Identifier. -// -// The Programmatic Identifier must be registered, because it will be looked up -// in the Windows Registry. The registry entry has the following keys: CLSID, -// Insertable, Protocol and Shell -// (https://msdn.microsoft.com/en-us/library/dd542719(v=vs.85).aspx). -// -// programID identifies the class id with less precision and is not guaranteed -// to be unique. These are usually found in the registry under -// HKEY_LOCAL_MACHINE\SOFTWARE\Classes, usually with the format of -// "Program.Component.Version" with version being optional. -// -// CLSIDFromProgID in Windows API. -func CLSIDFromProgID(progId string) (clsid *GUID, err error) { - var guid GUID - lpszProgID := uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(progId))) - hr, _, _ := procCLSIDFromProgID.Call(lpszProgID, uintptr(unsafe.Pointer(&guid))) - if hr != 0 { - err = NewError(hr) - } - clsid = &guid - return -} - -// CLSIDFromString retrieves Class ID from string representation. -// -// This is technically the string version of the GUID and will convert the -// string to object. -// -// CLSIDFromString in Windows API. -func CLSIDFromString(str string) (clsid *GUID, err error) { - var guid GUID - lpsz := uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(str))) - hr, _, _ := procCLSIDFromString.Call(lpsz, uintptr(unsafe.Pointer(&guid))) - if hr != 0 { - err = NewError(hr) - } - clsid = &guid - return -} - -// StringFromCLSID returns GUID formated string from GUID object. -func StringFromCLSID(clsid *GUID) (str string, err error) { - var p *uint16 - hr, _, _ := procStringFromCLSID.Call(uintptr(unsafe.Pointer(clsid)), uintptr(unsafe.Pointer(&p))) - if hr != 0 { - err = NewError(hr) - } - str = LpOleStrToString(p) - return -} - -// IIDFromString returns GUID from program ID. -func IIDFromString(progId string) (clsid *GUID, err error) { - var guid GUID - lpsz := uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(progId))) - hr, _, _ := procIIDFromString.Call(lpsz, uintptr(unsafe.Pointer(&guid))) - if hr != 0 { - err = NewError(hr) - } - clsid = &guid - return -} - -// StringFromIID returns GUID formatted string from GUID object. -func StringFromIID(iid *GUID) (str string, err error) { - var p *uint16 - hr, _, _ := procStringFromIID.Call(uintptr(unsafe.Pointer(iid)), uintptr(unsafe.Pointer(&p))) - if hr != 0 { - err = NewError(hr) - } - str = LpOleStrToString(p) - return -} - -// CreateInstance of single uninitialized object with GUID. -func CreateInstance(clsid *GUID, iid *GUID) (unk *IUnknown, err error) { - if iid == nil { - iid = IID_IUnknown - } - hr, _, _ := procCoCreateInstance.Call( - uintptr(unsafe.Pointer(clsid)), - 0, - CLSCTX_SERVER, - uintptr(unsafe.Pointer(iid)), - uintptr(unsafe.Pointer(&unk))) - if hr != 0 { - err = NewError(hr) - } - return -} - -// GetActiveObject retrieves pointer to active object. -func GetActiveObject(clsid *GUID, iid *GUID) (unk *IUnknown, err error) { - if iid == nil { - iid = IID_IUnknown - } - hr, _, _ := procGetActiveObject.Call( - uintptr(unsafe.Pointer(clsid)), - uintptr(unsafe.Pointer(iid)), - uintptr(unsafe.Pointer(&unk))) - if hr != 0 { - err = NewError(hr) - } - return -} - -// VariantInit initializes variant. -func VariantInit(v *VARIANT) (err error) { - hr, _, _ := procVariantInit.Call(uintptr(unsafe.Pointer(v))) - if hr != 0 { - err = NewError(hr) - } - return -} - -// VariantClear clears value in Variant settings to VT_EMPTY. -func VariantClear(v *VARIANT) (err error) { - hr, _, _ := procVariantClear.Call(uintptr(unsafe.Pointer(v))) - if hr != 0 { - err = NewError(hr) - } - return -} - -// SysAllocString allocates memory for string and copies string into memory. -func SysAllocString(v string) (ss *int16) { - pss, _, _ := procSysAllocString.Call(uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(v)))) - ss = (*int16)(unsafe.Pointer(pss)) - return -} - -// SysAllocStringLen copies up to length of given string returning pointer. -func SysAllocStringLen(v string) (ss *int16) { - utf16 := utf16.Encode([]rune(v + "\x00")) - ptr := &utf16[0] - - pss, _, _ := procSysAllocStringLen.Call(uintptr(unsafe.Pointer(ptr)), uintptr(len(utf16)-1)) - ss = (*int16)(unsafe.Pointer(pss)) - return -} - -// SysFreeString frees string system memory. This must be called with SysAllocString. -func SysFreeString(v *int16) (err error) { - hr, _, _ := procSysFreeString.Call(uintptr(unsafe.Pointer(v))) - if hr != 0 { - err = NewError(hr) - } - return -} - -// SysStringLen is the length of the system allocated string. -func SysStringLen(v *int16) uint32 { - l, _, _ := procSysStringLen.Call(uintptr(unsafe.Pointer(v))) - return uint32(l) -} - -// CreateStdDispatch provides default IDispatch implementation for IUnknown. -// -// This handles default IDispatch implementation for objects. It haves a few -// limitations with only supporting one language. It will also only return -// default exception codes. -func CreateStdDispatch(unk *IUnknown, v uintptr, ptinfo *IUnknown) (disp *IDispatch, err error) { - hr, _, _ := procCreateStdDispatch.Call( - uintptr(unsafe.Pointer(unk)), - v, - uintptr(unsafe.Pointer(ptinfo)), - uintptr(unsafe.Pointer(&disp))) - if hr != 0 { - err = NewError(hr) - } - return -} - -// CreateDispTypeInfo provides default ITypeInfo implementation for IDispatch. -// -// This will not handle the full implementation of the interface. -func CreateDispTypeInfo(idata *INTERFACEDATA) (pptinfo *IUnknown, err error) { - hr, _, _ := procCreateDispTypeInfo.Call( - uintptr(unsafe.Pointer(idata)), - uintptr(GetUserDefaultLCID()), - uintptr(unsafe.Pointer(&pptinfo))) - if hr != 0 { - err = NewError(hr) - } - return -} - -// copyMemory moves location of a block of memory. -func copyMemory(dest unsafe.Pointer, src unsafe.Pointer, length uint32) { - procCopyMemory.Call(uintptr(dest), uintptr(src), uintptr(length)) -} - -// GetUserDefaultLCID retrieves current user default locale. -func GetUserDefaultLCID() (lcid uint32) { - ret, _, _ := procGetUserDefaultLCID.Call() - lcid = uint32(ret) - return -} - -// GetMessage in message queue from runtime. -// -// This function appears to block. PeekMessage does not block. -func GetMessage(msg *Msg, hwnd uint32, MsgFilterMin uint32, MsgFilterMax uint32) (ret int32, err error) { - r0, _, err := procGetMessageW.Call(uintptr(unsafe.Pointer(msg)), uintptr(hwnd), uintptr(MsgFilterMin), uintptr(MsgFilterMax)) - ret = int32(r0) - return -} - -// DispatchMessage to window procedure. -func DispatchMessage(msg *Msg) (ret int32) { - r0, _, _ := procDispatchMessageW.Call(uintptr(unsafe.Pointer(msg))) - ret = int32(r0) - return -} - -func GetVariantDate(value float64) (time.Time, error) { - var st syscall.Systemtime - r, _, _ := procVariantTimeToSystemTime.Call(uintptr(unsafe.Pointer(&value)), uintptr(unsafe.Pointer(&st))) - if r != 0 { - return time.Date(int(st.Year), time.Month(st.Month), int(st.Day), int(st.Hour), int(st.Minute), int(st.Second), int(st.Milliseconds/1000), nil), nil - } - return time.Now(), errors.New("Could not convert to time, passing current time.") -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/com_func.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/com_func.go deleted file mode 100644 index 425aad32336..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/com_func.go +++ /dev/null @@ -1,174 +0,0 @@ -// +build !windows - -package ole - -import ( - "time" - "unsafe" -) - -// coInitialize initializes COM library on current thread. -// -// MSDN documentation suggests that this function should not be called. Call -// CoInitializeEx() instead. The reason has to do with threading and this -// function is only for single-threaded apartments. -// -// That said, most users of the library have gotten away with just this -// function. If you are experiencing threading issues, then use -// CoInitializeEx(). -func coInitialize() error { - return NewError(E_NOTIMPL) -} - -// coInitializeEx initializes COM library with concurrency model. -func coInitializeEx(coinit uint32) error { - return NewError(E_NOTIMPL) -} - -// CoInitialize initializes COM library on current thread. -// -// MSDN documentation suggests that this function should not be called. Call -// CoInitializeEx() instead. The reason has to do with threading and this -// function is only for single-threaded apartments. -// -// That said, most users of the library have gotten away with just this -// function. If you are experiencing threading issues, then use -// CoInitializeEx(). -func CoInitialize(p uintptr) error { - return NewError(E_NOTIMPL) -} - -// CoInitializeEx initializes COM library with concurrency model. -func CoInitializeEx(p uintptr, coinit uint32) error { - return NewError(E_NOTIMPL) -} - -// CoUninitialize uninitializes COM Library. -func CoUninitialize() {} - -// CoTaskMemFree frees memory pointer. -func CoTaskMemFree(memptr uintptr) {} - -// CLSIDFromProgID retrieves Class Identifier with the given Program Identifier. -// -// The Programmatic Identifier must be registered, because it will be looked up -// in the Windows Registry. The registry entry has the following keys: CLSID, -// Insertable, Protocol and Shell -// (https://msdn.microsoft.com/en-us/library/dd542719(v=vs.85).aspx). -// -// programID identifies the class id with less precision and is not guaranteed -// to be unique. These are usually found in the registry under -// HKEY_LOCAL_MACHINE\SOFTWARE\Classes, usually with the format of -// "Program.Component.Version" with version being optional. -// -// CLSIDFromProgID in Windows API. -func CLSIDFromProgID(progId string) (*GUID, error) { - return nil, NewError(E_NOTIMPL) -} - -// CLSIDFromString retrieves Class ID from string representation. -// -// This is technically the string version of the GUID and will convert the -// string to object. -// -// CLSIDFromString in Windows API. -func CLSIDFromString(str string) (*GUID, error) { - return nil, NewError(E_NOTIMPL) -} - -// StringFromCLSID returns GUID formated string from GUID object. -func StringFromCLSID(clsid *GUID) (string, error) { - return "", NewError(E_NOTIMPL) -} - -// IIDFromString returns GUID from program ID. -func IIDFromString(progId string) (*GUID, error) { - return nil, NewError(E_NOTIMPL) -} - -// StringFromIID returns GUID formatted string from GUID object. -func StringFromIID(iid *GUID) (string, error) { - return "", NewError(E_NOTIMPL) -} - -// CreateInstance of single uninitialized object with GUID. -func CreateInstance(clsid *GUID, iid *GUID) (*IUnknown, error) { - return nil, NewError(E_NOTIMPL) -} - -// GetActiveObject retrieves pointer to active object. -func GetActiveObject(clsid *GUID, iid *GUID) (*IUnknown, error) { - return nil, NewError(E_NOTIMPL) -} - -// VariantInit initializes variant. -func VariantInit(v *VARIANT) error { - return NewError(E_NOTIMPL) -} - -// VariantClear clears value in Variant settings to VT_EMPTY. -func VariantClear(v *VARIANT) error { - return NewError(E_NOTIMPL) -} - -// SysAllocString allocates memory for string and copies string into memory. -func SysAllocString(v string) *int16 { - u := int16(0) - return &u -} - -// SysAllocStringLen copies up to length of given string returning pointer. -func SysAllocStringLen(v string) *int16 { - u := int16(0) - return &u -} - -// SysFreeString frees string system memory. This must be called with SysAllocString. -func SysFreeString(v *int16) error { - return NewError(E_NOTIMPL) -} - -// SysStringLen is the length of the system allocated string. -func SysStringLen(v *int16) uint32 { - return uint32(0) -} - -// CreateStdDispatch provides default IDispatch implementation for IUnknown. -// -// This handles default IDispatch implementation for objects. It haves a few -// limitations with only supporting one language. It will also only return -// default exception codes. -func CreateStdDispatch(unk *IUnknown, v uintptr, ptinfo *IUnknown) (*IDispatch, error) { - return nil, NewError(E_NOTIMPL) -} - -// CreateDispTypeInfo provides default ITypeInfo implementation for IDispatch. -// -// This will not handle the full implementation of the interface. -func CreateDispTypeInfo(idata *INTERFACEDATA) (*IUnknown, error) { - return nil, NewError(E_NOTIMPL) -} - -// copyMemory moves location of a block of memory. -func copyMemory(dest unsafe.Pointer, src unsafe.Pointer, length uint32) {} - -// GetUserDefaultLCID retrieves current user default locale. -func GetUserDefaultLCID() uint32 { - return uint32(0) -} - -// GetMessage in message queue from runtime. -// -// This function appears to block. PeekMessage does not block. -func GetMessage(msg *Msg, hwnd uint32, MsgFilterMin uint32, MsgFilterMax uint32) (int32, error) { - return int32(0), NewError(E_NOTIMPL) -} - -// DispatchMessage to window procedure. -func DispatchMessage(msg *Msg) int32 { - return int32(0) -} - -func GetVariantDate(value float64) (time.Time, error) { - return time.Now(), NewError(E_NOTIMPL) -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/com_func_test.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/com_func_test.go deleted file mode 100644 index 151898e59fa..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/com_func_test.go +++ /dev/null @@ -1,193 +0,0 @@ -// +build !windows - -package ole - -import "testing" - -// TestComSetupAndShutDown tests that API fails on Linux. -func TestComSetupAndShutDown(t *testing.T) { - defer func() { - if r := recover(); r != nil { - t.Log(r) - t.Fail() - } - }() - - err := coInitialize() - if err == nil { - t.Error("should be error, because only Windows is supported.") - t.FailNow() - } - - CoUninitialize() -} - -// TestComPublicSetupAndShutDown tests that API fails on Linux. -func TestComPublicSetupAndShutDown(t *testing.T) { - defer func() { - if r := recover(); r != nil { - t.Log(r) - t.Fail() - } - }() - - err := CoInitialize(0) - if err == nil { - t.Error("should be error, because only Windows is supported.") - t.FailNow() - } - - CoUninitialize() -} - -// TestComPublicSetupAndShutDown_WithValue tests that API fails on Linux. -func TestComPublicSetupAndShutDown_WithValue(t *testing.T) { - defer func() { - if r := recover(); r != nil { - t.Log(r) - t.Fail() - } - }() - - err := CoInitialize(5) - if err == nil { - t.Error("should be error, because only Windows is supported.") - t.FailNow() - } - - CoUninitialize() -} - -// TestComExSetupAndShutDown tests that API fails on Linux. -func TestComExSetupAndShutDown(t *testing.T) { - defer func() { - if r := recover(); r != nil { - t.Log(r) - t.Fail() - } - }() - - err := coInitializeEx(COINIT_MULTITHREADED) - if err == nil { - t.Error("should be error, because only Windows is supported.") - t.FailNow() - } - - CoUninitialize() -} - -// TestComPublicExSetupAndShutDown tests that API fails on Linux. -func TestComPublicExSetupAndShutDown(t *testing.T) { - defer func() { - if r := recover(); r != nil { - t.Log(r) - t.Fail() - } - }() - - err := CoInitializeEx(0, COINIT_MULTITHREADED) - if err == nil { - t.Error("should be error, because only Windows is supported.") - t.FailNow() - } - - CoUninitialize() -} - -// TestComPublicExSetupAndShutDown_WithValue tests that API fails on Linux. -func TestComPublicExSetupAndShutDown_WithValue(t *testing.T) { - defer func() { - if r := recover(); r != nil { - t.Log(r) - t.Fail() - } - }() - - err := CoInitializeEx(5, COINIT_MULTITHREADED) - if err == nil { - t.Error("should be error, because only Windows is supported.") - t.FailNow() - } - - CoUninitialize() -} - -// TestClsidFromProgID_WindowsMediaNSSManager tests that API fails on Linux. -func TestClsidFromProgID_WindowsMediaNSSManager(t *testing.T) { - defer func() { - if r := recover(); r != nil { - t.Log(r) - t.Fail() - } - }() - - coInitialize() - defer CoUninitialize() - _, err := CLSIDFromProgID("WMPNSSCI.NSSManager") - if err == nil { - t.Error("should be error, because only Windows is supported.") - t.FailNow() - } -} - -// TestClsidFromString_WindowsMediaNSSManager tests that API fails on Linux. -func TestClsidFromString_WindowsMediaNSSManager(t *testing.T) { - defer func() { - if r := recover(); r != nil { - t.Log(r) - t.Fail() - } - }() - - coInitialize() - defer CoUninitialize() - _, err := CLSIDFromString("{92498132-4D1A-4297-9B78-9E2E4BA99C07}") - - if err == nil { - t.Error("should be error, because only Windows is supported.") - t.FailNow() - } -} - -// TestCreateInstance_WindowsMediaNSSManager tests that API fails on Linux. -func TestCreateInstance_WindowsMediaNSSManager(t *testing.T) { - defer func() { - if r := recover(); r != nil { - t.Log(r) - t.Fail() - } - }() - - coInitialize() - defer CoUninitialize() - _, err := CLSIDFromProgID("WMPNSSCI.NSSManager") - - if err == nil { - t.Error("should be error, because only Windows is supported.") - t.FailNow() - } -} - -// TestError tests that API fails on Linux. -func TestError(t *testing.T) { - defer func() { - if r := recover(); r != nil { - t.Log(r) - t.Fail() - } - }() - - coInitialize() - defer CoUninitialize() - _, err := CLSIDFromProgID("INTERFACE-NOT-FOUND") - if err == nil { - t.Error("should be error, because only Windows is supported.") - t.FailNow() - } - - switch vt := err.(type) { - case *OleError: - default: - t.Fatalf("should be *ole.OleError %t", vt) - } -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/com_test.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/com_test.go deleted file mode 100644 index dd1f8119b05..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/com_test.go +++ /dev/null @@ -1,205 +0,0 @@ -// +build windows - -package ole - -import ( - "fmt" - "testing" -) - -func TestComSetupAndShutDown(t *testing.T) { - defer func() { - if r := recover(); r != nil { - t.Log(r) - t.Fail() - } - }() - - err := coInitialize() - if err != nil { - t.Error(err) - t.FailNow() - } - - CoUninitialize() -} - -func TestComPublicSetupAndShutDown(t *testing.T) { - defer func() { - if r := recover(); r != nil { - t.Log(r) - t.Fail() - } - }() - - err := CoInitialize(0) - if err != nil { - t.Error(err) - t.FailNow() - } - - CoUninitialize() -} - -func TestComPublicSetupAndShutDown_WithValue(t *testing.T) { - defer func() { - if r := recover(); r != nil { - t.Log(r) - t.Fail() - } - }() - - err := CoInitialize(5) - if err != nil { - t.Error(err) - t.FailNow() - } - - CoUninitialize() -} - -func TestComExSetupAndShutDown(t *testing.T) { - defer func() { - if r := recover(); r != nil { - t.Log(r) - t.Fail() - } - }() - - err := coInitializeEx(COINIT_MULTITHREADED) - if err != nil { - t.Error(err) - t.FailNow() - } - - CoUninitialize() -} - -func TestComPublicExSetupAndShutDown(t *testing.T) { - defer func() { - if r := recover(); r != nil { - t.Log(r) - t.Fail() - } - }() - - err := CoInitializeEx(0, COINIT_MULTITHREADED) - if err != nil { - t.Error(err) - t.FailNow() - } - - CoUninitialize() -} - -func TestComPublicExSetupAndShutDown_WithValue(t *testing.T) { - defer func() { - if r := recover(); r != nil { - t.Log(r) - t.Fail() - } - }() - - err := CoInitializeEx(5, COINIT_MULTITHREADED) - if err != nil { - t.Error(err) - t.FailNow() - } - - CoUninitialize() -} - -func TestClsidFromProgID_WindowsMediaNSSManager(t *testing.T) { - defer func() { - if r := recover(); r != nil { - t.Log(r) - t.Fail() - } - }() - - expected := &GUID{0x92498132, 0x4D1A, 0x4297, [8]byte{0x9B, 0x78, 0x9E, 0x2E, 0x4B, 0xA9, 0x9C, 0x07}} - - coInitialize() - defer CoUninitialize() - actual, err := CLSIDFromProgID("WMPNSSCI.NSSManager") - if err == nil { - if !IsEqualGUID(expected, actual) { - t.Log(err) - t.Log(fmt.Sprintf("Actual GUID: %+v\n", actual)) - t.Fail() - } - } -} - -func TestClsidFromString_WindowsMediaNSSManager(t *testing.T) { - defer func() { - if r := recover(); r != nil { - t.Log(r) - t.Fail() - } - }() - - expected := &GUID{0x92498132, 0x4D1A, 0x4297, [8]byte{0x9B, 0x78, 0x9E, 0x2E, 0x4B, 0xA9, 0x9C, 0x07}} - - coInitialize() - defer CoUninitialize() - actual, err := CLSIDFromString("{92498132-4D1A-4297-9B78-9E2E4BA99C07}") - - if !IsEqualGUID(expected, actual) { - t.Log(err) - t.Log(fmt.Sprintf("Actual GUID: %+v\n", actual)) - t.Fail() - } -} - -func TestCreateInstance_WindowsMediaNSSManager(t *testing.T) { - defer func() { - if r := recover(); r != nil { - t.Log(r) - t.Fail() - } - }() - - expected := &GUID{0x92498132, 0x4D1A, 0x4297, [8]byte{0x9B, 0x78, 0x9E, 0x2E, 0x4B, 0xA9, 0x9C, 0x07}} - - coInitialize() - defer CoUninitialize() - actual, err := CLSIDFromProgID("WMPNSSCI.NSSManager") - - if err == nil { - if !IsEqualGUID(expected, actual) { - t.Log(err) - t.Log(fmt.Sprintf("Actual GUID: %+v\n", actual)) - t.Fail() - } - - unknown, err := CreateInstance(actual, IID_IUnknown) - if err != nil { - t.Log(err) - t.Fail() - } - unknown.Release() - } -} - -func TestError(t *testing.T) { - defer func() { - if r := recover(); r != nil { - t.Log(r) - t.Fail() - } - }() - - coInitialize() - defer CoUninitialize() - _, err := CLSIDFromProgID("INTERFACE-NOT-FOUND") - if err == nil { - t.Fatalf("should be fail", err) - } - - switch vt := err.(type) { - case *OleError: - default: - t.Fatalf("should be *ole.OleError %t", vt) - } -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/connect.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/connect.go deleted file mode 100644 index b2ac2ec67ac..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/connect.go +++ /dev/null @@ -1,192 +0,0 @@ -package ole - -// Connection contains IUnknown for fluent interface interaction. -// -// Deprecated. Use oleutil package instead. -type Connection struct { - Object *IUnknown // Access COM -} - -// Initialize COM. -func (*Connection) Initialize() (err error) { - return coInitialize() -} - -// Uninitialize COM. -func (*Connection) Uninitialize() { - CoUninitialize() -} - -// Create IUnknown object based first on ProgId and then from String. -func (c *Connection) Create(progId string) (err error) { - var clsid *GUID - clsid, err = CLSIDFromProgID(progId) - if err != nil { - clsid, err = CLSIDFromString(progId) - if err != nil { - return - } - } - - unknown, err := CreateInstance(clsid, IID_IUnknown) - if err != nil { - return - } - c.Object = unknown - - return -} - -// Release IUnknown object. -func (c *Connection) Release() { - c.Object.Release() -} - -// Load COM object from list of programIDs or strings. -func (c *Connection) Load(names ...string) (errors []error) { - var tempErrors []error = make([]error, len(names)) - var numErrors int = 0 - for _, name := range names { - err := c.Create(name) - if err != nil { - tempErrors = append(tempErrors, err) - numErrors += 1 - continue - } - break - } - - copy(errors, tempErrors[0:numErrors]) - return -} - -// Dispatch returns Dispatch object. -func (c *Connection) Dispatch() (object *Dispatch, err error) { - dispatch, err := c.Object.QueryInterface(IID_IDispatch) - if err != nil { - return - } - object = &Dispatch{dispatch} - return -} - -// Dispatch stores IDispatch object. -type Dispatch struct { - Object *IDispatch // Dispatch object. -} - -// Call method on IDispatch with parameters. -func (d *Dispatch) Call(method string, params ...interface{}) (result *VARIANT, err error) { - id, err := d.GetId(method) - if err != nil { - return - } - - result, err = d.Invoke(id, DISPATCH_METHOD, params) - return -} - -// MustCall method on IDispatch with parameters. -func (d *Dispatch) MustCall(method string, params ...interface{}) (result *VARIANT) { - id, err := d.GetId(method) - if err != nil { - panic(err) - } - - result, err = d.Invoke(id, DISPATCH_METHOD, params) - if err != nil { - panic(err) - } - - return -} - -// Get property on IDispatch with parameters. -func (d *Dispatch) Get(name string, params ...interface{}) (result *VARIANT, err error) { - id, err := d.GetId(name) - if err != nil { - return - } - result, err = d.Invoke(id, DISPATCH_PROPERTYGET, params) - return -} - -// MustGet property on IDispatch with parameters. -func (d *Dispatch) MustGet(name string, params ...interface{}) (result *VARIANT) { - id, err := d.GetId(name) - if err != nil { - panic(err) - } - - result, err = d.Invoke(id, DISPATCH_PROPERTYGET, params) - if err != nil { - panic(err) - } - return -} - -// Set property on IDispatch with parameters. -func (d *Dispatch) Set(name string, params ...interface{}) (result *VARIANT, err error) { - id, err := d.GetId(name) - if err != nil { - return - } - result, err = d.Invoke(id, DISPATCH_PROPERTYPUT, params) - return -} - -// MustSet property on IDispatch with parameters. -func (d *Dispatch) MustSet(name string, params ...interface{}) (result *VARIANT) { - id, err := d.GetId(name) - if err != nil { - panic(err) - } - - result, err = d.Invoke(id, DISPATCH_PROPERTYPUT, params) - if err != nil { - panic(err) - } - return -} - -// GetId retrieves ID of name on IDispatch. -func (d *Dispatch) GetId(name string) (id int32, err error) { - var dispid []int32 - dispid, err = d.Object.GetIDsOfName([]string{name}) - if err != nil { - return - } - id = dispid[0] - return -} - -// GetIds retrieves all IDs of names on IDispatch. -func (d *Dispatch) GetIds(names ...string) (dispid []int32, err error) { - dispid, err = d.Object.GetIDsOfName(names) - return -} - -// Invoke IDispatch on DisplayID of dispatch type with parameters. -// -// There have been problems where if send cascading params..., it would error -// out because the parameters would be empty. -func (d *Dispatch) Invoke(id int32, dispatch int16, params []interface{}) (result *VARIANT, err error) { - if len(params) < 1 { - result, err = d.Object.Invoke(id, dispatch) - } else { - result, err = d.Object.Invoke(id, dispatch, params...) - } - return -} - -// Release IDispatch object. -func (d *Dispatch) Release() { - d.Object.Release() -} - -// Connect initializes COM and attempts to load IUnknown based on given names. -func Connect(names ...string) (connection *Connection) { - connection.Initialize() - connection.Load(names...) - return -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/connect_test.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/connect_test.go deleted file mode 100644 index fe35c7578a5..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/connect_test.go +++ /dev/null @@ -1,159 +0,0 @@ -// +build !windows - -package ole - -import "strings" - -func Example_quickbooks() { - var err error - - connection := &Connection{nil} - - err = connection.Initialize() - if err != nil { - return - } - defer connection.Uninitialize() - - err = connection.Create("QBXMLRP2.RequestProcessor.1") - if err != nil { - if err.(*OleError).Code() == CO_E_CLASSSTRING { - return - } - } - defer connection.Release() - - dispatch, err := connection.Dispatch() - if err != nil { - return - } - defer dispatch.Release() -} - -func Example_quickbooksConnectHelperCallDispatch() { - var err error - - connection := &Connection{nil} - - err = connection.Initialize() - if err != nil { - return - } - defer connection.Uninitialize() - - err = connection.Create("QBXMLRP2.RequestProcessor.1") - if err != nil { - if err.(*OleError).Code() == CO_E_CLASSSTRING { - return - } - return - } - defer connection.Release() - - dispatch, err := connection.Dispatch() - if err != nil { - return - } - defer dispatch.Release() - - var result *VARIANT - - _, err = dispatch.Call("OpenConnection2", "", "Test Application 1", 1) - if err != nil { - return - } - - result, err = dispatch.Call("BeginSession", "", 2) - if err != nil { - return - } - - ticket := result.ToString() - - _, err = dispatch.Call("EndSession", ticket) - if err != nil { - return - } - - _, err = dispatch.Call("CloseConnection") - if err != nil { - return - } -} - -func Example_quickbooksConnectHelperDispatchProperty() { - var err error - - connection := &Connection{nil} - - err = connection.Initialize() - if err != nil { - return - } - defer connection.Uninitialize() - - err = connection.Create("QBXMLRP2.RequestProcessor.1") - if err != nil { - if err.(*OleError).Code() == CO_E_CLASSSTRING { - return - } - return - } - defer connection.Release() - - dispatch, err := connection.Dispatch() - if err != nil { - return - } - defer dispatch.Release() - - var result *VARIANT - - _, err = dispatch.Call("OpenConnection2", "", "Test Application 1", 1) - if err != nil { - return - } - - result, err = dispatch.Call("BeginSession", "", 2) - if err != nil { - return - } - - ticket := result.ToString() - - result, err = dispatch.Get("QBXMLVersionsForSession", ticket) - if err != nil { - return - } - - conversion := result.ToArray() - - totalElements, _ := conversion.TotalElements(0) - if totalElements != 13 { - return - } - - versions := conversion.ToStringArray() - expectedVersionString := "1.0, 1.1, 2.0, 2.1, 3.0, 4.0, 4.1, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0" - versionString := strings.Join(versions, ", ") - - if len(versions) != 13 { - return - } - - if expectedVersionString != versionString { - return - } - - conversion.Release() - - _, err = dispatch.Call("EndSession", ticket) - if err != nil { - return - } - - _, err = dispatch.Call("CloseConnection") - if err != nil { - return - } -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/connect_windows_test.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/connect_windows_test.go deleted file mode 100644 index a1c3daa7276..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/connect_windows_test.go +++ /dev/null @@ -1,181 +0,0 @@ -// +build windows - -package ole - -import ( - "fmt" - "strings" - "testing" -) - -func Example_quickbooks() { - var err error - - connection := &Connection{nil} - - err = connection.Initialize() - if err != nil { - return - } - defer connection.Uninitialize() - - err = connection.Create("QBXMLRP2.RequestProcessor.1") - if err != nil { - if err.(*OleError).Code() == CO_E_CLASSSTRING { - return - } - } - defer connection.Release() - - dispatch, err := connection.Dispatch() - if err != nil { - return - } - defer dispatch.Release() -} - -func TestConnectHelperCallDispatch_QuickBooks(t *testing.T) { - var err error - - connection := &Connection{nil} - - err = connection.Initialize() - if err != nil { - t.Log(err) - t.FailNow() - } - defer connection.Uninitialize() - - err = connection.Create("QBXMLRP2.RequestProcessor.1") - if err != nil { - if err.(*OleError).Code() == CO_E_CLASSSTRING { - return - } - t.Log(err) - t.FailNow() - } - defer connection.Release() - - dispatch, err := connection.Dispatch() - if err != nil { - t.Log(err) - t.FailNow() - } - defer dispatch.Release() - - var result *VARIANT - - _, err = dispatch.Call("OpenConnection2", "", "Test Application 1", 1) - if err != nil { - t.Log(err) - t.FailNow() - } - - result, err = dispatch.Call("BeginSession", "", 2) - if err != nil { - t.Log(err) - t.FailNow() - } - - ticket := result.ToString() - - _, err = dispatch.Call("EndSession", ticket) - if err != nil { - t.Log(err) - t.Fail() - } - - _, err = dispatch.Call("CloseConnection") - if err != nil { - t.Log(err) - t.Fail() - } -} - -func TestConnectHelperDispatchProperty_QuickBooks(t *testing.T) { - var err error - - connection := &Connection{nil} - - err = connection.Initialize() - if err != nil { - t.Log(err) - t.FailNow() - } - defer connection.Uninitialize() - - err = connection.Create("QBXMLRP2.RequestProcessor.1") - if err != nil { - if err.(*OleError).Code() == CO_E_CLASSSTRING { - return - } - t.Log(err) - t.FailNow() - } - defer connection.Release() - - dispatch, err := connection.Dispatch() - if err != nil { - t.Log(err) - t.FailNow() - } - defer dispatch.Release() - - var result *VARIANT - - _, err = dispatch.Call("OpenConnection2", "", "Test Application 1", 1) - if err != nil { - t.Log(err) - t.FailNow() - } - - result, err = dispatch.Call("BeginSession", "", 2) - if err != nil { - t.Log(err) - t.FailNow() - } - - ticket := result.ToString() - - result, err = dispatch.Get("QBXMLVersionsForSession", ticket) - if err != nil { - t.Log(err) - t.FailNow() - } - - conversion := result.ToArray() - - totalElements, _ := conversion.TotalElements(0) - if totalElements != 13 { - t.Log(fmt.Sprintf("%d total elements does not equal 13\n", totalElements)) - t.Fail() - } - - versions := conversion.ToStringArray() - expectedVersionString := "1.0, 1.1, 2.0, 2.1, 3.0, 4.0, 4.1, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0" - versionString := strings.Join(versions, ", ") - - if len(versions) != 13 { - t.Log(fmt.Sprintf("%s\n", versionString)) - t.Fail() - } - - if expectedVersionString != versionString { - t.Log(fmt.Sprintf("Expected: %s\nActual: %s", expectedVersionString, versionString)) - t.Fail() - } - - conversion.Release() - - _, err = dispatch.Call("EndSession", ticket) - if err != nil { - t.Log(err) - t.Fail() - } - - _, err = dispatch.Call("CloseConnection") - if err != nil { - t.Log(err) - t.Fail() - } -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/constants.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/constants.go deleted file mode 100644 index fd0c6d74b0e..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/constants.go +++ /dev/null @@ -1,153 +0,0 @@ -package ole - -const ( - CLSCTX_INPROC_SERVER = 1 - CLSCTX_INPROC_HANDLER = 2 - CLSCTX_LOCAL_SERVER = 4 - CLSCTX_INPROC_SERVER16 = 8 - CLSCTX_REMOTE_SERVER = 16 - CLSCTX_ALL = CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER | CLSCTX_LOCAL_SERVER - CLSCTX_INPROC = CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER - CLSCTX_SERVER = CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER -) - -const ( - COINIT_APARTMENTTHREADED = 0x2 - COINIT_MULTITHREADED = 0x0 - COINIT_DISABLE_OLE1DDE = 0x4 - COINIT_SPEED_OVER_MEMORY = 0x8 -) - -const ( - DISPATCH_METHOD = 1 - DISPATCH_PROPERTYGET = 2 - DISPATCH_PROPERTYPUT = 4 - DISPATCH_PROPERTYPUTREF = 8 -) - -const ( - S_OK = 0x00000000 - E_UNEXPECTED = 0x8000FFFF - E_NOTIMPL = 0x80004001 - E_OUTOFMEMORY = 0x8007000E - E_INVALIDARG = 0x80070057 - E_NOINTERFACE = 0x80004002 - E_POINTER = 0x80004003 - E_HANDLE = 0x80070006 - E_ABORT = 0x80004004 - E_FAIL = 0x80004005 - E_ACCESSDENIED = 0x80070005 - E_PENDING = 0x8000000A - - CO_E_CLASSSTRING = 0x800401F3 -) - -const ( - CC_FASTCALL = iota - CC_CDECL - CC_MSCPASCAL - CC_PASCAL = CC_MSCPASCAL - CC_MACPASCAL - CC_STDCALL - CC_FPFASTCALL - CC_SYSCALL - CC_MPWCDECL - CC_MPWPASCAL - CC_MAX = CC_MPWPASCAL -) - -type VT uint16 - -const ( - VT_EMPTY VT = 0x0 - VT_NULL VT = 0x1 - VT_I2 VT = 0x2 - VT_I4 VT = 0x3 - VT_R4 VT = 0x4 - VT_R8 VT = 0x5 - VT_CY VT = 0x6 - VT_DATE VT = 0x7 - VT_BSTR VT = 0x8 - VT_DISPATCH VT = 0x9 - VT_ERROR VT = 0xa - VT_BOOL VT = 0xb - VT_VARIANT VT = 0xc - VT_UNKNOWN VT = 0xd - VT_DECIMAL VT = 0xe - VT_I1 VT = 0x10 - VT_UI1 VT = 0x11 - VT_UI2 VT = 0x12 - VT_UI4 VT = 0x13 - VT_I8 VT = 0x14 - VT_UI8 VT = 0x15 - VT_INT VT = 0x16 - VT_UINT VT = 0x17 - VT_VOID VT = 0x18 - VT_HRESULT VT = 0x19 - VT_PTR VT = 0x1a - VT_SAFEARRAY VT = 0x1b - VT_CARRAY VT = 0x1c - VT_USERDEFINED VT = 0x1d - VT_LPSTR VT = 0x1e - VT_LPWSTR VT = 0x1f - VT_RECORD VT = 0x24 - VT_INT_PTR VT = 0x25 - VT_UINT_PTR VT = 0x26 - VT_FILETIME VT = 0x40 - VT_BLOB VT = 0x41 - VT_STREAM VT = 0x42 - VT_STORAGE VT = 0x43 - VT_STREAMED_OBJECT VT = 0x44 - VT_STORED_OBJECT VT = 0x45 - VT_BLOB_OBJECT VT = 0x46 - VT_CF VT = 0x47 - VT_CLSID VT = 0x48 - VT_BSTR_BLOB VT = 0xfff - VT_VECTOR VT = 0x1000 - VT_ARRAY VT = 0x2000 - VT_BYREF VT = 0x4000 - VT_RESERVED VT = 0x8000 - VT_ILLEGAL VT = 0xffff - VT_ILLEGALMASKED VT = 0xfff - VT_TYPEMASK VT = 0xfff -) - -const ( - DISPID_UNKNOWN = -1 - DISPID_VALUE = 0 - DISPID_PROPERTYPUT = -3 - DISPID_NEWENUM = -4 - DISPID_EVALUATE = -5 - DISPID_CONSTRUCTOR = -6 - DISPID_DESTRUCTOR = -7 - DISPID_COLLECT = -8 -) - -const ( - TKIND_ENUM = 1 - TKIND_RECORD = 2 - TKIND_MODULE = 3 - TKIND_INTERFACE = 4 - TKIND_DISPATCH = 5 - TKIND_COCLASS = 6 - TKIND_ALIAS = 7 - TKIND_UNION = 8 - TKIND_MAX = 9 -) - -// Safe Array Feature Flags - -const ( - FADF_AUTO = 0x0001 - FADF_STATIC = 0x0002 - FADF_EMBEDDED = 0x0004 - FADF_FIXEDSIZE = 0x0010 - FADF_RECORD = 0x0020 - FADF_HAVEIID = 0x0040 - FADF_HAVEVARTYPE = 0x0080 - FADF_BSTR = 0x0100 - FADF_UNKNOWN = 0x0200 - FADF_DISPATCH = 0x0400 - FADF_VARIANT = 0x0800 - FADF_RESERVED = 0xF008 -) diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/data/screenshot.png b/Godeps/_workspace/src/github.com/go-ole/go-ole/data/screenshot.png deleted file mode 100644 index f61344b6005..00000000000 Binary files a/Godeps/_workspace/src/github.com/go-ole/go-ole/data/screenshot.png and /dev/null differ diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/error.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/error.go deleted file mode 100644 index 096b456d3a1..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/error.go +++ /dev/null @@ -1,51 +0,0 @@ -package ole - -// OleError stores COM errors. -type OleError struct { - hr uintptr - description string - subError error -} - -// NewError creates new error with HResult. -func NewError(hr uintptr) *OleError { - return &OleError{hr: hr} -} - -// NewErrorWithDescription creates new COM error with HResult and description. -func NewErrorWithDescription(hr uintptr, description string) *OleError { - return &OleError{hr: hr, description: description} -} - -// NewErrorWithSubError creates new COM error with parent error. -func NewErrorWithSubError(hr uintptr, description string, err error) *OleError { - return &OleError{hr: hr, description: description, subError: err} -} - -// Code is the HResult. -func (v *OleError) Code() uintptr { - return uintptr(v.hr) -} - -// String description, either manually set or format message with error code. -func (v *OleError) String() string { - if v.description != "" { - return errstr(int(v.hr)) + " (" + v.description + ")" - } - return errstr(int(v.hr)) -} - -// Error implements error interface. -func (v *OleError) Error() string { - return v.String() -} - -// Description retrieves error summary, if there is one. -func (v *OleError) Description() string { - return v.description -} - -// SubError returns parent error, if there is one. -func (v *OleError) SubError() error { - return v.subError -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/error_func.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/error_func.go deleted file mode 100644 index 8a2ffaa2724..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/error_func.go +++ /dev/null @@ -1,8 +0,0 @@ -// +build !windows - -package ole - -// errstr converts error code to string. -func errstr(errno int) string { - return "" -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/error_windows.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/error_windows.go deleted file mode 100644 index d0e8e68595c..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/error_windows.go +++ /dev/null @@ -1,24 +0,0 @@ -// +build windows - -package ole - -import ( - "fmt" - "syscall" - "unicode/utf16" -) - -// errstr converts error code to string. -func errstr(errno int) string { - // ask windows for the remaining errors - var flags uint32 = syscall.FORMAT_MESSAGE_FROM_SYSTEM | syscall.FORMAT_MESSAGE_ARGUMENT_ARRAY | syscall.FORMAT_MESSAGE_IGNORE_INSERTS - b := make([]uint16, 300) - n, err := syscall.FormatMessage(flags, 0, uint32(errno), 0, b, nil) - if err != nil { - return fmt.Sprintf("error %d (FormatMessage failed with: %v)", errno, err) - } - // trim terminating \r and \n - for ; n > 0 && (b[n-1] == '\n' || b[n-1] == '\r'); n-- { - } - return string(utf16.Decode(b[:n])) -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/example/excel/excel.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/example/excel/excel.go deleted file mode 100644 index 5c20033f734..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/example/excel/excel.go +++ /dev/null @@ -1,31 +0,0 @@ -// +build windows - -package main - -import ( - "time" - - ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole" - "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil" -) - -func main() { - ole.CoInitialize(0) - unknown, _ := oleutil.CreateObject("Excel.Application") - excel, _ := unknown.QueryInterface(ole.IID_IDispatch) - oleutil.PutProperty(excel, "Visible", true) - workbooks := oleutil.MustGetProperty(excel, "Workbooks").ToIDispatch() - workbook := oleutil.MustCallMethod(workbooks, "Add", nil).ToIDispatch() - worksheet := oleutil.MustGetProperty(workbook, "Worksheets", 1).ToIDispatch() - cell := oleutil.MustGetProperty(worksheet, "Cells", 1, 1).ToIDispatch() - oleutil.PutProperty(cell, "Value", 12345) - - time.Sleep(2000000000) - - oleutil.PutProperty(workbook, "Saved", true) - oleutil.CallMethod(workbook, "Close", false) - oleutil.CallMethod(excel, "Quit") - excel.Release() - - ole.CoUninitialize() -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/example/excel2/excel.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/example/excel2/excel.go deleted file mode 100644 index 87ab1b41779..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/example/excel2/excel.go +++ /dev/null @@ -1,96 +0,0 @@ -// +build windows - -package main - -import ( - "fmt" - "log" - "os" - - ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole" - "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil" -) - -func writeExample(excel, workbooks *ole.IDispatch, filepath string) { - // ref: https://msdn.microsoft.com/zh-tw/library/office/ff198017.aspx - // http://stackoverflow.com/questions/12159513/what-is-the-correct-xlfileformat-enumeration-for-excel-97-2003 - const xlExcel8 = 56 - workbook := oleutil.MustCallMethod(workbooks, "Add", nil).ToIDispatch() - defer workbook.Release() - worksheet := oleutil.MustGetProperty(workbook, "Worksheets", 1).ToIDispatch() - defer worksheet.Release() - cell := oleutil.MustGetProperty(worksheet, "Cells", 1, 1).ToIDispatch() - oleutil.PutProperty(cell, "Value", 12345) - cell.Release() - activeWorkBook := oleutil.MustGetProperty(excel, "ActiveWorkBook").ToIDispatch() - defer activeWorkBook.Release() - - os.Remove(filepath) - // ref: https://msdn.microsoft.com/zh-tw/library/microsoft.office.tools.excel.workbook.saveas.aspx - oleutil.MustCallMethod(activeWorkBook, "SaveAs", filepath, xlExcel8, nil, nil).ToIDispatch() - - //time.Sleep(2 * time.Second) - - // let excel could close without asking - // oleutil.PutProperty(workbook, "Saved", true) - // oleutil.CallMethod(workbook, "Close", false) -} - -func readExample(fileName string, excel, workbooks *ole.IDispatch) { - workbook, err := oleutil.CallMethod(workbooks, "Open", fileName) - - if err != nil { - log.Fatalln(err) - } - defer workbook.ToIDispatch().Release() - - sheets := oleutil.MustGetProperty(excel, "Sheets").ToIDispatch() - sheetCount := (int)(oleutil.MustGetProperty(sheets, "Count").Val) - fmt.Println("sheet count=", sheetCount) - sheets.Release() - - worksheet := oleutil.MustGetProperty(workbook.ToIDispatch(), "Worksheets", 1).ToIDispatch() - defer worksheet.Release() - for row := 1; row <= 2; row++ { - for col := 1; col <= 5; col++ { - cell := oleutil.MustGetProperty(worksheet, "Cells", row, col).ToIDispatch() - val, err := oleutil.GetProperty(cell, "Value") - if err != nil { - break - } - fmt.Printf("(%d,%d)=%+v toString=%s\n", col, row, val.Value(), val.ToString()) - cell.Release() - } - } -} - -func showMethodsAndProperties(i *ole.IDispatch) { - n, err := i.GetTypeInfoCount() - if err != nil { - log.Fatalln(err) - } - tinfo, err := i.GetTypeInfo() - if err != nil { - log.Fatalln(err) - } - - fmt.Println("n=", n, "tinfo=", tinfo) -} - -func main() { - log.SetFlags(log.Flags() | log.Lshortfile) - ole.CoInitialize(0) - unknown, _ := oleutil.CreateObject("Excel.Application") - excel, _ := unknown.QueryInterface(ole.IID_IDispatch) - oleutil.PutProperty(excel, "Visible", true) - - workbooks := oleutil.MustGetProperty(excel, "Workbooks").ToIDispatch() - cwd, _ := os.Getwd() - writeExample(excel, workbooks, cwd+"\\write.xls") - readExample(cwd+"\\excel97-2003.xls", excel, workbooks) - showMethodsAndProperties(workbooks) - workbooks.Release() - // oleutil.CallMethod(excel, "Quit") - excel.Release() - ole.CoUninitialize() -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/example/ie/ie.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/example/ie/ie.go deleted file mode 100644 index 4de881e9ae0..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/example/ie/ie.go +++ /dev/null @@ -1,33 +0,0 @@ -// +build windows - -package main - -import ( - "time" - - ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole" - "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil" -) - -func main() { - ole.CoInitialize(0) - unknown, _ := oleutil.CreateObject("InternetExplorer.Application") - ie, _ := unknown.QueryInterface(ole.IID_IDispatch) - oleutil.CallMethod(ie, "Navigate", "http://www.google.com") - oleutil.PutProperty(ie, "Visible", true) - for { - if oleutil.MustGetProperty(ie, "Busy").Val == 0 { - break - } - } - - time.Sleep(1e9) - - document := oleutil.MustGetProperty(ie, "document").ToIDispatch() - window := oleutil.MustGetProperty(document, "parentWindow").ToIDispatch() - // set 'golang' to text box. - oleutil.MustCallMethod(window, "eval", "document.getElementsByName('q')[0].value = 'golang'") - // click btnG. - btnG := oleutil.MustCallMethod(window, "eval", "document.getElementsByName('btnG')[0]").ToIDispatch() - oleutil.MustCallMethod(btnG, "click") -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/example/itunes/itunes.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/example/itunes/itunes.go deleted file mode 100644 index 9cc5df57195..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/example/itunes/itunes.go +++ /dev/null @@ -1,47 +0,0 @@ -// +build windows - -package main - -import ( - "log" - "os" - "strings" - - "github.com/gonuts/commander" - ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole" - "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil" -) - -func iTunes() *ole.IDispatch { - ole.CoInitialize(0) - unknown, err := oleutil.CreateObject("iTunes.Application") - if err != nil { - log.Fatal(err) - } - itunes, err := unknown.QueryInterface(ole.IID_IDispatch) - if err != nil { - log.Fatal(err) - } - return itunes -} - -func main() { - command := &commander.Command{ - UsageLine: os.Args[0], - Short: "itunes cmd", - } - command.Subcommands = []*commander.Command{} - for _, name := range []string{"Play", "Stop", "Pause", "Quit"} { - command.Subcommands = append(command.Subcommands, &commander.Command{ - Run: func(cmd *commander.Command, args []string) error { - _, err := oleutil.CallMethod(iTunes(), name) - return err - }, - UsageLine: strings.ToLower(name), - }) - } - err := command.Dispatch(os.Args[1:]) - if err != nil { - log.Fatal(err) - } -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/example/mediaplayer/mediaplayer.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/example/mediaplayer/mediaplayer.go deleted file mode 100644 index 0260f502967..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/example/mediaplayer/mediaplayer.go +++ /dev/null @@ -1,29 +0,0 @@ -// +build windows - -package main - -import ( - "fmt" - "log" - - ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole" - "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil" -) - -func main() { - ole.CoInitialize(0) - unknown, err := oleutil.CreateObject("WMPlayer.OCX") - if err != nil { - log.Fatal(err) - } - wmp := unknown.MustQueryInterface(ole.IID_IDispatch) - collection := oleutil.MustGetProperty(wmp, "MediaCollection").ToIDispatch() - list := oleutil.MustCallMethod(collection, "getAll").ToIDispatch() - count := int(oleutil.MustGetProperty(list, "count").Val) - for i := 0; i < count; i++ { - item := oleutil.MustGetProperty(list, "item", i).ToIDispatch() - name := oleutil.MustGetProperty(item, "name").ToString() - sourceURL := oleutil.MustGetProperty(item, "sourceURL").ToString() - fmt.Println(name, sourceURL) - } -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/example/msagent/msagent.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/example/msagent/msagent.go deleted file mode 100644 index 39cf3bb56f5..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/example/msagent/msagent.go +++ /dev/null @@ -1,24 +0,0 @@ -// +build windows - -package main - -import ( - "time" - - ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole" - "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil" -) - -func main() { - ole.CoInitialize(0) - unknown, _ := oleutil.CreateObject("Agent.Control.1") - agent, _ := unknown.QueryInterface(ole.IID_IDispatch) - oleutil.PutProperty(agent, "Connected", true) - characters := oleutil.MustGetProperty(agent, "Characters").ToIDispatch() - oleutil.CallMethod(characters, "Load", "Merlin", "c:\\windows\\msagent\\chars\\Merlin.acs") - character := oleutil.MustCallMethod(characters, "Character", "Merlin").ToIDispatch() - oleutil.CallMethod(character, "Show") - oleutil.CallMethod(character, "Speak", "こんにちわ世界") - - time.Sleep(4000000000) -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/example/msxml/rssreader.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/example/msxml/rssreader.go deleted file mode 100644 index e1d0253ec89..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/example/msxml/rssreader.go +++ /dev/null @@ -1,49 +0,0 @@ -// +build windows - -package main - -import ( - "fmt" - "time" - - ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole" - "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil" -) - -func main() { - ole.CoInitialize(0) - unknown, _ := oleutil.CreateObject("Microsoft.XMLHTTP") - xmlhttp, _ := unknown.QueryInterface(ole.IID_IDispatch) - _, err := oleutil.CallMethod(xmlhttp, "open", "GET", "http://rss.slashdot.org/Slashdot/slashdot", false) - if err != nil { - panic(err.Error()) - } - _, err = oleutil.CallMethod(xmlhttp, "send", nil) - if err != nil { - panic(err.Error()) - } - state := -1 - for state != 4 { - state = int(oleutil.MustGetProperty(xmlhttp, "readyState").Val) - time.Sleep(10000000) - } - responseXml := oleutil.MustGetProperty(xmlhttp, "responseXml").ToIDispatch() - items := oleutil.MustCallMethod(responseXml, "selectNodes", "/rss/channel/item").ToIDispatch() - length := int(oleutil.MustGetProperty(items, "length").Val) - - for n := 0; n < length; n++ { - item := oleutil.MustGetProperty(items, "item", n).ToIDispatch() - - title := oleutil.MustCallMethod(item, "selectSingleNode", "title").ToIDispatch() - fmt.Println(oleutil.MustGetProperty(title, "text").ToString()) - - link := oleutil.MustCallMethod(item, "selectSingleNode", "link").ToIDispatch() - fmt.Println(" " + oleutil.MustGetProperty(link, "text").ToString()) - - title.Release() - link.Release() - item.Release() - } - items.Release() - xmlhttp.Release() -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/example/outlook/outlook.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/example/outlook/outlook.go deleted file mode 100644 index 1452b8c8627..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/example/outlook/outlook.go +++ /dev/null @@ -1,29 +0,0 @@ -// +build windows - -package main - -import ( - "fmt" - - ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole" - "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil" -) - -func main() { - ole.CoInitialize(0) - unknown, _ := oleutil.CreateObject("Outlook.Application") - outlook, _ := unknown.QueryInterface(ole.IID_IDispatch) - ns := oleutil.MustCallMethod(outlook, "GetNamespace", "MAPI").ToIDispatch() - folder := oleutil.MustCallMethod(ns, "GetDefaultFolder", 10).ToIDispatch() - contacts := oleutil.MustCallMethod(folder, "Items").ToIDispatch() - count := oleutil.MustGetProperty(contacts, "Count").Value().(int32) - for i := 1; i <= int(count); i++ { - item, err := oleutil.GetProperty(contacts, "Item", i) - if err == nil && item.VT == ole.VT_DISPATCH { - if value, err := oleutil.GetProperty(item.ToIDispatch(), "FullName"); err == nil { - fmt.Println(value.Value()) - } - } - } - oleutil.MustCallMethod(outlook, "Quit") -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/example/winsock/winsock.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/example/winsock/winsock.go deleted file mode 100644 index 0d29955b83d..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/example/winsock/winsock.go +++ /dev/null @@ -1,140 +0,0 @@ -// +build windows - -package main - -import ( - "log" - "syscall" - "unsafe" - - ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole" - "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil" -) - -type EventReceiver struct { - lpVtbl *EventReceiverVtbl - ref int32 - host *ole.IDispatch -} - -type EventReceiverVtbl struct { - pQueryInterface uintptr - pAddRef uintptr - pRelease uintptr - pGetTypeInfoCount uintptr - pGetTypeInfo uintptr - pGetIDsOfNames uintptr - pInvoke uintptr -} - -func QueryInterface(this *ole.IUnknown, iid *ole.GUID, punk **ole.IUnknown) uint32 { - s, _ := ole.StringFromCLSID(iid) - *punk = nil - if ole.IsEqualGUID(iid, ole.IID_IUnknown) || - ole.IsEqualGUID(iid, ole.IID_IDispatch) { - AddRef(this) - *punk = this - return ole.S_OK - } - if s == "{248DD893-BB45-11CF-9ABC-0080C7E7B78D}" { - AddRef(this) - *punk = this - return ole.S_OK - } - return ole.E_NOINTERFACE -} - -func AddRef(this *ole.IUnknown) int32 { - pthis := (*EventReceiver)(unsafe.Pointer(this)) - pthis.ref++ - return pthis.ref -} - -func Release(this *ole.IUnknown) int32 { - pthis := (*EventReceiver)(unsafe.Pointer(this)) - pthis.ref-- - return pthis.ref -} - -func GetIDsOfNames(this *ole.IUnknown, iid *ole.GUID, wnames []*uint16, namelen int, lcid int, pdisp []int32) uintptr { - for n := 0; n < namelen; n++ { - pdisp[n] = int32(n) - } - return uintptr(ole.S_OK) -} - -func GetTypeInfoCount(pcount *int) uintptr { - if pcount != nil { - *pcount = 0 - } - return uintptr(ole.S_OK) -} - -func GetTypeInfo(ptypeif *uintptr) uintptr { - return uintptr(ole.E_NOTIMPL) -} - -func Invoke(this *ole.IDispatch, dispid int, riid *ole.GUID, lcid int, flags int16, dispparams *ole.DISPPARAMS, result *ole.VARIANT, pexcepinfo *ole.EXCEPINFO, nerr *uint) uintptr { - switch dispid { - case 0: - log.Println("DataArrival") - winsock := (*EventReceiver)(unsafe.Pointer(this)).host - var data ole.VARIANT - ole.VariantInit(&data) - oleutil.CallMethod(winsock, "GetData", &data) - s := string(data.ToArray().ToByteArray()) - println() - println(s) - println() - case 1: - log.Println("Connected") - winsock := (*EventReceiver)(unsafe.Pointer(this)).host - oleutil.CallMethod(winsock, "SendData", "GET / HTTP/1.0\r\n\r\n") - case 3: - log.Println("SendProgress") - case 4: - log.Println("SendComplete") - case 5: - log.Println("Close") - this.Release() - case 6: - log.Fatal("Error") - default: - log.Println(dispid) - } - return ole.E_NOTIMPL -} - -func main() { - ole.CoInitialize(0) - - unknown, err := oleutil.CreateObject("{248DD896-BB45-11CF-9ABC-0080C7E7B78D}") - if err != nil { - panic(err.Error()) - } - winsock, _ := unknown.QueryInterface(ole.IID_IDispatch) - iid, _ := ole.CLSIDFromString("{248DD893-BB45-11CF-9ABC-0080C7E7B78D}") - - dest := &EventReceiver{} - dest.lpVtbl = &EventReceiverVtbl{} - dest.lpVtbl.pQueryInterface = syscall.NewCallback(QueryInterface) - dest.lpVtbl.pAddRef = syscall.NewCallback(AddRef) - dest.lpVtbl.pRelease = syscall.NewCallback(Release) - dest.lpVtbl.pGetTypeInfoCount = syscall.NewCallback(GetTypeInfoCount) - dest.lpVtbl.pGetTypeInfo = syscall.NewCallback(GetTypeInfo) - dest.lpVtbl.pGetIDsOfNames = syscall.NewCallback(GetIDsOfNames) - dest.lpVtbl.pInvoke = syscall.NewCallback(Invoke) - dest.host = winsock - - oleutil.ConnectObject(winsock, iid, (*ole.IUnknown)(unsafe.Pointer(dest))) - _, err = oleutil.CallMethod(winsock, "Connect", "127.0.0.1", 80) - if err != nil { - log.Fatal(err) - } - - var m ole.Msg - for dest.ref != 0 { - ole.GetMessage(&m, 0, 0, 0) - ole.DispatchMessage(&m) - } -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/guid.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/guid.go deleted file mode 100644 index 7b3e33d8a99..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/guid.go +++ /dev/null @@ -1,115 +0,0 @@ -package ole - -var ( - // IID_NULL is null Interface ID, used when no other Interface ID is known. - IID_NULL = &GUID{0x00000000, 0x0000, 0x0000, [8]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}} - - // IID_IUnknown is for IUnknown interfaces. - IID_IUnknown = &GUID{0x00000000, 0x0000, 0x0000, [8]byte{0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}} - - // IID_IDispatch is for IDispatch interfaces. - IID_IDispatch = &GUID{0x00020400, 0x0000, 0x0000, [8]byte{0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}} - - // IID_IConnectionPointContainer is for IConnectionPointContainer interfaces. - IID_IConnectionPointContainer = &GUID{0xB196B284, 0xBAB4, 0x101A, [8]byte{0xB6, 0x9C, 0x00, 0xAA, 0x00, 0x34, 0x1D, 0x07}} - - // IID_IConnectionPoint is for IConnectionPoint interfaces. - IID_IConnectionPoint = &GUID{0xB196B286, 0xBAB4, 0x101A, [8]byte{0xB6, 0x9C, 0x00, 0xAA, 0x00, 0x34, 0x1D, 0x07}} - - // IID_IInspectable is for IInspectable interfaces. - IID_IInspectable = &GUID{0xaf86e2e0, 0xb12d, 0x4c6a, [8]byte{0x9c, 0x5a, 0xd7, 0xaa, 0x65, 0x10, 0x1e, 0x90}} - - // IID_IProvideClassInfo is for IProvideClassInfo interfaces. - IID_IProvideClassInfo = &GUID{0xb196b283, 0xbab4, 0x101a, [8]byte{0xB6, 0x9C, 0x00, 0xAA, 0x00, 0x34, 0x1D, 0x07}} -) - -// These are for testing and not part of any library. -var ( - // IID_ICOMTestString is for ICOMTestString interfaces. - // - // {E0133EB4-C36F-469A-9D3D-C66B84BE19ED} - IID_ICOMTestString = &GUID{0xe0133eb4, 0xc36f, 0x469a, [8]byte{0x9d, 0x3d, 0xc6, 0x6b, 0x84, 0xbe, 0x19, 0xed}} - - // IID_ICOMTestInt8 is for ICOMTestInt8 interfaces. - // - // {BEB06610-EB84-4155-AF58-E2BFF53608B4} - IID_ICOMTestInt8 = &GUID{0xbeb06610, 0xeb84, 0x4155, [8]byte{0xaf, 0x58, 0xe2, 0xbf, 0xf5, 0x36, 0x80, 0xb4}} - - // IID_ICOMTestInt16 is for ICOMTestInt16 interfaces. - // - // {DAA3F9FA-761E-4976-A860-8364CE55F6FC} - IID_ICOMTestInt16 = &GUID{0xdaa3f9fa, 0x761e, 0x4976, [8]byte{0xa8, 0x60, 0x83, 0x64, 0xce, 0x55, 0xf6, 0xfc}} - - // IID_ICOMTestInt32 is for ICOMTestInt32 interfaces. - // - // {E3DEDEE7-38A2-4540-91D1-2EEF1D8891B0} - IID_ICOMTestInt32 = &GUID{0xe3dedee7, 0x38a2, 0x4540, [8]byte{0x91, 0xd1, 0x2e, 0xef, 0x1d, 0x88, 0x91, 0xb0}} - - // IID_ICOMTestInt64 is for ICOMTestInt64 interfaces. - // - // {8D437CBC-B3ED-485C-BC32-C336432A1623} - IID_ICOMTestInt64 = &GUID{0x8d437cbc, 0xb3ed, 0x485c, [8]byte{0xbc, 0x32, 0xc3, 0x36, 0x43, 0x2a, 0x16, 0x23}} - - // IID_ICOMTestFloat is for ICOMTestFloat interfaces. - // - // {BF1ED004-EA02-456A-AA55-2AC8AC6B054C} - IID_ICOMTestFloat = &GUID{0xbf1ed004, 0xea02, 0x456a, [8]byte{0xaa, 0x55, 0x2a, 0xc8, 0xac, 0x6b, 0x5, 0x4c}} - - // IID_ICOMTestDouble is for ICOMTestDouble interfaces. - // - // {BF908A81-8687-4E93-999F-D86FAB284BA0} - IID_ICOMTestDouble = &GUID{0xbf908a81, 0x8687, 0x4e93, [8]byte{0x99, 0x9f, 0xd8, 0x6f, 0xab, 0x28, 0x4b, 0xa0}} - - // IID_ICOMTestBoolean is for ICOMTestBoolean interfaces. - // - // {D530E7A6-4EE8-40D1-8931-3D63B8605001} - IID_ICOMTestBoolean = &GUID{0xd530e7a6, 0x4ee8, 0x40d1, [8]byte{0x89, 0x31, 0x3d, 0x63, 0xb8, 0x60, 0x50, 0x10}} - - // IID_ICOMEchoTestObject is for ICOMEchoTestObject interfaces. - // - // {6485B1EF-D780-4834-A4FE-1EBB51746CA3} - IID_ICOMEchoTestObject = &GUID{0x6485b1ef, 0xd780, 0x4834, [8]byte{0xa4, 0xfe, 0x1e, 0xbb, 0x51, 0x74, 0x6c, 0xa3}} - - // IID_ICOMTestTypes is for ICOMTestTypes interfaces. - // - // {CCA8D7AE-91C0-4277-A8B3-FF4EDF28D3C0} - IID_ICOMTestTypes = &GUID{0xcca8d7ae, 0x91c0, 0x4277, [8]byte{0xa8, 0xb3, 0xff, 0x4e, 0xdf, 0x28, 0xd3, 0xc0}} - - // CLSID_COMEchoTestObject is for COMEchoTestObject class. - // - // {3C24506A-AE9E-4D50-9157-EF317281F1B0} - CLSID_COMEchoTestObject = &GUID{0x3c24506a, 0xae9e, 0x4d50, [8]byte{0x91, 0x57, 0xef, 0x31, 0x72, 0x81, 0xf1, 0xb0}} - - // CLSID_COMTestScalarClass is for COMTestScalarClass class. - // - // {865B85C5-0334-4AC6-9EF6-AACEC8FC5E86} - CLSID_COMTestScalarClass = &GUID{0x865b85c5, 0x3340, 0x4ac6, [8]byte{0x9e, 0xf6, 0xaa, 0xce, 0xc8, 0xfc, 0x5e, 0x86}} -) - -// GUID is Windows API specific GUID type. -// -// This exists to match Windows GUID type for direct passing for COM. -// Format is in xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxxx. -type GUID struct { - Data1 uint32 - Data2 uint16 - Data3 uint16 - Data4 [8]byte -} - -// IsEqualGUID compares two GUID. -// -// Not constant time comparison. -func IsEqualGUID(guid1 *GUID, guid2 *GUID) bool { - return guid1.Data1 == guid2.Data1 && - guid1.Data2 == guid2.Data2 && - guid1.Data3 == guid2.Data3 && - guid1.Data4[0] == guid2.Data4[0] && - guid1.Data4[1] == guid2.Data4[1] && - guid1.Data4[2] == guid2.Data4[2] && - guid1.Data4[3] == guid2.Data4[3] && - guid1.Data4[4] == guid2.Data4[4] && - guid1.Data4[5] == guid2.Data4[5] && - guid1.Data4[6] == guid2.Data4[6] && - guid1.Data4[7] == guid2.Data4[7] -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/iconnectionpoint.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/iconnectionpoint.go deleted file mode 100644 index 9e6c49f41f0..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/iconnectionpoint.go +++ /dev/null @@ -1,20 +0,0 @@ -package ole - -import "unsafe" - -type IConnectionPoint struct { - IUnknown -} - -type IConnectionPointVtbl struct { - IUnknownVtbl - GetConnectionInterface uintptr - GetConnectionPointContainer uintptr - Advise uintptr - Unadvise uintptr - EnumConnections uintptr -} - -func (v *IConnectionPoint) VTable() *IConnectionPointVtbl { - return (*IConnectionPointVtbl)(unsafe.Pointer(v.RawVTable)) -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/iconnectionpoint_func.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/iconnectionpoint_func.go deleted file mode 100644 index 5414dc3cd3b..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/iconnectionpoint_func.go +++ /dev/null @@ -1,21 +0,0 @@ -// +build !windows - -package ole - -import "unsafe" - -func (v *IConnectionPoint) GetConnectionInterface(piid **GUID) int32 { - return int32(0) -} - -func (v *IConnectionPoint) Advise(unknown *IUnknown) (uint32, error) { - return uint32(0), NewError(E_NOTIMPL) -} - -func (v *IConnectionPoint) Unadvise(cookie uint32) error { - return NewError(E_NOTIMPL) -} - -func (v *IConnectionPoint) EnumConnections(p *unsafe.Pointer) (err error) { - return NewError(E_NOTIMPL) -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/iconnectionpoint_windows.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/iconnectionpoint_windows.go deleted file mode 100644 index 32bc183248d..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/iconnectionpoint_windows.go +++ /dev/null @@ -1,43 +0,0 @@ -// +build windows - -package ole - -import ( - "syscall" - "unsafe" -) - -func (v *IConnectionPoint) GetConnectionInterface(piid **GUID) int32 { - // XXX: This doesn't look like it does what it's supposed to - return release((*IUnknown)(unsafe.Pointer(v))) -} - -func (v *IConnectionPoint) Advise(unknown *IUnknown) (cookie uint32, err error) { - hr, _, _ := syscall.Syscall( - v.VTable().Advise, - 3, - uintptr(unsafe.Pointer(v)), - uintptr(unsafe.Pointer(unknown)), - uintptr(unsafe.Pointer(&cookie))) - if hr != 0 { - err = NewError(hr) - } - return -} - -func (v *IConnectionPoint) Unadvise(cookie uint32) (err error) { - hr, _, _ := syscall.Syscall( - v.VTable().Unadvise, - 2, - uintptr(unsafe.Pointer(v)), - uintptr(cookie), - 0) - if hr != 0 { - err = NewError(hr) - } - return -} - -func (v *IConnectionPoint) EnumConnections(p *unsafe.Pointer) error { - return NewError(E_NOTIMPL) -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/iconnectionpointcontainer.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/iconnectionpointcontainer.go deleted file mode 100644 index 165860d199e..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/iconnectionpointcontainer.go +++ /dev/null @@ -1,17 +0,0 @@ -package ole - -import "unsafe" - -type IConnectionPointContainer struct { - IUnknown -} - -type IConnectionPointContainerVtbl struct { - IUnknownVtbl - EnumConnectionPoints uintptr - FindConnectionPoint uintptr -} - -func (v *IConnectionPointContainer) VTable() *IConnectionPointContainerVtbl { - return (*IConnectionPointContainerVtbl)(unsafe.Pointer(v.RawVTable)) -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/iconnectionpointcontainer_func.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/iconnectionpointcontainer_func.go deleted file mode 100644 index 5dfa42aaebb..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/iconnectionpointcontainer_func.go +++ /dev/null @@ -1,11 +0,0 @@ -// +build !windows - -package ole - -func (v *IConnectionPointContainer) EnumConnectionPoints(points interface{}) error { - return NewError(E_NOTIMPL) -} - -func (v *IConnectionPointContainer) FindConnectionPoint(iid *GUID, point **IConnectionPoint) error { - return NewError(E_NOTIMPL) -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/iconnectionpointcontainer_windows.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/iconnectionpointcontainer_windows.go deleted file mode 100644 index ad30d79efc4..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/iconnectionpointcontainer_windows.go +++ /dev/null @@ -1,25 +0,0 @@ -// +build windows - -package ole - -import ( - "syscall" - "unsafe" -) - -func (v *IConnectionPointContainer) EnumConnectionPoints(points interface{}) error { - return NewError(E_NOTIMPL) -} - -func (v *IConnectionPointContainer) FindConnectionPoint(iid *GUID, point **IConnectionPoint) (err error) { - hr, _, _ := syscall.Syscall( - v.VTable().FindConnectionPoint, - 3, - uintptr(unsafe.Pointer(v)), - uintptr(unsafe.Pointer(iid)), - uintptr(unsafe.Pointer(point))) - if hr != 0 { - err = NewError(hr) - } - return -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/idispatch.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/idispatch.go deleted file mode 100644 index 08abeac80dc..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/idispatch.go +++ /dev/null @@ -1,39 +0,0 @@ -package ole - -import "unsafe" - -type IDispatch struct { - IUnknown -} - -type IDispatchVtbl struct { - IUnknownVtbl - GetTypeInfoCount uintptr - GetTypeInfo uintptr - GetIDsOfNames uintptr - Invoke uintptr -} - -func (v *IDispatch) VTable() *IDispatchVtbl { - return (*IDispatchVtbl)(unsafe.Pointer(v.RawVTable)) -} - -func (v *IDispatch) GetIDsOfName(names []string) (dispid []int32, err error) { - dispid, err = getIDsOfName(v, names) - return -} - -func (v *IDispatch) Invoke(dispid int32, dispatch int16, params ...interface{}) (result *VARIANT, err error) { - result, err = invoke(v, dispid, dispatch, params...) - return -} - -func (v *IDispatch) GetTypeInfoCount() (c uint32, err error) { - c, err = getTypeInfoCount(v) - return -} - -func (v *IDispatch) GetTypeInfo() (tinfo *ITypeInfo, err error) { - tinfo, err = getTypeInfo(v) - return -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/idispatch_func.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/idispatch_func.go deleted file mode 100644 index b8fbbe319f1..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/idispatch_func.go +++ /dev/null @@ -1,19 +0,0 @@ -// +build !windows - -package ole - -func getIDsOfName(disp *IDispatch, names []string) ([]int32, error) { - return []int32{}, NewError(E_NOTIMPL) -} - -func getTypeInfoCount(disp *IDispatch) (uint32, error) { - return uint32(0), NewError(E_NOTIMPL) -} - -func getTypeInfo(disp *IDispatch) (*ITypeInfo, error) { - return nil, NewError(E_NOTIMPL) -} - -func invoke(disp *IDispatch, dispid int32, dispatch int16, params ...interface{}) (*VARIANT, error) { - return nil, NewError(E_NOTIMPL) -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/idispatch_windows.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/idispatch_windows.go deleted file mode 100644 index d698b1e31f3..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/idispatch_windows.go +++ /dev/null @@ -1,184 +0,0 @@ -// +build windows - -package ole - -import ( - "syscall" - "time" - "unsafe" -) - -func getIDsOfName(disp *IDispatch, names []string) (dispid []int32, err error) { - wnames := make([]*uint16, len(names)) - for i := 0; i < len(names); i++ { - wnames[i] = syscall.StringToUTF16Ptr(names[i]) - } - dispid = make([]int32, len(names)) - namelen := uint32(len(names)) - hr, _, _ := syscall.Syscall6( - disp.VTable().GetIDsOfNames, - 6, - uintptr(unsafe.Pointer(disp)), - uintptr(unsafe.Pointer(IID_NULL)), - uintptr(unsafe.Pointer(&wnames[0])), - uintptr(namelen), - uintptr(GetUserDefaultLCID()), - uintptr(unsafe.Pointer(&dispid[0]))) - if hr != 0 { - err = NewError(hr) - } - return -} - -func getTypeInfoCount(disp *IDispatch) (c uint32, err error) { - hr, _, _ := syscall.Syscall( - disp.VTable().GetTypeInfoCount, - 2, - uintptr(unsafe.Pointer(disp)), - uintptr(unsafe.Pointer(&c)), - 0) - if hr != 0 { - err = NewError(hr) - } - return -} - -func getTypeInfo(disp *IDispatch) (tinfo *ITypeInfo, err error) { - hr, _, _ := syscall.Syscall( - disp.VTable().GetTypeInfo, - 3, - uintptr(unsafe.Pointer(disp)), - uintptr(GetUserDefaultLCID()), - uintptr(unsafe.Pointer(&tinfo))) - if hr != 0 { - err = NewError(hr) - } - return -} - -func invoke(disp *IDispatch, dispid int32, dispatch int16, params ...interface{}) (result *VARIANT, err error) { - var dispparams DISPPARAMS - - if dispatch&DISPATCH_PROPERTYPUT != 0 { - dispnames := [1]int32{DISPID_PROPERTYPUT} - dispparams.rgdispidNamedArgs = uintptr(unsafe.Pointer(&dispnames[0])) - dispparams.cNamedArgs = 1 - } - var vargs []VARIANT - if len(params) > 0 { - vargs = make([]VARIANT, len(params)) - for i, v := range params { - //n := len(params)-i-1 - n := len(params) - i - 1 - VariantInit(&vargs[n]) - switch vv := v.(type) { - case bool: - if vv { - vargs[n] = NewVariant(VT_BOOL, 0xffff) - } else { - vargs[n] = NewVariant(VT_BOOL, 0) - } - case *bool: - vargs[n] = NewVariant(VT_BOOL|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*bool))))) - case byte: - vargs[n] = NewVariant(VT_I1, int64(v.(byte))) - case *byte: - vargs[n] = NewVariant(VT_I1|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*byte))))) - case int16: - vargs[n] = NewVariant(VT_I2, int64(v.(int16))) - case *int16: - vargs[n] = NewVariant(VT_I2|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*int16))))) - case uint16: - vargs[n] = NewVariant(VT_UI2, int64(v.(uint16))) - case *uint16: - vargs[n] = NewVariant(VT_UI2|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*uint16))))) - case int, int32: - vargs[n] = NewVariant(VT_I4, int64(v.(int))) - case *int, *int32: - vargs[n] = NewVariant(VT_I4|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*int))))) - case uint, uint32: - vargs[n] = NewVariant(VT_UI4, int64(v.(uint))) - case *uint, *uint32: - vargs[n] = NewVariant(VT_UI4|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*uint))))) - case int64: - vargs[n] = NewVariant(VT_I8, int64(v.(int64))) - case *int64: - vargs[n] = NewVariant(VT_I8|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*int64))))) - case uint64: - vargs[n] = NewVariant(VT_UI8, v.(int64)) - case *uint64: - vargs[n] = NewVariant(VT_UI8|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*uint64))))) - case float32: - vargs[n] = NewVariant(VT_R4, *(*int64)(unsafe.Pointer(&vv))) - case *float32: - vargs[n] = NewVariant(VT_R4|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*float32))))) - case float64: - vargs[n] = NewVariant(VT_R8, *(*int64)(unsafe.Pointer(&vv))) - case *float64: - vargs[n] = NewVariant(VT_R8|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*float64))))) - case string: - vargs[n] = NewVariant(VT_BSTR, int64(uintptr(unsafe.Pointer(SysAllocStringLen(v.(string)))))) - case *string: - vargs[n] = NewVariant(VT_BSTR|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*string))))) - case time.Time: - s := vv.Format("2006-01-02 15:04:05") - vargs[n] = NewVariant(VT_BSTR, int64(uintptr(unsafe.Pointer(SysAllocStringLen(s))))) - case *time.Time: - s := vv.Format("2006-01-02 15:04:05") - vargs[n] = NewVariant(VT_BSTR|VT_BYREF, int64(uintptr(unsafe.Pointer(&s)))) - case *IDispatch: - vargs[n] = NewVariant(VT_DISPATCH, int64(uintptr(unsafe.Pointer(v.(*IDispatch))))) - case **IDispatch: - vargs[n] = NewVariant(VT_DISPATCH|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(**IDispatch))))) - case nil: - vargs[n] = NewVariant(VT_NULL, 0) - case *VARIANT: - vargs[n] = NewVariant(VT_VARIANT|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*VARIANT))))) - case []byte: - safeByteArray := safeArrayFromByteSlice(v.([]byte)) - vargs[n] = NewVariant(VT_ARRAY|VT_UI1, int64(uintptr(unsafe.Pointer(safeByteArray)))) - defer VariantClear(&vargs[n]) - case []string: - safeByteArray := safeArrayFromStringSlice(v.([]string)) - vargs[n] = NewVariant(VT_ARRAY|VT_BSTR, int64(uintptr(unsafe.Pointer(safeByteArray)))) - defer VariantClear(&vargs[n]) - default: - panic("unknown type") - } - } - dispparams.rgvarg = uintptr(unsafe.Pointer(&vargs[0])) - dispparams.cArgs = uint32(len(params)) - } - - result = new(VARIANT) - var excepInfo EXCEPINFO - VariantInit(result) - hr, _, _ := syscall.Syscall9( - disp.VTable().Invoke, - 9, - uintptr(unsafe.Pointer(disp)), - uintptr(dispid), - uintptr(unsafe.Pointer(IID_NULL)), - uintptr(GetUserDefaultLCID()), - uintptr(dispatch), - uintptr(unsafe.Pointer(&dispparams)), - uintptr(unsafe.Pointer(result)), - uintptr(unsafe.Pointer(&excepInfo)), - 0) - if hr != 0 { - err = NewErrorWithSubError(hr, BstrToString(excepInfo.bstrDescription), excepInfo) - } - for _, varg := range vargs { - if varg.VT == VT_BSTR && varg.Val != 0 { - SysFreeString(((*int16)(unsafe.Pointer(uintptr(varg.Val))))) - } - /* - if varg.VT == (VT_BSTR|VT_BYREF) && varg.Val != 0 { - *(params[n].(*string)) = LpOleStrToString((*uint16)(unsafe.Pointer(uintptr(varg.Val)))) - println(*(params[n].(*string))) - fmt.Fprintln(os.Stderr, *(params[n].(*string))) - } - */ - } - return -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/idispatch_windows_test.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/idispatch_windows_test.go deleted file mode 100644 index f8c8c99929d..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/idispatch_windows_test.go +++ /dev/null @@ -1,83 +0,0 @@ -// +build windows - -package ole - -import ( - "reflect" - "testing" -) - -func TestIDispatch(t *testing.T) { - defer func() { - if r := recover(); r != nil { - t.Error(r) - } - }() - - var err error - - err = CoInitialize(0) - if err != nil { - t.Fatal(err) - } - - defer CoUninitialize() - - var unknown *IUnknown - var dispatch *IDispatch - - // oleutil.CreateObject() - unknown, err = CreateInstance(CLSID_COMEchoTestObject, IID_IUnknown) - if err != nil { - t.Fatal(err) - return - } - defer unknown.Release() - - dispatch, err = unknown.QueryInterface(IID_ICOMEchoTestObject) - if err != nil { - t.Fatal(err) - return - } - defer dispatch.Release() - - echoValue := func(method string, value interface{}) (interface{}, bool) { - var dispid []int32 - var err error - - dispid, err = dispatch.GetIDsOfName([]string{method}) - if err != nil { - t.Fatal(err) - return nil, false - } - - result, err := dispatch.Invoke(dispid[0], DISPATCH_METHOD, value) - if err != nil { - t.Fatal(err) - return nil, false - } - - return result.Value(), true - } - - methods := map[string]interface{}{ - "EchoInt8": int8(1), - "EchoInt16": int16(1), - "EchoInt32": int32(1), - "EchoInt64": int64(1), - "EchoUInt8": uint8(1), - "EchoUInt16": uint16(1), - "EchoUInt32": uint(1), - "EchoUInt64": uint64(1), - "EchoFloat32": float32(1.2), - "EchoFloat64": float64(1.2), - "EchoString": "Test String"} - - for method, expected := range methods { - if actual, passed := echoValue(method, expected); passed { - if !reflect.DeepEqual(expected, actual) { - t.Errorf("%s() expected %v did not match %v", method, expected, actual) - } - } - } -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/ienumvariant.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/ienumvariant.go deleted file mode 100644 index 24338975443..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/ienumvariant.go +++ /dev/null @@ -1,19 +0,0 @@ -package ole - -import "unsafe" - -type IEnumVARIANT struct { - IUnknown -} - -type IEnumVARIANTVtbl struct { - IUnknownVtbl - Next uintptr - Skip uintptr - Reset uintptr - Clone uintptr -} - -func (v *IEnumVARIANT) VTable() *IEnumVARIANTVtbl { - return (*IEnumVARIANTVtbl)(unsafe.Pointer(v.RawVTable)) -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/ienumvariant_func.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/ienumvariant_func.go deleted file mode 100644 index 8cfe8a5394b..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/ienumvariant_func.go +++ /dev/null @@ -1,19 +0,0 @@ -// +build !windows - -package ole - -func (enum *IEnumVARIANT) Clone() (*IEnumVARIANT, error) { - return nil, NewError(E_NOTIMPL) -} - -func (enum *IEnumVARIANT) Reset() error { - return NewError(E_NOTIMPL) -} - -func (enum *IEnumVARIANT) Skip(celt uint) error { - return NewError(E_NOTIMPL) -} - -func (enum *IEnumVARIANT) Next(celt uint) (*VARIANT, uint, error) { - return nil, 0, NewError(E_NOTIMPL) -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/ienumvariant_windows.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/ienumvariant_windows.go deleted file mode 100644 index b63345f1ec9..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/ienumvariant_windows.go +++ /dev/null @@ -1,63 +0,0 @@ -// +build windows - -package ole - -import ( - "syscall" - "unsafe" -) - -func (enum *IEnumVARIANT) Clone() (cloned *IEnumVARIANT, err error) { - hr, _, _ := syscall.Syscall( - enum.VTable().Clone, - 2, - uintptr(unsafe.Pointer(enum)), - uintptr(unsafe.Pointer(&cloned)), - 0) - if hr != 0 { - err = NewError(hr) - } - return -} - -func (enum *IEnumVARIANT) Reset() (err error) { - hr, _, _ := syscall.Syscall( - enum.VTable().Reset, - 1, - uintptr(unsafe.Pointer(enum)), - 0, - 0) - if hr != 0 { - err = NewError(hr) - } - return -} - -func (enum *IEnumVARIANT) Skip(celt uint) (err error) { - hr, _, _ := syscall.Syscall( - enum.VTable().Skip, - 2, - uintptr(unsafe.Pointer(enum)), - uintptr(celt), - 0) - if hr != 0 { - err = NewError(hr) - } - return -} - -func (enum *IEnumVARIANT) Next(celt uint) (array *VARIANT, length uint, err error) { - hr, _, _ := syscall.Syscall6( - enum.VTable().Next, - 4, - uintptr(unsafe.Pointer(enum)), - uintptr(celt), - uintptr(unsafe.Pointer(&array)), - uintptr(unsafe.Pointer(&length)), - 0, - 0) - if hr != 0 { - err = NewError(hr) - } - return -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/iinspectable.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/iinspectable.go deleted file mode 100644 index f4a19e253af..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/iinspectable.go +++ /dev/null @@ -1,18 +0,0 @@ -package ole - -import "unsafe" - -type IInspectable struct { - IUnknown -} - -type IInspectableVtbl struct { - IUnknownVtbl - GetIIds uintptr - GetRuntimeClassName uintptr - GetTrustLevel uintptr -} - -func (v *IInspectable) VTable() *IInspectableVtbl { - return (*IInspectableVtbl)(unsafe.Pointer(v.RawVTable)) -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/iinspectable_func.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/iinspectable_func.go deleted file mode 100644 index 348829bf062..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/iinspectable_func.go +++ /dev/null @@ -1,15 +0,0 @@ -// +build !windows - -package ole - -func (v *IInspectable) GetIids() ([]*GUID, error) { - return []*GUID{}, NewError(E_NOTIMPL) -} - -func (v *IInspectable) GetRuntimeClassName() (string, error) { - return "", NewError(E_NOTIMPL) -} - -func (v *IInspectable) GetTrustLevel() (uint32, error) { - return uint32(0), NewError(E_NOTIMPL) -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/iinspectable_windows.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/iinspectable_windows.go deleted file mode 100644 index b19dde5b57c..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/iinspectable_windows.go +++ /dev/null @@ -1,72 +0,0 @@ -// +build windows - -package ole - -import ( - "bytes" - "encoding/binary" - "reflect" - "syscall" - "unsafe" -) - -func (v *IInspectable) GetIids() (iids []*GUID, err error) { - var count uint32 - var array uintptr - hr, _, _ := syscall.Syscall( - v.VTable().GetIIds, - 3, - uintptr(unsafe.Pointer(v)), - uintptr(unsafe.Pointer(&count)), - uintptr(unsafe.Pointer(&array))) - if hr != 0 { - err = NewError(hr) - return - } - defer CoTaskMemFree(array) - - iids = make([]*GUID, count) - byteCount := count * uint32(unsafe.Sizeof(GUID{})) - slicehdr := reflect.SliceHeader{Data: array, Len: int(byteCount), Cap: int(byteCount)} - byteSlice := *(*[]byte)(unsafe.Pointer(&slicehdr)) - reader := bytes.NewReader(byteSlice) - for i, _ := range iids { - guid := GUID{} - err = binary.Read(reader, binary.LittleEndian, &guid) - if err != nil { - return - } - iids[i] = &guid - } - return -} - -func (v *IInspectable) GetRuntimeClassName() (s string, err error) { - var hstring HString - hr, _, _ := syscall.Syscall( - v.VTable().GetRuntimeClassName, - 2, - uintptr(unsafe.Pointer(v)), - uintptr(unsafe.Pointer(&hstring)), - 0) - if hr != 0 { - err = NewError(hr) - return - } - s = hstring.String() - DeleteHString(hstring) - return -} - -func (v *IInspectable) GetTrustLevel() (level uint32, err error) { - hr, _, _ := syscall.Syscall( - v.VTable().GetTrustLevel, - 2, - uintptr(unsafe.Pointer(v)), - uintptr(unsafe.Pointer(&level)), - 0) - if hr != 0 { - err = NewError(hr) - } - return -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/iprovideclassinfo.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/iprovideclassinfo.go deleted file mode 100644 index 25f3a6f24a9..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/iprovideclassinfo.go +++ /dev/null @@ -1,21 +0,0 @@ -package ole - -import "unsafe" - -type IProvideClassInfo struct { - IUnknown -} - -type IProvideClassInfoVtbl struct { - IUnknownVtbl - GetClassInfo uintptr -} - -func (v *IProvideClassInfo) VTable() *IProvideClassInfoVtbl { - return (*IProvideClassInfoVtbl)(unsafe.Pointer(v.RawVTable)) -} - -func (v *IProvideClassInfo) GetClassInfo() (cinfo *ITypeInfo, err error) { - cinfo, err = getClassInfo(v) - return -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/iprovideclassinfo_func.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/iprovideclassinfo_func.go deleted file mode 100644 index 7e3cb63ea73..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/iprovideclassinfo_func.go +++ /dev/null @@ -1,7 +0,0 @@ -// +build !windows - -package ole - -func getClassInfo(disp *IProvideClassInfo) (tinfo *ITypeInfo, err error) { - return nil, NewError(E_NOTIMPL) -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/iprovideclassinfo_windows.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/iprovideclassinfo_windows.go deleted file mode 100644 index 2ad01639497..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/iprovideclassinfo_windows.go +++ /dev/null @@ -1,21 +0,0 @@ -// +build windows - -package ole - -import ( - "syscall" - "unsafe" -) - -func getClassInfo(disp *IProvideClassInfo) (tinfo *ITypeInfo, err error) { - hr, _, _ := syscall.Syscall( - disp.VTable().GetClassInfo, - 2, - uintptr(unsafe.Pointer(disp)), - uintptr(unsafe.Pointer(&tinfo)), - 0) - if hr != 0 { - err = NewError(hr) - } - return -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/itypeinfo.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/itypeinfo.go deleted file mode 100644 index dd3c5e21bbf..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/itypeinfo.go +++ /dev/null @@ -1,34 +0,0 @@ -package ole - -import "unsafe" - -type ITypeInfo struct { - IUnknown -} - -type ITypeInfoVtbl struct { - IUnknownVtbl - GetTypeAttr uintptr - GetTypeComp uintptr - GetFuncDesc uintptr - GetVarDesc uintptr - GetNames uintptr - GetRefTypeOfImplType uintptr - GetImplTypeFlags uintptr - GetIDsOfNames uintptr - Invoke uintptr - GetDocumentation uintptr - GetDllEntry uintptr - GetRefTypeInfo uintptr - AddressOfMember uintptr - CreateInstance uintptr - GetMops uintptr - GetContainingTypeLib uintptr - ReleaseTypeAttr uintptr - ReleaseFuncDesc uintptr - ReleaseVarDesc uintptr -} - -func (v *ITypeInfo) VTable() *ITypeInfoVtbl { - return (*ITypeInfoVtbl)(unsafe.Pointer(v.RawVTable)) -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/itypeinfo_func.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/itypeinfo_func.go deleted file mode 100644 index 8364a659bae..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/itypeinfo_func.go +++ /dev/null @@ -1,7 +0,0 @@ -// +build !windows - -package ole - -func (v *ITypeInfo) GetTypeAttr() (*TYPEATTR, error) { - return nil, NewError(E_NOTIMPL) -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/itypeinfo_windows.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/itypeinfo_windows.go deleted file mode 100644 index 54782b3da5d..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/itypeinfo_windows.go +++ /dev/null @@ -1,21 +0,0 @@ -// +build windows - -package ole - -import ( - "syscall" - "unsafe" -) - -func (v *ITypeInfo) GetTypeAttr() (tattr *TYPEATTR, err error) { - hr, _, _ := syscall.Syscall( - uintptr(v.VTable().GetTypeAttr), - 2, - uintptr(unsafe.Pointer(v)), - uintptr(unsafe.Pointer(&tattr)), - 0) - if hr != 0 { - err = NewError(hr) - } - return -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/iunknown.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/iunknown.go deleted file mode 100644 index 26d996345d7..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/iunknown.go +++ /dev/null @@ -1,57 +0,0 @@ -package ole - -import "unsafe" - -type IUnknown struct { - RawVTable *interface{} -} - -type IUnknownVtbl struct { - QueryInterface uintptr - AddRef uintptr - Release uintptr -} - -type UnknownLike interface { - QueryInterface(iid *GUID) (disp *IDispatch, err error) - AddRef() int32 - Release() int32 -} - -func (v *IUnknown) VTable() *IUnknownVtbl { - return (*IUnknownVtbl)(unsafe.Pointer(v.RawVTable)) -} - -func (v *IUnknown) PutQueryInterface(interfaceID *GUID, obj interface{}) error { - return reflectQueryInterface(v, v.VTable().QueryInterface, interfaceID, &obj) -} - -func (v *IUnknown) IDispatch(interfaceID *GUID) (dispatch *IDispatch, err error) { - err = v.PutQueryInterface(interfaceID, &dispatch) - return -} - -func (v *IUnknown) IEnumVARIANT(interfaceID *GUID) (enum *IEnumVARIANT, err error) { - err = v.PutQueryInterface(interfaceID, &enum) - return -} - -func (v *IUnknown) QueryInterface(iid *GUID) (*IDispatch, error) { - return queryInterface(v, iid) -} - -func (v *IUnknown) MustQueryInterface(iid *GUID) (disp *IDispatch) { - unk, err := queryInterface(v, iid) - if err != nil { - panic(err) - } - return unk -} - -func (v *IUnknown) AddRef() int32 { - return addRef(v) -} - -func (v *IUnknown) Release() int32 { - return release(v) -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/iunknown_func.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/iunknown_func.go deleted file mode 100644 index d0a62cfd730..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/iunknown_func.go +++ /dev/null @@ -1,19 +0,0 @@ -// +build !windows - -package ole - -func reflectQueryInterface(self interface{}, method uintptr, interfaceID *GUID, obj interface{}) (err error) { - return NewError(E_NOTIMPL) -} - -func queryInterface(unk *IUnknown, iid *GUID) (disp *IDispatch, err error) { - return nil, NewError(E_NOTIMPL) -} - -func addRef(unk *IUnknown) int32 { - return 0 -} - -func release(unk *IUnknown) int32 { - return 0 -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/iunknown_windows.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/iunknown_windows.go deleted file mode 100644 index eea5042c7cd..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/iunknown_windows.go +++ /dev/null @@ -1,55 +0,0 @@ -// +build windows - -package ole - -import ( - "reflect" - "syscall" - "unsafe" -) - -func reflectQueryInterface(self interface{}, method uintptr, interfaceID *GUID, obj interface{}) (err error) { - hr, _, _ := syscall.Syscall( - method, - 3, - reflect.ValueOf(self).UnsafeAddr(), - uintptr(unsafe.Pointer(interfaceID)), - reflect.ValueOf(obj).UnsafeAddr()) - if hr != 0 { - err = NewError(hr) - } - return -} - -func queryInterface(unk *IUnknown, iid *GUID) (disp *IDispatch, err error) { - hr, _, _ := syscall.Syscall( - unk.VTable().QueryInterface, - 3, - uintptr(unsafe.Pointer(unk)), - uintptr(unsafe.Pointer(iid)), - uintptr(unsafe.Pointer(&disp))) - if hr != 0 { - err = NewError(hr) - } - return -} - -func addRef(unk *IUnknown) int32 { - ret, _, _ := syscall.Syscall( - unk.VTable().AddRef, - 1, - uintptr(unsafe.Pointer(unk)), - 0, - 0) - return int32(ret) -} - -func release(unk *IUnknown) int32 { - ret, _, _ := syscall.Syscall( - unk.VTable().Release, - 1, - uintptr(unsafe.Pointer(unk)), - 0, - 0) - return int32(ret) -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/iunknown_windows_test.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/iunknown_windows_test.go deleted file mode 100644 index c78591f2e7c..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/iunknown_windows_test.go +++ /dev/null @@ -1,32 +0,0 @@ -// +build windows - -package ole - -import "testing" - -func TestIUnknown(t *testing.T) { - defer func() { - if r := recover(); r != nil { - t.Error(r) - } - }() - - var err error - - err = CoInitialize(0) - if err != nil { - t.Fatal(err) - } - - defer CoUninitialize() - - var unknown *IUnknown - - // oleutil.CreateObject() - unknown, err = CreateInstance(CLSID_COMEchoTestObject, IID_IUnknown) - if err != nil { - t.Fatal(err) - return - } - unknown.Release() -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/ole.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/ole.go deleted file mode 100644 index b92b4ea189f..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/ole.go +++ /dev/null @@ -1,147 +0,0 @@ -package ole - -import ( - "fmt" - "strings" -) - -// DISPPARAMS are the arguments that passed to methods or property. -type DISPPARAMS struct { - rgvarg uintptr - rgdispidNamedArgs uintptr - cArgs uint32 - cNamedArgs uint32 -} - -// EXCEPINFO defines exception info. -type EXCEPINFO struct { - wCode uint16 - wReserved uint16 - bstrSource *uint16 - bstrDescription *uint16 - bstrHelpFile *uint16 - dwHelpContext uint32 - pvReserved uintptr - pfnDeferredFillIn uintptr - scode uint32 -} - -// String convert EXCEPINFO to string. -func (e EXCEPINFO) String() string { - var src, desc, hlp string - if e.bstrSource == nil { - src = "" - } else { - src = BstrToString(e.bstrSource) - } - - if e.bstrDescription == nil { - desc = "" - } else { - desc = BstrToString(e.bstrDescription) - } - - if e.bstrHelpFile == nil { - hlp = "" - } else { - hlp = BstrToString(e.bstrHelpFile) - } - - return fmt.Sprintf( - "wCode: %#x, bstrSource: %v, bstrDescription: %v, bstrHelpFile: %v, dwHelpContext: %#x, scode: %#x", - e.wCode, src, desc, hlp, e.dwHelpContext, e.scode, - ) -} - -// Error implements error interface and returns error string. -func (e EXCEPINFO) Error() string { - if e.bstrDescription != nil { - return strings.TrimSpace(BstrToString(e.bstrDescription)) - } - - src := "Unknown" - if e.bstrSource != nil { - src = BstrToString(e.bstrSource) - } - - code := e.scode - if e.wCode != 0 { - code = uint32(e.wCode) - } - - return fmt.Sprintf("%v: %#x", src, code) -} - -// PARAMDATA defines parameter data type. -type PARAMDATA struct { - Name *int16 - Vt uint16 -} - -// METHODDATA defines method info. -type METHODDATA struct { - Name *uint16 - Data *PARAMDATA - Dispid int32 - Meth uint32 - CC int32 - CArgs uint32 - Flags uint16 - VtReturn uint32 -} - -// INTERFACEDATA defines interface info. -type INTERFACEDATA struct { - MethodData *METHODDATA - CMembers uint32 -} - -// Point is 2D vector type. -type Point struct { - X int32 - Y int32 -} - -// Msg is message between processes. -type Msg struct { - Hwnd uint32 - Message uint32 - Wparam int32 - Lparam int32 - Time uint32 - Pt Point -} - -// TYPEDESC defines data type. -type TYPEDESC struct { - Hreftype uint32 - VT uint16 -} - -// IDLDESC defines IDL info. -type IDLDESC struct { - DwReserved uint32 - WIDLFlags uint16 -} - -// TYPEATTR defines type info. -type TYPEATTR struct { - Guid GUID - Lcid uint32 - dwReserved uint32 - MemidConstructor int32 - MemidDestructor int32 - LpstrSchema *uint16 - CbSizeInstance uint32 - Typekind int32 - CFuncs uint16 - CVars uint16 - CImplTypes uint16 - CbSizeVft uint16 - CbAlignment uint16 - WTypeFlags uint16 - WMajorVerNum uint16 - WMinorVerNum uint16 - TdescAlias TYPEDESC - IdldescType IDLDESC -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil/connection.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil/connection.go deleted file mode 100644 index 3f7ec124365..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil/connection.go +++ /dev/null @@ -1,100 +0,0 @@ -// +build windows - -package oleutil - -import ( - "reflect" - "unsafe" - - ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole" -) - -type stdDispatch struct { - lpVtbl *stdDispatchVtbl - ref int32 - iid *ole.GUID - iface interface{} - funcMap map[string]int32 -} - -type stdDispatchVtbl struct { - pQueryInterface uintptr - pAddRef uintptr - pRelease uintptr - pGetTypeInfoCount uintptr - pGetTypeInfo uintptr - pGetIDsOfNames uintptr - pInvoke uintptr -} - -func dispQueryInterface(this *ole.IUnknown, iid *ole.GUID, punk **ole.IUnknown) uint32 { - pthis := (*stdDispatch)(unsafe.Pointer(this)) - *punk = nil - if ole.IsEqualGUID(iid, ole.IID_IUnknown) || - ole.IsEqualGUID(iid, ole.IID_IDispatch) { - dispAddRef(this) - *punk = this - return ole.S_OK - } - if ole.IsEqualGUID(iid, pthis.iid) { - dispAddRef(this) - *punk = this - return ole.S_OK - } - return ole.E_NOINTERFACE -} - -func dispAddRef(this *ole.IUnknown) int32 { - pthis := (*stdDispatch)(unsafe.Pointer(this)) - pthis.ref++ - return pthis.ref -} - -func dispRelease(this *ole.IUnknown) int32 { - pthis := (*stdDispatch)(unsafe.Pointer(this)) - pthis.ref-- - return pthis.ref -} - -func dispGetIDsOfNames(this *ole.IUnknown, iid *ole.GUID, wnames []*uint16, namelen int, lcid int, pdisp []int32) uintptr { - pthis := (*stdDispatch)(unsafe.Pointer(this)) - names := make([]string, len(wnames)) - for i := 0; i < len(names); i++ { - names[i] = ole.LpOleStrToString(wnames[i]) - } - for n := 0; n < namelen; n++ { - if id, ok := pthis.funcMap[names[n]]; ok { - pdisp[n] = id - } - } - return ole.S_OK -} - -func dispGetTypeInfoCount(pcount *int) uintptr { - if pcount != nil { - *pcount = 0 - } - return ole.S_OK -} - -func dispGetTypeInfo(ptypeif *uintptr) uintptr { - return ole.E_NOTIMPL -} - -func dispInvoke(this *ole.IDispatch, dispid int32, riid *ole.GUID, lcid int, flags int16, dispparams *ole.DISPPARAMS, result *ole.VARIANT, pexcepinfo *ole.EXCEPINFO, nerr *uint) uintptr { - pthis := (*stdDispatch)(unsafe.Pointer(this)) - found := "" - for name, id := range pthis.funcMap { - if id == dispid { - found = name - } - } - if found != "" { - rv := reflect.ValueOf(pthis.iface).Elem() - rm := rv.MethodByName(found) - rr := rm.Call([]reflect.Value{}) - println(len(rr)) - return ole.S_OK - } - return ole.E_NOTIMPL -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil/connection_func.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil/connection_func.go deleted file mode 100644 index 6fea57d122c..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil/connection_func.go +++ /dev/null @@ -1,10 +0,0 @@ -// +build !windows - -package oleutil - -import ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole" - -// ConnectObject creates a connection point between two services for communication. -func ConnectObject(disp *ole.IDispatch, iid *ole.GUID, idisp interface{}) (uint32, error) { - return 0, ole.NewError(ole.E_NOTIMPL) -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil/connection_windows.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil/connection_windows.go deleted file mode 100644 index cf5454c03bb..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil/connection_windows.go +++ /dev/null @@ -1,57 +0,0 @@ -// +build windows - -package oleutil - -import ( - "reflect" - "syscall" - "unsafe" - - ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole" -) - -// ConnectObject creates a connection point between two services for communication. -func ConnectObject(disp *ole.IDispatch, iid *ole.GUID, idisp interface{}) (cookie uint32, err error) { - unknown, err := disp.QueryInterface(ole.IID_IConnectionPointContainer) - if err != nil { - return - } - - container := (*ole.IConnectionPointContainer)(unsafe.Pointer(unknown)) - var point *ole.IConnectionPoint - err = container.FindConnectionPoint(iid, &point) - if err != nil { - return - } - if edisp, ok := idisp.(*ole.IUnknown); ok { - cookie, err = point.Advise(edisp) - container.Release() - if err != nil { - return - } - } - rv := reflect.ValueOf(disp).Elem() - if rv.Type().Kind() == reflect.Struct { - dest := &stdDispatch{} - dest.lpVtbl = &stdDispatchVtbl{} - dest.lpVtbl.pQueryInterface = syscall.NewCallback(dispQueryInterface) - dest.lpVtbl.pAddRef = syscall.NewCallback(dispAddRef) - dest.lpVtbl.pRelease = syscall.NewCallback(dispRelease) - dest.lpVtbl.pGetTypeInfoCount = syscall.NewCallback(dispGetTypeInfoCount) - dest.lpVtbl.pGetTypeInfo = syscall.NewCallback(dispGetTypeInfo) - dest.lpVtbl.pGetIDsOfNames = syscall.NewCallback(dispGetIDsOfNames) - dest.lpVtbl.pInvoke = syscall.NewCallback(dispInvoke) - dest.iface = disp - dest.iid = iid - cookie, err = point.Advise((*ole.IUnknown)(unsafe.Pointer(dest))) - container.Release() - if err != nil { - point.Release() - return - } - } - - container.Release() - - return 0, ole.NewError(ole.E_INVALIDARG) -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil/go-get.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil/go-get.go deleted file mode 100644 index 58347628f24..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil/go-get.go +++ /dev/null @@ -1,6 +0,0 @@ -// This file is here so go get succeeds as without it errors with: -// no buildable Go source files in ... -// -// +build !windows - -package oleutil diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil/oleutil.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil/oleutil.go deleted file mode 100644 index cfae91a094a..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil/oleutil.go +++ /dev/null @@ -1,132 +0,0 @@ -package oleutil - -import ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole" - -// ClassIDFrom retrieves class ID whether given is program ID or application string. -func ClassIDFrom(programID string) (classID *ole.GUID, err error) { - classID, err = ole.CLSIDFromProgID(programID) - if err != nil { - classID, err = ole.CLSIDFromString(programID) - if err != nil { - return - } - } - return -} - -// CreateObject creates object from programID based on interface type. -// -// Only supports IUnknown. -// -// Program ID can be either program ID or application string. -func CreateObject(programID string) (unknown *ole.IUnknown, err error) { - classID, err := ClassIDFrom(programID) - if err != nil { - return - } - - unknown, err = ole.CreateInstance(classID, ole.IID_IUnknown) - if err != nil { - return - } - - return -} - -// GetActiveObject retrieves active object for program ID and interface ID based -// on interface type. -// -// Only supports IUnknown. -// -// Program ID can be either program ID or application string. -func GetActiveObject(programID string) (unknown *ole.IUnknown, err error) { - classID, err := ClassIDFrom(programID) - if err != nil { - return - } - - unknown, err = ole.GetActiveObject(classID, ole.IID_IUnknown) - if err != nil { - return - } - - return -} - -// CallMethod calls method on IDispatch with parameters. -func CallMethod(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT, err error) { - var dispid []int32 - dispid, err = disp.GetIDsOfName([]string{name}) - if err != nil { - return - } - - if len(params) < 1 { - result, err = disp.Invoke(dispid[0], ole.DISPATCH_METHOD) - } else { - result, err = disp.Invoke(dispid[0], ole.DISPATCH_METHOD, params...) - } - - return -} - -// MustCallMethod calls method on IDispatch with parameters or panics. -func MustCallMethod(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT) { - r, err := CallMethod(disp, name, params...) - if err != nil { - panic(err.Error()) - } - return r -} - -// GetProperty retrieves property from IDispatch. -func GetProperty(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT, err error) { - var dispid []int32 - dispid, err = disp.GetIDsOfName([]string{name}) - if err != nil { - return - } - - if len(params) < 1 { - result, err = disp.Invoke(dispid[0], ole.DISPATCH_PROPERTYGET) - } else { - result, err = disp.Invoke(dispid[0], ole.DISPATCH_PROPERTYGET, params...) - } - - return -} - -// MustGetProperty retrieves property from IDispatch or panics. -func MustGetProperty(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT) { - r, err := GetProperty(disp, name, params...) - if err != nil { - panic(err.Error()) - } - return r -} - -// PutProperty mutates property. -func PutProperty(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT, err error) { - var dispid []int32 - dispid, err = disp.GetIDsOfName([]string{name}) - if err != nil { - return - } - - if len(params) < 1 { - result, err = disp.Invoke(dispid[0], ole.DISPATCH_PROPERTYPUT) - } else { - result, err = disp.Invoke(dispid[0], ole.DISPATCH_PROPERTYPUT, params...) - } - - return -} - -// MustPutProperty mutates property or panics. -func MustPutProperty(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT) { - r, err := PutProperty(disp, name, params...) - if err != nil { - panic(err.Error()) - } - return r -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/safearray.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/safearray.go deleted file mode 100644 index a5201b56c3d..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/safearray.go +++ /dev/null @@ -1,27 +0,0 @@ -// Package is meant to retrieve and process safe array data returned from COM. - -package ole - -// SafeArrayBound defines the SafeArray boundaries. -type SafeArrayBound struct { - Elements uint32 - LowerBound int32 -} - -// SafeArray is how COM handles arrays. -type SafeArray struct { - Dimensions uint16 - FeaturesFlag uint16 - ElementsSize uint32 - LocksAmount uint32 - Data uint32 - Bounds [16]byte -} - -// SAFEARRAY is obsolete, exists for backwards compatibility. -// Use SafeArray -type SAFEARRAY SafeArray - -// SAFEARRAYBOUND is obsolete, exists for backwards compatibility. -// Use SafeArrayBound -type SAFEARRAYBOUND SafeArrayBound diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/safearray_func.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/safearray_func.go deleted file mode 100644 index c261a0078c7..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/safearray_func.go +++ /dev/null @@ -1,207 +0,0 @@ -// +build !windows - -package ole - -// safeArrayAccessData returns raw array pointer. -// -// AKA: SafeArrayAccessData in Windows API. -func safeArrayAccessData(safearray *SafeArray) (uintptr, error) { - return uintptr(0), NewError(E_NOTIMPL) -} - -// safeArrayUnaccessData releases raw array. -// -// AKA: SafeArrayUnaccessData in Windows API. -func safeArrayUnaccessData(safearray *SafeArray) error { - return NewError(E_NOTIMPL) -} - -// safeArrayAllocData allocates SafeArray. -// -// AKA: SafeArrayAllocData in Windows API. -func safeArrayAllocData(safearray *SafeArray) error { - return NewError(E_NOTIMPL) -} - -// safeArrayAllocDescriptor allocates SafeArray. -// -// AKA: SafeArrayAllocDescriptor in Windows API. -func safeArrayAllocDescriptor(dimensions uint32) (*SafeArray, error) { - return nil, NewError(E_NOTIMPL) -} - -// safeArrayAllocDescriptorEx allocates SafeArray. -// -// AKA: SafeArrayAllocDescriptorEx in Windows API. -func safeArrayAllocDescriptorEx(variantType VT, dimensions uint32) (*SafeArray, error) { - return nil, NewError(E_NOTIMPL) -} - -// safeArrayCopy returns copy of SafeArray. -// -// AKA: SafeArrayCopy in Windows API. -func safeArrayCopy(original *SafeArray) (*SafeArray, error) { - return nil, NewError(E_NOTIMPL) -} - -// safeArrayCopyData duplicates SafeArray into another SafeArray object. -// -// AKA: SafeArrayCopyData in Windows API. -func safeArrayCopyData(original *SafeArray, duplicate *SafeArray) error { - return NewError(E_NOTIMPL) -} - -// safeArrayCreate creates SafeArray. -// -// AKA: SafeArrayCreate in Windows API. -func safeArrayCreate(variantType VT, dimensions uint32, bounds *SafeArrayBound) (*SafeArray, error) { - return nil, NewError(E_NOTIMPL) -} - -// safeArrayCreateEx creates SafeArray. -// -// AKA: SafeArrayCreateEx in Windows API. -func safeArrayCreateEx(variantType VT, dimensions uint32, bounds *SafeArrayBound, extra uintptr) (*SafeArray, error) { - return nil, NewError(E_NOTIMPL) -} - -// safeArrayCreateVector creates SafeArray. -// -// AKA: SafeArrayCreateVector in Windows API. -func safeArrayCreateVector(variantType VT, lowerBound int32, length uint32) (*SafeArray, error) { - return nil, NewError(E_NOTIMPL) -} - -// safeArrayCreateVectorEx creates SafeArray. -// -// AKA: SafeArrayCreateVectorEx in Windows API. -func safeArrayCreateVectorEx(variantType VT, lowerBound int32, length uint32, extra uintptr) (*SafeArray, error) { - return nil, NewError(E_NOTIMPL) -} - -// safeArrayDestroy destroys SafeArray object. -// -// AKA: SafeArrayDestroy in Windows API. -func safeArrayDestroy(safearray *SafeArray) error { - return NewError(E_NOTIMPL) -} - -// safeArrayDestroyData destroys SafeArray object. -// -// AKA: SafeArrayDestroyData in Windows API. -func safeArrayDestroyData(safearray *SafeArray) error { - return NewError(E_NOTIMPL) -} - -// safeArrayDestroyDescriptor destroys SafeArray object. -// -// AKA: SafeArrayDestroyDescriptor in Windows API. -func safeArrayDestroyDescriptor(safearray *SafeArray) error { - return NewError(E_NOTIMPL) -} - -// safeArrayGetDim is the amount of dimensions in the SafeArray. -// -// SafeArrays may have multiple dimensions. Meaning, it could be -// multidimensional array. -// -// AKA: SafeArrayGetDim in Windows API. -func safeArrayGetDim(safearray *SafeArray) (*uint32, error) { - u := uint32(0) - return &u, NewError(E_NOTIMPL) -} - -// safeArrayGetElementSize is the element size in bytes. -// -// AKA: SafeArrayGetElemsize in Windows API. -func safeArrayGetElementSize(safearray *SafeArray) (*uint32, error) { - u := uint32(0) - return &u, NewError(E_NOTIMPL) -} - -// safeArrayGetElement retrieves element at given index. -func safeArrayGetElement(safearray *SafeArray, index int64) (uintptr, error) { - return uintptr(0), NewError(E_NOTIMPL) -} - -// safeArrayGetElement retrieves element at given index and converts to string. -func safeArrayGetElementString(safearray *SafeArray, index int64) (string, error) { - return "", NewError(E_NOTIMPL) -} - -// safeArrayGetIID is the InterfaceID of the elements in the SafeArray. -// -// AKA: SafeArrayGetIID in Windows API. -func safeArrayGetIID(safearray *SafeArray) (*GUID, error) { - return nil, NewError(E_NOTIMPL) -} - -// safeArrayGetLBound returns lower bounds of SafeArray. -// -// SafeArrays may have multiple dimensions. Meaning, it could be -// multidimensional array. -// -// AKA: SafeArrayGetLBound in Windows API. -func safeArrayGetLBound(safearray *SafeArray, dimension uint32) (int64, error) { - return int64(0), NewError(E_NOTIMPL) -} - -// safeArrayGetUBound returns upper bounds of SafeArray. -// -// SafeArrays may have multiple dimensions. Meaning, it could be -// multidimensional array. -// -// AKA: SafeArrayGetUBound in Windows API. -func safeArrayGetUBound(safearray *SafeArray, dimension uint32) (int64, error) { - return int64(0), NewError(E_NOTIMPL) -} - -// safeArrayGetVartype returns data type of SafeArray. -// -// AKA: SafeArrayGetVartype in Windows API. -func safeArrayGetVartype(safearray *SafeArray) (uint16, error) { - return uint16(0), NewError(E_NOTIMPL) -} - -// safeArrayLock locks SafeArray for reading to modify SafeArray. -// -// This must be called during some calls to ensure that another process does not -// read or write to the SafeArray during editing. -// -// AKA: SafeArrayLock in Windows API. -func safeArrayLock(safearray *SafeArray) error { - return NewError(E_NOTIMPL) -} - -// safeArrayUnlock unlocks SafeArray for reading. -// -// AKA: SafeArrayUnlock in Windows API. -func safeArrayUnlock(safearray *SafeArray) error { - return NewError(E_NOTIMPL) -} - -// safeArrayPutElement stores the data element at the specified location in the -// array. -// -// AKA: SafeArrayPutElement in Windows API. -func safeArrayPutElement(safearray *SafeArray, index int64, element uintptr) error { - return NewError(E_NOTIMPL) -} - -// safeArrayGetRecordInfo accesses IRecordInfo info for custom types. -// -// AKA: SafeArrayGetRecordInfo in Windows API. -// -// XXX: Must implement IRecordInfo interface for this to return. -func safeArrayGetRecordInfo(safearray *SafeArray) (interface{}, error) { - return nil, NewError(E_NOTIMPL) -} - -// safeArraySetRecordInfo mutates IRecordInfo info for custom types. -// -// AKA: SafeArraySetRecordInfo in Windows API. -// -// XXX: Must implement IRecordInfo interface for this to return. -func safeArraySetRecordInfo(safearray *SafeArray, recordInfo interface{}) error { - return NewError(E_NOTIMPL) -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/safearray_test.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/safearray_test.go deleted file mode 100644 index 31409cec068..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/safearray_test.go +++ /dev/null @@ -1,108 +0,0 @@ -package ole - -// This tests more than one function. It tests all of the functions needed in -// order to retrieve an SafeArray populated with Strings. -func Example_safeArrayGetElementString() { - CoInitialize(0) - defer CoUninitialize() - - clsid, err := CLSIDFromProgID("QBXMLRP2.RequestProcessor.1") - if err != nil { - if err.(*OleError).Code() == CO_E_CLASSSTRING { - return - } - } - - unknown, err := CreateInstance(clsid, IID_IUnknown) - if err != nil { - return - } - defer unknown.Release() - - dispatch, err := unknown.QueryInterface(IID_IDispatch) - if err != nil { - return - } - - var dispid []int32 - dispid, err = dispatch.GetIDsOfName([]string{"OpenConnection2"}) - if err != nil { - return - } - - var result *VARIANT - _, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD, "", "Test Application 1", 1) - if err != nil { - return - } - - dispid, err = dispatch.GetIDsOfName([]string{"BeginSession"}) - if err != nil { - return - } - - result, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD, "", 2) - if err != nil { - return - } - - ticket := result.ToString() - - dispid, err = dispatch.GetIDsOfName([]string{"QBXMLVersionsForSession"}) - if err != nil { - return - } - - result, err = dispatch.Invoke(dispid[0], DISPATCH_PROPERTYGET, ticket) - if err != nil { - return - } - - // Where the real tests begin. - var qbXMLVersions *SafeArray - var qbXmlVersionStrings []string - qbXMLVersions = result.ToArray().Array - - // Get array bounds - var LowerBounds int64 - var UpperBounds int64 - LowerBounds, err = safeArrayGetLBound(qbXMLVersions, 1) - if err != nil { - return - } - - UpperBounds, err = safeArrayGetUBound(qbXMLVersions, 1) - if err != nil { - return - } - - totalElements := UpperBounds - LowerBounds + 1 - qbXmlVersionStrings = make([]string, totalElements) - - for i := int64(0); i < totalElements; i++ { - qbXmlVersionStrings[int32(i)], _ = safeArrayGetElementString(qbXMLVersions, i) - } - - // Release Safe Array memory - safeArrayDestroy(qbXMLVersions) - - dispid, err = dispatch.GetIDsOfName([]string{"EndSession"}) - if err != nil { - return - } - - _, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD, ticket) - if err != nil { - return - } - - dispid, err = dispatch.GetIDsOfName([]string{"CloseConnection"}) - if err != nil { - return - } - - _, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD) - if err != nil { - return - } -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/safearray_windows.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/safearray_windows.go deleted file mode 100644 index 593947b8494..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/safearray_windows.go +++ /dev/null @@ -1,338 +0,0 @@ -// +build windows - -package ole - -import ( - "unsafe" -) - -var ( - procSafeArrayAccessData, _ = modoleaut32.FindProc("SafeArrayAccessData") - procSafeArrayAllocData, _ = modoleaut32.FindProc("SafeArrayAllocData") - procSafeArrayAllocDescriptor, _ = modoleaut32.FindProc("SafeArrayAllocDescriptor") - procSafeArrayAllocDescriptorEx, _ = modoleaut32.FindProc("SafeArrayAllocDescriptorEx") - procSafeArrayCopy, _ = modoleaut32.FindProc("SafeArrayCopy") - procSafeArrayCopyData, _ = modoleaut32.FindProc("SafeArrayCopyData") - procSafeArrayCreate, _ = modoleaut32.FindProc("SafeArrayCreate") - procSafeArrayCreateEx, _ = modoleaut32.FindProc("SafeArrayCreateEx") - procSafeArrayCreateVector, _ = modoleaut32.FindProc("SafeArrayCreateVector") - procSafeArrayCreateVectorEx, _ = modoleaut32.FindProc("SafeArrayCreateVectorEx") - procSafeArrayDestroy, _ = modoleaut32.FindProc("SafeArrayDestroy") - procSafeArrayDestroyData, _ = modoleaut32.FindProc("SafeArrayDestroyData") - procSafeArrayDestroyDescriptor, _ = modoleaut32.FindProc("SafeArrayDestroyDescriptor") - procSafeArrayGetDim, _ = modoleaut32.FindProc("SafeArrayGetDim") - procSafeArrayGetElement, _ = modoleaut32.FindProc("SafeArrayGetElement") - procSafeArrayGetElemsize, _ = modoleaut32.FindProc("SafeArrayGetElemsize") - procSafeArrayGetIID, _ = modoleaut32.FindProc("SafeArrayGetIID") - procSafeArrayGetLBound, _ = modoleaut32.FindProc("SafeArrayGetLBound") - procSafeArrayGetUBound, _ = modoleaut32.FindProc("SafeArrayGetUBound") - procSafeArrayGetVartype, _ = modoleaut32.FindProc("SafeArrayGetVartype") - procSafeArrayLock, _ = modoleaut32.FindProc("SafeArrayLock") - procSafeArrayPtrOfIndex, _ = modoleaut32.FindProc("SafeArrayPtrOfIndex") - procSafeArrayUnaccessData, _ = modoleaut32.FindProc("SafeArrayUnaccessData") - procSafeArrayUnlock, _ = modoleaut32.FindProc("SafeArrayUnlock") - procSafeArrayPutElement, _ = modoleaut32.FindProc("SafeArrayPutElement") - //procSafeArrayRedim, _ = modoleaut32.FindProc("SafeArrayRedim") // TODO - //procSafeArraySetIID, _ = modoleaut32.FindProc("SafeArraySetIID") // TODO - procSafeArrayGetRecordInfo, _ = modoleaut32.FindProc("SafeArrayGetRecordInfo") - procSafeArraySetRecordInfo, _ = modoleaut32.FindProc("SafeArraySetRecordInfo") -) - -// safeArrayAccessData returns raw array pointer. -// -// AKA: SafeArrayAccessData in Windows API. -// Todo: Test -func safeArrayAccessData(safearray *SafeArray) (element uintptr, err error) { - err = convertHresultToError( - procSafeArrayAccessData.Call( - uintptr(unsafe.Pointer(safearray)), - uintptr(unsafe.Pointer(&element)))) - return -} - -// safeArrayUnaccessData releases raw array. -// -// AKA: SafeArrayUnaccessData in Windows API. -func safeArrayUnaccessData(safearray *SafeArray) (err error) { - err = convertHresultToError(procSafeArrayUnaccessData.Call(uintptr(unsafe.Pointer(safearray)))) - return -} - -// safeArrayAllocData allocates SafeArray. -// -// AKA: SafeArrayAllocData in Windows API. -func safeArrayAllocData(safearray *SafeArray) (err error) { - err = convertHresultToError(procSafeArrayAllocData.Call(uintptr(unsafe.Pointer(safearray)))) - return -} - -// safeArrayAllocDescriptor allocates SafeArray. -// -// AKA: SafeArrayAllocDescriptor in Windows API. -func safeArrayAllocDescriptor(dimensions uint32) (safearray *SafeArray, err error) { - err = convertHresultToError( - procSafeArrayAllocDescriptor.Call(uintptr(dimensions), uintptr(unsafe.Pointer(&safearray)))) - return -} - -// safeArrayAllocDescriptorEx allocates SafeArray. -// -// AKA: SafeArrayAllocDescriptorEx in Windows API. -func safeArrayAllocDescriptorEx(variantType VT, dimensions uint32) (safearray *SafeArray, err error) { - err = convertHresultToError( - procSafeArrayAllocDescriptorEx.Call( - uintptr(variantType), - uintptr(dimensions), - uintptr(unsafe.Pointer(&safearray)))) - return -} - -// safeArrayCopy returns copy of SafeArray. -// -// AKA: SafeArrayCopy in Windows API. -func safeArrayCopy(original *SafeArray) (safearray *SafeArray, err error) { - err = convertHresultToError( - procSafeArrayCopy.Call( - uintptr(unsafe.Pointer(original)), - uintptr(unsafe.Pointer(&safearray)))) - return -} - -// safeArrayCopyData duplicates SafeArray into another SafeArray object. -// -// AKA: SafeArrayCopyData in Windows API. -func safeArrayCopyData(original *SafeArray, duplicate *SafeArray) (err error) { - err = convertHresultToError( - procSafeArrayCopyData.Call( - uintptr(unsafe.Pointer(original)), - uintptr(unsafe.Pointer(duplicate)))) - return -} - -// safeArrayCreate creates SafeArray. -// -// AKA: SafeArrayCreate in Windows API. -func safeArrayCreate(variantType VT, dimensions uint32, bounds *SafeArrayBound) (safearray *SafeArray, err error) { - sa, _, err := procSafeArrayCreate.Call( - uintptr(variantType), - uintptr(dimensions), - uintptr(unsafe.Pointer(bounds))) - safearray = (*SafeArray)(unsafe.Pointer(&sa)) - return -} - -// safeArrayCreateEx creates SafeArray. -// -// AKA: SafeArrayCreateEx in Windows API. -func safeArrayCreateEx(variantType VT, dimensions uint32, bounds *SafeArrayBound, extra uintptr) (safearray *SafeArray, err error) { - sa, _, err := procSafeArrayCreateEx.Call( - uintptr(variantType), - uintptr(dimensions), - uintptr(unsafe.Pointer(bounds)), - extra) - safearray = (*SafeArray)(unsafe.Pointer(sa)) - return -} - -// safeArrayCreateVector creates SafeArray. -// -// AKA: SafeArrayCreateVector in Windows API. -func safeArrayCreateVector(variantType VT, lowerBound int32, length uint32) (safearray *SafeArray, err error) { - sa, _, err := procSafeArrayCreateVector.Call( - uintptr(variantType), - uintptr(lowerBound), - uintptr(length)) - safearray = (*SafeArray)(unsafe.Pointer(sa)) - return -} - -// safeArrayCreateVectorEx creates SafeArray. -// -// AKA: SafeArrayCreateVectorEx in Windows API. -func safeArrayCreateVectorEx(variantType VT, lowerBound int32, length uint32, extra uintptr) (safearray *SafeArray, err error) { - sa, _, err := procSafeArrayCreateVectorEx.Call( - uintptr(variantType), - uintptr(lowerBound), - uintptr(length), - extra) - safearray = (*SafeArray)(unsafe.Pointer(sa)) - return -} - -// safeArrayDestroy destroys SafeArray object. -// -// AKA: SafeArrayDestroy in Windows API. -func safeArrayDestroy(safearray *SafeArray) (err error) { - err = convertHresultToError(procSafeArrayDestroy.Call(uintptr(unsafe.Pointer(safearray)))) - return -} - -// safeArrayDestroyData destroys SafeArray object. -// -// AKA: SafeArrayDestroyData in Windows API. -func safeArrayDestroyData(safearray *SafeArray) (err error) { - err = convertHresultToError(procSafeArrayDestroyData.Call(uintptr(unsafe.Pointer(safearray)))) - return -} - -// safeArrayDestroyDescriptor destroys SafeArray object. -// -// AKA: SafeArrayDestroyDescriptor in Windows API. -func safeArrayDestroyDescriptor(safearray *SafeArray) (err error) { - err = convertHresultToError(procSafeArrayDestroyDescriptor.Call(uintptr(unsafe.Pointer(safearray)))) - return -} - -// safeArrayGetDim is the amount of dimensions in the SafeArray. -// -// SafeArrays may have multiple dimensions. Meaning, it could be -// multidimensional array. -// -// AKA: SafeArrayGetDim in Windows API. -func safeArrayGetDim(safearray *SafeArray) (dimensions *uint32, err error) { - l, _, err := procSafeArrayGetDim.Call(uintptr(unsafe.Pointer(safearray))) - dimensions = (*uint32)(unsafe.Pointer(l)) - return -} - -// safeArrayGetElementSize is the element size in bytes. -// -// AKA: SafeArrayGetElemsize in Windows API. -func safeArrayGetElementSize(safearray *SafeArray) (length *uint32, err error) { - l, _, err := procSafeArrayGetElemsize.Call(uintptr(unsafe.Pointer(safearray))) - length = (*uint32)(unsafe.Pointer(l)) - return -} - -// safeArrayGetElement retrieves element at given index. -func safeArrayGetElement(safearray *SafeArray, index int64) (element uintptr, err error) { - err = convertHresultToError( - procSafeArrayGetElement.Call( - uintptr(unsafe.Pointer(safearray)), - uintptr(unsafe.Pointer(&index)), - uintptr(unsafe.Pointer(&element)))) - return -} - -// safeArrayGetElement retrieves element at given index and converts to string. -func safeArrayGetElementString(safearray *SafeArray, index int64) (str string, err error) { - var element *int16 - err = convertHresultToError( - procSafeArrayGetElement.Call( - uintptr(unsafe.Pointer(safearray)), - uintptr(unsafe.Pointer(&index)), - uintptr(unsafe.Pointer(&element)))) - str = BstrToString(*(**uint16)(unsafe.Pointer(&element))) - SysFreeString(element) - return -} - -// safeArrayGetIID is the InterfaceID of the elements in the SafeArray. -// -// AKA: SafeArrayGetIID in Windows API. -func safeArrayGetIID(safearray *SafeArray) (guid *GUID, err error) { - err = convertHresultToError( - procSafeArrayGetIID.Call( - uintptr(unsafe.Pointer(safearray)), - uintptr(unsafe.Pointer(&guid)))) - return -} - -// safeArrayGetLBound returns lower bounds of SafeArray. -// -// SafeArrays may have multiple dimensions. Meaning, it could be -// multidimensional array. -// -// AKA: SafeArrayGetLBound in Windows API. -func safeArrayGetLBound(safearray *SafeArray, dimension uint32) (lowerBound int64, err error) { - err = convertHresultToError( - procSafeArrayGetLBound.Call( - uintptr(unsafe.Pointer(safearray)), - uintptr(dimension), - uintptr(unsafe.Pointer(&lowerBound)))) - return -} - -// safeArrayGetUBound returns upper bounds of SafeArray. -// -// SafeArrays may have multiple dimensions. Meaning, it could be -// multidimensional array. -// -// AKA: SafeArrayGetUBound in Windows API. -func safeArrayGetUBound(safearray *SafeArray, dimension uint32) (upperBound int64, err error) { - err = convertHresultToError( - procSafeArrayGetUBound.Call( - uintptr(unsafe.Pointer(safearray)), - uintptr(dimension), - uintptr(unsafe.Pointer(&upperBound)))) - return -} - -// safeArrayGetVartype returns data type of SafeArray. -// -// AKA: SafeArrayGetVartype in Windows API. -func safeArrayGetVartype(safearray *SafeArray) (varType uint16, err error) { - err = convertHresultToError( - procSafeArrayGetVartype.Call( - uintptr(unsafe.Pointer(safearray)), - uintptr(unsafe.Pointer(&varType)))) - return -} - -// safeArrayLock locks SafeArray for reading to modify SafeArray. -// -// This must be called during some calls to ensure that another process does not -// read or write to the SafeArray during editing. -// -// AKA: SafeArrayLock in Windows API. -func safeArrayLock(safearray *SafeArray) (err error) { - err = convertHresultToError(procSafeArrayLock.Call(uintptr(unsafe.Pointer(safearray)))) - return -} - -// safeArrayUnlock unlocks SafeArray for reading. -// -// AKA: SafeArrayUnlock in Windows API. -func safeArrayUnlock(safearray *SafeArray) (err error) { - err = convertHresultToError(procSafeArrayUnlock.Call(uintptr(unsafe.Pointer(safearray)))) - return -} - -// safeArrayPutElement stores the data element at the specified location in the -// array. -// -// AKA: SafeArrayPutElement in Windows API. -func safeArrayPutElement(safearray *SafeArray, index int64, element uintptr) (err error) { - err = convertHresultToError( - procSafeArrayPutElement.Call( - uintptr(unsafe.Pointer(safearray)), - uintptr(unsafe.Pointer(&index)), - uintptr(unsafe.Pointer(element)))) - return -} - -// safeArrayGetRecordInfo accesses IRecordInfo info for custom types. -// -// AKA: SafeArrayGetRecordInfo in Windows API. -// -// XXX: Must implement IRecordInfo interface for this to return. -func safeArrayGetRecordInfo(safearray *SafeArray) (recordInfo interface{}, err error) { - err = convertHresultToError( - procSafeArrayGetRecordInfo.Call( - uintptr(unsafe.Pointer(safearray)), - uintptr(unsafe.Pointer(&recordInfo)))) - return -} - -// safeArraySetRecordInfo mutates IRecordInfo info for custom types. -// -// AKA: SafeArraySetRecordInfo in Windows API. -// -// XXX: Must implement IRecordInfo interface for this to return. -func safeArraySetRecordInfo(safearray *SafeArray, recordInfo interface{}) (err error) { - err = convertHresultToError( - procSafeArraySetRecordInfo.Call( - uintptr(unsafe.Pointer(safearray)), - uintptr(unsafe.Pointer(&recordInfo)))) - return -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/safearrayconversion.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/safearrayconversion.go deleted file mode 100644 index c7f0ce540c7..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/safearrayconversion.go +++ /dev/null @@ -1,72 +0,0 @@ -// Helper for converting SafeArray to array of objects. - -package ole - -import "unsafe" - -type SafeArrayConversion struct { - Array *SafeArray -} - -func (sac *SafeArrayConversion) ToStringArray() (strings []string) { - totalElements, _ := sac.TotalElements(0) - strings = make([]string, totalElements) - - for i := int64(0); i < totalElements; i++ { - strings[int32(i)], _ = safeArrayGetElementString(sac.Array, i) - } - - return -} - -func (sac *SafeArrayConversion) ToByteArray() (bytes []byte) { - totalElements, _ := sac.TotalElements(0) - bytes = make([]byte, totalElements) - - for i := int64(0); i < totalElements; i++ { - ptr, _ := safeArrayGetElement(sac.Array, i) - bytes[int32(i)] = *(*byte)(unsafe.Pointer(&ptr)) - } - - return -} - -func (sac *SafeArrayConversion) GetType() (varType uint16, err error) { - return safeArrayGetVartype(sac.Array) -} - -func (sac *SafeArrayConversion) GetDimensions() (dimensions *uint32, err error) { - return safeArrayGetDim(sac.Array) -} - -func (sac *SafeArrayConversion) GetSize() (length *uint32, err error) { - return safeArrayGetElementSize(sac.Array) -} - -func (sac *SafeArrayConversion) TotalElements(index uint32) (totalElements int64, err error) { - if index < 1 { - index = 1 - } - - // Get array bounds - var LowerBounds int64 - var UpperBounds int64 - - LowerBounds, err = safeArrayGetLBound(sac.Array, index) - if err != nil { - return - } - - UpperBounds, err = safeArrayGetUBound(sac.Array, index) - if err != nil { - return - } - - totalElements = UpperBounds - LowerBounds + 1 - return -} - -// Release Safe Array memory -func (sac *SafeArrayConversion) Release() { - safeArrayDestroy(sac.Array) -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/safearrayconversion_test.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/safearrayconversion_test.go deleted file mode 100644 index 302a9acf21d..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/safearrayconversion_test.go +++ /dev/null @@ -1,119 +0,0 @@ -// +build windows - -package ole - -import ( - "fmt" - "strings" - "testing" -) - -// This tests more than one function. It tests all of the functions needed in order to retrieve an -// SafeArray populated with Strings. -func TestSafeArrayConversionString(t *testing.T) { - CoInitialize(0) - defer CoUninitialize() - - clsid, err := CLSIDFromProgID("QBXMLRP2.RequestProcessor.1") - if err != nil { - if err.(*OleError).Code() == CO_E_CLASSSTRING { - return - } - t.Log(err) - t.FailNow() - } - - unknown, err := CreateInstance(clsid, IID_IUnknown) - if err != nil { - t.Log(err) - t.FailNow() - } - defer unknown.Release() - - dispatch, err := unknown.QueryInterface(IID_IDispatch) - if err != nil { - t.Log(err) - t.FailNow() - } - - var dispid []int32 - dispid, err = dispatch.GetIDsOfName([]string{"OpenConnection2"}) - if err != nil { - t.Log(err) - t.FailNow() - } - - var result *VARIANT - _, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD, "", "Test Application 1", 1) - if err != nil { - t.Log(err) - t.FailNow() - } - - dispid, err = dispatch.GetIDsOfName([]string{"BeginSession"}) - if err != nil { - t.Log(err) - t.FailNow() - } - - result, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD, "", 2) - if err != nil { - t.Log(err) - t.FailNow() - } - - ticket := result.ToString() - - dispid, err = dispatch.GetIDsOfName([]string{"QBXMLVersionsForSession"}) - if err != nil { - t.Log(err) - t.FailNow() - } - - result, err = dispatch.Invoke(dispid[0], DISPATCH_PROPERTYGET, ticket) - if err != nil { - t.Log(err) - t.FailNow() - } - - // Where the real tests begin. - conversion := result.ToArray() - - totalElements, _ := conversion.TotalElements(0) - if totalElements != 13 { - t.Log(fmt.Sprintf("%d total elements does not equal 13\n", totalElements)) - t.Fail() - } - - versions := conversion.ToStringArray() - if len(versions) != 13 { - t.Log(fmt.Sprintf("%s\n", strings.Join(versions, ", "))) - t.Fail() - } - - conversion.Release() - - dispid, err = dispatch.GetIDsOfName([]string{"EndSession"}) - if err != nil { - t.Log(err) - t.FailNow() - } - - _, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD, ticket) - if err != nil { - t.Log(err) - t.FailNow() - } - - dispid, err = dispatch.GetIDsOfName([]string{"CloseConnection"}) - if err != nil { - t.Log(err) - t.FailNow() - } - - _, err = dispatch.Invoke(dispid[0], DISPATCH_METHOD) - if err != nil { - t.Log(err) - t.FailNow() - } -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/safearrayslices.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/safearrayslices.go deleted file mode 100644 index a9fa885f1d8..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/safearrayslices.go +++ /dev/null @@ -1,33 +0,0 @@ -// +build windows - -package ole - -import ( - "unsafe" -) - -func safeArrayFromByteSlice(slice []byte) *SafeArray { - array, _ := safeArrayCreateVector(VT_UI1, 0, uint32(len(slice))) - - if array == nil { - panic("Could not convert []byte to SAFEARRAY") - } - - for i, v := range slice { - safeArrayPutElement(array, int64(i), uintptr(unsafe.Pointer(&v))) - } - return array -} - -func safeArrayFromStringSlice(slice []string) *SafeArray { - array, _ := safeArrayCreateVector(VT_BSTR, 0, uint32(len(slice))) - - if array == nil { - panic("Could not convert []string to SAFEARRAY") - } - // SysAllocStringLen(s) - for i, v := range slice { - safeArrayPutElement(array, int64(i), uintptr(unsafe.Pointer(SysAllocStringLen(v)))) - } - return array -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/utility.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/utility.go deleted file mode 100644 index 2c27235876b..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/utility.go +++ /dev/null @@ -1,85 +0,0 @@ -package ole - -import ( - "unicode/utf16" - "unsafe" -) - -// BytePtrToString converts byte pointer to a Go string. -func BytePtrToString(p *byte) string { - a := (*[10000]uint8)(unsafe.Pointer(p)) - i := 0 - for a[i] != 0 { - i++ - } - return string(a[:i]) -} - -// UTF16PtrToString is alias for LpOleStrToString. -// -// Kept for compatibility reasons. -func UTF16PtrToString(p *uint16) string { - return LpOleStrToString(p) -} - -// LpOleStrToString converts COM Unicode to Go string. -func LpOleStrToString(p *uint16) string { - if p == nil { - return "" - } - - length := lpOleStrLen(p) - a := make([]uint16, length) - - ptr := unsafe.Pointer(p) - - for i := 0; i < int(length); i++ { - a[i] = *(*uint16)(ptr) - ptr = unsafe.Pointer(uintptr(ptr) + 2) - } - - return string(utf16.Decode(a)) -} - -// BstrToString converts COM binary string to Go string. -func BstrToString(p *uint16) string { - if p == nil { - return "" - } - length := SysStringLen((*int16)(unsafe.Pointer(p))) - a := make([]uint16, length) - - ptr := unsafe.Pointer(p) - - for i := 0; i < int(length); i++ { - a[i] = *(*uint16)(ptr) - ptr = unsafe.Pointer(uintptr(ptr) + 2) - } - return string(utf16.Decode(a)) -} - -// lpOleStrLen returns the length of Unicode string. -func lpOleStrLen(p *uint16) (length int64) { - if p == nil { - return 0 - } - - ptr := unsafe.Pointer(p) - - for i := 0; ; i++ { - if 0 == *(*uint16)(ptr) { - length = int64(i) - break - } - ptr = unsafe.Pointer(uintptr(ptr) + 2) - } - return -} - -// convertHresultToError converts syscall to error, if call is unsuccessful. -func convertHresultToError(hr uintptr, r2 uintptr, ignore error) (err error) { - if hr != 0 { - err = NewError(hr) - } - return -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/variables.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/variables.go deleted file mode 100644 index ebe00f1cfc9..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/variables.go +++ /dev/null @@ -1,16 +0,0 @@ -// +build windows - -package ole - -import ( - "syscall" -) - -var ( - modcombase = syscall.NewLazyDLL("combase.dll") - modkernel32, _ = syscall.LoadDLL("kernel32.dll") - modole32, _ = syscall.LoadDLL("ole32.dll") - modoleaut32, _ = syscall.LoadDLL("oleaut32.dll") - modmsvcrt, _ = syscall.LoadDLL("msvcrt.dll") - moduser32, _ = syscall.LoadDLL("user32.dll") -) diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/variant.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/variant.go deleted file mode 100644 index 62b47fb772f..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/variant.go +++ /dev/null @@ -1,101 +0,0 @@ -package ole - -import "unsafe" - -// NewVariant returns new variant based on type and value. -func NewVariant(vt VT, val int64) VARIANT { - return VARIANT{VT: vt, Val: val} -} - -// ToIUnknown converts Variant to Unknown object. -func (v *VARIANT) ToIUnknown() *IUnknown { - if v.VT != VT_UNKNOWN { - return nil - } - return (*IUnknown)(unsafe.Pointer(uintptr(v.Val))) -} - -// ToIDispatch converts variant to dispatch object. -func (v *VARIANT) ToIDispatch() *IDispatch { - if v.VT != VT_DISPATCH { - return nil - } - return (*IDispatch)(unsafe.Pointer(uintptr(v.Val))) -} - -// ToArray converts variant to SafeArray helper. -func (v *VARIANT) ToArray() *SafeArrayConversion { - if v.VT != VT_SAFEARRAY { - return nil - } - var safeArray *SafeArray = (*SafeArray)(unsafe.Pointer(uintptr(v.Val))) - return &SafeArrayConversion{safeArray} -} - -// ToString converts variant to Go string. -func (v *VARIANT) ToString() string { - if v.VT != VT_BSTR { - return "" - } - return BstrToString(*(**uint16)(unsafe.Pointer(&v.Val))) -} - -// Clear the memory of variant object. -func (v *VARIANT) Clear() error { - return VariantClear(v) -} - -// Value returns variant value based on its type. -// -// Currently supported types: 2- and 4-byte integers, strings, bools. -// Note that 64-bit integers, datetimes, and other types are stored as strings -// and will be returned as strings. -// -// Needs to be further converted, because this returns an interface{}. -func (v *VARIANT) Value() interface{} { - switch v.VT { - case VT_I1: - return int8(v.Val) - case VT_UI1: - return uint8(v.Val) - case VT_I2: - return int16(v.Val) - case VT_UI2: - return uint16(v.Val) - case VT_I4: - return int32(v.Val) - case VT_UINT: - return uint32(v.Val) - case VT_INT_PTR: - return uintptr(v.Val) // TODO - case VT_UINT_PTR: - return uintptr(v.Val) - case VT_UI4: - return uint32(v.Val) - case VT_I8: - return int64(v.Val) - case VT_UI8: - return uint64(v.Val) - case VT_R4: - return float32(v.Val) - case VT_R8: - return float64(v.Val) - case VT_BSTR: - return v.ToString() - case VT_DATE: - // VT_DATE type will either return float64 or time.Time. - d := float64(v.Val) - date, err := GetVariantDate(d) - if err != nil { - return d - } - return date - case VT_UNKNOWN: - return v.ToIUnknown() - case VT_DISPATCH: - return v.ToIDispatch() - case VT_BOOL: - return v.Val != 0 - } - return nil -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/variant_386.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/variant_386.go deleted file mode 100644 index e73736bf391..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/variant_386.go +++ /dev/null @@ -1,11 +0,0 @@ -// +build 386 - -package ole - -type VARIANT struct { - VT VT // 2 - wReserved1 uint16 // 4 - wReserved2 uint16 // 6 - wReserved3 uint16 // 8 - Val int64 // 16 -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/variant_amd64.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/variant_amd64.go deleted file mode 100644 index dccdde13233..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/variant_amd64.go +++ /dev/null @@ -1,12 +0,0 @@ -// +build amd64 - -package ole - -type VARIANT struct { - VT VT // 2 - wReserved1 uint16 // 4 - wReserved2 uint16 // 6 - wReserved3 uint16 // 8 - Val int64 // 16 - _ [8]byte // 24 -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/vt_string.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/vt_string.go deleted file mode 100644 index 729b4a04dd9..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/vt_string.go +++ /dev/null @@ -1,58 +0,0 @@ -// generated by stringer -output vt_string.go -type VT; DO NOT EDIT - -package ole - -import "fmt" - -const ( - _VT_name_0 = "VT_EMPTYVT_NULLVT_I2VT_I4VT_R4VT_R8VT_CYVT_DATEVT_BSTRVT_DISPATCHVT_ERRORVT_BOOLVT_VARIANTVT_UNKNOWNVT_DECIMAL" - _VT_name_1 = "VT_I1VT_UI1VT_UI2VT_UI4VT_I8VT_UI8VT_INTVT_UINTVT_VOIDVT_HRESULTVT_PTRVT_SAFEARRAYVT_CARRAYVT_USERDEFINEDVT_LPSTRVT_LPWSTR" - _VT_name_2 = "VT_RECORDVT_INT_PTRVT_UINT_PTR" - _VT_name_3 = "VT_FILETIMEVT_BLOBVT_STREAMVT_STORAGEVT_STREAMED_OBJECTVT_STORED_OBJECTVT_BLOB_OBJECTVT_CFVT_CLSID" - _VT_name_4 = "VT_BSTR_BLOBVT_VECTOR" - _VT_name_5 = "VT_ARRAY" - _VT_name_6 = "VT_BYREF" - _VT_name_7 = "VT_RESERVED" - _VT_name_8 = "VT_ILLEGAL" -) - -var ( - _VT_index_0 = [...]uint8{0, 8, 15, 20, 25, 30, 35, 40, 47, 54, 65, 73, 80, 90, 100, 110} - _VT_index_1 = [...]uint8{0, 5, 11, 17, 23, 28, 34, 40, 47, 54, 64, 70, 82, 91, 105, 113, 122} - _VT_index_2 = [...]uint8{0, 9, 19, 30} - _VT_index_3 = [...]uint8{0, 11, 18, 27, 37, 55, 71, 85, 90, 98} - _VT_index_4 = [...]uint8{0, 12, 21} - _VT_index_5 = [...]uint8{0, 8} - _VT_index_6 = [...]uint8{0, 8} - _VT_index_7 = [...]uint8{0, 11} - _VT_index_8 = [...]uint8{0, 10} -) - -func (i VT) String() string { - switch { - case 0 <= i && i <= 14: - return _VT_name_0[_VT_index_0[i]:_VT_index_0[i+1]] - case 16 <= i && i <= 31: - i -= 16 - return _VT_name_1[_VT_index_1[i]:_VT_index_1[i+1]] - case 36 <= i && i <= 38: - i -= 36 - return _VT_name_2[_VT_index_2[i]:_VT_index_2[i+1]] - case 64 <= i && i <= 72: - i -= 64 - return _VT_name_3[_VT_index_3[i]:_VT_index_3[i+1]] - case 4095 <= i && i <= 4096: - i -= 4095 - return _VT_name_4[_VT_index_4[i]:_VT_index_4[i+1]] - case i == 8192: - return _VT_name_5 - case i == 16384: - return _VT_name_6 - case i == 32768: - return _VT_name_7 - case i == 65535: - return _VT_name_8 - default: - return fmt.Sprintf("VT(%d)", i) - } -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/winrt.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/winrt.go deleted file mode 100644 index 4e9eca73244..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/winrt.go +++ /dev/null @@ -1,99 +0,0 @@ -// +build windows - -package ole - -import ( - "reflect" - "syscall" - "unicode/utf8" - "unsafe" -) - -var ( - procRoInitialize = modcombase.NewProc("RoInitialize") - procRoActivateInstance = modcombase.NewProc("RoActivateInstance") - procRoGetActivationFactory = modcombase.NewProc("RoGetActivationFactory") - procWindowsCreateString = modcombase.NewProc("WindowsCreateString") - procWindowsDeleteString = modcombase.NewProc("WindowsDeleteString") - procWindowsGetStringRawBuffer = modcombase.NewProc("WindowsGetStringRawBuffer") -) - -func RoInitialize(thread_type uint32) (err error) { - hr, _, _ := procRoInitialize.Call(uintptr(thread_type)) - if hr != 0 { - err = NewError(hr) - } - return -} - -func RoActivateInstance(clsid string) (ins *IInspectable, err error) { - hClsid, err := NewHString(clsid) - if err != nil { - return nil, err - } - defer DeleteHString(hClsid) - - hr, _, _ := procRoActivateInstance.Call( - uintptr(unsafe.Pointer(hClsid)), - uintptr(unsafe.Pointer(&ins))) - if hr != 0 { - err = NewError(hr) - } - return -} - -func RoGetActivationFactory(clsid string, iid *GUID) (ins *IInspectable, err error) { - hClsid, err := NewHString(clsid) - if err != nil { - return nil, err - } - defer DeleteHString(hClsid) - - hr, _, _ := procRoGetActivationFactory.Call( - uintptr(unsafe.Pointer(hClsid)), - uintptr(unsafe.Pointer(iid)), - uintptr(unsafe.Pointer(&ins))) - if hr != 0 { - err = NewError(hr) - } - return -} - -// HString is handle string for pointers. -type HString uintptr - -// NewHString returns a new HString for Go string. -func NewHString(s string) (hstring HString, err error) { - u16 := syscall.StringToUTF16Ptr(s) - len := uint32(utf8.RuneCountInString(s)) - hr, _, _ := procWindowsCreateString.Call( - uintptr(unsafe.Pointer(u16)), - uintptr(len), - uintptr(unsafe.Pointer(&hstring))) - if hr != 0 { - err = NewError(hr) - } - return -} - -// DeleteHString deletes HString. -func DeleteHString(hstring HString) (err error) { - hr, _, _ := procWindowsDeleteString.Call(uintptr(hstring)) - if hr != 0 { - err = NewError(hr) - } - return -} - -// String returns Go string value of HString. -func (h HString) String() string { - var u16buf uintptr - var u16len uint32 - u16buf, _, _ = procWindowsGetStringRawBuffer.Call( - uintptr(h), - uintptr(unsafe.Pointer(&u16len))) - - u16hdr := reflect.SliceHeader{Data: u16buf, Len: int(u16len), Cap: int(u16len)} - u16 := *(*[]uint16)(unsafe.Pointer(&u16hdr)) - return syscall.UTF16ToString(u16) -} diff --git a/Godeps/_workspace/src/github.com/go-ole/go-ole/winrt_doc.go b/Godeps/_workspace/src/github.com/go-ole/go-ole/winrt_doc.go deleted file mode 100644 index 52e6d74c9ab..00000000000 --- a/Godeps/_workspace/src/github.com/go-ole/go-ole/winrt_doc.go +++ /dev/null @@ -1,36 +0,0 @@ -// +build !windows - -package ole - -// RoInitialize -func RoInitialize(thread_type uint32) (err error) { - return NewError(E_NOTIMPL) -} - -// RoActivateInstance -func RoActivateInstance(clsid string) (ins *IInspectable, err error) { - return nil, NewError(E_NOTIMPL) -} - -// RoGetActivationFactory -func RoGetActivationFactory(clsid string, iid *GUID) (ins *IInspectable, err error) { - return nil, NewError(E_NOTIMPL) -} - -// HString is handle string for pointers. -type HString uintptr - -// NewHString returns a new HString for Go string. -func NewHString(s string) (hstring HString, err error) { - return HString(uintptr(0)), NewError(E_NOTIMPL) -} - -// DeleteHString deletes HString. -func DeleteHString(hstring HString) (err error) { - return NewError(E_NOTIMPL) -} - -// String returns Go string value of HString. -func (h HString) String() string { - return "" -} diff --git a/Godeps/_workspace/src/github.com/inconshreveable/go-update/LICENSE b/Godeps/_workspace/src/github.com/inconshreveable/go-update/LICENSE deleted file mode 100644 index 5f0d1fb6a7b..00000000000 --- a/Godeps/_workspace/src/github.com/inconshreveable/go-update/LICENSE +++ /dev/null @@ -1,13 +0,0 @@ -Copyright 2014 Alan Shreve - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/Godeps/_workspace/src/github.com/inconshreveable/go-update/README.md b/Godeps/_workspace/src/github.com/inconshreveable/go-update/README.md deleted file mode 100644 index f070062c226..00000000000 --- a/Godeps/_workspace/src/github.com/inconshreveable/go-update/README.md +++ /dev/null @@ -1,37 +0,0 @@ -# go-update: Automatically update Go programs from the internet - -go-update allows a program to update itself by replacing its executable file -with a new version. It provides the flexibility to implement different updating user experiences -like auto-updating, or manual user-initiated updates. It also boasts -advanced features like binary patching and code signing verification. - -Updating your program to a new version is as easy as: - - err, errRecover := update.New().FromUrl("http://release.example.com/2.0/myprogram") - if err != nil { - fmt.Printf("Update failed: %v\n", err) - } - -## Documentation and API Reference - -Comprehensive API documentation and code examples are available in the code documentation available on godoc.org: - -[![GoDoc](https://godoc.org/github.com/inconshreveable/go-update?status.svg)](https://godoc.org/github.com/inconshreveable/go-update) - -## Features - -- Cross platform support (Windows too!) -- Binary patch application -- Checksum verification -- Code signing verification -- Support for updating arbitrary files - -## [equinox.io](https://equinox.io) -go-update provides the primitives for building self-updating applications, but there a number of other challenges -involved in a complete updating solution such as hosting, code signing, update channels, gradual rollout, -dynamically computing binary patches, tracking update metrics like versions and failures, plus more. - -I provide this service, a complete solution, free for open source projects, at [equinox.io](https://equinox.io). - -## License -Apache diff --git a/Godeps/_workspace/src/github.com/inconshreveable/go-update/check/check.go b/Godeps/_workspace/src/github.com/inconshreveable/go-update/check/check.go deleted file mode 100644 index 0b2530c7d56..00000000000 --- a/Godeps/_workspace/src/github.com/inconshreveable/go-update/check/check.go +++ /dev/null @@ -1,209 +0,0 @@ -package check - -import ( - "bytes" - _ "crypto/sha512" // for tls cipher support - "encoding/hex" - "encoding/json" - "fmt" - "io/ioutil" - "net/http" - "runtime" - - "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/inconshreveable/go-update" - "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/kardianos/osext" -) - -type Initiative string - -const ( - INITIATIVE_NEVER Initiative = "never" - INITIATIVE_AUTO = "auto" - INITIATIVE_MANUAL = "manual" -) - -var NoUpdateAvailable error = fmt.Errorf("No update available") - -type Params struct { - // protocol version - Version int `json:"version"` - // identifier of the application to update - AppId string `json:"app_id"` - // version of the application updating itself - AppVersion string `json:"app_version"` - // operating system of target platform - OS string `json:"-"` - // hardware architecture of target platform - Arch string `json:"-"` - // application-level user identifier - UserId string `json:"user_id"` - // checksum of the binary to replace (used for returning diff patches) - Checksum string `json:"checksum"` - // release channel (empty string means 'stable') - Channel string `json:"-"` - // tags for custom update channels - Tags map[string]string `json:"tags"` -} - -type Result struct { - up *update.Update - - // should the update be applied automatically/manually - Initiative Initiative `json:"initiative"` - // url where to download the updated application - Url string `json:"url"` - // a URL to a patch to apply - PatchUrl string `json:"patch_url"` - // the patch format (only bsdiff supported at the moment) - PatchType update.PatchType `json:"patch_type"` - // version of the new application - Version string `json:"version"` - // expected checksum of the new application - Checksum string `json:"checksum"` - // signature for verifying update authenticity - Signature string `json:"signature"` -} - -// CheckForUpdate makes an HTTP post to a URL with the JSON serialized -// representation of Params. It returns the deserialized result object -// returned by the remote endpoint or an error. If you do not set -// OS/Arch, CheckForUpdate will populate them for you. Similarly, if -// Version is 0, it will be set to 1. Lastly, if Checksum is the empty -// string, it will be automatically be computed for the running program's -// executable file. -func (p *Params) CheckForUpdate(url string, up *update.Update) (*Result, error) { - if p.Tags == nil { - p.Tags = make(map[string]string) - } - - if p.Channel == "" { - p.Channel = "stable" - } - - if p.OS == "" { - p.OS = runtime.GOOS - } - - if p.Arch == "" { - p.Arch = runtime.GOARCH - } - - if p.Version == 0 { - p.Version = 1 - } - - // ignore errors auto-populating the checksum - // if it fails, you just won't be able to patch - if up.TargetPath == "" { - p.Checksum = defaultChecksum() - } else { - checksum, err := update.ChecksumForFile(up.TargetPath) - if err != nil { - return nil, err - } - p.Checksum = hex.EncodeToString(checksum) - } - - p.Tags["os"] = p.OS - p.Tags["arch"] = p.Arch - p.Tags["channel"] = p.Channel - - body, err := json.Marshal(p) - if err != nil { - return nil, err - } - - resp, err := http.Post(url, "application/json", bytes.NewReader(body)) - if err != nil { - return nil, err - } - - // no content means no available update - if resp.StatusCode == 204 { - return nil, NoUpdateAvailable - } - - defer resp.Body.Close() - respBytes, err := ioutil.ReadAll(resp.Body) - if err != nil { - return nil, err - } - - result := &Result{up: up} - if err := json.Unmarshal(respBytes, result); err != nil { - return nil, err - } - - return result, nil -} - -func (p *Params) CheckAndApplyUpdate(url string, up *update.Update) (result *Result, err error, errRecover error) { - // check for an update - result, err = p.CheckForUpdate(url, up) - if err != nil { - return - } - - // run the available update - err, errRecover = result.Update() - return -} - -func (r *Result) Update() (err error, errRecover error) { - if r.Checksum != "" { - r.up.Checksum, err = hex.DecodeString(r.Checksum) - if err != nil { - return - } - } - - if r.Signature != "" { - r.up.Signature, err = hex.DecodeString(r.Signature) - if err != nil { - return - } - } - - if r.PatchType != "" { - r.up.PatchType = r.PatchType - } - - if r.Url == "" && r.PatchUrl == "" { - err = fmt.Errorf("Result does not contain an update url or patch update url") - return - } - - if r.PatchUrl != "" { - err, errRecover = r.up.FromUrl(r.PatchUrl) - if err == nil { - // success! - return - } else { - // failed to update from patch URL, try with the whole thing - if r.Url == "" || errRecover != nil { - // we can't try updating from a URL with the full contents - // in these cases, so fail - return - } else { - r.up.PatchType = update.PATCHTYPE_NONE - } - } - } - - // try updating from a URL with the full contents - return r.up.FromUrl(r.Url) -} - -func defaultChecksum() string { - path, err := osext.Executable() - if err != nil { - return "" - } - - checksum, err := update.ChecksumForFile(path) - if err != nil { - return "" - } - - return hex.EncodeToString(checksum) -} diff --git a/Godeps/_workspace/src/github.com/inconshreveable/go-update/download/download.go b/Godeps/_workspace/src/github.com/inconshreveable/go-update/download/download.go deleted file mode 100644 index b4a24b1b8be..00000000000 --- a/Godeps/_workspace/src/github.com/inconshreveable/go-update/download/download.go +++ /dev/null @@ -1,230 +0,0 @@ -package download - -import ( - "bytes" - "compress/gzip" - "fmt" - "io" - "net/http" - "os" - "runtime" -) - -type roundTripper struct { - RoundTripFn func(*http.Request) (*http.Response, error) -} - -func (rt *roundTripper) RoundTrip(r *http.Request) (*http.Response, error) { - return rt.RoundTripFn(r) -} - -// Download encapsulates the state and parameters to download content -// from a URL which: -// -// - Publishes the percentage of the download completed to a channel. -// - May resume a previous download that was partially completed. -// -// Create an instance with the New() factory function. -type Download struct { - // net/http.Client to use when downloading the update. - // If nil, a default http.Client is used - HttpClient *http.Client - - // As bytes are downloaded, they are written to Target. - // Download also uses the Target's Seek method to determine - // the size of partial-downloads so that it may properly - // request the remaining bytes to resume the download. - Target Target - - // Progress returns the percentage of the download - // completed as an integer between 0 and 100 - Progress chan (int) - - // HTTP Method to use in the download request. Default is "GET" - Method string - - // HTTP URL to issue the download request to - Url string -} - -// New initializes a new Download object which will download -// the content from url into target. -func New(url string, target Target) *Download { - return &Download{ - HttpClient: new(http.Client), - Progress: make(chan int), - Method: "GET", - Url: url, - Target: target, - } -} - -// Get() downloads the content of a url to a target destination. -// -// Only HTTP/1.1 servers that implement the Range header support resuming a -// partially completed download. -// -// On success, the server must return 200 and the content, or 206 when resuming a partial download. -// If the HTTP server returns a 3XX redirect, it will be followed according to d.HttpClient's redirect policy. -// -func (d *Download) Get() (err error) { - // Close the progress channel whenever this function completes - defer close(d.Progress) - - // determine the size of the download target to determine if we're resuming a partial download - offset, err := d.Target.Size() - if err != nil { - return - } - - // create the download request - req, err := http.NewRequest(d.Method, d.Url, nil) - if err != nil { - return - } - - // we have to add headers like this so they get used across redirects - trans := d.HttpClient.Transport - if trans == nil { - trans = http.DefaultTransport - } - - d.HttpClient.Transport = &roundTripper{ - RoundTripFn: func(r *http.Request) (*http.Response, error) { - // add header for download continuation - if offset > 0 { - r.Header.Add("Range", fmt.Sprintf("%d-", offset)) - } - - // ask for gzipped content so that net/http won't unzip it for us - // and destroy the content length header we need for progress calculations - r.Header.Add("Accept-Encoding", "gzip") - - return trans.RoundTrip(r) - }, - } - - // issue the download request - resp, err := d.HttpClient.Do(req) - if err != nil { - return - } - defer resp.Body.Close() - - switch resp.StatusCode { - // ok - case 200, 206: - - // server error - default: - err = fmt.Errorf("Non 2XX response when downloading update: %s", resp.Status) - return - } - - // Determine how much we have to download - // net/http sets this to -1 when it is unknown - clength := resp.ContentLength - - // Read the content from the response body - rd := resp.Body - - // meter the rate at which we download content for - // progress reporting if we know how much to expect - if clength > 0 { - rd = &meteredReader{rd: rd, totalSize: clength, progress: d.Progress} - } - - // Decompress the content if necessary - if resp.Header.Get("Content-Encoding") == "gzip" { - rd, err = gzip.NewReader(rd) - if err != nil { - return - } - } - - // Download the update - _, err = io.Copy(d.Target, rd) - if err != nil { - return - } - - return -} - -// meteredReader wraps a ReadCloser. Calls to a meteredReader's Read() method -// publish updates to a progress channel with the percentage read so far. -type meteredReader struct { - rd io.ReadCloser - totalSize int64 - progress chan int - totalRead int64 - ticks int64 -} - -func (m *meteredReader) Close() error { - return m.rd.Close() -} - -func (m *meteredReader) Read(b []byte) (n int, err error) { - chunkSize := (m.totalSize / 100) + 1 - lenB := int64(len(b)) - - var nChunk int - for start := int64(0); start < lenB; start += int64(nChunk) { - end := start + chunkSize - if end > lenB { - end = lenB - } - - nChunk, err = m.rd.Read(b[start:end]) - - n += nChunk - m.totalRead += int64(nChunk) - - if m.totalRead > (m.ticks * chunkSize) { - m.ticks += 1 - // try to send on channel, but don't block if it's full - select { - case m.progress <- int(m.ticks + 1): - default: - } - - // give the progress channel consumer a chance to run - runtime.Gosched() - } - - if err != nil { - return - } - } - - return -} - -// A Target is what you can supply to Download, -// it's just an io.Writer with a Size() method so that -// the a Download can "resume" an interrupted download -type Target interface { - io.Writer - Size() (int, error) -} - -type FileTarget struct { - *os.File -} - -func (t *FileTarget) Size() (int, error) { - if fi, err := t.File.Stat(); err != nil { - return 0, err - } else { - return int(fi.Size()), nil - } -} - -type MemoryTarget struct { - bytes.Buffer -} - -func (t *MemoryTarget) Size() (int, error) { - return t.Buffer.Len(), nil -} diff --git a/Godeps/_workspace/src/github.com/inconshreveable/go-update/hide_noop.go b/Godeps/_workspace/src/github.com/inconshreveable/go-update/hide_noop.go deleted file mode 100644 index 3707756087d..00000000000 --- a/Godeps/_workspace/src/github.com/inconshreveable/go-update/hide_noop.go +++ /dev/null @@ -1,7 +0,0 @@ -// +build !windows - -package update - -func hideFile(path string) error { - return nil -} diff --git a/Godeps/_workspace/src/github.com/inconshreveable/go-update/hide_windows.go b/Godeps/_workspace/src/github.com/inconshreveable/go-update/hide_windows.go deleted file mode 100644 index c368b9cc45b..00000000000 --- a/Godeps/_workspace/src/github.com/inconshreveable/go-update/hide_windows.go +++ /dev/null @@ -1,19 +0,0 @@ -package update - -import ( - "syscall" - "unsafe" -) - -func hideFile(path string) error { - kernel32 := syscall.NewLazyDLL("kernel32.dll") - setFileAttributes := kernel32.NewProc("SetFileAttributesW") - - r1, _, err := setFileAttributes.Call(uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(path))), 2) - - if r1 == 0 { - return err - } else { - return nil - } -} diff --git a/Godeps/_workspace/src/github.com/inconshreveable/go-update/update.go b/Godeps/_workspace/src/github.com/inconshreveable/go-update/update.go deleted file mode 100644 index 234d1db8bee..00000000000 --- a/Godeps/_workspace/src/github.com/inconshreveable/go-update/update.go +++ /dev/null @@ -1,487 +0,0 @@ -/* -go-update allows a program to update itself by replacing its executable file -with a new version. It provides the flexibility to implement different updating user experiences -like auto-updating, or manual user-initiated updates. It also boasts -advanced features like binary patching and code signing verification. - -Updating your program to a new version is as easy as: - - err, errRecover := update.New().FromUrl("http://release.example.com/2.0/myprogram") - if err != nil { - fmt.Printf("Update failed: %v\n", err) - } - -You may also choose to update from other data sources such as a file or an io.Reader: - - err, errRecover := update.New().FromFile("/path/to/update") - -Binary Diff Patching - -Binary diff updates are supported and easy to use: - - up := update.New().ApplyPatch(update.PATCHTYPE_BSDIFF) - err, errRecover := up.FromUrl("http://release.example.com/2.0/mypatch") - -Checksum Verification - -You should also verify the checksum of new updates as well as verify -the digital signature of an update. Note that even when you choose to apply -a patch, the checksum is verified against the complete update after that patch -has been applied. - - up := update.New().ApplyPatch(update.PATCHTYPE_BSDIFF).VerifyChecksum(checksum) - err, errRecover := up.FromUrl("http://release.example.com/2.0/mypatch") - -Updating other files - -Updating arbitrary files is also supported. You may update files which are -not the currently running program: - - up := update.New().Target("/usr/local/bin/some-program") - err, errRecover := up.FromUrl("http://release.example.com/2.0/some-program") - -Code Signing - -Truly secure updates use code signing to verify that the update was issued by a trusted party. -To do this, you'll need to generate a public/private key pair. You can do this with openssl, -or the equinox.io client (https://equinox.io/client) can easily generate one for you: - - # with equinox client - equinox genkey --private-key=private.pem --public-key=public.pem - - # with openssl - openssl genrsa -out private.pem 2048 - openssl rsa -in private.pem -out public.pem -pubout - -Once you have your key pair, you can instruct your program to validate its updates -with the public key: - - const publicKey = `-----BEGIN PUBLIC KEY----- - ... - -----END PUBLIC KEY-----` - - up, err := update.New().VerifySignatureWithPEM(publicKey) - if err != nil { - return fmt.Errorf("Bad public key: '%v': %v", publicKey, err) - } - -Once you've configured your program this way, it will disallow all updates unless they -are properly signed. You must now pass in the signature to verify with: - - up.VerifySignature(signature).FromUrl("http://dl.example.com/update") - -Error Handling and Recovery - -To perform an update, the process must be able to read its executable file and to write -to the directory that contains its executable file. It can be useful to check whether the process -has the necessary permissions to perform an update before trying to apply one. Use the -CanUpdate call to provide a useful message to the user if the update can't proceed without -elevated permissions: - - up := update.New().Target("/etc/hosts") - err := up.CanUpdate() - if err != nil { - fmt.Printf("Can't update because: '%v'. Try as root or Administrator\n", err) - return - } - err, errRecover := up.FromUrl("https://example.com/new/hosts") - -Although exceedingly unlikely, the update operation itself is not atomic and can fail -in such a way that a user's computer is left in an inconsistent state. If that happens, -go-update attempts to recover to leave the system in a good state. If the recovery step -fails (even more unlikely), a second error, referred to as "errRecover" will be non-nil -so that you may inform your users of the bad news. You should handle this case as shown -here: - - err, errRecover := up.FromUrl("https://example.com/update") - if err != nil { - fmt.Printf("Update failed: %v\n", err) - if errRecover != nil { - fmt.Printf("Failed to recover bad update: %v!\n", errRecover) - fmt.Printf("Program exectuable may be missing!\n") - } - } - -Subpackages - -Sub-package check contains the client functionality for a simple protocol for negotiating -whether a new update is available, where it is, and the metadata needed for verifying it. - -Sub-package download contains functionality for downloading from an HTTP endpoint -while outputting a progress meter and supports resuming partial downloads. -*/ -package update - -import ( - "bytes" - "crypto" - "crypto/rsa" - "crypto/sha256" - _ "crypto/sha512" // for tls cipher support - "crypto/x509" - "encoding/pem" - "fmt" - "io" - "io/ioutil" - "os" - "path/filepath" - - "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/inconshreveable/go-update/download" - "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/kardianos/osext" - "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/kr/binarydist" -) - -// The type of a binary patch, if any. Only bsdiff is supported -type PatchType string - -const ( - PATCHTYPE_BSDIFF PatchType = "bsdiff" - PATCHTYPE_NONE = "" -) - -type Update struct { - // empty string means "path of the current executable" - TargetPath string - - // type of patch to apply. PATCHTYPE_NONE means "not a patch" - PatchType - - // sha256 checksum of the new binary to verify against - Checksum []byte - - // public key to use for signature verification - PublicKey *rsa.PublicKey - - // signature to use for signature verification - Signature []byte -} - -func (u *Update) getPath() (string, error) { - if u.TargetPath == "" { - return osext.Executable() - } else { - return u.TargetPath, nil - } -} - -// New creates a new Update object. -// A default update object assumes the complete binary -// content will be used for update (not a patch) and that -// the intended target is the running executable. -// -// Use this as the start of a chain of calls on the Update -// object to build up your configuration. Example: -// -// up := update.New().ApplyPatch(update.PATCHTYPE_BSDIFF).VerifyChecksum(checksum) -// -func New() *Update { - return &Update{ - TargetPath: "", - PatchType: PATCHTYPE_NONE, - } -} - -// Target configures the update to update the file at the given path. -// The emptry string means 'the executable file of the running program'. -func (u *Update) Target(path string) *Update { - u.TargetPath = path - return u -} - -// ApplyPatch configures the update to treat the contents of the update -// as a patch to apply to the existing to target. You must specify the -// format of the patch. Only PATCHTYPE_BSDIFF is supported at the moment. -func (u *Update) ApplyPatch(patchType PatchType) *Update { - u.PatchType = patchType - return u -} - -// VerifyChecksum configures the update to verify that the -// the update has the given sha256 checksum. -func (u *Update) VerifyChecksum(checksum []byte) *Update { - u.Checksum = checksum - return u -} - -// VerifySignature configures the update to verify the given -// signature of the update. You must also call one of the -// VerifySignatureWith* functions to specify a public key -// to use for verification. -func (u *Update) VerifySignature(signature []byte) *Update { - u.Signature = signature - return u -} - -// VerifySignatureWith configures the update to use the given RSA -// public key to verify the update's signature. You must also call -// VerifySignature() with a signature to check. -// -// You'll probably want to use VerifySignatureWithPEM instead of -// parsing the public key yourself. -func (u *Update) VerifySignatureWith(publicKey *rsa.PublicKey) *Update { - u.PublicKey = publicKey - return u -} - -// VerifySignatureWithPEM configures the update to use the given PEM-formatted -// RSA public key to verify the update's signature. You must also call -// VerifySignature() with a signature to check. -// -// A PEM formatted public key typically begins with -// -----BEGIN PUBLIC KEY----- -func (u *Update) VerifySignatureWithPEM(publicKeyPEM []byte) (*Update, error) { - block, _ := pem.Decode(publicKeyPEM) - if block == nil { - return u, fmt.Errorf("Couldn't parse PEM data") - } - - pub, err := x509.ParsePKIXPublicKey(block.Bytes) - if err != nil { - return u, err - } - - var ok bool - u.PublicKey, ok = pub.(*rsa.PublicKey) - if !ok { - return u, fmt.Errorf("Public key isn't an RSA public key") - } - - return u, nil -} - -// FromUrl updates the target with the contents of the given URL. -func (u *Update) FromUrl(url string) (err error, errRecover error) { - target := new(download.MemoryTarget) - err = download.New(url, target).Get() - if err != nil { - return - } - - return u.FromStream(target) -} - -// FromFile updates the target the contents of the given file. -func (u *Update) FromFile(path string) (err error, errRecover error) { - // open the new updated contents - fp, err := os.Open(path) - if err != nil { - return - } - defer fp.Close() - - // do the update - return u.FromStream(fp) -} - -// FromStream updates the target file with the contents of the supplied io.Reader. -// -// FromStream performs the following actions to ensure a safe cross-platform update: -// -// 1. If configured, applies the contents of the io.Reader as a binary patch. -// -// 2. If configured, computes the sha256 checksum and verifies it matches. -// -// 3. If configured, verifies the RSA signature with a public key. -// -// 4. Creates a new file, /path/to/.target.new with mode 0755 with the contents of the updated file -// -// 5. Renames /path/to/target to /path/to/.target.old -// -// 6. Renames /path/to/.target.new to /path/to/target -// -// 7. If the rename is successful, deletes /path/to/.target.old, returns no error -// -// 8. If the rename fails, attempts to rename /path/to/.target.old back to /path/to/target -// If this operation fails, it is reported in the errRecover return value so as not to -// mask the original error that caused the recovery attempt. -// -// On Windows, the removal of /path/to/.target.old always fails, so instead, -// we just make the old file hidden instead. -func (u *Update) FromStream(updateWith io.Reader) (err error, errRecover error) { - updatePath, err := u.getPath() - if err != nil { - return - } - - var newBytes []byte - // apply a patch if requested - switch u.PatchType { - case PATCHTYPE_BSDIFF: - newBytes, err = applyPatch(updateWith, updatePath) - if err != nil { - return - } - case PATCHTYPE_NONE: - // no patch to apply, go on through - newBytes, err = ioutil.ReadAll(updateWith) - if err != nil { - return - } - default: - err = fmt.Errorf("Unrecognized patch type: %s", u.PatchType) - return - } - - // verify checksum if requested - if u.Checksum != nil { - if err = verifyChecksum(newBytes, u.Checksum); err != nil { - return - } - } - - // verify signature if requested - if u.Signature != nil || u.PublicKey != nil { - if u.Signature == nil { - err = fmt.Errorf("No public key specified to verify signature") - return - } - - if u.PublicKey == nil { - err = fmt.Errorf("No signature to verify!") - return - } - - if err = verifySignature(newBytes, u.Signature, u.PublicKey); err != nil { - return - } - } - - // get the directory the executable exists in - updateDir := filepath.Dir(updatePath) - filename := filepath.Base(updatePath) - - // Copy the contents of of newbinary to a the new executable file - newPath := filepath.Join(updateDir, fmt.Sprintf(".%s.new", filename)) - fp, err := os.OpenFile(newPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0755) - if err != nil { - return - } - defer fp.Close() - _, err = io.Copy(fp, bytes.NewReader(newBytes)) - - // if we don't call fp.Close(), windows won't let us move the new executable - // because the file will still be "in use" - fp.Close() - - // this is where we'll move the executable to so that we can swap in the updated replacement - oldPath := filepath.Join(updateDir, fmt.Sprintf(".%s.old", filename)) - - // delete any existing old exec file - this is necessary on Windows for two reasons: - // 1. after a successful update, Windows can't remove the .old file because the process is still running - // 2. windows rename operations fail if the destination file already exists - _ = os.Remove(oldPath) - - // move the existing executable to a new file in the same directory - err = os.Rename(updatePath, oldPath) - if err != nil { - return - } - - // move the new exectuable in to become the new program - err = os.Rename(newPath, updatePath) - - if err != nil { - // copy unsuccessful - errRecover = os.Rename(oldPath, updatePath) - } else { - // copy successful, remove the old binary - errRemove := os.Remove(oldPath) - - // windows has trouble with removing old binaries, so hide it instead - if errRemove != nil { - _ = hideFile(oldPath) - } - } - - return -} - -// CanUpdate() determines whether the process has the correct permissions to -// perform the requested update. If the update can proceed, it returns nil, otherwise -// it returns the error that would occur if an update were attempted. -func (u *Update) CanUpdate() (err error) { - // get the directory the file exists in - path, err := u.getPath() - if err != nil { - return - } - - fileDir := filepath.Dir(path) - fileName := filepath.Base(path) - - // attempt to open a file in the file's directory - newPath := filepath.Join(fileDir, fmt.Sprintf(".%s.new", fileName)) - fp, err := os.OpenFile(newPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0755) - if err != nil { - return - } - fp.Close() - - _ = os.Remove(newPath) - return -} - -func applyPatch(patch io.Reader, updatePath string) ([]byte, error) { - // open the file to update - old, err := os.Open(updatePath) - if err != nil { - return nil, err - } - defer old.Close() - - // apply the patch - applied := new(bytes.Buffer) - if err = binarydist.Patch(old, applied, patch); err != nil { - return nil, err - } - - return applied.Bytes(), nil -} - -func verifyChecksum(updated []byte, expectedChecksum []byte) error { - checksum, err := ChecksumForBytes(updated) - if err != nil { - return err - } - - if !bytes.Equal(expectedChecksum, checksum) { - return fmt.Errorf("Updated file has wrong checksum. Expected: %x, got: %x", expectedChecksum, checksum) - } - - return nil -} - -// ChecksumForFile returns the sha256 checksum for the given file -func ChecksumForFile(path string) ([]byte, error) { - f, err := os.Open(path) - if err != nil { - return nil, err - } - defer f.Close() - - return ChecksumForReader(f) -} - -// ChecksumForReader returns the sha256 checksum for the entire -// contents of the given reader. -func ChecksumForReader(rd io.Reader) ([]byte, error) { - h := sha256.New() - if _, err := io.Copy(h, rd); err != nil { - return nil, err - } - return h.Sum(nil), nil -} - -// ChecksumForBytes returns the sha256 checksum for the given bytes -func ChecksumForBytes(source []byte) ([]byte, error) { - return ChecksumForReader(bytes.NewReader(source)) -} - -func verifySignature(source, signature []byte, publicKey *rsa.PublicKey) error { - checksum, err := ChecksumForBytes(source) - if err != nil { - return err - } - - return rsa.VerifyPKCS1v15(publicKey, crypto.SHA256, checksum, signature) -} diff --git a/Godeps/_workspace/src/github.com/inconshreveable/go-update/update_test.go b/Godeps/_workspace/src/github.com/inconshreveable/go-update/update_test.go deleted file mode 100644 index c4634b59221..00000000000 --- a/Godeps/_workspace/src/github.com/inconshreveable/go-update/update_test.go +++ /dev/null @@ -1,380 +0,0 @@ -package update - -import ( - "bytes" - "crypto" - "crypto/rand" - "crypto/rsa" - "crypto/x509" - "encoding/pem" - "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/kr/binarydist" - "io/ioutil" - "net" - "net/http" - "os" - "testing" -) - -var ( - oldFile = []byte{0xDE, 0xAD, 0xBE, 0xEF} - newFile = []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06} -) - -func cleanup(path string) { - os.Remove(path) -} - -// we write with a separate name for each test so that we can run them in parallel -func writeOldFile(path string, t *testing.T) { - if err := ioutil.WriteFile(path, oldFile, 0777); err != nil { - t.Fatalf("Failed to write file for testing preparation: %v", err) - } -} - -func validateUpdate(path string, err error, t *testing.T) { - if err != nil { - t.Fatalf("Failed to update: %v", err) - } - - buf, err := ioutil.ReadFile(path) - if err != nil { - t.Fatalf("Failed to read file post-update: %v", err) - } - - if !bytes.Equal(buf, newFile) { - t.Fatalf("File was not updated! Bytes read: %v, Bytes expected: %v", buf, newFile) - } -} - -func TestFromStream(t *testing.T) { - t.Parallel() - - fName := "TestFromStream" - defer cleanup(fName) - writeOldFile(fName, t) - - err, _ := New().Target(fName).FromStream(bytes.NewReader(newFile)) - validateUpdate(fName, err, t) -} - -func TestFromFile(t *testing.T) { - t.Parallel() - - fName := "TestFromFile" - newFName := "NewTestFromFile" - defer cleanup(fName) - defer cleanup(newFName) - writeOldFile(fName, t) - - if err := ioutil.WriteFile(newFName, newFile, 0777); err != nil { - t.Fatalf("Failed to write file to update from: %v", err) - } - - err, _ := New().Target(fName).FromFile(newFName) - validateUpdate(fName, err, t) -} - -func TestFromUrl(t *testing.T) { - t.Parallel() - - fName := "TestFromUrl" - defer cleanup(fName) - writeOldFile(fName, t) - - l, err := net.Listen("tcp", ":0") - if err != nil { - t.Fatalf("Couldn't bind listener: %v", err) - } - addr := l.Addr().String() - - go http.Serve(l, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Write(newFile) - })) - - err, _ = New().Target(fName).FromUrl("http://" + addr) - validateUpdate(fName, err, t) -} - -func TestVerifyChecksum(t *testing.T) { - t.Parallel() - - fName := "TestVerifyChecksum" - defer cleanup(fName) - writeOldFile(fName, t) - - checksum, err := ChecksumForBytes(newFile) - if err != nil { - t.Fatalf("Failed to compute checksum: %v", err) - } - - err, _ = New().Target(fName).VerifyChecksum(checksum).FromStream(bytes.NewReader(newFile)) - validateUpdate(fName, err, t) -} - -func TestVerifyChecksumNegative(t *testing.T) { - t.Parallel() - - fName := "TestVerifyChecksumNegative" - defer cleanup(fName) - writeOldFile(fName, t) - - badChecksum := []byte{0x0A, 0x0B, 0x0C, 0xFF} - err, _ := New().Target(fName).VerifyChecksum(badChecksum).FromStream(bytes.NewReader(newFile)) - if err == nil { - t.Fatalf("Failed to detect bad checksum!") - } -} - -func TestApplyPatch(t *testing.T) { - t.Parallel() - - fName := "TestApplyPatch" - defer cleanup(fName) - writeOldFile(fName, t) - - patch := new(bytes.Buffer) - err := binarydist.Diff(bytes.NewReader(oldFile), bytes.NewReader(newFile), patch) - if err != nil { - t.Fatalf("Failed to create patch: %v", err) - } - - up := New().Target(fName).ApplyPatch(PATCHTYPE_BSDIFF) - err, _ = up.FromStream(bytes.NewReader(patch.Bytes())) - validateUpdate(fName, err, t) -} - -func TestCorruptPatch(t *testing.T) { - t.Parallel() - - fName := "TestCorruptPatch" - defer cleanup(fName) - writeOldFile(fName, t) - - badPatch := []byte{0x44, 0x38, 0x86, 0x3c, 0x4f, 0x8d, 0x26, 0x54, 0xb, 0x11, 0xce, 0xfe, 0xc1, 0xc0, 0xf8, 0x31, 0x38, 0xa0, 0x12, 0x1a, 0xa2, 0x57, 0x2a, 0xe1, 0x3a, 0x48, 0x62, 0x40, 0x2b, 0x81, 0x12, 0xb1, 0x21, 0xa5, 0x16, 0xed, 0x73, 0xd6, 0x54, 0x84, 0x29, 0xa6, 0xd6, 0xb2, 0x1b, 0xfb, 0xe6, 0xbe, 0x7b, 0x70} - up := New().Target(fName).ApplyPatch(PATCHTYPE_BSDIFF) - err, _ := up.FromStream(bytes.NewReader(badPatch)) - if err == nil { - t.Fatalf("Failed to detect corrupt patch!") - } -} - -func TestVerifyChecksumPatchNegative(t *testing.T) { - t.Parallel() - - fName := "TestVerifyChecksumPatchNegative" - defer cleanup(fName) - writeOldFile(fName, t) - - checksum, err := ChecksumForBytes(newFile) - if err != nil { - t.Fatalf("Failed to compute checksum: %v", err) - } - - patch := new(bytes.Buffer) - anotherFile := []byte{0x77, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66} - err = binarydist.Diff(bytes.NewReader(oldFile), bytes.NewReader(anotherFile), patch) - if err != nil { - t.Fatalf("Failed to create patch: %v", err) - } - - up := New().Target(fName).ApplyPatch(PATCHTYPE_BSDIFF).VerifyChecksum(checksum) - err, _ = up.FromStream(bytes.NewReader(patch.Bytes())) - if err == nil { - t.Fatalf("Failed to detect patch to wrong file!") - } -} - -const publicKey = `-----BEGIN PUBLIC KEY----- -MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxSWmu7trWKAwDFjiCN2D -Tk2jj2sgcr/CMlI4cSSiIOHrXCFxP1I8i9PvQkd4hasXQrLbT5WXKrRGv1HKUKab -b9ead+kD0kxk7i2bFYvKX43oq66IW0mOLTQBO7I9UyT4L7svcMD+HUQ2BqHoaQe4 -y20C59dPr9Dpcz8DZkdLsBV6YKF6Ieb3iGk8oRLMWNaUqPa8f1BGgxAkvPHcqDjT -x4xRnjgTRRRlZvRtALHMUkIChgxDOhoEzKpGiqnX7HtMJfrhV6h0PAXNA4h9Kjv5 -5fhJ08Rz7mmZmtH5JxTK5XTquo59sihSajR4bSjZbbkQ1uLkeFlY3eli3xdQ7Nrf -fQIDAQAB ------END PUBLIC KEY-----` - -const privateKey = `-----BEGIN RSA PRIVATE KEY----- -MIIEogIBAAKCAQEAxSWmu7trWKAwDFjiCN2DTk2jj2sgcr/CMlI4cSSiIOHrXCFx -P1I8i9PvQkd4hasXQrLbT5WXKrRGv1HKUKabb9ead+kD0kxk7i2bFYvKX43oq66I -W0mOLTQBO7I9UyT4L7svcMD+HUQ2BqHoaQe4y20C59dPr9Dpcz8DZkdLsBV6YKF6 -Ieb3iGk8oRLMWNaUqPa8f1BGgxAkvPHcqDjTx4xRnjgTRRRlZvRtALHMUkIChgxD -OhoEzKpGiqnX7HtMJfrhV6h0PAXNA4h9Kjv55fhJ08Rz7mmZmtH5JxTK5XTquo59 -sihSajR4bSjZbbkQ1uLkeFlY3eli3xdQ7NrffQIDAQABAoIBAAkN+6RvrTR61voa -Mvd5RQiZpEN4Bht/Fyo8gH8h0Zh1B9xJZOwlmMZLS5fdtHlfLEhR8qSrGDBL61vq -I8KkhEsUufF78EL+YzxVN+Q7cWYGHIOWFokqza7hzpSxUQO6lPOMQ1eIZaNueJTB -Zu07/47ISPPg/bXzgGVcpYlTCPTjUwKjtfyMqvX9AD7fIyYRm6zfE7EHj1J2sBFt -Yz1OGELg6HfJwXfpnPfBvftD0hWGzJ78Bp71fPJe6n5gnqmSqRvrcXNWFnH/yqkN -d6vPIxD6Z3LjvyZpkA7JillLva2L/zcIFhg4HZvQnWd8/PpDnUDonu36hcj4SC5j -W4aVPLkCgYEA4XzNKWxqYcajzFGZeSxlRHupSAl2MT7Cc5085MmE7dd31wK2T8O4 -n7N4bkm/rjTbX85NsfWdKtWb6mpp8W3VlLP0rp4a/12OicVOkg4pv9LZDmY0sRlE -YuDJk1FeCZ50UrwTZI3rZ9IhZHhkgVA6uWAs7tYndONkxNHG0pjqs4sCgYEA39MZ -JwMqo3qsPntpgP940cCLflEsjS9hYNO3+Sv8Dq3P0HLVhBYajJnotf8VuU0fsQZG -grmtVn1yThFbMq7X1oY4F0XBA+paSiU18c4YyUnwax2u4sw9U/Q9tmQUZad5+ueT -qriMBwGv+ewO+nQxqvAsMUmemrVzrfwA5Oct+hcCgYAfiyXoNZJsOy2O15twqBVC -j0oPGcO+/9iT89sg5lACNbI+EdMPNYIOVTzzsL1v0VUfAe08h++Enn1BPcG0VHkc -ZFBGXTfJoXzfKQrkw7ZzbzuOGB4m6DH44xlP0oIlNlVvfX/5ASF9VJf3RiBJNsAA -TsP6ZVr/rw/ZuL7nlxy+IQKBgDhL/HOXlE3yOQiuOec8WsNHTs7C1BXe6PtVxVxi -988pYK/pclL6zEq5G5NLSceF4obAMVQIJ9UtUGbabrncyGUo9UrFPLsjYvprSZo8 -YHegpVwL50UcYgCP2kXZ/ldjPIcjYDz8lhvdDMor2cidGTEJn9P11HLNWP9V91Ob -4jCZAoGAPNRSC5cC8iP/9j+s2/kdkfWJiNaolPYAUrmrkL6H39PYYZM5tnhaIYJV -Oh9AgABamU0eb3p3vXTISClVgV7ifq1HyZ7BSUhMfaY2Jk/s3sUHCWFxPZe9sgEG -KinIY/373KIkIV/5g4h2v1w330IWcfptxKcY/Er3DJr38f695GE= ------END RSA PRIVATE KEY-----` - -func sign(privatePEM string, source []byte, t *testing.T) []byte { - block, _ := pem.Decode([]byte(privatePEM)) - if block == nil { - t.Fatalf("Failed to parse private key PEM") - } - - priv, err := x509.ParsePKCS1PrivateKey(block.Bytes) - if err != nil { - t.Fatalf("Failed to parse private key DER") - } - - checksum, err := ChecksumForBytes(source) - if err != nil { - t.Fatalf("Failed to make checksum") - } - - sig, err := rsa.SignPKCS1v15(rand.Reader, priv, crypto.SHA256, checksum) - if err != nil { - t.Fatalf("Failed to sign: %v", sig) - } - - return sig -} - -func TestVerifySignature(t *testing.T) { - t.Parallel() - - fName := "TestVerifySignature" - defer cleanup(fName) - writeOldFile(fName, t) - - up, err := New().Target(fName).VerifySignatureWithPEM([]byte(publicKey)) - if err != nil { - t.Fatalf("Could not parse public key: %v", err) - } - - signature := sign(privateKey, newFile, t) - err, _ = up.VerifySignature(signature).FromStream(bytes.NewReader(newFile)) - validateUpdate(fName, err, t) -} - -func TestVerifyFailBadSignature(t *testing.T) { - t.Parallel() - - fName := "TestVerifyFailBadSignature" - defer cleanup(fName) - writeOldFile(fName, t) - - up, err := New().Target(fName).VerifySignatureWithPEM([]byte(publicKey)) - if err != nil { - t.Fatalf("Could not parse public key: %v", err) - } - - badSig := []byte{0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA} - err, _ = up.VerifySignature(badSig).FromStream(bytes.NewReader(newFile)) - if err == nil { - t.Fatalf("Did not fail with bad signature") - } -} - -func TestVerifyFailNoSignature(t *testing.T) { - t.Parallel() - - fName := "TestVerifySignatureWithPEM" - defer cleanup(fName) - writeOldFile(fName, t) - - up, err := New().Target(fName).VerifySignatureWithPEM([]byte(publicKey)) - if err != nil { - t.Fatalf("Could not parse public key: %v", err) - } - - err, _ = up.VerifySignature([]byte{}).FromStream(bytes.NewReader(newFile)) - if err == nil { - t.Fatalf("Did not fail with empty signature") - } -} - -const wrongKey = `-----BEGIN RSA PRIVATE KEY----- -MIIEpAIBAAKCAQEArKqjT+xOFJILe0CX7lKfQy52YwWLF9devYtLeUHTbPOueGLy -6CjrXJBrWIxNBxRd53y4dtgiMqCX6Gmmvuy8HnfbBuJjR2mcdEYo8UDy+aSVBQ6T -/ND7Fd7KSzOruEFFzl2QFnZ/SrW/nsXdGyuF8l+YIwjZJRyV6StZkZ4ydOzOqUk9 -FXTeIkhX/Q7/jTETw7L3wxMyLgJAlV3lxDsPkMjxymngtbAIjwEjLsVeU+Prcz2e -Ww34SZQ8qwzAdXieuDPryMwEsCcgc5NAKJFNL8TppYGDXOHI7CRXqHfNiJq2R+kQ -LdxRvmfx8/iu4xM2hBzk4uSDS6TTn2AnWBm+cQIDAQABAoIBAFp//aUwaCRj/9yU -GI3zhEJEIgz4pNTUL3YNgnuFwvlCJ9o1kreYavRTRdBdiSoCxM1GE7FGy3XZsoVA -iwNbNaaKj6RmGD8f3b8b3u3EaxXp66mA4JQMPO5TnZgY9xJWM+5cH9+GMGXKKStg -7ekFwOkuraD/TEElYHWcIRAv6KZbc/YOIa6YDKi+1Gc7u0MeIvwqN7nwaBAoJKUE -ZrJIfYKIViD/ZrCpgWN47C9x8w3ne7iiDrYoYct+0reC9LFlqwVBtDnyVx/q3upW -zzczbNQagu3w0QgprDGhy0ZhDNxuylV3XBWTB+xBrFQgz6rD3LzUPywlbt0N7ZmD -936MVSECgYEA1IElCahF/+hC/OxFgy98DubAUDGmrvxWeZF3bvTseWZQp/gzxVS+ -SYumYyd2Ysx5+UjXQlVgR6BbDG13+DpSpZm6+MeWHBAR+KA2qCg009SDFv7l26/d -xMT7lvIWz7ckQDb/+jvhF9HL2llyTN1Zex+n3XBeAMKNrPaubdEBFsUCgYEA0AIO -tZMtzOpioAR1lGbwIguq04msDdrJNaY2TKrLeviJuQUw94fgL+3ULAPsiyxaU/Gv -vln11R7aIp1SJ09T2UoFRbty+6SGRC56+Wh0pn5VnAi7aT6qdkYWhEjhqRHuXosf -PYboXBuMwA0FBUTxWQL/lux2PZgvBkniYh5jI70CgYEAk9KmhhpFX2gdOT3OeRxO -CzufaemwDqfAK97yGwBLg4OV9dJliQ6TNCvt+amY489jxfJSs3UafZjh3TpFKyq/ -FS1kb+y+0hSnu7EPdFhLr1N0QUndcb3b4iY48V7EWYgHspfP5y1CPsSVLvXr2eZc -eZaiuhqReavczAXpfsDWJhUCgYEAwmUp2gfyhc+G3IVOXaLWSPseaxP+9/PAl6L+ -nCgCgqpEC+YOHUee/SwHXhtMtcR9pnX5CKyKUuLCehcM8C/y7N+AjerhSsw3rwDB -bNVyLydiWrDOdU1bga1+3aI/QwK/AxyB1b5+6ZXVtKZ2SrZj2Aw1UZcr6eSQDhB+ -wbQkcwECgYBF13FMA6OOon992t9H3I+4KDgmz6G6mz3bVXSoFWfO1p/yXP04BzJl -jtLFvFVTZdMs2o/wTd4SL6gYjx9mlOWwM8FblmjfiNSUVIyye33fRntEAr1n+FYI -Xhv6aVnNdaGehGIqQxXFoGyiJxG3RYNkSwaTOamxY1V+ceLuO26n2Q== ------END RSA PRIVATE KEY-----` - -func TestVerifyFailWrongSignature(t *testing.T) { - t.Parallel() - - fName := "TestVerifyFailWrongSignature" - defer cleanup(fName) - writeOldFile(fName, t) - - up, err := New().Target(fName).VerifySignatureWithPEM([]byte(publicKey)) - if err != nil { - t.Fatalf("Could not parse public key: %v", err) - } - - signature := sign(wrongKey, newFile, t) - err, _ = up.VerifySignature(signature).FromStream(bytes.NewReader(newFile)) - if err == nil { - t.Fatalf("Verified an update that was signed by an untrusted key!") - } -} - -func TestSignatureButNoPublicKey(t *testing.T) { - t.Parallel() - - fName := "TestSignatureButNoPublicKey" - defer cleanup(fName) - writeOldFile(fName, t) - - sig := sign(privateKey, newFile, t) - err, _ := New().Target(fName).VerifySignature(sig).FromStream(bytes.NewReader(newFile)) - if err == nil { - t.Fatalf("Allowed an update with a signautre verification when no public key was specified!") - } -} - -func TestPublicKeyButNoSignature(t *testing.T) { - t.Parallel() - - fName := "TestPublicKeyButNoSignature" - defer cleanup(fName) - writeOldFile(fName, t) - - up, err := New().Target(fName).VerifySignatureWithPEM([]byte(publicKey)) - if err != nil { - t.Fatalf("Could not parse public key: %v", err) - } - - err, _ = up.FromStream(bytes.NewReader(newFile)) - if err == nil { - t.Fatalf("Allowed an update with no signautre when a public key was specified!") - } -} diff --git a/Godeps/_workspace/src/github.com/kardianos/osext/LICENSE b/Godeps/_workspace/src/github.com/kardianos/osext/LICENSE deleted file mode 100644 index 74487567632..00000000000 --- a/Godeps/_workspace/src/github.com/kardianos/osext/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2012 The Go Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the name of Google Inc. nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/Godeps/_workspace/src/github.com/kardianos/osext/README.md b/Godeps/_workspace/src/github.com/kardianos/osext/README.md deleted file mode 100644 index 820e1ecb544..00000000000 --- a/Godeps/_workspace/src/github.com/kardianos/osext/README.md +++ /dev/null @@ -1,14 +0,0 @@ -### Extensions to the "os" package. - -## Find the current Executable and ExecutableFolder. - -There is sometimes utility in finding the current executable file -that is running. This can be used for upgrading the current executable -or finding resources located relative to the executable file. - -Multi-platform and supports: - * Linux - * OS X - * Windows - * Plan 9 - * BSDs. diff --git a/Godeps/_workspace/src/github.com/kardianos/osext/osext.go b/Godeps/_workspace/src/github.com/kardianos/osext/osext.go deleted file mode 100644 index 4ed4b9aa334..00000000000 --- a/Godeps/_workspace/src/github.com/kardianos/osext/osext.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2012 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Extensions to the standard "os" package. -package osext - -import "path/filepath" - -// Executable returns an absolute path that can be used to -// re-invoke the current program. -// It may not be valid after the current program exits. -func Executable() (string, error) { - p, err := executable() - return filepath.Clean(p), err -} - -// Returns same path as Executable, returns just the folder -// path. Excludes the executable name. -func ExecutableFolder() (string, error) { - p, err := Executable() - if err != nil { - return "", err - } - folder, _ := filepath.Split(p) - return folder, nil -} diff --git a/Godeps/_workspace/src/github.com/kardianos/osext/osext_plan9.go b/Godeps/_workspace/src/github.com/kardianos/osext/osext_plan9.go deleted file mode 100644 index 655750c5426..00000000000 --- a/Godeps/_workspace/src/github.com/kardianos/osext/osext_plan9.go +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2012 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package osext - -import ( - "os" - "strconv" - "syscall" -) - -func executable() (string, error) { - f, err := os.Open("/proc/" + strconv.Itoa(os.Getpid()) + "/text") - if err != nil { - return "", err - } - defer f.Close() - return syscall.Fd2path(int(f.Fd())) -} diff --git a/Godeps/_workspace/src/github.com/kardianos/osext/osext_procfs.go b/Godeps/_workspace/src/github.com/kardianos/osext/osext_procfs.go deleted file mode 100644 index b2598bc77a4..00000000000 --- a/Godeps/_workspace/src/github.com/kardianos/osext/osext_procfs.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2012 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build linux netbsd openbsd solaris dragonfly - -package osext - -import ( - "errors" - "fmt" - "os" - "runtime" - "strings" -) - -func executable() (string, error) { - switch runtime.GOOS { - case "linux": - const deletedTag = " (deleted)" - execpath, err := os.Readlink("/proc/self/exe") - if err != nil { - return execpath, err - } - execpath = strings.TrimSuffix(execpath, deletedTag) - execpath = strings.TrimPrefix(execpath, deletedTag) - return execpath, nil - case "netbsd": - return os.Readlink("/proc/curproc/exe") - case "openbsd", "dragonfly": - return os.Readlink("/proc/curproc/file") - case "solaris": - return os.Readlink(fmt.Sprintf("/proc/%d/path/a.out", os.Getpid())) - } - return "", errors.New("ExecPath not implemented for " + runtime.GOOS) -} diff --git a/Godeps/_workspace/src/github.com/kardianos/osext/osext_sysctl.go b/Godeps/_workspace/src/github.com/kardianos/osext/osext_sysctl.go deleted file mode 100644 index b66cac878c4..00000000000 --- a/Godeps/_workspace/src/github.com/kardianos/osext/osext_sysctl.go +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright 2012 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build darwin freebsd - -package osext - -import ( - "os" - "path/filepath" - "runtime" - "syscall" - "unsafe" -) - -var initCwd, initCwdErr = os.Getwd() - -func executable() (string, error) { - var mib [4]int32 - switch runtime.GOOS { - case "freebsd": - mib = [4]int32{1 /* CTL_KERN */, 14 /* KERN_PROC */, 12 /* KERN_PROC_PATHNAME */, -1} - case "darwin": - mib = [4]int32{1 /* CTL_KERN */, 38 /* KERN_PROCARGS */, int32(os.Getpid()), -1} - } - - n := uintptr(0) - // Get length. - _, _, errNum := syscall.Syscall6(syscall.SYS___SYSCTL, uintptr(unsafe.Pointer(&mib[0])), 4, 0, uintptr(unsafe.Pointer(&n)), 0, 0) - if errNum != 0 { - return "", errNum - } - if n == 0 { // This shouldn't happen. - return "", nil - } - buf := make([]byte, n) - _, _, errNum = syscall.Syscall6(syscall.SYS___SYSCTL, uintptr(unsafe.Pointer(&mib[0])), 4, uintptr(unsafe.Pointer(&buf[0])), uintptr(unsafe.Pointer(&n)), 0, 0) - if errNum != 0 { - return "", errNum - } - if n == 0 { // This shouldn't happen. - return "", nil - } - for i, v := range buf { - if v == 0 { - buf = buf[:i] - break - } - } - var err error - execPath := string(buf) - // execPath will not be empty due to above checks. - // Try to get the absolute path if the execPath is not rooted. - if execPath[0] != '/' { - execPath, err = getAbs(execPath) - if err != nil { - return execPath, err - } - } - // For darwin KERN_PROCARGS may return the path to a symlink rather than the - // actual executable. - if runtime.GOOS == "darwin" { - if execPath, err = filepath.EvalSymlinks(execPath); err != nil { - return execPath, err - } - } - return execPath, nil -} - -func getAbs(execPath string) (string, error) { - if initCwdErr != nil { - return execPath, initCwdErr - } - // The execPath may begin with a "../" or a "./" so clean it first. - // Join the two paths, trailing and starting slashes undetermined, so use - // the generic Join function. - return filepath.Join(initCwd, filepath.Clean(execPath)), nil -} diff --git a/Godeps/_workspace/src/github.com/kardianos/osext/osext_test.go b/Godeps/_workspace/src/github.com/kardianos/osext/osext_test.go deleted file mode 100644 index 5aafa3af2d2..00000000000 --- a/Godeps/_workspace/src/github.com/kardianos/osext/osext_test.go +++ /dev/null @@ -1,180 +0,0 @@ -// Copyright 2012 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build darwin linux freebsd netbsd windows - -package osext - -import ( - "bytes" - "fmt" - "io" - "os" - "os/exec" - "path/filepath" - "runtime" - "testing" -) - -const ( - executableEnvVar = "OSTEST_OUTPUT_EXECUTABLE" - - executableEnvValueMatch = "match" - executableEnvValueDelete = "delete" -) - -func TestExecutableMatch(t *testing.T) { - ep, err := Executable() - if err != nil { - t.Fatalf("Executable failed: %v", err) - } - - // fullpath to be of the form "dir/prog". - dir := filepath.Dir(filepath.Dir(ep)) - fullpath, err := filepath.Rel(dir, ep) - if err != nil { - t.Fatalf("filepath.Rel: %v", err) - } - // Make child start with a relative program path. - // Alter argv[0] for child to verify getting real path without argv[0]. - cmd := &exec.Cmd{ - Dir: dir, - Path: fullpath, - Env: []string{fmt.Sprintf("%s=%s", executableEnvVar, executableEnvValueMatch)}, - } - out, err := cmd.CombinedOutput() - if err != nil { - t.Fatalf("exec(self) failed: %v", err) - } - outs := string(out) - if !filepath.IsAbs(outs) { - t.Fatalf("Child returned %q, want an absolute path", out) - } - if !sameFile(outs, ep) { - t.Fatalf("Child returned %q, not the same file as %q", out, ep) - } -} - -func TestExecutableDelete(t *testing.T) { - if runtime.GOOS != "linux" { - t.Skip() - } - fpath, err := Executable() - if err != nil { - t.Fatalf("Executable failed: %v", err) - } - - r, w := io.Pipe() - stderrBuff := &bytes.Buffer{} - stdoutBuff := &bytes.Buffer{} - cmd := &exec.Cmd{ - Path: fpath, - Env: []string{fmt.Sprintf("%s=%s", executableEnvVar, executableEnvValueDelete)}, - Stdin: r, - Stderr: stderrBuff, - Stdout: stdoutBuff, - } - err = cmd.Start() - if err != nil { - t.Fatalf("exec(self) start failed: %v", err) - } - - tempPath := fpath + "_copy" - _ = os.Remove(tempPath) - - err = copyFile(tempPath, fpath) - if err != nil { - t.Fatalf("copy file failed: %v", err) - } - err = os.Remove(fpath) - if err != nil { - t.Fatalf("remove running test file failed: %v", err) - } - err = os.Rename(tempPath, fpath) - if err != nil { - t.Fatalf("rename copy to previous name failed: %v", err) - } - - w.Write([]byte{0}) - w.Close() - - err = cmd.Wait() - if err != nil { - t.Fatalf("exec wait failed: %v", err) - } - - childPath := stderrBuff.String() - if !filepath.IsAbs(childPath) { - t.Fatalf("Child returned %q, want an absolute path", childPath) - } - if !sameFile(childPath, fpath) { - t.Fatalf("Child returned %q, not the same file as %q", childPath, fpath) - } -} - -func sameFile(fn1, fn2 string) bool { - fi1, err := os.Stat(fn1) - if err != nil { - return false - } - fi2, err := os.Stat(fn2) - if err != nil { - return false - } - return os.SameFile(fi1, fi2) -} -func copyFile(dest, src string) error { - df, err := os.Create(dest) - if err != nil { - return err - } - defer df.Close() - - sf, err := os.Open(src) - if err != nil { - return err - } - defer sf.Close() - - _, err = io.Copy(df, sf) - return err -} - -func TestMain(m *testing.M) { - env := os.Getenv(executableEnvVar) - switch env { - case "": - os.Exit(m.Run()) - case executableEnvValueMatch: - // First chdir to another path. - dir := "/" - if runtime.GOOS == "windows" { - dir = filepath.VolumeName(".") - } - os.Chdir(dir) - if ep, err := Executable(); err != nil { - fmt.Fprint(os.Stderr, "ERROR: ", err) - } else { - fmt.Fprint(os.Stderr, ep) - } - case executableEnvValueDelete: - bb := make([]byte, 1) - var err error - n, err := os.Stdin.Read(bb) - if err != nil { - fmt.Fprint(os.Stderr, "ERROR: ", err) - os.Exit(2) - } - if n != 1 { - fmt.Fprint(os.Stderr, "ERROR: n != 1, n == ", n) - os.Exit(2) - } - if ep, err := Executable(); err != nil { - fmt.Fprint(os.Stderr, "ERROR: ", err) - } else { - fmt.Fprint(os.Stderr, ep) - } - } - os.Exit(0) -} diff --git a/Godeps/_workspace/src/github.com/kardianos/osext/osext_windows.go b/Godeps/_workspace/src/github.com/kardianos/osext/osext_windows.go deleted file mode 100644 index 72d282cf8c0..00000000000 --- a/Godeps/_workspace/src/github.com/kardianos/osext/osext_windows.go +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2012 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package osext - -import ( - "syscall" - "unicode/utf16" - "unsafe" -) - -var ( - kernel = syscall.MustLoadDLL("kernel32.dll") - getModuleFileNameProc = kernel.MustFindProc("GetModuleFileNameW") -) - -// GetModuleFileName() with hModule = NULL -func executable() (exePath string, err error) { - return getModuleFileName() -} - -func getModuleFileName() (string, error) { - var n uint32 - b := make([]uint16, syscall.MAX_PATH) - size := uint32(len(b)) - - r0, _, e1 := getModuleFileNameProc.Call(0, uintptr(unsafe.Pointer(&b[0])), uintptr(size)) - n = uint32(r0) - if n == 0 { - return "", e1 - } - return string(utf16.Decode(b[0:n])), nil -} diff --git a/Godeps/_workspace/src/github.com/kr/binarydist/.gitignore b/Godeps/_workspace/src/github.com/kr/binarydist/.gitignore deleted file mode 100644 index 653f1601457..00000000000 --- a/Godeps/_workspace/src/github.com/kr/binarydist/.gitignore +++ /dev/null @@ -1 +0,0 @@ -test.* diff --git a/Godeps/_workspace/src/github.com/kr/binarydist/License b/Godeps/_workspace/src/github.com/kr/binarydist/License deleted file mode 100644 index 183c3898c36..00000000000 --- a/Godeps/_workspace/src/github.com/kr/binarydist/License +++ /dev/null @@ -1,22 +0,0 @@ -Copyright 2012 Keith Rarick - -Permission is hereby granted, free of charge, to any person -obtaining a copy of this software and associated documentation -files (the "Software"), to deal in the Software without -restriction, including without limitation the rights to use, -copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. diff --git a/Godeps/_workspace/src/github.com/kr/binarydist/Readme.md b/Godeps/_workspace/src/github.com/kr/binarydist/Readme.md deleted file mode 100644 index dadc3683de5..00000000000 --- a/Godeps/_workspace/src/github.com/kr/binarydist/Readme.md +++ /dev/null @@ -1,7 +0,0 @@ -# binarydist - -Package binarydist implements binary diff and patch as described on -. It reads and writes files -compatible with the tools there. - -Documentation at . diff --git a/Godeps/_workspace/src/github.com/kr/binarydist/bzip2.go b/Godeps/_workspace/src/github.com/kr/binarydist/bzip2.go deleted file mode 100644 index a2516b81df2..00000000000 --- a/Godeps/_workspace/src/github.com/kr/binarydist/bzip2.go +++ /dev/null @@ -1,40 +0,0 @@ -package binarydist - -import ( - "io" - "os/exec" -) - -type bzip2Writer struct { - c *exec.Cmd - w io.WriteCloser -} - -func (w bzip2Writer) Write(b []byte) (int, error) { - return w.w.Write(b) -} - -func (w bzip2Writer) Close() error { - if err := w.w.Close(); err != nil { - return err - } - return w.c.Wait() -} - -// Package compress/bzip2 implements only decompression, -// so we'll fake it by running bzip2 in another process. -func newBzip2Writer(w io.Writer) (wc io.WriteCloser, err error) { - var bw bzip2Writer - bw.c = exec.Command("bzip2", "-c") - bw.c.Stdout = w - - if bw.w, err = bw.c.StdinPipe(); err != nil { - return nil, err - } - - if err = bw.c.Start(); err != nil { - return nil, err - } - - return bw, nil -} diff --git a/Godeps/_workspace/src/github.com/kr/binarydist/common_test.go b/Godeps/_workspace/src/github.com/kr/binarydist/common_test.go deleted file mode 100644 index af5161668d7..00000000000 --- a/Godeps/_workspace/src/github.com/kr/binarydist/common_test.go +++ /dev/null @@ -1,93 +0,0 @@ -package binarydist - -import ( - "crypto/rand" - "io" - "io/ioutil" - "os" -) - -func mustOpen(path string) *os.File { - f, err := os.Open(path) - if err != nil { - panic(err) - } - - return f -} - -func mustReadAll(r io.Reader) []byte { - b, err := ioutil.ReadAll(r) - if err != nil { - panic(err) - } - return b -} - -func fileCmp(a, b *os.File) int64 { - sa, err := a.Seek(0, 2) - if err != nil { - panic(err) - } - - sb, err := b.Seek(0, 2) - if err != nil { - panic(err) - } - - if sa != sb { - return sa - } - - _, err = a.Seek(0, 0) - if err != nil { - panic(err) - } - - _, err = b.Seek(0, 0) - if err != nil { - panic(err) - } - - pa, err := ioutil.ReadAll(a) - if err != nil { - panic(err) - } - - pb, err := ioutil.ReadAll(b) - if err != nil { - panic(err) - } - - for i := range pa { - if pa[i] != pb[i] { - return int64(i) - } - } - return -1 -} - -func mustWriteRandFile(path string, size int) *os.File { - p := make([]byte, size) - _, err := rand.Read(p) - if err != nil { - panic(err) - } - - f, err := os.Create(path) - if err != nil { - panic(err) - } - - _, err = f.Write(p) - if err != nil { - panic(err) - } - - _, err = f.Seek(0, 0) - if err != nil { - panic(err) - } - - return f -} diff --git a/Godeps/_workspace/src/github.com/kr/binarydist/diff.go b/Godeps/_workspace/src/github.com/kr/binarydist/diff.go deleted file mode 100644 index 1d2d951bb4d..00000000000 --- a/Godeps/_workspace/src/github.com/kr/binarydist/diff.go +++ /dev/null @@ -1,408 +0,0 @@ -package binarydist - -import ( - "bytes" - "encoding/binary" - "io" - "io/ioutil" -) - -func swap(a []int, i, j int) { a[i], a[j] = a[j], a[i] } - -func split(I, V []int, start, length, h int) { - var i, j, k, x, jj, kk int - - if length < 16 { - for k = start; k < start+length; k += j { - j = 1 - x = V[I[k]+h] - for i = 1; k+i < start+length; i++ { - if V[I[k+i]+h] < x { - x = V[I[k+i]+h] - j = 0 - } - if V[I[k+i]+h] == x { - swap(I, k+i, k+j) - j++ - } - } - for i = 0; i < j; i++ { - V[I[k+i]] = k + j - 1 - } - if j == 1 { - I[k] = -1 - } - } - return - } - - x = V[I[start+length/2]+h] - jj = 0 - kk = 0 - for i = start; i < start+length; i++ { - if V[I[i]+h] < x { - jj++ - } - if V[I[i]+h] == x { - kk++ - } - } - jj += start - kk += jj - - i = start - j = 0 - k = 0 - for i < jj { - if V[I[i]+h] < x { - i++ - } else if V[I[i]+h] == x { - swap(I, i, jj+j) - j++ - } else { - swap(I, i, kk+k) - k++ - } - } - - for jj+j < kk { - if V[I[jj+j]+h] == x { - j++ - } else { - swap(I, jj+j, kk+k) - k++ - } - } - - if jj > start { - split(I, V, start, jj-start, h) - } - - for i = 0; i < kk-jj; i++ { - V[I[jj+i]] = kk - 1 - } - if jj == kk-1 { - I[jj] = -1 - } - - if start+length > kk { - split(I, V, kk, start+length-kk, h) - } -} - -func qsufsort(obuf []byte) []int { - var buckets [256]int - var i, h int - I := make([]int, len(obuf)+1) - V := make([]int, len(obuf)+1) - - for _, c := range obuf { - buckets[c]++ - } - for i = 1; i < 256; i++ { - buckets[i] += buckets[i-1] - } - copy(buckets[1:], buckets[:]) - buckets[0] = 0 - - for i, c := range obuf { - buckets[c]++ - I[buckets[c]] = i - } - - I[0] = len(obuf) - for i, c := range obuf { - V[i] = buckets[c] - } - - V[len(obuf)] = 0 - for i = 1; i < 256; i++ { - if buckets[i] == buckets[i-1]+1 { - I[buckets[i]] = -1 - } - } - I[0] = -1 - - for h = 1; I[0] != -(len(obuf) + 1); h += h { - var n int - for i = 0; i < len(obuf)+1; { - if I[i] < 0 { - n -= I[i] - i -= I[i] - } else { - if n != 0 { - I[i-n] = -n - } - n = V[I[i]] + 1 - i - split(I, V, i, n, h) - i += n - n = 0 - } - } - if n != 0 { - I[i-n] = -n - } - } - - for i = 0; i < len(obuf)+1; i++ { - I[V[i]] = i - } - return I -} - -func matchlen(a, b []byte) (i int) { - for i < len(a) && i < len(b) && a[i] == b[i] { - i++ - } - return i -} - -func search(I []int, obuf, nbuf []byte, st, en int) (pos, n int) { - if en-st < 2 { - x := matchlen(obuf[I[st]:], nbuf) - y := matchlen(obuf[I[en]:], nbuf) - - if x > y { - return I[st], x - } else { - return I[en], y - } - } - - x := st + (en-st)/2 - if bytes.Compare(obuf[I[x]:], nbuf) < 0 { - return search(I, obuf, nbuf, x, en) - } else { - return search(I, obuf, nbuf, st, x) - } - panic("unreached") -} - -// Diff computes the difference between old and new, according to the bsdiff -// algorithm, and writes the result to patch. -func Diff(old, new io.Reader, patch io.Writer) error { - obuf, err := ioutil.ReadAll(old) - if err != nil { - return err - } - - nbuf, err := ioutil.ReadAll(new) - if err != nil { - return err - } - - pbuf, err := diffBytes(obuf, nbuf) - if err != nil { - return err - } - - _, err = patch.Write(pbuf) - return err -} - -func diffBytes(obuf, nbuf []byte) ([]byte, error) { - var patch seekBuffer - err := diff(obuf, nbuf, &patch) - if err != nil { - return nil, err - } - return patch.buf, nil -} - -func diff(obuf, nbuf []byte, patch io.WriteSeeker) error { - var lenf int - I := qsufsort(obuf) - db := make([]byte, len(nbuf)) - eb := make([]byte, len(nbuf)) - var dblen, eblen int - - var hdr header - hdr.Magic = magic - hdr.NewSize = int64(len(nbuf)) - err := binary.Write(patch, signMagLittleEndian{}, &hdr) - if err != nil { - return err - } - - // Compute the differences, writing ctrl as we go - pfbz2, err := newBzip2Writer(patch) - if err != nil { - return err - } - var scan, pos, length int - var lastscan, lastpos, lastoffset int - for scan < len(nbuf) { - var oldscore int - scan += length - for scsc := scan; scan < len(nbuf); scan++ { - pos, length = search(I, obuf, nbuf[scan:], 0, len(obuf)) - - for ; scsc < scan+length; scsc++ { - if scsc+lastoffset < len(obuf) && - obuf[scsc+lastoffset] == nbuf[scsc] { - oldscore++ - } - } - - if (length == oldscore && length != 0) || length > oldscore+8 { - break - } - - if scan+lastoffset < len(obuf) && obuf[scan+lastoffset] == nbuf[scan] { - oldscore-- - } - } - - if length != oldscore || scan == len(nbuf) { - var s, Sf int - lenf = 0 - for i := 0; lastscan+i < scan && lastpos+i < len(obuf); { - if obuf[lastpos+i] == nbuf[lastscan+i] { - s++ - } - i++ - if s*2-i > Sf*2-lenf { - Sf = s - lenf = i - } - } - - lenb := 0 - if scan < len(nbuf) { - var s, Sb int - for i := 1; (scan >= lastscan+i) && (pos >= i); i++ { - if obuf[pos-i] == nbuf[scan-i] { - s++ - } - if s*2-i > Sb*2-lenb { - Sb = s - lenb = i - } - } - } - - if lastscan+lenf > scan-lenb { - overlap := (lastscan + lenf) - (scan - lenb) - s := 0 - Ss := 0 - lens := 0 - for i := 0; i < overlap; i++ { - if nbuf[lastscan+lenf-overlap+i] == obuf[lastpos+lenf-overlap+i] { - s++ - } - if nbuf[scan-lenb+i] == obuf[pos-lenb+i] { - s-- - } - if s > Ss { - Ss = s - lens = i + 1 - } - } - - lenf += lens - overlap - lenb -= lens - } - - for i := 0; i < lenf; i++ { - db[dblen+i] = nbuf[lastscan+i] - obuf[lastpos+i] - } - for i := 0; i < (scan-lenb)-(lastscan+lenf); i++ { - eb[eblen+i] = nbuf[lastscan+lenf+i] - } - - dblen += lenf - eblen += (scan - lenb) - (lastscan + lenf) - - err = binary.Write(pfbz2, signMagLittleEndian{}, int64(lenf)) - if err != nil { - pfbz2.Close() - return err - } - - val := (scan - lenb) - (lastscan + lenf) - err = binary.Write(pfbz2, signMagLittleEndian{}, int64(val)) - if err != nil { - pfbz2.Close() - return err - } - - val = (pos - lenb) - (lastpos + lenf) - err = binary.Write(pfbz2, signMagLittleEndian{}, int64(val)) - if err != nil { - pfbz2.Close() - return err - } - - lastscan = scan - lenb - lastpos = pos - lenb - lastoffset = pos - scan - } - } - err = pfbz2.Close() - if err != nil { - return err - } - - // Compute size of compressed ctrl data - l64, err := patch.Seek(0, 1) - if err != nil { - return err - } - hdr.CtrlLen = int64(l64 - 32) - - // Write compressed diff data - pfbz2, err = newBzip2Writer(patch) - if err != nil { - return err - } - n, err := pfbz2.Write(db[:dblen]) - if err != nil { - pfbz2.Close() - return err - } - if n != dblen { - pfbz2.Close() - return io.ErrShortWrite - } - err = pfbz2.Close() - if err != nil { - return err - } - - // Compute size of compressed diff data - n64, err := patch.Seek(0, 1) - if err != nil { - return err - } - hdr.DiffLen = n64 - l64 - - // Write compressed extra data - pfbz2, err = newBzip2Writer(patch) - if err != nil { - return err - } - n, err = pfbz2.Write(eb[:eblen]) - if err != nil { - pfbz2.Close() - return err - } - if n != eblen { - pfbz2.Close() - return io.ErrShortWrite - } - err = pfbz2.Close() - if err != nil { - return err - } - - // Seek to the beginning, write the header, and close the file - _, err = patch.Seek(0, 0) - if err != nil { - return err - } - err = binary.Write(patch, signMagLittleEndian{}, &hdr) - if err != nil { - return err - } - return nil -} diff --git a/Godeps/_workspace/src/github.com/kr/binarydist/diff_test.go b/Godeps/_workspace/src/github.com/kr/binarydist/diff_test.go deleted file mode 100644 index 9baa4926d8c..00000000000 --- a/Godeps/_workspace/src/github.com/kr/binarydist/diff_test.go +++ /dev/null @@ -1,67 +0,0 @@ -package binarydist - -import ( - "bytes" - "io/ioutil" - "os" - "os/exec" - "testing" -) - -var diffT = []struct { - old *os.File - new *os.File -}{ - { - old: mustWriteRandFile("test.old", 1e3), - new: mustWriteRandFile("test.new", 1e3), - }, - { - old: mustOpen("testdata/sample.old"), - new: mustOpen("testdata/sample.new"), - }, -} - -func TestDiff(t *testing.T) { - for _, s := range diffT { - got, err := ioutil.TempFile("/tmp", "bspatch.") - if err != nil { - panic(err) - } - os.Remove(got.Name()) - - exp, err := ioutil.TempFile("/tmp", "bspatch.") - if err != nil { - panic(err) - } - - cmd := exec.Command("bsdiff", s.old.Name(), s.new.Name(), exp.Name()) - cmd.Stdout = os.Stdout - err = cmd.Run() - os.Remove(exp.Name()) - if err != nil { - panic(err) - } - - err = Diff(s.old, s.new, got) - if err != nil { - t.Fatal("err", err) - } - - _, err = got.Seek(0, 0) - if err != nil { - panic(err) - } - gotBuf := mustReadAll(got) - expBuf := mustReadAll(exp) - - if !bytes.Equal(gotBuf, expBuf) { - t.Fail() - t.Logf("diff %s %s", s.old.Name(), s.new.Name()) - t.Logf("%s: len(got) = %d", got.Name(), len(gotBuf)) - t.Logf("%s: len(exp) = %d", exp.Name(), len(expBuf)) - i := matchlen(gotBuf, expBuf) - t.Logf("produced different output at pos %d; %d != %d", i, gotBuf[i], expBuf[i]) - } - } -} diff --git a/Godeps/_workspace/src/github.com/kr/binarydist/doc.go b/Godeps/_workspace/src/github.com/kr/binarydist/doc.go deleted file mode 100644 index 3c92d875005..00000000000 --- a/Godeps/_workspace/src/github.com/kr/binarydist/doc.go +++ /dev/null @@ -1,24 +0,0 @@ -// Package binarydist implements binary diff and patch as described on -// http://www.daemonology.net/bsdiff/. It reads and writes files -// compatible with the tools there. -package binarydist - -var magic = [8]byte{'B', 'S', 'D', 'I', 'F', 'F', '4', '0'} - -// File format: -// 0 8 "BSDIFF40" -// 8 8 X -// 16 8 Y -// 24 8 sizeof(newfile) -// 32 X bzip2(control block) -// 32+X Y bzip2(diff block) -// 32+X+Y ??? bzip2(extra block) -// with control block a set of triples (x,y,z) meaning "add x bytes -// from oldfile to x bytes from the diff block; copy y bytes from the -// extra block; seek forwards in oldfile by z bytes". -type header struct { - Magic [8]byte - CtrlLen int64 - DiffLen int64 - NewSize int64 -} diff --git a/Godeps/_workspace/src/github.com/kr/binarydist/encoding.go b/Godeps/_workspace/src/github.com/kr/binarydist/encoding.go deleted file mode 100644 index 75ba5856a62..00000000000 --- a/Godeps/_workspace/src/github.com/kr/binarydist/encoding.go +++ /dev/null @@ -1,53 +0,0 @@ -package binarydist - -// SignMagLittleEndian is the numeric encoding used by the bsdiff tools. -// It implements binary.ByteOrder using a sign-magnitude format -// and little-endian byte order. Only methods Uint64 and String -// have been written; the rest panic. -type signMagLittleEndian struct{} - -func (signMagLittleEndian) Uint16(b []byte) uint16 { panic("unimplemented") } - -func (signMagLittleEndian) PutUint16(b []byte, v uint16) { panic("unimplemented") } - -func (signMagLittleEndian) Uint32(b []byte) uint32 { panic("unimplemented") } - -func (signMagLittleEndian) PutUint32(b []byte, v uint32) { panic("unimplemented") } - -func (signMagLittleEndian) Uint64(b []byte) uint64 { - y := int64(b[0]) | - int64(b[1])<<8 | - int64(b[2])<<16 | - int64(b[3])<<24 | - int64(b[4])<<32 | - int64(b[5])<<40 | - int64(b[6])<<48 | - int64(b[7]&0x7f)<<56 - - if b[7]&0x80 != 0 { - y = -y - } - return uint64(y) -} - -func (signMagLittleEndian) PutUint64(b []byte, v uint64) { - x := int64(v) - neg := x < 0 - if neg { - x = -x - } - - b[0] = byte(x) - b[1] = byte(x >> 8) - b[2] = byte(x >> 16) - b[3] = byte(x >> 24) - b[4] = byte(x >> 32) - b[5] = byte(x >> 40) - b[6] = byte(x >> 48) - b[7] = byte(x >> 56) - if neg { - b[7] |= 0x80 - } -} - -func (signMagLittleEndian) String() string { return "signMagLittleEndian" } diff --git a/Godeps/_workspace/src/github.com/kr/binarydist/patch.go b/Godeps/_workspace/src/github.com/kr/binarydist/patch.go deleted file mode 100644 index eb0322578be..00000000000 --- a/Godeps/_workspace/src/github.com/kr/binarydist/patch.go +++ /dev/null @@ -1,109 +0,0 @@ -package binarydist - -import ( - "bytes" - "compress/bzip2" - "encoding/binary" - "errors" - "io" - "io/ioutil" -) - -var ErrCorrupt = errors.New("corrupt patch") - -// Patch applies patch to old, according to the bspatch algorithm, -// and writes the result to new. -func Patch(old io.Reader, new io.Writer, patch io.Reader) error { - var hdr header - err := binary.Read(patch, signMagLittleEndian{}, &hdr) - if err != nil { - return err - } - if hdr.Magic != magic { - return ErrCorrupt - } - if hdr.CtrlLen < 0 || hdr.DiffLen < 0 || hdr.NewSize < 0 { - return ErrCorrupt - } - - ctrlbuf := make([]byte, hdr.CtrlLen) - _, err = io.ReadFull(patch, ctrlbuf) - if err != nil { - return err - } - cpfbz2 := bzip2.NewReader(bytes.NewReader(ctrlbuf)) - - diffbuf := make([]byte, hdr.DiffLen) - _, err = io.ReadFull(patch, diffbuf) - if err != nil { - return err - } - dpfbz2 := bzip2.NewReader(bytes.NewReader(diffbuf)) - - // The entire rest of the file is the extra block. - epfbz2 := bzip2.NewReader(patch) - - obuf, err := ioutil.ReadAll(old) - if err != nil { - return err - } - - nbuf := make([]byte, hdr.NewSize) - - var oldpos, newpos int64 - for newpos < hdr.NewSize { - var ctrl struct{ Add, Copy, Seek int64 } - err = binary.Read(cpfbz2, signMagLittleEndian{}, &ctrl) - if err != nil { - return err - } - - // Sanity-check - if newpos+ctrl.Add > hdr.NewSize { - return ErrCorrupt - } - - // Read diff string - _, err = io.ReadFull(dpfbz2, nbuf[newpos:newpos+ctrl.Add]) - if err != nil { - return ErrCorrupt - } - - // Add old data to diff string - for i := int64(0); i < ctrl.Add; i++ { - if oldpos+i >= 0 && oldpos+i < int64(len(obuf)) { - nbuf[newpos+i] += obuf[oldpos+i] - } - } - - // Adjust pointers - newpos += ctrl.Add - oldpos += ctrl.Add - - // Sanity-check - if newpos+ctrl.Copy > hdr.NewSize { - return ErrCorrupt - } - - // Read extra string - _, err = io.ReadFull(epfbz2, nbuf[newpos:newpos+ctrl.Copy]) - if err != nil { - return ErrCorrupt - } - - // Adjust pointers - newpos += ctrl.Copy - oldpos += ctrl.Seek - } - - // Write the new file - for len(nbuf) > 0 { - n, err := new.Write(nbuf) - if err != nil { - return err - } - nbuf = nbuf[n:] - } - - return nil -} diff --git a/Godeps/_workspace/src/github.com/kr/binarydist/patch_test.go b/Godeps/_workspace/src/github.com/kr/binarydist/patch_test.go deleted file mode 100644 index 840a919e209..00000000000 --- a/Godeps/_workspace/src/github.com/kr/binarydist/patch_test.go +++ /dev/null @@ -1,62 +0,0 @@ -package binarydist - -import ( - "io/ioutil" - "os" - "os/exec" - "testing" -) - -func TestPatch(t *testing.T) { - mustWriteRandFile("test.old", 1e3) - mustWriteRandFile("test.new", 1e3) - - got, err := ioutil.TempFile("/tmp", "bspatch.") - if err != nil { - panic(err) - } - os.Remove(got.Name()) - - err = exec.Command("bsdiff", "test.old", "test.new", "test.patch").Run() - if err != nil { - panic(err) - } - - err = Patch(mustOpen("test.old"), got, mustOpen("test.patch")) - if err != nil { - t.Fatal("err", err) - } - - ref, err := got.Seek(0, 2) - if err != nil { - panic(err) - } - - t.Logf("got %d bytes", ref) - if n := fileCmp(got, mustOpen("test.new")); n > -1 { - t.Fatalf("produced different output at pos %d", n) - } -} - -func TestPatchHk(t *testing.T) { - got, err := ioutil.TempFile("/tmp", "bspatch.") - if err != nil { - panic(err) - } - os.Remove(got.Name()) - - err = Patch(mustOpen("testdata/sample.old"), got, mustOpen("testdata/sample.patch")) - if err != nil { - t.Fatal("err", err) - } - - ref, err := got.Seek(0, 2) - if err != nil { - panic(err) - } - - t.Logf("got %d bytes", ref) - if n := fileCmp(got, mustOpen("testdata/sample.new")); n > -1 { - t.Fatalf("produced different output at pos %d", n) - } -} diff --git a/Godeps/_workspace/src/github.com/kr/binarydist/seek.go b/Godeps/_workspace/src/github.com/kr/binarydist/seek.go deleted file mode 100644 index 96c03461e4e..00000000000 --- a/Godeps/_workspace/src/github.com/kr/binarydist/seek.go +++ /dev/null @@ -1,43 +0,0 @@ -package binarydist - -import ( - "errors" -) - -type seekBuffer struct { - buf []byte - pos int -} - -func (b *seekBuffer) Write(p []byte) (n int, err error) { - n = copy(b.buf[b.pos:], p) - if n == len(p) { - b.pos += n - return n, nil - } - b.buf = append(b.buf, p[n:]...) - b.pos += len(p) - return len(p), nil -} - -func (b *seekBuffer) Seek(offset int64, whence int) (ret int64, err error) { - var abs int64 - switch whence { - case 0: - abs = offset - case 1: - abs = int64(b.pos) + offset - case 2: - abs = int64(len(b.buf)) + offset - default: - return 0, errors.New("binarydist: invalid whence") - } - if abs < 0 { - return 0, errors.New("binarydist: negative position") - } - if abs >= 1<<31 { - return 0, errors.New("binarydist: position out of range") - } - b.pos = int(abs) - return abs, nil -} diff --git a/Godeps/_workspace/src/github.com/kr/binarydist/sort_test.go b/Godeps/_workspace/src/github.com/kr/binarydist/sort_test.go deleted file mode 100644 index be483c3a262..00000000000 --- a/Godeps/_workspace/src/github.com/kr/binarydist/sort_test.go +++ /dev/null @@ -1,33 +0,0 @@ -package binarydist - -import ( - "bytes" - "crypto/rand" - "testing" -) - -var sortT = [][]byte{ - mustRandBytes(1000), - mustReadAll(mustOpen("test.old")), - []byte("abcdefabcdef"), -} - -func TestQsufsort(t *testing.T) { - for _, s := range sortT { - I := qsufsort(s) - for i := 1; i < len(I); i++ { - if bytes.Compare(s[I[i-1]:], s[I[i]:]) > 0 { - t.Fatalf("unsorted at %d", i) - } - } - } -} - -func mustRandBytes(n int) []byte { - b := make([]byte, n) - _, err := rand.Read(b) - if err != nil { - panic(err) - } - return b -} diff --git a/Godeps/_workspace/src/github.com/kr/binarydist/testdata/sample.new b/Godeps/_workspace/src/github.com/kr/binarydist/testdata/sample.new deleted file mode 100644 index 592cdbe2dff..00000000000 Binary files a/Godeps/_workspace/src/github.com/kr/binarydist/testdata/sample.new and /dev/null differ diff --git a/Godeps/_workspace/src/github.com/kr/binarydist/testdata/sample.old b/Godeps/_workspace/src/github.com/kr/binarydist/testdata/sample.old deleted file mode 100644 index 7bc64dacb0a..00000000000 Binary files a/Godeps/_workspace/src/github.com/kr/binarydist/testdata/sample.old and /dev/null differ diff --git a/Godeps/_workspace/src/github.com/kr/binarydist/testdata/sample.patch b/Godeps/_workspace/src/github.com/kr/binarydist/testdata/sample.patch deleted file mode 100644 index 516a3a9af68..00000000000 Binary files a/Godeps/_workspace/src/github.com/kr/binarydist/testdata/sample.patch and /dev/null differ diff --git a/Godeps/_workspace/src/github.com/shirou/gopsutil/common/common.go b/Godeps/_workspace/src/github.com/shirou/gopsutil/common/common.go deleted file mode 100644 index a7dbc28eb0d..00000000000 --- a/Godeps/_workspace/src/github.com/shirou/gopsutil/common/common.go +++ /dev/null @@ -1,209 +0,0 @@ -// -// gopsutil is a port of psutil(http://pythonhosted.org/psutil/). -// This covers these architectures. -// - linux (amd64, arm) -// - freebsd (amd64) -// - windows (amd64) -package common - -import ( - "bufio" - "errors" - "io/ioutil" - "net/url" - "os" - "os/exec" - "path" - "reflect" - "runtime" - "strconv" - "strings" -) - -type Invoker interface { - Command(string, ...string) ([]byte, error) -} - -type Invoke struct{} - -func (i Invoke) Command(name string, arg ...string) ([]byte, error) { - return exec.Command(name, arg...).Output() -} - -type FakeInvoke struct { - CommandExpectedDir string // CommandExpectedDir specifies dir which includes expected outputs. - Suffix string // Suffix species expected file name suffix such as "fail" - Error error // If Error specfied, return the error. -} - -// Command in FakeInvoke returns from expected file if exists. -func (i FakeInvoke) Command(name string, arg ...string) ([]byte, error) { - if i.Error != nil { - return []byte{}, i.Error - } - - arch := runtime.GOOS - - fname := strings.Join(append([]string{name}, arg...), "") - fname = url.QueryEscape(fname) - var dir string - if i.CommandExpectedDir == "" { - dir = "expected" - } else { - dir = i.CommandExpectedDir - } - fpath := path.Join(dir, arch, fname) - if i.Suffix != "" { - fpath += "_" + i.Suffix - } - if PathExists(fpath) { - return ioutil.ReadFile(fpath) - } else { - return exec.Command(name, arg...).Output() - } -} - -var NotImplementedError = errors.New("not implemented yet") - -// ReadLines reads contents from a file and splits them by new lines. -// A convenience wrapper to ReadLinesOffsetN(filename, 0, -1). -func ReadLines(filename string) ([]string, error) { - return ReadLinesOffsetN(filename, 0, -1) -} - -// ReadLines reads contents from file and splits them by new line. -// The offset tells at which line number to start. -// The count determines the number of lines to read (starting from offset): -// n >= 0: at most n lines -// n < 0: whole file -func ReadLinesOffsetN(filename string, offset uint, n int) ([]string, error) { - f, err := os.Open(filename) - if err != nil { - return []string{""}, err - } - defer f.Close() - - var ret []string - - r := bufio.NewReader(f) - for i := 0; i < n+int(offset) || n < 0; i++ { - line, err := r.ReadString('\n') - if err != nil { - break - } - if i < int(offset) { - continue - } - ret = append(ret, strings.Trim(line, "\n")) - } - - return ret, nil -} - -func IntToString(orig []int8) string { - ret := make([]byte, len(orig)) - size := -1 - for i, o := range orig { - if o == 0 { - size = i - break - } - ret[i] = byte(o) - } - if size == -1 { - size = len(orig) - } - - return string(ret[0:size]) -} - -func ByteToString(orig []byte) string { - n := -1 - l := -1 - for i, b := range orig { - // skip left side null - if l == -1 && b == 0 { - continue - } - if l == -1 { - l = i - } - - if b == 0 { - break - } - n = i + 1 - } - if n == -1 { - return string(orig) - } - return string(orig[l:n]) -} - -// Parse to int32 without error -func mustParseInt32(val string) int32 { - vv, _ := strconv.ParseInt(val, 10, 32) - return int32(vv) -} - -// Parse to uint64 without error -func mustParseUint64(val string) uint64 { - vv, _ := strconv.ParseInt(val, 10, 64) - return uint64(vv) -} - -// Parse to Float64 without error -func mustParseFloat64(val string) float64 { - vv, _ := strconv.ParseFloat(val, 64) - return vv -} - -// StringsHas checks the target string slice containes src or not -func StringsHas(target []string, src string) bool { - for _, t := range target { - if strings.TrimSpace(t) == src { - return true - } - } - return false -} - -// StringsContains checks the src in any string of the target string slice -func StringsContains(target []string, src string) bool { - for _, t := range target { - if strings.Contains(t, src) { - return true - } - } - return false -} - -// get struct attributes. -// This method is used only for debugging platform dependent code. -func attributes(m interface{}) map[string]reflect.Type { - typ := reflect.TypeOf(m) - if typ.Kind() == reflect.Ptr { - typ = typ.Elem() - } - - attrs := make(map[string]reflect.Type) - if typ.Kind() != reflect.Struct { - return nil - } - - for i := 0; i < typ.NumField(); i++ { - p := typ.Field(i) - if !p.Anonymous { - attrs[p.Name] = p.Type - } - } - - return attrs -} - -func PathExists(filename string) bool { - if _, err := os.Stat(filename); err == nil { - return true - } - return false -} diff --git a/Godeps/_workspace/src/github.com/shirou/gopsutil/common/common_darwin.go b/Godeps/_workspace/src/github.com/shirou/gopsutil/common/common_darwin.go deleted file mode 100644 index 7d6f3c69269..00000000000 --- a/Godeps/_workspace/src/github.com/shirou/gopsutil/common/common_darwin.go +++ /dev/null @@ -1,60 +0,0 @@ -// +build darwin - -package common - -import ( - "os/exec" - "strings" - "syscall" - "unsafe" -) - -func DoSysctrl(mib string) ([]string, error) { - out, err := exec.Command("/usr/sbin/sysctl", "-n", mib).Output() - if err != nil { - return []string{}, err - } - v := strings.Replace(string(out), "{ ", "", 1) - v = strings.Replace(string(v), " }", "", 1) - values := strings.Fields(string(v)) - - return values, nil -} - -func CallSyscall(mib []int32) ([]byte, uint64, error) { - miblen := uint64(len(mib)) - - // get required buffer size - length := uint64(0) - _, _, err := syscall.Syscall6( - syscall.SYS___SYSCTL, - uintptr(unsafe.Pointer(&mib[0])), - uintptr(miblen), - 0, - uintptr(unsafe.Pointer(&length)), - 0, - 0) - if err != 0 { - var b []byte - return b, length, err - } - if length == 0 { - var b []byte - return b, length, err - } - // get proc info itself - buf := make([]byte, length) - _, _, err = syscall.Syscall6( - syscall.SYS___SYSCTL, - uintptr(unsafe.Pointer(&mib[0])), - uintptr(miblen), - uintptr(unsafe.Pointer(&buf[0])), - uintptr(unsafe.Pointer(&length)), - 0, - 0) - if err != 0 { - return buf, length, err - } - - return buf, length, nil -} diff --git a/Godeps/_workspace/src/github.com/shirou/gopsutil/common/common_freebsd.go b/Godeps/_workspace/src/github.com/shirou/gopsutil/common/common_freebsd.go deleted file mode 100644 index 1b13b3ed193..00000000000 --- a/Godeps/_workspace/src/github.com/shirou/gopsutil/common/common_freebsd.go +++ /dev/null @@ -1,60 +0,0 @@ -// +build freebsd - -package common - -import ( - "syscall" - "os/exec" - "strings" - "unsafe" -) - -func DoSysctrl(mib string) ([]string, error) { - out, err := exec.Command("/sbin/sysctl", "-n", mib).Output() - if err != nil { - return []string{}, err - } - v := strings.Replace(string(out), "{ ", "", 1) - v = strings.Replace(string(v), " }", "", 1) - values := strings.Fields(string(v)) - - return values, nil -} - -func CallSyscall(mib []int32) ([]byte, uint64, error) { - miblen := uint64(len(mib)) - - // get required buffer size - length := uint64(0) - _, _, err := syscall.Syscall6( - syscall.SYS___SYSCTL, - uintptr(unsafe.Pointer(&mib[0])), - uintptr(miblen), - 0, - uintptr(unsafe.Pointer(&length)), - 0, - 0) - if err != 0 { - var b []byte - return b, length, err - } - if length == 0 { - var b []byte - return b, length, err - } - // get proc info itself - buf := make([]byte, length) - _, _, err = syscall.Syscall6( - syscall.SYS___SYSCTL, - uintptr(unsafe.Pointer(&mib[0])), - uintptr(miblen), - uintptr(unsafe.Pointer(&buf[0])), - uintptr(unsafe.Pointer(&length)), - 0, - 0) - if err != 0 { - return buf, length, err - } - - return buf, length, nil -} diff --git a/Godeps/_workspace/src/github.com/shirou/gopsutil/common/common_linux.go b/Godeps/_workspace/src/github.com/shirou/gopsutil/common/common_linux.go deleted file mode 100644 index 0a122e9d6ae..00000000000 --- a/Godeps/_workspace/src/github.com/shirou/gopsutil/common/common_linux.go +++ /dev/null @@ -1,3 +0,0 @@ -// +build linux - -package common diff --git a/Godeps/_workspace/src/github.com/shirou/gopsutil/common/common_test.go b/Godeps/_workspace/src/github.com/shirou/gopsutil/common/common_test.go deleted file mode 100644 index b2660b2af4f..00000000000 --- a/Godeps/_workspace/src/github.com/shirou/gopsutil/common/common_test.go +++ /dev/null @@ -1,90 +0,0 @@ -package common - -import ( - "fmt" - "strings" - "testing" -) - -func TestReadlines(t *testing.T) { - ret, err := ReadLines("common_test.go") - if err != nil { - t.Error(err) - } - if !strings.Contains(ret[0], "package common") { - t.Error("could not read correctly") - } -} - -func TestReadLinesOffsetN(t *testing.T) { - ret, err := ReadLinesOffsetN("common_test.go", 2, 1) - if err != nil { - t.Error(err) - } - fmt.Println(ret[0]) - if !strings.Contains(ret[0], `import (`) { - t.Error("could not read correctly") - } -} - -func TestIntToString(t *testing.T) { - src := []int8{65, 66, 67} - dst := IntToString(src) - if dst != "ABC" { - t.Error("could not convert") - } -} -func TestByteToString(t *testing.T) { - src := []byte{65, 66, 67} - dst := ByteToString(src) - if dst != "ABC" { - t.Error("could not convert") - } - - src = []byte{0, 65, 66, 67} - dst = ByteToString(src) - if dst != "ABC" { - t.Error("could not convert") - } -} - -func TestmustParseInt32(t *testing.T) { - ret := mustParseInt32("11111") - if ret != int32(11111) { - t.Error("could not parse") - } -} -func TestmustParseUint64(t *testing.T) { - ret := mustParseUint64("11111") - if ret != uint64(11111) { - t.Error("could not parse") - } -} -func TestmustParseFloat64(t *testing.T) { - ret := mustParseFloat64("11111.11") - if ret != float64(11111.11) { - t.Error("could not parse") - } - ret = mustParseFloat64("11111") - if ret != float64(11111) { - t.Error("could not parse") - } -} -func TestStringsContains(t *testing.T) { - target, err := ReadLines("common_test.go") - if err != nil { - t.Error(err) - } - if !StringsContains(target, "func TestStringsContains(t *testing.T) {") { - t.Error("cloud not test correctly") - } -} - -func TestPathExists(t *testing.T) { - if !PathExists("common_test.go") { - t.Error("exists but return not exists") - } - if PathExists("should_not_exists.go") { - t.Error("not exists but return exists") - } -} diff --git a/Godeps/_workspace/src/github.com/shirou/gopsutil/common/common_unix.go b/Godeps/_workspace/src/github.com/shirou/gopsutil/common/common_unix.go deleted file mode 100644 index d0557ad2558..00000000000 --- a/Godeps/_workspace/src/github.com/shirou/gopsutil/common/common_unix.go +++ /dev/null @@ -1,40 +0,0 @@ -// +build linux freebsd darwin - -package common - -import ( - "os/exec" - "strconv" - "strings" -) - -func CallLsof(invoke Invoker, pid int32, args ...string) ([]string, error) { - var cmd []string - if pid == 0 { // will get from all processes. - cmd = []string{"-a", "-n", "-P"} - } else { - cmd = []string{"-a", "-n", "-P", "-p", strconv.Itoa(int(pid))} - } - cmd = append(cmd, args...) - lsof, err := exec.LookPath("lsof") - if err != nil { - return []string{}, err - } - out, err := invoke.Command(lsof, cmd...) - if err != nil { - // if no pid found, lsof returnes code 1. - if err.Error() == "exit status 1" && len(out) == 0 { - return []string{}, nil - } - } - lines := strings.Split(string(out), "\n") - - var ret []string - for _, l := range lines[1:] { - if len(l) == 0 { - continue - } - ret = append(ret, l) - } - return ret, nil -} diff --git a/Godeps/_workspace/src/github.com/shirou/gopsutil/common/common_windows.go b/Godeps/_workspace/src/github.com/shirou/gopsutil/common/common_windows.go deleted file mode 100644 index d727378cbeb..00000000000 --- a/Godeps/_workspace/src/github.com/shirou/gopsutil/common/common_windows.go +++ /dev/null @@ -1,110 +0,0 @@ -// +build windows - -package common - -import ( - "syscall" - "unsafe" -) - -// for double values -type PDH_FMT_COUNTERVALUE_DOUBLE struct { - CStatus uint32 - DoubleValue float64 -} - -// for 64 bit integer values -type PDH_FMT_COUNTERVALUE_LARGE struct { - CStatus uint32 - LargeValue int64 -} - -// for long values -type PDH_FMT_COUNTERVALUE_LONG struct { - CStatus uint32 - LongValue int32 - padding [4]byte -} - -// windows system const -const ( - ERROR_SUCCESS = 0 - ERROR_FILE_NOT_FOUND = 2 - DRIVE_REMOVABLE = 2 - DRIVE_FIXED = 3 - HKEY_LOCAL_MACHINE = 0x80000002 - RRF_RT_REG_SZ = 0x00000002 - RRF_RT_REG_DWORD = 0x00000010 - PDH_FMT_LONG = 0x00000100 - PDH_FMT_DOUBLE = 0x00000200 - PDH_FMT_LARGE = 0x00000400 - PDH_INVALID_DATA = 0xc0000bc6 - PDH_INVALID_HANDLE = 0xC0000bbc - PDH_NO_DATA = 0x800007d5 -) - -var ( - Modkernel32 = syscall.NewLazyDLL("kernel32.dll") - ModNt = syscall.NewLazyDLL("ntdll.dll") - ModPdh = syscall.NewLazyDLL("pdh.dll") - - ProcGetSystemTimes = Modkernel32.NewProc("GetSystemTimes") - ProcNtQuerySystemInformation = ModNt.NewProc("NtQuerySystemInformation") - PdhOpenQuery = ModPdh.NewProc("PdhOpenQuery") - PdhAddCounter = ModPdh.NewProc("PdhAddCounterW") - PdhCollectQueryData = ModPdh.NewProc("PdhCollectQueryData") - PdhGetFormattedCounterValue = ModPdh.NewProc("PdhGetFormattedCounterValue") - PdhCloseQuery = ModPdh.NewProc("PdhCloseQuery") -) - -type FILETIME struct { - DwLowDateTime uint32 - DwHighDateTime uint32 -} - -// borrowed from net/interface_windows.go -func BytePtrToString(p *uint8) string { - a := (*[10000]uint8)(unsafe.Pointer(p)) - i := 0 - for a[i] != 0 { - i++ - } - return string(a[:i]) -} - -// CounterInfo -// copied from https://github.com/mackerelio/mackerel-agent/ -type CounterInfo struct { - PostName string - CounterName string - Counter syscall.Handle -} - -// CreateQuery XXX -// copied from https://github.com/mackerelio/mackerel-agent/ -func CreateQuery() (syscall.Handle, error) { - var query syscall.Handle - r, _, err := PdhOpenQuery.Call(0, 0, uintptr(unsafe.Pointer(&query))) - if r != 0 { - return 0, err - } - return query, nil -} - -// CreateCounter XXX -func CreateCounter(query syscall.Handle, pname, cname string) (*CounterInfo, error) { - var counter syscall.Handle - r, _, err := PdhAddCounter.Call( - uintptr(query), - uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(cname))), - 0, - uintptr(unsafe.Pointer(&counter))) - if r != 0 { - return nil, err - } - return &CounterInfo{ - PostName: pname, - CounterName: cname, - Counter: counter, - }, nil -} diff --git a/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/binary.go b/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/binary.go deleted file mode 100644 index 418e591f4b1..00000000000 --- a/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/binary.go +++ /dev/null @@ -1,634 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package binary implements simple translation between numbers and byte -// sequences and encoding and decoding of varints. -// -// Numbers are translated by reading and writing fixed-size values. -// A fixed-size value is either a fixed-size arithmetic -// type (int8, uint8, int16, float32, complex64, ...) -// or an array or struct containing only fixed-size values. -// -// The varint functions encode and decode single integer values using -// a variable-length encoding; smaller values require fewer bytes. -// For a specification, see -// http://code.google.com/apis/protocolbuffers/docs/encoding.html. -// -// This package favors simplicity over efficiency. Clients that require -// high-performance serialization, especially for large data structures, -// should look at more advanced solutions such as the encoding/gob -// package or protocol buffers. -package disk - -import ( - "errors" - "io" - "math" - "reflect" -) - -// A ByteOrder specifies how to convert byte sequences into -// 16-, 32-, or 64-bit unsigned integers. -type ByteOrder interface { - Uint16([]byte) uint16 - Uint32([]byte) uint32 - Uint64([]byte) uint64 - PutUint16([]byte, uint16) - PutUint32([]byte, uint32) - PutUint64([]byte, uint64) - String() string -} - -// LittleEndian is the little-endian implementation of ByteOrder. -var LittleEndian littleEndian - -// BigEndian is the big-endian implementation of ByteOrder. -var BigEndian bigEndian - -type littleEndian struct{} - -func (littleEndian) Uint16(b []byte) uint16 { return uint16(b[0]) | uint16(b[1])<<8 } - -func (littleEndian) PutUint16(b []byte, v uint16) { - b[0] = byte(v) - b[1] = byte(v >> 8) -} - -func (littleEndian) Uint32(b []byte) uint32 { - return uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24 -} - -func (littleEndian) PutUint32(b []byte, v uint32) { - b[0] = byte(v) - b[1] = byte(v >> 8) - b[2] = byte(v >> 16) - b[3] = byte(v >> 24) -} - -func (littleEndian) Uint64(b []byte) uint64 { - return uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 | - uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56 -} - -func (littleEndian) PutUint64(b []byte, v uint64) { - b[0] = byte(v) - b[1] = byte(v >> 8) - b[2] = byte(v >> 16) - b[3] = byte(v >> 24) - b[4] = byte(v >> 32) - b[5] = byte(v >> 40) - b[6] = byte(v >> 48) - b[7] = byte(v >> 56) -} - -func (littleEndian) String() string { return "LittleEndian" } - -func (littleEndian) GoString() string { return "binary.LittleEndian" } - -type bigEndian struct{} - -func (bigEndian) Uint16(b []byte) uint16 { return uint16(b[1]) | uint16(b[0])<<8 } - -func (bigEndian) PutUint16(b []byte, v uint16) { - b[0] = byte(v >> 8) - b[1] = byte(v) -} - -func (bigEndian) Uint32(b []byte) uint32 { - return uint32(b[3]) | uint32(b[2])<<8 | uint32(b[1])<<16 | uint32(b[0])<<24 -} - -func (bigEndian) PutUint32(b []byte, v uint32) { - b[0] = byte(v >> 24) - b[1] = byte(v >> 16) - b[2] = byte(v >> 8) - b[3] = byte(v) -} - -func (bigEndian) Uint64(b []byte) uint64 { - return uint64(b[7]) | uint64(b[6])<<8 | uint64(b[5])<<16 | uint64(b[4])<<24 | - uint64(b[3])<<32 | uint64(b[2])<<40 | uint64(b[1])<<48 | uint64(b[0])<<56 -} - -func (bigEndian) PutUint64(b []byte, v uint64) { - b[0] = byte(v >> 56) - b[1] = byte(v >> 48) - b[2] = byte(v >> 40) - b[3] = byte(v >> 32) - b[4] = byte(v >> 24) - b[5] = byte(v >> 16) - b[6] = byte(v >> 8) - b[7] = byte(v) -} - -func (bigEndian) String() string { return "BigEndian" } - -func (bigEndian) GoString() string { return "binary.BigEndian" } - -// Read reads structured binary data from r into data. -// Data must be a pointer to a fixed-size value or a slice -// of fixed-size values. -// Bytes read from r are decoded using the specified byte order -// and written to successive fields of the data. -// When reading into structs, the field data for fields with -// blank (_) field names is skipped; i.e., blank field names -// may be used for padding. -// When reading into a struct, all non-blank fields must be exported. -func Read(r io.Reader, order ByteOrder, data interface{}) error { - // Fast path for basic types and slices. - if n := intDataSize(data); n != 0 { - var b [8]byte - var bs []byte - if n > len(b) { - bs = make([]byte, n) - } else { - bs = b[:n] - } - if _, err := io.ReadFull(r, bs); err != nil { - return err - } - switch data := data.(type) { - case *int8: - *data = int8(b[0]) - case *uint8: - *data = b[0] - case *int16: - *data = int16(order.Uint16(bs)) - case *uint16: - *data = order.Uint16(bs) - case *int32: - *data = int32(order.Uint32(bs)) - case *uint32: - *data = order.Uint32(bs) - case *int64: - *data = int64(order.Uint64(bs)) - case *uint64: - *data = order.Uint64(bs) - case []int8: - for i, x := range bs { // Easier to loop over the input for 8-bit values. - data[i] = int8(x) - } - case []uint8: - copy(data, bs) - case []int16: - for i := range data { - data[i] = int16(order.Uint16(bs[2*i:])) - } - case []uint16: - for i := range data { - data[i] = order.Uint16(bs[2*i:]) - } - case []int32: - for i := range data { - data[i] = int32(order.Uint32(bs[4*i:])) - } - case []uint32: - for i := range data { - data[i] = order.Uint32(bs[4*i:]) - } - case []int64: - for i := range data { - data[i] = int64(order.Uint64(bs[8*i:])) - } - case []uint64: - for i := range data { - data[i] = order.Uint64(bs[8*i:]) - } - } - return nil - } - - // Fallback to reflect-based decoding. - v := reflect.ValueOf(data) - size := -1 - switch v.Kind() { - case reflect.Ptr: - v = v.Elem() - size = dataSize(v) - case reflect.Slice: - size = dataSize(v) - } - if size < 0 { - return errors.New("binary.Read: invalid type " + reflect.TypeOf(data).String()) - } - d := &decoder{order: order, buf: make([]byte, size)} - if _, err := io.ReadFull(r, d.buf); err != nil { - return err - } - d.value(v) - return nil -} - -// Write writes the binary representation of data into w. -// Data must be a fixed-size value or a slice of fixed-size -// values, or a pointer to such data. -// Bytes written to w are encoded using the specified byte order -// and read from successive fields of the data. -// When writing structs, zero values are written for fields -// with blank (_) field names. -func Write(w io.Writer, order ByteOrder, data interface{}) error { - // Fast path for basic types and slices. - if n := intDataSize(data); n != 0 { - var b [8]byte - var bs []byte - if n > len(b) { - bs = make([]byte, n) - } else { - bs = b[:n] - } - switch v := data.(type) { - case *int8: - bs = b[:1] - b[0] = byte(*v) - case int8: - bs = b[:1] - b[0] = byte(v) - case []int8: - for i, x := range v { - bs[i] = byte(x) - } - case *uint8: - bs = b[:1] - b[0] = *v - case uint8: - bs = b[:1] - b[0] = byte(v) - case []uint8: - bs = v - case *int16: - bs = b[:2] - order.PutUint16(bs, uint16(*v)) - case int16: - bs = b[:2] - order.PutUint16(bs, uint16(v)) - case []int16: - for i, x := range v { - order.PutUint16(bs[2*i:], uint16(x)) - } - case *uint16: - bs = b[:2] - order.PutUint16(bs, *v) - case uint16: - bs = b[:2] - order.PutUint16(bs, v) - case []uint16: - for i, x := range v { - order.PutUint16(bs[2*i:], x) - } - case *int32: - bs = b[:4] - order.PutUint32(bs, uint32(*v)) - case int32: - bs = b[:4] - order.PutUint32(bs, uint32(v)) - case []int32: - for i, x := range v { - order.PutUint32(bs[4*i:], uint32(x)) - } - case *uint32: - bs = b[:4] - order.PutUint32(bs, *v) - case uint32: - bs = b[:4] - order.PutUint32(bs, v) - case []uint32: - for i, x := range v { - order.PutUint32(bs[4*i:], x) - } - case *int64: - bs = b[:8] - order.PutUint64(bs, uint64(*v)) - case int64: - bs = b[:8] - order.PutUint64(bs, uint64(v)) - case []int64: - for i, x := range v { - order.PutUint64(bs[8*i:], uint64(x)) - } - case *uint64: - bs = b[:8] - order.PutUint64(bs, *v) - case uint64: - bs = b[:8] - order.PutUint64(bs, v) - case []uint64: - for i, x := range v { - order.PutUint64(bs[8*i:], x) - } - } - _, err := w.Write(bs) - return err - } - - // Fallback to reflect-based encoding. - v := reflect.Indirect(reflect.ValueOf(data)) - size := dataSize(v) - if size < 0 { - return errors.New("binary.Write: invalid type " + reflect.TypeOf(data).String()) - } - buf := make([]byte, size) - e := &encoder{order: order, buf: buf} - e.value(v) - _, err := w.Write(buf) - return err -} - -// Size returns how many bytes Write would generate to encode the value v, which -// must be a fixed-size value or a slice of fixed-size values, or a pointer to such data. -// If v is neither of these, Size returns -1. -func Size(v interface{}) int { - return dataSize(reflect.Indirect(reflect.ValueOf(v))) -} - -// dataSize returns the number of bytes the actual data represented by v occupies in memory. -// For compound structures, it sums the sizes of the elements. Thus, for instance, for a slice -// it returns the length of the slice times the element size and does not count the memory -// occupied by the header. If the type of v is not acceptable, dataSize returns -1. -func dataSize(v reflect.Value) int { - if v.Kind() == reflect.Slice { - if s := sizeof(v.Type().Elem()); s >= 0 { - return s * v.Len() - } - return -1 - } - return sizeof(v.Type()) -} - -// sizeof returns the size >= 0 of variables for the given type or -1 if the type is not acceptable. -func sizeof(t reflect.Type) int { - switch t.Kind() { - case reflect.Array: - if s := sizeof(t.Elem()); s >= 0 { - return s * t.Len() - } - - case reflect.Struct: - sum := 0 - for i, n := 0, t.NumField(); i < n; i++ { - s := sizeof(t.Field(i).Type) - if s < 0 { - return -1 - } - sum += s - } - return sum - - case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, - reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, - reflect.Float32, reflect.Float64, reflect.Complex64, reflect.Complex128, reflect.Ptr: - return int(t.Size()) - } - - return -1 -} - -type coder struct { - order ByteOrder - buf []byte -} - -type decoder coder -type encoder coder - -func (d *decoder) uint8() uint8 { - x := d.buf[0] - d.buf = d.buf[1:] - return x -} - -func (e *encoder) uint8(x uint8) { - e.buf[0] = x - e.buf = e.buf[1:] -} - -func (d *decoder) uint16() uint16 { - x := d.order.Uint16(d.buf[0:2]) - d.buf = d.buf[2:] - return x -} - -func (e *encoder) uint16(x uint16) { - e.order.PutUint16(e.buf[0:2], x) - e.buf = e.buf[2:] -} - -func (d *decoder) uint32() uint32 { - x := d.order.Uint32(d.buf[0:4]) - d.buf = d.buf[4:] - return x -} - -func (e *encoder) uint32(x uint32) { - e.order.PutUint32(e.buf[0:4], x) - e.buf = e.buf[4:] -} - -func (d *decoder) uint64() uint64 { - x := d.order.Uint64(d.buf[0:8]) - d.buf = d.buf[8:] - return x -} - -func (e *encoder) uint64(x uint64) { - e.order.PutUint64(e.buf[0:8], x) - e.buf = e.buf[8:] -} - -func (d *decoder) int8() int8 { return int8(d.uint8()) } - -func (e *encoder) int8(x int8) { e.uint8(uint8(x)) } - -func (d *decoder) int16() int16 { return int16(d.uint16()) } - -func (e *encoder) int16(x int16) { e.uint16(uint16(x)) } - -func (d *decoder) int32() int32 { return int32(d.uint32()) } - -func (e *encoder) int32(x int32) { e.uint32(uint32(x)) } - -func (d *decoder) int64() int64 { return int64(d.uint64()) } - -func (e *encoder) int64(x int64) { e.uint64(uint64(x)) } - -func (d *decoder) value(v reflect.Value) { - switch v.Kind() { - case reflect.Array: - l := v.Len() - for i := 0; i < l; i++ { - d.value(v.Index(i)) - } - - case reflect.Struct: - t := v.Type() - l := v.NumField() - for i := 0; i < l; i++ { - // Note: Calling v.CanSet() below is an optimization. - // It would be sufficient to check the field name, - // but creating the StructField info for each field is - // costly (run "go test -bench=ReadStruct" and compare - // results when making changes to this code). - if v := v.Field(i); v.CanSet() || t.Field(i).Name != "_" { - d.value(v) - } else { - d.skip(v) - } - } - - case reflect.Slice: - l := v.Len() - for i := 0; i < l; i++ { - d.value(v.Index(i)) - } - - case reflect.Int8: - v.SetInt(int64(d.int8())) - case reflect.Int16: - v.SetInt(int64(d.int16())) - case reflect.Int32: - v.SetInt(int64(d.int32())) - case reflect.Int64: - v.SetInt(d.int64()) - - case reflect.Uint8: - v.SetUint(uint64(d.uint8())) - case reflect.Uint16: - v.SetUint(uint64(d.uint16())) - case reflect.Uint32: - v.SetUint(uint64(d.uint32())) - case reflect.Uint64: - v.SetUint(d.uint64()) - - case reflect.Float32: - v.SetFloat(float64(math.Float32frombits(d.uint32()))) - case reflect.Float64: - v.SetFloat(math.Float64frombits(d.uint64())) - - case reflect.Complex64: - v.SetComplex(complex( - float64(math.Float32frombits(d.uint32())), - float64(math.Float32frombits(d.uint32())), - )) - case reflect.Complex128: - v.SetComplex(complex( - math.Float64frombits(d.uint64()), - math.Float64frombits(d.uint64()), - )) - } -} - -func (e *encoder) value(v reflect.Value) { - switch v.Kind() { - case reflect.Array: - l := v.Len() - for i := 0; i < l; i++ { - e.value(v.Index(i)) - } - - case reflect.Struct: - t := v.Type() - l := v.NumField() - for i := 0; i < l; i++ { - // see comment for corresponding code in decoder.value() - if v := v.Field(i); v.CanSet() || t.Field(i).Name != "_" { - e.value(v) - } else { - e.skip(v) - } - } - - case reflect.Slice: - l := v.Len() - for i := 0; i < l; i++ { - e.value(v.Index(i)) - } - - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - switch v.Type().Kind() { - case reflect.Int8: - e.int8(int8(v.Int())) - case reflect.Int16: - e.int16(int16(v.Int())) - case reflect.Int32: - e.int32(int32(v.Int())) - case reflect.Int64: - e.int64(v.Int()) - } - - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: - switch v.Type().Kind() { - case reflect.Uint8: - e.uint8(uint8(v.Uint())) - case reflect.Uint16: - e.uint16(uint16(v.Uint())) - case reflect.Uint32: - e.uint32(uint32(v.Uint())) - case reflect.Uint64: - e.uint64(v.Uint()) - } - - case reflect.Float32, reflect.Float64: - switch v.Type().Kind() { - case reflect.Float32: - e.uint32(math.Float32bits(float32(v.Float()))) - case reflect.Float64: - e.uint64(math.Float64bits(v.Float())) - } - - case reflect.Complex64, reflect.Complex128: - switch v.Type().Kind() { - case reflect.Complex64: - x := v.Complex() - e.uint32(math.Float32bits(float32(real(x)))) - e.uint32(math.Float32bits(float32(imag(x)))) - case reflect.Complex128: - x := v.Complex() - e.uint64(math.Float64bits(real(x))) - e.uint64(math.Float64bits(imag(x))) - } - } -} - -func (d *decoder) skip(v reflect.Value) { - d.buf = d.buf[dataSize(v):] -} - -func (e *encoder) skip(v reflect.Value) { - n := dataSize(v) - for i := range e.buf[0:n] { - e.buf[i] = 0 - } - e.buf = e.buf[n:] -} - -// intDataSize returns the size of the data required to represent the data when encoded. -// It returns zero if the type cannot be implemented by the fast path in Read or Write. -func intDataSize(data interface{}) int { - switch data := data.(type) { - case int8, *int8, *uint8: - return 1 - case []int8: - return len(data) - case []uint8: - return len(data) - case int16, *int16, *uint16: - return 2 - case []int16: - return 2 * len(data) - case []uint16: - return 2 * len(data) - case int32, *int32, *uint32: - return 4 - case []int32: - return 4 * len(data) - case []uint32: - return 4 * len(data) - case int64, *int64, *uint64: - return 8 - case []int64: - return 8 * len(data) - case []uint64: - return 8 * len(data) - } - return 0 -} diff --git a/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk.go b/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk.go deleted file mode 100644 index 0aa26cd1baa..00000000000 --- a/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk.go +++ /dev/null @@ -1,52 +0,0 @@ -package disk - -import ( - "encoding/json" -) - -type DiskUsageStat struct { - Path string `json:"path"` - Fstype string `json:"fstype"` - Total uint64 `json:"total"` - Free uint64 `json:"free"` - Used uint64 `json:"used"` - UsedPercent float64 `json:"used_percent"` - InodesTotal uint64 `json:"inodes_total"` - InodesUsed uint64 `json:"inodes_used"` - InodesFree uint64 `json:"inodes_free"` - InodesUsedPercent float64 `json:"inodes_used_percent"` -} - -type DiskPartitionStat struct { - Device string `json:"device"` - Mountpoint string `json:"mountpoint"` - Fstype string `json:"fstype"` - Opts string `json:"opts"` -} - -type DiskIOCountersStat struct { - ReadCount uint64 `json:"read_count"` - WriteCount uint64 `json:"write_count"` - ReadBytes uint64 `json:"read_bytes"` - WriteBytes uint64 `json:"write_bytes"` - ReadTime uint64 `json:"read_time"` - WriteTime uint64 `json:"write_time"` - Name string `json:"name"` - IoTime uint64 `json:"io_time"` - SerialNumber string `json:"serial_number"` -} - -func (d DiskUsageStat) String() string { - s, _ := json.Marshal(d) - return string(s) -} - -func (d DiskPartitionStat) String() string { - s, _ := json.Marshal(d) - return string(s) -} - -func (d DiskIOCountersStat) String() string { - s, _ := json.Marshal(d) - return string(s) -} diff --git a/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_darwin.go b/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_darwin.go deleted file mode 100644 index 96f3c94e368..00000000000 --- a/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_darwin.go +++ /dev/null @@ -1,104 +0,0 @@ -// +build darwin - -package disk - -import ( - "syscall" - "unsafe" - - common "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/shirou/gopsutil/common" -) - -func DiskPartitions(all bool) ([]DiskPartitionStat, error) { - var ret []DiskPartitionStat - - count, err := Getfsstat(nil, MntWait) - if err != nil { - return ret, err - } - fs := make([]Statfs_t, count) - _, err = Getfsstat(fs, MntWait) - for _, stat := range fs { - opts := "rw" - if stat.Flags&MntReadOnly != 0 { - opts = "ro" - } - if stat.Flags&MntSynchronous != 0 { - opts += ",sync" - } - if stat.Flags&MntNoExec != 0 { - opts += ",noexec" - } - if stat.Flags&MntNoSuid != 0 { - opts += ",nosuid" - } - if stat.Flags&MntUnion != 0 { - opts += ",union" - } - if stat.Flags&MntAsync != 0 { - opts += ",async" - } - if stat.Flags&MntSuidDir != 0 { - opts += ",suiddir" - } - if stat.Flags&MntSoftDep != 0 { - opts += ",softdep" - } - if stat.Flags&MntNoSymFollow != 0 { - opts += ",nosymfollow" - } - if stat.Flags&MntGEOMJournal != 0 { - opts += ",gjounalc" - } - if stat.Flags&MntMultilabel != 0 { - opts += ",multilabel" - } - if stat.Flags&MntACLs != 0 { - opts += ",acls" - } - if stat.Flags&MntNoATime != 0 { - opts += ",noattime" - } - if stat.Flags&MntClusterRead != 0 { - opts += ",nocluster" - } - if stat.Flags&MntClusterWrite != 0 { - opts += ",noclusterw" - } - if stat.Flags&MntNFS4ACLs != 0 { - opts += ",nfs4acls" - } - d := DiskPartitionStat{ - Device: common.IntToString(stat.Mntfromname[:]), - Mountpoint: common.IntToString(stat.Mntonname[:]), - Fstype: common.IntToString(stat.Fstypename[:]), - Opts: opts, - } - ret = append(ret, d) - } - - return ret, nil -} - -func DiskIOCounters() (map[string]DiskIOCountersStat, error) { - return nil, common.NotImplementedError -} - -func Getfsstat(buf []Statfs_t, flags int) (n int, err error) { - var _p0 unsafe.Pointer - var bufsize uintptr - if len(buf) > 0 { - _p0 = unsafe.Pointer(&buf[0]) - bufsize = unsafe.Sizeof(Statfs_t{}) * uintptr(len(buf)) - } - r0, _, e1 := syscall.Syscall(SYS_GETFSSTAT64, uintptr(_p0), bufsize, uintptr(flags)) - n = int(r0) - if e1 != 0 { - err = e1 - } - return -} - -func getFsType(stat syscall.Statfs_t) string { - return common.IntToString(stat.Fstypename[:]) -} diff --git a/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_darwin_amd64.go b/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_darwin_amd64.go deleted file mode 100644 index f58e2131274..00000000000 --- a/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_darwin_amd64.go +++ /dev/null @@ -1,58 +0,0 @@ -// +build darwin -// +build amd64 - -package disk - -const ( - MntWait = 1 - MfsNameLen = 15 /* length of fs type name, not inc. nul */ - MNameLen = 90 /* length of buffer for returned name */ - - MFSTYPENAMELEN = 16 /* length of fs type name including null */ - MAXPATHLEN = 1024 - MNAMELEN = MAXPATHLEN - - SYS_GETFSSTAT64 = 347 -) - -type Fsid struct{ val [2]int32 } /* file system id type */ -type uid_t int32 - -// sys/mount.h -const ( - MntReadOnly = 0x00000001 /* read only filesystem */ - MntSynchronous = 0x00000002 /* filesystem written synchronously */ - MntNoExec = 0x00000004 /* can't exec from filesystem */ - MntNoSuid = 0x00000008 /* don't honor setuid bits on fs */ - MntUnion = 0x00000020 /* union with underlying filesystem */ - MntAsync = 0x00000040 /* filesystem written asynchronously */ - MntSuidDir = 0x00100000 /* special handling of SUID on dirs */ - MntSoftDep = 0x00200000 /* soft updates being done */ - MntNoSymFollow = 0x00400000 /* do not follow symlinks */ - MntGEOMJournal = 0x02000000 /* GEOM journal support enabled */ - MntMultilabel = 0x04000000 /* MAC support for individual objects */ - MntACLs = 0x08000000 /* ACL support enabled */ - MntNoATime = 0x10000000 /* disable update of file access time */ - MntClusterRead = 0x40000000 /* disable cluster read */ - MntClusterWrite = 0x80000000 /* disable cluster write */ - MntNFS4ACLs = 0x00000010 -) - -type Statfs_t struct { - Bsize uint32 - Iosize int32 - Blocks uint64 - Bfree uint64 - Bavail uint64 - Files uint64 - Ffree uint64 - Fsid Fsid - Owner uint32 - Type uint32 - Flags uint32 - Fssubtype uint32 - Fstypename [16]int8 - Mntonname [1024]int8 - Mntfromname [1024]int8 - Reserved [8]uint32 -} diff --git a/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_freebsd.go b/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_freebsd.go deleted file mode 100644 index 619d373d392..00000000000 --- a/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_freebsd.go +++ /dev/null @@ -1,179 +0,0 @@ -// +build freebsd - -package disk - -import ( - "bytes" - "encoding/binary" - "strconv" - "syscall" - "unsafe" - - common "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/shirou/gopsutil/common" -) - -const ( - CTLKern = 1 - // KernDevstat = 773 // for freebsd 8.4 - // KernDevstatAll = 772 // for freebsd 8.4 - KernDevstat = 974 - KernDevstatAll = 975 -) - -func DiskPartitions(all bool) ([]DiskPartitionStat, error) { - var ret []DiskPartitionStat - - // get length - count, err := syscall.Getfsstat(nil, MNT_WAIT) - if err != nil { - return ret, err - } - - fs := make([]Statfs, count) - _, err = Getfsstat(fs, MNT_WAIT) - - for _, stat := range fs { - opts := "rw" - if stat.Flags&MNT_RDONLY != 0 { - opts = "ro" - } - if stat.Flags&MNT_SYNCHRONOUS != 0 { - opts += ",sync" - } - if stat.Flags&MNT_NOEXEC != 0 { - opts += ",noexec" - } - if stat.Flags&MNT_NOSUID != 0 { - opts += ",nosuid" - } - if stat.Flags&MNT_UNION != 0 { - opts += ",union" - } - if stat.Flags&MNT_ASYNC != 0 { - opts += ",async" - } - if stat.Flags&MNT_SUIDDIR != 0 { - opts += ",suiddir" - } - if stat.Flags&MNT_SOFTDEP != 0 { - opts += ",softdep" - } - if stat.Flags&MNT_NOSYMFOLLOW != 0 { - opts += ",nosymfollow" - } - if stat.Flags&MNT_GJOURNAL != 0 { - opts += ",gjounalc" - } - if stat.Flags&MNT_MULTILABEL != 0 { - opts += ",multilabel" - } - if stat.Flags&MNT_ACLS != 0 { - opts += ",acls" - } - if stat.Flags&MNT_NOATIME != 0 { - opts += ",noattime" - } - if stat.Flags&MNT_NOCLUSTERR != 0 { - opts += ",nocluster" - } - if stat.Flags&MNT_NOCLUSTERW != 0 { - opts += ",noclusterw" - } - if stat.Flags&MNT_NFS4ACLS != 0 { - opts += ",nfs4acls" - } - - d := DiskPartitionStat{ - Device: common.IntToString(stat.Mntfromname[:]), - Mountpoint: common.IntToString(stat.Mntonname[:]), - Fstype: common.IntToString(stat.Fstypename[:]), - Opts: opts, - } - ret = append(ret, d) - } - - return ret, nil -} - -func DiskIOCounters() (map[string]DiskIOCountersStat, error) { - // statinfo->devinfo->devstat - // /usr/include/devinfo.h - - // sysctl.sysctl ('kern.devstat.all', 0) - ret := make(map[string]DiskIOCountersStat) - mib := []int32{CTLKern, KernDevstat, KernDevstatAll} - - buf, length, err := common.CallSyscall(mib) - if err != nil { - return nil, err - } - - ds := Devstat{} - devstatLen := int(unsafe.Sizeof(ds)) - count := int(length / uint64(devstatLen)) - - buf = buf[8:] // devstat.all has version in the head. - // parse buf to Devstat - for i := 0; i < count; i++ { - b := buf[i*devstatLen : i*devstatLen+devstatLen] - d, err := parseDevstat(b) - if err != nil { - continue - } - un := strconv.Itoa(int(d.Unit_number)) - name := common.IntToString(d.Device_name[:]) + un - - ds := DiskIOCountersStat{ - ReadCount: d.Operations[DEVSTAT_READ], - WriteCount: d.Operations[DEVSTAT_WRITE], - ReadBytes: d.Bytes[DEVSTAT_READ], - WriteBytes: d.Bytes[DEVSTAT_WRITE], - ReadTime: d.Duration[DEVSTAT_READ].Compute(), - WriteTime: d.Duration[DEVSTAT_WRITE].Compute(), - Name: name, - } - ret[name] = ds - } - - return ret, nil -} - -func (b Bintime) Compute() uint64 { - BINTIME_SCALE := 5.42101086242752217003726400434970855712890625e-20 - return uint64(b.Sec) + b.Frac*uint64(BINTIME_SCALE) -} - -// BT2LD(time) ((long double)(time).sec + (time).frac * BINTIME_SCALE) - -// Getfsstat is borrowed from pkg/syscall/syscall_freebsd.go -// change Statfs_t to Statfs in order to get more information -func Getfsstat(buf []Statfs, flags int) (n int, err error) { - var _p0 unsafe.Pointer - var bufsize uintptr - if len(buf) > 0 { - _p0 = unsafe.Pointer(&buf[0]) - bufsize = unsafe.Sizeof(Statfs{}) * uintptr(len(buf)) - } - r0, _, e1 := syscall.Syscall(syscall.SYS_GETFSSTAT, uintptr(_p0), bufsize, uintptr(flags)) - n = int(r0) - if e1 != 0 { - err = e1 - } - return -} - -func parseDevstat(buf []byte) (Devstat, error) { - var ds Devstat - br := bytes.NewReader(buf) - // err := binary.Read(br, binary.LittleEndian, &ds) - err := Read(br, binary.LittleEndian, &ds) - if err != nil { - return ds, err - } - - return ds, nil -} - -func getFsType(stat syscall.Statfs_t) string { - return common.IntToString(stat.Fstypename[:]) -} diff --git a/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_freebsd_amd64.go b/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_freebsd_amd64.go deleted file mode 100644 index bbae1595ccd..00000000000 --- a/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_freebsd_amd64.go +++ /dev/null @@ -1,111 +0,0 @@ -// Created by cgo -godefs - DO NOT EDIT -// cgo -godefs types_freebsd.go - -package disk - -const ( - sizeofPtr = 0x8 - sizeofShort = 0x2 - sizeofInt = 0x4 - sizeofLong = 0x8 - sizeofLongLong = 0x8 - sizeofLongDouble = 0x8 - - DEVSTAT_NO_DATA = 0x00 - DEVSTAT_READ = 0x01 - DEVSTAT_WRITE = 0x02 - DEVSTAT_FREE = 0x03 - - MNT_RDONLY = 0x00000001 - MNT_SYNCHRONOUS = 0x00000002 - MNT_NOEXEC = 0x00000004 - MNT_NOSUID = 0x00000008 - MNT_UNION = 0x00000020 - MNT_ASYNC = 0x00000040 - MNT_SUIDDIR = 0x00100000 - MNT_SOFTDEP = 0x00200000 - MNT_NOSYMFOLLOW = 0x00400000 - MNT_GJOURNAL = 0x02000000 - MNT_MULTILABEL = 0x04000000 - MNT_ACLS = 0x08000000 - MNT_NOATIME = 0x10000000 - MNT_NOCLUSTERR = 0x40000000 - MNT_NOCLUSTERW = 0x80000000 - MNT_NFS4ACLS = 0x00000010 - - MNT_WAIT = 1 - MNT_NOWAIT = 2 - MNT_LAZY = 3 - MNT_SUSPEND = 4 -) - -type ( - _C_short int16 - _C_int int32 - _C_long int64 - _C_long_long int64 - _C_long_double int64 -) - -type Statfs struct { - Version uint32 - Type uint32 - Flags uint64 - Bsize uint64 - Iosize uint64 - Blocks uint64 - Bfree uint64 - Bavail int64 - Files uint64 - Ffree int64 - Syncwrites uint64 - Asyncwrites uint64 - Syncreads uint64 - Asyncreads uint64 - Spare [10]uint64 - Namemax uint32 - Owner uint32 - Fsid Fsid - Charspare [80]int8 - Fstypename [16]int8 - Mntfromname [88]int8 - Mntonname [88]int8 -} -type Fsid struct { - Val [2]int32 -} - -type Devstat struct { - Sequence0 uint32 - Allocated int32 - Start_count uint32 - End_count uint32 - Busy_from Bintime - Dev_links _Ctype_struct___0 - Device_number uint32 - Device_name [16]int8 - Unit_number int32 - Bytes [4]uint64 - Operations [4]uint64 - Duration [4]Bintime - Busy_time Bintime - Creation_time Bintime - Block_size uint32 - Pad_cgo_0 [4]byte - Tag_types [3]uint64 - Flags uint32 - Device_type uint32 - Priority uint32 - Pad_cgo_1 [4]byte - Id *byte - Sequence1 uint32 - Pad_cgo_2 [4]byte -} -type Bintime struct { - Sec int64 - Frac uint64 -} - -type _Ctype_struct___0 struct { - Empty uint64 -} diff --git a/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_linux.go b/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_linux.go deleted file mode 100644 index f44905a9bc9..00000000000 --- a/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_linux.go +++ /dev/null @@ -1,327 +0,0 @@ -// +build linux - -package disk - -import ( - "fmt" - "os/exec" - "strconv" - "strings" - "syscall" - - common "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/shirou/gopsutil/common" -) - -const ( - SectorSize = 512 -) -const ( - // man statfs - ADFS_SUPER_MAGIC = 0xadf5 - AFFS_SUPER_MAGIC = 0xADFF - BDEVFS_MAGIC = 0x62646576 - BEFS_SUPER_MAGIC = 0x42465331 - BFS_MAGIC = 0x1BADFACE - BINFMTFS_MAGIC = 0x42494e4d - BTRFS_SUPER_MAGIC = 0x9123683E - CGROUP_SUPER_MAGIC = 0x27e0eb - CIFS_MAGIC_NUMBER = 0xFF534D42 - CODA_SUPER_MAGIC = 0x73757245 - COH_SUPER_MAGIC = 0x012FF7B7 - CRAMFS_MAGIC = 0x28cd3d45 - DEBUGFS_MAGIC = 0x64626720 - DEVFS_SUPER_MAGIC = 0x1373 - DEVPTS_SUPER_MAGIC = 0x1cd1 - EFIVARFS_MAGIC = 0xde5e81e4 - EFS_SUPER_MAGIC = 0x00414A53 - EXT_SUPER_MAGIC = 0x137D - EXT2_OLD_SUPER_MAGIC = 0xEF51 - EXT2_SUPER_MAGIC = 0xEF53 - EXT3_SUPER_MAGIC = 0xEF53 - EXT4_SUPER_MAGIC = 0xEF53 - FUSE_SUPER_MAGIC = 0x65735546 - FUTEXFS_SUPER_MAGIC = 0xBAD1DEA - HFS_SUPER_MAGIC = 0x4244 - HOSTFS_SUPER_MAGIC = 0x00c0ffee - HPFS_SUPER_MAGIC = 0xF995E849 - HUGETLBFS_MAGIC = 0x958458f6 - ISOFS_SUPER_MAGIC = 0x9660 - JFFS2_SUPER_MAGIC = 0x72b6 - JFS_SUPER_MAGIC = 0x3153464a - MINIX_SUPER_MAGIC = 0x137F /* orig. minix */ - MINIX_SUPER_MAGIC2 = 0x138F /* 30 char minix */ - MINIX2_SUPER_MAGIC = 0x2468 /* minix V2 */ - MINIX2_SUPER_MAGIC2 = 0x2478 /* minix V2, 30 char names */ - MINIX3_SUPER_MAGIC = 0x4d5a /* minix V3 fs, 60 char names */ - MQUEUE_MAGIC = 0x19800202 - MSDOS_SUPER_MAGIC = 0x4d44 - NCP_SUPER_MAGIC = 0x564c - NFS_SUPER_MAGIC = 0x6969 - NILFS_SUPER_MAGIC = 0x3434 - NTFS_SB_MAGIC = 0x5346544e - OCFS2_SUPER_MAGIC = 0x7461636f - OPENPROM_SUPER_MAGIC = 0x9fa1 - PIPEFS_MAGIC = 0x50495045 - PROC_SUPER_MAGIC = 0x9fa0 - PSTOREFS_MAGIC = 0x6165676C - QNX4_SUPER_MAGIC = 0x002f - QNX6_SUPER_MAGIC = 0x68191122 - RAMFS_MAGIC = 0x858458f6 - REISERFS_SUPER_MAGIC = 0x52654973 - ROMFS_MAGIC = 0x7275 - SELINUX_MAGIC = 0xf97cff8c - SMACK_MAGIC = 0x43415d53 - SMB_SUPER_MAGIC = 0x517B - SOCKFS_MAGIC = 0x534F434B - SQUASHFS_MAGIC = 0x73717368 - SYSFS_MAGIC = 0x62656572 - SYSV2_SUPER_MAGIC = 0x012FF7B6 - SYSV4_SUPER_MAGIC = 0x012FF7B5 - TMPFS_MAGIC = 0x01021994 - UDF_SUPER_MAGIC = 0x15013346 - UFS_MAGIC = 0x00011954 - USBDEVICE_SUPER_MAGIC = 0x9fa2 - V9FS_MAGIC = 0x01021997 - VXFS_SUPER_MAGIC = 0xa501FCF5 - XENFS_SUPER_MAGIC = 0xabba1974 - XENIX_SUPER_MAGIC = 0x012FF7B4 - XFS_SUPER_MAGIC = 0x58465342 - _XIAFS_SUPER_MAGIC = 0x012FD16D - - AFS_SUPER_MAGIC = 0x5346414F - AUFS_SUPER_MAGIC = 0x61756673 - ANON_INODE_FS_SUPER_MAGIC = 0x09041934 - CEPH_SUPER_MAGIC = 0x00C36400 - ECRYPTFS_SUPER_MAGIC = 0xF15F - FAT_SUPER_MAGIC = 0x4006 - FHGFS_SUPER_MAGIC = 0x19830326 - FUSEBLK_SUPER_MAGIC = 0x65735546 - FUSECTL_SUPER_MAGIC = 0x65735543 - GFS_SUPER_MAGIC = 0x1161970 - GPFS_SUPER_MAGIC = 0x47504653 - MTD_INODE_FS_SUPER_MAGIC = 0x11307854 - INOTIFYFS_SUPER_MAGIC = 0x2BAD1DEA - ISOFS_R_WIN_SUPER_MAGIC = 0x4004 - ISOFS_WIN_SUPER_MAGIC = 0x4000 - JFFS_SUPER_MAGIC = 0x07C0 - KAFS_SUPER_MAGIC = 0x6B414653 - LUSTRE_SUPER_MAGIC = 0x0BD00BD0 - NFSD_SUPER_MAGIC = 0x6E667364 - PANFS_SUPER_MAGIC = 0xAAD7AAEA - RPC_PIPEFS_SUPER_MAGIC = 0x67596969 - SECURITYFS_SUPER_MAGIC = 0x73636673 - UFS_BYTESWAPPED_SUPER_MAGIC = 0x54190100 - VMHGFS_SUPER_MAGIC = 0xBACBACBC - VZFS_SUPER_MAGIC = 0x565A4653 - ZFS_SUPER_MAGIC = 0x2FC12FC1 -) - -// coreutils/src/stat.c -var fsTypeMap = map[int64]string{ - ADFS_SUPER_MAGIC: "adfs", /* 0xADF5 local */ - AFFS_SUPER_MAGIC: "affs", /* 0xADFF local */ - AFS_SUPER_MAGIC: "afs", /* 0x5346414F remote */ - ANON_INODE_FS_SUPER_MAGIC: "anon-inode FS", /* 0x09041934 local */ - AUFS_SUPER_MAGIC: "aufs", /* 0x61756673 remote */ - // AUTOFS_SUPER_MAGIC: "autofs", /* 0x0187 local */ - BEFS_SUPER_MAGIC: "befs", /* 0x42465331 local */ - BDEVFS_MAGIC: "bdevfs", /* 0x62646576 local */ - BFS_MAGIC: "bfs", /* 0x1BADFACE local */ - BINFMTFS_MAGIC: "binfmt_misc", /* 0x42494E4D local */ - BTRFS_SUPER_MAGIC: "btrfs", /* 0x9123683E local */ - CEPH_SUPER_MAGIC: "ceph", /* 0x00C36400 remote */ - CGROUP_SUPER_MAGIC: "cgroupfs", /* 0x0027E0EB local */ - CIFS_MAGIC_NUMBER: "cifs", /* 0xFF534D42 remote */ - CODA_SUPER_MAGIC: "coda", /* 0x73757245 remote */ - COH_SUPER_MAGIC: "coh", /* 0x012FF7B7 local */ - CRAMFS_MAGIC: "cramfs", /* 0x28CD3D45 local */ - DEBUGFS_MAGIC: "debugfs", /* 0x64626720 local */ - DEVFS_SUPER_MAGIC: "devfs", /* 0x1373 local */ - DEVPTS_SUPER_MAGIC: "devpts", /* 0x1CD1 local */ - ECRYPTFS_SUPER_MAGIC: "ecryptfs", /* 0xF15F local */ - EFS_SUPER_MAGIC: "efs", /* 0x00414A53 local */ - EXT_SUPER_MAGIC: "ext", /* 0x137D local */ - EXT2_SUPER_MAGIC: "ext2/ext3", /* 0xEF53 local */ - EXT2_OLD_SUPER_MAGIC: "ext2", /* 0xEF51 local */ - FAT_SUPER_MAGIC: "fat", /* 0x4006 local */ - FHGFS_SUPER_MAGIC: "fhgfs", /* 0x19830326 remote */ - FUSEBLK_SUPER_MAGIC: "fuseblk", /* 0x65735546 remote */ - FUSECTL_SUPER_MAGIC: "fusectl", /* 0x65735543 remote */ - FUTEXFS_SUPER_MAGIC: "futexfs", /* 0x0BAD1DEA local */ - GFS_SUPER_MAGIC: "gfs/gfs2", /* 0x1161970 remote */ - GPFS_SUPER_MAGIC: "gpfs", /* 0x47504653 remote */ - HFS_SUPER_MAGIC: "hfs", /* 0x4244 local */ - HPFS_SUPER_MAGIC: "hpfs", /* 0xF995E849 local */ - HUGETLBFS_MAGIC: "hugetlbfs", /* 0x958458F6 local */ - MTD_INODE_FS_SUPER_MAGIC: "inodefs", /* 0x11307854 local */ - INOTIFYFS_SUPER_MAGIC: "inotifyfs", /* 0x2BAD1DEA local */ - ISOFS_SUPER_MAGIC: "isofs", /* 0x9660 local */ - ISOFS_R_WIN_SUPER_MAGIC: "isofs", /* 0x4004 local */ - ISOFS_WIN_SUPER_MAGIC: "isofs", /* 0x4000 local */ - JFFS_SUPER_MAGIC: "jffs", /* 0x07C0 local */ - JFFS2_SUPER_MAGIC: "jffs2", /* 0x72B6 local */ - JFS_SUPER_MAGIC: "jfs", /* 0x3153464A local */ - KAFS_SUPER_MAGIC: "k-afs", /* 0x6B414653 remote */ - LUSTRE_SUPER_MAGIC: "lustre", /* 0x0BD00BD0 remote */ - MINIX_SUPER_MAGIC: "minix", /* 0x137F local */ - MINIX_SUPER_MAGIC2: "minix (30 char.)", /* 0x138F local */ - MINIX2_SUPER_MAGIC: "minix v2", /* 0x2468 local */ - MINIX2_SUPER_MAGIC2: "minix v2 (30 char.)", /* 0x2478 local */ - MINIX3_SUPER_MAGIC: "minix3", /* 0x4D5A local */ - MQUEUE_MAGIC: "mqueue", /* 0x19800202 local */ - MSDOS_SUPER_MAGIC: "msdos", /* 0x4D44 local */ - NCP_SUPER_MAGIC: "novell", /* 0x564C remote */ - NFS_SUPER_MAGIC: "nfs", /* 0x6969 remote */ - NFSD_SUPER_MAGIC: "nfsd", /* 0x6E667364 remote */ - NILFS_SUPER_MAGIC: "nilfs", /* 0x3434 local */ - NTFS_SB_MAGIC: "ntfs", /* 0x5346544E local */ - OPENPROM_SUPER_MAGIC: "openprom", /* 0x9FA1 local */ - OCFS2_SUPER_MAGIC: "ocfs2", /* 0x7461636f remote */ - PANFS_SUPER_MAGIC: "panfs", /* 0xAAD7AAEA remote */ - PIPEFS_MAGIC: "pipefs", /* 0x50495045 remote */ - PROC_SUPER_MAGIC: "proc", /* 0x9FA0 local */ - PSTOREFS_MAGIC: "pstorefs", /* 0x6165676C local */ - QNX4_SUPER_MAGIC: "qnx4", /* 0x002F local */ - QNX6_SUPER_MAGIC: "qnx6", /* 0x68191122 local */ - RAMFS_MAGIC: "ramfs", /* 0x858458F6 local */ - REISERFS_SUPER_MAGIC: "reiserfs", /* 0x52654973 local */ - ROMFS_MAGIC: "romfs", /* 0x7275 local */ - RPC_PIPEFS_SUPER_MAGIC: "rpc_pipefs", /* 0x67596969 local */ - SECURITYFS_SUPER_MAGIC: "securityfs", /* 0x73636673 local */ - SELINUX_MAGIC: "selinux", /* 0xF97CFF8C local */ - SMB_SUPER_MAGIC: "smb", /* 0x517B remote */ - SOCKFS_MAGIC: "sockfs", /* 0x534F434B local */ - SQUASHFS_MAGIC: "squashfs", /* 0x73717368 local */ - SYSFS_MAGIC: "sysfs", /* 0x62656572 local */ - SYSV2_SUPER_MAGIC: "sysv2", /* 0x012FF7B6 local */ - SYSV4_SUPER_MAGIC: "sysv4", /* 0x012FF7B5 local */ - TMPFS_MAGIC: "tmpfs", /* 0x01021994 local */ - UDF_SUPER_MAGIC: "udf", /* 0x15013346 local */ - UFS_MAGIC: "ufs", /* 0x00011954 local */ - UFS_BYTESWAPPED_SUPER_MAGIC: "ufs", /* 0x54190100 local */ - USBDEVICE_SUPER_MAGIC: "usbdevfs", /* 0x9FA2 local */ - V9FS_MAGIC: "v9fs", /* 0x01021997 local */ - VMHGFS_SUPER_MAGIC: "vmhgfs", /* 0xBACBACBC remote */ - VXFS_SUPER_MAGIC: "vxfs", /* 0xA501FCF5 local */ - VZFS_SUPER_MAGIC: "vzfs", /* 0x565A4653 local */ - XENFS_SUPER_MAGIC: "xenfs", /* 0xABBA1974 local */ - XENIX_SUPER_MAGIC: "xenix", /* 0x012FF7B4 local */ - XFS_SUPER_MAGIC: "xfs", /* 0x58465342 local */ - _XIAFS_SUPER_MAGIC: "xia", /* 0x012FD16D local */ - ZFS_SUPER_MAGIC: "zfs", /* 0x2FC12FC1 local */ -} - -// Get disk partitions. -// should use setmntent(3) but this implement use /etc/mtab file -func DiskPartitions(all bool) ([]DiskPartitionStat, error) { - - filename := "/etc/mtab" - lines, err := common.ReadLines(filename) - if err != nil { - return nil, err - } - - ret := make([]DiskPartitionStat, 0, len(lines)) - - for _, line := range lines { - fields := strings.Fields(line) - d := DiskPartitionStat{ - Device: fields[0], - Mountpoint: fields[1], - Fstype: fields[2], - Opts: fields[3], - } - ret = append(ret, d) - } - - return ret, nil -} - -func DiskIOCounters() (map[string]DiskIOCountersStat, error) { - filename := "/proc/diskstats" - lines, err := common.ReadLines(filename) - if err != nil { - return nil, err - } - ret := make(map[string]DiskIOCountersStat, 0) - empty := DiskIOCountersStat{} - - for _, line := range lines { - fields := strings.Fields(line) - name := fields[2] - reads, err := strconv.ParseUint((fields[3]), 10, 64) - if err != nil { - return ret, err - } - rbytes, err := strconv.ParseUint((fields[5]), 10, 64) - if err != nil { - return ret, err - } - rtime, err := strconv.ParseUint((fields[6]), 10, 64) - if err != nil { - return ret, err - } - writes, err := strconv.ParseUint((fields[7]), 10, 64) - if err != nil { - return ret, err - } - wbytes, err := strconv.ParseUint((fields[9]), 10, 64) - if err != nil { - return ret, err - } - wtime, err := strconv.ParseUint((fields[10]), 10, 64) - if err != nil { - return ret, err - } - iotime, err := strconv.ParseUint((fields[12]), 10, 64) - if err != nil { - return ret, err - } - d := DiskIOCountersStat{ - ReadBytes: rbytes * SectorSize, - WriteBytes: wbytes * SectorSize, - ReadCount: reads, - WriteCount: writes, - ReadTime: rtime, - WriteTime: wtime, - IoTime: iotime, - } - if d == empty { - continue - } - d.Name = name - - d.SerialNumber = GetDiskSerialNumber(name) - ret[name] = d - } - return ret, nil -} - -func GetDiskSerialNumber(name string) string { - n := fmt.Sprintf("--name=%s", name) - out, err := exec.Command("/sbin/udevadm", "info", "--query=property", n).Output() - - // does not return error, just an empty string - if err != nil { - return "" - } - lines := strings.Split(string(out), "\n") - for _, line := range lines { - values := strings.Split(line, "=") - if len(values) < 2 || values[0] != "ID_SERIAL" { - // only get ID_SERIAL, not ID_SERIAL_SHORT - continue - } - return values[1] - } - return "" -} - -func getFsType(stat syscall.Statfs_t) string { - t := int64(stat.Type) - ret, ok := fsTypeMap[t] - if !ok { - return "" - } - return ret -} diff --git a/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_test.go b/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_test.go deleted file mode 100644 index 70eb675f460..00000000000 --- a/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_test.go +++ /dev/null @@ -1,97 +0,0 @@ -package disk - -import ( - "fmt" - "runtime" - "testing" -) - -func TestDisk_usage(t *testing.T) { - path := "/" - if runtime.GOOS == "windows" { - path = "C:" - } - v, err := DiskUsage(path) - if err != nil { - t.Errorf("error %v", err) - } - if v.Path != path { - t.Errorf("error %v", err) - } -} - -func TestDisk_partitions(t *testing.T) { - ret, err := DiskPartitions(false) - if err != nil || len(ret) == 0 { - t.Errorf("error %v", err) - } - empty := DiskPartitionStat{} - for _, disk := range ret { - if disk == empty { - t.Errorf("Could not get device info %v", disk) - } - } -} - -func TestDisk_io_counters(t *testing.T) { - ret, err := DiskIOCounters() - if err != nil { - t.Errorf("error %v", err) - } - if len(ret) == 0 { - t.Errorf("ret is empty, %v", ret) - } - empty := DiskIOCountersStat{} - for part, io := range ret { - if io == empty { - t.Errorf("io_counter error %v, %v", part, io) - } - } -} - -func TestDiskUsageStat_String(t *testing.T) { - v := DiskUsageStat{ - Path: "/", - Total: 1000, - Free: 2000, - Used: 3000, - UsedPercent: 50.1, - InodesTotal: 4000, - InodesUsed: 5000, - InodesFree: 6000, - InodesUsedPercent: 49.1, - Fstype: "ext4", - } - e := `{"path":"/","fstype":"ext4","total":1000,"free":2000,"used":3000,"used_percent":50.1,"inodes_total":4000,"inodes_used":5000,"inodes_free":6000,"inodes_used_percent":49.1}` - if e != fmt.Sprintf("%v", v) { - t.Errorf("DiskUsageStat string is invalid: %v", v) - } -} - -func TestDiskPartitionStat_String(t *testing.T) { - v := DiskPartitionStat{ - Device: "sd01", - Mountpoint: "/", - Fstype: "ext4", - Opts: "ro", - } - e := `{"device":"sd01","mountpoint":"/","fstype":"ext4","opts":"ro"}` - if e != fmt.Sprintf("%v", v) { - t.Errorf("DiskUsageStat string is invalid: %v", v) - } -} - -func TestDiskIOCountersStat_String(t *testing.T) { - v := DiskIOCountersStat{ - Name: "sd01", - ReadCount: 100, - WriteCount: 200, - ReadBytes: 300, - WriteBytes: 400, - SerialNumber: "SERIAL", - } - e := `{"read_count":100,"write_count":200,"read_bytes":300,"write_bytes":400,"read_time":0,"write_time":0,"name":"sd01","io_time":0,"serial_number":"SERIAL"}` - if e != fmt.Sprintf("%v", v) { - t.Errorf("DiskUsageStat string is invalid: %v", v) - } -} diff --git a/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_unix.go b/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_unix.go deleted file mode 100644 index f006c1ac526..00000000000 --- a/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_unix.go +++ /dev/null @@ -1,30 +0,0 @@ -// +build freebsd linux darwin - -package disk - -import "syscall" - -func DiskUsage(path string) (*DiskUsageStat, error) { - stat := syscall.Statfs_t{} - err := syscall.Statfs(path, &stat) - if err != nil { - return nil, err - } - bsize := stat.Bsize - - ret := &DiskUsageStat{ - Path: path, - Fstype: getFsType(stat), - Total: (uint64(stat.Blocks) * uint64(bsize)), - Free: (uint64(stat.Bfree) * uint64(bsize)), - InodesTotal: (uint64(stat.Files)), - InodesFree: (uint64(stat.Ffree)), - } - - ret.InodesUsed = (ret.InodesTotal - ret.InodesFree) - ret.InodesUsedPercent = (float64(ret.InodesUsed) / float64(ret.InodesTotal)) * 100.0 - ret.Used = (uint64(stat.Blocks) - uint64(stat.Bfree)) * uint64(bsize) - ret.UsedPercent = (float64(ret.Used) / float64(ret.Total)) * 100.0 - - return ret, nil -} diff --git a/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_windows.go b/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_windows.go deleted file mode 100644 index 3eb265b84f8..00000000000 --- a/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/disk_windows.go +++ /dev/null @@ -1,155 +0,0 @@ -// +build windows - -package disk - -import ( - "bytes" - "syscall" - "unsafe" - - "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/StackExchange/wmi" - - common "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/shirou/gopsutil/common" -) - -var ( - procGetDiskFreeSpaceExW = common.Modkernel32.NewProc("GetDiskFreeSpaceExW") - procGetLogicalDriveStringsW = common.Modkernel32.NewProc("GetLogicalDriveStringsW") - procGetDriveType = common.Modkernel32.NewProc("GetDriveTypeW") - provGetVolumeInformation = common.Modkernel32.NewProc("GetVolumeInformationW") -) - -var ( - FileFileCompression = int64(16) // 0x00000010 - FileReadOnlyVolume = int64(524288) // 0x00080000 -) - -type Win32_PerfFormattedData struct { - Name string - AvgDiskBytesPerRead uint64 - AvgDiskBytesPerWrite uint64 - AvgDiskReadQueueLength uint64 - AvgDiskWriteQueueLength uint64 - AvgDisksecPerRead uint64 - AvgDisksecPerWrite uint64 -} - -const WaitMSec = 500 - -func DiskUsage(path string) (*DiskUsageStat, error) { - ret := &DiskUsageStat{} - - lpFreeBytesAvailable := int64(0) - lpTotalNumberOfBytes := int64(0) - lpTotalNumberOfFreeBytes := int64(0) - diskret, _, err := procGetDiskFreeSpaceExW.Call( - uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(path))), - uintptr(unsafe.Pointer(&lpFreeBytesAvailable)), - uintptr(unsafe.Pointer(&lpTotalNumberOfBytes)), - uintptr(unsafe.Pointer(&lpTotalNumberOfFreeBytes))) - if diskret == 0 { - return nil, err - } - ret = &DiskUsageStat{ - Path: path, - Total: uint64(lpTotalNumberOfBytes), - Free: uint64(lpTotalNumberOfFreeBytes), - Used: uint64(lpTotalNumberOfBytes) - uint64(lpTotalNumberOfFreeBytes), - UsedPercent: (float64(lpTotalNumberOfBytes) - float64(lpTotalNumberOfFreeBytes)) / float64(lpTotalNumberOfBytes) * 100, - // InodesTotal: 0, - // InodesFree: 0, - // InodesUsed: 0, - // InodesUsedPercent: 0, - } - return ret, nil -} - -func DiskPartitions(all bool) ([]DiskPartitionStat, error) { - var ret []DiskPartitionStat - lpBuffer := make([]byte, 254) - diskret, _, err := procGetLogicalDriveStringsW.Call( - uintptr(len(lpBuffer)), - uintptr(unsafe.Pointer(&lpBuffer[0]))) - if diskret == 0 { - return ret, err - } - for _, v := range lpBuffer { - if v >= 65 && v <= 90 { - path := string(v) + ":" - if path == "A:" || path == "B:" { // skip floppy drives - continue - } - typepath, _ := syscall.UTF16PtrFromString(path) - typeret, _, _ := procGetDriveType.Call(uintptr(unsafe.Pointer(typepath))) - if typeret == 0 { - return ret, syscall.GetLastError() - } - // 2: DRIVE_REMOVABLE 3: DRIVE_FIXED 5: DRIVE_CDROM - - if typeret == 2 || typeret == 3 || typeret == 5 { - lpVolumeNameBuffer := make([]byte, 256) - lpVolumeSerialNumber := int64(0) - lpMaximumComponentLength := int64(0) - lpFileSystemFlags := int64(0) - lpFileSystemNameBuffer := make([]byte, 256) - volpath, _ := syscall.UTF16PtrFromString(string(v) + ":/") - driveret, _, err := provGetVolumeInformation.Call( - uintptr(unsafe.Pointer(volpath)), - uintptr(unsafe.Pointer(&lpVolumeNameBuffer[0])), - uintptr(len(lpVolumeNameBuffer)), - uintptr(unsafe.Pointer(&lpVolumeSerialNumber)), - uintptr(unsafe.Pointer(&lpMaximumComponentLength)), - uintptr(unsafe.Pointer(&lpFileSystemFlags)), - uintptr(unsafe.Pointer(&lpFileSystemNameBuffer[0])), - uintptr(len(lpFileSystemNameBuffer))) - if driveret == 0 { - if typeret == 5 { - continue //device is not ready will happen if there is no disk in the drive - } - return ret, err - } - opts := "rw" - if lpFileSystemFlags&FileReadOnlyVolume != 0 { - opts = "ro" - } - if lpFileSystemFlags&FileFileCompression != 0 { - opts += ".compress" - } - - d := DiskPartitionStat{ - Mountpoint: path, - Device: path, - Fstype: string(bytes.Replace(lpFileSystemNameBuffer, []byte("\x00"), []byte(""), -1)), - Opts: opts, - } - ret = append(ret, d) - } - } - } - return ret, nil -} - -func DiskIOCounters() (map[string]DiskIOCountersStat, error) { - ret := make(map[string]DiskIOCountersStat, 0) - var dst []Win32_PerfFormattedData - - err := wmi.Query("SELECT * FROM Win32_PerfFormattedData_PerfDisk_LogicalDisk ", &dst) - if err != nil { - return ret, err - } - for _, d := range dst { - if len(d.Name) > 3 { // not get _Total or Harddrive - continue - } - ret[d.Name] = DiskIOCountersStat{ - Name: d.Name, - ReadCount: uint64(d.AvgDiskReadQueueLength), - WriteCount: d.AvgDiskWriteQueueLength, - ReadBytes: uint64(d.AvgDiskBytesPerRead), - WriteBytes: uint64(d.AvgDiskBytesPerWrite), - ReadTime: d.AvgDisksecPerRead, - WriteTime: d.AvgDisksecPerWrite, - } - } - return ret, nil -} diff --git a/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/types_freebsd.go b/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/types_freebsd.go deleted file mode 100644 index 44869042f7a..00000000000 --- a/Godeps/_workspace/src/github.com/shirou/gopsutil/disk/types_freebsd.go +++ /dev/null @@ -1,85 +0,0 @@ -// +build ignore -// Hand writing: _Ctype_struct___0 - -/* -Input to cgo -godefs. - -*/ - -package disk - -/* -#include -#include -#include - -enum { - sizeofPtr = sizeof(void*), -}; - -// because statinfo has long double snap_time, redefine with changing long long -struct statinfo2 { - long cp_time[CPUSTATES]; - long tk_nin; - long tk_nout; - struct devinfo *dinfo; - long long snap_time; -}; -*/ -import "C" - -// Machine characteristics; for internal use. - -const ( - sizeofPtr = C.sizeofPtr - sizeofShort = C.sizeof_short - sizeofInt = C.sizeof_int - sizeofLong = C.sizeof_long - sizeofLongLong = C.sizeof_longlong - sizeofLongDouble = C.sizeof_longlong - - DEVSTAT_NO_DATA = 0x00 - DEVSTAT_READ = 0x01 - DEVSTAT_WRITE = 0x02 - DEVSTAT_FREE = 0x03 - - // from sys/mount.h - MNT_RDONLY = 0x00000001 /* read only filesystem */ - MNT_SYNCHRONOUS = 0x00000002 /* filesystem written synchronously */ - MNT_NOEXEC = 0x00000004 /* can't exec from filesystem */ - MNT_NOSUID = 0x00000008 /* don't honor setuid bits on fs */ - MNT_UNION = 0x00000020 /* union with underlying filesystem */ - MNT_ASYNC = 0x00000040 /* filesystem written asynchronously */ - MNT_SUIDDIR = 0x00100000 /* special handling of SUID on dirs */ - MNT_SOFTDEP = 0x00200000 /* soft updates being done */ - MNT_NOSYMFOLLOW = 0x00400000 /* do not follow symlinks */ - MNT_GJOURNAL = 0x02000000 /* GEOM journal support enabled */ - MNT_MULTILABEL = 0x04000000 /* MAC support for individual objects */ - MNT_ACLS = 0x08000000 /* ACL support enabled */ - MNT_NOATIME = 0x10000000 /* disable update of file access time */ - MNT_NOCLUSTERR = 0x40000000 /* disable cluster read */ - MNT_NOCLUSTERW = 0x80000000 /* disable cluster write */ - MNT_NFS4ACLS = 0x00000010 - - MNT_WAIT = 1 /* synchronously wait for I/O to complete */ - MNT_NOWAIT = 2 /* start all I/O, but do not wait for it */ - MNT_LAZY = 3 /* push data not written by filesystem syncer */ - MNT_SUSPEND = 4 /* Suspend file system after sync */ - -) - -// Basic types - -type ( - _C_short C.short - _C_int C.int - _C_long C.long - _C_long_long C.longlong - _C_long_double C.longlong -) - -type Statfs C.struct_statfs -type Fsid C.struct_fsid - -type Devstat C.struct_devstat -type Bintime C.struct_bintime diff --git a/Godeps/_workspace/src/github.com/shirou/gopsutil/mem/mem.go b/Godeps/_workspace/src/github.com/shirou/gopsutil/mem/mem.go deleted file mode 100644 index 67f8741e7c9..00000000000 --- a/Godeps/_workspace/src/github.com/shirou/gopsutil/mem/mem.go +++ /dev/null @@ -1,38 +0,0 @@ -package mem - -import ( - "encoding/json" -) - -type VirtualMemoryStat struct { - Total uint64 `json:"total"` - Available uint64 `json:"available"` - Used uint64 `json:"used"` - UsedPercent float64 `json:"used_percent"` - Free uint64 `json:"free"` - Active uint64 `json:"active"` - Inactive uint64 `json:"inactive"` - Buffers uint64 `json:"buffers"` - Cached uint64 `json:"cached"` - Wired uint64 `json:"wired"` - Shared uint64 `json:"shared"` -} - -type SwapMemoryStat struct { - Total uint64 `json:"total"` - Used uint64 `json:"used"` - Free uint64 `json:"free"` - UsedPercent float64 `json:"used_percent"` - Sin uint64 `json:"sin"` - Sout uint64 `json:"sout"` -} - -func (m VirtualMemoryStat) String() string { - s, _ := json.Marshal(m) - return string(s) -} - -func (m SwapMemoryStat) String() string { - s, _ := json.Marshal(m) - return string(s) -} diff --git a/Godeps/_workspace/src/github.com/shirou/gopsutil/mem/mem_darwin.go b/Godeps/_workspace/src/github.com/shirou/gopsutil/mem/mem_darwin.go deleted file mode 100644 index ce74557ee71..00000000000 --- a/Godeps/_workspace/src/github.com/shirou/gopsutil/mem/mem_darwin.go +++ /dev/null @@ -1,153 +0,0 @@ -// +build darwin - -package mem - -import ( - "os/exec" - "strconv" - "strings" - - common "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/shirou/gopsutil/common" -) - -func getPageSize() (uint64, error) { - out, err := exec.Command("pagesize").Output() - if err != nil { - return 0, err - } - o := strings.TrimSpace(string(out)) - p, err := strconv.ParseUint(o, 10, 64) - if err != nil { - return 0, err - } - return p, nil -} - -// Runs vm_stat and returns Free and inactive pages -func getVmStat(pagesize uint64, vms *VirtualMemoryStat) error { - out, err := exec.Command("vm_stat").Output() - if err != nil { - return err - } - return parseVmStat(string(out), pagesize, vms) -} - -func parseVmStat(out string, pagesize uint64, vms *VirtualMemoryStat) error { - var err error - - lines := strings.Split(out, "\n") - for _, line := range lines { - fields := strings.Split(line, ":") - if len(fields) < 2 { - continue - } - key := strings.TrimSpace(fields[0]) - value := strings.Trim(fields[1], " .") - switch key { - case "Pages free": - free, e := strconv.ParseUint(value, 10, 64) - if e != nil { - err = e - } - vms.Free = free * pagesize - case "Pages inactive": - inactive, e := strconv.ParseUint(value, 10, 64) - if e != nil { - err = e - } - vms.Cached += inactive * pagesize - vms.Inactive = inactive * pagesize - case "Pages active": - active, e := strconv.ParseUint(value, 10, 64) - if e != nil { - err = e - } - vms.Active = active * pagesize - case "Pages wired down": - wired, e := strconv.ParseUint(value, 10, 64) - if e != nil { - err = e - } - vms.Wired = wired * pagesize - case "Pages purgeable": - purgeable, e := strconv.ParseUint(value, 10, 64) - if e != nil { - err = e - } - vms.Cached += purgeable * pagesize - } - } - return err -} - -// VirtualMemory returns VirtualmemoryStat. -func VirtualMemory() (*VirtualMemoryStat, error) { - ret := &VirtualMemoryStat{} - - p, err := getPageSize() - if err != nil { - return nil, err - } - t, err := common.DoSysctrl("hw.memsize") - if err != nil { - return nil, err - } - total, err := strconv.ParseUint(t[0], 10, 64) - if err != nil { - return nil, err - } - err = getVmStat(p, ret) - if err != nil { - return nil, err - } - - ret.Available = ret.Free + ret.Cached - ret.Total = total - - ret.Used = ret.Total - ret.Free - ret.UsedPercent = float64(ret.Total-ret.Available) / float64(ret.Total) * 100.0 - - return ret, nil -} - -// SwapMemory returns swapinfo. -func SwapMemory() (*SwapMemoryStat, error) { - var ret *SwapMemoryStat - - swapUsage, err := common.DoSysctrl("vm.swapusage") - if err != nil { - return ret, err - } - - total := strings.Replace(swapUsage[2], "M", "", 1) - used := strings.Replace(swapUsage[5], "M", "", 1) - free := strings.Replace(swapUsage[8], "M", "", 1) - - total_v, err := strconv.ParseFloat(total, 64) - if err != nil { - return nil, err - } - used_v, err := strconv.ParseFloat(used, 64) - if err != nil { - return nil, err - } - free_v, err := strconv.ParseFloat(free, 64) - if err != nil { - return nil, err - } - - u := float64(0) - if total_v != 0 { - u = ((total_v - free_v) / total_v) * 100.0 - } - - // vm.swapusage shows "M", multiply 1000 - ret = &SwapMemoryStat{ - Total: uint64(total_v * 1000), - Used: uint64(used_v * 1000), - Free: uint64(free_v * 1000), - UsedPercent: u, - } - - return ret, nil -} diff --git a/Godeps/_workspace/src/github.com/shirou/gopsutil/mem/mem_darwin_test.go b/Godeps/_workspace/src/github.com/shirou/gopsutil/mem/mem_darwin_test.go deleted file mode 100644 index c52e7d43e43..00000000000 --- a/Godeps/_workspace/src/github.com/shirou/gopsutil/mem/mem_darwin_test.go +++ /dev/null @@ -1,67 +0,0 @@ -// +build darwin - -package mem - -import ( - "testing" -) - -var vm_stat_out = ` -Mach Virtual Memory Statistics: (page size of 4096 bytes) -Pages free: 105885. -Pages active: 725641. -Pages inactive: 449242. -Pages speculative: 6155. -Pages throttled: 0. -Pages wired down: 560835. -Pages purgeable: 128967. -"Translation faults": 622528839. -Pages copy-on-write: 17697839. -Pages zero filled: 311034413. -Pages reactivated: 4705104. -Pages purged: 5605610. -File-backed pages: 349192. -Anonymous pages: 831846. -Pages stored in compressor: 876507. -Pages occupied by compressor: 249167. -Decompressions: 4555025. -Compressions: 7524729. -Pageins: 40532443. -Pageouts: 126496. -Swapins: 2988073. -Swapouts: 3283599. -` - -func TestParseVmStat(t *testing.T) { - ret := &VirtualMemoryStat{} - err := parseVmStat(vm_stat_out, 4096, ret) - - if err != nil { - t.Errorf("Expected no error, got %s\n", err.Error()) - } - - if ret.Free != uint64(105885*4096) { - t.Errorf("Free pages, actual: %d, expected: %d", ret.Free, - 105885*4096) - } - - if ret.Inactive != uint64(449242*4096) { - t.Errorf("Inactive pages, actual: %d, expected: %d", ret.Inactive, - 449242*4096) - } - - if ret.Active != uint64(725641*4096) { - t.Errorf("Active pages, actual: %d, expected: %d", ret.Active, - 725641*4096) - } - - if ret.Wired != uint64(560835*4096) { - t.Errorf("Wired pages, actual: %d, expected: %d", ret.Wired, - 560835*4096) - } - - if ret.Cached != uint64(128967*4096+449242.*4096) { - t.Errorf("Cached pages, actual: %d, expected: %d", ret.Cached, - 128967*4096+449242.*4096) - } -} diff --git a/Godeps/_workspace/src/github.com/shirou/gopsutil/mem/mem_freebsd.go b/Godeps/_workspace/src/github.com/shirou/gopsutil/mem/mem_freebsd.go deleted file mode 100644 index 3ef17ed096f..00000000000 --- a/Godeps/_workspace/src/github.com/shirou/gopsutil/mem/mem_freebsd.go +++ /dev/null @@ -1,129 +0,0 @@ -// +build freebsd - -package mem - -import ( - "os/exec" - "strconv" - "strings" - - common "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/shirou/gopsutil/common" -) - -func VirtualMemory() (*VirtualMemoryStat, error) { - pageSize, err := common.DoSysctrl("vm.stats.vm.v_page_size") - if err != nil { - return nil, err - } - p, err := strconv.ParseUint(pageSize[0], 10, 64) - if err != nil { - return nil, err - } - - pageCount, err := common.DoSysctrl("vm.stats.vm.v_page_count") - if err != nil { - return nil, err - } - free, err := common.DoSysctrl("vm.stats.vm.v_free_count") - if err != nil { - return nil, err - } - active, err := common.DoSysctrl("vm.stats.vm.v_active_count") - if err != nil { - return nil, err - } - inactive, err := common.DoSysctrl("vm.stats.vm.v_inactive_count") - if err != nil { - return nil, err - } - cache, err := common.DoSysctrl("vm.stats.vm.v_cache_count") - if err != nil { - return nil, err - } - buffer, err := common.DoSysctrl("vfs.bufspace") - if err != nil { - return nil, err - } - wired, err := common.DoSysctrl("vm.stats.vm.v_wire_count") - if err != nil { - return nil, err - } - - parsed := make([]uint64, 0, 7) - vv := []string{ - pageCount[0], - free[0], - active[0], - inactive[0], - cache[0], - buffer[0], - wired[0], - } - for _, target := range vv { - t, err := strconv.ParseUint(target, 10, 64) - if err != nil { - return nil, err - } - parsed = append(parsed, t) - } - - ret := &VirtualMemoryStat{ - Total: parsed[0] * p, - Free: parsed[1] * p, - Active: parsed[2] * p, - Inactive: parsed[3] * p, - Cached: parsed[4] * p, - Buffers: parsed[5], - Wired: parsed[6] * p, - } - - ret.Available = ret.Inactive + ret.Cached + ret.Free - ret.Used = ret.Active + ret.Wired + ret.Cached - ret.UsedPercent = float64(ret.Total-ret.Available) / float64(ret.Total) * 100.0 - - return ret, nil -} - -// Return swapinfo -// FreeBSD can have multiple swap devices. but use only first device -func SwapMemory() (*SwapMemoryStat, error) { - out, err := exec.Command("swapinfo").Output() - if err != nil { - return nil, err - } - var ret *SwapMemoryStat - for _, line := range strings.Split(string(out), "\n") { - values := strings.Fields(line) - // skip title line - if len(values) == 0 || values[0] == "Device" { - continue - } - - u := strings.Replace(values[4], "%", "", 1) - total_v, err := strconv.ParseUint(values[1], 10, 64) - if err != nil { - return nil, err - } - used_v, err := strconv.ParseUint(values[2], 10, 64) - if err != nil { - return nil, err - } - free_v, err := strconv.ParseUint(values[3], 10, 64) - if err != nil { - return nil, err - } - up_v, err := strconv.ParseFloat(u, 64) - if err != nil { - return nil, err - } - - ret = &SwapMemoryStat{ - Total: total_v, - Used: used_v, - Free: free_v, - UsedPercent: up_v, - } - } - - return ret, nil -} diff --git a/Godeps/_workspace/src/github.com/shirou/gopsutil/mem/mem_linux.go b/Godeps/_workspace/src/github.com/shirou/gopsutil/mem/mem_linux.go deleted file mode 100644 index 896d4ed60ec..00000000000 --- a/Godeps/_workspace/src/github.com/shirou/gopsutil/mem/mem_linux.go +++ /dev/null @@ -1,99 +0,0 @@ -// +build linux - -package mem - -import ( - "strconv" - "strings" - "syscall" - - common "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/shirou/gopsutil/common" -) - -func VirtualMemory() (*VirtualMemoryStat, error) { - filename := "/proc/meminfo" - lines, _ := common.ReadLines(filename) - // flag if MemAvailable is in /proc/meminfo (kernel 3.14+) - memavail := false - - ret := &VirtualMemoryStat{} - for _, line := range lines { - fields := strings.Split(line, ":") - if len(fields) != 2 { - continue - } - key := strings.TrimSpace(fields[0]) - value := strings.TrimSpace(fields[1]) - value = strings.Replace(value, " kB", "", -1) - - t, err := strconv.ParseUint(value, 10, 64) - if err != nil { - return ret, err - } - switch key { - case "MemTotal": - ret.Total = t * 1024 - case "MemFree": - ret.Free = t * 1024 - case "MemAvailable": - memavail = true - ret.Available = t * 1024 - case "Buffers": - ret.Buffers = t * 1024 - case "Cached": - ret.Cached = t * 1024 - case "Active": - ret.Active = t * 1024 - case "Inactive": - ret.Inactive = t * 1024 - } - } - if !memavail { - ret.Available = ret.Free + ret.Buffers + ret.Cached - } - ret.Used = ret.Total - ret.Free - ret.UsedPercent = float64(ret.Total-ret.Available) / float64(ret.Total) * 100.0 - - return ret, nil -} - -func SwapMemory() (*SwapMemoryStat, error) { - sysinfo := &syscall.Sysinfo_t{} - - if err := syscall.Sysinfo(sysinfo); err != nil { - return nil, err - } - ret := &SwapMemoryStat{ - Total: uint64(sysinfo.Totalswap), - Free: uint64(sysinfo.Freeswap), - } - ret.Used = ret.Total - ret.Free - //check Infinity - if ret.Total != 0 { - ret.UsedPercent = float64(ret.Total-ret.Free) / float64(ret.Total) * 100.0 - } else { - ret.UsedPercent = 0 - } - lines, _ := common.ReadLines("/proc/vmstat") - for _, l := range lines { - fields := strings.Fields(l) - if len(fields) < 2 { - continue - } - switch fields[0] { - case "pswpin": - value, err := strconv.ParseUint(fields[1], 10, 64) - if err != nil { - continue - } - ret.Sin = value * 4 * 1024 - case "pswpout": - value, err := strconv.ParseUint(fields[1], 10, 64) - if err != nil { - continue - } - ret.Sout = value * 4 * 1024 - } - } - return ret, nil -} diff --git a/Godeps/_workspace/src/github.com/shirou/gopsutil/mem/mem_test.go b/Godeps/_workspace/src/github.com/shirou/gopsutil/mem/mem_test.go deleted file mode 100644 index 28693574a5a..00000000000 --- a/Godeps/_workspace/src/github.com/shirou/gopsutil/mem/mem_test.go +++ /dev/null @@ -1,55 +0,0 @@ -package mem - -import ( - "fmt" - "testing" -) - -func TestVirtual_memory(t *testing.T) { - v, err := VirtualMemory() - if err != nil { - t.Errorf("error %v", err) - } - empty := &VirtualMemoryStat{} - if v == empty { - t.Errorf("error %v", v) - } -} - -func TestSwap_memory(t *testing.T) { - v, err := SwapMemory() - if err != nil { - t.Errorf("error %v", err) - } - empty := &SwapMemoryStat{} - if v == empty { - t.Errorf("error %v", v) - } -} - -func TestVirtualMemoryStat_String(t *testing.T) { - v := VirtualMemoryStat{ - Total: 10, - Available: 20, - Used: 30, - UsedPercent: 30.1, - Free: 40, - } - e := `{"total":10,"available":20,"used":30,"used_percent":30.1,"free":40,"active":0,"inactive":0,"buffers":0,"cached":0,"wired":0,"shared":0}` - if e != fmt.Sprintf("%v", v) { - t.Errorf("VirtualMemoryStat string is invalid: %v", v) - } -} - -func TestSwapMemoryStat_String(t *testing.T) { - v := SwapMemoryStat{ - Total: 10, - Used: 30, - Free: 40, - UsedPercent: 30.1, - } - e := `{"total":10,"used":30,"free":40,"used_percent":30.1,"sin":0,"sout":0}` - if e != fmt.Sprintf("%v", v) { - t.Errorf("SwapMemoryStat string is invalid: %v", v) - } -} diff --git a/Godeps/_workspace/src/github.com/shirou/gopsutil/mem/mem_windows.go b/Godeps/_workspace/src/github.com/shirou/gopsutil/mem/mem_windows.go deleted file mode 100644 index ce5f45d91b9..00000000000 --- a/Godeps/_workspace/src/github.com/shirou/gopsutil/mem/mem_windows.go +++ /dev/null @@ -1,50 +0,0 @@ -// +build windows - -package mem - -import ( - "syscall" - "unsafe" - - common "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/shirou/gopsutil/common" -) - -var ( - procGlobalMemoryStatusEx = common.Modkernel32.NewProc("GlobalMemoryStatusEx") -) - -type MEMORYSTATUSEX struct { - cbSize uint32 - dwMemoryLoad uint32 - ullTotalPhys uint64 // in bytes - ullAvailPhys uint64 - ullTotalPageFile uint64 - ullAvailPageFile uint64 - ullTotalVirtual uint64 - ullAvailVirtual uint64 - ullAvailExtendedVirtual uint64 -} - -func VirtualMemory() (*VirtualMemoryStat, error) { - var memInfo MEMORYSTATUSEX - memInfo.cbSize = uint32(unsafe.Sizeof(memInfo)) - mem, _, _ := procGlobalMemoryStatusEx.Call(uintptr(unsafe.Pointer(&memInfo))) - if mem == 0 { - return nil, syscall.GetLastError() - } - - ret := &VirtualMemoryStat{ - Total: memInfo.ullTotalPhys, - Available: memInfo.ullAvailPhys, - UsedPercent: float64(memInfo.dwMemoryLoad), - } - - ret.Used = ret.Total - ret.Available - return ret, nil -} - -func SwapMemory() (*SwapMemoryStat, error) { - ret := &SwapMemoryStat{} - - return ret, nil -} diff --git a/Godeps/_workspace/src/github.com/whyrusleeping/go-sysinfo/info.go b/Godeps/_workspace/src/github.com/whyrusleeping/go-sysinfo/info.go new file mode 100644 index 00000000000..d1be7534111 --- /dev/null +++ b/Godeps/_workspace/src/github.com/whyrusleeping/go-sysinfo/info.go @@ -0,0 +1,38 @@ +package sysinfo + +import ( + "errors" +) + +var ErrPlatformNotSupported = errors.New("this operation is not supported on your platform") + +type DiskStats struct { + Free uint64 + Total uint64 + FsType string +} + +var diskUsageImpl func(string) (*DiskStats, error) + +func DiskUsage(path string) (*DiskStats, error) { + if diskUsageImpl == nil { + return nil, ErrPlatformNotSupported + } + + return diskUsageImpl(path) +} + +type MemStats struct { + Swap uint64 + Used uint64 +} + +var memInfoImpl func() (*MemStats, error) + +func MemoryInfo() (*MemStats, error) { + if memInfoImpl == nil { + return nil, ErrPlatformNotSupported + } + + return memInfoImpl() +} diff --git a/Godeps/_workspace/src/github.com/whyrusleeping/go-sysinfo/info_darwin.go b/Godeps/_workspace/src/github.com/whyrusleeping/go-sysinfo/info_darwin.go new file mode 100644 index 00000000000..c4e17fe44c9 --- /dev/null +++ b/Godeps/_workspace/src/github.com/whyrusleeping/go-sysinfo/info_darwin.go @@ -0,0 +1,32 @@ +package sysinfo + +import ( + "fmt" + "syscall" +) + +func init() { + diskUsageImpl = darwinDiskUsage + memInfoImpl = darwinMemInfo +} + +func darwinDiskUsage(path string) (*DiskStats, error) { + var stfst syscall.Statfs_t + err := syscall.Statfs(path, &stfst) + if err != nil { + return nil, err + } + + free := stfst.Bfree * uint64(stfst.Bsize) + total := stfst.Bavail * uint64(stfst.Bsize) + return &DiskStats{ + Free: free, + Total: total, + FsType: fmt.Sprint(stfst.Type), + }, nil +} + +func darwinMemInfo() (*MemStats, error) { + // TODO: use vm_stat on osx to gather memory information + return new(MemStats), nil +} diff --git a/Godeps/_workspace/src/github.com/whyrusleeping/go-sysinfo/info_linux.go b/Godeps/_workspace/src/github.com/whyrusleeping/go-sysinfo/info_linux.go new file mode 100644 index 00000000000..b5342620118 --- /dev/null +++ b/Godeps/_workspace/src/github.com/whyrusleeping/go-sysinfo/info_linux.go @@ -0,0 +1,70 @@ +package sysinfo + +import ( + "bytes" + "fmt" + "io/ioutil" + "strings" + "syscall" + + humanize "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/dustin/go-humanize" +) + +func init() { + diskUsageImpl = linuxDiskUsage + memInfoImpl = linuxMemInfo +} + +func linuxDiskUsage(path string) (*DiskStats, error) { + var stfst syscall.Statfs_t + err := syscall.Statfs(path, &stfst) + if err != nil { + return nil, err + } + + free := stfst.Bfree * uint64(stfst.Bsize) + total := stfst.Bavail * uint64(stfst.Bsize) + return &DiskStats{ + Free: free, + Total: total, + FsType: fmt.Sprint(stfst.Type), + }, nil +} + +func linuxMemInfo() (*MemStats, error) { + info, err := ioutil.ReadFile("/proc/self/status") + if err != nil { + return nil, err + } + + var stats MemStats + for _, e := range bytes.Split(info, []byte("\n")) { + if !bytes.HasPrefix(e, []byte("Vm")) { + continue + } + + parts := bytes.Split(e, []byte(":")) + if len(parts) != 2 { + return nil, fmt.Errorf("unexpected line in proc stats: %q", string(e)) + } + + val := strings.Trim(string(parts[1]), " \n\t") + switch string(parts[0]) { + case "VmSize": + vmsize, err := humanize.ParseBytes(val) + if err != nil { + return nil, err + } + + stats.Used = vmsize + case "VmSwap": + swapsize, err := humanize.ParseBytes(val) + if err != nil { + return nil, err + } + + stats.Swap = swapsize + } + } + return &stats, nil +} diff --git a/cmd/ipfs/goreq.go b/cmd/ipfs/goreq.go deleted file mode 100644 index 0a3b15a8a40..00000000000 --- a/cmd/ipfs/goreq.go +++ /dev/null @@ -1,3 +0,0 @@ -// +build !go1.5 - -`IPFS needs to be built with go version 1.5 or greater` diff --git a/core/commands/sysdiag.go b/core/commands/sysdiag.go index caa5d70dcf7..48d46cb4263 100644 --- a/core/commands/sysdiag.go +++ b/core/commands/sysdiag.go @@ -9,8 +9,7 @@ import ( config "github.com/ipfs/go-ipfs/repo/config" manet "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr-net" - psud "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/shirou/gopsutil/disk" - psum "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/shirou/gopsutil/mem" + sysi "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/whyrusleeping/go-sysinfo" ) var sysDiagCmd = &cmds.Command{ @@ -91,14 +90,13 @@ func ipfsPath() string { func diskSpaceInfo(out map[string]interface{}) error { di := make(map[string]interface{}) - dinfo, err := psud.DiskUsage(ipfsPath()) + dinfo, err := sysi.DiskUsage(ipfsPath()) if err != nil { return err } - di["fstype"] = dinfo.Fstype + di["fstype"] = dinfo.FsType di["total_space"] = dinfo.Total - di["used_space"] = dinfo.Used di["free_space"] = dinfo.Free out["diskinfo"] = di @@ -107,18 +105,14 @@ func diskSpaceInfo(out map[string]interface{}) error { func memInfo(out map[string]interface{}) error { m := make(map[string]interface{}) - swap, err := psum.SwapMemory() - if err != nil { - return err - } - virt, err := psum.VirtualMemory() + meminf, err := sysi.MemoryInfo() if err != nil { return err } - m["swap"] = swap - m["virt"] = virt + m["swap"] = meminf.Swap + m["virt"] = meminf.Used out["memory"] = m return nil } diff --git a/util/sadhack/godep.go b/util/sadhack/godep.go index e26a2acb713..b7515531cb3 100644 --- a/util/sadhack/godep.go +++ b/util/sadhack/godep.go @@ -7,7 +7,3 @@ import _ "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/dustin/go-hum // imported by chegga/pb on windows, this is here so running godeps on non-windows doesnt // drop it from our vendoring import _ "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/olekukonko/ts" - -// these two are for diagnostics on windows systems -import _ "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/StackExchange/wmi" -import _ "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole"