Example #1
0
static gboolean
test_sync(void)
{
    int rv;
    int p[2];
    ipc_binary_proto_t *proto;
    ipc_binary_cmd_t *cmd;
    struct proto_and_fd data;
    GThread *child;

    if (pipe(p) == -1) {
	perror("pipe");
	return FALSE;
    }

    proto = ipc_binary_proto_new(0xE10E);
    cmd = ipc_binary_proto_add_cmd(proto, MY_PROTO_CMD1);
    ipc_binary_cmd_add_arg(cmd, MY_PROTO_HOSTNAME, IPC_BINARY_STRING);
    ipc_binary_cmd_add_arg(cmd, MY_PROTO_DISK, IPC_BINARY_STRING|IPC_BINARY_OPTIONAL);
    cmd = ipc_binary_proto_add_cmd(proto, MY_PROTO_CMD2);
    ipc_binary_cmd_add_arg(cmd, MY_PROTO_DATA, 0);

    /* start the child thread */
    data.proto = proto;
    data.fd = p[1];
    child = g_thread_create(test_sync_child, &data, TRUE, NULL);

    /* run the parent and collect the results */
    rv = test_sync_parent(proto, p[0]) && GPOINTER_TO_INT(g_thread_join(child));
    return (rv) ? TRUE : FALSE;
}
Example #2
0
ipc_binary_proto_t *
get_ndmp_proxy_proto(void)
{
    static ipc_binary_proto_t *proto = NULL;
    static GStaticMutex mutex = G_STATIC_MUTEX_INIT;

    g_static_mutex_lock(&mutex);
    if (!proto) {
	ipc_binary_cmd_t *cmd;

	proto = ipc_binary_proto_new(0xC74F);

	/* Note that numbers here (NDMP_PROXY_COUNT) are represented as
	 * strings.
	 *
	 * NDMP_PROXY_SERVICE is one of "DEVICE", "APPLICATION", or "CHANGER".
	 *
	 * Error codes are stringified versions of the relevant NDMP constants,
	 * e.g., NDMP9_ILLEGAL_ARGS_ERR.  NDMP_PROXY_ERROR is just a string.  Where
	 * both are provided in a reply, either both args are omitted or both are
	 * present.
	 */

	cmd = ipc_binary_proto_add_cmd(proto, NDMP_PROXY_CMD_SELECT_SERVICE);
	ipc_binary_cmd_add_arg(cmd, NDMP_PROXY_SERVICE, IPC_BINARY_STRING);

	cmd = ipc_binary_proto_add_cmd(proto, NDMP_PROXY_REPLY_GENERIC);
	ipc_binary_cmd_add_arg(cmd, NDMP_PROXY_ERRCODE, IPC_BINARY_STRING | IPC_BINARY_OPTIONAL);
	ipc_binary_cmd_add_arg(cmd, NDMP_PROXY_ERROR, IPC_BINARY_STRING | IPC_BINARY_OPTIONAL);

	cmd = ipc_binary_proto_add_cmd(proto, NDMP_PROXY_CMD_TAPE_OPEN);
	ipc_binary_cmd_add_arg(cmd, NDMP_PROXY_FILENAME, IPC_BINARY_STRING);
	ipc_binary_cmd_add_arg(cmd, NDMP_PROXY_MODE, IPC_BINARY_STRING);
	ipc_binary_cmd_add_arg(cmd, NDMP_PROXY_HOST, IPC_BINARY_STRING);
	ipc_binary_cmd_add_arg(cmd, NDMP_PROXY_PORT, IPC_BINARY_STRING);
	ipc_binary_cmd_add_arg(cmd, NDMP_PROXY_USERNAME, IPC_BINARY_STRING);
	ipc_binary_cmd_add_arg(cmd, NDMP_PROXY_PASSWORD, IPC_BINARY_STRING);
	/* ndmp-proxy gives generic reply */

	cmd = ipc_binary_proto_add_cmd(proto, NDMP_PROXY_CMD_TAPE_CLOSE);
	/* ndmp-proxy gives generic reply */

	cmd = ipc_binary_proto_add_cmd(proto, NDMP_PROXY_CMD_TAPE_MTIO);
	/* COMMAND can be one of "REWIND" or "EOF" */
	ipc_binary_cmd_add_arg(cmd, NDMP_PROXY_COMMAND, IPC_BINARY_STRING);
	ipc_binary_cmd_add_arg(cmd, NDMP_PROXY_COUNT, IPC_BINARY_STRING);
	/* ndmp-proxy gives generic reply */

	cmd = ipc_binary_proto_add_cmd(proto, NDMP_PROXY_CMD_TAPE_WRITE);
	ipc_binary_cmd_add_arg(cmd, NDMP_PROXY_DATA, 0);
	/* ndmp-proxy gives generic reply */

	cmd = ipc_binary_proto_add_cmd(proto, NDMP_PROXY_CMD_TAPE_READ);
	ipc_binary_cmd_add_arg(cmd, NDMP_PROXY_COUNT, IPC_BINARY_STRING);

	cmd = ipc_binary_proto_add_cmd(proto, NDMP_PROXY_REPLY_TAPE_READ);
	ipc_binary_cmd_add_arg(cmd, NDMP_PROXY_DATA, IPC_BINARY_OPTIONAL);
	ipc_binary_cmd_add_arg(cmd, NDMP_PROXY_ERRCODE, IPC_BINARY_STRING | IPC_BINARY_OPTIONAL);
	ipc_binary_cmd_add_arg(cmd, NDMP_PROXY_ERROR, IPC_BINARY_STRING | IPC_BINARY_OPTIONAL);
    }

    g_static_mutex_unlock(&mutex);
    return proto;
}