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