protocol: add C header work in progress and test client
The test client simply (optionally) requests a list of hashes of an existing file. Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
7f497b2e68
commit
33b1767d05
96
proxmox-protocol/proxmox-protocol.h
Normal file
96
proxmox-protocol/proxmox-protocol.h
Normal file
@ -0,0 +1,96 @@
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef int64_t proxmox_backup_read_cb(void *opaque, void *buffer, uint64_t size);
|
||||
typedef int64_t proxmox_backup_write_cb(void *opaque, const void *buffer, uint64_t size);
|
||||
typedef void proxmox_backup_drop_cb(void *opaque);
|
||||
|
||||
typedef struct ProxmoxBackup ProxmoxBackup;
|
||||
|
||||
extern ProxmoxBackup *proxmox_backup_new(
|
||||
void *opaque,
|
||||
proxmox_backup_read_cb *read_cb,
|
||||
proxmox_backup_write_cb *write_cb,
|
||||
proxmox_backup_drop_cb *drop_cb);
|
||||
|
||||
extern void proxmox_backup_done(ProxmoxBackup *self);
|
||||
|
||||
extern void proxmox_backup_clear_err(ProxmoxBackup *self);
|
||||
extern const char* proxmox_backup_get_error(const ProxmoxBackup *self);
|
||||
|
||||
extern bool proxmox_backup_is_eof(const ProxmoxBackup *self);
|
||||
|
||||
extern int proxmox_backup_wait_for_handshake(ProxmoxBackup *self);
|
||||
|
||||
extern int proxmox_backup_query_hashes(ProxmoxBackup *self, const char *file_name);
|
||||
extern int proxmox_backup_wait_for_hashes(ProxmoxBackup *self);
|
||||
|
||||
extern bool proxmox_backup_is_chunk_available(ProxmoxBackup *self, const void *digest);
|
||||
extern int proxmox_backup_upload_chunk(
|
||||
ProxmoxBackup *self,
|
||||
const void *digest,
|
||||
const void *data,
|
||||
uint64_t size);
|
||||
extern int proxmox_backup_continue_upload(ProxmoxBackup *self);
|
||||
|
||||
extern int proxmox_backup_poll_read(ProxmoxBackup *self);
|
||||
extern int proxmox_backup_poll_send(ProxmoxBackup *self);
|
||||
|
||||
extern int proxmox_backup_wait_for_id(ProxmoxBackup *self, int id);
|
||||
extern int proxmox_backup_discard_id(ProxmoxBackup *self, int id);
|
||||
|
||||
extern int proxmox_backup_create(
|
||||
ProxmoxBackup *self,
|
||||
bool dynamic,
|
||||
const char *backup_type,
|
||||
const char *backup_id,
|
||||
int64_t time_epoch,
|
||||
const char *file_name,
|
||||
size_t chunk_size,
|
||||
int64_t file_size,
|
||||
bool is_new);
|
||||
|
||||
extern int proxmox_backup_dynamic_data(
|
||||
ProxmoxBackup *self,
|
||||
int stream,
|
||||
const void *digest,
|
||||
uint64_t size);
|
||||
|
||||
extern int proxmox_backup_fixed_data(
|
||||
ProxmoxBackup *self,
|
||||
int stream,
|
||||
size_t index,
|
||||
const void *digest);
|
||||
|
||||
|
||||
typedef struct ProxmoxChunker ProxmoxChunker;
|
||||
extern ProxmoxChunker *proxmox_chunker_new(uint64_t chunk_size_avg);
|
||||
extern void proxmox_chunker_done(ProxmoxChunker *self);
|
||||
extern uint64_t proxmox_chunker_scan(ProxmoxChunker *self, const void *data, size_t size);
|
||||
|
||||
extern void proxmox_chunk_digest(const void *data, size_t size, uint8_t (*digest)[32]);
|
||||
|
||||
typedef struct ProxmoxConnector ProxmoxConnector;
|
||||
extern ProxmoxConnector *proxmox_connector_new(
|
||||
const char *user,
|
||||
const char *server,
|
||||
const char *store);
|
||||
extern void proxmox_connector_drop(ProxmoxConnector *self);
|
||||
extern int proxmox_connector_set_password(ProxmoxConnector *self, const char *password);
|
||||
extern int proxmox_connector_set_ticket(
|
||||
ProxmoxConnector *self,
|
||||
const char *ticket,
|
||||
const char *token);
|
||||
extern void proxmox_connector_set_certificate_validation(ProxmoxConnector *self, bool on);
|
||||
extern ProxmoxBackup *proxmox_connector_connect(ProxmoxConnector *self);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
77
tests/proto-client.c
Normal file
77
tests/proto-client.c
Normal file
@ -0,0 +1,77 @@
|
||||
/* Compile with:
|
||||
* $ make
|
||||
* $ gcc -o c-test-client tests/proto-client.c \
|
||||
* -L target/debug/deps -Wl,-rpath -Wl,target/debug/deps -lproxmox_protocol
|
||||
*
|
||||
* Run like:
|
||||
* $ ./c-test-client 'host/backup1/2019-03-06T10:06:52+01:00/foo.catar.fidx'
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../proxmox-protocol/proxmox-protocol.h"
|
||||
|
||||
static bool useClient(ProxmoxBackup *client, int argc, char **argv);
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
ProxmoxConnector *connector = proxmox_connector_new("root@pam", "127.0.0.1:8007", "local");
|
||||
if (!connector) {
|
||||
fprintf(stderr, "failed to create connector: %m\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (proxmox_connector_set_password(connector, "12341234") != 0) {
|
||||
fprintf(stderr, "failed to set password: %m\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
proxmox_connector_set_certificate_validation(connector, false);
|
||||
|
||||
ProxmoxBackup *client = proxmox_connector_connect(connector);
|
||||
if (!client) {
|
||||
fprintf(stderr, "failed to connect\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!useClient(client, argc, argv)) {
|
||||
const char *msg = proxmox_backup_get_error(client);
|
||||
if (msg) {
|
||||
fprintf(stderr, "proxmox client error: %s\n", msg);
|
||||
} else {
|
||||
fprintf(stderr, "unknown proxmox client error\n", msg);
|
||||
}
|
||||
}
|
||||
|
||||
proxmox_backup_done(client);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool
|
||||
useClient(ProxmoxBackup *client, int argc, char **argv)
|
||||
{
|
||||
if (argc <= 1)
|
||||
return true;
|
||||
|
||||
printf("requesting hashes for '%s'\n", argv[1]);
|
||||
int rc = proxmox_backup_query_hashes(client, argv[1]);
|
||||
if (rc < 0)
|
||||
return false;
|
||||
|
||||
for (;;) {
|
||||
printf("Wait iteration...\n");
|
||||
int rc = proxmox_backup_wait_for_hashes(client);
|
||||
if (rc < 0)
|
||||
return false;
|
||||
if (rc)
|
||||
break;
|
||||
}
|
||||
|
||||
printf("got hashes\n");
|
||||
return true;
|
||||
}
|
Loading…
Reference in New Issue
Block a user