Back to index

glibc  2.9
pmap_prot2.c
Go to the documentation of this file.
00001 /* @(#)pmap_prot2.c  2.1 88/07/29 4.0 RPCSRC */
00002 /*
00003  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
00004  * unrestricted use provided that this legend is included on all tape
00005  * media and as a part of the software program in whole or part.  Users
00006  * may copy or modify Sun RPC without charge, but are not authorized
00007  * to license or distribute it to anyone else except as part of a product or
00008  * program developed by the user.
00009  *
00010  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
00011  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
00012  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
00013  *
00014  * Sun RPC is provided with no support and without any obligation on the
00015  * part of Sun Microsystems, Inc. to assist in its use, correction,
00016  * modification or enhancement.
00017  *
00018  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
00019  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
00020  * OR ANY PART THEREOF.
00021  *
00022  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
00023  * or profits or other special, indirect and consequential damages, even if
00024  * Sun has been advised of the possibility of such damages.
00025  *
00026  * Sun Microsystems, Inc.
00027  * 2550 Garcia Avenue
00028  * Mountain View, California  94043
00029  */
00030 #if !defined(lint) && defined(SCCSIDS)
00031 static char sccsid[] = "@(#)pmap_prot2.c 1.3 87/08/11 Copyr 1984 Sun Micro";
00032 #endif
00033 
00034 /*
00035  * pmap_prot2.c
00036  * Protocol for the local binder service, or pmap.
00037  *
00038  * Copyright (C) 1984, Sun Microsystems, Inc.
00039  */
00040 
00041 #include <rpc/types.h>
00042 #include <rpc/xdr.h>
00043 #include <rpc/pmap_prot.h>
00044 
00045 
00046 /*
00047  * What is going on with linked lists? (!)
00048  * First recall the link list declaration from pmap_prot.h:
00049  *
00050  * struct pmaplist {
00051  *      struct pmap pml_map;
00052  *      struct pmaplist *pml_map;
00053  * };
00054  *
00055  * Compare that declaration with a corresponding xdr declaration that
00056  * is (a) pointer-less, and (b) recursive:
00057  *
00058  * typedef union switch (bool_t) {
00059  *
00060  *      case TRUE: struct {
00061  *              struct pmap;
00062  *              pmaplist_t foo;
00063  *      };
00064  *
00065  *      case FALSE: struct {};
00066  * } pmaplist_t;
00067  *
00068  * Notice that the xdr declaration has no nxt pointer while
00069  * the C declaration has no bool_t variable.  The bool_t can be
00070  * interpreted as ``more data follows me''; if FALSE then nothing
00071  * follows this bool_t; if TRUE then the bool_t is followed by
00072  * an actual struct pmap, and then (recursively) by the
00073  * xdr union, pamplist_t.
00074  *
00075  * This could be implemented via the xdr_union primitive, though this
00076  * would cause a one recursive call per element in the list.  Rather than do
00077  * that we can ``unwind'' the recursion
00078  * into a while loop and do the union arms in-place.
00079  *
00080  * The head of the list is what the C programmer wishes to past around
00081  * the net, yet is the data that the pointer points to which is interesting;
00082  * this sounds like a job for xdr_reference!
00083  */
00084 bool_t
00085 xdr_pmaplist (xdrs, rp)
00086      XDR *xdrs;
00087      struct pmaplist **rp;
00088 {
00089   /*
00090    * more_elements is pre-computed in case the direction is
00091    * XDR_ENCODE or XDR_FREE.  more_elements is overwritten by
00092    * xdr_bool when the direction is XDR_DECODE.
00093    */
00094   bool_t more_elements;
00095   int freeing = (xdrs->x_op == XDR_FREE);
00096   struct pmaplist *next = NULL;
00097 
00098   while (TRUE)
00099     {
00100       more_elements = (bool_t) (*rp != NULL);
00101       if (!INTUSE(xdr_bool) (xdrs, &more_elements))
00102        return FALSE;
00103       if (!more_elements)
00104        return TRUE;         /* we are done */
00105       /*
00106        * the unfortunate side effect of non-recursion is that in
00107        * the case of freeing we must remember the next object
00108        * before we free the current object ...
00109        */
00110       if (freeing)
00111        next = (*rp)->pml_next;
00112       if (!INTUSE(xdr_reference) (xdrs, (caddr_t *) rp,
00113                               (u_int) sizeof (struct pmaplist),
00114                               (xdrproc_t) INTUSE(xdr_pmap)))
00115          return FALSE;
00116       rp = freeing ? &next : &((*rp)->pml_next);
00117     }
00118 }
00119 INTDEF(xdr_pmaplist)