08d54ceba4fc267e75dda8d1cc04b058cf813044
[ira/wip.git] / source3 / rpc_server / srv_echo_nt.c
1 /* 
2  *  Unix SMB/CIFS implementation.
3  *  RPC Pipe client / server routines for rpcecho
4  *  Copyright (C) Tim Potter                   2003
5  *  Copyright (C) Jelmer Vernooij              2006
6  *  Copyright (C) Gerald (Jerry) Carter        2007
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 /* This is the interface to the rpcecho pipe. */
24
25 #include "includes.h"
26 #include "nterr.h"
27
28 #ifdef DEVELOPER
29
30 #undef DBGC_CLASS
31 #define DBGC_CLASS DBGC_RPC_SRV
32
33 /* Add one to the input and return it */
34
35 void _echo_AddOne(pipes_struct *p, struct echo_AddOne *r )
36 {
37         DEBUG(10, ("_echo_AddOne\n"));
38
39         *r->out.out_data = r->in.in_data + 1;
40 }
41
42 /* Echo back an array of data */
43
44 void _echo_EchoData(pipes_struct *p, struct echo_EchoData *r)
45 {
46         DEBUG(10, ("_echo_EchoData\n"));
47
48         if ( r->in.len == 0 ) {         
49                 r->out.out_data = NULL;
50                 return;
51         }
52
53         r->out.out_data = TALLOC(p->mem_ctx, r->in.len);        
54         memcpy( r->out.out_data, r->in.in_data, r->in.len );
55         return; 
56 }
57
58 /* Sink an array of data */
59
60 void _echo_SinkData(pipes_struct *p, struct echo_SinkData *r)
61 {
62         DEBUG(10, ("_echo_SinkData\n"));
63
64         /* My that was some yummy data! */
65         return; 
66 }
67
68 /* Source an array of data */
69
70 void _echo_SourceData(pipes_struct *p, struct echo_SourceData *r)
71 {
72         uint32 i;
73
74         DEBUG(10, ("_echo_SourceData\n"));
75
76         if ( r->in.len == 0 ) {
77                 r->out.data = NULL;             
78                 return;
79         }
80
81         r->out.data = TALLOC(p->mem_ctx, r->in.len );
82
83         for (i = 0; i < r->in.len; i++ ) {              
84                 r->out.data[i] = i & 0xff;
85         }
86         
87         return; 
88 }
89
90 void _echo_TestCall(pipes_struct *p, struct echo_TestCall *r)
91 {
92         *r->out.s2 = talloc_strdup(p->mem_ctx, r->in.s1);
93 }
94
95 NTSTATUS _echo_TestCall2(pipes_struct *p, struct echo_TestCall2 *r)
96 {
97         switch (r->in.level) {
98         case 1:
99                 r->out.info->info1.v = 10;
100                 break;
101         case 2:
102                 r->out.info->info2.v = 20;
103                 break;
104         case 3:
105                 r->out.info->info3.v = 30;
106                 break;
107         case 4:
108                 r->out.info->info4.v = 40;
109                 break;
110         case 5:
111                 r->out.info->info5.v1 = 50;
112                 r->out.info->info5.v2 = 60;
113                 break;
114         case 6:
115                 r->out.info->info6.v1 = 70;
116                 r->out.info->info6.info1.v= 80;
117                 break;
118         case 7:
119                 r->out.info->info7.v1 = 80;
120                 r->out.info->info7.info4.v = 90;
121                 break;
122         default:
123                 return NT_STATUS_INVALID_LEVEL;
124         }
125
126         return NT_STATUS_OK;
127 }
128
129 uint32 _echo_TestSleep(pipes_struct *p, struct echo_TestSleep *r)
130 {
131         sleep(r->in.seconds);
132         return r->in.seconds;
133 }
134
135 void _echo_TestEnum(pipes_struct *p, struct echo_TestEnum *r)
136 {
137 }
138
139 void _echo_TestSurrounding(pipes_struct *p, struct echo_TestSurrounding *r)
140 {
141         r->out.data->x *= 2;
142         r->out.data->surrounding = TALLOC_ZERO_ARRAY(p->mem_ctx, uint16_t, r->in.data->x);
143 }
144
145 uint16 _echo_TestDoublePointer(pipes_struct *p, struct echo_TestDoublePointer *r)
146 {
147         if (!*r->in.data) 
148                 return 0;
149         if (!**r->in.data)
150                 return 0;
151         return ***r->in.data;
152 }
153
154 #endif /* DEVELOPER */