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