xdr.c revision e8031f0a8ed0e45c6d8847c5e09424e66fd34a4b
2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License, Version 1.0 only 2N/A * (the "License"). You may not use this file except in compliance 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 2N/A * Use is subject to license terms. 2N/A/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 2N/A/* All Rights Reserved */ 2N/A * Portions of this source code were derived from Berkeley 2N/A * 4.3 BSD under license from the Regents of the University of 2N/A#
pragma ident "%Z%%M% %I% %E% SMI" 2N/A * Generic XDR routines implementation. 2N/A * These are the "generic" xdr routines used to serialize and de-serialize 2N/A * most common data items. See xdr.h for more info on the interface to 2N/A * The following routine was part of a workaround for an rpcgen 2N/A * that was fixed, this routine should be removed sometime. 2N/A * constants specific to the xdr "protocol" 2N/A/* fragment size to use when doing an xdr_string() */ 2N/A * for unit alignment 2N/A * Free a data structure using XDR 2N/A * Not a filter, but a convenient utility nonetheless 2N/A * xdr_time_t sends time_t value over the wire. 2N/A * Due to RPC Protocol limitation, it can only send 2N/A * up to 32-bit integer quantity over the wire. 2N/A * Check for the time overflow, when encoding it. 2N/A * Don't want to send OTW the time value too large to 2N/A * handle by the protocol. 2N/A * XDR unsigned integers 2N/A * The definition of xdr_long()/xdr_u_long() is kept for backward 2N/A * XDR long integers, same as xdr_u_long 2N/A * XDR unsigned long integers 2N/A * XDR short integers 2N/A * XDR unsigned short integers 2N/A * XDR an unsigned char 2N/A * enums are treated as ints 2N/A * Allows the specification of a fixed size sequence of opaque bytes. 2N/A * cp points to the opaque object and cnt gives the byte length. 2N/A * if no data we are done 2N/A * round byte count to full xdr units 2N/A * *cpp is a pointer to the bytes, *sizep is the count. 2N/A * If *cpp is NULL maxsize bytes are allocated 2N/Astatic const char xdr_err[] =
"xdr_%s: out of memory";
2N/A char *
sp = *
cpp;
/* sp is the actual string pointer */ 2N/A * first deal with the length since xdr bytes are counted 2N/A * We decided not to use MACRO XDR_U_INT here, because the 2N/A * advantages here will be miniscule compared to xdr_bytes. 2N/A * This saved us 100 bytes in the library size. 2N/A * now deal with the actual bytes 2N/A * Implemented here due to commonality of the object. 2N/A * XDR a descriminated union 2N/A * Support routine for discriminated unions. 2N/A * You create an array of xdrdiscrim structures, terminated with 2N/A * an entry with a null procedure pointer. The routine gets 2N/A * the discriminant value and then searches the array of xdrdiscrims 2N/A * looking for that value. It calls the procedure given in the xdrdiscrim 2N/A * to handle the discriminant. If there is no specific routine a default 2N/A * routine may be called. 2N/A * If there is no specific or default routine an error is returned. 2N/A * we deal with the discriminator; it's an enum 2N/A * search choices for a value that matches the discriminator. 2N/A * if we find one, execute the xdr routine for that value. 2N/A * no match - execute the default xdr routine if there is one 2N/A * Non-portable xdr primitives. 2N/A * Care should be taken when moving these routines to new architectures. 2N/A * XDR null terminated ASCII strings 2N/A * xdr_string deals with "C strings" - arrays of bytes that are 2N/A * terminated by a NULL character. The parameter cpp references a 2N/A * pointer to storage; If the pointer is null, then the necessary 2N/A * storage is allocated. The last parameter is the max allowed length 2N/A * of the string as specified by a protocol. 2N/A * first deal with the length since xdr strings are counted-strings 2N/A * We decided not to use MACRO XDR_U_INT here, because the 2N/A * advantages here will be miniscule compared to xdr_string. 2N/A * This saved us 100 bytes in the library size. 2N/A * now deal with the actual bytes 2N/A /* if buffer is already given, call xdr_opaque() directly */ 2N/A * We have to allocate a buffer of size 'size'. To avoid 2N/A * malloc()ing one huge chunk, we'll read the bytes in max 2N/A * FRAGMENT size blocks and keep realloc()ing. 'block' is 2N/A * the number of bytes to read in each xdr_opaque() and 2N/A * 'bytesread' is what we have already read. sp is NULL 2N/A * when we are in the loop for the first time. 2N/A * allocate enough for 'bytesread + block' bytes and 2N/A * one extra for the terminating NULL. 2N/A /* LINTED pointer cast */ 2N/A /* LINTED pointer cast */ 2N/A /* LINTED pointer cast */ 2N/A /* LINTED pointer cast */ 2N/A * Wrapper for xdr_string that can be called directly from 2N/A * routines like clnt_call