eec126d83759464ac3f9def4f6fc985dfff7a93c
[shibboleth/cpp-sp.git] / oncrpc / rpc / svc.h
1 /*********************************************************************
2  * RPC for the Windows NT Operating System
3  * 1993 by Martin F. Gergeleit
4  * Users may use, copy or modify Sun RPC for the Windows NT Operating 
5  * System according to the Sun copyright below.
6  *
7  * RPC for the Windows NT Operating System COMES WITH ABSOLUTELY NO 
8  * WARRANTY, NOR WILL I BE LIABLE FOR ANY DAMAGES INCURRED FROM THE 
9  * USE OF. USE ENTIRELY AT YOUR OWN RISK!!!
10  *********************************************************************/
11
12 /* @(#)svc.h    2.2 88/07/29 4.0 RPCSRC; from 1.20 88/02/08 SMI */
13 /*
14  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
15  * unrestricted use provided that this legend is included on all tape
16  * media and as a part of the software program in whole or part.  Users
17  * may copy or modify Sun RPC without charge, but are not authorized
18  * to license or distribute it to anyone else except as part of a product or
19  * program developed by the user.
20  * 
21  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
22  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
24  * 
25  * Sun RPC is provided with no support and without any obligation on the
26  * part of Sun Microsystems, Inc. to assist in its use, correction,
27  * modification or enhancement.
28  * 
29  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
30  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
31  * OR ANY PART THEREOF.
32  * 
33  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
34  * or profits or other special, indirect and consequential damages, even if
35  * Sun has been advised of the possibility of such damages.
36  * 
37  * Sun Microsystems, Inc.
38  * 2550 Garcia Avenue
39  * Mountain View, California  94043
40  */
41
42 /*
43  * svc.h, Server-side remote procedure call interface.
44  *
45  * Copyright (C) 1984, Sun Microsystems, Inc.
46  */
47
48 #ifndef __SVC_HEADER__
49 #define __SVC_HEADER__
50
51 #ifdef __cplusplus
52 extern "C" {
53 #define DOTS ...
54 #else
55 #define DOTS
56 #endif
57
58
59 /*
60  * This interface must manage two items concerning remote procedure calling:
61  *
62  * 1) An arbitrary number of transport connections upon which rpc requests
63  * are received.  The two most notable transports are TCP and UDP;  they are
64  * created and registered by routines in svc_tcp.c and svc_udp.c, respectively;
65  * they in turn call xprt_register and xprt_unregister.
66  *
67  * 2) An arbitrary number of locally registered services.  Services are
68  * described by the following four data: program number, version number,
69  * "service dispatch" function, a transport handle, and a boolean that
70  * indicates whether or not the exported program should be registered with a
71  * local binder service;  if true the program's number and version and the
72  * port number from the transport handle are registered with the binder.
73  * These data are registered with the rpc svc system via svc_register.
74  *
75  * A service's dispatch function is called whenever an rpc request comes in
76  * on a transport.  The request's program and version numbers must match
77  * those of the registered service.  The dispatch function is passed two
78  * parameters, struct svc_req * and SVCXPRT *, defined below.
79  */
80
81 enum xprt_stat {
82         XPRT_DIED,
83         XPRT_MOREREQS,
84         XPRT_IDLE
85 };
86
87 /*
88  * Server side transport handle
89  */
90 typedef struct {
91         int             xp_sock;
92         u_short         xp_port;         /* associated port number */
93         struct xp_ops {
94             bool_t      (*xp_recv)(DOTS);        /* receive incomming requests */
95             enum xprt_stat (*xp_stat)(DOTS); /* get transport status */
96             bool_t      (*xp_getargs)(DOTS); /* get arguments */
97             bool_t      (*xp_reply)(DOTS);       /* send reply */
98             bool_t      (*xp_freeargs)(DOTS);/* free mem allocated for args */
99             void        (*xp_destroy)(DOTS); /* destroy this struct */
100         } *xp_ops;
101         int             xp_addrlen;      /* length of remote address */
102         struct sockaddr_in xp_raddr;     /* remote address */
103         struct opaque_auth xp_verf;      /* raw response verifier */
104         caddr_t         xp_p1;           /* private */
105         caddr_t         xp_p2;           /* private */
106 } SVCXPRT;
107
108 /*
109  *  Approved way of getting address of caller
110  */
111 #define svc_getcaller(x) (&(x)->xp_raddr)
112
113 /*
114  * Operations defined on an SVCXPRT handle
115  *
116  * SVCXPRT              *xprt;
117  * struct rpc_msg       *msg;
118  * xdrproc_t             xargs;
119  * caddr_t               argsp;
120  */
121 #define SVC_RECV(xprt, msg)                             \
122         (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
123 #define svc_recv(xprt, msg)                             \
124         (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
125
126 #define SVC_STAT(xprt)                                  \
127         (*(xprt)->xp_ops->xp_stat)(xprt)
128 #define svc_stat(xprt)                                  \
129         (*(xprt)->xp_ops->xp_stat)(xprt)
130
131 #define SVC_GETARGS(xprt, xargs, argsp)                 \
132         (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
133 #define svc_getargs(xprt, xargs, argsp)                 \
134         (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
135
136 #define SVC_REPLY(xprt, msg)                            \
137         (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
138 #define svc_reply(xprt, msg)                            \
139         (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
140
141 #define SVC_FREEARGS(xprt, xargs, argsp)                \
142         (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
143 #define svc_freeargs(xprt, xargs, argsp)                \
144         (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
145
146 #define SVC_DESTROY(xprt)                               \
147         (*(xprt)->xp_ops->xp_destroy)(xprt)
148 #define svc_destroy(xprt)                               \
149         (*(xprt)->xp_ops->xp_destroy)(xprt)
150
151
152 /*
153  * Service request
154  */
155 struct svc_req {
156         u_long          rq_prog;        /* service program number */
157         u_long          rq_vers;        /* service protocol version */
158         u_long          rq_proc;        /* the desired procedure */
159         struct opaque_auth rq_cred;     /* raw creds from the wire */
160         caddr_t         rq_clntcred;    /* read only cooked cred */
161         SVCXPRT *rq_xprt;               /* associated transport */
162 };
163
164
165 /*
166  * Service registration
167  *
168  * svc_register(xprt, prog, vers, dispatch, protocol)
169  *      SVCXPRT *xprt;
170  *      u_long prog;
171  *      u_long vers;
172  *      void (*dispatch)(DOTS);
173  *      int protocol;  /* like TCP or UDP, zero means do not register 
174  */
175 extern bool_t   svc_register(DOTS);
176
177 /*
178  * Service un-registration
179  *
180  * svc_unregister(prog, vers)
181  *      u_long prog;
182  *      u_long vers;
183  */
184 extern void     svc_unregister(DOTS);
185
186 /*
187  * Transport registration.
188  *
189  * xprt_register(xprt)
190  *      SVCXPRT *xprt;
191  */
192 extern void     xprt_register(DOTS);
193
194 /*
195  * Transport un-register
196  *
197  * xprt_unregister(xprt)
198  *      SVCXPRT *xprt;
199  */
200 extern void     xprt_unregister(DOTS);
201
202
203
204
205 /*
206  * When the service routine is called, it must first check to see if it
207  * knows about the procedure;  if not, it should call svcerr_noproc
208  * and return.  If so, it should deserialize its arguments via 
209  * SVC_GETARGS (defined above).  If the deserialization does not work,
210  * svcerr_decode should be called followed by a return.  Successful
211  * decoding of the arguments should be followed the execution of the
212  * procedure's code and a call to svc_sendreply.
213  *
214  * Also, if the service refuses to execute the procedure due to too-
215  * weak authentication parameters, svcerr_weakauth should be called.
216  * Note: do not confuse access-control failure with weak authentication!
217  *
218  * NB: In pure implementations of rpc, the caller always waits for a reply
219  * msg.  This message is sent when svc_sendreply is called.  
220  * Therefore pure service implementations should always call
221  * svc_sendreply even if the function logically returns void;  use
222  * xdr.h - xdr_void for the xdr routine.  HOWEVER, tcp based rpc allows
223  * for the abuse of pure rpc via batched calling or pipelining.  In the
224  * case of a batched call, svc_sendreply should NOT be called since
225  * this would send a return message, which is what batching tries to avoid.
226  * It is the service/protocol writer's responsibility to know which calls are
227  * batched and which are not.  Warning: responding to batch calls may
228  * deadlock the caller and server processes!
229  */
230
231 extern bool_t   svc_sendreply(DOTS);
232 extern void     svcerr_decode(DOTS);
233 extern void     svcerr_weakauth(DOTS);
234 extern void     svcerr_noproc(DOTS);
235 extern void     svcerr_progvers(DOTS);
236 extern void     svcerr_auth(DOTS);
237 extern void     svcerr_noprog(DOTS);
238 extern void     svcerr_systemerr(DOTS);
239     
240 /*
241  * Lowest level dispatching -OR- who owns this process anyway.
242  * Somebody has to wait for incoming requests and then call the correct
243  * service routine.  The routine svc_run does infinite waiting; i.e.,
244  * svc_run never returns.
245  * Since another (co-existant) package may wish to selectively wait for
246  * incoming calls or other events outside of the rpc architecture, the
247  * routine svc_getreq is provided.  It must be passed readfds, the
248  * "in-place" results of a select system call (see select, section 2).
249  */
250
251 /*
252  * Global keeper of rpc service descriptors in use
253  * dynamic; must be inspected before each call to select 
254  */
255 #ifdef FD_SETSIZE
256 #define svc_fdset (*_thr_svc_fdset())
257 #ifndef WIN32
258 #define svc_fds svc_fdset.fds_bits[0]   /* compatibility */
259 #endif
260 #else
261 extern int svc_fds;
262 #endif /* def FD_SETSIZE */
263
264 /*
265  * a small program implemented by the svc_rpc implementation itself;
266  * also see clnt.h for protocol numbers.
267  */
268 extern void rpctest_service(DOTS);
269
270 extern void     svc_getreq(DOTS);
271 extern void     svc_getreqset(DOTS);    /* takes fdset instead of int */
272 extern void     svc_run(DOTS);   /* never returns */
273
274 /*
275  * Socket to use on svcxxx_create call to get default socket
276  */
277 #define RPC_ANYSOCK     -1
278
279 /*
280  * These are the existing service side transport implementations
281  */
282
283 /*
284  * Memory based rpc for testing and timing.
285  */
286 extern SVCXPRT *svcraw_create(DOTS);
287
288 /*
289  * Udp based rpc.
290  */
291 extern SVCXPRT *svcudp_create(DOTS);
292 extern SVCXPRT *svcudp_bufcreate(DOTS);
293
294 /*
295  * Tcp based rpc.
296  */
297 extern SVCXPRT *svctcp_create(DOTS);
298
299 /*
300  * Unix FD-style rpc
301  */
302 extern SVCXPRT *svcfd_create(DOTS);
303
304 #ifdef __cplusplus
305 };
306 #endif
307
308 #endif /* __SVC_HEADER__ */