Mon Jan 21 15:03:04 CET 2008 Jim Meyering <meyering@redhat.com>
+ Adjust sexpr-related interfaces to be const-correct.
+ * src/sexpr.c (sexpr_cons, append, sexpr_append, sexpr2string)
+ (sexpr_lookup_key, sexpr_lookup, sexpr_node, sexpr_fmt_node):
+ Add "const" attribute where appropriate.
+ * src/xend_internal.c (sexpr_int, sexpr_float, sexpr_u64)
+ (sexpr_uuid, sexpr_to_xend_domain_info, sexpr_to_xend_node_info)
+ (sexpr_to_xend_topology_xml, sexpr_to_domain): Likewise.
+ * src/sexpr.h: Adjust prototypes.
+
Don't access line[-1] for a zero-length "line" from fgets.
A NUL byte at beginning of input, or just after a newline
would provoke an invalid buf[-1] access (possible segfault).
* Returns the resulting S-Expression pointer or NULL in case of error.
*/
struct sexpr *
-sexpr_cons(struct sexpr *car, struct sexpr *cdr)
+sexpr_cons(const struct sexpr *car, const struct sexpr *cdr)
{
struct sexpr *ret = sexpr_new();
if (ret == NULL)
return ret;
ret->kind = SEXPR_CONS;
- ret->u.s.car = car;
- ret->u.s.cdr = cdr;
+ ret->u.s.car = (struct sexpr *) car;
+ ret->u.s.cdr = (struct sexpr *) cdr;
return ret;
}
* Internal operation appending a value at the end of an existing list
*/
static void
-append(struct sexpr *lst, struct sexpr *value)
+append(struct sexpr *lst, const struct sexpr *value)
{
while (lst->kind != SEXPR_NIL) {
lst = lst->u.s.cdr;
}
lst->kind = SEXPR_CONS;
- lst->u.s.car = value;
+ lst->u.s.car = (struct sexpr *) value;
lst->u.s.cdr = sexpr_nil();
}
* Returns lst or NULL in case of error
*/
struct sexpr *
-sexpr_append(struct sexpr *lst, struct sexpr *value)
+sexpr_append(struct sexpr *lst, const struct sexpr *value)
{
if (lst == NULL)
return (NULL);
* 0 in case of error.
*/
size_t
-sexpr2string(struct sexpr * sexpr, char *buffer, size_t n_buffer)
+sexpr2string(const struct sexpr * sexpr, char *buffer, size_t n_buffer)
{
size_t ret = 0, tmp;
* Returns the pointer to the sub expression or NULL if not found.
*/
static struct sexpr *
-sexpr_lookup_key(struct sexpr *sexpr, const char *node)
+sexpr_lookup_key(const struct sexpr *sexpr, const char *node)
{
char buffer[4096], *ptr, *token;
}
for (token = strsep(&ptr, "/"); token; token = strsep(&ptr, "/")) {
- struct sexpr *i;
+ const struct sexpr *i;
if (token == NULL)
continue;
return NULL;
}
- return sexpr;
+ return (struct sexpr *) sexpr;
}
/**
* Returns the pointer to the sub expression or NULL if not found.
*/
struct sexpr *
-sexpr_lookup(struct sexpr *sexpr, const char *node)
+sexpr_lookup(const struct sexpr *sexpr, const char *node)
{
struct sexpr *s = sexpr_lookup_key(sexpr, node);
* Returns the value of the node or NULL if not found.
*/
const char *
-sexpr_node(struct sexpr *sexpr, const char *node)
+sexpr_node(const struct sexpr *sexpr, const char *node)
{
struct sexpr *n = sexpr_lookup(sexpr, node);
* Returns the value of the node or NULL if not found.
*/
const char *
-sexpr_fmt_node(struct sexpr *sexpr, const char *fmt, ...)
+sexpr_fmt_node(const struct sexpr *sexpr, const char *fmt, ...)
{
va_list ap;
char node[4096];
};
/* conversion to/from strings */
-size_t sexpr2string(struct sexpr *sexpr, char *buffer, size_t n_buffer);
+size_t sexpr2string(const struct sexpr *sexpr, char *buffer, size_t n_buffer);
struct sexpr *string2sexpr(const char *buffer);
/* constructors and destructors */
struct sexpr *sexpr_nil(void);
struct sexpr *sexpr_string(const char *str, ssize_t len);
-struct sexpr *sexpr_cons(struct sexpr *car, struct sexpr *cdr);
-struct sexpr *sexpr_append(struct sexpr *lst, struct sexpr *item);
+struct sexpr *sexpr_cons(const struct sexpr *car, const struct sexpr *cdr);
+struct sexpr *sexpr_append(struct sexpr *lst, const struct sexpr *item);
void sexpr_free(struct sexpr *sexpr);
/* lookup in S-Expressions */
-const char *sexpr_node(struct sexpr *sexpr, const char *node);
-const char *sexpr_fmt_node(struct sexpr *sexpr, const char *fmt, ...)
+const char *sexpr_node(const struct sexpr *sexpr, const char *node);
+const char *sexpr_fmt_node(const struct sexpr *sexpr, const char *fmt, ...)
ATTRIBUTE_FORMAT(printf,2,3);
-struct sexpr *sexpr_lookup(struct sexpr *sexpr, const char *node);
+struct sexpr *sexpr_lookup(const struct sexpr *sexpr, const char *node);
int sexpr_has(struct sexpr *sexpr, const char *node);
#endif
* Returns the value found or 0 if not found (but may not be an error)
*/
static int
-sexpr_int(struct sexpr *sexpr, const char *name)
+sexpr_int(const struct sexpr *sexpr, const char *name)
{
const char *value = sexpr_node(sexpr, name);
* Returns the value found or 0 if not found (but may not be an error)
*/
static double
-sexpr_float(struct sexpr *sexpr, const char *name)
+sexpr_float(const struct sexpr *sexpr, const char *name)
{
const char *value = sexpr_node(sexpr, name);
* Returns the value found or 0 if not found (but may not be an error)
*/
static uint64_t
-sexpr_u64(struct sexpr *sexpr, const char *name)
+sexpr_u64(const struct sexpr *sexpr, const char *name)
{
const char *value = sexpr_node(sexpr, name);
* Returns a -1 on error, 0 on success
*/
static int
-sexpr_uuid(unsigned char *ptr, struct sexpr *node, const char *path)
+sexpr_uuid(unsigned char *ptr, const struct sexpr *node, const char *path)
{
const char *r = sexpr_node(node, path);
if (!r)
* Returns 0 in case of success, -1 in case of error
*/
static int
-sexpr_to_xend_domain_info(virDomainPtr domain, struct sexpr *root, virDomainInfoPtr info)
+sexpr_to_xend_domain_info(virDomainPtr domain, const struct sexpr *root,
+ virDomainInfoPtr info)
{
const char *flags;
* Returns 0 in case of success, -1 in case of error
*/
static int
-sexpr_to_xend_node_info(struct sexpr *root, virNodeInfoPtr info)
+sexpr_to_xend_node_info(const struct sexpr *root, virNodeInfoPtr info)
{
const char *machine;
* Returns 0 in case of success, -1 in case of error
*/
static int
-sexpr_to_xend_topology_xml(virConnectPtr conn, struct sexpr *root, virBufferPtr xml)
+sexpr_to_xend_topology_xml(virConnectPtr conn, const struct sexpr *root,
+ virBufferPtr xml)
{
const char *nodeToCpu;
int numCells = 0;
* Returns the domain pointer or NULL in case of error.
*/
static virDomainPtr
-sexpr_to_domain(virConnectPtr conn, struct sexpr *root)
+sexpr_to_domain(virConnectPtr conn, const struct sexpr *root)
{
virDomainPtr ret = NULL;
unsigned char uuid[VIR_UUID_BUFLEN];