2 * Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Useful macros and other stuff for generic lookups
26 * Copyright (C) 1989 by NeXT, Inc.
33 #include <sys/cdefs.h>
36 * kvbuf_t is used to encode requests and replies.
37 * It encodes a list of dictionaries.
38 * First 4 bytes are number of dictionaries.
39 * All numbers and lengths are uint32_t in network byte order.
40 * Each dictionary is a list of (key, value list) pairs.
41 * First 4 bytes in a dictionary are the number of keys.
42 * Key is 4 bytes (length) followed by nul-terminated string.
43 * Following the key is a value list.
44 * First 4 bytes in a value list are the number of values.
45 * Each value is 4 bytes (length) followed by nul-terminated string.
77 * Utilities for creating KV buffers
79 kvbuf_t
*kvbuf_new(void);
80 kvbuf_t
*kvbuf_init(char *buffer
, uint32_t length
);
82 void kvbuf_add_dict(kvbuf_t
*kv
);
83 void kvbuf_add_key(kvbuf_t
*kv
, const char *key
);
84 void kvbuf_add_val(kvbuf_t
*kv
, const char *val
);
85 void kvbuf_add_val_len(kvbuf_t
*kv
, const char *val
, uint32_t len
);
86 uint32_t kvbuf_get_len(const char *p
);
87 void kvbuf_free(kvbuf_t
*kv
);
90 * Utilities for getting data back from KV buffers
91 * These are ugly, but reasonably efficient.
92 * Libinfo routines decode the raw databuf in a single pass
93 * i.e. not with these routines.
96 kvarray_t
*kvbuf_decode(kvbuf_t
*kv
);
97 void kvarray_free(kvarray_t
*a
);
100 * Utility to append a kvbuf to an existing kvbuf
102 void kvbuf_append_kvbuf( kvbuf_t
*kv
, const kvbuf_t
*kv2
);
105 * Call this to start walking through the kvbuf.
106 * Returns the number of dictionaries.
108 uint32_t kvbuf_reset(kvbuf_t
*kv
);
111 * Walk through dictionaries.
112 * Returns the number of keys in the dictionary.
114 uint32_t kvbuf_next_dict(kvbuf_t
*kv
);
117 * Walk through keys in a dictionary.
118 * Returns the key. Don't free it!
119 * Sets the number of values for the key in the val_count output parameter.
121 char *kvbuf_next_key(kvbuf_t
*kv
, uint32_t *val_count
);
124 * Walk through values for a key.
125 * Returns the value. Don't free it!
127 char *kvbuf_next_val(kvbuf_t
*kv
);
130 * Walk through values for a key, with a length returned
131 * Returns the value. Don't free it!
133 char *kvbuf_next_val_len(kvbuf_t
*kv
, uint32_t *vl
);
137 #endif /* ! _KVBUF_H_ */