mirror of
https://github.com/cesanta/mongoose.git
synced 2026-12-04 21:58:22 +00:00
Moved next_option() to the rest of string functions
This commit is contained in:
1 parent
2f69ca37d3
commit
9390c66b48
1 file changed
+39
-39
+39
-39
@@ -427,6 +427,45 @@ static void mg_strlcpy(register char *dst, register const char *src, size_t n) {
|
|||||||
*dst = '\0';
|
*dst = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A helper function for traversing a comma separated list of values.
|
||||||
|
// It returns a list pointer shifted to the next value, or NULL if the end
|
||||||
|
// of the list found.
|
||||||
|
// Value is stored in val vector. If value has form "x=y", then eq_val
|
||||||
|
// vector is initialized to point to the "y" part, and val vector length
|
||||||
|
// is adjusted to point only to "x".
|
||||||
|
static const char *next_option(const char *list, struct vec *val,
|
||||||
|
struct vec *eq_val) {
|
||||||
|
if (list == NULL || *list == '\0') {
|
||||||
|
// End of the list
|
||||||
|
list = NULL;
|
||||||
|
} else {
|
||||||
|
val->ptr = list;
|
||||||
|
if ((list = strchr(val->ptr, ',')) != NULL) {
|
||||||
|
// Comma found. Store length and shift the list ptr
|
||||||
|
val->len = list - val->ptr;
|
||||||
|
list++;
|
||||||
|
} else {
|
||||||
|
// This value is the last one
|
||||||
|
list = val->ptr + strlen(val->ptr);
|
||||||
|
val->len = list - val->ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (eq_val != NULL) {
|
||||||
|
// Value has form "x=y", adjust pointers and lengths
|
||||||
|
// so that val points to "x", and eq_val points to "y".
|
||||||
|
eq_val->len = 0;
|
||||||
|
eq_val->ptr = (const char *) memchr(val->ptr, '=', val->len);
|
||||||
|
if (eq_val->ptr != NULL) {
|
||||||
|
eq_val->ptr++; // Skip over '=' character
|
||||||
|
eq_val->len = val->ptr + val->len - eq_val->ptr;
|
||||||
|
val->len = (eq_val->ptr - val->ptr) - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
static int spool(struct iobuf *io, const void *buf, int len) {
|
static int spool(struct iobuf *io, const void *buf, int len) {
|
||||||
static const double mult = 1.2;
|
static const double mult = 1.2;
|
||||||
char *p = NULL;
|
char *p = NULL;
|
||||||
@@ -589,45 +628,6 @@ int mg_printf(struct mg_connection *conn, const char *fmt, ...) {
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A helper function for traversing a comma separated list of values.
|
|
||||||
// It returns a list pointer shifted to the next value, or NULL if the end
|
|
||||||
// of the list found.
|
|
||||||
// Value is stored in val vector. If value has form "x=y", then eq_val
|
|
||||||
// vector is initialized to point to the "y" part, and val vector length
|
|
||||||
// is adjusted to point only to "x".
|
|
||||||
static const char *next_option(const char *list, struct vec *val,
|
|
||||||
struct vec *eq_val) {
|
|
||||||
if (list == NULL || *list == '\0') {
|
|
||||||
// End of the list
|
|
||||||
list = NULL;
|
|
||||||
} else {
|
|
||||||
val->ptr = list;
|
|
||||||
if ((list = strchr(val->ptr, ',')) != NULL) {
|
|
||||||
// Comma found. Store length and shift the list ptr
|
|
||||||
val->len = list - val->ptr;
|
|
||||||
list++;
|
|
||||||
} else {
|
|
||||||
// This value is the last one
|
|
||||||
list = val->ptr + strlen(val->ptr);
|
|
||||||
val->len = list - val->ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (eq_val != NULL) {
|
|
||||||
// Value has form "x=y", adjust pointers and lengths
|
|
||||||
// so that val points to "x", and eq_val points to "y".
|
|
||||||
eq_val->len = 0;
|
|
||||||
eq_val->ptr = (const char *) memchr(val->ptr, '=', val->len);
|
|
||||||
if (eq_val->ptr != NULL) {
|
|
||||||
eq_val->ptr++; // Skip over '=' character
|
|
||||||
eq_val->len = val->ptr + val->len - eq_val->ptr;
|
|
||||||
val->len = (eq_val->ptr - val->ptr) - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int mg_socketpair(sock_t sp[2]) {
|
static int mg_socketpair(sock_t sp[2]) {
|
||||||
struct sockaddr_in sa;
|
struct sockaddr_in sa;
|
||||||
sock_t sock, ret = -1;
|
sock_t sock, ret = -1;
|
||||||
|
|||||||
Reference in new issue
Block a user