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