forked from open-amt-cloud-toolkit/rpc-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.go
52 lines (45 loc) · 1.27 KB
/
lib.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*********************************************************************
* Copyright (c) Intel Corporation 2021
* SPDX-License-Identifier: Apache-2.0
**********************************************************************/
package main
// NOTE: this file is designed to be built into a C library and the import
// of 'C' introduces a dependency on the gcc toolchain
import "C"
import (
"encoding/csv"
"github.com/jc-lab/intel-amt-host-api/pkg/utils"
"strings"
log "github.com/sirupsen/logrus"
)
//export rpcCheckAccess
func rpcCheckAccess() int {
rc, err := checkAccess()
if err != nil {
log.Error(err.Error())
}
return int(rc)
}
//export rpcExec
func rpcExec(Input *C.char, Output **C.char) int {
if accessStatus := rpcCheckAccess(); accessStatus != int(utils.Success) {
*Output = C.CString(AccessErrMsg)
return accessStatus
}
//create argument array from input string
inputString := C.GoString(Input)
// Split string
r := csv.NewReader(strings.NewReader(inputString))
r.Comma = ' ' // space
args, err := r.Read()
if err != nil {
log.Error(err.Error())
return int(utils.InvalidParameterCombination)
}
args = append([]string{"rpc"}, args...)
rc := runRPC(args)
if rc != utils.Success {
*Output = C.CString("rpcExec failed: " + inputString)
}
return int(rc)
}