// Package gio was automatically generated by github.com/bnema/puregotk DO NOT EDIT package gio import ( "structs" "unsafe" "github.com/ebitengine/purego" "github.com/bnema/puregotk/pkg/core" "github.com/bnema/puregotk/v4/glib" "github.com/bnema/puregotk/v4/gobject/types" ) // Provides an interface for handling proxy connection and payload. type ProxyInterface struct { _ structs.HostLayout GIface uintptr xConnect uintptr xConnectAsync uintptr xConnectFinish uintptr xSupportsHostname uintptr } func (x *ProxyInterface) GoPointer() uintptr { return uintptr(unsafe.Pointer(x)) } // OverrideConnect sets the "connect" callback function. // Connect to proxy server and wrap (if required) the #connection // // to handle payload. func (x *ProxyInterface) OverrideConnect(cb func(Proxy, *IOStream, *ProxyAddress, *Cancellable) *IOStream) { if cb == nil { x.xConnect = 0 } else { x.xConnect = purego.NewCallback(func(ProxyVarp uintptr, ConnectionVarp uintptr, ProxyAddressVarp uintptr, CancellableVarp uintptr) uintptr { ret := cb(&ProxyBase{Ptr: ProxyVarp}, IOStreamNewFromInternalPtr(ConnectionVarp), ProxyAddressNewFromInternalPtr(ProxyAddressVarp), CancellableNewFromInternalPtr(CancellableVarp)) if ret == nil { return 0 } return ret.GoPointer() }) } } // GetConnect gets the "connect" callback function. // Connect to proxy server and wrap (if required) the #connection // // to handle payload. func (x *ProxyInterface) GetConnect() func(Proxy, *IOStream, *ProxyAddress, *Cancellable) *IOStream { if x.xConnect == 0 { return nil } var rawCallback func(ProxyVarp uintptr, ConnectionVarp uintptr, ProxyAddressVarp uintptr, CancellableVarp uintptr) uintptr purego.RegisterFunc(&rawCallback, x.xConnect) return func(ProxyVar Proxy, ConnectionVar *IOStream, ProxyAddressVar *ProxyAddress, CancellableVar *Cancellable) *IOStream { rawRet := rawCallback(ProxyVar.GoPointer(), ConnectionVar.GoPointer(), ProxyAddressVar.GoPointer(), CancellableVar.GoPointer()) if rawRet == 0 { return nil } ret := &IOStream{} ret.Ptr = rawRet return ret } } // OverrideConnectAsync sets the "connect_async" callback function. // Same as connect() but asynchronous. func (x *ProxyInterface) OverrideConnectAsync(cb func(Proxy, *IOStream, *ProxyAddress, *Cancellable, *AsyncReadyCallback, uintptr)) { if cb == nil { x.xConnectAsync = 0 } else { x.xConnectAsync = purego.NewCallback(func(ProxyVarp uintptr, ConnectionVarp uintptr, ProxyAddressVarp uintptr, CancellableVarp uintptr, CallbackVarp uintptr, UserDataVarp uintptr) { cb(&ProxyBase{Ptr: ProxyVarp}, IOStreamNewFromInternalPtr(ConnectionVarp), ProxyAddressNewFromInternalPtr(ProxyAddressVarp), CancellableNewFromInternalPtr(CancellableVarp), (*AsyncReadyCallback)(unsafe.Pointer(CallbackVarp)), UserDataVarp) }) } } // GetConnectAsync gets the "connect_async" callback function. // Same as connect() but asynchronous. func (x *ProxyInterface) GetConnectAsync() func(Proxy, *IOStream, *ProxyAddress, *Cancellable, *AsyncReadyCallback, uintptr) { if x.xConnectAsync == 0 { return nil } var rawCallback func(ProxyVarp uintptr, ConnectionVarp uintptr, ProxyAddressVarp uintptr, CancellableVarp uintptr, CallbackVarp uintptr, UserDataVarp uintptr) purego.RegisterFunc(&rawCallback, x.xConnectAsync) return func(ProxyVar Proxy, ConnectionVar *IOStream, ProxyAddressVar *ProxyAddress, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr) { rawCallback(ProxyVar.GoPointer(), ConnectionVar.GoPointer(), ProxyAddressVar.GoPointer(), CancellableVar.GoPointer(), glib.NewCallbackNullable(CallbackVar), UserDataVar) } } // OverrideConnectFinish sets the "connect_finish" callback function. // Returns the result of connect_async() func (x *ProxyInterface) OverrideConnectFinish(cb func(Proxy, AsyncResult) *IOStream) { if cb == nil { x.xConnectFinish = 0 } else { x.xConnectFinish = purego.NewCallback(func(ProxyVarp uintptr, ResultVarp uintptr) uintptr { ret := cb(&ProxyBase{Ptr: ProxyVarp}, &AsyncResultBase{Ptr: ResultVarp}) if ret == nil { return 0 } return ret.GoPointer() }) } } // GetConnectFinish gets the "connect_finish" callback function. // Returns the result of connect_async() func (x *ProxyInterface) GetConnectFinish() func(Proxy, AsyncResult) *IOStream { if x.xConnectFinish == 0 { return nil } var rawCallback func(ProxyVarp uintptr, ResultVarp uintptr) uintptr purego.RegisterFunc(&rawCallback, x.xConnectFinish) return func(ProxyVar Proxy, ResultVar AsyncResult) *IOStream { rawRet := rawCallback(ProxyVar.GoPointer(), ResultVar.GoPointer()) if rawRet == 0 { return nil } ret := &IOStream{} ret.Ptr = rawRet return ret } } // OverrideSupportsHostname sets the "supports_hostname" callback function. // Returns whether the proxy supports hostname lookups. func (x *ProxyInterface) OverrideSupportsHostname(cb func(Proxy) bool) { if cb == nil { x.xSupportsHostname = 0 } else { x.xSupportsHostname = purego.NewCallback(func(ProxyVarp uintptr) bool { return cb(&ProxyBase{Ptr: ProxyVarp}) }) } } // GetSupportsHostname gets the "supports_hostname" callback function. // Returns whether the proxy supports hostname lookups. func (x *ProxyInterface) GetSupportsHostname() func(Proxy) bool { if x.xSupportsHostname == 0 { return nil } var rawCallback func(ProxyVarp uintptr) bool purego.RegisterFunc(&rawCallback, x.xSupportsHostname) return func(ProxyVar Proxy) bool { return rawCallback(ProxyVar.GoPointer()) } } // A `GProxy` handles connecting to a remote host via a given type of // proxy server. It is implemented by the `gio-proxy` extension point. // The extensions are named after their proxy protocol name. As an // example, a SOCKS5 proxy implementation can be retrieved with the // name `socks5` using the function // [method@Gio.IOExtensionPoint.get_extension_by_name]. type Proxy interface { GoPointer() uintptr SetGoPointer(uintptr) Connect(ConnectionVar *IOStream, ProxyAddressVar *ProxyAddress, CancellableVar *Cancellable) (*IOStream, error) ConnectAsync(ConnectionVar *IOStream, ProxyAddressVar *ProxyAddress, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr) ConnectFinish(ResultVar AsyncResult) (*IOStream, error) SupportsHostname() bool } var xProxyGLibType func() types.GType func ProxyGLibType() types.GType { return xProxyGLibType() } type ProxyBase struct { Ptr uintptr } func (x *ProxyBase) GoPointer() uintptr { if x == nil { return 0 } return x.Ptr } func (x *ProxyBase) SetGoPointer(ptr uintptr) { x.Ptr = ptr } // Given @connection to communicate with a proxy (eg, a // #GSocketConnection that is connected to the proxy server), this // does the necessary handshake to connect to @proxy_address, and if // required, wraps the #GIOStream to handle proxy payload. func (x *ProxyBase) Connect(ConnectionVar *IOStream, ProxyAddressVar *ProxyAddress, CancellableVar *Cancellable) (*IOStream, error) { var cls *IOStream var cerr *glib.Error cret := XGProxyConnect(x.GoPointer(), ConnectionVar.GoPointer(), ProxyAddressVar.GoPointer(), CancellableVar.GoPointer(), &cerr) if cret == 0 { return nil, cerr } cls = &IOStream{} cls.Ptr = cret if cerr == nil { return cls, nil } return cls, cerr } // Asynchronous version of g_proxy_connect(). func (x *ProxyBase) ConnectAsync(ConnectionVar *IOStream, ProxyAddressVar *ProxyAddress, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr) { XGProxyConnectAsync(x.GoPointer(), ConnectionVar.GoPointer(), ProxyAddressVar.GoPointer(), CancellableVar.GoPointer(), glib.NewCallbackNullable(CallbackVar), UserDataVar) } // See g_proxy_connect(). func (x *ProxyBase) ConnectFinish(ResultVar AsyncResult) (*IOStream, error) { var cls *IOStream var cerr *glib.Error cret := XGProxyConnectFinish(x.GoPointer(), ResultVar.GoPointer(), &cerr) if cret == 0 { return nil, cerr } cls = &IOStream{} cls.Ptr = cret if cerr == nil { return cls, nil } return cls, cerr } // Some proxy protocols expect to be passed a hostname, which they // will resolve to an IP address themselves. Others, like SOCKS4, do // not allow this. This function will return %FALSE if @proxy is // implementing such a protocol. When %FALSE is returned, the caller // should resolve the destination hostname first, and then pass a // #GProxyAddress containing the stringified IP address to // g_proxy_connect() or g_proxy_connect_async(). func (x *ProxyBase) SupportsHostname() bool { cret := XGProxySupportsHostname(x.GoPointer()) return cret } var XGProxyConnect func(uintptr, uintptr, uintptr, uintptr, **glib.Error) uintptr var XGProxyConnectAsync func(uintptr, uintptr, uintptr, uintptr, uintptr, uintptr) var XGProxyConnectFinish func(uintptr, uintptr, **glib.Error) uintptr var XGProxySupportsHostname func(uintptr) bool const ( // Extension point for proxy functionality. // See [Extending GIO](overview.html#extending-gio). PROXY_EXTENSION_POINT_NAME string = "gio-proxy" ) var xProxyGetDefaultForProtocol func(string) uintptr // Find the `gio-proxy` extension point for a proxy implementation that supports // the specified protocol. func ProxyGetDefaultForProtocol(ProtocolVar string) *ProxyBase { var cls *ProxyBase cret := xProxyGetDefaultForProtocol(ProtocolVar) if cret == 0 { return nil } cls = &ProxyBase{} cls.Ptr = cret return cls } func init() { core.SetPackageName("GIO", "gio-2.0") core.SetSharedLibraries("GIO", []string{"libgio-2.0.so.0"}) var libs []uintptr for _, libPath := range core.GetPaths("GIO") { lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL) if err != nil { panic(err) } libs = append(libs, lib) } core.PuregoSafeRegister(&xProxyGetDefaultForProtocol, libs, "g_proxy_get_default_for_protocol") core.PuregoSafeRegister(&xProxyGLibType, libs, "g_proxy_get_type") core.PuregoSafeRegister(&XGProxyConnect, libs, "g_proxy_connect") core.PuregoSafeRegister(&XGProxyConnectAsync, libs, "g_proxy_connect_async") core.PuregoSafeRegister(&XGProxyConnectFinish, libs, "g_proxy_connect_finish") core.PuregoSafeRegister(&XGProxySupportsHostname, libs, "g_proxy_supports_hostname") }