00001 /********************************************************************* 00002 * RPC for the Windows NT Operating System 00003 * 1993 by Martin F. Gergeleit 00004 * Users may use, copy or modify Sun RPC for the Windows NT Operating 00005 * System according to the Sun copyright below. 00006 * 00007 * RPC for the Windows NT Operating System COMES WITH ABSOLUTELY NO 00008 * WARRANTY, NOR WILL I BE LIABLE FOR ANY DAMAGES INCURRED FROM THE 00009 * USE OF. USE ENTIRELY AT YOUR OWN RISK!!! 00010 *********************************************************************/ 00011 00012 /* @(#)xdr_reference.c 2.1 88/07/29 4.0 RPCSRC */ 00013 /* 00014 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 00015 * unrestricted use provided that this legend is included on all tape 00016 * media and as a part of the software program in whole or part. Users 00017 * may copy or modify Sun RPC without charge, but are not authorized 00018 * to license or distribute it to anyone else except as part of a product or 00019 * program developed by the user. 00020 * 00021 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 00022 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 00023 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 00024 * 00025 * Sun RPC is provided with no support and without any obligation on the 00026 * part of Sun Microsystems, Inc. to assist in its use, correction, 00027 * modification or enhancement. 00028 * 00029 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 00030 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 00031 * OR ANY PART THEREOF. 00032 * 00033 * In no event will Sun Microsystems, Inc. be liable for any lost revenue 00034 * or profits or other special, indirect and consequential damages, even if 00035 * Sun has been advised of the possibility of such damages. 00036 * 00037 * Sun Microsystems, Inc. 00038 * 2550 Garcia Avenue 00039 * Mountain View, California 94043 00040 */ 00041 #if !defined(lint) && defined(SCCSIDS) 00042 static char sccsid[] = "@(#)xdr_reference.c 1.11 87/08/11 SMI"; 00043 #endif 00044 00045 /* 00046 * xdr_reference.c, Generic XDR routines impelmentation. 00047 * 00048 * Copyright (C) 1987, Sun Microsystems, Inc. 00049 * 00050 * These are the "non-trivial" xdr primitives used to serialize and de-serialize 00051 * "pointers". See xdr.h for more info on the interface to xdr. 00052 */ 00053 00054 #if !defined(UNDER_CE) && !defined(WINDOWS_CE) 00055 #include <stdio.h> 00056 #endif 00057 00058 #include "xdr.h" 00059 00060 #define LASTUNSIGNED ((u_int)0-1) 00061 00062 /* 00063 * XDR an indirect pointer 00064 * xdr_reference is for recursively translating a structure that is 00065 * referenced by a pointer inside the structure that is currently being 00066 * translated. pp references a pointer to storage. If *pp is null 00067 * the necessary storage is allocated. 00068 * size is the sizeof the referneced structure. 00069 * proc is the routine to handle the referenced structure. 00070 */ 00071 bool_t 00072 xdr_reference(xdrs, pp, size, proc) 00073 register XDR *xdrs; 00074 caddr_t *pp; /* the pointer to work on */ 00075 u_int size; /* size of the object pointed to */ 00076 xdrproc_t proc; /* xdr routine to handle the object */ 00077 { 00078 register caddr_t loc = *pp; 00079 register bool_t stat; 00080 00081 if (loc == NULL) 00082 switch (xdrs->x_op) { 00083 case XDR_FREE: 00084 return (TRUE); 00085 00086 case XDR_DECODE: 00087 *pp = loc = (caddr_t) mem_alloc(size); 00088 if (loc == NULL) { 00089 #if !defined(UNDER_CE) && !defined(WINDOWS_CE) 00090 #ifdef WIN32 00091 (void) nt_rpc_report( 00092 #else 00093 (void) fprintf(stderr, 00094 #endif 00095 "xdr_reference: out of memory\n"); 00096 #endif 00097 return (FALSE); 00098 } 00099 bzero(loc, (int)size); 00100 break; 00101 } 00102 00103 stat = (*proc)(xdrs, loc, LASTUNSIGNED); 00104 00105 if (xdrs->x_op == XDR_FREE) { 00106 mem_free(loc, size); 00107 *pp = NULL; 00108 } 00109 return (stat); 00110 } 00111 00112 00113 /* 00114 * xdr_pointer(): 00115 * 00116 * XDR a pointer to a possibly recursive data structure. This 00117 * differs with xdr_reference in that it can serialize/deserialiaze 00118 * trees correctly. 00119 * 00120 * What's sent is actually a union: 00121 * 00122 * union object_pointer switch (boolean b) { 00123 * case TRUE: object_data data; 00124 * case FALSE: void nothing; 00125 * } 00126 * 00127 * > objpp: Pointer to the pointer to the object. 00128 * > obj_size: size of the object. 00129 * > xdr_obj: routine to XDR an object. 00130 * 00131 */ 00132 bool_t 00133 xdr_pointer(xdrs,objpp,obj_size,xdr_obj) 00134 register XDR *xdrs; 00135 char **objpp; 00136 u_int obj_size; 00137 xdrproc_t xdr_obj; 00138 { 00139 00140 bool_t more_data; 00141 00142 more_data = (*objpp != NULL); 00143 if (! xdr_bool(xdrs,&more_data)) { 00144 return (FALSE); 00145 } 00146 if (! more_data) { 00147 *objpp = NULL; 00148 return (TRUE); 00149 } 00150 return (xdr_reference(xdrs,objpp,obj_size,xdr_obj)); 00151 }