iscontrol(8): Fix synopsis, sync usage() & improve markup
[dragonfly.git] / lib / libcaps / caps_struct.h
blob5fd23e309d4dcc7b08bcf11da459b7fcc376ef55
1 /*
2 * CAPS_STRUCT.H
4 * Copyright (c) 2003 Matthew Dillon <dillon@backplane.com>
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
28 * $DragonFly: src/lib/libcaps/caps_struct.h,v 1.1 2004/03/07 23:36:44 dillon Exp $
30 #include <sys/endian.h>
32 struct caps_label;
33 struct caps_struct;
34 struct caps_msgbuf;
36 typedef const struct caps_label *caps_label_t;
37 typedef const struct caps_struct *caps_struct_t;
38 typedef struct caps_msgbuf *caps_msgbuf_t;
40 typedef u_int32_t caps_fid_t;
42 struct caps_label {
43 int offset;
44 int type;
45 int size; /* element size for array[1] */
46 caps_fid_t fid;
47 int nary; /* can be 0 or 1 to indicate 1 element */
48 caps_struct_t csinfo; /* if embedded structure */
51 struct caps_struct {
52 char *name;
53 const caps_label_t labels;
56 struct caps_msgbuf {
57 u_int8_t *base;
58 int index;
59 int bufsize;
60 int error;
63 #define CAPS_OPF_PTR 0x0100
65 #define CAPS_OP_INT_T 1
66 #define CAPS_OP_UINT_T 2
67 #define CAPS_OP_STRBUF_T 3
68 #define CAPS_OP_STRPTR_T (3|CAPS_OPF_PTR)
69 #define CAPS_OP_OPAQUE_T 4
72 * Note: signed/unsignedness may not reflect the actual type. Instead it
73 * reflects our casting policy if the client and server are using different
74 * integer sizes for any given field.
76 #define CAPS_IN_INT_T CAPS_OP_INT_T, sizeof(int)
77 #define CAPS_IN_INT8_T CAPS_OP_INT_T, sizeof(int8_t)
78 #define CAPS_IN_INT16_T CAPS_OP_INT_T, sizeof(int16_t)
79 #define CAPS_IN_INT32_T CAPS_OP_INT_T, sizeof(int32_t)
80 #define CAPS_IN_LONG_T CAPS_OP_INT_T, sizeof(long)
81 #define CAPS_IN_INT64_T CAPS_OP_INT_T, sizeof(int64_t)
83 #define CAPS_IN_UINT_T CAPS_OP_INT_T, sizeof(u_int)
84 #define CAPS_IN_UINT8_T CAPS_OP_INT_T, sizeof(u_int8_t)
85 #define CAPS_IN_UINT16_T CAPS_OP_INT_T, sizeof(u_int16_t)
86 #define CAPS_IN_UINT32_T CAPS_OP_INT_T, sizeof(u_int32_t)
87 #define CAPS_IN_ULONG_T CAPS_OP_INT_T, sizeof(u_long)
88 #define CAPS_IN_UINT64_T CAPS_OP_INT_T, sizeof(u_int64_t)
90 #define CAPS_IN_STRPTR_T CAPS_OP_STRPTR_T, 0
91 #define CAPS_IN_STRBUF_T(n) CAPS_OP_STRBUF_T, (n)
92 #define CAPS_IN_UID_T CAPS_OP_INT_T, sizeof(uid_t)
93 #define CAPS_IN_GID_T CAPS_OP_INT_T, sizeof(gid_t)
94 #define CAPS_IN_TIME_T CAPS_OP_UINT_T, sizeof(time_t)
95 #define CAPS_IN_OFF_T CAPS_OP_INT_T, sizeof(off_t)
96 #define CAPS_IN_SIZE_T CAPS_OP_UINT_T, sizeof(size_t)
97 #define CAPS_IN_SSIZE_T CAPS_OP_INT_T, sizeof(ssize_t)
99 static __inline
100 u_int8_t
101 caps_msgbuf_getc(caps_msgbuf_t msg)
103 u_int8_t c = 0;
105 if (msg->index < msg->bufsize)
106 c = msg->base[msg->index];
107 ++msg->index;
108 return(c); /* always bumped */
111 static __inline
112 void
113 caps_msgbuf_putc(caps_msgbuf_t msg, u_int8_t c)
115 if (msg->index < msg->bufsize) {
116 msg->base[msg->index] = c;
118 ++msg->index; /* always bumped */
121 extern const struct caps_struct caps_passwd_struct;
123 int caps_encode(void *buf, int bytes, void *data, caps_struct_t cs);
124 int caps_decode(const void *buf, int bytes, void *data, caps_struct_t cs, int *error);
125 void caps_struct_free_pointers(void *data, caps_struct_t cs);
126 void caps_array_free_pointers(void *data, caps_label_t label);
128 void caps_init_msgbuf(caps_msgbuf_t msg, void *data, int size);
129 void caps_msgbuf_error(caps_msgbuf_t msg, int eno, int undo);
130 u_int8_t caps_msgbuf_getclass(caps_msgbuf_t msg, u_int8_t **pptr, int *plen);
131 void caps_msgbuf_printf(caps_msgbuf_t msg, const char *ctl, ...);
133 void caps_msg_encode_structure(caps_msgbuf_t msg, void *data, caps_struct_t cs);
134 void caps_msg_encode_array(caps_msgbuf_t msg, void *data, caps_label_t label);
135 void caps_msg_encode_data(caps_msgbuf_t msg, void *data, int type, int size);
136 void caps_msg_decode_structure(caps_msgbuf_t msg, void *data, caps_struct_t cs);
137 void caps_msg_decode_array(caps_msgbuf_t msg, void *data, int nary, caps_label_t label);
138 void caps_msg_decode_data(char *ptr, int len, void *data, int type, int size);