Add mg_next_comma_list_entry_n()

And mgos_conf_check_access_n()

PUBLISHED_FROM=c7de937b4f5463ca463d604183a4ee831617bd6d
This commit is contained in:
Dmitry Frank 2017-08-27 13:43:17 +01:00 committed by Cesanta Bot
parent 38e984a008
commit 6fe9cae62a
2 changed files with 21 additions and 8 deletions

View File

@ -1926,19 +1926,30 @@ const char *mg_next_comma_list_entry(const char *, struct mg_str *,
struct mg_str *) WEAK;
const char *mg_next_comma_list_entry(const char *list, struct mg_str *val,
struct mg_str *eq_val) {
if (list == NULL || *list == '\0') {
struct mg_str ret = mg_next_comma_list_entry_n(mg_mk_str(list), val, eq_val);
return ret.p;
}
struct mg_str mg_next_comma_list_entry_n(struct mg_str list, struct mg_str *val,
struct mg_str *eq_val) WEAK;
struct mg_str mg_next_comma_list_entry_n(struct mg_str list, struct mg_str *val,
struct mg_str *eq_val) {
if (list.len == 0) {
/* End of the list */
list = NULL;
list = mg_mk_str(NULL);
} else {
val->p = list;
if ((list = strchr(val->p, ',')) != NULL) {
const char *chr = NULL;
*val = list;
if ((chr = mg_strchr(*val, ',')) != NULL) {
/* Comma found. Store length and shift the list ptr */
val->len = list - val->p;
list++;
val->len = chr - val->p;
chr++;
list.len -= (chr - list.p);
list.p = chr;
} else {
/* This value is the last one */
list = val->p + strlen(val->p);
val->len = list - val->p;
list = mg_mk_str_n(list.p + list.len, 0);
}
if (eq_val != NULL) {

View File

@ -2104,6 +2104,8 @@ int mg_avprintf(char **buf, size_t size, const char *fmt, va_list ap);
*/
const char *mg_next_comma_list_entry(const char *list, struct mg_str *val,
struct mg_str *eq_val);
struct mg_str mg_next_comma_list_entry_n(struct mg_str list, struct mg_str *val,
struct mg_str *eq_val);
/*
* Matches 0-terminated string (mg_match_prefix) or string with given length