forked from TrueCloudLab/rclone
f38c262471
This changes the interface for the C code to return a struct on the stack that is defined in the code rather than one which is defined by the cgo compiler. This is more future proof and inline with the gomobile interface. This also adds a gomobile interface RcloneMobileRPC which uses generic go types conforming to the gobind restrictions. It also fixes up initialisation errors.
63 lines
1.4 KiB
C
63 lines
1.4 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <dlfcn.h>
|
|
#include "librclone.h"
|
|
|
|
void testRPC(char *method, char *in) {
|
|
struct RcloneRPCResult out = RcloneRPC(method, in);
|
|
printf("status: %d\n", out.Status);
|
|
printf("output: %s\n", out.Output);
|
|
free(out.Output);
|
|
}
|
|
|
|
// noop command
|
|
void testNoOp() {
|
|
printf("test rc/noop\n");
|
|
testRPC("rc/noop",
|
|
"{"
|
|
" \"p1\": [1,\"2\",null,4],"
|
|
" \"p2\": { \"a\":1, \"b\":2 } "
|
|
"}");
|
|
}
|
|
|
|
// error command
|
|
void testError() {
|
|
printf("test rc/error\n");
|
|
testRPC("rc/error",
|
|
"{"
|
|
" \"p1\": [1,\"2\",null,4],"
|
|
" \"p2\": { \"a\":1, \"b\":2 } "
|
|
"}");
|
|
}
|
|
|
|
// copy file using "operations/copyfile" command
|
|
void testCopyFile() {
|
|
printf("test operations/copyfile\n");
|
|
testRPC("operations/copyfile",
|
|
"{"
|
|
"\"srcFs\": \"/tmp\","
|
|
"\"srcRemote\": \"tmpfile\","
|
|
"\"dstFs\": \"/tmp\","
|
|
"\"dstRemote\": \"tmpfile2\""
|
|
"}");
|
|
}
|
|
|
|
// list the remotes
|
|
void testListRemotes() {
|
|
printf("test operations/listremotes\n");
|
|
testRPC("config/listremotes", "{}");
|
|
}
|
|
|
|
int main(int argc, char** argv) {
|
|
printf("c main begin\n");
|
|
RcloneInitialize();
|
|
|
|
testNoOp();
|
|
testError();
|
|
testCopyFile();
|
|
testListRemotes();
|
|
|
|
RcloneFinalize();
|
|
return EXIT_SUCCESS;
|
|
}
|