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