hmp: Rewrite strlist_from_comma_list() as hmp_split_at_comma()
Use g_strsplit() for the actual splitting. Give external linkage, so the next commit can move one of its users to another source file. Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20230124121946.1139465-15-armbru@redhat.com>
This commit is contained in:
parent
52cafcea43
commit
0d79271b57
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
bool hmp_handle_error(Monitor *mon, Error *err);
|
bool hmp_handle_error(Monitor *mon, Error *err);
|
||||||
void hmp_help_cmd(Monitor *mon, const char *name);
|
void hmp_help_cmd(Monitor *mon, const char *name);
|
||||||
|
strList *hmp_split_at_comma(const char *str);
|
||||||
|
|
||||||
void hmp_info_name(Monitor *mon, const QDict *qdict);
|
void hmp_info_name(Monitor *mon, const QDict *qdict);
|
||||||
void hmp_info_version(Monitor *mon, const QDict *qdict);
|
void hmp_info_version(Monitor *mon, const QDict *qdict);
|
||||||
|
@ -54,28 +54,21 @@ bool hmp_handle_error(Monitor *mon, Error *err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Produce a strList from a comma separated list.
|
* Split @str at comma.
|
||||||
* A NULL or empty input string return NULL.
|
* A null @str defaults to "".
|
||||||
*/
|
*/
|
||||||
static strList *strList_from_comma_list(const char *in)
|
strList *hmp_split_at_comma(const char *str)
|
||||||
{
|
{
|
||||||
|
char **split = g_strsplit(str ?: "", ",", -1);
|
||||||
strList *res = NULL;
|
strList *res = NULL;
|
||||||
strList **tail = &res;
|
strList **tail = &res;
|
||||||
|
int i;
|
||||||
|
|
||||||
while (in && in[0]) {
|
for (i = 0; split[i]; i++) {
|
||||||
char *comma = strchr(in, ',');
|
QAPI_LIST_APPEND(tail, split[i]);
|
||||||
char *value;
|
|
||||||
|
|
||||||
if (comma) {
|
|
||||||
value = g_strndup(in, comma - in);
|
|
||||||
in = comma + 1; /* skip the , */
|
|
||||||
} else {
|
|
||||||
value = g_strdup(in);
|
|
||||||
in = NULL;
|
|
||||||
}
|
|
||||||
QAPI_LIST_APPEND(tail, value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_free(split);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -632,7 +625,7 @@ void hmp_announce_self(Monitor *mon, const QDict *qdict)
|
|||||||
migrate_announce_params());
|
migrate_announce_params());
|
||||||
|
|
||||||
qapi_free_strList(params->interfaces);
|
qapi_free_strList(params->interfaces);
|
||||||
params->interfaces = strList_from_comma_list(interfaces_str);
|
params->interfaces = hmp_split_at_comma(interfaces_str);
|
||||||
params->has_interfaces = params->interfaces != NULL;
|
params->has_interfaces = params->interfaces != NULL;
|
||||||
params->id = g_strdup(id);
|
params->id = g_strdup(id);
|
||||||
qmp_announce_self(params, NULL);
|
qmp_announce_self(params, NULL);
|
||||||
@ -1234,7 +1227,7 @@ static StatsFilter *stats_filter(StatsTarget target, const char *names,
|
|||||||
request->provider = provider_idx;
|
request->provider = provider_idx;
|
||||||
if (names && !g_str_equal(names, "*")) {
|
if (names && !g_str_equal(names, "*")) {
|
||||||
request->has_names = true;
|
request->has_names = true;
|
||||||
request->names = strList_from_comma_list(names);
|
request->names = hmp_split_at_comma(names);
|
||||||
}
|
}
|
||||||
QAPI_LIST_PREPEND(request_list, request);
|
QAPI_LIST_PREPEND(request_list, request);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user