Commit 5db4af8bc8eb99333b0d2be1f88c943353361e50
Committed by
Anthony Liguori
1 parent
e15f4a99
Introduce get_next_param_value
In order to parse multiple instances of the same param=value pair, introduce get_next_param_value which can pass back to string parsing position after reading a parameter value. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Showing
2 changed files
with
15 additions
and
4 deletions
sysemu.h
... | ... | @@ -275,6 +275,8 @@ void usb_info(Monitor *mon); |
275 | 275 | |
276 | 276 | int get_param_value(char *buf, int buf_size, |
277 | 277 | const char *tag, const char *str); |
278 | +int get_next_param_value(char *buf, int buf_size, | |
279 | + const char *tag, const char **pstr); | |
278 | 280 | int check_params(char *buf, int buf_size, |
279 | 281 | const char * const *params, const char *str); |
280 | 282 | ... | ... |
vl.c
... | ... | @@ -1812,20 +1812,23 @@ static int socket_init(void) |
1812 | 1812 | } |
1813 | 1813 | #endif |
1814 | 1814 | |
1815 | -int get_param_value(char *buf, int buf_size, | |
1816 | - const char *tag, const char *str) | |
1815 | +int get_next_param_value(char *buf, int buf_size, | |
1816 | + const char *tag, const char **pstr) | |
1817 | 1817 | { |
1818 | 1818 | const char *p; |
1819 | 1819 | char option[128]; |
1820 | 1820 | |
1821 | - p = str; | |
1821 | + p = *pstr; | |
1822 | 1822 | for(;;) { |
1823 | 1823 | p = get_opt_name(option, sizeof(option), p, '='); |
1824 | 1824 | if (*p != '=') |
1825 | 1825 | break; |
1826 | 1826 | p++; |
1827 | 1827 | if (!strcmp(tag, option)) { |
1828 | - (void)get_opt_value(buf, buf_size, p); | |
1828 | + *pstr = get_opt_value(buf, buf_size, p); | |
1829 | + if (**pstr == ',') { | |
1830 | + (*pstr)++; | |
1831 | + } | |
1829 | 1832 | return strlen(buf); |
1830 | 1833 | } else { |
1831 | 1834 | p = get_opt_value(NULL, 0, p); |
... | ... | @@ -1837,6 +1840,12 @@ int get_param_value(char *buf, int buf_size, |
1837 | 1840 | return 0; |
1838 | 1841 | } |
1839 | 1842 | |
1843 | +int get_param_value(char *buf, int buf_size, | |
1844 | + const char *tag, const char *str) | |
1845 | +{ | |
1846 | + return get_next_param_value(buf, buf_size, tag, &str); | |
1847 | +} | |
1848 | + | |
1840 | 1849 | int check_params(char *buf, int buf_size, |
1841 | 1850 | const char * const *params, const char *str) |
1842 | 1851 | { | ... | ... |