r29: setting version
[Samba.git] / source / rpc_client / cli_echo.c
blob03a4ab36ee0d163d219aced9ce926eabccb578da
1 /*
2 Unix SMB/CIFS implementation.
4 RPC pipe client
6 Copyright (C) Tim Potter 2003
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "includes.h"
25 NTSTATUS cli_echo_add_one(struct cli_state *cli, TALLOC_CTX *mem_ctx,
26 uint32 request, uint32 *response)
28 prs_struct qbuf, rbuf;
29 ECHO_Q_ADD_ONE q;
30 ECHO_R_ADD_ONE r;
31 BOOL result = False;
33 ZERO_STRUCT(q);
34 ZERO_STRUCT(r);
36 /* Initialise parse structures */
38 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
39 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
41 /* Marshall data and send request */
43 init_echo_q_add_one(&q, request);
45 if (!echo_io_q_add_one("", &q, &qbuf, 0) ||
46 !rpc_api_pipe_req(cli, ECHO_ADD_ONE, &qbuf, &rbuf))
47 goto done;
49 /* Unmarshall response */
51 if (!echo_io_r_add_one("", &r, &rbuf, 0))
52 goto done;
54 if (response)
55 *response = r.response;
57 result = True;
59 done:
60 prs_mem_free(&qbuf);
61 prs_mem_free(&rbuf);
63 return result ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
66 NTSTATUS cli_echo_data(struct cli_state *cli, TALLOC_CTX *mem_ctx,
67 uint32 size, char *in_data, char **out_data)
69 prs_struct qbuf, rbuf;
70 ECHO_Q_ECHO_DATA q;
71 ECHO_R_ECHO_DATA r;
72 BOOL result = False;
74 ZERO_STRUCT(q);
75 ZERO_STRUCT(r);
77 /* Initialise parse structures */
79 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
80 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
82 /* Marshall data and send request */
84 init_echo_q_echo_data(&q, size, in_data);
86 if (!echo_io_q_echo_data("", &q, &qbuf, 0) ||
87 !rpc_api_pipe_req(cli, ECHO_DATA, &qbuf, &rbuf))
88 goto done;
90 /* Unmarshall response */
92 if (!echo_io_r_echo_data("", &r, &rbuf, 0))
93 goto done;
95 result = True;
97 if (out_data) {
98 *out_data = talloc(mem_ctx, size);
99 memcpy(*out_data, r.data, size);
102 done:
103 prs_mem_free(&qbuf);
104 prs_mem_free(&rbuf);
106 return result ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
109 NTSTATUS cli_echo_sink_data(struct cli_state *cli, TALLOC_CTX *mem_ctx,
110 uint32 size, char *in_data)
112 prs_struct qbuf, rbuf;
113 ECHO_Q_SINK_DATA q;
114 ECHO_R_SINK_DATA r;
115 BOOL result = False;
117 ZERO_STRUCT(q);
118 ZERO_STRUCT(r);
120 /* Initialise parse structures */
122 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
123 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
125 /* Marshall data and send request */
127 init_echo_q_sink_data(&q, size, in_data);
129 if (!echo_io_q_sink_data("", &q, &qbuf, 0) ||
130 !rpc_api_pipe_req(cli, ECHO_SINK_DATA, &qbuf, &rbuf)) {
131 goto done;
134 /* Unmarshall response */
136 if (!echo_io_r_sink_data("", &r, &rbuf, 0)) {
137 goto done;
140 result = True;
142 done:
143 prs_mem_free(&qbuf);
144 prs_mem_free(&rbuf);
146 return result ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
149 NTSTATUS cli_echo_source_data(struct cli_state *cli, TALLOC_CTX *mem_ctx,
150 uint32 size, char **out_data)
152 prs_struct qbuf, rbuf;
153 ECHO_Q_SOURCE_DATA q;
154 ECHO_R_SOURCE_DATA r;
155 BOOL result = False;
157 ZERO_STRUCT(q);
158 ZERO_STRUCT(r);
160 /* Initialise parse structures */
162 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
163 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
165 /* Marshall data and send request */
167 init_echo_q_source_data(&q, size);
169 if (!echo_io_q_source_data("", &q, &qbuf, 0) ||
170 !rpc_api_pipe_req(cli, ECHO_SOURCE_DATA, &qbuf, &rbuf)) {
171 goto done;
174 /* Unmarshall response */
176 if (!echo_io_r_source_data("", &r, &rbuf, 0)) {
177 goto done;
180 result = True;
182 done:
183 prs_mem_free(&qbuf);
184 prs_mem_free(&rbuf);
186 return result ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;