1// Package gio was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package gio
3
4import (
5 "structs"
6 "unsafe"
7
8 "github.com/ebitengine/purego"
9
10 "github.com/bnema/puregotk/pkg/core"
11 "github.com/bnema/puregotk/v4/glib"
12 "github.com/bnema/puregotk/v4/gobject/types"
13)
14
15// Provides an interface for handling proxy connection and payload.
16type ProxyInterface struct {
17 _ structs.HostLayout
18
19 GIface uintptr
20
21 xConnect uintptr
22
23 xConnectAsync uintptr
24
25 xConnectFinish uintptr
26
27 xSupportsHostname uintptr
28}
29
30func (x *ProxyInterface) GoPointer() uintptr {
31 return uintptr(unsafe.Pointer(x))
32}
33
34// OverrideConnect sets the "connect" callback function.
35// Connect to proxy server and wrap (if required) the #connection
36//
37// to handle payload.
38func (x *ProxyInterface) OverrideConnect(cb func(Proxy, *IOStream, *ProxyAddress, *Cancellable) *IOStream) {
39 if cb == nil {
40 x.xConnect = 0
41 } else {
42 x.xConnect = purego.NewCallback(func(ProxyVarp uintptr, ConnectionVarp uintptr, ProxyAddressVarp uintptr, CancellableVarp uintptr) uintptr {
43 ret := cb(&ProxyBase{Ptr: ProxyVarp}, IOStreamNewFromInternalPtr(ConnectionVarp), ProxyAddressNewFromInternalPtr(ProxyAddressVarp), CancellableNewFromInternalPtr(CancellableVarp))
44 if ret == nil {
45 return 0
46 }
47 return ret.GoPointer()
48 })
49 }
50}
51
52// GetConnect gets the "connect" callback function.
53// Connect to proxy server and wrap (if required) the #connection
54//
55// to handle payload.
56func (x *ProxyInterface) GetConnect() func(Proxy, *IOStream, *ProxyAddress, *Cancellable) *IOStream {
57 if x.xConnect == 0 {
58 return nil
59 }
60 var rawCallback func(ProxyVarp uintptr, ConnectionVarp uintptr, ProxyAddressVarp uintptr, CancellableVarp uintptr) uintptr
61 purego.RegisterFunc(&rawCallback, x.xConnect)
62 return func(ProxyVar Proxy, ConnectionVar *IOStream, ProxyAddressVar *ProxyAddress, CancellableVar *Cancellable) *IOStream {
63 rawRet := rawCallback(ProxyVar.GoPointer(), ConnectionVar.GoPointer(), ProxyAddressVar.GoPointer(), CancellableVar.GoPointer())
64 if rawRet == 0 {
65 return nil
66 }
67 ret := &IOStream{}
68 ret.Ptr = rawRet
69 return ret
70 }
71}
72
73// OverrideConnectAsync sets the "connect_async" callback function.
74// Same as connect() but asynchronous.
75func (x *ProxyInterface) OverrideConnectAsync(cb func(Proxy, *IOStream, *ProxyAddress, *Cancellable, *AsyncReadyCallback, uintptr)) {
76 if cb == nil {
77 x.xConnectAsync = 0
78 } else {
79 x.xConnectAsync = purego.NewCallback(func(ProxyVarp uintptr, ConnectionVarp uintptr, ProxyAddressVarp uintptr, CancellableVarp uintptr, CallbackVarp uintptr, UserDataVarp uintptr) {
80 cb(&ProxyBase{Ptr: ProxyVarp}, IOStreamNewFromInternalPtr(ConnectionVarp), ProxyAddressNewFromInternalPtr(ProxyAddressVarp), CancellableNewFromInternalPtr(CancellableVarp), (*AsyncReadyCallback)(unsafe.Pointer(CallbackVarp)), UserDataVarp)
81 })
82 }
83}
84
85// GetConnectAsync gets the "connect_async" callback function.
86// Same as connect() but asynchronous.
87func (x *ProxyInterface) GetConnectAsync() func(Proxy, *IOStream, *ProxyAddress, *Cancellable, *AsyncReadyCallback, uintptr) {
88 if x.xConnectAsync == 0 {
89 return nil
90 }
91 var rawCallback func(ProxyVarp uintptr, ConnectionVarp uintptr, ProxyAddressVarp uintptr, CancellableVarp uintptr, CallbackVarp uintptr, UserDataVarp uintptr)
92 purego.RegisterFunc(&rawCallback, x.xConnectAsync)
93 return func(ProxyVar Proxy, ConnectionVar *IOStream, ProxyAddressVar *ProxyAddress, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr) {
94 rawCallback(ProxyVar.GoPointer(), ConnectionVar.GoPointer(), ProxyAddressVar.GoPointer(), CancellableVar.GoPointer(), glib.NewCallbackNullable(CallbackVar), UserDataVar)
95 }
96}
97
98// OverrideConnectFinish sets the "connect_finish" callback function.
99// Returns the result of connect_async()
100func (x *ProxyInterface) OverrideConnectFinish(cb func(Proxy, AsyncResult) *IOStream) {
101 if cb == nil {
102 x.xConnectFinish = 0
103 } else {
104 x.xConnectFinish = purego.NewCallback(func(ProxyVarp uintptr, ResultVarp uintptr) uintptr {
105 ret := cb(&ProxyBase{Ptr: ProxyVarp}, &AsyncResultBase{Ptr: ResultVarp})
106 if ret == nil {
107 return 0
108 }
109 return ret.GoPointer()
110 })
111 }
112}
113
114// GetConnectFinish gets the "connect_finish" callback function.
115// Returns the result of connect_async()
116func (x *ProxyInterface) GetConnectFinish() func(Proxy, AsyncResult) *IOStream {
117 if x.xConnectFinish == 0 {
118 return nil
119 }
120 var rawCallback func(ProxyVarp uintptr, ResultVarp uintptr) uintptr
121 purego.RegisterFunc(&rawCallback, x.xConnectFinish)
122 return func(ProxyVar Proxy, ResultVar AsyncResult) *IOStream {
123 rawRet := rawCallback(ProxyVar.GoPointer(), ResultVar.GoPointer())
124 if rawRet == 0 {
125 return nil
126 }
127 ret := &IOStream{}
128 ret.Ptr = rawRet
129 return ret
130 }
131}
132
133// OverrideSupportsHostname sets the "supports_hostname" callback function.
134// Returns whether the proxy supports hostname lookups.
135func (x *ProxyInterface) OverrideSupportsHostname(cb func(Proxy) bool) {
136 if cb == nil {
137 x.xSupportsHostname = 0
138 } else {
139 x.xSupportsHostname = purego.NewCallback(func(ProxyVarp uintptr) bool {
140 return cb(&ProxyBase{Ptr: ProxyVarp})
141 })
142 }
143}
144
145// GetSupportsHostname gets the "supports_hostname" callback function.
146// Returns whether the proxy supports hostname lookups.
147func (x *ProxyInterface) GetSupportsHostname() func(Proxy) bool {
148 if x.xSupportsHostname == 0 {
149 return nil
150 }
151 var rawCallback func(ProxyVarp uintptr) bool
152 purego.RegisterFunc(&rawCallback, x.xSupportsHostname)
153 return func(ProxyVar Proxy) bool {
154 return rawCallback(ProxyVar.GoPointer())
155 }
156}
157
158// A `GProxy` handles connecting to a remote host via a given type of
159// proxy server. It is implemented by the `gio-proxy` extension point.
160// The extensions are named after their proxy protocol name. As an
161// example, a SOCKS5 proxy implementation can be retrieved with the
162// name `socks5` using the function
163// [method@Gio.IOExtensionPoint.get_extension_by_name].
164type Proxy interface {
165 GoPointer() uintptr
166 SetGoPointer(uintptr)
167 Connect(ConnectionVar *IOStream, ProxyAddressVar *ProxyAddress, CancellableVar *Cancellable) (*IOStream, error)
168 ConnectAsync(ConnectionVar *IOStream, ProxyAddressVar *ProxyAddress, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr)
169 ConnectFinish(ResultVar AsyncResult) (*IOStream, error)
170 SupportsHostname() bool
171}
172
173var xProxyGLibType func() types.GType
174
175func ProxyGLibType() types.GType {
176 return xProxyGLibType()
177}
178
179type ProxyBase struct {
180 Ptr uintptr
181}
182
183func (x *ProxyBase) GoPointer() uintptr {
184 if x == nil {
185 return 0
186 }
187 return x.Ptr
188}
189
190func (x *ProxyBase) SetGoPointer(ptr uintptr) {
191 x.Ptr = ptr
192}
193
194// Given @connection to communicate with a proxy (eg, a
195// #GSocketConnection that is connected to the proxy server), this
196// does the necessary handshake to connect to @proxy_address, and if
197// required, wraps the #GIOStream to handle proxy payload.
198func (x *ProxyBase) Connect(ConnectionVar *IOStream, ProxyAddressVar *ProxyAddress, CancellableVar *Cancellable) (*IOStream, error) {
199 var cls *IOStream
200 var cerr *glib.Error
201
202 cret := XGProxyConnect(x.GoPointer(), ConnectionVar.GoPointer(), ProxyAddressVar.GoPointer(), CancellableVar.GoPointer(), &cerr)
203
204 if cret == 0 {
205 return nil, cerr
206 }
207 cls = &IOStream{}
208 cls.Ptr = cret
209 if cerr == nil {
210 return cls, nil
211 }
212 return cls, cerr
213
214}
215
216// Asynchronous version of g_proxy_connect().
217func (x *ProxyBase) ConnectAsync(ConnectionVar *IOStream, ProxyAddressVar *ProxyAddress, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr) {
218
219 XGProxyConnectAsync(x.GoPointer(), ConnectionVar.GoPointer(), ProxyAddressVar.GoPointer(), CancellableVar.GoPointer(), glib.NewCallbackNullable(CallbackVar), UserDataVar)
220
221}
222
223// See g_proxy_connect().
224func (x *ProxyBase) ConnectFinish(ResultVar AsyncResult) (*IOStream, error) {
225 var cls *IOStream
226 var cerr *glib.Error
227
228 cret := XGProxyConnectFinish(x.GoPointer(), ResultVar.GoPointer(), &cerr)
229
230 if cret == 0 {
231 return nil, cerr
232 }
233 cls = &IOStream{}
234 cls.Ptr = cret
235 if cerr == nil {
236 return cls, nil
237 }
238 return cls, cerr
239
240}
241
242// Some proxy protocols expect to be passed a hostname, which they
243// will resolve to an IP address themselves. Others, like SOCKS4, do
244// not allow this. This function will return %FALSE if @proxy is
245// implementing such a protocol. When %FALSE is returned, the caller
246// should resolve the destination hostname first, and then pass a
247// #GProxyAddress containing the stringified IP address to
248// g_proxy_connect() or g_proxy_connect_async().
249func (x *ProxyBase) SupportsHostname() bool {
250
251 cret := XGProxySupportsHostname(x.GoPointer())
252 return cret
253}
254
255var XGProxyConnect func(uintptr, uintptr, uintptr, uintptr, **glib.Error) uintptr
256var XGProxyConnectAsync func(uintptr, uintptr, uintptr, uintptr, uintptr, uintptr)
257var XGProxyConnectFinish func(uintptr, uintptr, **glib.Error) uintptr
258var XGProxySupportsHostname func(uintptr) bool
259
260const (
261 // Extension point for proxy functionality.
262 // See [Extending GIO](overview.html#extending-gio).
263 PROXY_EXTENSION_POINT_NAME string = "gio-proxy"
264)
265
266var xProxyGetDefaultForProtocol func(string) uintptr
267
268// Find the `gio-proxy` extension point for a proxy implementation that supports
269// the specified protocol.
270func ProxyGetDefaultForProtocol(ProtocolVar string) *ProxyBase {
271 var cls *ProxyBase
272
273 cret := xProxyGetDefaultForProtocol(ProtocolVar)
274
275 if cret == 0 {
276 return nil
277 }
278 cls = &ProxyBase{}
279 cls.Ptr = cret
280 return cls
281}
282
283func init() {
284 core.SetPackageName("GIO", "gio-2.0")
285 core.SetSharedLibraries("GIO", []string{"libgio-2.0.so.0"})
286 var libs []uintptr
287 for _, libPath := range core.GetPaths("GIO") {
288 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
289 if err != nil {
290 panic(err)
291 }
292 libs = append(libs, lib)
293 }
294
295 core.PuregoSafeRegister(&xProxyGetDefaultForProtocol, libs, "g_proxy_get_default_for_protocol")
296
297 core.PuregoSafeRegister(&xProxyGLibType, libs, "g_proxy_get_type")
298
299 core.PuregoSafeRegister(&XGProxyConnect, libs, "g_proxy_connect")
300 core.PuregoSafeRegister(&XGProxyConnectAsync, libs, "g_proxy_connect_async")
301 core.PuregoSafeRegister(&XGProxyConnectFinish, libs, "g_proxy_connect_finish")
302 core.PuregoSafeRegister(&XGProxySupportsHostname, libs, "g_proxy_supports_hostname")
303
304}