Files
guestfs-inspect/libguestfs-inspect.h

52 lines
1.2 KiB
C

#include <czmq.h>
enum guestfs_inspect_command_const {
GUESTFS_COMMAND_LS,
/* GUESTFS_COMMAND_TOUCH, */
/* GUESTFS_COMMAND_MKDIR, */
GUESTFS_COMMAND_CAT
};
struct guestfs_ls_args {
size_t paths_length;
char **paths;
};
struct guestfs_cat_args {};
struct guestfs_inpsect_command {
char *name;
enum guestfs_inspect_command_const command;
union {
struct guestfs_ls_args ls;
struct guestfs_cat_args cat;
} args;
};
static char *endpoint() {
// TODO: This should be based on GUESTFS_INSPECT_ENDPOINT, or XDG_RUNTIME_DIR if the former is not set, and default to a sensible path if neither are set.
const char* ep = "ipc:///tmp/guestfs-inspect.sock";
char *res = malloc(strlen(ep) + 1);
strcpy(res, ep);
return res;
}
static zmsg_t *command_to_zmsg(struct guestfs_inpsect_command *command) {
zmsg_t *res = zmsg_new();
zmsg_pushstr(res, command->name);
zmsg_pushmem(res, &(command->command), sizeof(command->command));
switch (command->command) {
case GUESTFS_COMMAND_LS:
zmsg_pushmem(res, &(command->args.ls.paths_length), sizeof(command->args.ls.paths_length));
for (size_t i = 0; i < (command->args.ls.paths_length); i++) {
zmsg_pushstr(res, command->args.ls.paths[i]);
}
break;
}
return res;
}