github.com/aergoio/aergo@v1.3.1/contract/keyword.go (about)

     1  package contract
     2  
     3  /*
     4  #include <stdlib.h>
     5  #include "sqlcheck.h"
     6  */
     7  import "C"
     8  import (
     9  	"unsafe"
    10  
    11  	"github.com/derekparker/trie"
    12  )
    13  
    14  var keywords *trie.Trie
    15  
    16  func init() {
    17  	keywords = trie.New()
    18  	keywords.Add("ALTER", nil)
    19  	keywords.Add("CREATE", nil)
    20  	keywords.Add("DELETE", nil)
    21  	keywords.Add("DROP", nil)
    22  	keywords.Add("INSERT", nil)
    23  	keywords.Add("REINDEX", nil)
    24  	keywords.Add("REPLACE", nil)
    25  	keywords.Add("SELECT", nil)
    26  	keywords.Add("UPDATE", nil)
    27  }
    28  
    29  //export PermittedCmd
    30  func PermittedCmd(cmd *C.char) C.int {
    31  	if _, ok := keywords.Find(C.GoString(cmd)); ok {
    32  		return C.int(1)
    33  	}
    34  	return C.int(0)
    35  }
    36  
    37  func cPermittedSql(sql string) bool {
    38  	cstr := C.CString(sql)
    39  	r := C.sqlcheck_is_permitted_sql(cstr)
    40  	var b bool
    41  	if r == C.int(1) {
    42  		b = true
    43  	}
    44  	C.free(unsafe.Pointer(cstr))
    45  	return b
    46  }
    47  
    48  func cReadOnlySql(sql string) bool {
    49  	cstr := C.CString(sql)
    50  	r := C.sqlcheck_is_readonly_sql(cstr)
    51  	var b bool
    52  	if r == C.int(1) {
    53  		b = true
    54  	}
    55  	C.free(unsafe.Pointer(cstr))
    56  	return b
    57  }