]> git.proxmox.com Git - proxmox-backup.git/blame - tests/proto-client.c
api: define subscription key schema and use it
[proxmox-backup.git] / tests / proto-client.c
CommitLineData
33b1767d
WB
1/* Compile with:
2 * $ make
3 * $ gcc -o c-test-client tests/proto-client.c \
4 * -L target/debug/deps -Wl,-rpath -Wl,target/debug/deps -lproxmox_protocol
5 *
6 * Run like:
7 * $ ./c-test-client 'host/backup1/2019-03-06T10:06:52+01:00/foo.catar.fidx'
8 */
9
10#include <stdio.h>
11
12#include "../proxmox-protocol/proxmox-protocol.h"
13
14static bool useClient(ProxmoxBackup *client, int argc, char **argv);
15
16int
17main(int argc, char **argv)
18{
19 (void)argc;
20 (void)argv;
21
22 ProxmoxConnector *connector = proxmox_connector_new("root@pam", "127.0.0.1:8007", "local");
23 if (!connector) {
24 fprintf(stderr, "failed to create connector: %m\n");
25 return 1;
26 }
27
28 if (proxmox_connector_set_password(connector, "12341234") != 0) {
29 fprintf(stderr, "failed to set password: %m\n");
30 return 1;
31 }
32
33 proxmox_connector_set_certificate_validation(connector, false);
34
35 ProxmoxBackup *client = proxmox_connector_connect(connector);
36 if (!client) {
37 fprintf(stderr, "failed to connect\n");
38 return 1;
39 }
40
41 if (!useClient(client, argc, argv)) {
42 const char *msg = proxmox_backup_get_error(client);
43 if (msg) {
44 fprintf(stderr, "proxmox client error: %s\n", msg);
45 } else {
46 fprintf(stderr, "unknown proxmox client error\n", msg);
47 }
48 }
49
50 proxmox_backup_done(client);
51
52 return 0;
53}
54
55static bool
56useClient(ProxmoxBackup *client, int argc, char **argv)
57{
58 if (argc <= 1)
59 return true;
60
61 printf("requesting hashes for '%s'\n", argv[1]);
62 int rc = proxmox_backup_query_hashes(client, argv[1]);
63 if (rc < 0)
64 return false;
65
66 for (;;) {
67 printf("Wait iteration...\n");
68 int rc = proxmox_backup_wait_for_hashes(client);
69 if (rc < 0)
70 return false;
71 if (rc)
72 break;
73 }
74
75 printf("got hashes\n");
76 return true;
77}