Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / bsd / libbind / dist / include / isc / irpmarshall.h
blobe850ec5777e5e37541be1254ba9575dc4b4f15ed
1 /* $NetBSD$ */
3 /*
4 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (c) 1999 by Internet Software Consortium.
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
17 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 * Id: irpmarshall.h,v 1.4 2005/04/27 04:56:17 sra Exp
24 #ifndef _IRPMARSHALL_H_INCLUDED
25 #define _IRPMARSHALL_H_INCLUDED
27 /* Hide function names */
28 #define irp_marshall_gr __irp_marshall_gr
29 #define irp_marshall_ho __irp_marshall_ho
30 #define irp_marshall_ne __irp_marshall_ne
31 #define irp_marshall_ng __irp_marshall_ng
32 #define irp_marshall_nw __irp_marshall_nw
33 #define irp_marshall_pr __irp_marshall_pr
34 #define irp_marshall_pw __irp_marshall_pw
35 #define irp_marshall_sv __irp_marshall_sv
36 #define irp_unmarshall_gr __irp_unmarshall_gr
37 #define irp_unmarshall_ho __irp_unmarshall_ho
38 #define irp_unmarshall_ne __irp_unmarshall_ne
39 #define irp_unmarshall_ng __irp_unmarshall_ng
40 #define irp_unmarshall_nw __irp_unmarshall_nw
41 #define irp_unmarshall_pr __irp_unmarshall_pr
42 #define irp_unmarshall_pw __irp_unmarshall_pw
43 #define irp_unmarshall_sv __irp_unmarshall_sv
45 #define MAXPADDRSIZE (sizeof "255.255.255.255" + 1)
46 #define ADDR_T_STR(x) (x == AF_INET ? "AF_INET" :\
47 (x == AF_INET6 ? "AF_INET6" : "UNKNOWN"))
49 /* See comment below on usage */
50 int irp_marshall_pw(const struct passwd *, char **, size_t *);
51 int irp_unmarshall_pw(struct passwd *, char *);
52 int irp_marshall_gr(const struct group *, char **, size_t *);
53 int irp_unmarshall_gr(struct group *, char *);
54 int irp_marshall_sv(const struct servent *, char **, size_t *);
55 int irp_unmarshall_sv(struct servent *, char *);
56 int irp_marshall_pr(struct protoent *, char **, size_t *);
57 int irp_unmarshall_pr(struct protoent *, char *);
58 int irp_marshall_ho(struct hostent *, char **, size_t *);
59 int irp_unmarshall_ho(struct hostent *, char *);
60 int irp_marshall_ng(const char *, const char *, const char *,
61 char **, size_t *);
62 int irp_unmarshall_ng(const char **, const char **, const char **, char *);
63 int irp_marshall_nw(struct nwent *, char **, size_t *);
64 int irp_unmarshall_nw(struct nwent *, char *);
65 int irp_marshall_ne(struct netent *, char **, size_t *);
66 int irp_unmarshall_ne(struct netent *, char *);
68 /*! \file
69 * \brief
70 * Functions to marshall and unmarshall various system data structures. We
71 * use a printable ascii format that is as close to various system config
72 * files as reasonable (e.g. /etc/passwd format).
74 * We are not forgiving with unmarhsalling misformatted buffers. In
75 * particular whitespace in fields is not ignored. So a formatted password
76 * entry "brister :1364:100:...." will yield a username of "brister "
78 * We potentially do a lot of mallocs to fill fields that are of type
79 * (char **) like a hostent h_addr field. Building (for example) the
80 * h_addr field and its associated addresses all in one buffer is
81 * certainly possible, but not done here.
83 * The following description is true for all the marshalling functions:
85 * int irp_marshall_XX(struct yyyy *XX, char **buffer, size_t *len);
87 * The argument XX (of type struct passwd for example) is marshalled in the
88 * buffer pointed at by *BUFFER, which is of length *LEN. Returns 0
89 * on success and -1 on failure. Failure will occur if *LEN is
90 * smaller than needed.
92 * If BUFFER is NULL, then *LEN is set to the size of the buffer
93 * needed to marshall the data and no marshalling is actually done.
95 * If *BUFFER is NULL, then a buffer large enough will be allocated
96 * with memget() and the size allocated will be stored in *LEN. An extra 2
97 * bytes will be allocated for the client to append CRLF if wanted. The
98 * value of *LEN will include these two bytes.
100 * All the marshalling functions produce a buffer with the fields
101 * separated by colons (except for the hostent marshalling, which uses '@'
102 * to separate fields). Fields that have multiple subfields (like the
103 * gr_mem field in struct group) have their subparts separated by
104 * commas.
106 * int irp_unmarshall_XX(struct YYYYY *XX, char *buffer);
108 * The unmashalling functions break apart the buffer and store the
109 * values in the struct pointed to by XX. All pointer values inside
110 * XX are allocated with malloc. All arrays of pointers have a NULL
111 * as the last element.
114 #endif