r3428: switched to using minimal includes for the auto-generated RPC code.
[gd/samba-autobuild/.git] / source4 / rpc_server / echo / rpc_echo.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    endpoint server for the echo pipe
5
6    Copyright (C) Andrew Tridgell 2003
7    
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.
12    
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.
17    
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.
21 */
22
23 #include "includes.h"
24 #include "librpc/gen_ndr/ndr_echo.h"
25
26
27 static NTSTATUS echo_AddOne(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_AddOne *r)
28 {
29         *r->out.v = *r->in.v + 1;
30         return NT_STATUS_OK;
31 }
32
33 static NTSTATUS echo_EchoData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_EchoData *r)
34 {
35         if (!r->in.len) {
36                 return NT_STATUS_OK;
37         }
38
39         r->out.out_data = talloc(mem_ctx, r->in.len);
40         if (!r->out.out_data) {
41                 return NT_STATUS_NO_MEMORY;
42         }
43         memcpy(r->out.out_data, r->in.in_data, r->in.len);
44
45         return NT_STATUS_OK;
46 }
47
48 static NTSTATUS echo_SinkData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_SinkData *r)
49 {
50         return NT_STATUS_OK;
51 }
52
53 static NTSTATUS echo_SourceData(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_SourceData *r)
54 {
55         int i;
56         for (i=0;i<r->in.len;i++) {
57                 r->out.data[i] = i;
58         }
59
60         return NT_STATUS_OK;
61 }
62
63 static NTSTATUS echo_TestCall(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_TestCall *r)
64 {
65         r->out.s2 = "this is a test string";
66         
67         return NT_STATUS_OK;
68 }
69
70 static NTSTATUS echo_TestCall2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_TestCall2 *r)
71 {
72         r->out.info = talloc(mem_ctx, sizeof(*r->out.info));
73         if (!r->out.info) {
74                 return NT_STATUS_NO_MEMORY;
75         }
76
77         switch (r->in.level) {
78         case 1:
79                 r->out.info->info1.v = 10;
80                 break;
81         case 2:
82                 r->out.info->info2.v = 20;
83                 break;
84         case 3:
85                 r->out.info->info3.v = 30;
86                 break;
87         case 4:
88                 r->out.info->info4.v = 40;
89                 break;
90         case 5:
91                 r->out.info->info5.v1 = 50;
92                 r->out.info->info5.v2 = 60;
93                 break;
94         case 6:
95                 r->out.info->info6.v1 = 70;
96                 r->out.info->info6.info1.v= 80;
97                 break;
98         case 7:
99                 r->out.info->info7.v1 = 80;
100                 r->out.info->info7.info4.v = 90;
101                 break;
102         default:
103                 return NT_STATUS_INVALID_LEVEL;
104         }
105
106         return NT_STATUS_OK;
107 }
108
109 static long echo_TestSleep(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_TestSleep *r)
110 {
111         sleep(r->in.seconds);
112         return r->in.seconds;
113 }
114
115 /* include the generated boilerplate */
116 #include "librpc/gen_ndr/ndr_echo_s.c"