export cliproxyHostCall
(hostCtx unsafe.Pointer, method *C.char, request *C.uint8_t, requestLen C.size_t, response *C.cliproxy_buffer)
| 20 | |
| 21 | //export cliproxyHostCall |
| 22 | func cliproxyHostCall(hostCtx unsafe.Pointer, method *C.char, request *C.uint8_t, requestLen C.size_t, response *C.cliproxy_buffer) C.int { |
| 23 | if response != nil { |
| 24 | response.ptr = nil |
| 25 | response.len = 0 |
| 26 | } |
| 27 | if hostCtx == nil || method == nil { |
| 28 | return 1 |
| 29 | } |
| 30 | id := uintptr(*(*C.uintptr_t)(hostCtx)) |
| 31 | rawHost, okHost := hostCallbackEntries.Load(id) |
| 32 | if !okHost { |
| 33 | return 1 |
| 34 | } |
| 35 | entry, okHost := rawHost.(dynamicHostCallbackEntry) |
| 36 | if !okHost || entry.host == nil { |
| 37 | return 1 |
| 38 | } |
| 39 | var requestBytes []byte |
| 40 | if request != nil && requestLen > 0 { |
| 41 | requestBytes = C.GoBytes(unsafe.Pointer(request), C.int(requestLen)) |
| 42 | } |
| 43 | ctx := withHostCallbackPluginID(context.Background(), entry.pluginID) |
| 44 | resp, errCall := entry.host.callFromPlugin(ctx, C.GoString(method), requestBytes) |
| 45 | if errCall != nil { |
| 46 | resp = marshalRPCError("host_call_failed", errCall.Error()) |
| 47 | } |
| 48 | if len(resp) == 0 || response == nil { |
| 49 | return 0 |
| 50 | } |
| 51 | ptr := C.CBytes(resp) |
| 52 | if ptr == nil { |
| 53 | return 1 |
| 54 | } |
| 55 | response.ptr = ptr |
| 56 | response.len = C.size_t(len(resp)) |
| 57 | return 0 |
| 58 | } |
| 59 | |
| 60 | //export cliproxyHostFree |
| 61 | func cliproxyHostFree(ptr unsafe.Pointer, len C.size_t) { |
nothing calls this directly
no test coverage detected