r20124: clean up nested extern declaration warnings
[Samba/gebeck_regimport.git] / source3 / rpcclient / cmd_echo.c
blobb8058fa28a0794640238886faec3fd3faf0739c3
1 /*
2 Unix SMB/CIFS implementation.
3 RPC pipe client
5 Copyright (C) Tim Potter 2003
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "includes.h"
23 #include "rpcclient.h"
25 static NTSTATUS cmd_echo_add_one(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
26 int argc, const char **argv)
28 uint32 request = 1, response;
29 NTSTATUS result;
31 if (argc > 2) {
32 printf("Usage: %s [num]\n", argv[0]);
33 return NT_STATUS_OK;
36 if (argc == 2)
37 request = atoi(argv[1]);
39 result = rpccli_echo_AddOne(cli, mem_ctx, request, &response);
41 if (!NT_STATUS_IS_OK(result))
42 goto done;
44 printf("%d + 1 = %d\n", request, response);
46 done:
47 return result;
50 static NTSTATUS cmd_echo_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
51 int argc, const char **argv)
53 uint32 size, i;
54 NTSTATUS result;
55 uint8 *in_data = NULL, *out_data = NULL;
57 if (argc != 2) {
58 printf("Usage: %s num\n", argv[0]);
59 return NT_STATUS_OK;
62 size = atoi(argv[1]);
63 in_data = (uint8 *)SMB_MALLOC(size);
65 for (i = 0; i < size; i++)
66 in_data[i] = i & 0xff;
68 result = rpccli_echo_EchoData(cli, mem_ctx, size, in_data, &out_data);
70 if (!NT_STATUS_IS_OK(result))
71 goto done;
73 for (i = 0; i < size; i++) {
74 if (in_data[i] != out_data[i]) {
75 printf("mismatch at offset %d, %d != %d\n",
76 i, in_data[i], out_data[i]);
77 result = NT_STATUS_UNSUCCESSFUL;
81 done:
82 SAFE_FREE(in_data);
83 TALLOC_FREE(out_data);
85 return result;
88 static NTSTATUS cmd_echo_source_data(struct rpc_pipe_client *cli,
89 TALLOC_CTX *mem_ctx, int argc,
90 const char **argv)
92 uint32 size, i;
93 NTSTATUS result;
94 uint8 *out_data;
96 if (argc != 2) {
97 printf("Usage: %s num\n", argv[0]);
98 return NT_STATUS_OK;
101 size = atoi(argv[1]);
103 result = rpccli_echo_SourceData(cli, mem_ctx, size, &out_data);
105 if (!NT_STATUS_IS_OK(result))
106 goto done;
108 for (i = 0; i < size; i++) {
109 if (out_data[i] != (i & 0xff)) {
110 printf("mismatch at offset %d, %d != %d\n",
111 i, out_data[i], i & 0xff);
112 result = NT_STATUS_UNSUCCESSFUL;
116 done:
117 TALLOC_FREE(out_data);
119 return result;
122 static NTSTATUS cmd_echo_sink_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
123 int argc, const char **argv)
125 uint32 size, i;
126 NTSTATUS result;
127 uint8 *in_data = NULL;
129 if (argc != 2) {
130 printf("Usage: %s num\n", argv[0]);
131 return NT_STATUS_OK;
134 size = atoi(argv[1]);
135 in_data = (uint8 *)SMB_MALLOC(size);
137 for (i = 0; i < size; i++)
138 in_data[i] = i & 0xff;
140 result = rpccli_echo_SinkData(cli, mem_ctx, size, in_data);
142 if (!NT_STATUS_IS_OK(result))
143 goto done;
145 done:
146 SAFE_FREE(in_data);
148 return result;
151 /* List of commands exported by this module */
153 struct cmd_set echo_commands[] = {
155 { "ECHO" },
157 { "echoaddone", RPC_RTYPE_NTSTATUS, cmd_echo_add_one, NULL, PI_RPCECHO, NULL, "Add one to a number", "" },
158 { "echodata", RPC_RTYPE_NTSTATUS, cmd_echo_data, NULL, PI_RPCECHO, NULL, "Echo data", "" },
159 { "sinkdata", RPC_RTYPE_NTSTATUS, cmd_echo_sink_data, NULL, PI_RPCECHO, NULL, "Sink data", "" },
160 { "sourcedata", RPC_RTYPE_NTSTATUS, cmd_echo_source_data, NULL, PI_RPCECHO, NULL, "Source data", "" },
161 { NULL }