r10656: BIG merge from trunk. Features not copied over
[ira/wip.git] / source3 / rpc_client / cli_echo.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    RPC pipe client
5
6    Copyright (C) Tim Potter 2003
7    Copyright (C) Jeremy Allison 2005.
8    
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 2 of the License, or
12    (at your option) any later version.
13    
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18    
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 #include "includes.h"
25
26 NTSTATUS rpccli_echo_add_one(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
27                           uint32 request, uint32 *response)
28 {
29         prs_struct qbuf, rbuf;
30         ECHO_Q_ADD_ONE q;
31         ECHO_R_ADD_ONE r;
32         BOOL result = False;
33
34         ZERO_STRUCT(q);
35         ZERO_STRUCT(r);
36
37         /* Marshall data and send request */
38
39         init_echo_q_add_one(&q, request);
40
41         CLI_DO_RPC( cli, mem_ctx, PI_ECHO, ECHO_ADD_ONE,
42                         q, r,
43                         qbuf, rbuf,
44                         echo_io_q_add_one,
45                         echo_io_r_add_one,
46                         NT_STATUS_UNSUCCESSFUL);
47
48         if (response)
49                 *response = r.response;
50
51         result = True;
52
53         return result ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
54 }
55
56 NTSTATUS rpccli_echo_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
57                        uint32 size, char *in_data, char **out_data)
58 {
59         prs_struct qbuf, rbuf;
60         ECHO_Q_ECHO_DATA q;
61         ECHO_R_ECHO_DATA r;
62         BOOL result = False;
63
64         ZERO_STRUCT(q);
65         ZERO_STRUCT(r);
66
67         /* Marshall data and send request */
68
69         init_echo_q_echo_data(&q, size, in_data);
70
71         CLI_DO_RPC( cli, mem_ctx, PI_ECHO, ECHO_DATA,
72                         q, r,
73                         qbuf, rbuf,
74                         echo_io_q_echo_data,
75                         echo_io_r_echo_data,
76                         NT_STATUS_UNSUCCESSFUL);
77
78         result = True;
79
80         if (out_data) {
81                 *out_data = TALLOC(mem_ctx, size);
82                 memcpy(*out_data, r.data, size);
83         }
84
85         return result ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
86 }
87
88 NTSTATUS rpccli_echo_sink_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
89                             uint32 size, char *in_data)
90 {
91         prs_struct qbuf, rbuf;
92         ECHO_Q_SINK_DATA q;
93         ECHO_R_SINK_DATA r;
94         BOOL result = False;
95
96         ZERO_STRUCT(q);
97         ZERO_STRUCT(r);
98
99         /* Marshall data and send request */
100
101         init_echo_q_sink_data(&q, size, in_data);
102
103         CLI_DO_RPC( cli, mem_ctx, PI_ECHO, ECHO_SINK_DATA,
104                         q, r,
105                         qbuf, rbuf,
106                         echo_io_q_sink_data,
107                         echo_io_r_sink_data,
108                         NT_STATUS_UNSUCCESSFUL);
109
110         result = True;
111
112         return result ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
113 }
114
115 NTSTATUS rpccli_echo_source_data(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
116                               uint32 size, char **out_data)
117 {
118         prs_struct qbuf, rbuf;
119         ECHO_Q_SOURCE_DATA q;
120         ECHO_R_SOURCE_DATA r;
121         BOOL result = False;
122
123         ZERO_STRUCT(q);
124         ZERO_STRUCT(r);
125
126         /* Marshall data and send request */
127
128         init_echo_q_source_data(&q, size);
129
130         CLI_DO_RPC( cli, mem_ctx, PI_ECHO, ECHO_SOURCE_DATA,
131                         q, r,
132                         qbuf, rbuf,
133                         echo_io_q_source_data,
134                         echo_io_r_source_data,
135                         NT_STATUS_UNSUCCESSFUL);
136
137         result = True;
138
139         return result ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
140 }