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