mirror of
https://github.com/rwinkhart/cmutton.git
synced 2026-09-05 16:47:28 -04:00
Add helper function for passing Go string slices to C; document some functions that won't be ported
This commit is contained in:
@@ -27,6 +27,21 @@ func getPascalStringFromBytes(goBytes []byte) C.PascalString {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getCPascalStringArrayFromStringSlice converts a Go slice
|
||||||
|
// of strings to a C array of pascal strings.
|
||||||
|
func getCPascalStringArrayFromStringSlice(goSlice []string) *C.PascalString {
|
||||||
|
// allocate C array for PascalStrings
|
||||||
|
cArrPtr := (*C.PascalString)(C.malloc(C.size_t(len(goSlice)) * C.size_t(C.sizeof_PascalString)))
|
||||||
|
|
||||||
|
// populate the array with the decrypted lines
|
||||||
|
cArr := (*[1 << 30]C.PascalString)(unsafe.Pointer(cArrPtr))[:len(goSlice):len(goSlice)]
|
||||||
|
for i := range goSlice {
|
||||||
|
cArr[i] = getPascalString(goSlice[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
return cArrPtr
|
||||||
|
}
|
||||||
|
|
||||||
// GetPascalStringFromCString is a helper meant to be used from C.
|
// GetPascalStringFromCString is a helper meant to be used from C.
|
||||||
//
|
//
|
||||||
//export GetPascalStringFromCString
|
//export GetPascalStringFromCString
|
||||||
|
|||||||
@@ -111,11 +111,11 @@ int main() {
|
|||||||
- [ ] ShearRemote(vanityPath string, onlyShearAgeFile bool) error
|
- [ ] ShearRemote(vanityPath string, onlyShearAgeFile bool) error
|
||||||
- [ ] RunJob() (*syncListsT, error)
|
- [ ] RunJob() (*syncListsT, error)
|
||||||
- [ ] synccommon
|
- [ ] synccommon
|
||||||
- [ ] AddFolderLocal(vanityPath string) error
|
- [X] ~~AddFolderLocal(vanityPath string) error~~ (not for use outside of libmutton)
|
||||||
- [ ] RenameLocal(oldVanityPath, newVanityPath string) error
|
- [X] ~~RenameLocal(oldVanityPath, newVanityPath string) error~~ (not for use outside of libmutton)
|
||||||
- [ ] ShearAgeFileLocal(vanityPath string) error
|
- [X] ~~ShearAgeFileLocal(vanityPath string) error~~ (not for use outside of libmutton)
|
||||||
- [ ] ShearLocal(vanityPath, clientDeviceID string, onlyShearAgeFile bool) (string, bool, error)
|
- [X] ~~ShearLocal(vanityPath, clientDeviceID string, onlyShearAgeFile bool) (string, bool, error)~~ (not for use outside of libmutton)
|
||||||
- [ ] WalkEntryDir() ([]string, []string, error)
|
- [ ] WalkEntryDir() ([]string, []string, error)
|
||||||
- [ ] GetAllEntryData() (EntryMapT, error)
|
- [X] ~~GetAllEntryData() (EntryMapT, error)~~ (not easy to port to C; also not needed)
|
||||||
- [ ] syncserver
|
- [ ] syncserver
|
||||||
- [ ] GetRemoteDataFromServer(clientDeviceID string)
|
- [ ] GetRemoteDataFromServer(clientDeviceID string)
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ package main
|
|||||||
// #include "types.h"
|
// #include "types.h"
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"github.com/rwinkhart/libmutton/crypt"
|
"github.com/rwinkhart/libmutton/crypt"
|
||||||
"github.com/rwinkhart/rcw/wrappers"
|
"github.com/rwinkhart/rcw/wrappers"
|
||||||
)
|
)
|
||||||
@@ -28,16 +26,7 @@ func DecryptFileToSlice(realPath, rcwPassword C.PascalString) (*C.char, *C.Pasca
|
|||||||
return nil, nil, 0
|
return nil, nil, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// allocate C array for PascalStrings
|
return nil, getCPascalStringArrayFromStringSlice(lines), C.int(len(lines))
|
||||||
cLinesPtr := (*C.PascalString)(C.malloc(C.size_t(len(lines)) * C.size_t(C.sizeof_PascalString)))
|
|
||||||
|
|
||||||
// populate the array with the decrypted lines
|
|
||||||
cLinesSlice := (*[1 << 30]C.PascalString)(unsafe.Pointer(cLinesPtr))[:len(lines):len(lines)]
|
|
||||||
for i, line := range lines {
|
|
||||||
cLinesSlice[i] = getPascalString(line)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, cLinesPtr, C.int(len(lines))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// EncryptBytes returns:
|
// EncryptBytes returns:
|
||||||
|
|||||||
Reference in New Issue
Block a user