1355b4669Sjacobs /*
2355b4669Sjacobs  * CDDL HEADER START
3355b4669Sjacobs  *
4355b4669Sjacobs  * The contents of this file are subject to the terms of the
5355b4669Sjacobs  * Common Development and Distribution License (the "License").
6355b4669Sjacobs  * You may not use this file except in compliance with the License.
7355b4669Sjacobs  *
8355b4669Sjacobs  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9355b4669Sjacobs  * or http://www.opensolaris.org/os/licensing.
10355b4669Sjacobs  * See the License for the specific language governing permissions
11355b4669Sjacobs  * and limitations under the License.
12355b4669Sjacobs  *
13355b4669Sjacobs  * When distributing Covered Code, include this CDDL HEADER in each
14355b4669Sjacobs  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15355b4669Sjacobs  * If applicable, add the following below this CDDL HEADER, with the
16355b4669Sjacobs  * fields enclosed by brackets "[]" replaced with your own identifying
17355b4669Sjacobs  * information: Portions Copyright [yyyy] [name of copyright owner]
18355b4669Sjacobs  *
19355b4669Sjacobs  * CDDL HEADER END
20355b4669Sjacobs  */
22355b4669Sjacobs /*
23*c40965e4Sjacobs  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24355b4669Sjacobs  * Use is subject to license terms.
25355b4669Sjacobs  *
26355b4669Sjacobs  */
28355b4669Sjacobs /* $Id: read.c 146 2006-03-24 00:26:54Z njacobs $ */
30355b4669Sjacobs #pragma ident	"%Z%%M%	%I%	%E% SMI"
32355b4669Sjacobs #include <stdio.h>
33355b4669Sjacobs #include <stdlib.h>
34355b4669Sjacobs #include <alloca.h>
35355b4669Sjacobs #include <string.h>
36355b4669Sjacobs #include <stdarg.h>
37355b4669Sjacobs #include <sys/types.h>
38355b4669Sjacobs #include <netinet/in.h>
39355b4669Sjacobs #include <inttypes.h>
41355b4669Sjacobs #include <papi.h>
42355b4669Sjacobs #include <ipp.h>
45355b4669Sjacobs #define	_ipp_tag_string(id) ipp_tag_string((id), buf, sizeof (buf))
47355b4669Sjacobs static papi_status_t
read_name_with_language(ipp_reader_t iread,void * fd,papi_attribute_t *** message)48355b4669Sjacobs read_name_with_language(ipp_reader_t iread, void *fd,
49355b4669Sjacobs 			papi_attribute_t ***message)
50355b4669Sjacobs {
51355b4669Sjacobs 	char *string;
52355b4669Sjacobs 	uint16_t size;
54355b4669Sjacobs 	/* read the language */
55355b4669Sjacobs 	if (iread(fd, &size, 2) != 2) {
56355b4669Sjacobs 		ipp_set_status(message, PAPI_BAD_REQUEST,
57355b4669Sjacobs 				"read failed: lang len\n");
58355b4669Sjacobs 		return (PAPI_BAD_REQUEST);
59355b4669Sjacobs 	}
60355b4669Sjacobs 	size = (uint16_t)ntohs(size);
62355b4669Sjacobs 	if ((string = alloca(size + 1)) == NULL) {
63355b4669Sjacobs 		ipp_set_status(message, PAPI_TEMPORARY_ERROR,
64355b4669Sjacobs 				"Memory allocation failed");
65355b4669Sjacobs 		return (PAPI_TEMPORARY_ERROR);
66355b4669Sjacobs 	}
67355b4669Sjacobs 	if (iread(fd, string, size) != size) {
68355b4669Sjacobs 		ipp_set_status(message, PAPI_BAD_REQUEST,
69355b4669Sjacobs 				"read failed: lang\n");
70355b4669Sjacobs 		return (PAPI_BAD_REQUEST);
71355b4669Sjacobs 	}
73355b4669Sjacobs 	/* read the text */
74355b4669Sjacobs 	if (iread(fd, &size, 2) != 2) {
75355b4669Sjacobs 		ipp_set_status(message, PAPI_BAD_REQUEST,