2 * Copyright (c) 2003 Matthew Dillon <dillon@backplane.com>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * $DragonFly: src/lib/libcaps/caps_msgbuf.c,v 1.1 2004/03/07 23:36:44 dillon Exp $
32 caps_init_msgbuf(caps_msgbuf_t msg
, void *data
, int size
)
41 caps_msgbuf_error(caps_msgbuf_t msg
, int eno
, int undo
)
45 if (msg
->index
< undo
)
52 * Extract the next class specification. A class specification is an upper
53 * case letter followed by quoted data or non-quoted data. Non-quoted data
54 * may only contain the characters 0-9 and LOWER CASE a-z, '.', or '_'.
55 * The returned (ptr,len) tuple includes the quotes in quoted data.
58 caps_msgbuf_getclass(caps_msgbuf_t msg
, u_int8_t
**pptr
, int *plen
)
64 while (msg
->index
< msg
->bufsize
) {
65 c
= msg
->base
[msg
->index
++];
66 if (c
>= 'A' && c
<= 'Z') {
68 *pptr
= msg
->base
+ i
;
69 if (i
< msg
->bufsize
&& msg
->base
[i
] == '\"') {
70 for (++i
; i
< msg
->bufsize
; ++i
) {
72 if ((cc
>= 'a' && cc
<= 'z') ||
73 (cc
>= 'A' && cc
<= 'Z') ||
74 (cc
>= '0' && cc
<= '9') ||
75 cc
== '_' || cc
== '.' || cc
== '/' || cc
== '+' ||
76 cc
== '-' || cc
== '%'
80 if (cc
== '"') /* quote end string, else error */
87 for (; i
< msg
->bufsize
; ++i
) {
89 if (cc
>= 'a' && cc
<= 'z')
91 if (cc
>= '0' && cc
<= '9')
93 if (cc
== '.' || cc
== '_')
98 *plen
= i
- msg
->index
;
102 if (c
== ',' || c
== '{' || c
== '}')
104 if (c
!= '\t' && c
!= ' ' && c
!= '\r' && c
!= '\n') {
108 /* loop on whitespce */
114 * Support routines for encoding/decoding
117 caps_msgbuf_printf(caps_msgbuf_t msg
, const char *ctl
, ...)
124 if (i
<= msg
->bufsize
)
125 i
+= vsnprintf(msg
->base
+ i
, msg
->bufsize
- i
, ctl
, va
);
127 i
+= vsnprintf(NULL
, 0, ctl
, va
);