virlog: Introduce virLogParseFilters

Abstraction added over parsing a single filter. The method parses potentially a
set of logging filters, while adding each filter logging object to a
caller-provided array.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
Erik Skultety 2016-10-05 16:48:47 +02:00
parent 4b266c180b
commit 09d7ced8ee
3 changed files with 53 additions and 0 deletions

View File

@ -1891,6 +1891,7 @@ virLogParseAndDefineFilters;
virLogParseAndDefineOutputs;
virLogParseDefaultPriority;
virLogParseFilter;
virLogParseFilters;
virLogParseOutput;
virLogParseOutputs;
virLogPriorityFromSyslog;

View File

@ -2099,3 +2099,53 @@ virLogParseOutputs(const char *src, virLogOutputPtr **outputs)
virStringFreeList(strings);
return ret;
}
/**
* virLogParseFilters:
* @src: string defining a (set of) filter(s)
* @filters: pointer to a list where the individual filters shall be parsed
*
* This method parses @src and produces a list of individual filters which then
* needs to be passed to virLogDefineFilters in order to be set and taken into
* effect.
* Multiple filters can be defined in a single @src, they just need to be
* separated by spaces.
*
* Returns the number of filter parsed or -1 in case of error.
*/
int
virLogParseFilters(const char *src, virLogFilterPtr **filters)
{
int ret = -1;
size_t nfilters = 0;
size_t i, count;
char **strings = NULL;
virLogFilterPtr filter = NULL;
virLogFilterPtr *list = NULL;
VIR_DEBUG("filters=%s", src);
if (!(strings = virStringSplitCount(src, " ", 0, &count)))
goto cleanup;
for (i = 0; i < count; i++) {
/* virStringSplit may return empty strings */
if (STREQ(strings[i], ""))
continue;
if (!(filter = virLogParseFilter(strings[i])))
goto cleanup;
if (VIR_APPEND_ELEMENT(list, nfilters, filter)) {
virLogFilterFree(filter);
goto cleanup;
}
}
ret = nfilters;
*filters = list;
list = NULL;
cleanup:
virStringFreeList(strings);
return ret;
}

View File

@ -244,5 +244,7 @@ virLogOutputPtr virLogParseOutput(const char *src) ATTRIBUTE_NONNULL(1);
virLogFilterPtr virLogParseFilter(const char *src) ATTRIBUTE_NONNULL(1);
int virLogParseOutputs(const char *src,
virLogOutputPtr **outputs) ATTRIBUTE_NONNULL(1);
int virLogParseFilters(const char *src,
virLogFilterPtr **filters) ATTRIBUTE_NONNULL(1);
#endif