Adding upstream version 2.52.6.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
a960158181
commit
6d002e9543
441 changed files with 95392 additions and 0 deletions
100
internal/go-ole/oleutil/connection.go
Normal file
100
internal/go-ole/oleutil/connection.go
Normal file
|
@ -0,0 +1,100 @@
|
|||
//go:build windows
|
||||
|
||||
package oleutil
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"unsafe"
|
||||
|
||||
ole "github.com/gofiber/fiber/v2/internal/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, 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
|
||||
}
|
10
internal/go-ole/oleutil/connection_func.go
Normal file
10
internal/go-ole/oleutil/connection_func.go
Normal file
|
@ -0,0 +1,10 @@
|
|||
//go:build !windows
|
||||
|
||||
package oleutil
|
||||
|
||||
import ole "github.com/gofiber/fiber/v2/internal/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)
|
||||
}
|
58
internal/go-ole/oleutil/connection_windows.go
Normal file
58
internal/go-ole/oleutil/connection_windows.go
Normal file
|
@ -0,0 +1,58 @@
|
|||
//go:build windows
|
||||
|
||||
package oleutil
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
ole "github.com/gofiber/fiber/v2/internal/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
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
container.Release()
|
||||
|
||||
return 0, ole.NewError(ole.E_INVALIDARG)
|
||||
}
|
6
internal/go-ole/oleutil/go-get.go
Normal file
6
internal/go-ole/oleutil/go-get.go
Normal file
|
@ -0,0 +1,6 @@
|
|||
// This file is here so go get succeeds as without it errors with:
|
||||
// no buildable Go source files in ...
|
||||
//
|
||||
//go:build !windows
|
||||
|
||||
package oleutil
|
127
internal/go-ole/oleutil/oleutil.go
Normal file
127
internal/go-ole/oleutil/oleutil.go
Normal file
|
@ -0,0 +1,127 @@
|
|||
package oleutil
|
||||
|
||||
import ole "github.com/gofiber/fiber/v2/internal/go-ole"
|
||||
|
||||
// ClassIDFrom retrieves class ID whether given is program ID or application string.
|
||||
func ClassIDFrom(programID string) (classID *ole.GUID, err error) {
|
||||
return ole.ClassIDFrom(programID)
|
||||
}
|
||||
|
||||
// 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 := ole.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 := ole.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) {
|
||||
return disp.InvokeWithOptionalArgs(name, ole.DISPATCH_METHOD, params)
|
||||
}
|
||||
|
||||
// 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) {
|
||||
return disp.InvokeWithOptionalArgs(name, ole.DISPATCH_PROPERTYGET, params)
|
||||
}
|
||||
|
||||
// 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) {
|
||||
return disp.InvokeWithOptionalArgs(name, ole.DISPATCH_PROPERTYPUT, params)
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// PutPropertyRef mutates property reference.
|
||||
func PutPropertyRef(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT, err error) {
|
||||
return disp.InvokeWithOptionalArgs(name, ole.DISPATCH_PROPERTYPUTREF, params)
|
||||
}
|
||||
|
||||
// MustPutPropertyRef mutates property reference or panics.
|
||||
func MustPutPropertyRef(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT) {
|
||||
r, err := PutPropertyRef(disp, name, params...)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func ForEach(disp *ole.IDispatch, f func(v *ole.VARIANT) error) error {
|
||||
newEnum, err := disp.GetProperty("_NewEnum")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer newEnum.Clear()
|
||||
|
||||
enum, err := newEnum.ToIUnknown().IEnumVARIANT(ole.IID_IEnumVariant)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer enum.Release()
|
||||
|
||||
for item, length, err := enum.Next(1); length > 0; item, length, err = enum.Next(1) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if ferr := f(&item); ferr != nil {
|
||||
return ferr
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue