The return type of canonicalize() can be modified to const char *.
This avoids the need to cast the const away from the input parameter.
There need to be quite some other functions modified to take const
parameters in order to avoid further casts.
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
struct cmd_s {
char *cmd;
- int (*func)(const void *, struct connection *, char **, int);
+ int (*func)(const void *, struct connection *, const char **, int);
char *pars;
/*
* max_pars can be used to limit the size of the parameter vector,
};
static int do_control_check(const void *ctx, struct connection *conn,
- char **vec, int num)
+ const char **vec, int num)
{
if (num)
return EINVAL;
}
static int do_control_log(const void *ctx, struct connection *conn,
- char **vec, int num)
+ const char **vec, int num)
{
int ret;
}
static int quota_set(const void *ctx, struct connection *conn,
- char **vec, int num, struct quota *quotas)
+ const char **vec, int num, struct quota *quotas)
{
unsigned int i;
int val;
}
static int quota_get(const void *ctx, struct connection *conn,
- char **vec, int num)
+ const char **vec, int num)
{
if (num != 1)
return EINVAL;
}
static int quota_max(const void *ctx, struct connection *conn,
- char **vec, int num)
+ const char **vec, int num)
{
if (num > 1)
return EINVAL;
}
static int do_control_quota(const void *ctx, struct connection *conn,
- char **vec, int num)
+ const char **vec, int num)
{
if (num == 0)
return quota_show_current(ctx, conn, hard_quotas);
}
static int do_control_quota_s(const void *ctx, struct connection *conn,
- char **vec, int num)
+ const char **vec, int num)
{
if (num == 0)
return quota_show_current(ctx, conn, soft_quotas);
#ifdef __MINIOS__
static int do_control_memreport(const void *ctx, struct connection *conn,
- char **vec, int num)
+ const char **vec, int num)
{
if (num)
return EINVAL;
}
#else
static int do_control_logfile(const void *ctx, struct connection *conn,
- char **vec, int num)
+ const char **vec, int num)
{
if (num != 1)
return EINVAL;
}
static int do_control_memreport(const void *ctx, struct connection *conn,
- char **vec, int num)
+ const char **vec, int num)
{
FILE *fp;
int fd;
#endif
static int do_control_print(const void *ctx, struct connection *conn,
- char **vec, int num)
+ const char **vec, int num)
{
if (num != 1)
return EINVAL;
return 0;
}
-static int do_control_help(const void *, struct connection *, char **, int);
+static int do_control_help(const void *, struct connection *, const char **,
+ int);
static struct cmd_s cmds[] = {
{ "check", do_control_check, "" },
};
static int do_control_help(const void *ctx, struct connection *conn,
- char **vec, int num)
+ const char **vec, int num)
{
int cmd;
char *resp;
struct buffered_data *in)
{
unsigned int cmd, num, off;
- char **vec = NULL;
+ const char **vec = NULL;
if (domain_is_unprivileged(conn))
return EACCES;
num = xenstore_count_strings(in->buffer, in->used);
if (cmds[cmd].max_pars)
num = min(num, cmds[cmd].max_pars);
- vec = talloc_array(ctx, char *, num);
+ vec = (const char **)talloc_array(ctx, char *, num);
if (!vec)
return ENOMEM;
if (get_strings(in, vec, num) < num)
* ignore any data after the final nul.
*/
unsigned int get_strings(struct buffered_data *data,
- char *vec[], unsigned int num)
+ const char *vec[], unsigned int num)
{
unsigned int off, i, len;
return strings;
}
-char *canonicalize(struct connection *conn, const void *ctx, const char *node)
+const char *canonicalize(struct connection *conn, const void *ctx,
+ const char *node)
{
const char *prefix;
if (!node || (node[0] == '/') || (node[0] == '@'))
- return (char *)node;
+ return node;
prefix = get_implicit_path(conn);
if (prefix)
return talloc_asprintf(ctx, "%s/%s", prefix, node);
- return (char *)node;
+ return node;
}
static struct node *get_node_canonicalized(struct connection *conn,
const void *ctx,
const char *name,
- char **canonical_name,
+ const char **canonical_name,
unsigned int perm)
{
- char *tmp_name;
+ const char *tmp_name;
if (!canonical_name)
canonical_name = &tmp_name;
}
static struct node *get_spec_node(struct connection *conn, const void *ctx,
- const char *name, char **canonical_name,
+ const char *name, const char **canonical_name,
unsigned int perm)
{
if (name[0] == '@')
{
unsigned int offset, datalen;
struct node *node;
- char *vec[1] = { NULL }; /* gcc4 + -W + -Werror fucks code. */
- char *name;
+ const char *vec[1] = { NULL }; /* gcc4 + -W + -Werror fucks code. */
+ const char *name;
/* Extra "strings" can be created by binary data. */
if (get_strings(in, vec, ARRAY_SIZE(vec)) < ARRAY_SIZE(vec))
struct buffered_data *in)
{
struct node *node;
- char *name;
+ const char *name;
node = get_node_canonicalized(conn, ctx, onearg(in), &name,
XS_PERM_WRITE);
{
struct node *node;
int ret;
- char *name;
+ const char *name;
char *parentname;
node = get_node_canonicalized(conn, ctx, onearg(in), &name,
struct buffered_data *in)
{
struct node_perms perms, old_perms;
- char *name, *permstr;
+ const char *name;
+ char *permstr;
struct node *node;
perms.num = xenstore_count_strings(in->buffer, in->used);
/* Break input into vectors, return the number, fill in up to num of them. */
unsigned int get_strings(struct buffered_data *data,
- char *vec[], unsigned int num);
+ const char *vec[], unsigned int num);
unsigned int get_string(const struct buffered_data *data, unsigned int offset);
void send_reply(struct connection *conn, enum xsd_sockmsg_type type,
void send_ack(struct connection *conn, enum xsd_sockmsg_type type);
/* Canonicalize this path if possible. */
-char *canonicalize(struct connection *conn, const void *ctx, const char *node);
+const char *canonicalize(struct connection *conn, const void *ctx,
+ const char *node);
/* Get access permissions. */
unsigned int perm_for_conn(struct connection *conn,
struct buffered_data *in)
{
struct domain *domain;
- char *vec[3];
+ const char *vec[3];
unsigned int domid;
evtchn_port_t port;
int do_set_target(const void *ctx, struct connection *conn,
struct buffered_data *in)
{
- char *vec[2];
+ const char *vec[2];
unsigned int domid, tdomid;
struct domain *domain, *tdomain;
if (get_strings(in, vec, ARRAY_SIZE(vec)) < ARRAY_SIZE(vec))
return NULL;
}
-int do_control_lu(const void *ctx, struct connection *conn, char **vec,
+int do_control_lu(const void *ctx, struct connection *conn, const char **vec,
int num)
{
const char *ret = NULL;
/* Write the "OK" response for the live-update command */
unsigned int lu_write_response(FILE *fp);
-int do_control_lu(const void *ctx, struct connection *conn, char **vec,
+int do_control_lu(const void *ctx, struct connection *conn, const char **vec,
int num);
/* Live update private interfaces. */
FILE *lu_dump_open(const void *ctx);
void lu_dump_close(FILE *fp);
char *lu_exec(const void *ctx, int argc, char **argv);
-const char *lu_arch(const void *ctx, struct connection *conn, char **vec,
+const char *lu_arch(const void *ctx, struct connection *conn, const char **vec,
int num);
const char *lu_begin(struct connection *conn);
void lu_destroy_arch(void *data);
return NULL;
}
-const char *lu_arch(const void *ctx, struct connection *conn, char **vec,
+const char *lu_arch(const void *ctx, struct connection *conn, const char **vec,
int num)
{
if (num == 2 && !strcmp(vec[0], "-f"))
return NULL;
}
-const char *lu_arch(const void *ctx, struct connection *conn, char **vec,
+const char *lu_arch(const void *ctx, struct connection *conn, const char **vec,
int num)
{
if (num == 2 && !strcmp(vec[0], "-b"))
}
static int check_watch_path(struct connection *conn, const void *ctx,
- char **path, bool *relative)
+ const char **path, bool *relative)
{
/* Check if valid event. */
if (strstarts(*path, "@")) {
return errno;
}
-static struct watch *add_watch(struct connection *conn, char *path, char *token,
- bool relative, bool no_quota_check)
+static struct watch *add_watch(struct connection *conn, const char *path,
+ const char *token, bool relative,
+ bool no_quota_check)
{
struct watch *watch;
int do_watch(const void *ctx, struct connection *conn, struct buffered_data *in)
{
struct watch *watch;
- char *vec[2];
+ const char *vec[2];
bool relative;
if (get_strings(in, vec, ARRAY_SIZE(vec)) != ARRAY_SIZE(vec))
struct buffered_data *in)
{
struct watch *watch;
- char *node, *vec[2];
+ const char *node;
+ const char *vec[2];
if (get_strings(in, vec, ARRAY_SIZE(vec)) != ARRAY_SIZE(vec))
return EINVAL;
{
const struct xs_state_watch *sw = state;
struct connection *conn;
- char *path, *token;
+ const char *path, *token;
bool relative;
conn = get_connection_by_id(sw->conn_id);