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