コード例 #1
0
ファイル: swift.go プロジェクト: vanadium/go.swift
//export swift_io_v_v23_security_simple_nativeSetBlessings
func swift_io_v_v23_security_simple_nativeSetBlessings(ctxHandle C.GoContextHandle, encodedSwiftBlessings C.SwiftByteArray, errOut *C.SwiftVError) {
	ctx := context.GoContext(uint64(ctxHandle))
	encodedBlessings := util.GoBytesNoCopy(unsafe.Pointer(&encodedSwiftBlessings))
	var blessings security.Blessings
	if err := vom.Decode(encodedBlessings, &blessings); err != nil {
		ctx.Error("Unable to decode:", err)
		util.ThrowSwiftError(nil, err, unsafe.Pointer(errOut))
		return
	}
	principal := v23.GetPrincipal(ctx)
	if err := principal.BlessingStore().SetDefault(blessings); err != nil {
		util.ThrowSwiftError(nil, err, unsafe.Pointer(errOut))
		return
	}
}
コード例 #2
0
ファイル: swift.go プロジェクト: vanadium/go.swift
//export swift_io_v_impl_google_rpc_ClientImpl_nativeStartCallAsync
func swift_io_v_impl_google_rpc_ClientImpl_nativeStartCallAsync(ctxHandle C.GoContextHandle, cName *C.char, cMethod *C.char, cVomArgs C.SwiftByteArrayArray, skipServerAuth bool, asyncId C.AsyncCallbackIdentifier, successCallback C.SwiftAsyncSuccessHandleCallback, failureCallback C.SwiftAsyncFailureCallback) {
	name := C.GoString(cName)
	method := C.GoString(cMethod)
	ctx := scontext.GoContext(uint64(ctxHandle))
	client := v23.GetClient(ctx)

	// TODO Get args (we don't have VOM yet in Swift so nothing to get until then)
	//	args, err := decodeArgs(env, jVomArgs)
	//	if err != nil {
	//		sutil.ThrowSwiftError(ctx, err, unsafe.Pointer(errOut))
	//		return C.GoClientCallHandle(0)
	//	}
	args := make([]interface{}, 0)

	go func() {
		result, err := doStartCall(ctx, name, method, skipServerAuth == true, client, args)
		if err != nil {
			var swiftVError C.SwiftVError
			sutil.ThrowSwiftError(ctx, err, unsafe.Pointer(&swiftVError))
			sutil.DoFailureCallback(unsafe.Pointer(failureCallback), int32(asyncId), unsafe.Pointer(&swiftVError))
		} else {
			handle := C.GoClientCallHandle(SwiftClientCall(result))
			sutil.DoSuccessHandlerCallback(unsafe.Pointer(successCallback), int32(asyncId), uint64(handle))
		}
	}()
}
コード例 #3
0
ファイル: swift.go プロジェクト: vanadium/go.swift
// Exports the discovery scan API to CGO using JSON to marshal ads
//export swift_io_v_v23_discovery_scan
func swift_io_v_v23_discovery_scan(ctxHandle C.GoContextHandle, discoveryHandle C.GoDiscoveryHandle, query C.SwiftCString, asyncId C.AsyncCallbackIdentifier, callbackBlock C.SwiftAsyncJsonCallback, errOut *C.SwiftVError) bool {
	ctx := scontext.GoContext(uint64(ctxHandle))
	d := GoDiscoveryT(uint64(discoveryHandle))
	goQuery := sutil.GoString(unsafe.Pointer(&query), false)
	ch, err := d.Scan(ctx, goQuery)
	if err != nil {
		sutil.ThrowSwiftError(ctx, err, unsafe.Pointer(errOut))
		return false
	}
	go func() {
		for update := range ch {
			data := struct {
				IsLost bool
				Ad     discovery.Advertisement
			}{
				IsLost: update.IsLost(),
				Ad:     update.Advertisement(),
			}
			b, err := json.Marshal(data)
			if err != nil {
				ctx.Fatal("Unable to JSON serialize discovery update: ", err)
			}
			ba := swiftBytesCopy(b)
			C.CallScanCallback(callbackBlock, asyncId, ba)
			C.free(ba.data)
		}
		C.CallScanCallback(callbackBlock, asyncId, emptySwiftByteArray())
	}()
	return true
}
コード例 #4
0
ファイル: swift.go プロジェクト: vanadium/go.swift
//export swift_io_v_impl_google_rpc_ClientCallImpl_nativeCloseSend
func swift_io_v_impl_google_rpc_ClientCallImpl_nativeCloseSend(ctxHandle C.GoContextHandle, callHandle C.GoClientCallHandle, errOut *C.SwiftVError) {
	ctx := scontext.GoContext(uint64(ctxHandle))
	call := GoClientCall(uint64(callHandle))
	if err := call.CloseSend(); err != nil {
		sutil.ThrowSwiftError(ctx, err, unsafe.Pointer(errOut))
		return
	}
}
コード例 #5
0
ファイル: swift.go プロジェクト: vanadium/go.swift
//export swift_io_v_v23_V_nativeInitLogging
func swift_io_v_v23_V_nativeInitLogging(logDir *C.char, logToStderr bool, logLevel int, moduleSpec *C.char, errOut *C.SwiftVError) {
	dir, toStderr, level, vmodule, err := loggingOpts(C.GoString(logDir), logToStderr, logLevel, C.GoString(moduleSpec))
	if err != nil {
		sutil.ThrowSwiftError(nil, err, unsafe.Pointer(errOut))
		return
	}
	vlog.Log.Configure(vlog.OverridePriorConfiguration(true), dir, toStderr, level, vmodule)
}
コード例 #6
0
ファイル: swift.go プロジェクト: vanadium/go.swift
//export swift_io_v_v23_discovery_new
func swift_io_v_v23_discovery_new(ctxHandle C.GoContextHandle, errOut *C.SwiftVError) C.GoDiscoveryHandle {
	ctx := scontext.GoContext(uint64(ctxHandle))
	d, err := v23.NewDiscovery(ctx)
	if err != nil {
		sutil.ThrowSwiftError(ctx, err, unsafe.Pointer(errOut))
		return C.GoDiscoveryHandle(0)
	}
	return C.GoDiscoveryHandle(sutil.GoNewRef(&d))
}
コード例 #7
0
ファイル: swift.go プロジェクト: vanadium/go.swift
//export swift_io_v_v23_V_nativeInitGlobal
func swift_io_v_v23_V_nativeInitGlobal(credentialsDir *C.char, errOut *C.SwiftVError) {
	// Send all vlog logs to stderr during the init so that we don't crash on android trying
	// to create a log file.  These settings will be overwritten in nativeInitLogging below.
	vlog.Log.Configure(vlog.OverridePriorConfiguration(true), vlog.LogToStderr(true))

	if credentialsDir != nil {
		dir := C.GoString(credentialsDir)
		os.Setenv(ref.EnvCredentials, dir)
	}
	if err := sv23.Init(); err != nil {
		sutil.ThrowSwiftError(nil, err, unsafe.Pointer(errOut))
		return
	}
	if err := sgoogle.Init(); err != nil {
		sutil.ThrowSwiftError(nil, err, unsafe.Pointer(errOut))
		return
	}
}
コード例 #8
0
ファイル: swift.go プロジェクト: vanadium/go.swift
//export swift_io_v_v23_context_VContext_nativeWithCancel
func swift_io_v_v23_context_VContext_nativeWithCancel(ctxHandle C.GoContextHandle, errOut C.SwiftVErrorPtr) C.GoCancelableContextHandle {
	ctx := GoContext(uint64(ctxHandle))
	ctx, cancelFunc := context.WithCancel(ctx)
	swiftCtx, err := SwiftCancelableContext(ctx, cancelFunc)
	if err != nil {
		sutil.ThrowSwiftError(ctx, err, unsafe.Pointer(errOut))
		return C.GoCancelableContextHandle(0)
	}
	return C.GoCancelableContextHandle(swiftCtx)
}
コード例 #9
0
ファイル: swift.go プロジェクト: vanadium/go.swift
//export swift_io_v_v23_security_simple_nativePublicKey
func swift_io_v_v23_security_simple_nativePublicKey(ctxHandle C.GoContextHandle, errOut *C.SwiftVError) *C.char {
	ctx := context.GoContext(uint64(ctxHandle))
	der, err := v23.GetPrincipal(ctx).PublicKey().MarshalBinary()
	if err != nil {
		util.ThrowSwiftError(nil, err, unsafe.Pointer(errOut))
		return nil
	}
	// Swift will have to free the allocation
	return C.CString(base64.URLEncoding.EncodeToString(der))
}
コード例 #10
0
ファイル: swift.go プロジェクト: vanadium/go.swift
//export swift_io_v_impl_google_rt_VRuntimeImpl_nativeWithNewClient
func swift_io_v_impl_google_rt_VRuntimeImpl_nativeWithNewClient(ctxHandle C.GoContextHandle, errOut *C.SwiftVError) C.GoContextHandle {
	ctx := scontext.GoContext(uint64(ctxHandle))
	// No options supported yet.
	newCtx, _, err := v23.WithNewClient(ctx)
	if err != nil {
		sutil.ThrowSwiftError(ctx, err, unsafe.Pointer(errOut))
		return C.GoContextHandle(0)
	}

	return C.GoContextHandle(scontext.SwiftContext(newCtx))
}
コード例 #11
0
ファイル: swift.go プロジェクト: vanadium/go.swift
//export swift_io_v_v23_context_VContext_nativeWithTimeout
func swift_io_v_v23_context_VContext_nativeWithTimeout(ctxHandle C.GoContextHandle, nsTimeout C.double, errOut *C.SwiftVError) C.GoCancelableContextHandle {
	ctx := GoContext(uint64(ctxHandle))
	timeout := sutil.GoDuration(float64(nsTimeout))
	ctx, cancelFunc := context.WithTimeout(ctx, timeout)
	swiftCtx, err := SwiftCancelableContext(ctx, cancelFunc)
	if err != nil {
		sutil.ThrowSwiftError(ctx, err, unsafe.Pointer(errOut))
		return C.GoCancelableContextHandle(0)
	}
	return C.GoCancelableContextHandle(swiftCtx)
}
コード例 #12
0
ファイル: swift.go プロジェクト: vanadium/go.swift
//export swift_io_v_v23_context_VContext_nativeWithDeadline
func swift_io_v_v23_context_VContext_nativeWithDeadline(ctxHandle C.GoContextHandle, deadlineEpoch C.double, errOut C.SwiftVErrorPtr) C.GoCancelableContextHandle {
	ctx := GoContext(uint64(ctxHandle))
	deadline := sutil.GoTime(float64(deadlineEpoch))
	ctx, cancelFunc := context.WithDeadline(ctx, deadline)
	swiftCtx, err := SwiftCancelableContext(ctx, cancelFunc)
	if err != nil {
		sutil.ThrowSwiftError(ctx, err, unsafe.Pointer(errOut))
		return C.GoCancelableContextHandle(0)
	}
	return C.GoCancelableContextHandle(swiftCtx)
}
コード例 #13
0
ファイル: swift.go プロジェクト: vanadium/go.swift
//export swift_io_v_impl_google_rpc_ClientCallImpl_nativeFinishAsync
func swift_io_v_impl_google_rpc_ClientCallImpl_nativeFinishAsync(ctxHandle C.GoContextHandle, callHandle C.GoClientCallHandle, numResults int, asyncId C.AsyncCallbackIdentifier, successCallback C.SwiftAsyncSuccessByteArrayArrayCallback, failureCallback C.SwiftAsyncFailureCallback) {
	ctx := scontext.GoContext(uint64(ctxHandle))
	call := GoClientCall(uint64(callHandle))
	go func() {
		result, err := doFinish(call, numResults)
		if err != nil {
			var swiftVError C.SwiftVError
			sutil.ThrowSwiftError(ctx, err, unsafe.Pointer(&swiftVError))
			sutil.DoFailureCallback(unsafe.Pointer(failureCallback), int32(asyncId), unsafe.Pointer(&swiftVError))
		} else {
			sutil.DoSuccessByteArrayArrayCallback(unsafe.Pointer(successCallback), int32(asyncId), unsafe.Pointer(&result))
		}
	}()
}
コード例 #14
0
ファイル: swift.go プロジェクト: vanadium/go.swift
// Exports the discovery advertise API to CGO using JSON to marshal ads
//export swift_io_v_v23_discovery_advertise
func swift_io_v_v23_discovery_advertise(ctxHandle C.GoContextHandle, discoveryHandle C.GoDiscoveryHandle, adJson C.SwiftByteArray, visibilityArray C.SwiftCStringArray, asyncId C.AsyncCallbackIdentifier, doneCallback C.SwiftAsyncSuccessCallback, errOut *C.SwiftVError) bool {
	ctx := scontext.GoContext(uint64(ctxHandle))
	d := GoDiscoveryT(uint64(discoveryHandle))
	ad := discovery.Advertisement{}
	if err := json.Unmarshal(sutil.GoBytesNoCopy(unsafe.Pointer(&adJson)), &ad); err != nil {
		sutil.ThrowSwiftError(ctx, err, unsafe.Pointer(errOut))
		return false
	}
	var visibility []security.BlessingPattern
	for _, v := range visibilityArray.toStrings() {
		visibility = append(visibility, security.BlessingPattern(v))
	}
	doneChan, err := d.Advertise(ctx, &ad, visibility)
	if err != nil {
		sutil.ThrowSwiftError(ctx, err, unsafe.Pointer(errOut))
		return false
	}
	go func() {
		<-doneChan
		C.CallAdvertisingCallback(doneCallback, asyncId)
	}()
	return true
}