2021-02-26 11:41:38 +01:00
|
|
|
// Package librclone exports shims for C library use
|
|
|
|
//
|
|
|
|
// This directory contains code to build rclone as a C library and the
|
|
|
|
// shims for accessing rclone from C.
|
|
|
|
//
|
|
|
|
// The shims are a thin wrapper over the rclone RPC.
|
|
|
|
//
|
|
|
|
// Build a shared library like this:
|
|
|
|
//
|
|
|
|
// go build --buildmode=c-shared -o librclone.so github.com/rclone/rclone/librclone
|
|
|
|
//
|
|
|
|
// Build a static library like this:
|
|
|
|
//
|
|
|
|
// go build --buildmode=c-archive -o librclone.a github.com/rclone/rclone/librclone
|
|
|
|
//
|
|
|
|
// Both the above commands will also generate `librclone.h` which should
|
|
|
|
// be `#include`d in `C` programs wishing to use the library.
|
|
|
|
//
|
|
|
|
// The library will depend on `libdl` and `libpthread`.
|
2020-12-31 03:32:52 +01:00
|
|
|
package main
|
|
|
|
|
2021-03-30 11:02:48 +02:00
|
|
|
/*
|
|
|
|
struct RcloneRPCResult {
|
|
|
|
char* Output;
|
|
|
|
int Status;
|
|
|
|
};
|
|
|
|
*/
|
|
|
|
import "C"
|
2021-02-26 11:41:38 +01:00
|
|
|
|
2021-03-30 11:02:48 +02:00
|
|
|
import (
|
2021-04-28 13:58:08 +02:00
|
|
|
"github.com/rclone/rclone/librclone/librclone"
|
2020-12-31 03:32:52 +01:00
|
|
|
|
|
|
|
_ "github.com/rclone/rclone/backend/all" // import all backends
|
|
|
|
_ "github.com/rclone/rclone/lib/plugin" // import plugins
|
|
|
|
)
|
|
|
|
|
2021-02-26 11:41:38 +01:00
|
|
|
// RcloneInitialize initializes rclone as a library
|
|
|
|
//
|
|
|
|
//export RcloneInitialize
|
|
|
|
func RcloneInitialize() {
|
2021-04-28 13:58:08 +02:00
|
|
|
librclone.Initialize()
|
2020-12-31 03:32:52 +01:00
|
|
|
}
|
|
|
|
|
2021-02-26 11:41:38 +01:00
|
|
|
// RcloneFinalize finalizes the library
|
|
|
|
//
|
|
|
|
//export RcloneFinalize
|
|
|
|
func RcloneFinalize() {
|
2021-04-28 13:58:08 +02:00
|
|
|
librclone.Finalize()
|
2020-12-31 03:32:52 +01:00
|
|
|
}
|
|
|
|
|
2021-03-30 11:02:48 +02:00
|
|
|
// RcloneRPCResult is returned from RcloneRPC
|
|
|
|
//
|
|
|
|
// Output will be returned as a serialized JSON object
|
|
|
|
// Status is a HTTP status return (200=OK anything else fail)
|
2021-03-30 12:37:59 +02:00
|
|
|
type RcloneRPCResult struct { //nolint:deadcode
|
2021-03-30 11:02:48 +02:00
|
|
|
Output *C.char
|
|
|
|
Status C.int
|
|
|
|
}
|
|
|
|
|
2021-02-26 11:41:38 +01:00
|
|
|
// RcloneRPC does a single RPC call. The inputs are (method, input)
|
|
|
|
// and the output is (output, status). This is an exported interface
|
|
|
|
// to the rclone API as described in https://rclone.org/rc/
|
|
|
|
//
|
|
|
|
// method is a string, eg "operations/list"
|
|
|
|
// input should be a serialized JSON object
|
2021-03-30 11:02:48 +02:00
|
|
|
// result.Output will be returned as a serialized JSON object
|
|
|
|
// result.Status is a HTTP status return (200=OK anything else fail)
|
2021-02-26 11:41:38 +01:00
|
|
|
//
|
2021-03-30 11:02:48 +02:00
|
|
|
// Caller is responsible for freeing the memory for result.Output,
|
|
|
|
// result itself is passed on the stack.
|
2021-02-26 11:41:38 +01:00
|
|
|
//
|
|
|
|
//export RcloneRPC
|
2021-03-30 11:02:48 +02:00
|
|
|
func RcloneRPC(method *C.char, input *C.char) (result C.struct_RcloneRPCResult) { //nolint:golint
|
2021-04-28 13:58:08 +02:00
|
|
|
output, status := librclone.RPC(C.GoString(method), C.GoString(input))
|
2021-03-30 11:02:48 +02:00
|
|
|
result.Output = C.CString(output)
|
|
|
|
result.Status = C.int(status)
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2021-02-26 11:41:38 +01:00
|
|
|
// do nothing here - necessary for building into a C library
|
2020-12-31 03:32:52 +01:00
|
|
|
func main() {}
|