2N/A/*
2N/A * CDDL HEADER START
2N/A *
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 * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
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 *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
2N/A/* All Rights Reserved */
2N/A/*
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 * California.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A/*
2N/A * Generic XDR routines impelmentation.
2N/A *
2N/A * These are the "non-trivial" xdr primitives used to serialize and de-serialize
2N/A * "pointers". See xdr.h for more info on the interface to xdr.
2N/A */
2N/A#include "mt.h"
2N/A#include <sys/types.h>
2N/A#include <syslog.h>
2N/A#include <stdio.h>
2N/A#include <stdlib.h>
2N/A#include <rpc/types.h>
2N/A#include <rpc/xdr.h>
2N/A#include <memory.h>
2N/A
2N/A#define LASTUNSIGNED ((uint_t)0-1)
2N/Achar mem_err_msg_ref[] = "xdr_reference: out of memory";
2N/A
2N/A/*
2N/A * XDR an indirect pointer
2N/A * xdr_reference is for recursively translating a structure that is
2N/A * referenced by a pointer inside the structure that is currently being
2N/A * translated. pp references a pointer to storage. If *pp is null
2N/A * the necessary storage is allocated.
2N/A * size is the sizeof the referneced structure.
2N/A * proc is the routine to handle the referenced structure.
2N/A */
2N/Abool_t
2N/Axdr_reference(XDR *xdrs, caddr_t *pp, uint_t size, const xdrproc_t proc)
2N/A{
2N/A caddr_t loc = *pp;
2N/A bool_t stat;
2N/A
2N/A if (loc == NULL)
2N/A switch (xdrs->x_op) {
2N/A case XDR_FREE:
2N/A return (TRUE);
2N/A case XDR_DECODE:
2N/A *pp = loc = malloc(size);
2N/A if (loc == NULL) {
2N/A (void) syslog(LOG_ERR, mem_err_msg_ref);
2N/A return (FALSE);
2N/A }
2N/A (void) memset(loc, 0, (int)size);
2N/A break;
2N/A }
2N/A
2N/A stat = (*proc)(xdrs, loc, LASTUNSIGNED);
2N/A
2N/A if (xdrs->x_op == XDR_FREE) {
2N/A free(loc);
2N/A *pp = NULL;
2N/A }
2N/A return (stat);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * xdr_pointer():
2N/A *
2N/A * XDR a pointer to a possibly recursive data structure. This
2N/A * differs with xdr_reference in that it can serialize/deserialiaze
2N/A * trees correctly.
2N/A *
2N/A * What's sent is actually a union:
2N/A *
2N/A * union object_pointer switch (boolean b) {
2N/A * case TRUE: object_data data;
2N/A * case FALSE: void nothing;
2N/A * }
2N/A *
2N/A * > objpp: Pointer to the pointer to the object.
2N/A * > obj_size: size of the object.
2N/A * > xdr_obj: routine to XDR an object.
2N/A *
2N/A */
2N/Abool_t
2N/Axdr_pointer(XDR *xdrs, char **objpp, uint_t obj_size, const xdrproc_t xdr_obj)
2N/A{
2N/A bool_t more_data;
2N/A
2N/A more_data = (*objpp != NULL);
2N/A if (!xdr_bool(xdrs, &more_data))
2N/A return (FALSE);
2N/A if (!more_data) {
2N/A *objpp = NULL;
2N/A return (TRUE);
2N/A }
2N/A return (xdr_reference(xdrs, objpp, obj_size, xdr_obj));
2N/A}